about summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/jitter/jit_options.py97
-rw-r--r--test/jitter/jitload.py3
-rw-r--r--test/jitter/vm_mngr.py3
-rwxr-xr-xtest/test_all.py5
4 files changed, 105 insertions, 3 deletions
diff --git a/test/jitter/jit_options.py b/test/jitter/jit_options.py
new file mode 100644
index 00000000..cc955c64
--- /dev/null
+++ b/test/jitter/jit_options.py
@@ -0,0 +1,97 @@
+import os
+import sys
+from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
+from miasm2.analysis.machine import Machine
+from pdb import pm
+
+# Shellcode
+
+# main:
+#       MOV EAX, 0x1
+# loop_main:
+#       CMP EAX, 0x10
+#       JZ loop_end
+# loop_inc:
+#       INC EAX
+#       JMP loop_main
+# loop_end:
+#       RET
+data = "b80100000083f810740340ebf8c3".decode("hex")
+run_addr = 0x40000000
+
+def code_sentinelle(jitter):
+    jitter.run = False
+    jitter.pc = 0
+    return True
+
+def init_jitter():
+    global data, run_addr
+    # Create jitter
+    myjit = Machine("x86_32").jitter(sys.argv[1])
+
+    myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, data)
+
+    # Init jitter
+    myjit.init_stack()
+    myjit.jit.log_regs = True
+    myjit.jit.log_mn = True
+    myjit.push_uint32_t(0x1337beef)
+
+    myjit.add_breakpoint(0x1337beef, code_sentinelle)
+    return myjit
+
+# Test 'max_exec_per_call'
+print "[+] First run, to jit blocks"
+myjit = init_jitter()
+myjit.init_run(run_addr)
+myjit.continue_run()
+
+assert myjit.run is False
+assert myjit.cpu.EAX  == 0x10
+
+## Let's specify a max_exec_per_call
+## 5: main, loop_main, loop_inc, loop_main, loop_inc
+myjit.jit.options["max_exec_per_call"] = 5
+
+first_call = True
+def cb(jitter):
+    global first_call
+    if first_call:
+        # Avoid breaking on the first pass (before any execution)
+        first_call = False
+        return True
+    return False
+
+## Second run
+print "[+] Second run"
+myjit.push_uint32_t(0x1337beef)
+myjit.cpu.EAX = 0
+myjit.init_run(run_addr)
+myjit.exec_cb = cb
+myjit.continue_run()
+
+assert myjit.run is True
+# Use a '<=' because it's a 'max_...'
+assert myjit.cpu.EAX <= 3
+
+# Test 'jit_maxline'
+print "[+] Run instr one by one"
+myjit = init_jitter()
+myjit.jit.options["jit_maxline"] = 1
+myjit.jit.options["max_exec_per_call"] = 1
+
+counter = 0
+def cb(jitter):
+    global counter
+    counter += 1
+    return True
+
+myjit.init_run(run_addr)
+myjit.exec_cb = cb
+myjit.continue_run()
+
+assert myjit.run is False
+assert myjit.cpu.EAX  == 0x10
+## dry(1) + main(1) + (loop_main(2) + loop_inc(2))*(0x10 - 1) + loop_main(2) +
+## loop_end(1) = 65
+assert counter == 65
diff --git a/test/jitter/jitload.py b/test/jitter/jitload.py
index 283298db..544e9d18 100644
--- a/test/jitter/jitload.py
+++ b/test/jitter/jitload.py
@@ -1,3 +1,4 @@
+import sys
 from pdb import pm
 
 from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
@@ -9,7 +10,7 @@ from miasm2.expression.expression import ExprId, ExprInt32, ExprInt64, ExprAff,
 data = "8d49048d5b0180f90174058d5bffeb038d5b0189d8c3".decode("hex")
 
 # Init jitter
-myjit = Machine("x86_32").jitter()
+myjit = Machine("x86_32").jitter(sys.argv[1])
 myjit.init_stack()
 
 run_addr = 0x40000000
diff --git a/test/jitter/vm_mngr.py b/test/jitter/vm_mngr.py
index b2b7336b..87bc6f8f 100644
--- a/test/jitter/vm_mngr.py
+++ b/test/jitter/vm_mngr.py
@@ -1,7 +1,8 @@
+import sys
 from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
 from miasm2.analysis.machine import Machine
 
-myjit = Machine("x86_32").jitter()
+myjit = Machine("x86_32").jitter(sys.argv[1])
 
 base_addr = 0x13371337
 page_size = 0x1000
diff --git a/test/test_all.py b/test/test_all.py
index bec0c78d..59624832 100755
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -325,8 +325,11 @@ for i, test_args in enumerate(test_args):
 ## Jitter
 for script in ["jitload.py",
                "vm_mngr.py",
+               "jit_options.py",
                ]:
-    testset += RegressionTest([script], base_dir="jitter", tags=[TAGS["tcc"]])
+    for engine in ArchUnitTest.jitter_engines:
+        testset += RegressionTest([script, engine], base_dir="jitter",
+                                  tags=[TAGS.get(engine,None)])
 
 
 # Examples