about summary refs log tree commit diff stats
path: root/test/arch/mep/asm/ut_helpers_asm.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/arch/mep/asm/ut_helpers_asm.py')
-rw-r--r--test/arch/mep/asm/ut_helpers_asm.py41
1 files changed, 25 insertions, 16 deletions
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)