diff paraspace/tests/injection_test.py @ 135:b488ca519709

Make sure elements are absolute incremental for sorted arrays when injecting. - All sorted array of DEXFile must be absolute incremental. - If injected one is the same order as one already in the array, the one in array are used to replace injected one. - All references to clone and injected one refer to ones already in array instead.
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 09 Aug 2011 21:28:13 +0800
parents 75a31967ebee
children f31bfe55d9c2
line wrap: on
line diff
--- a/paraspace/tests/injection_test.py	Tue Aug 09 17:23:01 2011 +0800
+++ b/paraspace/tests/injection_test.py	Tue Aug 09 21:28:13 2011 +0800
@@ -492,3 +492,54 @@
             raise
         pass
     pass
+
+
+## \brief Test case for protoid out of order.
+#
+# Dalvik complaints that output of inject_redir() is out-of-order in
+# DEXFile.protoIds list.
+# \pre
+#   E/dalvikvm(  298): Out-of-order proto_id arguments
+#   E/dalvikvm(  298): Trouble with item 14 @ offset 0x304
+#   E/dalvikvm(  298): Cross-item verify of section type 0003 failed
+#   E/dalvikvm(  298): ERROR: Byte swap + verify failed
+#   E/dalvikvm(  298): Optimization failed
+#
+def proto_id_order_verify_test():
+    from paraspace.dex_deptracker import prepare_dep_decls
+    from paraspace.dex_deptracker import dex_sort_sorted_arrays
+    from paraspace.injection import inject_redir_no_restore
+    
+    _install_dexfile_4_deptracker()
+    
+    all_dep_decls = prepare_dep_decls()
+    
+    srcdir = os.path.dirname(__file__)
+    datapath = os.path.join(srcdir, '..', '..', 'data')
+
+    fake_path = os.path.join(datapath, 'fakefile.dex')
+    hello_path = os.path.join(datapath, 'helloworld.dex')
+    
+    fake_dex = dexfile.DEXFile.open(fake_path)
+    fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex,
+                                                            all_dep_decls)
+
+    hello_dex = dexfile.DEXFile.open(hello_path)
+    hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex,
+                                                             all_dep_decls)
+
+    inject_redir_no_restore(fake_linked, 'Lcom/codemud/fakefile/fakefile;',
+                            hello_linked, 'Ljava/io/File;', all_dep_decls)
+
+    dex_sort_sorted_arrays(hello_linked)
+
+    pairs = map(None, hello_linked.protoIds.items[:-1],
+                hello_linked.protoIds.items[1:])
+    for idx, (protoid0, protoid1) in enumerate(pairs):
+        try:
+            assert protoid0 < protoid1
+        except:
+            print 'ERROR: protoid %d is out of order' % (idx + 1)
+            raise
+        pass
+    pass