about summary refs log tree commit diff stats
path: root/test/arch/mep/jit/ut_helpers_jit.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/arch/mep/jit/ut_helpers_jit.py')
-rw-r--r--test/arch/mep/jit/ut_helpers_jit.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/arch/mep/jit/ut_helpers_jit.py b/test/arch/mep/jit/ut_helpers_jit.py
new file mode 100644
index 00000000..590c534f
--- /dev/null
+++ b/test/arch/mep/jit/ut_helpers_jit.py
@@ -0,0 +1,49 @@
+# Toshiba MeP-c4 - unit tests helpers
+# Guillaume Valadon <guillaume@valadon.net>
+
+from miasm2.analysis.machine import Machine
+from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
+
+
+def jit_instructions(mn_str):
+    """JIT instructions and return the jitter object."""
+
+    # Get the miasm2 Machine
+    machine = Machine("mepb")
+    mn_mep = machine.mn()
+
+    # Assemble the instructions
+    asm = ""
+    for instr_str in mn_str.split("\n"):
+        instr = mn_mep.fromstring(instr_str, "b")
+        instr.mode = "b"
+        asm += mn_mep.asm(instr)[0]
+
+    # Init the jitter and add the assembled instructions to memory
+    jitter = machine.jitter(jit_type="gcc")
+    jitter.vm.add_memory_page(0, PAGE_READ | PAGE_WRITE, asm)
+
+    # Set the breakpoint
+    jitter.add_breakpoint(len(asm), lambda x: False)
+
+    # Jit the instructions
+    #jitter.init_stack()
+    jitter.init_run(0)
+    jitter.continue_run()
+
+    return jitter
+
+
+def launch_tests(obj):
+    """Call test methods by name"""
+
+    test_methods = [name for name in dir(obj) if name.startswith("test")]
+
+    for method in test_methods:
+        print method
+        try:
+            getattr(obj, method)()
+        except AttributeError as e:
+            print "Method not found: %s" % method
+            assert(False)
+        print '-' * 42