about summary refs log tree commit diff stats
path: root/test/expression/simplifications.py
diff options
context:
space:
mode:
authorCamille Mougey <commial@gmail.com>2018-11-09 09:12:00 +0100
committerGitHub <noreply@github.com>2018-11-09 09:12:00 +0100
commit583c106a23cb1c95523d4cce637e861ffe4c8028 (patch)
tree0e3913d3eda6a6d491a102f9b6ea014ef71c3b68 /test/expression/simplifications.py
parent8276ac5629fdcf3ad885c8e4b9d2d7ed6e1e1d77 (diff)
parent3877d4db136e124973c59d66b106ebe80ce4f732 (diff)
downloadmiasm-583c106a23cb1c95523d4cce637e861ffe4c8028.tar.gz
miasm-583c106a23cb1c95523d4cce637e861ffe4c8028.zip
Merge pull request #864 from serpilliere/fix_hl_op
Fix hl op
Diffstat (limited to 'test/expression/simplifications.py')
-rw-r--r--test/expression/simplifications.py63
1 files changed, 61 insertions, 2 deletions
diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py
index 68dc0437..741d6adb 100644
--- a/test/expression/simplifications.py
+++ b/test/expression/simplifications.py
@@ -97,6 +97,7 @@ s = a[:8]
 i0 = ExprInt(0, 32)
 i1 = ExprInt(1, 32)
 i2 = ExprInt(2, 32)
+im1 = ExprInt(-1, 32)
 icustom = ExprInt(0x12345678, 32)
 cc = ExprCond(a, b, c)
 
@@ -452,9 +453,65 @@ for e_input, e_check in to_test:
     rez = e_new == e_check
     if not rez:
         raise ValueError(
-            'bug in expr_simp_explicit simp(%s) is %s and should be %s' % (e_input, e_new, e_check))
+            'bug in expr_simp_explicit simp(%s) is %s and should be %s' % (e_input, e_new, e_check)
+        )
     check(e_input, e_check)
 
+
+# Test high level op
+to_test = [
+    (ExprOp(TOK_EQUAL, a+i2, i1), ExprOp(TOK_EQUAL, a+i1, i0)),
+    (ExprOp(TOK_INF_SIGNED, a+i2, i1), ExprOp(TOK_INF_SIGNED, a+i2, i1)),
+    (ExprOp(TOK_INF_UNSIGNED, a+i2, i1), ExprOp(TOK_INF_UNSIGNED, a+i2, i1)),
+
+    (
+        ExprOp(TOK_EQUAL, ExprCompose(a8, ExprInt(0, 24)), im1),
+        ExprOp(TOK_EQUAL, a8, ExprInt(0xFF, 8))
+    ),
+
+    (ExprOp(TOK_INF_SIGNED, i1, i2), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_UNSIGNED, i1, i2), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_EQUAL_SIGNED, i1, i2), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_EQUAL_UNSIGNED, i1, i2), ExprInt(1, 1)),
+
+    (ExprOp(TOK_INF_SIGNED, i2, i1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_UNSIGNED, i2, i1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_EQUAL_SIGNED, i2, i1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_EQUAL_UNSIGNED, i2, i1), ExprInt(0, 1)),
+
+    (ExprOp(TOK_INF_SIGNED, i1, i1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_UNSIGNED, i1, i1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_EQUAL_SIGNED, i1, i1), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_EQUAL_UNSIGNED, i1, i1), ExprInt(1, 1)),
+
+
+    (ExprOp(TOK_INF_SIGNED, im1, i1), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_UNSIGNED, im1, i1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_EQUAL_SIGNED, im1, i1), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_EQUAL_UNSIGNED, im1, i1), ExprInt(0, 1)),
+
+    (ExprOp(TOK_INF_SIGNED, i1, im1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_UNSIGNED, i1, im1), ExprInt(1, 1)),
+    (ExprOp(TOK_INF_EQUAL_SIGNED, i1, im1), ExprInt(0, 1)),
+    (ExprOp(TOK_INF_EQUAL_UNSIGNED, i1, im1), ExprInt(1, 1)),
+
+    (ExprOp(TOK_EQUAL, a8.zeroExtend(32), b8.zeroExtend(32)), ExprOp(TOK_EQUAL, a8, b8)),
+    (ExprOp(TOK_EQUAL, a8.signExtend(32), b8.signExtend(32)), ExprOp(TOK_EQUAL, a8, b8)),
+
+]
+
+for e_input, e_check in to_test:
+    print "#" * 80
+    e_check = expr_simp(e_check)
+    e_new = expr_simp(e_input)
+    print "original: ", str(e_input), "new: ", str(e_new)
+    rez = e_new == e_check
+    if not rez:
+        raise ValueError(
+            'bug in expr_simp simp(%s) is %s and should be %s' % (e_input, e_new, e_check)
+        )
+
+
 # Test conds
 
 to_test = [
@@ -490,7 +547,9 @@ for e_input, e_check in to_test:
     rez = e_new == e_check
     if not rez:
         raise ValueError(
-            'bug in expr_simp simp(%s) is %s and should be %s' % (e_input, e_new, e_check))
+            'bug in expr_simp simp(%s) is %s and should be %s' % (e_input, e_new, e_check)
+        )
+
 
 if args.z3:
     # This check is done on 32 bits, but the size is not use by Miasm formulas, so