diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-02-25 11:09:54 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-03-05 16:52:49 +0100 |
| commit | 02bbb30efea4980c9d133947cbbf69fb599071ad (patch) | |
| tree | 3fea6826fcc5354840a27cb1dc99ff31eef81896 /test/arch/mep/asm/ut_helpers_asm.py | |
| parent | eab809932871f91d6f4aa770fc321af9e156e0f5 (diff) | |
| download | miasm-02bbb30efea4980c9d133947cbbf69fb599071ad.tar.gz miasm-02bbb30efea4980c9d133947cbbf69fb599071ad.zip | |
Support python2/python3
Diffstat (limited to 'test/arch/mep/asm/ut_helpers_asm.py')
| -rw-r--r-- | test/arch/mep/asm/ut_helpers_asm.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/test/arch/mep/asm/ut_helpers_asm.py b/test/arch/mep/asm/ut_helpers_asm.py index af010afc..26520787 100644 --- a/test/arch/mep/asm/ut_helpers_asm.py +++ b/test/arch/mep/asm/ut_helpers_asm.py @@ -1,6 +1,11 @@ # Toshiba MeP-c4 - unit tests helpers # Guillaume Valadon <guillaume@valadon.net> +from __future__ import print_function + +from builtins import range + +from miasm2.core.utils import decode_hex, encode_hex from miasm2.arch.mep.arch import mn_mep from miasm2.core.cpu import Disasm_Exception from miasm2.core.locationdb import LocationDB @@ -11,7 +16,7 @@ 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) |