about summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/analysis/dg_check.py20
-rw-r--r--test/analysis/dg_test_00_expected.json1
-rw-r--r--test/analysis/dg_test_00_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_01_expected.json1
-rw-r--r--test/analysis/dg_test_01_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_02_expected.json1
-rw-r--r--test/analysis/dg_test_02_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_03_expected.json1
-rw-r--r--test/analysis/dg_test_03_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_04_expected.json1
-rw-r--r--test/analysis/dg_test_04_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_05_expected.json1
-rw-r--r--test/analysis/dg_test_05_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_06_expected.json1
-rw-r--r--test/analysis/dg_test_06_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_07_expected.json1
-rw-r--r--test/analysis/dg_test_07_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_08_expected.json1
-rw-r--r--test/analysis/dg_test_08_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_09_expected.json2
-rw-r--r--test/analysis/dg_test_09_implicit_expected.json1
-rw-r--r--test/analysis/dg_test_10_expected.json1
-rw-r--r--test/analysis/dg_test_10_implicit_expected.json1
-rw-r--r--test/samples/x86_32/dg_test_00.S9
-rw-r--r--test/samples/x86_32/dg_test_01.S9
-rw-r--r--test/samples/x86_32/dg_test_02.S12
-rw-r--r--test/samples/x86_32/dg_test_03.S10
-rw-r--r--test/samples/x86_32/dg_test_04.S10
-rw-r--r--test/samples/x86_32/dg_test_05.S11
-rw-r--r--test/samples/x86_32/dg_test_06.S12
-rw-r--r--test/samples/x86_32/dg_test_07.S10
-rw-r--r--test/samples/x86_32/dg_test_08.S10
-rw-r--r--test/samples/x86_32/dg_test_09.S13
-rw-r--r--test/samples/x86_32/dg_test_10.S20
-rw-r--r--test/test_all.py58
35 files changed, 227 insertions, 0 deletions
diff --git a/test/analysis/dg_check.py b/test/analysis/dg_check.py
new file mode 100644
index 00000000..0d680b6f
--- /dev/null
+++ b/test/analysis/dg_check.py
@@ -0,0 +1,20 @@
+from pdb import pm
+import sys
+import subprocess
+import json
+
+
+expected_file = sys.argv[1]
+dg = subprocess.Popen(["python"] + sys.argv[2:], stdout=subprocess.PIPE)
+
+stdout, _ = dg.communicate()
+expected = json.load(open(expected_file))
+result = json.loads(stdout)
+
+
+expected.sort()
+result.sort()
+
+print expected
+print result
+assert expected == result
diff --git a/test/analysis/dg_test_00_expected.json b/test/analysis/dg_test_00_expected.json
new file mode 100644
index 00000000..cae8b582
--- /dev/null
+++ b/test/analysis/dg_test_00_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x1", "has_loop": false}]
diff --git a/test/analysis/dg_test_00_implicit_expected.json b/test/analysis/dg_test_00_implicit_expected.json
new file mode 100644
index 00000000..186704d0
--- /dev/null
+++ b/test/analysis/dg_test_00_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x1", "satisfiability": true, "constraints": {}}]
diff --git a/test/analysis/dg_test_01_expected.json b/test/analysis/dg_test_01_expected.json
new file mode 100644
index 00000000..724d74a3
--- /dev/null
+++ b/test/analysis/dg_test_01_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x3", "has_loop": false}]
diff --git a/test/analysis/dg_test_01_implicit_expected.json b/test/analysis/dg_test_01_implicit_expected.json
new file mode 100644
index 00000000..2edb5ede
--- /dev/null
+++ b/test/analysis/dg_test_01_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x3", "satisfiability": true, "constraints": {}}]
diff --git a/test/analysis/dg_test_02_expected.json b/test/analysis/dg_test_02_expected.json
new file mode 100644
index 00000000..16d409fb
--- /dev/null
+++ b/test/analysis/dg_test_02_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x3", "has_loop": false}, {"EAX": "0x4", "has_loop": false}]
diff --git a/test/analysis/dg_test_02_implicit_expected.json b/test/analysis/dg_test_02_implicit_expected.json
new file mode 100644
index 00000000..9394f01d
--- /dev/null
+++ b/test/analysis/dg_test_02_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x4", "satisfiability": true, "constraints": {"zf_init": "0x1"}}, {"has_loop": false, "EAX": "0x3", "satisfiability": true, "constraints": {"zf_init": "0x0"}}]
diff --git a/test/analysis/dg_test_03_expected.json b/test/analysis/dg_test_03_expected.json
new file mode 100644
index 00000000..9d0dfdbd
--- /dev/null
+++ b/test/analysis/dg_test_03_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x3", "has_loop": false}, {"EAX": "0x5", "has_loop": true}]
diff --git a/test/analysis/dg_test_03_implicit_expected.json b/test/analysis/dg_test_03_implicit_expected.json
new file mode 100644
index 00000000..9f7ddea0
--- /dev/null
+++ b/test/analysis/dg_test_03_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x3", "satisfiability": false, "constraints": {}}, {"has_loop": true, "EAX": "0x5", "satisfiability": false, "constraints": {}}]
diff --git a/test/analysis/dg_test_04_expected.json b/test/analysis/dg_test_04_expected.json
new file mode 100644
index 00000000..fb115835
--- /dev/null
+++ b/test/analysis/dg_test_04_expected.json
@@ -0,0 +1 @@
+[{"EAX": "EBX_init", "has_loop": false}]
diff --git a/test/analysis/dg_test_04_implicit_expected.json b/test/analysis/dg_test_04_implicit_expected.json
new file mode 100644
index 00000000..73e7209e
--- /dev/null
+++ b/test/analysis/dg_test_04_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "EBX_init", "satisfiability": true, "constraints": {}}, {"has_loop": true, "EAX": "EBX_init", "satisfiability": false, "constraints": {}}]
diff --git a/test/analysis/dg_test_05_expected.json b/test/analysis/dg_test_05_expected.json
new file mode 100644
index 00000000..724d74a3
--- /dev/null
+++ b/test/analysis/dg_test_05_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x3", "has_loop": false}]
diff --git a/test/analysis/dg_test_05_implicit_expected.json b/test/analysis/dg_test_05_implicit_expected.json
new file mode 100644
index 00000000..ef39008f
--- /dev/null
+++ b/test/analysis/dg_test_05_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x3", "satisfiability": true, "constraints": {}}, {"has_loop": true, "EAX": "0x3", "satisfiability": false, "constraints": {}}]
diff --git a/test/analysis/dg_test_06_expected.json b/test/analysis/dg_test_06_expected.json
new file mode 100644
index 00000000..7d823131
--- /dev/null
+++ b/test/analysis/dg_test_06_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x1", "has_loop": false}, {"EAX": "0x2", "has_loop": true}]
diff --git a/test/analysis/dg_test_06_implicit_expected.json b/test/analysis/dg_test_06_implicit_expected.json
new file mode 100644
index 00000000..050915c1
--- /dev/null
+++ b/test/analysis/dg_test_06_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x1", "satisfiability": true, "constraints": {"EAX_init": "0xffffffff"}}, {"has_loop": true, "EAX": "0x2", "satisfiability": false, "constraints": {}}]
diff --git a/test/analysis/dg_test_07_expected.json b/test/analysis/dg_test_07_expected.json
new file mode 100644
index 00000000..0ed0be95
--- /dev/null
+++ b/test/analysis/dg_test_07_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x1", "ECX": "0x2", "has_loop": false}]
diff --git a/test/analysis/dg_test_07_implicit_expected.json b/test/analysis/dg_test_07_implicit_expected.json
new file mode 100644
index 00000000..4f8c782a
--- /dev/null
+++ b/test/analysis/dg_test_07_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x1", "constraints": {}, "satisfiability": true, "ECX": "0x2"}]
diff --git a/test/analysis/dg_test_08_expected.json b/test/analysis/dg_test_08_expected.json
new file mode 100644
index 00000000..b4c379d1
--- /dev/null
+++ b/test/analysis/dg_test_08_expected.json
@@ -0,0 +1 @@
+[{"ECX": "0x2", "has_loop": false}]
diff --git a/test/analysis/dg_test_08_implicit_expected.json b/test/analysis/dg_test_08_implicit_expected.json
new file mode 100644
index 00000000..a0416a4e
--- /dev/null
+++ b/test/analysis/dg_test_08_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "constraints": {}, "satisfiability": true, "ECX": "0x2"}]
diff --git a/test/analysis/dg_test_09_expected.json b/test/analysis/dg_test_09_expected.json
new file mode 100644
index 00000000..ba0e4673
--- /dev/null
+++ b/test/analysis/dg_test_09_expected.json
@@ -0,0 +1,2 @@
+[{"EAX": "0x1", "EBX": "0x2", "has_loop": false},
+ {"EAX": "0x3", "EBX": "0x4", "has_loop": false}]
diff --git a/test/analysis/dg_test_09_implicit_expected.json b/test/analysis/dg_test_09_implicit_expected.json
new file mode 100644
index 00000000..1ea2976f
--- /dev/null
+++ b/test/analysis/dg_test_09_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x1", "EBX": "0x2", "satisfiability": true, "constraints": {}}, {"has_loop": false, "EAX": "0x3", "EBX": "0x4", "satisfiability": true, "constraints": {}}]
diff --git a/test/analysis/dg_test_10_expected.json b/test/analysis/dg_test_10_expected.json
new file mode 100644
index 00000000..720b85e2
--- /dev/null
+++ b/test/analysis/dg_test_10_expected.json
@@ -0,0 +1 @@
+[{"EAX": "0x1", "EBX": "0x3", "has_loop": false}, {"EAX": "0x1", "EBX": "0x4", "has_loop": false}, {"EAX": "0x2", "EBX": "0x4", "has_loop": false}, {"EAX": "0x2", "EBX": "0x3", "has_loop": false}]
diff --git a/test/analysis/dg_test_10_implicit_expected.json b/test/analysis/dg_test_10_implicit_expected.json
new file mode 100644
index 00000000..05b34918
--- /dev/null
+++ b/test/analysis/dg_test_10_implicit_expected.json
@@ -0,0 +1 @@
+[{"has_loop": false, "EAX": "0x1", "EBX": "0x3", "satisfiability": true, "constraints": {"zf_init": "0x0"}}, {"has_loop": false, "EAX": "0x2", "EBX": "0x3", "satisfiability": false, "constraints": {}}, {"has_loop": false, "EAX": "0x1", "EBX": "0x4", "satisfiability": false, "constraints": {}}, {"has_loop": false, "EAX": "0x2", "EBX": "0x4", "satisfiability": true, "constraints": {"zf_init": "0x1"}}]
diff --git a/test/samples/x86_32/dg_test_00.S b/test/samples/x86_32/dg_test_00.S
new file mode 100644
index 00000000..dc9ef665
--- /dev/null
+++ b/test/samples/x86_32/dg_test_00.S
@@ -0,0 +1,9 @@
+main:
+	MOV ECX, 0x1
+	JMP lbl1
+lbl1:
+	MOV EBX, ECX
+	JMP lbl2
+lbl2:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_01.S b/test/samples/x86_32/dg_test_01.S
new file mode 100644
index 00000000..4f4ff80d
--- /dev/null
+++ b/test/samples/x86_32/dg_test_01.S
@@ -0,0 +1,9 @@
+main:
+	MOV ECX, 0x1
+	JMP lbl1
+lbl1:
+	MOV EBX, 0x2
+	JMP lbl2
+lbl2:
+	LEA EAX, DWORD PTR [EBX + ECX]
+	RET
diff --git a/test/samples/x86_32/dg_test_02.S b/test/samples/x86_32/dg_test_02.S
new file mode 100644
index 00000000..164dd90a
--- /dev/null
+++ b/test/samples/x86_32/dg_test_02.S
@@ -0,0 +1,12 @@
+main:
+	MOV ECX, 0x1
+	JZ lbl2
+lbl1:
+	MOV EBX, 0x2
+	JMP end
+lbl2:
+	MOV EBX, 0x3
+	JMP end
+end:
+	LEA EAX, DWORD PTR [EBX + ECX]
+	RET
diff --git a/test/samples/x86_32/dg_test_03.S b/test/samples/x86_32/dg_test_03.S
new file mode 100644
index 00000000..ac0edc56
--- /dev/null
+++ b/test/samples/x86_32/dg_test_03.S
@@ -0,0 +1,10 @@
+main:
+	MOV EBX, 0x1
+	JMP lbl1
+lbl1:
+	ADD EBX, 0x2
+	CMP EBX, 0x0
+	JNZ lbl1
+end:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_04.S b/test/samples/x86_32/dg_test_04.S
new file mode 100644
index 00000000..393430ed
--- /dev/null
+++ b/test/samples/x86_32/dg_test_04.S
@@ -0,0 +1,10 @@
+main:
+	MOV ECX, 0x1
+	JMP lbl1
+lbl1:
+	ADD ECX, 0x2
+	CMP ECX, 0x0
+	JZ lbl1
+end:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_05.S b/test/samples/x86_32/dg_test_05.S
new file mode 100644
index 00000000..336ee3f5
--- /dev/null
+++ b/test/samples/x86_32/dg_test_05.S
@@ -0,0 +1,11 @@
+main:
+	MOV ECX, 0x1
+	MOV EBX, 0x3
+	JMP lbl1
+lbl1:
+	ADD ECX, 0x2
+	CMP ECX, 0x0
+	JZ lbl1
+end:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_06.S b/test/samples/x86_32/dg_test_06.S
new file mode 100644
index 00000000..e12766f2
--- /dev/null
+++ b/test/samples/x86_32/dg_test_06.S
@@ -0,0 +1,12 @@
+main:
+	MOV ECX, 0x1
+	MOV EDX, 0x2
+	JMP lbl1
+lbl1:
+	MOV EBX, ECX
+	MOV ECX, EDX
+	CMP EAX, 0x0
+	JZ lbl1
+end:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_07.S b/test/samples/x86_32/dg_test_07.S
new file mode 100644
index 00000000..a23d5b66
--- /dev/null
+++ b/test/samples/x86_32/dg_test_07.S
@@ -0,0 +1,10 @@
+main:
+	MOV ECX, 0x1
+	MOV EBX, 0x2
+	JMP lbl1
+lbl1:
+	XCHG EBX, ECX
+	JMP end
+end:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_08.S b/test/samples/x86_32/dg_test_08.S
new file mode 100644
index 00000000..a23d5b66
--- /dev/null
+++ b/test/samples/x86_32/dg_test_08.S
@@ -0,0 +1,10 @@
+main:
+	MOV ECX, 0x1
+	MOV EBX, 0x2
+	JMP lbl1
+lbl1:
+	XCHG EBX, ECX
+	JMP end
+end:
+	MOV EAX, EBX
+	RET
diff --git a/test/samples/x86_32/dg_test_09.S b/test/samples/x86_32/dg_test_09.S
new file mode 100644
index 00000000..d4d053f5
--- /dev/null
+++ b/test/samples/x86_32/dg_test_09.S
@@ -0,0 +1,13 @@
+main:
+	MOV ECX, 0x8
+	JZ lbl2
+lbl1:
+	MOV EAX, 0x1
+	MOV EBX, 0x2
+	JMP end
+lbl2:
+	MOV EAX, 0x3
+	MOV EBX, 0x4
+	JMP end
+end:
+	RET
diff --git a/test/samples/x86_32/dg_test_10.S b/test/samples/x86_32/dg_test_10.S
new file mode 100644
index 00000000..5825da67
--- /dev/null
+++ b/test/samples/x86_32/dg_test_10.S
@@ -0,0 +1,20 @@
+main:
+	MOV ECX, 0x8
+	JZ lbl2
+lbl1:
+	MOV EAX, 0x1
+	JMP end1
+lbl2:
+	MOV EAX, 0x2
+	JMP end1
+end1:
+	JZ lbl4
+lbl3:
+	MOV EBX, 0x3
+	JMP end
+lbl4:
+	MOV EBX, 0x4
+	JMP end
+
+end:
+	RET
diff --git a/test/test_all.py b/test/test_all.py
index 9a202442..d633d85c 100644
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -22,11 +22,19 @@ class RegressionTest(Test):
     - @base_dir: test/@base_dir
     - @tags: TAGS["regression"]"""
 
+    sample_dir = os.path.join("..", "samples")
+
     def __init__(self, *args, **kwargs):
         super(RegressionTest, self).__init__(*args, **kwargs)
         self.base_dir = os.path.join("test", self.base_dir)
         self.tags.append(TAGS["regression"])
 
+    @classmethod
+    def get_sample(cls, sample_name):
+        "Return the relative path of @sample_name"
+        return os.path.join(cls.sample_dir, sample_name)
+
+
 ## Architecture
 testset += RegressionTest(["x86/arch.py"], base_dir="arch",
                           products=["x86_speed_reg_test.bin",
@@ -242,6 +250,56 @@ testset += RegressionTest(["depgraph.py"], base_dir="analysis",
                                                         (14, 1), (15, 1)))
                            for fname in fnames])
 
+## Degraph
+class TestDepgraph(RegressionTest):
+    """Dependency graph test"""
+    example_depgraph = os.path.join("..", "..", "example", "symbol_exec",
+                                    "depgraph.py")
+    launcher = "dg_check.py"
+
+
+    def __init__(self, test_nb, implicit, base_addr, target_addr, elements,
+                 *args, **kwargs):
+        super(TestDepgraph, self).__init__([self.launcher],
+                                           *args, **kwargs)
+        self.base_dir = os.path.join(self.base_dir, "analysis")
+        if implicit:
+            expected_fname = "dg_test_%.2d_implicit_expected.json"
+            self.tags.append(TAGS["z3"])
+        else:
+            expected_fname = "dg_test_%.2d_expected.json"
+
+        self.command_line += [
+            expected_fname % test_nb,
+            self.example_depgraph,
+            "-m", "x86_32",
+            "--json",
+            self.get_sample(os.path.join("x86_32",
+                                         "dg_test_%.2d.bin" % test_nb)),
+            hex(base_addr),
+            hex(target_addr)] + elements
+        if implicit:
+            self.command_line.append("-i")
+
+# Depgraph emulation regression test
+test_args = [(0x401000, 0x40100d, ["EAX"]),
+             (0x401000, 0x401011, ["EAX"]),
+             (0x401000, 0x401018, ["EAX"]),
+             (0x401000, 0x401011, ["EAX"]),
+             (0x401000, 0x401011, ["EAX"]),
+             (0x401000, 0x401016, ["EAX"]),
+             (0x401000, 0x401017, ["EAX"]),
+             (0x401000, 0x401012, ["EAX", "ECX"]),
+             (0x401000, 0x401012, ["ECX"]),
+             (0x401000, 0x40101f, ["EAX", "EBX"]),
+             (0x401000, 0x401025, ["EAX", "EBX"]),
+]
+for i, test_args in enumerate(test_args):
+    test_dg = SemanticTestAsm("x86_32", "PE", ["dg_test_%.2d" % i])
+    testset += test_dg
+    testset += TestDepgraph(i, False, *test_args, depends=[test_dg])
+    testset += TestDepgraph(i, True, *test_args, depends=[test_dg])
+
 ## Jitter
 for script in ["jitload.py",
                ]: