about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2016-04-17 22:23:35 +0200
committerserpilliere <fabrice.desclaux@cea.fr>2016-04-18 20:37:22 +0200
commitc7478b7e2b98bc9a7c9198d1393732bae16341c5 (patch)
treee9410b270be21284b953fc055e91b4ea18a2c702
parent23879d0d8325e5c1ba144923d815cda639903415 (diff)
downloadmiasm-c7478b7e2b98bc9a7c9198d1393732bae16341c5.tar.gz
miasm-c7478b7e2b98bc9a7c9198d1393732bae16341c5.zip
X86/test: updt test api
-rw-r--r--test/arch/x86/unit/asm_test.py59
-rw-r--r--test/arch/x86/unit/mn_daa.py4
-rw-r--r--test/arch/x86/unit/mn_das.py4
-rw-r--r--test/arch/x86/unit/mn_float.py4
-rw-r--r--test/arch/x86/unit/mn_int.py4
-rw-r--r--test/arch/x86/unit/mn_pcmpeq.py8
-rw-r--r--test/arch/x86/unit/mn_pextr.py4
-rw-r--r--test/arch/x86/unit/mn_pinsr.py4
-rw-r--r--test/arch/x86/unit/mn_pmaxu.py4
-rw-r--r--test/arch/x86/unit/mn_pminu.py4
-rw-r--r--test/arch/x86/unit/mn_pmovmskb.py4
-rw-r--r--test/arch/x86/unit/mn_pshufb.py4
-rw-r--r--test/arch/x86/unit/mn_psrl_psll.py6
-rw-r--r--test/arch/x86/unit/mn_punpck.py14
-rw-r--r--test/arch/x86/unit/mn_stack.py4
-rw-r--r--test/arch/x86/unit/mn_strings.py6
16 files changed, 86 insertions, 51 deletions
diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py
index bf609aa5..118a57b4 100644
--- a/test/arch/x86/unit/asm_test.py
+++ b/test/arch/x86/unit/asm_test.py
@@ -21,22 +21,38 @@ if filename and os.path.isfile(filename):
 reg_and_id = dict(mn_x86.regs.all_regs_ids_byname)
 
 class Asm_Test(object):
+    run_addr = 0x0
+
     def __init__(self):
-        self.myjit = Machine("x86_32").jitter()
+        self.myjit = Machine(self.arch_name).jitter()
         self.myjit.init_stack()
 
         self.myjit.jit.log_regs = False
         self.myjit.jit.log_mn = False
 
+    def test_init(self):
+        pass
+
+    def prepare(self):
+        pass
 
     def __call__(self):
+        self.prepare()
         self.asm()
+        self.init_machine()
+        self.test_init()
         self.run()
         self.check()
 
+    def run(self):
+
+        self.myjit.init_run(self.run_addr)
+        self.myjit.continue_run()
+
+        assert(self.myjit.pc == self.ret_addr)
 
     def asm(self):
-        blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, self.TXT,
+        blocs, symbol_pool = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT,
                                                  symbol_pool = self.myjit.ir_arch.symbol_pool)
         # fix shellcode addr
         symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0)
@@ -48,18 +64,37 @@ class Asm_Test(object):
         s = str(s)
         self.assembly = s
 
-    def run(self):
-        run_addr = 0
-        self.myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
+    def check(self):
+        raise NotImplementedError('abstract method')
 
-        self.myjit.push_uint32_t(0x1337beef)
 
-        self.myjit.add_breakpoint(0x1337beef, lambda x:False)
+class Asm_Test_32(Asm_Test):
+    arch_name = "x86_32"
+    arch_attrib = 32
+    ret_addr = 0x1337beef
 
