diff options
Diffstat (limited to 'test/964-default-iface-init-generated/util-src')
| -rwxr-xr-x | test/964-default-iface-init-generated/util-src/generate_java.py (renamed from test/964-default-iface-init-generated/util-src/generate_smali.py) | 212 |
1 files changed, 50 insertions, 162 deletions
diff --git a/test/964-default-iface-init-generated/util-src/generate_smali.py b/test/964-default-iface-init-generated/util-src/generate_java.py index c0ba157109..b2df49f70e 100755 --- a/test/964-default-iface-init-generated/util-src/generate_smali.py +++ b/test/964-default-iface-init-generated/util-src/generate_java.py @@ -15,7 +15,7 @@ # limitations under the License. """ -Generate Smali test files for test 964. +Generate java test files for test 964. """ import os @@ -40,47 +40,27 @@ import string # The max depth the tree can have. MAX_IFACE_DEPTH = 3 -class MainClass(mixins.DumpMixin, mixins.Named, mixins.SmaliFileMixin): +class MainClass(mixins.DumpMixin, mixins.Named, mixins.JavaFileMixin): """ - A Main.smali file containing the Main class and the main function. It will run + A Main.java file containing the Main class and the main function. It will run all the test functions we have. """ MAIN_CLASS_TEMPLATE = """{copyright} - -.class public LMain; -.super Ljava/lang/Object; - -# class Main {{ - -.method public constructor <init>()V - .registers 1 - invoke-direct {{p0}}, Ljava/lang/Object;-><init>()V - return-void -.end method - +class Main {{ {test_groups} - {main_func} - -# }} +}} """ MAIN_FUNCTION_TEMPLATE = """ -# public static void main(String[] args) {{ -.method public static main([Ljava/lang/String;)V - .locals 2 - + public static void main(String[] args) {{ {test_group_invoke} - - return-void -.end method -# }} + }} """ TEST_GROUP_INVOKE_TEMPLATE = """ -# {test_name}(); - invoke-static {{}}, {test_name}()V + {test_name}(); """ def __init__(self): @@ -110,7 +90,7 @@ class MainClass(mixins.DumpMixin, mixins.Named, mixins.SmaliFileMixin): def __str__(self): """ - Print the smali code for this test. + Print the java code for this test. """ all_tests = sorted(self.tests) test_invoke = "" @@ -121,7 +101,7 @@ class MainClass(mixins.DumpMixin, mixins.Named, mixins.SmaliFileMixin): test_invoke += self.TEST_GROUP_INVOKE_TEMPLATE.format(test_name=t.get_name()) main_func = self.MAIN_FUNCTION_TEMPLATE.format(test_group_invoke=test_invoke) - return self.MAIN_CLASS_TEMPLATE.format(copyright = get_copyright('smali'), + return self.MAIN_CLASS_TEMPLATE.format(copyright = get_copyright('java'), test_groups = test_groups, main_func = main_func) @@ -132,46 +112,19 @@ class Func(mixins.Named, mixins.NameComparableMixin): """ TEST_FUNCTION_TEMPLATE = """ -# public static void {fname}() {{ -# try {{ -# System.out.println("About to initialize {tree}"); -# {farg} v = new {farg}(); -# System.out.println("Initialized {tree}"); -# v.touchAll(); -# System.out.println("All of {tree} hierarchy initialized"); -# return; -# }} catch (Error e) {{ -# e.printStackTrace(System.out); -# return; -# }} -# }} -.method public static {fname}()V - .locals 7 - :call_{fname}_try_start - sget-object v2, Ljava/lang/System;->out:Ljava/io/PrintStream; - const-string v3, "About to initialize {tree}" - invoke-virtual {{v2, v3}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V - - new-instance v6, L{farg}; - invoke-direct {{v6}}, L{farg};-><init>()V - - const-string v3, "Initialized {tree}" - invoke-virtual {{v2, v3}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V - - invoke-virtual {{v6}}, L{farg};->touchAll()V - - const-string v3, "All of {tree} hierarchy initialized" - invoke-virtual {{v2, v3}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V - - return-void - :call_{fname}_try_end - .catch Ljava/lang/Error; {{:call_{fname}_try_start .. :call_{fname}_try_end}} :error_{fname}_start - :error_{fname}_start - move-exception v3 - sget-object v2, Ljava/lang/System;->out:Ljava/io/PrintStream; - invoke-virtual {{v3,v2}}, Ljava/lang/Error;->printStackTrace(Ljava/io/PrintStream;)V - return-void -.end method + public static void {fname}() {{ + try {{ + System.out.println("About to initialize {tree}"); + {farg} v = new {farg}(); + System.out.println("Initialized {tree}"); + v.touchAll(); + System.out.println("All of {tree} hierarchy initialized"); + return; + }} catch (Error e) {{ + e.printStackTrace(System.out); + return; + }} + }} """ OUTPUT_FORMAT = """ @@ -190,7 +143,7 @@ All of {tree} hierarchy initialized def __str__(self): """ - Print the smali code for this test function. + Print the java code for this test function. """ return self.TEST_FUNCTION_TEMPLATE.format(fname=self.get_name(), farg=self.farg.get_name(), @@ -211,57 +164,26 @@ All of {tree} hierarchy initialized initialize_output = self.farg.get_initialize_output().strip(), touch_output = self.farg.get_touch_output().strip()) -class TestClass(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.SmaliFileMixin): +class TestClass(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.JavaFileMixin): """ A class that will be instantiated to test interface initialization order. """ TEST_CLASS_TEMPLATE = """{copyright} - -.class public L{class_name}; -.super Ljava/lang/Object; -{implements_spec} - -# public class {class_name} implements {ifaces} {{ -# -# public {class_name}() {{ -# }} -.method public constructor <init>()V - .locals 2 - invoke-direct {{p0}}, Ljava/lang/Object;-><init>()V - return-void -.end method - -# public void marker() {{ -# return; -# }} -.method public marker()V - .locals 0 - return-void -.end method - -# public void touchAll() {{ -.method public touchAll()V - .locals 2 - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - {touch_calls} - return-void -.end method -# }} -# }} -""" - - IMPLEMENTS_TEMPLATE = """ -.implements L{iface_name}; +public class {class_name} implements {ifaces} {{ + public void marker() {{ + return; + }} + + public void touchAll() {{ +{touch_calls} + }} +}} """ TOUCH_CALL_TEMPLATE = """ -# System.out.println("{class_name} touching {iface_name}"); -# {iface_name}.field.touch(); - const-string v1, "{class_name} touching {iface_name}" - invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V - sget-object v1, L{iface_name};->field:LDisplayer; - invoke-virtual {{v1}}, LDisplayer;->touch()V + System.out.println("{class_name} touching {iface_name}"); + {iface_name}.field.touch(); """ TOUCH_OUTPUT_TEMPLATE = """ @@ -306,63 +228,32 @@ class TestClass(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixi def __str__(self): """ - Print the smali code for this class. + Print the java code for this class. """ - s_ifaces = '\n'.join(map(lambda a: self.IMPLEMENTS_TEMPLATE.format(iface_name = a.get_name()), - self.ifaces)) j_ifaces = ', '.join(map(lambda a: a.get_name(), self.ifaces)) touches = '\n'.join(map(lambda a: self.TOUCH_CALL_TEMPLATE.format(class_name = self.class_name, iface_name = a.get_name()), self.get_all_interfaces())) - return self.TEST_CLASS_TEMPLATE.format(copyright = get_copyright('smali'), - implements_spec = s_ifaces, + return self.TEST_CLASS_TEMPLATE.format(copyright = get_copyright('java'), ifaces = j_ifaces, class_name = self.class_name, touch_calls = touches) -class TestInterface(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.SmaliFileMixin): +class TestInterface(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.JavaFileMixin): """ An interface that will be used to test default method resolution order. """ TEST_INTERFACE_TEMPLATE = """{copyright} -.class public abstract interface L{class_name}; -.super Ljava/lang/Object; -{implements_spec} - -# public interface {class_name} {extends} {ifaces} {{ -# public static final Displayer field = new Displayer("{tree}"); -.field public final static field:LDisplayer; - -.method static constructor <clinit>()V - .locals 3 - const-string v2, "{tree}" - new-instance v1, LDisplayer; - invoke-direct {{v1, v2}}, LDisplayer;-><init>(Ljava/lang/String;)V - sput-object v1, L{class_name};->field:LDisplayer; - return-void -.end method - -# public void marker(); -.method public abstract marker()V -.end method - +public interface {class_name} {extends} {ifaces} {{ + public static final Displayer field = new Displayer("{tree}"); + public void marker(); {funcs} - -# }} +}} """ DEFAULT_FUNC_TEMPLATE = """ -# public default void {class_name}_DEFAULT_FUNC() {{ -# return; -# }} -.method public {class_name}_DEFAULT_FUNC()V - .locals 0 - return-void -.end method -""" - IMPLEMENTS_TEMPLATE = """ -.implements L{iface_name}; + public default void {class_name}_DEFAULT_FUNC() {{ return; }} """ OUTPUT_TEMPLATE = "initialization of {tree}" @@ -429,17 +320,14 @@ class TestInterface(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, def __str__(self): """ - Print the smali code for this interface. + Print the java code for this interface. """ - s_ifaces = '\n'.join(map(lambda a: self.IMPLEMENTS_TEMPLATE.format(iface_name = a.get_name()), - self.ifaces)) j_ifaces = ', '.join(map(lambda a: a.get_name(), self.ifaces)) if self.default: funcs = self.DEFAULT_FUNC_TEMPLATE.format(class_name = self.class_name) else: funcs = "" - return self.TEST_INTERFACE_TEMPLATE.format(copyright = get_copyright('smali'), - implements_spec = s_ifaces, + return self.TEST_INTERFACE_TEMPLATE.format(copyright = get_copyright('java'), extends = "extends" if len(self.ifaces) else "", ifaces = j_ifaces, funcs = funcs, @@ -516,16 +404,16 @@ def create_all_test_files(): return mc, classes def main(argv): - smali_dir = Path(argv[1]) - if not smali_dir.exists() or not smali_dir.is_dir(): - print("{} is not a valid smali dir".format(smali_dir), file=sys.stderr) + java_dir = Path(argv[1]) + if not java_dir.exists() or not java_dir.is_dir(): + print("{} is not a valid java dir".format(java_dir), file=sys.stderr) sys.exit(1) expected_txt = Path(argv[2]) mainclass, all_files = create_all_test_files() with expected_txt.open('w') as out: print(mainclass.get_expected(), file=out) for f in all_files: - f.dump(smali_dir) + f.dump(java_dir) if __name__ == '__main__': main(sys.argv) |