From dcf03ce77a4baeeda8e72b5d5b44e6643cf11501 Mon Sep 17 00:00:00 2001 From: ajax Date: Thu, 12 Jun 2014 17:34:49 +0200 Subject: Simplifications: Add regression tests for simplifications_cond --- test/expression/simplifications.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test/expression/simplifications.py') diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 19f43d6e..7d76b6e2 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -3,7 +3,8 @@ # from pdb import pm from miasm2.expression.expression import * -from miasm2.expression.simplifications import expr_simp +from miasm2.expression.simplifications import expr_simp, ExpressionSimplifier +from miasm2.expression.simplifications_cond import TOK_INF_SIGNED, TOK_INF_UNSIGNED # Define example objects a = ExprId('a') @@ -173,6 +174,34 @@ for e, e_check in to_test[:]: raise ValueError( 'bug in expr_simp simp(%s) is %s and should be %s' % (e, e_new, e_check)) +# Test conds + +to_test = [ + (((a - b) ^ ((a ^ b) & ((a - b) ^ a)))[31:32], + ExprOp(TOK_INF_SIGNED, a, b)), + ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b)[31:32], + ExprOp(TOK_INF_UNSIGNED, a, b)), + (ExprOp(TOK_INF_UNSIGNED, ExprInt32(-1), ExprInt32(3)), ExprInt1(0)), + (ExprOp(TOK_INF_SIGNED, ExprInt32(-1), ExprInt32(3)), ExprInt1(1)), +] + +expr_simp_cond = ExpressionSimplifier() +expr_simp.enable_passes(ExpressionSimplifier.PASS_COND) + + +for e, e_check in to_test[:]: + # + print "#" * 80 + e_check = expr_simp(e_check) + # print str(e), str(e_check) + e_new = expr_simp(e) + print "original: ", str(e), "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, e_new, e_check)) + + x = ExprId('x') y = ExprId('y') -- cgit 1.4.1 From 8462e1b5b65b61e837e673229e1bae4dc78c7840 Mon Sep 17 00:00:00 2001 From: ajax Date: Thu, 12 Jun 2014 17:41:05 +0200 Subject: Test: Simplifications: Use ".msb()" instead of hard coded [31:32] --- test/expression/simplifications.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/expression/simplifications.py') diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 7d76b6e2..9a4fbe8c 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -177,9 +177,9 @@ for e, e_check in to_test[:]: # Test conds to_test = [ - (((a - b) ^ ((a ^ b) & ((a - b) ^ a)))[31:32], + (((a - b) ^ ((a ^ b) & ((a - b) ^ a))).msb(), ExprOp(TOK_INF_SIGNED, a, b)), - ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b)[31:32], + ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b).msb(), ExprOp(TOK_INF_UNSIGNED, a, b)), (ExprOp(TOK_INF_UNSIGNED, ExprInt32(-1), ExprInt32(3)), ExprInt1(0)), (ExprOp(TOK_INF_SIGNED, ExprInt32(-1), ExprInt32(3)), ExprInt1(1)), -- cgit 1.4.1 From 0698cd3820a70182c362ba113849fe8ca5e0e032 Mon Sep 17 00:00:00 2001 From: ajax Date: Thu, 12 Jun 2014 18:40:55 +0200 Subject: Simplifications_cond: Fix size issue, add constructor I could have use a child class of ExprOp specific for conditions, but I prefer to keep a better modularity by just using " Date: Thu, 12 Jun 2014 18:51:59 +0200 Subject: Simplifications: Add symetric cond catching + corresponding tests --- miasm2/expression/simplifications_cond.py | 40 +++++++++++++++++++++++++++++-- test/expression/simplifications.py | 2 ++ 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'test/expression/simplifications.py') diff --git a/miasm2/expression/simplifications_cond.py b/miasm2/expression/simplifications_cond.py index 8f41975b..ee23f6db 100644 --- a/miasm2/expression/simplifications_cond.py +++ b/miasm2/expression/simplifications_cond.py @@ -33,6 +33,8 @@ TOK_POS_STRICT = "Spos" jok1 = m2_expr.ExprId("jok1") jok2 = m2_expr.ExprId("jok2") jok3 = m2_expr.ExprId("jok3") +jok_small = m2_expr.ExprId("jok_small", 1) + # Constructors @@ -134,10 +136,44 @@ def expr_simp_inverse(expr_simp, e): """(x