about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2015-02-13 13:03:51 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2015-02-13 14:21:57 +0100
commitef6c6b0b855800375758058863861f28657b5ba7 (patch)
treeb54647a953afbb30b0939d90e9ac256604093b74
parent30d9311a3557cd964ad2524f58cd8574284cb07c (diff)
downloadmiasm-ef6c6b0b855800375758058863861f28657b5ba7.tar.gz
miasm-ef6c6b0b855800375758058863861f28657b5ba7.zip
Test: Add x86 64 mul/div regression test
-rw-r--r--test/samples/x86_64/mul_div.S55
-rw-r--r--test/test_all.py51
2 files changed, 105 insertions, 1 deletions
diff --git a/test/samples/x86_64/mul_div.S b/test/samples/x86_64/mul_div.S
new file mode 100644
index 00000000..4a5fcfdd
--- /dev/null
+++ b/test/samples/x86_64/mul_div.S
@@ -0,0 +1,55 @@
+main:
+	;; MUL
+	MOV RCX, 0x20000002
+	MOV RAX, 0x1122334455667788
+	MOV RDX, RAX
+	MOV RAX, 0x1122334400000020
+	MUL ECX
+	CMP RAX, 0x40
+	JNZ bad
+	CMP RDX, 0x4
+	JNZ bad
+
+	;; IMUL
+	MOV RCX, 0xFFFFFFF2
+	MOV RAX, 0x1122334455667788
+	MOV RDX, RAX
+	MOV RAX, 0x1122334400000020
+	IMUL ECX
+	MOV ESI, 0xFFFFFE40
+	CMP RAX, RSI
+	JNZ bad
+	MOV ESI 0xFFFFFFFF
+	CMP RDX, RSI
+	JNZ bad
+
+	;; DIV
+	MOV RAX, 0x1122334400000002
+	MOV RCX, RAX
+	MOV RAX, 0x1122334400000000
+	MOV RDX, RAX
+	MOV RAX, 0x1122334440000003
+	DIV ECX
+	CMP RAX, 0x20000001
+	JNZ bad
+	CMP RDX, 0x1
+	JNZ bad
+
+	;; IDIV
+	MOV RAX, 0x11223344FFFFFFF2
+	MOV RCX, RAX
+	MOV RAX, 0x11223344FFFFFFFF
+	MOV RDX, RAX
+	MOV RAX, 0x11223344FFFFFFF2
+	IDIV ECX
+	CMP RAX, 0x1
+	JNZ bad
+	CMP RDX, 0x0
+	JNZ bad
+
+
+	RET
+
+bad:
+	INT 0x3
+
diff --git a/test/test_all.py b/test/test_all.py
index 66620375..5f0721fc 100644
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -42,6 +42,56 @@ for script in ["x86/sem.py",
                "mips32/arch.py",
                ]:
     testset += RegressionTest([script], base_dir="arch")
+
+
+## Semantic
+class SemanticTestAsm(RegressionTest):
+    """Assemble an asm file"""
+
+    shellcode_script = os.path.join("example", "asm", "shellcode.py")
+    container_dct = {"PE": "--PE"}
+
+    def __init__(self, arch, container, *args, **kwargs):
+        super(SemanticTestAsm, self).__init__(*args, **kwargs)
+        self.base_dir = os.path.join(self.base_dir, "..")
+        sample_dir = os.path.join("test", "samples", arch)
+        base_filename = os.path.join(sample_dir, self.command_line[0])
+        input_filename = base_filename + ".S"
+        output_filename = base_filename + ".bin"
+        self.command_line = [self.shellcode_script,
+                             arch,
+                             input_filename,
+                             output_filename,
+                             self.container_dct.get(container, '')]
+        self.products = [output_filename, "graph.txt"]
+
+
+class SemanticTestExec(RegressionTest):
+    """Execute a binary file"""
+
+    launcher_dct = {("PE", "x86_64"): "sandbox_pe_x86_64.py"}
+    launcher_base = os.path.join("example", "jitter")
+
+    def __init__(self, arch, container, address, *args, **kwargs):
+        super(SemanticTestExec, self).__init__(*args, **kwargs)
+        self.base_dir = os.path.join(self.base_dir, "..")
+        sample_dir = os.path.join("test", "samples", arch)
+        base_filename = os.path.join(sample_dir, self.command_line[0])
+        input_filename = base_filename + ".bin"
+        launcher = os.path.join(self.launcher_base,
+                                self.launcher_dct[(container, arch)])
+        self.command_line = [launcher,
+                             input_filename,
+                             "-a", hex(address)]
+        self.products = []
+
+
+
+test_x86_64_mul_div = SemanticTestAsm("x86_64", "PE", ["mul_div"])
+testset += test_x86_64_mul_div
+testset += SemanticTestExec("x86_64", "PE", 0x401000, ["mul_div"],
+                            depends=[test_x86_64_mul_div])
+
 ## Core
 for script in ["interval.py",
                "graph.py",
@@ -116,7 +166,6 @@ class ExampleShellcode(ExampleAssembler):
                              self.command_line[3:]
         self.products = [self.command_line[3], "graph.txt"]
 
-
 testset += ExampleShellcode(['x86_32', 'x86_32_manip_ptr.S', "demo_x86_32.bin"])
 
 test_box = {}