diff options
| author | ajax <devnull@localhost> | 2014-06-12 17:34:49 +0200 |
|---|---|---|
| committer | ajax <devnull@localhost> | 2014-06-12 17:34:49 +0200 |
| commit | dcf03ce77a4baeeda8e72b5d5b44e6643cf11501 (patch) | |
| tree | 307f53a947d01eeac3ce8ead98ae5ac8d2980c35 /test/expression/simplifications.py | |
| parent | 82f6759b48be6eeaaf8dbe74c73a4dcd84b7ea38 (diff) | |
| download | miasm-dcf03ce77a4baeeda8e72b5d5b44e6643cf11501.tar.gz miasm-dcf03ce77a4baeeda8e72b5d5b44e6643cf11501.zip | |
Simplifications: Add regression tests for simplifications_cond
Diffstat (limited to 'test/expression/simplifications.py')
| -rw-r--r-- | test/expression/simplifications.py | 31 |
1 files changed, 30 insertions, 1 deletions
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') |