diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-02-10 10:53:38 +0100 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-02-10 10:53:38 +0100 |
| commit | 388b74c92f518584e0351af894588d90a48624ce (patch) | |
| tree | cbbabcbbfa9b13903fd9b429d46b8e91fa98e633 /test/expression/expression_helper.py | |
| parent | 33189681bf13f88a1e39383a86079fc001ec619d (diff) | |
| download | miasm-388b74c92f518584e0351af894588d90a48624ce.tar.gz miasm-388b74c92f518584e0351af894588d90a48624ce.zip | |
VariablesIdentifier: Handle corner cases (using var ident on already computed eq)
Diffstat (limited to 'test/expression/expression_helper.py')
| -rw-r--r-- | test/expression/expression_helper.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/test/expression/expression_helper.py b/test/expression/expression_helper.py index e1674fdc..514a9a51 100644 --- a/test/expression/expression_helper.py +++ b/test/expression/expression_helper.py @@ -30,6 +30,7 @@ class TestExpressionExpressionHelper(unittest.TestCase): # Test the result new_expr = vi.equation + ## Force replace in the variable dependency order for var_id, var_value in reversed(vi.vars.items()): new_expr = new_expr.replace_expr({var_id: var_value}) @@ -38,16 +39,46 @@ class TestExpressionExpressionHelper(unittest.TestCase): # Test prefix vi = Variables_Identifier(exprf, var_prefix="prefix_v") - # Use __str__ + ## Use __str__ print vi - # Test the result + ## Test the result new_expr = vi.equation - ## Force replace in the variable dependency order + ### Force replace in the variable dependency order for var_id, var_value in reversed(vi.vars.items()): new_expr = new_expr.replace_expr({var_id: var_value}) self.assertEqual(exprf, new_expr) + # Test an identify on an expression already containing identifier + vi = Variables_Identifier(exprf) + vi2 = Variables_Identifier(vi.equation) + + ## Test the result + new_expr = vi2.equation + ### Force replace in the variable dependency order + for var_id, var_value in reversed(vi2.vars.items()): + new_expr = new_expr.replace_expr({var_id: var_value}) + self.assertEqual(vi.equation, new_expr) + + ## Corner case: each sub var depends on itself + mem1 = m2_expr.ExprMem(ebx, size=32) + mem2 = m2_expr.ExprMem(mem1, size=32) + cst2 = m2_expr.ExprInt32(-1) + expr_mini = ((eax ^ mem2 ^ cst2) & (mem2 ^ (eax + mem2)))[31:32] + + ## Build + vi = Variables_Identifier(expr_mini) + vi2 = Variables_Identifier(vi.equation) + + ## Test the result + new_expr = vi2.equation + ### Force replace in the variable dependency order + for var_id, var_value in reversed(vi2.vars.items()): + new_expr = new_expr.replace_expr({var_id: var_value}) + self.assertEqual(vi.equation, new_expr) + + + if __name__ == '__main__': testcase = TestExpressionExpressionHelper testsuite = unittest.TestLoader().loadTestsFromTestCase(testcase) |