diff options
Diffstat (limited to 'test/arch/mep/asm')
| -rw-r--r-- | test/arch/mep/asm/test_asm.py | 20 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_0.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_1.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_10.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_11.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_12.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_13.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_14.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_15.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_2.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_3.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_4.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_5.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_6.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_7.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_8.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/test_major_opcode_9.py | 2 | ||||
| -rw-r--r-- | test/arch/mep/asm/ut_helpers_asm.py | 41 |
18 files changed, 53 insertions, 40 deletions
diff --git a/test/arch/mep/asm/test_asm.py b/test/arch/mep/asm/test_asm.py index ddf91ed6..7762669a 100644 --- a/test/arch/mep/asm/test_asm.py +++ b/test/arch/mep/asm/test_asm.py @@ -1,9 +1,11 @@ # Toshiba MeP-c4 - Misc unit tests # Guillaume Valadon <guillaume@valadon.net> -from miasm2.arch.mep.arch import mn_mep +from __future__ import print_function +from miasm.core.utils import decode_hex, encode_hex +from miasm.arch.mep.arch import mn_mep -class TestMisc: +class TestMisc(object): def test(self): @@ -18,21 +20,23 @@ class TestMisc: unit_tests += [("SW R7, 0x50(SP)", "4752")] for mn_str, mn_hex in unit_tests: - print "-" * 49 # Tests separation + print("-" * 49) # Tests separation # Dissassemble - mn_bin = mn_hex.decode("hex") + mn_bin = decode_hex(mn_hex) mn = mn_mep.dis(mn_bin, "b") - print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + print("dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20))) assert(str(mn) == mn_str) # dissassemble assertion # Assemble and return all possible candidates instr = mn_mep.fromstring(str(mn), "b") instr.mode = "b" - asm_list = [i.encode("hex") for i in mn_mep.asm(instr)] + asm_list = [encode_hex(i).decode() for i in mn_mep.asm(instr)] # Print the results - print "asm: %s -> %s" % (mn_str.rjust(20), - ", ".join(asm_list).rjust(20)) + print("asm: %s -> %s" % ( + mn_str.rjust(20), + ", ".join(asm_list).rjust(20)) + ) assert(mn_hex in asm_list) # assemble assertion diff --git a/test/arch/mep/asm/test_major_opcode_0.py b/test/arch/mep/asm/test_major_opcode_0.py index 69a9685c..db288e47 100644 --- a/test/arch/mep/asm/test_major_opcode_0.py +++ b/test/arch/mep/asm/test_major_opcode_0.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor0: +class TestMajor0(object): def test_MOV(self): """Test the MOV instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_1.py b/test/arch/mep/asm/test_major_opcode_1.py index c401bfd2..3a3c6538 100644 --- a/test/arch/mep/asm/test_major_opcode_1.py +++ b/test/arch/mep/asm/test_major_opcode_1.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor1: +class TestMajor1(object): def test_OR(self): """Test the OR instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_10.py b/test/arch/mep/asm/test_major_opcode_10.py index f1089c61..e10992c8 100644 --- a/test/arch/mep/asm/test_major_opcode_10.py +++ b/test/arch/mep/asm/test_major_opcode_10.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor10: +class TestMajor10(object): def test_BEQZ(self): """Test the BEQZ instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_11.py b/test/arch/mep/asm/test_major_opcode_11.py index b5d8a278..38f93e8b 100644 --- a/test/arch/mep/asm/test_major_opcode_11.py +++ b/test/arch/mep/asm/test_major_opcode_11.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor11: +class TestMajor11(object): def test_BRA(self): """Test the BRA instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_12.py b/test/arch/mep/asm/test_major_opcode_12.py index e721d287..c353861e 100644 --- a/test/arch/mep/asm/test_major_opcode_12.py +++ b/test/arch/mep/asm/test_major_opcode_12.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor12: +class TestMajor12(object): def test_ADD3(self): """Test the ADD3 instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_13.py b/test/arch/mep/asm/test_major_opcode_13.py index 996b47e3..bf95572c 100644 --- a/test/arch/mep/asm/test_major_opcode_13.py +++ b/test/arch/mep/asm/test_major_opcode_13.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor13: +class TestMajor13(object): def test_MOVU(self): """Test the MOVU instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_14.py b/test/arch/mep/asm/test_major_opcode_14.py index 6ad3c757..9ec99550 100644 --- a/test/arch/mep/asm/test_major_opcode_14.py +++ b/test/arch/mep/asm/test_major_opcode_14.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor14: +class TestMajor14(object): def test_BEQI(self): """Test the BEQI instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_15.py b/test/arch/mep/asm/test_major_opcode_15.py index ecad8b3f..891626e8 100644 --- a/test/arch/mep/asm/test_major_opcode_15.py +++ b/test/arch/mep/asm/test_major_opcode_15.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor15: +class TestMajor15(object): def test_DSP(self): """Test the DSP instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_2.py b/test/arch/mep/asm/test_major_opcode_2.py index 07743813..4cbe36ca 100644 --- a/test/arch/mep/asm/test_major_opcode_2.py +++ b/test/arch/mep/asm/test_major_opcode_2.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor2: +class TestMajor2(object): def test_BSETM(self): """Test the BSETM instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_3.py b/test/arch/mep/asm/test_major_opcode_3.py index 3e0c5864..793a4e87 100644 --- a/test/arch/mep/asm/test_major_opcode_3.py +++ b/test/arch/mep/asm/test_major_opcode_3.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor3: +class TestMajor3(object): def test_SWCPI(self): """Test the SWCPI instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_4.py b/test/arch/mep/asm/test_major_opcode_4.py index e52acf3f..a6f57ac2 100644 --- a/test/arch/mep/asm/test_major_opcode_4.py +++ b/test/arch/mep/asm/test_major_opcode_4.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor4: +class TestMajor4(object): def test_ADD3(self): """Test the ADD3 instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_5.py b/test/arch/mep/asm/test_major_opcode_5.py index e39230f4..2250c123 100644 --- a/test/arch/mep/asm/test_major_opcode_5.py +++ b/test/arch/mep/asm/test_major_opcode_5.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor5: +class TestMajor5(object): def test_MOV(self): """Test the MOV instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_6.py b/test/arch/mep/asm/test_major_opcode_6.py index 5eda1ea6..e10d1064 100644 --- a/test/arch/mep/asm/test_major_opcode_6.py +++ b/test/arch/mep/asm/test_major_opcode_6.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor6: +class TestMajor6(object): def test_ADD(self): """Test the ADD instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_7.py b/test/arch/mep/asm/test_major_opcode_7.py index 15a045da..1b1fba78 100644 --- a/test/arch/mep/asm/test_major_opcode_7.py +++ b/test/arch/mep/asm/test_major_opcode_7.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor7: +class TestMajor7(object): def test_DI(self): """Test the DI instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_8.py b/test/arch/mep/asm/test_major_opcode_8.py index 7f15f9e8..900cf004 100644 --- a/test/arch/mep/asm/test_major_opcode_8.py +++ b/test/arch/mep/asm/test_major_opcode_8.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor8: +class TestMajor8(object): def test_SB(self): """Test the SB instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_9.py b/test/arch/mep/asm/test_major_opcode_9.py index b8949887..9e59a863 100644 --- a/test/arch/mep/asm/test_major_opcode_9.py +++ b/test/arch/mep/asm/test_major_opcode_9.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor9: +class TestMajor9(object): def test_ADD3(self): """Test the ADD3 instruction""" diff --git a/test/arch/mep/asm/ut_helpers_asm.py b/test/arch/mep/asm/ut_helpers_asm.py index af010afc..9f6dc5c2 100644 --- a/test/arch/mep/asm/ut_helpers_asm.py +++ b/test/arch/mep/asm/ut_helpers_asm.py @@ -1,17 +1,22 @@ # Toshiba MeP-c4 - unit tests helpers # Guillaume Valadon <guillaume@valadon.net> -from miasm2.arch.mep.arch import mn_mep -from miasm2.core.cpu import Disasm_Exception -from miasm2.core.locationdb import LocationDB -from miasm2.expression.expression import ExprId, ExprInt, ExprLoc +from __future__ import print_function + +from builtins import range + +from miasm.core.utils import decode_hex, encode_hex +from miasm.arch.mep.arch import mn_mep +from miasm.core.cpu import Disasm_Exception +from miasm.core.locationdb import LocationDB +from miasm.expression.expression import ExprId, ExprInt, ExprLoc import re def dis(mn_hex): """Disassembly helper""" - mn_bin = mn_hex.decode("hex") + mn_bin = decode_hex(mn_hex) try: return mn_mep.dis(mn_bin, "b") except Disasm_Exception: @@ -50,7 +55,7 @@ def check_instruction(mn_str, mn_hex, multi=None, offset=0): addr = loc_db.get_location_offset(mn.args[i].loc_key) mn.args[i] = ExprInt(addr, args_size[i]) - print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + print("dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20))) assert(str(mn) == mn_str) # disassemble assertion # Assemble and return all possible candidates @@ -59,21 +64,25 @@ def check_instruction(mn_str, mn_hex, multi=None, offset=0): instr.mode = "b" if instr.offset: instr.fixDstOffset() - asm_list = [i.encode("hex") for i in mn_mep.asm(instr)] + asm_list = [encode_hex(i).decode() for i in mn_mep.asm(instr)] # Check instructions variants if multi: - print "Instructions count:", len(asm_list) + print("Instructions count:", len(asm_list)) assert(len(asm_list) == multi) # Ensure that variants correspond to the same disassembled instruction - for mn_hex in asm_list: - mn = dis(mn_hex) - print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + for mn_hex_tmp in asm_list: + mn = dis(mn_hex_tmp) + print("dis: %s -> %s" % (mn_hex_tmp.rjust(20), str(mn).rjust(20))) # Check the assembly result - print "asm: %s -> %s" % (mn_str.rjust(20), - ", ".join(asm_list).rjust(20)) + print( + "asm: %s -> %s" % ( + mn_str.rjust(20), + ", ".join(asm_list).rjust(20) + ) + ) assert(mn_hex in asm_list) # assemble assertion @@ -83,10 +92,10 @@ def launch_tests(obj): test_methods = [name for name in dir(obj) if name.startswith("test")] for method in test_methods: - print method + print(method) try: getattr(obj, method)() except AttributeError as e: - print "Method not found: %s" % method + print("Method not found: %s" % method) assert(False) - print '-' * 42 + print('-' * 42) |