-        self.myjit.init_run(run_addr)
-        self.myjit.continue_run()
+    def init_machine(self):
+        self.myjit.vm.add_memory_page(self.run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
+        self.myjit.push_uint32_t(self.ret_addr)
+        self.myjit.add_breakpoint(self.ret_addr, lambda x:False)
 
-        assert(self.myjit.pc == 0x1337beef)
 
-    def check(self):
-        raise NotImplementedError('abstract method')
+class Asm_Test_16(Asm_Test):
+    arch_name = "x86_16"
+    arch_attrib = 16
+    ret_addr = 0x1337
+
+    def __init__(self):
+        self.myjit = Machine(self.arch_name).jitter()
+        self.myjit.stack_base = 0x1000
+        self.myjit.stack_size = 0x1000
+        self.myjit.init_stack()
+
+        self.myjit.jit.log_regs = False
+        self.myjit.jit.log_mn = False
+
+
+    def init_machine(self):
+        self.myjit.vm.add_memory_page(self.run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
+        self.myjit.push_uint16_t(self.ret_addr)
+        self.myjit.add_breakpoint(self.ret_addr, lambda x:False)
diff --git a/test/arch/x86/unit/mn_daa.py b/test/arch/x86/unit/mn_daa.py
index cb96a22b..7aadf582 100644
--- a/test/arch/x86/unit/mn_daa.py
+++ b/test/arch/x86/unit/mn_daa.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 
 
-class Test_DAA(Asm_Test):
+class Test_DAA(Asm_Test_32):
     TXT = '''
     main:
        MOV     EBP, ESP
diff --git a/test/arch/x86/unit/mn_das.py b/test/arch/x86/unit/mn_das.py
index ba84abdd..0828cafe 100644
--- a/test/arch/x86/unit/mn_das.py
+++ b/test/arch/x86/unit/mn_das.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 
 
-class Test_DAS(Asm_Test):
+class Test_DAS(Asm_Test_32):
     TXT = '''
     main:
        MOV     EBP, ESP
diff --git a/test/arch/x86/unit/mn_float.py b/test/arch/x86/unit/mn_float.py
index 863e86c3..81eb518b 100644
--- a/test/arch/x86/unit/mn_float.py
+++ b/test/arch/x86/unit/mn_float.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 
 
-class Test_FADD(Asm_Test):
+class Test_FADD(Asm_Test_32):
     TXT = '''
     main:
        ; test float
diff --git a/test/arch/x86/unit/mn_int.py b/test/arch/x86/unit/mn_int.py
index 119e5b08..0f4a5717 100644
--- a/test/arch/x86/unit/mn_int.py
+++ b/test/arch/x86/unit/mn_int.py
@@ -1,9 +1,9 @@
 #! /usr/bin/env python
 from miasm2.jitter.csts import EXCEPT_INT_XX
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 
 
-class Test_INT(Asm_Test):
+class Test_INT(Asm_Test_32):
     TXT = '''
     main:
        INT 0x42
diff --git a/test/arch/x86/unit/mn_pcmpeq.py b/test/arch/x86/unit/mn_pcmpeq.py
index a8774cbc..06815e76 100644
--- a/test/arch/x86/unit/mn_pcmpeq.py
+++ b/test/arch/x86/unit/mn_pcmpeq.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PCMPEQB(Asm_Test):
+class Test_PCMPEQB(Asm_Test_32):
     TXT = '''
     main:
        CALL    next
@@ -21,7 +21,7 @@ class Test_PCMPEQB(Asm_Test):
         assert self.myjit.cpu.MM1 == 0xFF00000000FF0000
 
 
-class Test_PCMPEQW(Asm_Test):
+class Test_PCMPEQW(Asm_Test_32):
     TXT = '''
     main:
        CALL    next
@@ -41,7 +41,7 @@ class Test_PCMPEQW(Asm_Test):
 
 
 
-class Test_PCMPEQD(Asm_Test):
+class Test_PCMPEQD(Asm_Test_32):
     TXT = '''
     main:
        CALL    next
diff --git a/test/arch/x86/unit/mn_pextr.py b/test/arch/x86/unit/mn_pextr.py
index eb724cf9..0469eed7 100644
--- a/test/arch/x86/unit/mn_pextr.py
+++ b/test/arch/x86/unit/mn_pextr.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PEXTRB(Asm_Test):
+class Test_PEXTRB(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
diff --git a/test/arch/x86/unit/mn_pinsr.py b/test/arch/x86/unit/mn_pinsr.py
index b7a86d2d..a10cd286 100644
--- a/test/arch/x86/unit/mn_pinsr.py
+++ b/test/arch/x86/unit/mn_pinsr.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PINSRB(Asm_Test):
+class Test_PINSRB(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
diff --git a/test/arch/x86/unit/mn_pmaxu.py b/test/arch/x86/unit/mn_pmaxu.py
index 08e54c03..50cbff94 100644
--- a/test/arch/x86/unit/mn_pmaxu.py
+++ b/test/arch/x86/unit/mn_pmaxu.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PMAXU(Asm_Test):
+class Test_PMAXU(Asm_Test_32):
     TXT = '''
     main:
        CALL   next
diff --git a/test/arch/x86/unit/mn_pminu.py b/test/arch/x86/unit/mn_pminu.py
index 38a29787..27c9ad1e 100644
--- a/test/arch/x86/unit/mn_pminu.py
+++ b/test/arch/x86/unit/mn_pminu.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PMINU(Asm_Test):
+class Test_PMINU(Asm_Test_32):
     TXT = '''
     main:
        CALL   next
diff --git a/test/arch/x86/unit/mn_pmovmskb.py b/test/arch/x86/unit/mn_pmovmskb.py
index 97435794..796e977c 100644
--- a/test/arch/x86/unit/mn_pmovmskb.py
+++ b/test/arch/x86/unit/mn_pmovmskb.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PMOVMSKB(Asm_Test):
+class Test_PMOVMSKB(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
diff --git a/test/arch/x86/unit/mn_pshufb.py b/test/arch/x86/unit/mn_pshufb.py
index 187b2f72..594b0870 100644
--- a/test/arch/x86/unit/mn_pshufb.py
+++ b/test/arch/x86/unit/mn_pshufb.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PSHUFB(Asm_Test):
+class Test_PSHUFB(Asm_Test_32):
     TXT = '''
     main:
        CALL   next
diff --git a/test/arch/x86/unit/mn_psrl_psll.py b/test/arch/x86/unit/mn_psrl_psll.py
index 93a356f7..79125612 100644
--- a/test/arch/x86/unit/mn_psrl_psll.py
+++ b/test/arch/x86/unit/mn_psrl_psll.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PSRL(Asm_Test):
+class Test_PSRL(Asm_Test_32):
     TXT = '''
     main:
        CALL   next
@@ -26,7 +26,7 @@ class Test_PSRL(Asm_Test):
         assert self.myjit.cpu.MM2 == 0x0112233405566778L
         assert self.myjit.cpu.MM3 == 0x0112233445566778L
 
-class Test_PSLL(Asm_Test):
+class Test_PSLL(Asm_Test_32):
     TXT = '''
     main:
        CALL   next
diff --git a/test/arch/x86/unit/mn_punpck.py b/test/arch/x86/unit/mn_punpck.py
index 84d86c32..8b655aa0 100644
--- a/test/arch/x86/unit/mn_punpck.py
+++ b/test/arch/x86/unit/mn_punpck.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 import sys
 
-class Test_PUNPCKHBW(Asm_Test):
+class Test_PUNPCKHBW(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
@@ -21,7 +21,7 @@ class Test_PUNPCKHBW(Asm_Test):
         assert self.myjit.cpu.MM1 == 0xAA11BB22CC33DD44
 
 
-class Test_PUNPCKHWD(Asm_Test):
+class Test_PUNPCKHWD(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
@@ -41,7 +41,7 @@ class Test_PUNPCKHWD(Asm_Test):
 
 
 
-class Test_PUNPCKHDQ(Asm_Test):
+class Test_PUNPCKHDQ(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
@@ -62,7 +62,7 @@ class Test_PUNPCKHDQ(Asm_Test):
 
 
 
-class Test_PUNPCKLBW(Asm_Test):
+class Test_PUNPCKLBW(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
@@ -81,7 +81,7 @@ class Test_PUNPCKLBW(Asm_Test):
         assert self.myjit.cpu.MM1 == 0xEE55FF6602770188
 
 
-class Test_PUNPCKLWD(Asm_Test):
+class Test_PUNPCKLWD(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
@@ -101,7 +101,7 @@ class Test_PUNPCKLWD(Asm_Test):
 
 
 
-class Test_PUNPCKLDQ(Asm_Test):
+class Test_PUNPCKLDQ(Asm_Test_32):
     TXT = '''
     main:
        CALL      next
diff --git a/test/arch/x86/unit/mn_stack.py b/test/arch/x86/unit/mn_stack.py
index dd349d54..6ae26d67 100644
--- a/test/arch/x86/unit/mn_stack.py
+++ b/test/arch/x86/unit/mn_stack.py
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 
 
-class Test_PUSHPOP(Asm_Test):
+class Test_PUSHPOP(Asm_Test_32):
     TXT = '''
     main:
        MOV     EBP, ESP
diff --git a/test/arch/x86/unit/mn_strings.py b/test/arch/x86/unit/mn_strings.py
index db52fa74..f8055665 100644
--- a/test/arch/x86/unit/mn_strings.py
+++ b/test/arch/x86/unit/mn_strings.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
-from asm_test import Asm_Test
+from asm_test import Asm_Test_32
 
-class Test_SCAS(Asm_Test):
+class Test_SCAS(Asm_Test_32):
     MYSTRING = "test string"
     TXT = '''
     main:
@@ -22,7 +22,7 @@ class Test_SCAS(Asm_Test):
         assert(self.myjit.cpu.EDI == self.myjit.ir_arch.symbol_pool.getby_name('mystr').offset + len(self.MYSTRING)+1)
 
 
-class Test_MOVS(Asm_Test):
+class Test_MOVS(Asm_Test_32):
     MYSTRING = "test string"
     TXT = '''
     main: