about summary refs log tree commit diff stats
path: root/test/expression
diff options
context:
space:
mode:
Diffstat (limited to 'test/expression')
-rw-r--r--test/expression/expr_pickle.py15
-rw-r--r--test/expression/expression.py15
-rwxr-xr-xtest/expression/expression_helper.py15
-rw-r--r--test/expression/modint.py31
-rw-r--r--test/expression/parser.py3
-rw-r--r--test/expression/simplifications.py57
-rwxr-xr-xtest/expression/stp.py5
7 files changed, 75 insertions, 66 deletions
diff --git a/test/expression/expr_pickle.py b/test/expression/expr_pickle.py
index 870f761a..16b87db7 100644
--- a/test/expression/expr_pickle.py
+++ b/test/expression/expr_pickle.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 import pickle
 from miasm2.expression.expression import ExprInt, ExprAssign, ExprId, \
     Expr, ExprCompose, ExprMem
@@ -12,15 +13,15 @@ f = a[:8]
 aff = ExprAssign(a, b)
 
 
-print 'Pickling'
+print('Pickling')
 out = pickle.dumps((a, b, c, d, e, f, aff))
-print 'Unpickling'
+print('Unpickling')
 new_a, new_b, new_c, new_d, new_e, new_f, new_aff = pickle.loads(out)
-print 'Result'
-print a, b, c, aff
-print id(a), id(b), id(c), id(d), id(e), id(f), id(aff)
-print new_a, new_b, new_c, new_d, new_e, new_f, new_aff
-print id(new_a), id(new_b), id(new_c), id(new_d), id(new_e), id(new_f), id(new_aff)
+print('Result')
+print(a, b, c, aff)
+print(id(a), id(b), id(c), id(d), id(e), id(f), id(aff))
+print(new_a, new_b, new_c, new_d, new_e, new_f, new_aff)
+print(id(new_a), id(new_b), id(new_c), id(new_d), id(new_e), id(new_f), id(new_aff))
 
 assert a == new_a
 assert b == new_b
diff --git a/test/expression/expression.py b/test/expression/expression.py
index 1b39ab9f..b8a2642a 100644
--- a/test/expression/expression.py
+++ b/test/expression/expression.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 #
 # Expression regression tests  #
 #
@@ -42,15 +43,15 @@ for expr in [
                     ExprCond(cond2, cst3, cst4)),
         ExprCond(ExprCond(cond1, cst1, cst2), cst3, cst4),
 ]:
-    print "*" * 80
-    print expr
+    print("*" * 80)
+    print(expr)
     sol = possible_values(expr)
-    print sol
-    print "Resulting constraints:"
+    print(sol)
+    print("Resulting constraints:")
     for consval in sol:
-        print "For value %s" % consval.value
+        print("For value %s" % consval.value)
         for constraint in consval.constraints:
-            print "\t%s" % constraint.to_constraint()
+            print("\t%s" % constraint.to_constraint())
 
 # Repr
 for expr in [
@@ -63,7 +64,7 @@ for expr in [
         A.msb(),
         ExprAssign(A, cst1),
 ]:
-    print repr(expr)
+    print(repr(expr))
     assert expr == eval(repr(expr))
 
 
diff --git a/test/expression/expression_helper.py b/test/expression/expression_helper.py
index 35873ca4..6c6fb2a9 100755
--- a/test/expression/expression_helper.py
+++ b/test/expression/expression_helper.py
@@ -1,6 +1,9 @@
 #! /usr/bin/env python2
 #-*- coding:utf-8 -*-
 
+from __future__ import print_function
+
+from future.utils import viewitems
 import unittest
 
 
@@ -25,13 +28,13 @@ class TestExpressionExpressionHelper(unittest.TestCase):
         vi = Variables_Identifier(exprf)
 
         # Use __str__
-        print vi
+        print(vi)
 
         # Test the result
         new_expr = vi.equation
 
         ## Force replace in the variable dependency order
-        for var_id, var_value in reversed(vi.vars.items()):
+        for var_id, var_value in reversed(list(viewitems(vi.vars))):
             new_expr = new_expr.replace_expr({var_id: var_value})
         self.assertEqual(exprf, new_expr)
 
@@ -39,12 +42,12 @@ class TestExpressionExpressionHelper(unittest.TestCase):
         vi = Variables_Identifier(exprf, var_prefix="prefix_v")
 
         ## Use __str__
-        print vi
+        print(vi)
 
         ## Test the result
         new_expr = vi.equation
         ### Force replace in the variable dependency order
-        for var_id, var_value in reversed(vi.vars.items()):
+        for var_id, var_value in reversed(list(viewitems(vi.vars))):
             new_expr = new_expr.replace_expr({var_id: var_value})
         self.assertEqual(exprf, new_expr)
 
@@ -55,7 +58,7 @@ class TestExpressionExpressionHelper(unittest.TestCase):
         ## Test the result
         new_expr = vi2.equation
         ### Force replace in the variable dependency order
-        for var_id, var_value in reversed(vi2.vars.items()):
+        for var_id, var_value in reversed(list(viewitems(vi2.vars))):
             new_expr = new_expr.replace_expr({var_id: var_value})
         self.assertEqual(vi.equation, new_expr)
 
@@ -72,7 +75,7 @@ class TestExpressionExpressionHelper(unittest.TestCase):
         ## Test the result
         new_expr = vi2.equation
         ### Force replace in the variable dependency order
-        for var_id, var_value in reversed(vi2.vars.items()):
+        for var_id, var_value in reversed(list(viewitems(vi2.vars))):
             new_expr = new_expr.replace_expr({var_id: var_value})
         self.assertEqual(vi.equation, new_expr)
 
diff --git a/test/expression/modint.py b/test/expression/modint.py
index 17c12907..a833ee80 100644
--- a/test/expression/modint.py
+++ b/test/expression/modint.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from miasm2.expression.modint import *
 
 a = uint8(0x42)
@@ -10,12 +11,12 @@ e = uint1(1)
 f = uint8(0x1)
 g = int8(-3)
 
-print a, b, c
-print a + b, a + c, b + c
-print a == a, a == b, a == 0x42, a == 0x78
-print a != b, a != a
-print d, e
-print d + e, d + d, e + e, e + e + e, e + 0x11
+print(a, b, c)
+print(a + b, a + c, b + c)
+print(a == a, a == b, a == 0x42, a == 0x78)
+print(a != b, a != a)
+print(d, e)
+print(d + e, d + d, e + e, e + e + e, e + 0x11)
 
 assert(f == 1)
 assert(f + 1 == 2)
@@ -24,10 +25,10 @@ assert(f + 0xff == 0)
 assert(f & 0 == 0)
 assert(f & 0xff == f)
 assert(0xff & f == f)
-assert(f / 1 == f)
-assert(1 / f == f)
+assert(f // 1 == f)
+assert(1 // f == f)
+assert(int(f) == 1)
 assert(int(f) == 1)
-assert(long(f) == 1)
 assert(~f == 0xfe)
 assert(f << 1 == 2)
 assert(f << 8 == 0)
@@ -53,20 +54,20 @@ assert(f ^ f == 0)
 assert(f ^ 0 == f)
 assert(0 ^ f == f)
 assert(1 ^ f == 0)
-assert(c / g == -1)
-assert(c / -3 == -1)
+assert(c // g == -1)
+assert(c // -3 == -1)
 assert(c % g == 1)
 assert(c % -3 == 1)
 
-print e + c, c + e, c - e, e - c
-print 1000 * a
-print hex(a)
+print(e + c, c + e, c - e, e - c)
+print(1000 * a)
+print(hex(a))
 
 define_int(128)
 define_uint(128)
 h = uint128(0x11223344556677889900AABBCCDDEEFF)
 i = int128(-0x9900AABBCCDDEEFF1122334455667788)
 
-assert(i / h == 6)
+assert(i //h == 6)
 assert(i % h == 0x3221aa32bb43cd58d9cc54dd65ee7e)
 
diff --git a/test/expression/parser.py b/test/expression/parser.py
index ccae49b0..d05f8262 100644
--- a/test/expression/parser.py
+++ b/test/expression/parser.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from miasm2.expression.parser import str_to_expr
 from miasm2.expression.expression import ExprInt, ExprId, ExprSlice, ExprMem, \
     ExprCond, ExprCompose, ExprOp, ExprAssign, ExprLoc, LocKey
@@ -13,5 +14,5 @@ for expr_test in [ExprInt(0x12, 32),
                   ExprAssign(ExprId('EAX', 32),  ExprInt(0x12, 32)),
                   ]:
 
-    print 'Test: %s' % expr_test
+    print('Test: %s' % expr_test)
     assert str_to_expr(repr(expr_test)) == expr_test
diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py
index cc33fc54..ae9eb1c0 100644
--- a/test/expression/simplifications.py
+++ b/test/expression/simplifications.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 #
 # Expression simplification regression tests  #
 #
@@ -28,18 +29,18 @@ if args.z3:
 
     def check(expr_in, expr_out):
         """Check that expr_in is always equals to expr_out"""
-        print "Ensure %s = %s" % (expr_in, expr_out)
+        print("Ensure %s = %s" % (expr_in, expr_out))
         solver = z3.Solver()
         solver.add(trans.from_expr(expr_in) != trans.from_expr(expr_out))
 
         result = solver.check()
 
         if result != z3.unsat:
-            print "ERROR: a counter-example has been founded:"
+            print("ERROR: a counter-example has been founded:")
             model = solver.model()
-            print model
+            print(model)
 
-            print "Reinjecting in the simplifier:"
+            print("Reinjecting in the simplifier:")
             to_rep = {}
             expressions = expr_in.get_r().union(expr_out.get_r())
             for expr in expressions:
@@ -54,10 +55,10 @@ if args.z3:
             new_expr_in = expr_in.replace_expr(to_rep)
             new_expr_out = expr_out.replace_expr(to_rep)
 
-            print "Check %s = %s" % (new_expr_in, new_expr_out)
+            print("Check %s = %s" % (new_expr_in, new_expr_out))
             simp_in = expr_simp_explicit(new_expr_in)
             simp_out =  expr_simp_explicit(new_expr_out)
-            print "[%s] %s = %s" % (simp_in == simp_out, simp_in, simp_out)
+            print("[%s] %s = %s" % (simp_in == simp_out, simp_in, simp_out))
 
             # Either the simplification does not stand, either the test is wrong
             raise RuntimeError("Bad simplification")
@@ -313,7 +314,7 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)),
      (ExprCompose(a, ExprInt(0, 32)) * ExprInt(0x123, 64))[32:64]),
 
     (ExprInt(0x12, 32),
-     ExprInt(0x12L, 32)),
+     ExprInt(0x12, 32)),
 
 
     (ExprCompose(a, b, c)[:16],
@@ -335,32 +336,32 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)),
     (ExprCompose(a, b, c)[48:80],
      ExprCompose(b[16:], c[:16])),
 
-    (ExprCompose(a[0:8], b[8:16], ExprInt(0x0L, 48))[12:32],
+    (ExprCompose(a[0:8], b[8:16], ExprInt(0x0, 48))[12:32],
      ExprCompose(b[12:16], ExprInt(0, 16))
        ),
 
-    (ExprCompose(ExprCompose(a[:8], ExprInt(0x0L, 56))[8:32]
+    (ExprCompose(ExprCompose(a[:8], ExprInt(0x0, 56))[8:32]
                   &
-                  ExprInt(0x1L, 24),
-                  ExprInt(0x0L, 40)),
+                  ExprInt(0x1, 24),
+                  ExprInt(0x0, 40)),
      ExprInt(0, 64)),
 
-    (ExprCompose(ExprCompose(a[:8], ExprInt(0x0L, 56))[:8]
+    (ExprCompose(ExprCompose(a[:8], ExprInt(0x0, 56))[:8]
                  &
-                 ExprInt(0x1L, 8),
-                 (ExprInt(0x0L, 56))),
+                 ExprInt(0x1, 8),
+                 (ExprInt(0x0, 56))),
      ExprCompose(a[:8]&ExprInt(1, 8), ExprInt(0, 56))),
 
     (ExprCompose(ExprCompose(a[:8],
-                             ExprInt(0x0L, 56))[:32]
+                             ExprInt(0x0, 56))[:32]
                  &
-                 ExprInt(0x1L, 32),
-                 ExprInt(0x0L, 32)),
+                 ExprInt(0x1, 32),
+                 ExprInt(0x0, 32)),
      ExprCompose(ExprCompose(ExprSlice(a, 0, 8),
-                             ExprInt(0x0L, 24))
+                             ExprInt(0x0, 24))
                  &
-                 ExprInt(0x1L, 32),
-                 ExprInt(0x0L, 32))
+                 ExprInt(0x1, 32),
+                 ExprInt(0x0, 32))
        ),
     (ExprCompose(a[:16], b[:16])[8:32],
      ExprCompose(a[8:16], b[:16])),
@@ -472,9 +473,9 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)),
 ]
 
 for e_input, e_check in to_test:
-    print "#" * 80
+    print("#" * 80)
     e_new = expr_simp_explicit(e_input)
-    print "original: ", str(e_input), "new: ", str(e_new)
+    print("original: ", str(e_input), "new: ", str(e_new))
     rez = e_new == e_check
     if not rez:
         raise ValueError(
@@ -741,10 +742,10 @@ to_test = [
 ]
 
 for e_input, e_check in to_test:
-    print "#" * 80
+    print("#" * 80)
     e_check = expr_simp(e_check)
     e_new = expr_simp(e_input)
-    print "original: ", str(e_input), "new: ", str(e_new)
+    print("original: ", str(e_input), "new: ", str(e_new))
     rez = e_new == e_check
     if not rez:
         raise ValueError(
@@ -780,10 +781,10 @@ expr_simp.enable_passes(ExpressionSimplifier.PASS_COND)
 
 
 for e_input, e_check in to_test:
-    print "#" * 80
+    print("#" * 80)
     e_check = expr_simp(e_check)
     e_new = expr_simp(e_input)
-    print "original: ", str(e_input), "new: ", str(e_new)
+    print("original: ", str(e_input), "new: ", str(e_new))
     rez = e_new == e_check
     if not rez:
         raise ValueError(
@@ -902,6 +903,6 @@ for x, y in to_test:
 
     assert(x == y)
     assert(str(x) == str(y))
-    print x
+    print(x)
 
-print 'all tests ok'
+print('all tests ok')
diff --git a/test/expression/stp.py b/test/expression/stp.py
index 38bbf9c8..7650bf45 100755
--- a/test/expression/stp.py
+++ b/test/expression/stp.py
@@ -1,6 +1,7 @@
 #! /usr/bin/env python2
 #-*- coding:utf-8 -*-
 
+from builtins import range
 import unittest
 
 
@@ -11,7 +12,7 @@ class TestIrIr2STP(unittest.TestCase):
         from miasm2.ir.translators.translator  import Translator
         translator_smt2 = Translator.to_language("smt2")
 
-        args = [ExprInt(i, 32) for i in xrange(9)]
+        args = [ExprInt(i, 32) for i in range(9)]
 
         self.assertEqual(
             translator_smt2.from_expr(ExprOp('|',  *args[:2])), r'(bvor (_ bv0 32) (_ bv1 32))')
@@ -26,7 +27,7 @@ class TestIrIr2STP(unittest.TestCase):
         from miasm2.ir.translators.translator  import Translator
         translator_smt2 = Translator.to_language("smt2")
 
-        args = [ExprInt(i, 32) for i in xrange(9)]
+        args = [ExprInt(i, 32) for i in range(9)]
 
         self.assertEqual(
             translator_smt2.from_expr(args[0][1:2]), r'((_ extract 1 1) (_ bv0 32))')