diff options
Diffstat (limited to 'test')
103 files changed, 1268 insertions, 1108 deletions
diff --git a/test/analysis/data_flow.py b/test/analysis/data_flow.py index 2d4e2275..288f4bd6 100644 --- a/test/analysis/data_flow.py +++ b/test/analysis/data_flow.py @@ -1,4 +1,8 @@ """ Test cases for dead code elimination""" +from __future__ import print_function + +from future.utils import viewitems + from miasm2.expression.expression import ExprId, ExprInt, ExprAssign, ExprMem from miasm2.core.locationdb import LocationDB from miasm2.analysis.data_flow import * @@ -683,7 +687,7 @@ for test_nb, test in enumerate([(G1_IRA, G1_EXP_IRA), # Extract test elements g_ira, g_exp_ira = test - print "[+] Test", test_nb+1 + print("[+] Test", test_nb+1) # Print initial graph, for debug open("graph_%02d.dot" % (test_nb+1), "w").write(g_ira.dot()) @@ -700,6 +704,6 @@ for test_nb, test in enumerate([(G1_IRA, G1_EXP_IRA), # Same number of blocks assert len(g_ira.blocks) == len(g_exp_ira.blocks) # Check that each expr in the blocks are the same - for lbl, irb in g_ira.blocks.iteritems(): + for lbl, irb in viewitems(g_ira.blocks): exp_irb = g_exp_ira.blocks[lbl] assert exp_irb.assignblks == irb.assignblks diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index 4d9aa322..c229caf2 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -1,6 +1,10 @@ """Regression test module for DependencyGraph""" -from miasm2.expression.expression import ExprId, ExprInt, ExprAssign, ExprCond, \ - ExprLoc, LocKey +from __future__ import print_function + +from future.utils import viewitems + +from miasm2.expression.expression import ExprId, ExprInt, ExprAssign, \ + ExprCond, ExprLoc, LocKey from miasm2.core.locationdb import LocationDB from miasm2.ir.analysis import ira from miasm2.ir.ir import IRBlock, AssignBlock @@ -136,7 +140,7 @@ def bloc2graph(irgraph, label=False, lines=True): block_html_lines = [] if lines and irblock is not None: for assignblk in irblock: - for dst, src in assignblk.iteritems(): + for dst, src in viewitems(assignblk): if False: out_render = "%.8X</td><td %s> " % (0, td_attr) else: @@ -220,7 +224,7 @@ def dg2graph(graph, label=False, lines=True): return '\n'.join(out) -print " [+] Test dictionary equality" +print(" [+] Test dictionary equality") DNA = DependencyNode(LBL2, A, 0) DNB = DependencyNode(LBL1, B, 1) DNC = DependencyNode(LBL1, C, 0) @@ -747,10 +751,14 @@ def flatNode(node): element = int(node.element.arg) else: RuntimeError("Unsupported type '%s'" % type(enode.element)) - name = loc_db.pretty_str(node.loc_key) - return (name, - element, - node.line_nb) + names = loc_db.get_location_names(node.loc_key) + assert len(names) == 1 + name = next(iter(names)) + return ( + name, + element, + node.line_nb + ) else: return str(node) @@ -761,8 +769,10 @@ def flatGraph(graph): out_nodes.add(flatNode(node)) for nodeA, nodeB in graph.edges(): out_edges.add((flatNode(nodeA), flatNode(nodeB))) - out = (tuple(sorted(list(out_nodes))), - tuple(sorted(list(out_edges)))) + out = ( + tuple(sorted(list(out_nodes), key=str)), + tuple(sorted(list(out_edges), key=str)) + ) return out @@ -819,7 +829,7 @@ def test_result(graphA, graphB, leaves): if set(parentsA_noidx.keys()) != set(parentsB_noidx.keys()): return False - for node_noidx, nodeA in parentsA_noidx.iteritems(): + for node_noidx, nodeA in viewitems(parentsA_noidx): nodeB = parentsB_noidx[node_noidx] todo.add((nodeA, nodeB)) @@ -835,7 +845,8 @@ def match_results(resultsA, resultsB, nodes): if len(resultsA) != len(resultsB): return False - for resultA in resultsA: + for flatA in resultsA: + resultA = unflatGraph(flatA) nodes = resultA.leaves() for resultB in resultsB: if test_result(resultA, resultB, nodes): @@ -854,253 +865,253 @@ def get_flat_init_depnodes(depnodes): return out # TESTS -flat_test_results = [[((('lbl0', 1, 0), ('lbl0', 'c', 0), ('lbl1', 'b', 0), ('lbl2', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))], - [((('lbl0', 1, 0), - ('lbl0', 'c', 0), - ('lbl1', 2, 0), - ('lbl1', 'b', 0), - ('lbl2', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl2', 'a', 0)), - (('lbl1', 2, 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))], - [((('lbl0', 1, 0), - ('lbl0', 'c', 0), - ('lbl1', 2, 0), - ('lbl1', 'b', 0), - ('lbl3', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl3', 'a', 0)), - (('lbl1', 2, 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl3', 'a', 0)))), - ((('lbl0', 1, 0), - ('lbl0', 'c', 0), - ('lbl2', 3, 0), - ('lbl2', 'b', 0), - ('lbl3', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl3', 'a', 0)), - (('lbl2', 3, 0), ('lbl2', 'b', 0)), - (('lbl2', 'b', 0), ('lbl3', 'a', 0))))], - [(('b', ('lbl2', 'a', 0)), (('b', ('lbl2', 'a', 0)),))], - [((('lbl0', 1, 0), - ('lbl0', 'b', 0), - ('lbl1', 2, 0), - ('lbl1', 'b', 0), - ('lbl2', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'b', 0)), - (('lbl1', 2, 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0)))), - ((('lbl0', 1, 0), - ('lbl0', 'b', 0), - ('lbl1', 2, 0), - ('lbl1', 'b', 0), - ('lbl2', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'b', 0)), - (('lbl1', 2, 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))], - [((('lbl0', 1, 0), ('lbl0', 'b', 0), ('lbl1', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'a', 0))))], - [((('lbl0', 1, 0), - ('lbl0', 'c', 0), - ('lbl1', 'a', 1), - ('lbl1', 'b', 0), - ('lbl2', 'd', 0)), - ((('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl1', 'b', 0)), - (('lbl1', 'a', 1), ('lbl2', 'd', 0)), - (('lbl1', 'b', 0), ('lbl1', 'a', 1))))], - [(('d', ('lbl1', 'b', 0), ('lbl1', 'c', 1), ('lbl2', 'a', 0)), - (('d', ('lbl1', 'c', 1)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0)), - (('lbl1', 'c', 1), ('lbl1', 'b', 0)))), - ((('lbl0', 1, 0), ('lbl0', 'c', 0), ('lbl1', 'b', 0), ('lbl2', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))], +flat_test_results = [[(((b'lbl0', 1, 0), (b'lbl0', 'c', 0), (b'lbl1', 'b', 0), (b'lbl2', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))], + [(((b'lbl0', 1, 0), + (b'lbl0', 'c', 0), + (b'lbl1', 2, 0), + (b'lbl1', 'b', 0), + (b'lbl2', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl2', 'a', 0)), + ((b'lbl1', 2, 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))], + [(((b'lbl0', 1, 0), + (b'lbl0', 'c', 0), + (b'lbl1', 2, 0), + (b'lbl1', 'b', 0), + (b'lbl3', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl3', 'a', 0)), + ((b'lbl1', 2, 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl3', 'a', 0)))), + (((b'lbl0', 1, 0), + (b'lbl0', 'c', 0), + (b'lbl2', 3, 0), + (b'lbl2', 'b', 0), + (b'lbl3', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl3', 'a', 0)), + ((b'lbl2', 3, 0), (b'lbl2', 'b', 0)), + ((b'lbl2', 'b', 0), (b'lbl3', 'a', 0))))], + [(('b', (b'lbl2', 'a', 0)), (('b', (b'lbl2', 'a', 0)),))], + [(((b'lbl0', 1, 0), + (b'lbl0', 'b', 0), + (b'lbl1', 2, 0), + (b'lbl1', 'b', 0), + (b'lbl2', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 2, 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0)))), + (((b'lbl0', 1, 0), + (b'lbl0', 'b', 0), + (b'lbl1', 2, 0), + (b'lbl1', 'b', 0), + (b'lbl2', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 2, 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))], + [(((b'lbl0', 1, 0), (b'lbl0', 'b', 0), (b'lbl1', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'a', 0))))], + [(((b'lbl0', 1, 0), + (b'lbl0', 'c', 0), + (b'lbl1', 'a', 1), + (b'lbl1', 'b', 0), + (b'lbl2', 'd', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'a', 1), (b'lbl2', 'd', 0)), + ((b'lbl1', 'b', 0), (b'lbl1', 'a', 1))))], + [(('d', (b'lbl1', 'b', 0), (b'lbl1', 'c', 1), (b'lbl2', 'a', 0)), + (('d', (b'lbl1', 'c', 1)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0)), + ((b'lbl1', 'c', 1), (b'lbl1', 'b', 0)))), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0), (b'lbl1', 'b', 0), (b'lbl2', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))], [(('d', - ('lbl0', 1, 0), - ('lbl0', 'c', 0), - ('lbl1', 'b', 0), - ('lbl1', 'c', 1), - ('lbl2', 'a', 0)), - (('d', ('lbl1', 'c', 1)), - (('lbl0', 1, 0), ('lbl0', 'c', 0)), - (('lbl0', 'c', 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0)))), - (('d', ('lbl1', 'b', 0), ('lbl1', 'c', 1), ('lbl2', 'a', 0)), - (('d', ('lbl1', 'c', 1)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0)), - (('lbl1', 'c', 1), ('lbl1', 'b', 0))))], - [(('b', ('lbl1', 2, 0), ('lbl1', 'b', 0), ('lbl2', 'a', 0)), - (('b', ('lbl1', 'b', 0)), - (('lbl1', 2, 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0)))), - (('b', ('lbl1', 2, 0), ('lbl1', 'b', 0), ('lbl2', 'a', 0)), - (('b', ('lbl1', 'b', 0)), - (('lbl1', 2, 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))], - [((('lbl0', 1, 0), - ('lbl0', 2, 0), - ('lbl0', 'a', 0), - ('lbl0', 'b', 0), - ('lbl1', 'a', 0), - ('lbl1', 'b', 0), - ('lbl2', 'a', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 2, 0), ('lbl0', 'b', 0)), - (('lbl0', 'a', 0), ('lbl1', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'a', 0)), - (('lbl1', 'a', 0), ('lbl2', 'a', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))], - [((('lbl0', 1, 0), - ('lbl0', 'b', 0), - ('lbl1', 2, 1), - ('lbl1', 'a', 0), - ('lbl1', 'b', 1), - ('lbl2', 'b', 0)), - ((('lbl0', 1, 0), ('lbl0', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'b', 1)), - (('lbl1', 2, 1), ('lbl1', 'b', 1)), - (('lbl1', 'a', 0), ('lbl2', 'b', 0)), - (('lbl1', 'b', 1), ('lbl1', 'a', 0)))), - ((('lbl0', 1, 0), - ('lbl0', 'b', 0), - ('lbl1', 2, 1), - ('lbl1', 'a', 0), - ('lbl1', 'b', 1), - ('lbl2', 'b', 0)), - ((('lbl0', 1, 0), ('lbl0', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'b', 1)), - (('lbl1', 2, 1), ('lbl1', 'b', 1)), - (('lbl1', 'a', 0), ('lbl2', 'b', 0)), - (('lbl1', 'b', 1), ('lbl1', 'a', 0)), - (('lbl1', 'b', 1), ('lbl1', 'b', 1)))), - ((('lbl0', 1, 0), ('lbl0', 'b', 0), ('lbl1', 'a', 0), ('lbl2', 'b', 0)), - ((('lbl0', 1, 0), ('lbl0', 'b', 0)), - (('lbl0', 'b', 0), ('lbl1', 'a', 0)), - (('lbl1', 'a', 0), ('lbl2', 'b', 0))))], - [((('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'c', 0), - ('lbl2', 3, 0), - ('lbl2', 3, 1), - ('lbl2', 'a', 1), - ('lbl2', 'b', 0), - ('lbl3', 'r', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl2', 'b', 0)), - (('lbl1', 'c', 0), ('lbl3', 'r', 0)), - (('lbl2', 3, 0), ('lbl2', 'b', 0)), - (('lbl2', 3, 1), ('lbl2', 'a', 1)), - (('lbl2', 'a', 1), ('lbl1', 'c', 0)), - (('lbl2', 'a', 1), ('lbl2', 'b', 0)), - (('lbl2', 'b', 0), ('lbl2', 'a', 1)))), - ((('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'c', 0), - ('lbl2', 3, 0), - ('lbl2', 3, 1), - ('lbl2', 'a', 1), - ('lbl2', 'b', 0), - ('lbl3', 'r', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl2', 'b', 0)), - (('lbl1', 'c', 0), ('lbl3', 'r', 0)), - (('lbl2', 3, 0), ('lbl2', 'b', 0)), - (('lbl2', 3, 1), ('lbl2', 'a', 1)), - (('lbl2', 'a', 1), ('lbl1', 'c', 0)), - (('lbl2', 'b', 0), ('lbl2', 'a', 1)))), - ((('lbl0', 1, 0), ('lbl0', 'a', 0), ('lbl1', 'c', 0), ('lbl3', 'r', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl1', 'c', 0)), - (('lbl1', 'c', 0), ('lbl3', 'r', 0))))], + (b'lbl0', 1, 0), + (b'lbl0', 'c', 0), + (b'lbl1', 'b', 0), + (b'lbl1', 'c', 1), + (b'lbl2', 'a', 0)), + (('d', (b'lbl1', 'c', 1)), + ((b'lbl0', 1, 0), (b'lbl0', 'c', 0)), + ((b'lbl0', 'c', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0)))), + (('d', (b'lbl1', 'b', 0), (b'lbl1', 'c', 1), (b'lbl2', 'a', 0)), + (('d', (b'lbl1', 'c', 1)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0)), + ((b'lbl1', 'c', 1), (b'lbl1', 'b', 0))))], + [(('b', (b'lbl1', 2, 0), (b'lbl1', 'b', 0), (b'lbl2', 'a', 0)), + (('b', (b'lbl1', 'b', 0)), + ((b'lbl1', 2, 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0)))), + (('b', (b'lbl1', 2, 0), (b'lbl1', 'b', 0), (b'lbl2', 'a', 0)), + (('b', (b'lbl1', 'b', 0)), + ((b'lbl1', 2, 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))], + [(((b'lbl0', 1, 0), + (b'lbl0', 2, 0), + (b'lbl0', 'a', 0), + (b'lbl0', 'b', 0), + (b'lbl1', 'a', 0), + (b'lbl1', 'b', 0), + (b'lbl2', 'a', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 2, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'a', 0), (b'lbl1', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'a', 0)), + ((b'lbl1', 'a', 0), (b'lbl2', 'a', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))], + [(((b'lbl0', 1, 0), + (b'lbl0', 'b', 0), + (b'lbl1', 2, 1), + (b'lbl1', 'a', 0), + (b'lbl1', 'b', 1), + (b'lbl2', 'b', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'b', 1)), + ((b'lbl1', 2, 1), (b'lbl1', 'b', 1)), + ((b'lbl1', 'a', 0), (b'lbl2', 'b', 0)), + ((b'lbl1', 'b', 1), (b'lbl1', 'a', 0)))), + (((b'lbl0', 1, 0), + (b'lbl0', 'b', 0), + (b'lbl1', 2, 1), + (b'lbl1', 'a', 0), + (b'lbl1', 'b', 1), + (b'lbl2', 'b', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'b', 1)), + ((b'lbl1', 2, 1), (b'lbl1', 'b', 1)), + ((b'lbl1', 'a', 0), (b'lbl2', 'b', 0)), + ((b'lbl1', 'b', 1), (b'lbl1', 'a', 0)), + ((b'lbl1', 'b', 1), (b'lbl1', 'b', 1)))), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0), (b'lbl1', 'a', 0), (b'lbl2', 'b', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'b', 0)), + ((b'lbl0', 'b', 0), (b'lbl1', 'a', 0)), + ((b'lbl1', 'a', 0), (b'lbl2', 'b', 0))))], + [(((b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'c', 0), + (b'lbl2', 3, 0), + (b'lbl2', 3, 1), + (b'lbl2', 'a', 1), + (b'lbl2', 'b', 0), + (b'lbl3', 'r', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl2', 'b', 0)), + ((b'lbl1', 'c', 0), (b'lbl3', 'r', 0)), + ((b'lbl2', 3, 0), (b'lbl2', 'b', 0)), + ((b'lbl2', 3, 1), (b'lbl2', 'a', 1)), + ((b'lbl2', 'a', 1), (b'lbl1', 'c', 0)), + ((b'lbl2', 'a', 1), (b'lbl2', 'b', 0)), + ((b'lbl2', 'b', 0), (b'lbl2', 'a', 1)))), + (((b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'c', 0), + (b'lbl2', 3, 0), + (b'lbl2', 3, 1), + (b'lbl2', 'a', 1), + (b'lbl2', 'b', 0), + (b'lbl3', 'r', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl2', 'b', 0)), + ((b'lbl1', 'c', 0), (b'lbl3', 'r', 0)), + ((b'lbl2', 3, 0), (b'lbl2', 'b', 0)), + ((b'lbl2', 3, 1), (b'lbl2', 'a', 1)), + ((b'lbl2', 'a', 1), (b'lbl1', 'c', 0)), + ((b'lbl2', 'b', 0), (b'lbl2', 'a', 1)))), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0), (b'lbl1', 'c', 0), (b'lbl3', 'r', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl1', 'c', 0)), + ((b'lbl1', 'c', 0), (b'lbl3', 'r', 0))))], [(('d', - ('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'b', 0), - ('lbl3', 'r', 0)), - (('d', ('lbl3', 'r', 0)), - (('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl1', 'b', 0)), - (('lbl1', 'b', 0), ('lbl3', 'r', 0)))), - ((('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'b', 0), - ('lbl2', 1, 1), - ('lbl2', 'a', 1), - ('lbl2', 'd', 0), - ('lbl3', 'r', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl2', 'd', 0)), - (('lbl1', 'b', 0), ('lbl3', 'r', 0)), - (('lbl2', 1, 1), ('lbl2', 'a', 1)), - (('lbl2', 'a', 1), ('lbl1', 'b', 0)), - (('lbl2', 'a', 1), ('lbl2', 'd', 0)), - (('lbl2', 'd', 0), ('lbl2', 'a', 1)), - (('lbl2', 'd', 0), ('lbl3', 'r', 0)))), - ((('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'b', 0), - ('lbl2', 1, 1), - ('lbl2', 'a', 1), - ('lbl2', 'd', 0), - ('lbl3', 'r', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl2', 'd', 0)), - (('lbl1', 'b', 0), ('lbl3', 'r', 0)), - (('lbl2', 1, 1), ('lbl2', 'a', 1)), - (('lbl2', 'a', 1), ('lbl1', 'b', 0)), - (('lbl2', 'd', 0), ('lbl2', 'a', 1)), - (('lbl2', 'd', 0), ('lbl3', 'r', 0))))], + (b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'b', 0), + (b'lbl3', 'r', 0)), + (('d', (b'lbl3', 'r', 0)), + ((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'b', 0), (b'lbl3', 'r', 0)))), + (((b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'b', 0), + (b'lbl2', 1, 1), + (b'lbl2', 'a', 1), + (b'lbl2', 'd', 0), + (b'lbl3', 'r', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl2', 'd', 0)), + ((b'lbl1', 'b', 0), (b'lbl3', 'r', 0)), + ((b'lbl2', 1, 1), (b'lbl2', 'a', 1)), + ((b'lbl2', 'a', 1), (b'lbl1', 'b', 0)), + ((b'lbl2', 'a', 1), (b'lbl2', 'd', 0)), + ((b'lbl2', 'd', 0), (b'lbl2', 'a', 1)), + ((b'lbl2', 'd', 0), (b'lbl3', 'r', 0)))), + (((b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'b', 0), + (b'lbl2', 1, 1), + (b'lbl2', 'a', 1), + (b'lbl2', 'd', 0), + (b'lbl3', 'r', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl2', 'd', 0)), + ((b'lbl1', 'b', 0), (b'lbl3', 'r', 0)), + ((b'lbl2', 1, 1), (b'lbl2', 'a', 1)), + ((b'lbl2', 'a', 1), (b'lbl1', 'b', 0)), + ((b'lbl2', 'd', 0), (b'lbl2', 'a', 1)), + ((b'lbl2', 'd', 0), (b'lbl3', 'r', 0))))], [(('b', - ('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'b', 2), - ('lbl1', 'c', 1), - ('lbl1', 'd', 0), - ('lbl2', 'r', 0)), - (('b', ('lbl1', 'd', 0)), - (('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl1', 'd', 0)), - (('lbl1', 'b', 2), ('lbl1', 'd', 0)), - (('lbl1', 'b', 2), ('lbl2', 'r', 0)), - (('lbl1', 'c', 1), ('lbl1', 'b', 2)), - (('lbl1', 'd', 0), ('lbl1', 'c', 1)))), + (b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'b', 2), + (b'lbl1', 'c', 1), + (b'lbl1', 'd', 0), + (b'lbl2', 'r', 0)), + (('b', (b'lbl1', 'd', 0)), + ((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl1', 'd', 0)), + ((b'lbl1', 'b', 2), (b'lbl1', 'd', 0)), + ((b'lbl1', 'b', 2), (b'lbl2', 'r', 0)), + ((b'lbl1', 'c', 1), (b'lbl1', 'b', 2)), + ((b'lbl1', 'd', 0), (b'lbl1', 'c', 1)))), (('b', - ('lbl0', 1, 0), - ('lbl0', 'a', 0), - ('lbl1', 'b', 2), - ('lbl1', 'c', 1), - ('lbl1', 'd', 0), - ('lbl2', 'r', 0)), - (('b', ('lbl1', 'd', 0)), - (('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl1', 'd', 0)), - (('lbl1', 'b', 2), ('lbl2', 'r', 0)), - (('lbl1', 'c', 1), ('lbl1', 'b', 2)), - (('lbl1', 'd', 0), ('lbl1', 'c', 1))))], - [((('lbl0', 1, 0), ('lbl0', 'a', 0), ('lbl5', 'r', 0)), - ((('lbl0', 1, 0), ('lbl0', 'a', 0)), - (('lbl0', 'a', 0), ('lbl5', 'r', 0))))], - [((('lbl0', 2, 0), - ('lbl0', 'd', 0), - ('lbl1', 'a', 0), - ('lbl1', 'b', 0), - ('lbl2', 'a', 0)), - ((('lbl0', 2, 0), ('lbl0', 'd', 0)), - (('lbl0', 'd', 0), ('lbl1', 'a', 0)), - (('lbl0', 'd', 0), ('lbl1', 'b', 0)), - (('lbl1', 'a', 0), ('lbl2', 'a', 0)), - (('lbl1', 'b', 0), ('lbl2', 'a', 0))))]] + (b'lbl0', 1, 0), + (b'lbl0', 'a', 0), + (b'lbl1', 'b', 2), + (b'lbl1', 'c', 1), + (b'lbl1', 'd', 0), + (b'lbl2', 'r', 0)), + (('b', (b'lbl1', 'd', 0)), + ((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl1', 'd', 0)), + ((b'lbl1', 'b', 2), (b'lbl2', 'r', 0)), + ((b'lbl1', 'c', 1), (b'lbl1', 'b', 2)), + ((b'lbl1', 'd', 0), (b'lbl1', 'c', 1))))], + [(((b'lbl0', 1, 0), (b'lbl0', 'a', 0), (b'lbl5', 'r', 0)), + (((b'lbl0', 1, 0), (b'lbl0', 'a', 0)), + ((b'lbl0', 'a', 0), (b'lbl5', 'r', 0))))], + [(((b'lbl0', 2, 0), + (b'lbl0', 'd', 0), + (b'lbl1', 'a', 0), + (b'lbl1', 'b', 0), + (b'lbl2', 'a', 0)), + (((b'lbl0', 2, 0), (b'lbl0', 'd', 0)), + ((b'lbl0', 'd', 0), (b'lbl1', 'a', 0)), + ((b'lbl0', 'd', 0), (b'lbl1', 'b', 0)), + ((b'lbl1', 'a', 0), (b'lbl2', 'a', 0)), + ((b'lbl1', 'b', 0), (b'lbl2', 'a', 0))))]] test_results = [[unflatGraph(flat_result) for flat_result in flat_results] for flat_results in flat_test_results] @@ -1127,7 +1138,7 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT), ]): # Extract test elements - print "[+] Test", test_nb + 1 + print("[+] Test", test_nb + 1) ircfg, (depnodes, heads) = test open("graph_%02d.dot" % (test_nb + 1), "w").write(ircfg.dot()) @@ -1149,25 +1160,25 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT), # if g_ind == 4: # TODO: Implicit specifications # continue - print " - Class %s - %s" % (g_dep.__class__.__name__, - suffix_key_list[g_ind]) + print(" - Class %s - %s" % (g_dep.__class__.__name__, + suffix_key_list[g_ind])) # Select the correct result key mode_suffix = suffix_key_list[g_ind] graph_test_key = "graph" + mode_suffix # Test public APIs results = g_dep.get_from_depnodes(depnodes, heads) - print "RESULTS" + print("RESULTS") all_results = set() all_flat = set() for i, result in enumerate(results): all_flat.add(flatGraph(result.graph)) - all_results.add(unflatGraph(flatGraph(result.graph))) + all_results.add(flatGraph(result.graph)) open("graph_test_%02d_%02d.dot" % (test_nb + 1, i), "w").write(dg2graph(result.graph)) if g_ind == 0: - all_flat = sorted(all_flat) + all_flat = sorted(all_flat, key=str) all_flats.append(all_flat) flat_depnodes = get_flat_init_depnodes(depnodes) if not match_results(all_results, test_results[test_nb], flat_depnodes): @@ -1175,11 +1186,11 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT), continue if FAILED: - print "FAILED :", len(FAILED) + print("FAILED :", len(FAILED)) for test_num in sorted(FAILED): - print test_num, + print(test_num, end=' ') else: - print "SUCCESS" + print("SUCCESS") # Return an error status on error assert not FAILED diff --git a/test/analysis/dg_check.py b/test/analysis/dg_check.py index dd662079..a50855ef 100644 --- a/test/analysis/dg_check.py +++ b/test/analysis/dg_check.py @@ -1,3 +1,4 @@ +from __future__ import print_function from pdb import pm import sys import subprocess @@ -12,9 +13,7 @@ expected = json.load(open(expected_file)) result = json.loads(stdout) -expected.sort() -result.sort() +assert len(expected) == len(result) -print expected -print result -assert expected == result +assert all(r in result for r in expected) +assert all(r in expected for r in result) diff --git a/test/analysis/dse.py b/test/analysis/dse.py index 344b9108..82668ea8 100644 --- a/test/analysis/dse.py +++ b/test/analysis/dse.py @@ -1,6 +1,8 @@ import sys from pdb import pm +from future.utils import viewitems + from elfesteem.strpatchwork import StrPatchwork from miasm2.core import parse_asm from miasm2.expression.expression import ExprCompose, ExprOp, ExprInt, ExprId @@ -80,10 +82,10 @@ class DSETest(object): loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) output = StrPatchwork() patches = asm_resolve_final(mn_x86, blocks, loc_db) - for offset, raw in patches.items(): + for offset, raw in viewitems(patches): output[offset] = raw - self.assembly = str(output) + self.assembly = bytes(output) def check(self): regs = self.dse.ir_arch.arch.regs diff --git a/test/analysis/modularintervals.py b/test/analysis/modularintervals.py index 45aa82bd..cf286e3a 100644 --- a/test/analysis/modularintervals.py +++ b/test/analysis/modularintervals.py @@ -1,3 +1,4 @@ +from builtins import range from random import shuffle, seed from miasm2.core.interval import interval @@ -11,10 +12,10 @@ def gen_all_intervals(size): -> 2**(2**size) (number of partition) """ nb_elements = 1 << size - for bvec in xrange(1 << nb_elements): + for bvec in range(1 << nb_elements): # Bit vector: if bit i is on, i is in the interval to_ret = interval() - for i in xrange(nb_elements): + for i in range(nb_elements): if bvec & i == i: to_ret += [(i, i)] yield to_ret @@ -22,12 +23,12 @@ def gen_all_intervals(size): def interval_elements(interv): """Generator on element of an interval""" for sub_range in interv: - for i in xrange(sub_range[0], sub_range[1] + 1): + for i in range(sub_range[0], sub_range[1] + 1): yield i size = 4 left, right = list(gen_all_intervals(size)), list(gen_all_intervals(size)) -right_int = range(1 << size) +right_int = list(range(1 << size)) mask = (1 << size) - 1 def test(left, right): diff --git a/test/analysis/range.py b/test/analysis/range.py index 0e38ec95..946d0116 100644 --- a/test/analysis/range.py +++ b/test/analysis/range.py @@ -1,3 +1,4 @@ +from __future__ import print_function from miasm2.expression.expression import * from miasm2.analysis.expression_range import expr_range from miasm2.ir.translators import Translator @@ -81,7 +82,7 @@ for expr in [ ]: computed_range = expr_range(expr) - print expr, computed_range + print(expr, computed_range) # Trivia checks assert all(x[1] < (1 << expr.size) for x in computed_range) diff --git a/test/analysis/unssa.py b/test/analysis/unssa.py index a796f3b6..42e56246 100644 --- a/test/analysis/unssa.py +++ b/test/analysis/unssa.py @@ -1,4 +1,6 @@ """ Test cases for dead code elimination""" +from future.utils import viewvalues + from miasm2.expression.expression import ExprId, ExprInt, ExprAssign, ExprMem, \ ExprCond, ExprLoc from miasm2.core.locationdb import LocationDB @@ -568,7 +570,7 @@ class IRAOutRegs(IRATest): continue if reg in regs_todo: out[reg] = dst - return set(out.values()) + return set(viewvalues(out)) @@ -623,7 +625,7 @@ for test_nb, ircfg in enumerate( # Save a copy of ircfg ircfg_orig = IRCFG(IRDst, loc_db) - for irblock in ircfg.blocks.values(): + for irblock in viewvalues(ircfg.blocks): ircfg_orig.add_irblock(irblock) # SSA diff --git a/test/arch/aarch64/arch.py b/test/arch/aarch64/arch.py index d2f5114e..948ee489 100644 --- a/test/arch/aarch64/arch.py +++ b/test/arch/aarch64/arch.py @@ -1,6 +1,8 @@ +from __future__ import print_function import sys import time from pdb import pm +from miasm2.core.utils import decode_hex from miasm2.arch.aarch64.arch import * from miasm2.core.locationdb import LocationDB @@ -1824,25 +1826,25 @@ reg_tests_aarch64 = [ def h2i(s): - return s.replace(' ', '').decode('hex') + return decode_hex(s.replace(' ', '')) ts = time.time() for s, l in reg_tests_aarch64[:]: - print "-" * 80 - print s[:12], l + print("-" * 80) + print(s[:12], l) s = s[12:] b = h2i((l)) mn = mn_aarch64.dis(b, 'l') - print [str(x) for x in mn.args] - print s - print mn + print([str(x) for x in mn.args]) + print(s) + print(mn) assert(str(mn) == s) l = mn_aarch64.fromstring(s, loc_db, 'l') assert(str(l) == s) a = mn_aarch64.asm(l) - print [x for x in a] - print repr(b) + print([x for x in a]) + print(repr(b)) assert(b in a) diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py index 677d474f..e49a2a62 100644 --- a/test/arch/aarch64/unit/asm_test.py +++ b/test/arch/aarch64/unit/asm_test.py @@ -1,6 +1,8 @@ import sys import os +from future.utils import viewitems + from miasm2.arch.aarch64.arch import mn_aarch64, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * @@ -28,10 +30,10 @@ class Asm_Test(object): loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) s = StrPatchwork() patches = asmblock.asm_resolve_final(mn_aarch64, blocks, loc_db) - for offset, raw in patches.items(): + for offset, raw in viewitems(patches): s[offset] = raw - self.assembly = str(s) + self.assembly = bytes(s) def run(self): run_addr = 0 diff --git a/test/arch/arm/arch.py b/test/arch/arm/arch.py index f86c3cfb..bf2b1a02 100644 --- a/test/arch/arm/arch.py +++ b/test/arch/arm/arch.py @@ -1,4 +1,7 @@ +from __future__ import print_function import time + +from miasm2.core.utils import decode_hex, encode_hex from miasm2.arch.arm.arch import * from miasm2.core.locationdb import LocationDB from pdb import pm @@ -7,7 +10,7 @@ from pdb import pm loc_db = LocationDB() def h2i(s): - return s.replace(' ', '').decode('hex') + return decode_hex(s.replace(' ', '')) def u16swap(i): @@ -225,19 +228,19 @@ reg_tests_arm = [ ts = time.time() for s, l in reg_tests_arm: - print "-" * 80 + print("-" * 80) s = s[12:] b = h2i((l)) mn = mn_arm.dis(b, 'l') - print [str(x) for x in mn.args] - print s - print mn + print([str(x) for x in mn.args]) + print(s) + print(mn) assert(str(mn) == s) l = mn_arm.fromstring(s, loc_db, 'l') assert(str(l) == s) a = mn_arm.asm(l) - print [x for x in a] - print repr(b) + print([x for x in a]) + print(repr(b)) assert(b in a) reg_tests_armt = [ @@ -692,30 +695,30 @@ reg_tests_armt = [ ] -print "#" * 40, 'armthumb', '#' * 40 +print("#" * 40, 'armthumb', '#' * 40) for s, l in reg_tests_armt: - print "-" * 80 + print("-" * 80) s = s[12:] b = h2i((l)) - print b.encode('hex') + print(encode_hex(b)) mn = mn_armt.dis(b, 'l') - print [str(x) for x in mn.args] - print s - print mn + print([str(x) for x in mn.args]) + print(s) + print(mn) assert(str(mn) == s) l = mn_armt.fromstring(s, loc_db, 'l') assert(str(l) == s) - print 'Asm..', l + print('Asm..', l) a = mn_armt.asm(l) - print [x for x in a] - print repr(b) + print([x for x in a]) + print(repr(b)) assert(b in a) -print 'TEST time', time.time() - ts +print('TEST time', time.time() - ts) # speed test arm -o = "" +o = b"" for s, l in reg_tests_arm: s = s[12:] b = h2i((l)) @@ -731,11 +734,11 @@ while off < bs.getlen(): mn = mn_arm.dis(bs, 'l', off) instr_num += 1 off += 4 -print 'instr per sec:', instr_num / (time.time() - ts) +print('instr per sec:', instr_num // (time.time() - ts)) # speed test thumb -o = "" +o = b"" for s, l in reg_tests_armt: s = s[12:] b = h2i((l)) @@ -751,7 +754,7 @@ while off < bs.getlen(): mn = mn_armt.dis(bs, 'l', off) instr_num += 1 off += mn.l -print 'instr per sec:', instr_num / (time.time() - ts) +print('instr per sec:', instr_num // (time.time() - ts)) import cProfile cProfile.run(r'mn_arm.dis("\xe1\xa0\xa0\x06", "l")') diff --git a/test/arch/arm/sem.py b/test/arch/arm/sem.py index d94b7ded..9c19431b 100755 --- a/test/arch/arm/sem.py +++ b/test/arch/arm/sem.py @@ -1,9 +1,12 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from __future__ import print_function import unittest import logging +from future.utils import viewitems + from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.arch.arm.arch import mn_arm as mn from miasm2.arch.arm.sem import ir_arml as ir_arch @@ -23,7 +26,7 @@ def M(addr): def compute(asm, inputstate={}, debug=False): loc_db = LocationDB() sympool = dict(regs_init) - sympool.update({k: ExprInt(v, k.size) for k, v in inputstate.iteritems()}) + sympool.update({k: ExprInt(v, k.size) for k, v in viewitems(inputstate)}) ir_tmp = ir_arch(loc_db) ircfg = ir_tmp.new_ircfg() symexec = SymbolicExecutionEngine(ir_tmp, sympool) @@ -34,17 +37,17 @@ def compute(asm, inputstate={}, debug=False): lbl = ir_tmp.add_instr_to_ircfg(instr, ircfg) symexec.run_at(ircfg, lbl) if debug: - for k, v in symexec.symbols.items(): + for k, v in viewitems(symexec.symbols): if regs_init.get(k, None) != v: - print k, v + print(k, v) out = {} - for k, v in symexec.symbols.items(): + for k, v in viewitems(symexec.symbols): if k in EXCLUDE_REGS: continue elif regs_init.get(k, None) == v: continue elif isinstance(v, ExprInt): - out[k] = long(v) + out[k] = int(v) else: out[k] = v return out @@ -58,210 +61,210 @@ class TestARMSemantic(unittest.TestCase): def test_shift(self): # §A8.4: Shifts applied to a register self.assertEqual( - compute('MOV R4, R4 ', {R4: 0xDEADBEEFL, }), {R4: 0xDEADBEEFL, }) + compute('MOV R4, R4 ', {R4: 0xDEADBEEF, }), {R4: 0xDEADBEEF, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 LSL 0') self.assertEqual( - compute('MOV R4, R4 LSL 1', {R4: 0xDEADBEEFL, }), {R4: 0xBD5B7DDEL, }) + compute('MOV R4, R4 LSL 1', {R4: 0xDEADBEEF, }), {R4: 0xBD5B7DDE, }) self.assertEqual( - compute('MOV R4, R4 LSL 16', {R4: 0xDEADBEEFL, }), {R4: 0xBEEF0000L, }) + compute('MOV R4, R4 LSL 16', {R4: 0xDEADBEEF, }), {R4: 0xBEEF0000, }) self.assertEqual( - compute('MOV R4, R4 LSL 31', {R4: 0xDEADBEEFL, }), {R4: 0x80000000L, }) + compute('MOV R4, R4 LSL 31', {R4: 0xDEADBEEF, }), {R4: 0x80000000, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 LSL 32') self.assertEqual( - compute('MOV R4, R4 LSL R5', {R4: 0xDEADBEEFL, R5: 0xBADBAD01L, }), {R4: 0xBD5B7DDEL, R5: 0xBADBAD01L, }) + compute('MOV R4, R4 LSL R5', {R4: 0xDEADBEEF, R5: 0xBADBAD01, }), {R4: 0xBD5B7DDE, R5: 0xBADBAD01, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 LSR 0') self.assertEqual( - compute('MOV R4, R4 LSR 1', {R4: 0xDEADBEEFL, }), {R4: 0x6F56DF77L, }) + compute('MOV R4, R4 LSR 1', {R4: 0xDEADBEEF, }), {R4: 0x6F56DF77, }) self.assertEqual( - compute('MOV R4, R4 LSR 16', {R4: 0xDEADBEEFL, }), {R4: 0x0000DEADL, }) + compute('MOV R4, R4 LSR 16', {R4: 0xDEADBEEF, }), {R4: 0x0000DEAD, }) self.assertEqual( - compute('MOV R4, R4 LSR 31', {R4: 0xDEADBEEFL, }), {R4: 0x00000001L, }) + compute('MOV R4, R4 LSR 31', {R4: 0xDEADBEEF, }), {R4: 0x00000001, }) self.assertEqual( - compute('MOV R4, R4 LSR 32', {R4: 0xDEADBEEFL, }), {R4: 0xDEADBEEFL, }) + compute('MOV R4, R4 LSR 32', {R4: 0xDEADBEEF, }), {R4: 0xDEADBEEF, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 LSR 33') self.assertEqual( - compute('MOV R4, R4 LSR R5', {R4: 0xDEADBEEFL, R5: 0xBADBAD01L, }), {R4: 0x6F56DF77L, R5: 0xBADBAD01L, }) + compute('MOV R4, R4 LSR R5', {R4: 0xDEADBEEF, R5: 0xBADBAD01, }), {R4: 0x6F56DF77, R5: 0xBADBAD01, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 ASR 0') self.assertEqual( - compute('MOV R4, R4 ASR 1', {R4: 0xDEADBEEFL, }), {R4: 0xEF56DF77L, }) + compute('MOV R4, R4 ASR 1', {R4: 0xDEADBEEF, }), {R4: 0xEF56DF77, }) self.assertEqual( - compute('MOV R4, R4 ASR 16', {R4: 0xDEADBEEFL, }), {R4: 0xFFFFDEADL, }) + compute('MOV R4, R4 ASR 16', {R4: 0xDEADBEEF, }), {R4: 0xFFFFDEAD, }) self.assertEqual( - compute('MOV R4, R4 ASR 31', {R4: 0xDEADBEEFL, }), {R4: 0xFFFFFFFFL, }) + compute('MOV R4, R4 ASR 31', {R4: 0xDEADBEEF, }), {R4: 0xFFFFFFFF, }) self.assertEqual( - compute('MOV R4, R4 ASR 32', {R4: 0xDEADBEEFL, }), {R4: 0xDEADBEEFL, }) + compute('MOV R4, R4 ASR 32', {R4: 0xDEADBEEF, }), {R4: 0xDEADBEEF, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 ASR 33') self.assertEqual( - compute('MOV R4, R4 ASR R5', {R4: 0xDEADBEEFL, R5: 0xBADBAD01L, }), {R4: 0xEF56DF77L, R5: 0xBADBAD01L, }) + compute('MOV R4, R4 ASR R5', {R4: 0xDEADBEEF, R5: 0xBADBAD01, }), {R4: 0xEF56DF77, R5: 0xBADBAD01, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 ROR 0') self.assertEqual( - compute('MOV R4, R4 ROR 1', {R4: 0xDEADBEEFL, }), {R4: 0xEF56DF77L, }) + compute('MOV R4, R4 ROR 1', {R4: 0xDEADBEEF, }), {R4: 0xEF56DF77, }) self.assertEqual( - compute('MOV R4, R4 ROR 16', {R4: 0xDEADBEEFL, }), {R4: 0xBEEFDEADL, }) + compute('MOV R4, R4 ROR 16', {R4: 0xDEADBEEF, }), {R4: 0xBEEFDEAD, }) self.assertEqual( - compute('MOV R4, R4 ROR 31', {R4: 0xDEADBEEFL, }), {R4: 0xBD5B7DDFL, }) + compute('MOV R4, R4 ROR 31', {R4: 0xDEADBEEF, }), {R4: 0xBD5B7DDF, }) self.assertRaises(ValueError, compute, 'MOV R4, R4 ROR 32') self.assertEqual( - compute('MOV R4, R4 ROR R5', {R4: 0xDEADBEEFL, R5: 0xBADBAD01L, }), {R4: 0xEF56DF77L, R5: 0xBADBAD01L, }) - self.assertEqual(compute('MOV R4, R4 RRX ', {cf: 0L, R4: 0xDEADBEEFL, }), { - cf: 0L, R4: 0x6F56DF77L, }) - self.assertEqual(compute('MOV R4, R4 RRX ', {cf: 1L, R4: 0xDEADBEEFL, }), { - cf: 1L, R4: 0xEF56DF77L, }) + compute('MOV R4, R4 ROR R5', {R4: 0xDEADBEEF, R5: 0xBADBAD01, }), {R4: 0xEF56DF77, R5: 0xBADBAD01, }) + self.assertEqual(compute('MOV R4, R4 RRX ', {cf: 0, R4: 0xDEADBEEF, }), { + cf: 0, R4: 0x6F56DF77, }) + self.assertEqual(compute('MOV R4, R4 RRX ', {cf: 1, R4: 0xDEADBEEF, }), { + cf: 1, R4: 0xEF56DF77, }) def test_ADC(self): # §A8.8.1: ADC{S}{<c>}{<q>} {<Rd>,} <Rn>, #<const> self.assertRaises( ValueError, compute, 'ADC R4, 0x00000001 ') self.assertEqual(compute('ADC R4, R4, 0x00000001 ', { - cf: 0L, R4: 0x00000000L, }), {cf: 0L, R4: 0x00000001L, }) + cf: 0, R4: 0x00000000, }), {cf: 0, R4: 0x00000001, }) self.assertEqual(compute('ADC R4, R4, 0x00000000 ', { - cf: 1L, R4: 0x00000000L, }), {cf: 1L, R4: 0x00000001L, }) + cf: 1, R4: 0x00000000, }), {cf: 1, R4: 0x00000001, }) self.assertEqual(compute('ADC PC, R4, 0x00000001 ', { - cf: 0L, R4: 0xFFFFFFFFL, PC: 0x55555555L, }), {cf: 0L, R4: 0xFFFFFFFFL, PC: 0x00000000L, }) + cf: 0, R4: 0xFFFFFFFF, PC: 0x55555555, }), {cf: 0, R4: 0xFFFFFFFF, PC: 0x00000000, }) self.assertEqual(compute('ADC PC, R4, 0x00000000 ', { - cf: 1L, R4: 0xFFFFFFFFL, PC: 0x55555555L, }), {cf: 1L, R4: 0xFFFFFFFFL, PC: 0x00000000L, }) - self.assertEqual(compute('ADCS R4, R4, 0x80000000 ', {cf: 0L, R4: 0x80000000L, }), { - nf: 0L, zf: 1L, cf: 1L, of: 1L, R4: 0x00000000L, }) - self.assertEqual(compute('ADCS R4, R4, 0xFF000000 ', {cf: 1L, R4: 0x00FFFFFEL, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xFFFFFFFFL, }) + cf: 1, R4: 0xFFFFFFFF, PC: 0x55555555, }), {cf: 1, R4: 0xFFFFFFFF, PC: 0x00000000, }) + self.assertEqual(compute('ADCS R4, R4, 0x80000000 ', {cf: 0, R4: 0x80000000, }), { + nf: 0, zf: 1, cf: 1, of: 1, R4: 0x00000000, }) + self.assertEqual(compute('ADCS R4, R4, 0xFF000000 ', {cf: 1, R4: 0x00FFFFFE, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xFFFFFFFF, }) self.assertEqual(compute('ADCS PC, R4, 0x00000000 ', { - cf: 0L, R4: 0x00000000L, PC: 0x55555555L, }), {cf: 0L, R4: 0x00000000L, PC: 0x00000000L, }) + cf: 0, R4: 0x00000000, PC: 0x55555555, }), {cf: 0, R4: 0x00000000, PC: 0x00000000, }) self.assertEqual(compute('ADCS PC, R4, 0xFF000000 ', { - cf: 1L, R4: 0x01000000L, PC: 0x55555555L, }), {cf: 1L, R4: 0x01000000L, PC: 0x00000001L, }) + cf: 1, R4: 0x01000000, PC: 0x55555555, }), {cf: 1, R4: 0x01000000, PC: 0x00000001, }) # §A8.8.2: ADC{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm> {,<shift>} self.assertRaises( ValueError, compute, 'ADC R4, R5 ') self.assertEqual(compute('ADC R4, R4, R5 ', { - cf: 1L, R4: 0xFFFFFFFFL, R5: 0x00000000L, }), {cf: 1L, R4: 0x00000000L, R5: 0x00000000L, }) + cf: 1, R4: 0xFFFFFFFF, R5: 0x00000000, }), {cf: 1, R4: 0x00000000, R5: 0x00000000, }) self.assertEqual(compute('ADC R4, R4, R5 LSL 1 ', { - cf: 0L, R4: 0x00000001L, R5: 0x00000008L, }), {cf: 0L, R4: 0x00000011L, R5: 0x00000008L, }) + cf: 0, R4: 0x00000001, R5: 0x00000008, }), {cf: 0, R4: 0x00000011, R5: 0x00000008, }) self.assertEqual(compute('ADC R4, R4, R5 LSR 2 ', { - cf: 1L, R4: 0x00000000L, R5: 0x80000041L, }), {cf: 1L, R4: 0x20000011L, R5: 0x80000041L, }) + cf: 1, R4: 0x00000000, R5: 0x80000041, }), {cf: 1, R4: 0x20000011, R5: 0x80000041, }) self.assertEqual(compute('ADC R4, R4, R5 ASR 3 ', { - cf: 0L, R4: 0x00000001L, R5: 0x80000081L, }), {cf: 0L, R4: 0xF0000011L, R5: 0x80000081L, }) + cf: 0, R4: 0x00000001, R5: 0x80000081, }), {cf: 0, R4: 0xF0000011, R5: 0x80000081, }) self.assertEqual(compute('ADC R4, R4, R5 ROR 4 ', { - cf: 1L, R4: 0xFFFFFFFFL, R5: 0x0000010FL, }), {cf: 1L, R4: 0xF0000010L, R5: 0x0000010FL, }) + cf: 1, R4: 0xFFFFFFFF, R5: 0x0000010F, }), {cf: 1, R4: 0xF0000010, R5: 0x0000010F, }) self.assertEqual(compute('ADC R4, R4, R5 RRX ', { - cf: 1L, R4: 0xFFFFFFFFL, R5: 0x00000101L, }), {cf: 1L, R4: 0x80000080L, R5: 0x00000101L, }) - self.assertEqual(compute('ADCS R4, R4, R5 ', {cf: 1L, R4: 0xFFFFFFFFL, R5: 0x00000000L, }), { - nf: 0L, zf: 1L, cf: 1L, of: 0L, R4: 0x00000000L, R5: 0x00000000L, }) - self.assertEqual(compute('ADCS R4, R4, R5 LSL 1 ', {cf: 0L, R4: 0x00000001L, R5: 0x00000008L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x00000011L, R5: 0x00000008L, }) - self.assertEqual(compute('ADCS R4, R4, R5 LSR 2 ', {cf: 1L, R4: 0x00000000L, R5: 0x80000041L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x20000011L, R5: 0x80000041L, }) - self.assertEqual(compute('ADCS R4, R4, R5 ASR 3 ', {cf: 0L, R4: 0x00000001L, R5: 0x80000081L, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xF0000011L, R5: 0x80000081L, }) - self.assertEqual(compute('ADCS R4, R4, R5 ROR 4 ', {cf: 1L, R4: 0xFFFFFFFFL, R5: 0x0000010FL, }), { - nf: 1L, zf: 0L, cf: 1L, of: 0L, R4: 0xF0000010L, R5: 0x0000010FL, }) - self.assertEqual(compute('ADCS R4, R4, R5 RRX ', {cf: 1L, R4: 0xFFFFFFFFL, R5: 0x00000101L, }), { - nf: 1L, zf: 0L, cf: 1L, of: 0L, R4: 0x80000080L, R5: 0x00000101L, }) + cf: 1, R4: 0xFFFFFFFF, R5: 0x00000101, }), {cf: 1, R4: 0x80000080, R5: 0x00000101, }) + self.assertEqual(compute('ADCS R4, R4, R5 ', {cf: 1, R4: 0xFFFFFFFF, R5: 0x00000000, }), { + nf: 0, zf: 1, cf: 1, of: 0, R4: 0x00000000, R5: 0x00000000, }) + self.assertEqual(compute('ADCS R4, R4, R5 LSL 1 ', {cf: 0, R4: 0x00000001, R5: 0x00000008, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x00000011, R5: 0x00000008, }) + self.assertEqual(compute('ADCS R4, R4, R5 LSR 2 ', {cf: 1, R4: 0x00000000, R5: 0x80000041, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x20000011, R5: 0x80000041, }) + self.assertEqual(compute('ADCS R4, R4, R5 ASR 3 ', {cf: 0, R4: 0x00000001, R5: 0x80000081, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xF0000011, R5: 0x80000081, }) + self.assertEqual(compute('ADCS R4, R4, R5 ROR 4 ', {cf: 1, R4: 0xFFFFFFFF, R5: 0x0000010F, }), { + nf: 1, zf: 0, cf: 1, of: 0, R4: 0xF0000010, R5: 0x0000010F, }) + self.assertEqual(compute('ADCS R4, R4, R5 RRX ', {cf: 1, R4: 0xFFFFFFFF, R5: 0x00000101, }), { + nf: 1, zf: 0, cf: 1, of: 0, R4: 0x80000080, R5: 0x00000101, }) # §A8.8.3: ADC{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, <type> <Rs> self.assertEqual(compute('ADC R4, R6, R4 LSL R5', { - cf: 0L, R4: 0x00000001L, R5: 0x00000004L, R6: 0L, }), {cf: 0L, R4: 0x00000010L, R5: 0x00000004L, R6: 0L, }) + cf: 0, R4: 0x00000001, R5: 0x00000004, R6: 0, }), {cf: 0, R4: 0x00000010, R5: 0x00000004, R6: 0, }) self.assertEqual(compute('ADC R4, R6, R4 LSR R5', { - cf: 1L, R4: 0x00000110L, R5: 0x80000004L, R6: 0L, }), {cf: 1L, R4: 0x00000012L, R5: 0x80000004L, R6: 0L, }) + cf: 1, R4: 0x00000110, R5: 0x80000004, R6: 0, }), {cf: 1, R4: 0x00000012, R5: 0x80000004, R6: 0, }) self.assertEqual(compute('ADC R4, R6, R4 ASR R5', { - cf: 0L, R4: 0x80000010L, R5: 0xF0000001L, R6: 0L, }), {cf: 0L, R4: 0xC0000008L, R5: 0xF0000001L, R6: 0L, }) + cf: 0, R4: 0x80000010, R5: 0xF0000001, R6: 0, }), {cf: 0, R4: 0xC0000008, R5: 0xF0000001, R6: 0, }) self.assertEqual(compute('ADC R4, R6, R4 ROR R5', { - cf: 1L, R4: 0x000000FFL, R5: 0x00000F04L, R6: 0L, }), {cf: 1L, R4: 0xF0000010L, R5: 0x00000F04L, R6: 0L, }) - self.assertEqual(compute('ADCS R4, R6, R4 LSL R5', {cf: 0L, R4: 0x00000001L, R5: 0x00000004L, R6: 0L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x00000010L, R5: 0x00000004L, R6: 0L, }) - self.assertEqual(compute('ADCS R4, R6, R4 LSR R5', {cf: 1L, R4: 0x00000110L, R5: 0x80000004L, R6: 0L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x00000012L, R5: 0x80000004L, R6: 0L, }) - self.assertEqual(compute('ADCS R4, R6, R4 ASR R5', {cf: 0L, R4: 0x80000010L, R5: 0xF0000001L, R6: 0L, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xC0000008L, R5: 0xF0000001L, R6: 0L, }) - self.assertEqual(compute('ADCS R4, R6, R4 ROR R5', {cf: 1L, R4: 0x000000FFL, R5: 0x00000F04L, R6: 0L, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xF0000010L, R5: 0x00000F04L, R6: 0L, }) + cf: 1, R4: 0x000000FF, R5: 0x00000F04, R6: 0, }), {cf: 1, R4: 0xF0000010, R5: 0x00000F04, R6: 0, }) + self.assertEqual(compute('ADCS R4, R6, R4 LSL R5', {cf: 0, R4: 0x00000001, R5: 0x00000004, R6: 0, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x00000010, R5: 0x00000004, R6: 0, }) + self.assertEqual(compute('ADCS R4, R6, R4 LSR R5', {cf: 1, R4: 0x00000110, R5: 0x80000004, R6: 0, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x00000012, R5: 0x80000004, R6: 0, }) + self.assertEqual(compute('ADCS R4, R6, R4 ASR R5', {cf: 0, R4: 0x80000010, R5: 0xF0000001, R6: 0, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xC0000008, R5: 0xF0000001, R6: 0, }) + self.assertEqual(compute('ADCS R4, R6, R4 ROR R5', {cf: 1, R4: 0x000000FF, R5: 0x00000F04, R6: 0, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xF0000010, R5: 0x00000F04, R6: 0, }) def test_ADD(self): # §A8.8.{5,9}: ADD{S}{<c>}{<q>} {<Rd>,} <Rn>, #<const> self.assertRaises( ValueError, compute, 'ADD R4, 0x00000001L ') self.assertEqual(compute('ADD R4, R4, 0x00000001 ', { - R4: 0x00000000L, }), {R4: 0x00000001L, }) + R4: 0x00000000, }), {R4: 0x00000001, }) self.assertEqual(compute('ADD R4, R4, 0x00000000 ', { - R4: 0x00000000L, }), {R4: 0x00000000L, }) + R4: 0x00000000, }), {R4: 0x00000000, }) self.assertEqual(compute('ADD PC, R4, 0x00000001 ', { - R4: 0xFFFFFFFFL, PC: 0x55555555L, }), {R4: 0xFFFFFFFFL, PC: 0x00000000L, }) + R4: 0xFFFFFFFF, PC: 0x55555555, }), {R4: 0xFFFFFFFF, PC: 0x00000000, }) self.assertEqual(compute('ADD PC, R4, 0x00000000 ', { - R4: 0xFFFFFFFFL, PC: 0x55555555L, }), {R4: 0xFFFFFFFFL, PC: 0xFFFFFFFFL, }) - self.assertEqual(compute('ADDS R4, R4, 0x80000000 ', {R4: 0x80000000L, }), { - nf: 0L, zf: 1L, cf: 1L, of: 1L, R4: 0x00000000L, }) - self.assertEqual(compute('ADDS R4, R4, 0xFF000000 ', {R4: 0x00FFFFFEL, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xFFFFFFFEL, }) + R4: 0xFFFFFFFF, PC: 0x55555555, }), {R4: 0xFFFFFFFF, PC: 0xFFFFFFFF, }) + self.assertEqual(compute('ADDS R4, R4, 0x80000000 ', {R4: 0x80000000, }), { + nf: 0, zf: 1, cf: 1, of: 1, R4: 0x00000000, }) + self.assertEqual(compute('ADDS R4, R4, 0xFF000000 ', {R4: 0x00FFFFFE, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xFFFFFFFE, }) self.assertEqual(compute('ADDS PC, R4, 0x00000000 ', { - R4: 0x00000000L, PC: 0x55555555L, }), {R4: 0x00000000L, PC: 0x00000000L, }) + R4: 0x00000000, PC: 0x55555555, }), {R4: 0x00000000, PC: 0x00000000, }) self.assertEqual(compute('ADDS PC, R4, 0xFF000000 ', { - R4: 0x01000000L, PC: 0x55555555L, }), {R4: 0x01000000L, PC: 0x00000000L, }) + R4: 0x01000000, PC: 0x55555555, }), {R4: 0x01000000, PC: 0x00000000, }) # SP special part self.assertEqual(compute('ADD R4, SP, 0x00000001 ', { - R4: 0x00000000L, SP: 0x00000000L, }), {R4: 0x00000001L, SP: 0x00000000L, }) + R4: 0x00000000, SP: 0x00000000, }), {R4: 0x00000001, SP: 0x00000000, }) # §A8.8.{7,11}: ADD{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm> {,<shift>} self.assertRaises( ValueError, compute, 'ADD R4, R5 ') self.assertEqual(compute('ADD R4, R4, R5 ', { - R4: 0xFFFFFFFFL, R5: 0x00000001L, }), {R4: 0x00000000L, R5: 0x00000001L, }) + R4: 0xFFFFFFFF, R5: 0x00000001, }), {R4: 0x00000000, R5: 0x00000001, }) self.assertEqual(compute('ADD R4, R4, R5 LSL 1 ', { - R4: 0x00000001L, R5: 0x00000008L, }), {R4: 0x00000011L, R5: 0x00000008L, }) + R4: 0x00000001, R5: 0x00000008, }), {R4: 0x00000011, R5: 0x00000008, }) self.assertEqual(compute('ADD R4, R4, R5 LSR 2 ', { - R4: 0x00000000L, R5: 0x80000041L, }), {R4: 0x20000010L, R5: 0x80000041L, }) + R4: 0x00000000, R5: 0x80000041, }), {R4: 0x20000010, R5: 0x80000041, }) self.assertEqual(compute('ADD R4, R4, R5 ASR 3 ', { - R4: 0x00000001L, R5: 0x80000081L, }), {R4: 0xF0000011L, R5: 0x80000081L, }) + R4: 0x00000001, R5: 0x80000081, }), {R4: 0xF0000011, R5: 0x80000081, }) self.assertEqual(compute('ADD R4, R4, R5 ROR 4 ', { - R4: 0xFFFFFFFFL, R5: 0x0000010FL, }), {R4: 0xF000000FL, R5: 0x0000010FL, }) + R4: 0xFFFFFFFF, R5: 0x0000010F, }), {R4: 0xF000000F, R5: 0x0000010F, }) self.assertEqual(compute('ADD R4, R4, R5 RRX ', { - cf: 1L, R4: 0xFFFFFFFFL, R5: 0x00000101L, }), {cf: 1L, R4: 0x8000007FL, R5: 0x00000101L, }) - self.assertEqual(compute('ADDS R4, R4, R5 ', {R4: 0xFFFFFFFFL, R5: 0x00000001L, }), { - nf: 0L, zf: 1L, cf: 1L, of: 0L, R4: 0x00000000L, R5: 0x00000001L, }) - self.assertEqual(compute('ADDS R4, R4, R5 LSL 1 ', {R4: 0x00000001L, R5: 0x00000008L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x00000011L, R5: 0x00000008L, }) - self.assertEqual(compute('ADDS R4, R4, R5 LSR 2 ', {R4: 0x00000000L, R5: 0x80000041L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x20000010L, R5: 0x80000041L, }) - self.assertEqual(compute('ADDS R4, R4, R5 ASR 3 ', {R4: 0x00000001L, R5: 0x80000081L, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xF0000011L, R5: 0x80000081L, }) - self.assertEqual(compute('ADDS R4, R4, R5 ROR 4 ', {R4: 0xFFFFFFFFL, R5: 0x0000010FL, }), { - nf: 1L, zf: 0L, cf: 1L, of: 0L, R4: 0xF000000FL, R5: 0x0000010FL, }) - self.assertEqual(compute('ADDS R4, R4, R5 RRX ', {cf: 1L, R4: 0xFFFFFFFFL, R5: 0x00000101L, }), { - nf: 1L, zf: 0L, cf: 1L, of: 0L, R4: 0x8000007FL, R5: 0x00000101L, }) + cf: 1, R4: 0xFFFFFFFF, R5: 0x00000101, }), {cf: 1, R4: 0x8000007F, R5: 0x00000101, }) + self.assertEqual(compute('ADDS R4, R4, R5 ', {R4: 0xFFFFFFFF, R5: 0x00000001, }), { + nf: 0, zf: 1, cf: 1, of: 0, R4: 0x00000000, R5: 0x00000001, }) + self.assertEqual(compute('ADDS R4, R4, R5 LSL 1 ', {R4: 0x00000001, R5: 0x00000008, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x00000011, R5: 0x00000008, }) + self.assertEqual(compute('ADDS R4, R4, R5 LSR 2 ', {R4: 0x00000000, R5: 0x80000041, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x20000010, R5: 0x80000041, }) + self.assertEqual(compute('ADDS R4, R4, R5 ASR 3 ', {R4: 0x00000001, R5: 0x80000081, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xF0000011, R5: 0x80000081, }) + self.assertEqual(compute('ADDS R4, R4, R5 ROR 4 ', {R4: 0xFFFFFFFF, R5: 0x0000010F, }), { + nf: 1, zf: 0, cf: 1, of: 0, R4: 0xF000000F, R5: 0x0000010F, }) + self.assertEqual(compute('ADDS R4, R4, R5 RRX ', {cf: 1, R4: 0xFFFFFFFF, R5: 0x00000101, }), { + nf: 1, zf: 0, cf: 1, of: 0, R4: 0x8000007F, R5: 0x00000101, }) # SP special part self.assertEqual(compute('ADD R4, SP, R4 LSR 1 ', { - R4: 0x00000002L, SP: 0x00000000L, }), {R4: 0x00000001L, SP: 0x00000000L, }) + R4: 0x00000002, SP: 0x00000000, }), {R4: 0x00000001, SP: 0x00000000, }) # §A8.8.8: ADD{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, <type> <Rs> self.assertEqual(compute('ADD R4, R6, R4 LSL R5', { - R4: 0x00000001L, R5: 0x00000004L, R6: 0L, }), {R4: 0x00000010L, R5: 0x00000004L, R6: 0L, }) + R4: 0x00000001, R5: 0x00000004, R6: 0, }), {R4: 0x00000010, R5: 0x00000004, R6: 0, }) self.assertEqual(compute('ADD R4, R6, R4 LSR R5', { - R4: 0x00000110L, R5: 0x80000004L, R6: 0L, }), {R4: 0x00000011L, R5: 0x80000004L, R6: 0L, }) + R4: 0x00000110, R5: 0x80000004, R6: 0, }), {R4: 0x00000011, R5: 0x80000004, R6: 0, }) self.assertEqual(compute('ADD R4, R6, R4 ASR R5', { - R4: 0x80000010L, R5: 0xF0000001L, R6: 0L, }), {R4: 0xC0000008L, R5: 0xF0000001L, R6: 0L, }) + R4: 0x80000010, R5: 0xF0000001, R6: 0, }), {R4: 0xC0000008, R5: 0xF0000001, R6: 0, }) self.assertEqual(compute('ADD R4, R6, R4 ROR R5', { - R4: 0x000000FFL, R5: 0x00000F04L, R6: 0L, }), {R4: 0xF000000FL, R5: 0x00000F04L, R6: 0L, }) - self.assertEqual(compute('ADDS R4, R6, R4 LSL R5', {R4: 0x00000001L, R5: 0x00000004L, R6: 0L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x00000010L, R5: 0x00000004L, R6: 0L, }) - self.assertEqual(compute('ADDS R4, R6, R4 LSR R5', {R4: 0x00000110L, R5: 0x80000004L, R6: 0L, }), { - nf: 0L, zf: 0L, cf: 0L, of: 0L, R4: 0x00000011L, R5: 0x80000004L, R6: 0L, }) - self.assertEqual(compute('ADDS R4, R6, R4 ASR R5', {R4: 0x80000010L, R5: 0xF0000001L, R6: 0L, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xC0000008L, R5: 0xF0000001L, R6: 0L, }) - self.assertEqual(compute('ADDS R4, R6, R4 ROR R5', {R4: 0x000000FFL, R5: 0x00000F04L, R6: 0L, }), { - nf: 1L, zf: 0L, cf: 0L, of: 0L, R4: 0xF000000FL, R5: 0x00000F04L, R6: 0L, }) + R4: 0x000000FF, R5: 0x00000F04, R6: 0, }), {R4: 0xF000000F, R5: 0x00000F04, R6: 0, }) + self.assertEqual(compute('ADDS R4, R6, R4 LSL R5', {R4: 0x00000001, R5: 0x00000004, R6: 0, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x00000010, R5: 0x00000004, R6: 0, }) + self.assertEqual(compute('ADDS R4, R6, R4 LSR R5', {R4: 0x00000110, R5: 0x80000004, R6: 0, }), { + nf: 0, zf: 0, cf: 0, of: 0, R4: 0x00000011, R5: 0x80000004, R6: 0, }) + self.assertEqual(compute('ADDS R4, R6, R4 ASR R5', {R4: 0x80000010, R5: 0xF0000001, R6: 0, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xC0000008, R5: 0xF0000001, R6: 0, }) + self.assertEqual(compute('ADDS R4, R6, R4 ROR R5', {R4: 0x000000FF, R5: 0x00000F04, R6: 0, }), { + nf: 1, zf: 0, cf: 0, of: 0, R4: 0xF000000F, R5: 0x00000F04, R6: 0, }) # Test against qemu - self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x1L, R3: 0x1L}), - { nf: 0L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000001L, R3: 0x00000002L}) - self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x1L, R3: 0x7FFFFFFFL}), - { nf: 1L, zf: 0L, cf: 0L, of: 1L, R2: 0x00000001L, R3: 0x80000000L}) - self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x80000000L, R3: 0x80000000L}), - { nf: 0L, zf: 1L, cf: 1L, of: 1L, R2: 0x80000000L, R3: 0x00000000L}) - self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x7FFFFFFFL, R3:0x7FFFFFFFL}), - { nf: 1L, zf: 0L, cf: 0L, of: 1L, R2: 0x7FFFFFFFL, R3:0xFFFFFFFEL}) - self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0L, R3:0}), - { nf: 0L, zf: 1L, cf: 0L, of: 0L, R2: 0L, R3:0}) - self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0xFFFFFFFFL, R3:0xFFFFFFFFL}), - { nf: 1L, zf: 0L, cf: 1L, of: 0L, R2: 0xFFFFFFFFL, R3:0xFFFFFFFEL}) + self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x1, R3: 0x1}), + { nf: 0, zf: 0, cf: 0, of: 0, R2: 0x00000001, R3: 0x00000002}) + self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x1, R3: 0x7FFFFFFF}), + { nf: 1, zf: 0, cf: 0, of: 1, R2: 0x00000001, R3: 0x80000000}) + self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x80000000, R3: 0x80000000}), + { nf: 0, zf: 1, cf: 1, of: 1, R2: 0x80000000, R3: 0x00000000}) + self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0x7FFFFFFF, R3:0x7FFFFFFF}), + { nf: 1, zf: 0, cf: 0, of: 1, R2: 0x7FFFFFFF, R3:0xFFFFFFFE}) + self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0, R3:0}), + { nf: 0, zf: 1, cf: 0, of: 0, R2: 0, R3:0}) + self.assertEqual(compute('ADDS R3, R2, R3 ', {R2: 0xFFFFFFFF, R3:0xFFFFFFFF}), + { nf: 1, zf: 0, cf: 1, of: 0, R2: 0xFFFFFFFF, R3:0xFFFFFFFE}) @@ -275,26 +278,26 @@ class TestARMSemantic(unittest.TestCase): # §A8.8.13: AND{S}{<c>}{<q>} {<Rd>,} <Rn>, #<const> self.assertRaises( ValueError, compute, 'AND R4, 0x00000001 ') - self.assertEqual(compute('AND R4, R4, 0x00000001 ', {R4: 0xDEADBEEFL, }), {R4: 0x00000001L, }) - self.assertEqual(compute('AND R4, R4, 0x00000000 ', {R4: 0x00000000L, }), {R4: 0x00000000L, }) - self.assertEqual(compute('AND PC, R4, 0x00000001 ', {R4: 0xFFFFFFFFL, PC: 0x55555555L, }), {R4: 0xFFFFFFFFL, PC: 0x00000001L, }) - self.assertEqual(compute('AND PC, R4, 0x00000000 ', {R4: 0xFFFFFFFFL, PC: 0x55555555L, }), {R4: 0xFFFFFFFFL, PC: 0x00000000L, }) + self.assertEqual(compute('AND R4, R4, 0x00000001 ', {R4: 0xDEADBEEF, }), {R4: 0x00000001, }) + self.assertEqual(compute('AND R4, R4, 0x00000000 ', {R4: 0x00000000, }), {R4: 0x00000000, }) + self.assertEqual(compute('AND PC, R4, 0x00000001 ', {R4: 0xFFFFFFFF, PC: 0x55555555, }), {R4: 0xFFFFFFFF, PC: 0x00000001, }) + self.assertEqual(compute('AND PC, R4, 0x00000000 ', {R4: 0xFFFFFFFF, PC: 0x55555555, }), {R4: 0xFFFFFFFF, PC: 0x00000000, }) # §A8.8.14: AND{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm> {,<shift>} self.assertRaises( ValueError, compute, 'AND R4, R5 ') - self.assertEqual(compute('AND R4, R4, R5 ', {R4: 0xFFFFFFFEL, R5: 0x00000001L, }), {R4: 0x00000000L, R5: 0x00000001L, }) - self.assertEqual(compute('AND R4, R4, R5 LSL 1 ', {R4: 0x00000011L, R5: 0x00000008L, }), {R4: 0x00000010L, R5: 0x00000008L, }) - self.assertEqual(compute('AND R4, R4, R5 LSR 2 ', {R4: 0xFFFFFFFFL, R5: 0x80000041L, }), {R4: 0x20000010L, R5: 0x80000041L, }) - self.assertEqual(compute('AND R4, R4, R5 ASR 3 ', {R4: 0xF00000FFL, R5: 0x80000081L, }), {R4: 0xF0000010L, R5: 0x80000081L, }) - self.assertEqual(compute('AND R4, R4, R5 ROR 4 ', {R4: 0xFFFFFFFFL, R5: 0x000000FFL, }), {R4: 0xF000000FL, R5: 0x000000FFL, }) - self.assertEqual(compute('AND R4, R4, R5 RRX ', {R4: 0xFFFFFFFFL, R5: 0x00000101L, }), {R4: ExprCompose(ExprInt(0x80L, 31), cf_init), R5: 0x00000101L, }) + self.assertEqual(compute('AND R4, R4, R5 ', {R4: 0xFFFFFFFE, R5: 0x00000001, }), {R4: 0x00000000, R5: 0x00000001, }) + self.assertEqual(compute('AND R4, R4, R5 LSL 1 ', {R4: 0x00000011, R5: 0x00000008, }), {R4: 0x00000010, R5: 0x00000008, }) + self.assertEqual(compute('AND R4, R4, R5 LSR 2 ', {R4: 0xFFFFFFFF, R5: 0x80000041, }), {R4: 0x20000010, R5: 0x80000041, }) + self.assertEqual(compute('AND R4, R4, R5 ASR 3 ', {R4: 0xF00000FF, R5: 0x80000081, }), {R4: 0xF0000010, R5: 0x80000081, }) + self.assertEqual(compute('AND R4, R4, R5 ROR 4 ', {R4: 0xFFFFFFFF, R5: 0x000000FF, }), {R4: 0xF000000F, R5: 0x000000FF, }) + self.assertEqual(compute('AND R4, R4, R5 RRX ', {R4: 0xFFFFFFFF, R5: 0x00000101, }), {R4: ExprCompose(ExprInt(0x80, 31), cf_init), R5: 0x00000101, }) # §A8.8.15: AND{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, <type> <Rs> - self.assertEqual(compute('AND R4, R6, R4 LSL R5', {R4: 0x00000001L, R5: 0x00000004L, R6: -1, }), {R4: 0x00000010L, R5: 0x00000004L, R6: 0xFFFFFFFFL, }) - self.assertEqual(compute('AND R4, R6, R4 LSR R5', {R4: 0x00000110L, R5: 0x80000004L, R6: -1, }), {R4: 0x00000011L, R5: 0x80000004L, R6: 0xFFFFFFFFL, }) - self.assertEqual(compute('AND R4, R6, R4 ASR R5', {R4: 0x80000010L, R5: 0xF0000001L, R6: -1, }), {R4: 0xC0000008L, R5: 0xF0000001L, R6: 0xFFFFFFFFL, }) - self.assertEqual(compute('AND R4, R6, R4 ROR R5', {R4: 0x000000FFL, R5: 0x00000F04L, R6: -1, }), {R4: 0xF000000FL, R5: 0x00000F04L, R6: 0xFFFFFFFFL, }) + self.assertEqual(compute('AND R4, R6, R4 LSL R5', {R4: 0x00000001, R5: 0x00000004, R6: -1, }), {R4: 0x00000010, R5: 0x00000004, R6: 0xFFFFFFFF, }) + self.assertEqual(compute('AND R4, R6, R4 LSR R5', {R4: 0x00000110, R5: 0x80000004, R6: -1, }), {R4: 0x00000011, R5: 0x80000004, R6: 0xFFFFFFFF, }) + self.assertEqual(compute('AND R4, R6, R4 ASR R5', {R4: 0x80000010, R5: 0xF0000001, R6: -1, }), {R4: 0xC0000008, R5: 0xF0000001, R6: 0xFFFFFFFF, }) + self.assertEqual(compute('AND R4, R6, R4 ROR R5', {R4: 0x000000FF, R5: 0x00000F04, R6: -1, }), {R4: 0xF000000F, R5: 0x00000F04, R6: 0xFFFFFFFF, }) def test_ASR(self): # §A8.8.16: ASR{S}{<c>}{<q>} {<Rd>,} <Rm>, #<imm> <==> MOV{S}{<c>}{<q>} {<Rd>,} <Rm>, ASR #<n> @@ -305,191 +308,191 @@ class TestARMSemantic(unittest.TestCase): def test_SUBS(self): # Test against qemu - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x2L, R3: 0x1L}), - { nf: 0L, zf: 0L, cf: 1L, of: 0L, R2: 0x00000002L, R3: 0x1L}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1L, R3: 0x2L}), - { nf: 1L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000001L, R3: 0xFFFFFFFFL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x0L, R3: 0xFFFFFFFFL}), - { nf: 0L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000000L, R3: 0x1L}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0xFFFFFFFFL, R3: 0x0L}), - { nf: 1L, zf: 0L, cf: 1L, of: 0L, R2: 0xFFFFFFFFL, R3: 0xFFFFFFFFL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1L, R3: 0x7FFFFFFFL}), - { nf: 1L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000001L, R3: 0x80000002L}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x7FFFFFFFL, R3: 0x1L}), - { nf: 0L, zf: 0L, cf: 1L, of: 0L, R2: 0x7FFFFFFFL, R3: 0x7FFFFFFEL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000000L, R3: 0x80000001L}), - { nf: 1L, zf: 0L, cf: 0L, of: 0L, R2: 0x80000000L, R3: 0xFFFFFFFFL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000001L, R3: 0x80000000L}), - { nf: 0L, zf: 0L, cf: 1L, of: 0L, R2: 0x80000001L, R3: 0x1L}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x2, R3: 0x1}), + { nf: 0, zf: 0, cf: 1, of: 0, R2: 0x00000002, R3: 0x1}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1, R3: 0x2}), + { nf: 1, zf: 0, cf: 0, of: 0, R2: 0x00000001, R3: 0xFFFFFFFF}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x0, R3: 0xFFFFFFFF}), + { nf: 0, zf: 0, cf: 0, of: 0, R2: 0x00000000, R3: 0x1}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0xFFFFFFFF, R3: 0x0}), + { nf: 1, zf: 0, cf: 1, of: 0, R2: 0xFFFFFFFF, R3: 0xFFFFFFFF}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1, R3: 0x7FFFFFFF}), + { nf: 1, zf: 0, cf: 0, of: 0, R2: 0x00000001, R3: 0x80000002}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x7FFFFFFF, R3: 0x1}), + { nf: 0, zf: 0, cf: 1, of: 0, R2: 0x7FFFFFFF, R3: 0x7FFFFFFE}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000000, R3: 0x80000001}), + { nf: 1, zf: 0, cf: 0, of: 0, R2: 0x80000000, R3: 0xFFFFFFFF}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000001, R3: 0x80000000}), + { nf: 0, zf: 0, cf: 1, of: 0, R2: 0x80000001, R3: 0x1}) def test_CMP(self): # Test against qemu - self.assertEqual(compute('CMP R0, R1 ', {R0: 0x11223344L, R1: 0x88223344L}), - { nf: 1L, zf: 0L, cf: 0L, of: 1L, R0: 0x11223344L, R1: 0x88223344L}) - - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x2L, R3: 0x1L}), - { nf: 0L, zf: 0L, cf: 1L, of: 0L, R2: 0x00000002L, R3: 0x1L}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1L, R3: 0x2L}), - { nf: 1L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000001L, R3: 0xFFFFFFFFL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x0L, R3: 0xFFFFFFFFL}), - { nf: 0L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000000L, R3: 0x1L}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0xFFFFFFFFL, R3: 0x0L}), - { nf: 1L, zf: 0L, cf: 1L, of: 0L, R2: 0xFFFFFFFFL, R3: 0xFFFFFFFFL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1L, R3: 0x7FFFFFFFL}), - { nf: 1L, zf: 0L, cf: 0L, of: 0L, R2: 0x00000001L, R3: 0x80000002L}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x7FFFFFFFL, R3: 0x1L}), - { nf: 0L, zf: 0L, cf: 1L, of: 0L, R2: 0x7FFFFFFFL, R3: 0x7FFFFFFEL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000000L, R3: 0x80000001L}), - { nf: 1L, zf: 0L, cf: 0L, of: 0L, R2: 0x80000000L, R3: 0xFFFFFFFFL}) - self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000001L, R3: 0x80000000L}), - { nf: 0L, zf: 0L, cf: 1L, of: 0L, R2: 0x80000001L, R3: 0x1L}) + self.assertEqual(compute('CMP R0, R1 ', {R0: 0x11223344, R1: 0x88223344}), + { nf: 1, zf: 0, cf: 0, of: 1, R0: 0x11223344, R1: 0x88223344}) + + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x2, R3: 0x1}), + { nf: 0, zf: 0, cf: 1, of: 0, R2: 0x00000002, R3: 0x1}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1, R3: 0x2}), + { nf: 1, zf: 0, cf: 0, of: 0, R2: 0x00000001, R3: 0xFFFFFFFF}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x0, R3: 0xFFFFFFFF}), + { nf: 0, zf: 0, cf: 0, of: 0, R2: 0x00000000, R3: 0x1}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0xFFFFFFFF, R3: 0x0}), + { nf: 1, zf: 0, cf: 1, of: 0, R2: 0xFFFFFFFF, R3: 0xFFFFFFFF}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x1, R3: 0x7FFFFFFF}), + { nf: 1, zf: 0, cf: 0, of: 0, R2: 0x00000001, R3: 0x80000002}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x7FFFFFFF, R3: 0x1}), + { nf: 0, zf: 0, cf: 1, of: 0, R2: 0x7FFFFFFF, R3: 0x7FFFFFFE}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000000, R3: 0x80000001}), + { nf: 1, zf: 0, cf: 0, of: 0, R2: 0x80000000, R3: 0xFFFFFFFF}) + self.assertEqual(compute('SUBS R3, R2, R3 ', {R2: 0x80000001, R3: 0x80000000}), + { nf: 0, zf: 0, cf: 1, of: 0, R2: 0x80000001, R3: 0x1}) def test_ADDS(self): - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {R2: 0x3L, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {R2: 0x3L, R3: 0x2L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {R2: 0xffffffffL, R3: 0xffffffffL, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {R2: 0xffffffffL, R3: 0x0L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {R2: 0x80000000L, R3: 0x7fffffffL, of: 0x1L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {R2: 0x80000000L, R3: 0x1L, of: 0x1L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {R2: 0x1L, R3: 0x80000001L, of: 0x1L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {R2: 0x1L, R3: 0x80000000L, of: 0x1L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x2, R3: 0x1}), {R2: 0x3, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x1, R3: 0x2}), {R2: 0x3, R3: 0x2, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {R2: 0xffffffff, R3: 0xffffffff, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {R2: 0xffffffff, R3: 0x0, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {R2: 0x80000000, R3: 0x7fffffff, of: 0x1, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {R2: 0x80000000, R3: 0x1, of: 0x1, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {R2: 0x1, R3: 0x80000001, of: 0x1, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('ADDS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {R2: 0x1, R3: 0x80000000, of: 0x1, zf: 0x0, cf: 0x1, nf: 0x0}) def test_ANDS(self): - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0xffffffffL}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0x0L}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x0L, R2: 0x80000000L, nf: 0x1L, R3: 0x80000001L}) - self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x80000000L, nf: 0x1L, R3: 0x80000000L}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0xffffffff}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0x0}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x0, R2: 0x80000000, nf: 0x1, R3: 0x80000001}) + self.assertEqual(compute('ANDS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x80000000, nf: 0x1, R3: 0x80000000}) def test_BICS(self): - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x0L, R2: 0x2L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0xffffffffL}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x0L, R2: 0xffffffffL, nf: 0x1L, R3: 0x0L}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x7ffffffeL, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0x80000001L}) - self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x80000000L}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x0, R2: 0x2, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0xffffffff}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x0, R2: 0xffffffff, nf: 0x1, R3: 0x0}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x7ffffffe, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0x80000001}) + self.assertEqual(compute('BICS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x80000000}) def test_CMN(self): - self.assertEqual(compute('CMN R2, R3', {R2: 0x2L, R3: 0x1L}), {R2: 0x2L, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0x1L, R3: 0x2L}), {R2: 0x1L, R3: 0x2L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {R2: 0x0L, R3: 0xffffffffL, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {R2: 0xffffffffL, R3: 0x0L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {R2: 0x1L, R3: 0x7fffffffL, of: 0x1L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {R2: 0x7fffffffL, R3: 0x1L, of: 0x1L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {R2: 0x80000000L, R3: 0x80000001L, of: 0x1L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('CMN R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {R2: 0x80000001L, R3: 0x80000000L, of: 0x1L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x2, R3: 0x1}), {R2: 0x2, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x1, R3: 0x2}), {R2: 0x1, R3: 0x2, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x0, R3: 0xffffffff}), {R2: 0x0, R3: 0xffffffff, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMN R2, R3', {R2: 0xffffffff, R3: 0x0}), {R2: 0xffffffff, R3: 0x0, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x1, R3: 0x7fffffff}), {R2: 0x1, R3: 0x7fffffff, of: 0x1, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x7fffffff, R3: 0x1}), {R2: 0x7fffffff, R3: 0x1, of: 0x1, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x80000000, R3: 0x80000001}), {R2: 0x80000000, R3: 0x80000001, of: 0x1, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('CMN R2, R3', {R2: 0x80000001, R3: 0x80000000}), {R2: 0x80000001, R3: 0x80000000, of: 0x1, zf: 0x0, cf: 0x1, nf: 0x0}) def test_CMP(self): - self.assertEqual(compute('CMP R2, R3', {R2: 0x2L, R3: 0x1L}), {R2: 0x2L, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0x1L, R3: 0x2L}), {R2: 0x1L, R3: 0x2L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {R2: 0x0L, R3: 0xffffffffL, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {R2: 0xffffffffL, R3: 0x0L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x1L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {R2: 0x1L, R3: 0x7fffffffL, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {R2: 0x7fffffffL, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {R2: 0x80000000L, R3: 0x80000001L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('CMP R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {R2: 0x80000001L, R3: 0x80000000L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x2, R3: 0x1}), {R2: 0x2, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x1, R3: 0x2}), {R2: 0x1, R3: 0x2, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x0, R3: 0xffffffff}), {R2: 0x0, R3: 0xffffffff, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('CMP R2, R3', {R2: 0xffffffff, R3: 0x0}), {R2: 0xffffffff, R3: 0x0, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x1}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x1, R3: 0x7fffffff}), {R2: 0x1, R3: 0x7fffffff, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x7fffffff, R3: 0x1}), {R2: 0x7fffffff, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x80000000, R3: 0x80000001}), {R2: 0x80000000, R3: 0x80000001, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('CMP R2, R3', {R2: 0x80000001, R3: 0x80000000}), {R2: 0x80000001, R3: 0x80000000, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) def test_EORS(self): - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x0L, R2: 0x3L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x0L, R2: 0x3L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x0L, R2: 0xffffffffL, nf: 0x1L, R3: 0xffffffffL}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x0L, R2: 0xffffffffL, nf: 0x1L, R3: 0x0L}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x0L, R2: 0x7ffffffeL, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x7ffffffeL, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x80000001L}) - self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x80000000L}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x0, R2: 0x3, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x0, R2: 0x3, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x0, R2: 0xffffffff, nf: 0x1, R3: 0xffffffff}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x0, R2: 0xffffffff, nf: 0x1, R3: 0x0}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x0, R2: 0x7ffffffe, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x7ffffffe, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x80000001}) + self.assertEqual(compute('EORS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x80000000}) def test_MULS(self): - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x0L, R2: 0x2L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x0L, R2: 0x2L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0xffffffffL}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0x0L}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x0L, R2: 0x7fffffffL, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x7fffffffL, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x0L, R2: 0x80000000L, nf: 0x1L, R3: 0x80000001L}) - self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x80000000L, nf: 0x1L, R3: 0x80000000L}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x0, R2: 0x2, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x0, R2: 0x2, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0xffffffff}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0x0}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x0, R2: 0x7fffffff, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x7fffffff, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x0, R2: 0x80000000, nf: 0x1, R3: 0x80000001}) + self.assertEqual(compute('MULS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x80000000, nf: 0x1, R3: 0x80000000}) def test_ORRS(self): - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x0L, R2: 0x3L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x0L, R2: 0x3L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x0L, R2: 0xffffffffL, nf: 0x1L, R3: 0xffffffffL}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x0L, R2: 0xffffffffL, nf: 0x1L, R3: 0x0L}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x0L, R2: 0x7fffffffL, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x7fffffffL, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x0L, R2: 0x80000001L, nf: 0x1L, R3: 0x80000001L}) - self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x80000001L, nf: 0x1L, R3: 0x80000000L}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x0, R2: 0x3, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x0, R2: 0x3, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x0, R2: 0xffffffff, nf: 0x1, R3: 0xffffffff}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x0, R2: 0xffffffff, nf: 0x1, R3: 0x0}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x0, R2: 0x7fffffff, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x7fffffff, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x0, R2: 0x80000001, nf: 0x1, R3: 0x80000001}) + self.assertEqual(compute('ORRS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x80000001, nf: 0x1, R3: 0x80000000}) def test_RSBS(self): - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {R2: 0xffffffffL, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {R2: 0x1L, R3: 0x2L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {R2: 0xffffffffL, R3: 0xffffffffL, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x1L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {R2: 0x1L, R3: 0x0L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {R2: 0x7ffffffeL, R3: 0x7fffffffL, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {R2: 0x80000002L, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {R2: 0x1L, R3: 0x80000001L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {R2: 0xffffffffL, R3: 0x80000000L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x2, R3: 0x1}), {R2: 0xffffffff, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x1, R3: 0x2}), {R2: 0x1, R3: 0x2, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {R2: 0xffffffff, R3: 0xffffffff, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x1}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {R2: 0x1, R3: 0x0, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {R2: 0x7ffffffe, R3: 0x7fffffff, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {R2: 0x80000002, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {R2: 0x1, R3: 0x80000001, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('RSBS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {R2: 0xffffffff, R3: 0x80000000, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) def test_SUBS(self): - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x2L, R3: 0x1L}), {R2: 0x1L, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x1L, R3: 0x2L}), {R2: 0xffffffffL, R3: 0x2L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {R2: 0x1L, R3: 0xffffffffL, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x0L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {R2: 0xffffffffL, R3: 0x0L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x1L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {R2: 0x80000002L, R3: 0x7fffffffL, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {R2: 0x7ffffffeL, R3: 0x1L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {R2: 0xffffffffL, R3: 0x80000001L, of: 0x0L, zf: 0x0L, cf: 0x0L, nf: 0x1L}) - self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {R2: 0x1L, R3: 0x80000000L, of: 0x0L, zf: 0x0L, cf: 0x1L, nf: 0x0L}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x2, R3: 0x1}), {R2: 0x1, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x1, R3: 0x2}), {R2: 0xffffffff, R3: 0x2, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x0, R3: 0xffffffff}), {R2: 0x1, R3: 0xffffffff, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x0}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0xffffffff, R3: 0x0}), {R2: 0xffffffff, R3: 0x0, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x1}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x1, R3: 0x7fffffff}), {R2: 0x80000002, R3: 0x7fffffff, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x7fffffff, R3: 0x1}), {R2: 0x7ffffffe, R3: 0x1, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x80000000, R3: 0x80000001}), {R2: 0xffffffff, R3: 0x80000001, of: 0x0, zf: 0x0, cf: 0x0, nf: 0x1}) + self.assertEqual(compute('SUBS R2, R2, R3', {R2: 0x80000001, R3: 0x80000000}), {R2: 0x1, R3: 0x80000000, of: 0x0, zf: 0x0, cf: 0x1, nf: 0x0}) def test_TEQ(self): - self.assertEqual(compute('TEQ R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x0L, R2: 0x2L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x0L, R2: 0x0L, nf: 0x1L, R3: 0xffffffffL}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x0L, R2: 0xffffffffL, nf: 0x1L, R3: 0x0L}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x7fffffffL, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x0L, R2: 0x80000000L, nf: 0x0L, R3: 0x80000001L}) - self.assertEqual(compute('TEQ R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x80000001L, nf: 0x0L, R3: 0x80000000L}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x0, R2: 0x2, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x0, R2: 0x0, nf: 0x1, R3: 0xffffffff}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x0, R2: 0xffffffff, nf: 0x1, R3: 0x0}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x7fffffff, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x0, R2: 0x80000000, nf: 0x0, R3: 0x80000001}) + self.assertEqual(compute('TEQ R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x80000001, nf: 0x0, R3: 0x80000000}) def test_TST(self): - self.assertEqual(compute('TST R2, R3', {R2: 0x2L, R3: 0x1L}), {zf: 0x1L, R2: 0x2L, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('TST R2, R3', {R2: 0x1L, R3: 0x2L}), {zf: 0x1L, R2: 0x1L, nf: 0x0L, R3: 0x2L}) - self.assertEqual(compute('TST R2, R3', {R2: 0x0L, R3: 0xffffffffL}), {zf: 0x1L, R2: 0x0L, nf: 0x0L, R3: 0xffffffffL}) - self.assertEqual(compute('TST R2, R3', {R2: 0xffffffffL, R3: 0x0L}), {zf: 0x1L, R2: 0xffffffffL, nf: 0x0L, R3: 0x0L}) - self.assertEqual(compute('TST R2, R3', {R2: 0x1L, R3: 0x7fffffffL}), {zf: 0x0L, R2: 0x1L, nf: 0x0L, R3: 0x7fffffffL}) - self.assertEqual(compute('TST R2, R3', {R2: 0x7fffffffL, R3: 0x1L}), {zf: 0x0L, R2: 0x7fffffffL, nf: 0x0L, R3: 0x1L}) - self.assertEqual(compute('TST R2, R3', {R2: 0x80000000L, R3: 0x80000001L}), {zf: 0x0L, R2: 0x80000000L, nf: 0x1L, R3: 0x80000001L}) - self.assertEqual(compute('TST R2, R3', {R2: 0x80000001L, R3: 0x80000000L}), {zf: 0x0L, R2: 0x80000001L, nf: 0x1L, R3: 0x80000000L}) + self.assertEqual(compute('TST R2, R3', {R2: 0x2, R3: 0x1}), {zf: 0x1, R2: 0x2, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('TST R2, R3', {R2: 0x1, R3: 0x2}), {zf: 0x1, R2: 0x1, nf: 0x0, R3: 0x2}) + self.assertEqual(compute('TST R2, R3', {R2: 0x0, R3: 0xffffffff}), {zf: 0x1, R2: 0x0, nf: 0x0, R3: 0xffffffff}) + self.assertEqual(compute('TST R2, R3', {R2: 0xffffffff, R3: 0x0}), {zf: 0x1, R2: 0xffffffff, nf: 0x0, R3: 0x0}) + self.assertEqual(compute('TST R2, R3', {R2: 0x1, R3: 0x7fffffff}), {zf: 0x0, R2: 0x1, nf: 0x0, R3: 0x7fffffff}) + self.assertEqual(compute('TST R2, R3', {R2: 0x7fffffff, R3: 0x1}), {zf: 0x0, R2: 0x7fffffff, nf: 0x0, R3: 0x1}) + self.assertEqual(compute('TST R2, R3', {R2: 0x80000000, R3: 0x80000001}), {zf: 0x0, R2: 0x80000000, nf: 0x1, R3: 0x80000001}) + self.assertEqual(compute('TST R2, R3', {R2: 0x80000001, R3: 0x80000000}), {zf: 0x0, R2: 0x80000001, nf: 0x1, R3: 0x80000000}) def test_UMUL(self): - self.assertEqual(compute('UMULL R1, R2, R4, R5', {R4: 0x0L, R5: 0x0L}), {R1: 0x0L, R2: 0x0L, R4: 0x0L, R5: 0x0L}) - self.assertEqual(compute('UMULL R0, R1, R2, R3', {R2: 0x1L, R3: 0x80808080L}), {R0: 0x80808080L, R1: 0x0L, R2: 0x1L, R3: 0x80808080L}) - self.assertEqual(compute('UMULL R2, R3, R4, R5', {R4: 0x12345678L, R5: 0x87654321L}), {R2: 0x70b88d78L, R3: 0x09a0cd05L, R4: 0x12345678L, R5: 0x87654321L}) - self.assertEqual(compute('UMULL R2, R3, R4, R5', {R4: 0xffffffffL, R5: 0x00000002L}), {R2: 0xfffffffeL, R3: 0x00000001L, R4: 0xffffffffL, R5: 0x00000002L}) + self.assertEqual(compute('UMULL R1, R2, R4, R5', {R4: 0x0, R5: 0x0}), {R1: 0x0, R2: 0x0, R4: 0x0, R5: 0x0}) + self.assertEqual(compute('UMULL R0, R1, R2, R3', {R2: 0x1, R3: 0x80808080}), {R0: 0x80808080, R1: 0x0, R2: 0x1, R3: 0x80808080}) + self.assertEqual(compute('UMULL R2, R3, R4, R5', {R4: 0x12345678, R5: 0x87654321}), {R2: 0x70b88d78, R3: 0x09a0cd05, R4: 0x12345678, R5: 0x87654321}) + self.assertEqual(compute('UMULL R2, R3, R4, R5', {R4: 0xffffffff, R5: 0x00000002}), {R2: 0xfffffffe, R3: 0x00000001, R4: 0xffffffff, R5: 0x00000002}) def test_UMLAL(self): - self.assertEqual(compute('UMLAL R1, R2, R4, R5', {R1: 0x0L, R2: 0x0L, R4: 0x1L, R5: 0x0L}), {R1: 0x0L, R2: 0x0L, R4: 0x1L, R5: 0x0L}) - self.assertEqual(compute('UMLAL R0, R1, R2, R3', {R0: 0x0L, R1: 0x0L, R2: 0x1L, R3: 0x80808080L}), {R0: 0x80808080L, R1: 0x0L, R2: 0x1L, R3: 0x80808080L}) - self.assertEqual(compute('UMLAL R2, R3, R4, R5', {R2: 0xffffffffL, R3: 0x0L, R4: 0x12345678L, R5: 0x87654321L}), {R2: 0x70b88d77L, R3: 0x09a0cd06L, R4: 0x12345678L, R5: 0x87654321L}) - self.assertEqual(compute('UMLAL R2, R3, R4, R5', {R2: 0xffffffffL, R3: 0x2L, R4: 0x12345678L, R5: 0x87654321L}), {R2: 0x70b88d77L, R3: 0x09a0cd08L, R4: 0x12345678L, R5: 0x87654321L}) + self.assertEqual(compute('UMLAL R1, R2, R4, R5', {R1: 0x0, R2: 0x0, R4: 0x1, R5: 0x0}), {R1: 0x0, R2: 0x0, R4: 0x1, R5: 0x0}) + self.assertEqual(compute('UMLAL R0, R1, R2, R3', {R0: 0x0, R1: 0x0, R2: 0x1, R3: 0x80808080}), {R0: 0x80808080, R1: 0x0, R2: 0x1, R3: 0x80808080}) + self.assertEqual(compute('UMLAL R2, R3, R4, R5', {R2: 0xffffffff, R3: 0x0, R4: 0x12345678, R5: 0x87654321}), {R2: 0x70b88d77, R3: 0x09a0cd06, R4: 0x12345678, R5: 0x87654321}) + self.assertEqual(compute('UMLAL R2, R3, R4, R5', {R2: 0xffffffff, R3: 0x2, R4: 0x12345678, R5: 0x87654321}), {R2: 0x70b88d77, R3: 0x09a0cd08, R4: 0x12345678, R5: 0x87654321}) def test_SMUL(self): - self.assertEqual(compute('SMULL R1, R2, R4, R5', {R4: 0x0L, R5: 0x0L}), {R1: 0x0L, R2: 0x0L, R4: 0x0L, R5: 0x0L}) - self.assertEqual(compute('SMULL R0, R1, R2, R3', {R2: 0x1L, R3: 0x80808080L}), {R0: 0x80808080L, R1: 0xffffffffL, R2: 0x1L, R3: 0x80808080L}) - self.assertEqual(compute('SMULL R0, R1, R2, R3', {R2: 0xffff0000L, R3: 0xffff0000L}), {R0: 0x0L, R1: 0x1L, R2: 0xffff0000L, R3: 0xffff0000L}) - self.assertEqual(compute('SMULL R2, R3, R4, R5', {R4: 0x12345678L, R5: 0x87654321L}), {R2: 0x70b88d78L, R3: 0xf76c768dL, R4: 0x12345678L, R5: 0x87654321L}) - self.assertEqual(compute('SMULL R2, R3, R4, R5', {R4: 0xffffffffL, R5: 0x00000002L}), {R2: 0xfffffffeL, R3: 0xffffffffL, R4: 0xffffffffL, R5: 0x00000002L}) + self.assertEqual(compute('SMULL R1, R2, R4, R5', {R4: 0x0, R5: 0x0}), {R1: 0x0, R2: 0x0, R4: 0x0, R5: 0x0}) + self.assertEqual(compute('SMULL R0, R1, R2, R3', {R2: 0x1, R3: 0x80808080}), {R0: 0x80808080, R1: 0xffffffff, R2: 0x1, R3: 0x80808080}) + self.assertEqual(compute('SMULL R0, R1, R2, R3', {R2: 0xffff0000, R3: 0xffff0000}), {R0: 0x0, R1: 0x1, R2: 0xffff0000, R3: 0xffff0000}) + self.assertEqual(compute('SMULL R2, R3, R4, R5', {R4: 0x12345678, R5: 0x87654321}), {R2: 0x70b88d78, R3: 0xf76c768d, R4: 0x12345678, R5: 0x87654321}) + self.assertEqual(compute('SMULL R2, R3, R4, R5', {R4: 0xffffffff, R5: 0x00000002}), {R2: 0xfffffffe, R3: 0xffffffff, R4: 0xffffffff, R5: 0x00000002}) def test_SMLAL(self): - self.assertEqual(compute('SMLAL R1, R2, R4, R5', {R1: 0x0L, R2: 0x0L, R4: 0x1L, R5: 0x0L}), {R1: 0x0L, R2: 0x0L, R4: 0x1L, R5: 0x0L}) - self.assertEqual(compute('SMLAL R0, R1, R2, R3', {R0: 0x0L, R1: 0x0L, R2: 0x1L, R3: 0x80808080L}), {R0: 0x80808080L, R1: 0xffffffffL, R2: 0x1L, R3: 0x80808080L}) - self.assertEqual(compute('SMLAL R2, R3, R4, R5', {R2: 0xffffffffL, R3: 0x0L, R4: 0x12345678L, R5: 0x87654321L}), {R2: 0x70b88d77L, R3: 0xf76c768eL, R4: 0x12345678L, R5: 0x87654321L}) - self.assertEqual(compute('SMLAL R2, R3, R4, R5', {R2: 0xffffffffL, R3: 0x00000002L, R4: 0x12345678L, R5: 0x87654321L}), {R2: 0x70b88d77L, R3: 0xf76c7690L, R4: 0x12345678L, R5: 0x87654321L}) + self.assertEqual(compute('SMLAL R1, R2, R4, R5', {R1: 0x0, R2: 0x0, R4: 0x1, R5: 0x0}), {R1: 0x0, R2: 0x0, R4: 0x1, R5: 0x0}) + self.assertEqual(compute('SMLAL R0, R1, R2, R3', {R0: 0x0, R1: 0x0, R2: 0x1, R3: 0x80808080}), {R0: 0x80808080, R1: 0xffffffff, R2: 0x1, R3: 0x80808080}) + self.assertEqual(compute('SMLAL R2, R3, R4, R5', {R2: 0xffffffff, R3: 0x0, R4: 0x12345678, R5: 0x87654321}), {R2: 0x70b88d77, R3: 0xf76c768e, R4: 0x12345678, R5: 0x87654321}) + self.assertEqual(compute('SMLAL R2, R3, R4, R5', {R2: 0xffffffff, R3: 0x00000002, R4: 0x12345678, R5: 0x87654321}), {R2: 0x70b88d77, R3: 0xf76c7690, R4: 0x12345678, R5: 0x87654321}) if __name__ == '__main__': testsuite = unittest.TestLoader().loadTestsFromTestCase(TestARMSemantic) diff --git a/test/arch/mep/asm/test_asm.py b/test/arch/mep/asm/test_asm.py index ddf91ed6..217def86 100644 --- a/test/arch/mep/asm/test_asm.py +++ b/test/arch/mep/asm/test_asm.py @@ -1,9 +1,11 @@ # Toshiba MeP-c4 - Misc unit tests # Guillaume Valadon <guillaume@valadon.net> +from __future__ import print_function +from miasm2.core.utils import decode_hex, encode_hex from miasm2.arch.mep.arch import mn_mep -class TestMisc: +class TestMisc(object): def test(self): @@ -18,21 +20,23 @@ class TestMisc: unit_tests += [("SW R7, 0x50(SP)", "4752")] for mn_str, mn_hex in unit_tests: - print "-" * 49 # Tests separation + print("-" * 49) # Tests separation # Dissassemble - mn_bin = mn_hex.decode("hex") + mn_bin = decode_hex(mn_hex) mn = mn_mep.dis(mn_bin, "b") - print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + print("dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20))) assert(str(mn) == mn_str) # dissassemble assertion # Assemble and return all possible candidates instr = mn_mep.fromstring(str(mn), "b") instr.mode = "b" - asm_list = [i.encode("hex") for i in mn_mep.asm(instr)] + asm_list = [encode_hex(i).decode() for i in mn_mep.asm(instr)] # Print the results - print "asm: %s -> %s" % (mn_str.rjust(20), - ", ".join(asm_list).rjust(20)) + print("asm: %s -> %s" % ( + mn_str.rjust(20), + ", ".join(asm_list).rjust(20)) + ) assert(mn_hex in asm_list) # assemble assertion diff --git a/test/arch/mep/asm/test_major_opcode_0.py b/test/arch/mep/asm/test_major_opcode_0.py index 69a9685c..db288e47 100644 --- a/test/arch/mep/asm/test_major_opcode_0.py +++ b/test/arch/mep/asm/test_major_opcode_0.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor0: +class TestMajor0(object): def test_MOV(self): """Test the MOV instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_1.py b/test/arch/mep/asm/test_major_opcode_1.py index c401bfd2..3a3c6538 100644 --- a/test/arch/mep/asm/test_major_opcode_1.py +++ b/test/arch/mep/asm/test_major_opcode_1.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor1: +class TestMajor1(object): def test_OR(self): """Test the OR instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_10.py b/test/arch/mep/asm/test_major_opcode_10.py index f1089c61..e10992c8 100644 --- a/test/arch/mep/asm/test_major_opcode_10.py +++ b/test/arch/mep/asm/test_major_opcode_10.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor10: +class TestMajor10(object): def test_BEQZ(self): """Test the BEQZ instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_11.py b/test/arch/mep/asm/test_major_opcode_11.py index b5d8a278..38f93e8b 100644 --- a/test/arch/mep/asm/test_major_opcode_11.py +++ b/test/arch/mep/asm/test_major_opcode_11.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor11: +class TestMajor11(object): def test_BRA(self): """Test the BRA instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_12.py b/test/arch/mep/asm/test_major_opcode_12.py index e721d287..c353861e 100644 --- a/test/arch/mep/asm/test_major_opcode_12.py +++ b/test/arch/mep/asm/test_major_opcode_12.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor12: +class TestMajor12(object): def test_ADD3(self): """Test the ADD3 instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_13.py b/test/arch/mep/asm/test_major_opcode_13.py index 996b47e3..bf95572c 100644 --- a/test/arch/mep/asm/test_major_opcode_13.py +++ b/test/arch/mep/asm/test_major_opcode_13.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor13: +class TestMajor13(object): def test_MOVU(self): """Test the MOVU instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_14.py b/test/arch/mep/asm/test_major_opcode_14.py index 6ad3c757..9ec99550 100644 --- a/test/arch/mep/asm/test_major_opcode_14.py +++ b/test/arch/mep/asm/test_major_opcode_14.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor14: +class TestMajor14(object): def test_BEQI(self): """Test the BEQI instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_15.py b/test/arch/mep/asm/test_major_opcode_15.py index ecad8b3f..891626e8 100644 --- a/test/arch/mep/asm/test_major_opcode_15.py +++ b/test/arch/mep/asm/test_major_opcode_15.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor15: +class TestMajor15(object): def test_DSP(self): """Test the DSP instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_2.py b/test/arch/mep/asm/test_major_opcode_2.py index 07743813..4cbe36ca 100644 --- a/test/arch/mep/asm/test_major_opcode_2.py +++ b/test/arch/mep/asm/test_major_opcode_2.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor2: +class TestMajor2(object): def test_BSETM(self): """Test the BSETM instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_3.py b/test/arch/mep/asm/test_major_opcode_3.py index 3e0c5864..793a4e87 100644 --- a/test/arch/mep/asm/test_major_opcode_3.py +++ b/test/arch/mep/asm/test_major_opcode_3.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor3: +class TestMajor3(object): def test_SWCPI(self): """Test the SWCPI instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_4.py b/test/arch/mep/asm/test_major_opcode_4.py index e52acf3f..a6f57ac2 100644 --- a/test/arch/mep/asm/test_major_opcode_4.py +++ b/test/arch/mep/asm/test_major_opcode_4.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor4: +class TestMajor4(object): def test_ADD3(self): """Test the ADD3 instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_5.py b/test/arch/mep/asm/test_major_opcode_5.py index e39230f4..2250c123 100644 --- a/test/arch/mep/asm/test_major_opcode_5.py +++ b/test/arch/mep/asm/test_major_opcode_5.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor5: +class TestMajor5(object): def test_MOV(self): """Test the MOV instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_6.py b/test/arch/mep/asm/test_major_opcode_6.py index 5eda1ea6..e10d1064 100644 --- a/test/arch/mep/asm/test_major_opcode_6.py +++ b/test/arch/mep/asm/test_major_opcode_6.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor6: +class TestMajor6(object): def test_ADD(self): """Test the ADD instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_7.py b/test/arch/mep/asm/test_major_opcode_7.py index 15a045da..1b1fba78 100644 --- a/test/arch/mep/asm/test_major_opcode_7.py +++ b/test/arch/mep/asm/test_major_opcode_7.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor7: +class TestMajor7(object): def test_DI(self): """Test the DI instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_8.py b/test/arch/mep/asm/test_major_opcode_8.py index 7f15f9e8..900cf004 100644 --- a/test/arch/mep/asm/test_major_opcode_8.py +++ b/test/arch/mep/asm/test_major_opcode_8.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor8: +class TestMajor8(object): def test_SB(self): """Test the SB instruction""" diff --git a/test/arch/mep/asm/test_major_opcode_9.py b/test/arch/mep/asm/test_major_opcode_9.py index b8949887..9e59a863 100644 --- a/test/arch/mep/asm/test_major_opcode_9.py +++ b/test/arch/mep/asm/test_major_opcode_9.py @@ -4,7 +4,7 @@ from ut_helpers_asm import check_instruction -class TestMajor9: +class TestMajor9(object): def test_ADD3(self): """Test the ADD3 instruction""" diff --git a/test/arch/mep/asm/ut_helpers_asm.py b/test/arch/mep/asm/ut_helpers_asm.py index af010afc..26520787 100644 --- a/test/arch/mep/asm/ut_helpers_asm.py +++ b/test/arch/mep/asm/ut_helpers_asm.py @@ -1,6 +1,11 @@ # Toshiba MeP-c4 - unit tests helpers # Guillaume Valadon <guillaume@valadon.net> +from __future__ import print_function + +from builtins import range + +from miasm2.core.utils import decode_hex, encode_hex from miasm2.arch.mep.arch import mn_mep from miasm2.core.cpu import Disasm_Exception from miasm2.core.locationdb import LocationDB @@ -11,7 +16,7 @@ import re def dis(mn_hex): """Disassembly helper""" - mn_bin = mn_hex.decode("hex") + mn_bin = decode_hex(mn_hex) try: return mn_mep.dis(mn_bin, "b") except Disasm_Exception: @@ -50,7 +55,7 @@ def check_instruction(mn_str, mn_hex, multi=None, offset=0): addr = loc_db.get_location_offset(mn.args[i].loc_key) mn.args[i] = ExprInt(addr, args_size[i]) - print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + print("dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20))) assert(str(mn) == mn_str) # disassemble assertion # Assemble and return all possible candidates @@ -59,21 +64,25 @@ def check_instruction(mn_str, mn_hex, multi=None, offset=0): instr.mode = "b" if instr.offset: instr.fixDstOffset() - asm_list = [i.encode("hex") for i in mn_mep.asm(instr)] + asm_list = [encode_hex(i).decode() for i in mn_mep.asm(instr)] # Check instructions variants if multi: - print "Instructions count:", len(asm_list) + print("Instructions count:", len(asm_list)) assert(len(asm_list) == multi) # Ensure that variants correspond to the same disassembled instruction - for mn_hex in asm_list: - mn = dis(mn_hex) - print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + for mn_hex_tmp in asm_list: + mn = dis(mn_hex_tmp) + print("dis: %s -> %s" % (mn_hex_tmp.rjust(20), str(mn).rjust(20))) # Check the assembly result - print "asm: %s -> %s" % (mn_str.rjust(20), - ", ".join(asm_list).rjust(20)) + print( + "asm: %s -> %s" % ( + mn_str.rjust(20), + ", ".join(asm_list).rjust(20) + ) + ) assert(mn_hex in asm_list) # assemble assertion @@ -83,10 +92,10 @@ def launch_tests(obj): test_methods = [name for name in dir(obj) if name.startswith("test")] for method in test_methods: - print method + print(method) try: getattr(obj, method)() except AttributeError as e: - print "Method not found: %s" % method + print("Method not found: %s" % method) assert(False) - print '-' * 42 + print('-' * 42) diff --git a/test/arch/mep/ir/test_arithmetic.py b/test/arch/mep/ir/test_arithmetic.py index 6da938e9..2e0dbf32 100644 --- a/test/arch/mep/ir/test_arithmetic.py +++ b/test/arch/mep/ir/test_arithmetic.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestArithmetic: +class TestArithmetic(object): def test_add3(self): """Test ADD3 execution""" diff --git a/test/arch/mep/ir/test_bitmanipulation.py b/test/arch/mep/ir/test_bitmanipulation.py index 06466f9d..f4ea2f29 100644 --- a/test/arch/mep/ir/test_bitmanipulation.py +++ b/test/arch/mep/ir/test_bitmanipulation.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprMem -class TestBitManipulation: +class TestBitManipulation(object): def test_bsetm(self): """Test BSETM execution""" diff --git a/test/arch/mep/ir/test_branchjump.py b/test/arch/mep/ir/test_branchjump.py index 3f78558b..7e0953fd 100644 --- a/test/arch/mep/ir/test_branchjump.py +++ b/test/arch/mep/ir/test_branchjump.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt -class TestBranchJump: +class TestBranchJump(object): def test_bra(self): """Test BRA execution""" diff --git a/test/arch/mep/ir/test_control.py b/test/arch/mep/ir/test_control.py index a1b3c7c7..92dcb371 100644 --- a/test/arch/mep/ir/test_control.py +++ b/test/arch/mep/ir/test_control.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestControl: +class TestControl(object): def test_stc(self): """Test STC execution""" diff --git a/test/arch/mep/ir/test_coprocessor.py b/test/arch/mep/ir/test_coprocessor.py index e9b745ff..e9829c08 100644 --- a/test/arch/mep/ir/test_coprocessor.py +++ b/test/arch/mep/ir/test_coprocessor.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprMem, ExprInt -class TestCoprocessor: +class TestCoprocessor(object): def test_swcp(self): """Test SWCP execution""" diff --git a/test/arch/mep/ir/test_datacache.py b/test/arch/mep/ir/test_datacache.py index a462315d..7d92f9c7 100644 --- a/test/arch/mep/ir/test_datacache.py +++ b/test/arch/mep/ir/test_datacache.py @@ -4,7 +4,7 @@ from ut_helpers_ir import exec_instruction -class TestDataCache: +class TestDataCache(object): def test_cache(self): """Test CACHE execution""" diff --git a/test/arch/mep/ir/test_debug.py b/test/arch/mep/ir/test_debug.py index 53f4064d..b25e3a19 100644 --- a/test/arch/mep/ir/test_debug.py +++ b/test/arch/mep/ir/test_debug.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestDebug: +class TestDebug(object): def test_dret(self): """Test DRET execution""" diff --git a/test/arch/mep/ir/test_divide.py b/test/arch/mep/ir/test_divide.py index a63d0c5e..e3e4cb99 100644 --- a/test/arch/mep/ir/test_divide.py +++ b/test/arch/mep/ir/test_divide.py @@ -7,7 +7,7 @@ from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp from miasm2.jitter.csts import EXCEPT_DIV_BY_ZERO -class TestDivide: +class TestDivide(object): def test_div(self): """Test DIV execution""" diff --git a/test/arch/mep/ir/test_extension.py b/test/arch/mep/ir/test_extension.py index 72423220..10f16ebf 100644 --- a/test/arch/mep/ir/test_extension.py +++ b/test/arch/mep/ir/test_extension.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprMem, ExprInt -class TestExtension: +class TestExtension(object): def test_extb(self): """Test EXTB execution""" diff --git a/test/arch/mep/ir/test_ir.py b/test/arch/mep/ir/test_ir.py index 3fec9ec9..be717db8 100644 --- a/test/arch/mep/ir/test_ir.py +++ b/test/arch/mep/ir/test_ir.py @@ -1,6 +1,9 @@ # Toshiba MeP-c4 - Misc unit tests # Guillaume Valadon <guillaume@valadon.net> +from __future__ import print_function + +from miasm2.core.utils import decode_hex from miasm2.arch.mep.arch import mn_mep from miasm2.arch.mep.regs import regs_init from miasm2.arch.mep.ira import ir_mepb, ir_a_mepb @@ -9,7 +12,7 @@ from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.core.locationdb import LocationDB -class TestMisc: +class TestMisc(object): def test(self): @@ -18,16 +21,16 @@ class TestMisc: def exec_instruction(hex_asm, init_values): """Symbolically execute an instruction""" - print "Hex:", hex_asm + print("Hex:", hex_asm) # Disassemble an instruction - mn = mn_mep.dis(hex_asm.decode("hex"), "b") - print "Dis:", mn + mn = mn_mep.dis(decode_hex(hex_asm), "b") + print("Dis:", mn) # Get the IR im = ir_mepb() iir, eiir, = im.get_ir(mn) - print "\nInternal representation:", iir + print("\nInternal representation:", iir) # Symbolic execution loc_db = LocationDB() @@ -37,13 +40,13 @@ class TestMisc: for reg_expr_id, reg_expr_value in init_values: sb.symbols[reg_expr_id] = reg_expr_value - print "\nModified registers:", [reg for reg in sb.modified(mems=False)] - print "Modified memories:", [mem for mem in sb.modified()] + print("\nModified registers:", [reg for reg in sb.modified(mems=False)]) + print("Modified memories:", [mem for mem in sb.modified()]) - print "\nFinal registers:" + print("\nFinal registers:") sb.dump(mems=False) - print "\nFinal mems:" + print("\nFinal mems:") sb.dump() for hex_asm, init_values in [("6108", [(ExprId("R1", 32), ExprInt(0x40, 32))]), @@ -52,5 +55,5 @@ class TestMisc: ("0948", [(ExprId("R4", 32), ExprInt(0x41, 32)), (ExprId("R9", 32), ExprInt(0x28, 32)), (ExprMem(ExprInt(0x41, 32), 8), ExprInt(0, 8))])]: - print "-" * 49 # Tests separation + print("-" * 49) # Tests separation exec_instruction(hex_asm, init_values) diff --git a/test/arch/mep/ir/test_ldz.py b/test/arch/mep/ir/test_ldz.py index 02960b60..668030c8 100644 --- a/test/arch/mep/ir/test_ldz.py +++ b/test/arch/mep/ir/test_ldz.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestLdz: +class TestLdz(object): def test_ldz(self): """Test LDZ execution""" diff --git a/test/arch/mep/ir/test_loadstore.py b/test/arch/mep/ir/test_loadstore.py index c6b40d55..22cb4304 100644 --- a/test/arch/mep/ir/test_loadstore.py +++ b/test/arch/mep/ir/test_loadstore.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprMem, ExprInt -class TestLoadStore: +class TestLoadStore(object): def test_sb(self): """Test SB execution""" diff --git a/test/arch/mep/ir/test_logical.py b/test/arch/mep/ir/test_logical.py index 61cbbf0a..e78b5488 100644 --- a/test/arch/mep/ir/test_logical.py +++ b/test/arch/mep/ir/test_logical.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestLogical: +class TestLogical(object): def test_or(self): """Test OR execution""" diff --git a/test/arch/mep/ir/test_move.py b/test/arch/mep/ir/test_move.py index 56a4225e..8da7a18a 100644 --- a/test/arch/mep/ir/test_move.py +++ b/test/arch/mep/ir/test_move.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprMem, ExprInt -class TestMove: +class TestMove(object): def test_mov(self): """Test MOV execution""" diff --git a/test/arch/mep/ir/test_multiply.py b/test/arch/mep/ir/test_multiply.py index 0618f69f..5673994c 100644 --- a/test/arch/mep/ir/test_multiply.py +++ b/test/arch/mep/ir/test_multiply.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestMultiply: +class TestMultiply(object): def test_mul(self): """Test MUL execution""" diff --git a/test/arch/mep/ir/test_repeat.py b/test/arch/mep/ir/test_repeat.py index 252764b1..1e0e2f86 100644 --- a/test/arch/mep/ir/test_repeat.py +++ b/test/arch/mep/ir/test_repeat.py @@ -6,7 +6,7 @@ from ut_helpers_ir import exec_instruction from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp -class TestRepeat: +class TestRepeat(object): def test_repeat(self): """Test REPEAT execution""" diff --git a/test/arch/mep/ir/test_shift.py b/test/arch/mep/ir/test_shift.py index b63f9ed7..99755ba5 100644 --- a/test/arch/mep/ir/test_shift.py +++ b/test/arch/mep/ir/test_shift.py @@ -7,7 +7,7 @@ from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp from miasm2.core.cpu import sign_ext -class TestShift: +class TestShift(object): def test_sra(self): """Test SRA execution""" diff --git a/test/arch/mep/ir/ut_helpers_ir.py b/test/arch/mep/ir/ut_helpers_ir.py index 9c9efdfa..26eebeda 100644 --- a/test/arch/mep/ir/ut_helpers_ir.py +++ b/test/arch/mep/ir/ut_helpers_ir.py @@ -1,6 +1,8 @@ # Toshiba MeP-c4 - unit tests helpers # Guillaume Valadon <guillaume@valadon.net> +from __future__ import print_function + from miasm2.arch.mep.arch import mn_mep from miasm2.arch.mep.sem import ir_mepb from miasm2.arch.mep.regs import regs_init @@ -10,7 +12,8 @@ from miasm2.core.locationdb import LocationDB from miasm2.core.utils import Disasm_Exception from miasm2.ir.ir import AssignBlock from miasm2.arch.mep.ira import ir_a_mepb -from miasm2.expression.expression import ExprId, ExprInt, ExprOp, ExprMem, ExprAssign, ExprLoc +from miasm2.expression.expression import ExprId, ExprInt, ExprOp, ExprMem, \ + ExprAssign, ExprLoc def exec_instruction(mn_str, init_values, results, index=0, offset=0): @@ -67,8 +70,8 @@ def exec_instruction(mn_str, init_values, results, index=0, offset=0): # Ensure that all expected results were verified if len(results) is not matched_results: - print "Expected:", results - print "Modified:", [r for r in sb.modified(mems=False)] + print("Expected:", results) + print("Modified:", [r for r in sb.modified(mems=False)]) assert(False) @@ -78,10 +81,10 @@ def launch_tests(obj): test_methods = [name for name in dir(obj) if name.startswith("test")] for method in test_methods: - print method + print(method) try: getattr(obj, method)() except AttributeError as e: - print "Method not found: %s" % method + print("Method not found: %s" % method) assert(False) - print '-' * 42 + print('-' * 42) diff --git a/test/arch/mep/jit/test_jit_branchjump.py b/test/arch/mep/jit/test_jit_branchjump.py index baf602d8..1f932aa9 100644 --- a/test/arch/mep/jit/test_jit_branchjump.py +++ b/test/arch/mep/jit/test_jit_branchjump.py @@ -4,7 +4,7 @@ from ut_helpers_jit import jit_instructions -class TestBranchJump: +class TestBranchJump(object): def test_blti(self): """Test BLTI jit""" diff --git a/test/arch/mep/jit/test_jit_repeat.py b/test/arch/mep/jit/test_jit_repeat.py index 9fa64fa5..eaac1a1d 100644 --- a/test/arch/mep/jit/test_jit_repeat.py +++ b/test/arch/mep/jit/test_jit_repeat.py @@ -4,7 +4,7 @@ from ut_helpers_jit import jit_instructions -class TestRepeat: +class TestRepeat(object): def test_repeat(self): """Test REPEAT jit""" diff --git a/test/arch/mep/jit/ut_helpers_jit.py b/test/arch/mep/jit/ut_helpers_jit.py index 590c534f..999ead42 100644 --- a/test/arch/mep/jit/ut_helpers_jit.py +++ b/test/arch/mep/jit/ut_helpers_jit.py @@ -1,6 +1,8 @@ # Toshiba MeP-c4 - unit tests helpers # Guillaume Valadon <guillaume@valadon.net> +from __future__ import print_function + from miasm2.analysis.machine import Machine from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE @@ -13,7 +15,7 @@ def jit_instructions(mn_str): mn_mep = machine.mn() # Assemble the instructions - asm = "" + asm = b"" for instr_str in mn_str.split("\n"): instr = mn_mep.fromstring(instr_str, "b") instr.mode = "b" @@ -40,10 +42,10 @@ def launch_tests(obj): test_methods = [name for name in dir(obj) if name.startswith("test")] for method in test_methods: - print method + print(method) try: getattr(obj, method)() except AttributeError as e: - print "Method not found: %s" % method + print("Method not found: %s" % method) assert(False) - print '-' * 42 + print('-' * 42) diff --git a/test/arch/mips32/arch.py b/test/arch/mips32/arch.py index 1cbb554d..f71d3ee8 100644 --- a/test/arch/mips32/arch.py +++ b/test/arch/mips32/arch.py @@ -1,6 +1,8 @@ +from __future__ import print_function import time from pdb import pm +from miasm2.core.utils import decode_hex, encode_hex from miasm2.core.locationdb import LocationDB from miasm2.arch.mips32.arch import * @@ -217,20 +219,20 @@ reg_tests_mips32 = [ ts = time.time() def h2i(s): - return s.replace(' ', '').decode('hex') + return decode_hex(s.replace(' ', '')) for s, l in reg_tests_mips32: - print "-" * 80 + print("-" * 80) s = s[12:] b = h2i((l)) mn = mn_mips32.dis(b, 'b') - print [str(x) for x in mn.args] - print s - print mn + print([str(x) for x in mn.args]) + print(s) + print(mn) assert(str(mn) == s) l = mn_mips32.fromstring(s, loc_db, 'b') assert(str(l) == s) a = mn_mips32.asm(l, 'b') - print [x for x in a] - print repr(b) + print([x for x in a]) + print(repr(b)) assert(b in a) diff --git a/test/arch/mips32/unit/asm_test.py b/test/arch/mips32/unit/asm_test.py index da792874..7a50b38e 100644 --- a/test/arch/mips32/unit/asm_test.py +++ b/test/arch/mips32/unit/asm_test.py @@ -1,6 +1,8 @@ import sys import os +from future.utils import viewitems + from miasm2.arch.mips32.arch import mn_mips32 from miasm2.core import parse_asm from miasm2.expression.expression import * @@ -30,10 +32,10 @@ class Asm_Test(object): loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) s = StrPatchwork() patches = asmblock.asm_resolve_final(mn_mips32, blocks, loc_db) - for offset, raw in patches.items(): + for offset, raw in viewitems(patches): s[offset] = raw - s = str(s) + s = bytes(s) self.assembly = s def run(self): diff --git a/test/arch/msp430/arch.py b/test/arch/msp430/arch.py index 91de95b3..eea87091 100644 --- a/test/arch/msp430/arch.py +++ b/test/arch/msp430/arch.py @@ -1,12 +1,15 @@ +from __future__ import print_function + import time from pdb import pm +from miasm2.core.utils import decode_hex, encode_hex from miasm2.arch.msp430.arch import * from miasm2.core.locationdb import LocationDB loc_db = LocationDB() def h2i(s): - return s.replace(' ', '').decode('hex') + return decode_hex(s.replace(' ', '')) def u16swap(i): @@ -86,18 +89,18 @@ reg_tests_msp = [ ts = time.time() for s, l in reg_tests_msp: - print "-" * 80 + print("-" * 80) s = s[8:] b = h2i((l)) - print repr(b) + print(repr(b)) mn = mn_msp430.dis(b, None) - print [str(x) for x in mn.args] - print s - print mn + print([str(x) for x in mn.args]) + print(s) + print(mn) assert(str(mn) == s) l = mn_msp430.fromstring(s, loc_db, None) assert(str(l) == s) a = mn_msp430.asm(l) - print [x for x in a] - print repr(b) + print([x for x in a]) + print(repr(b)) assert(b in a) diff --git a/test/arch/msp430/sem.py b/test/arch/msp430/sem.py index 10e57e36..88aa990d 100755 --- a/test/arch/msp430/sem.py +++ b/test/arch/msp430/sem.py @@ -1,9 +1,12 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from __future__ import print_function import unittest import logging +from future.utils import viewitems + from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.arch.msp430.arch import mn_msp430 as mn, mode_msp430 as mode from miasm2.arch.msp430.sem import ir_msp430 as ir_arch @@ -22,7 +25,7 @@ def M(addr): def compute(asm, inputstate={}, debug=False): loc_db = LocationDB() sympool = dict(regs_init) - sympool.update({k: ExprInt(v, k.size) for k, v in inputstate.iteritems()}) + sympool.update({k: ExprInt(v, k.size) for k, v in viewitems(inputstate)}) ir_tmp = ir_arch(loc_db) ircfg = ir_tmp.new_ircfg() symexec = SymbolicExecutionEngine(ir_tmp, sympool) @@ -33,11 +36,13 @@ def compute(asm, inputstate={}, debug=False): loc_key = ir_tmp.add_instr_to_ircfg(instr, ircfg) symexec.run_at(ircfg, loc_key) if debug: - for k, v in symexec.symbols.items(): + for k, v in viewitems(symexec.symbols): if regs_init.get(k, None) != v: - print k, v - return {k: v.arg.arg for k, v in symexec.symbols.items() - if k not in EXCLUDE_REGS and regs_init.get(k, None) != v} + print(k, v) + return { + k: v.arg.arg for k, v in viewitems(symexec.symbols) + if k not in EXCLUDE_REGS and regs_init.get(k, None) != v + } class TestMSP430Semantic(unittest.TestCase): diff --git a/test/arch/sh4/arch.py b/test/arch/sh4/arch.py index f744b215..f52ed070 100644 --- a/test/arch/sh4/arch.py +++ b/test/arch/sh4/arch.py @@ -1,13 +1,15 @@ +from __future__ import print_function import time from pdb import pm from sys import stderr +from miasm2.core.utils import decode_hex, encode_hex from miasm2.arch.sh4.arch import * from miasm2.core.locationdb import LocationDB loc_db = LocationDB() def h2i(s): - return s.replace(' ', '').decode('hex') + return decode_hex(s.replace(' ', '')) reg_tests_sh4 = [ # vxworks @@ -389,25 +391,25 @@ reg_tests_sh4 = [ ] for s, l in reg_tests_sh4: - print "-" * 80 + print("-" * 80) s = s[12:] b = h2i((l)) - print b.encode('hex') + print(encode_hex(b)) mn = mn_sh4.dis(b, None) - print [str(x) for x in mn.args] - print s - print mn + print([str(x) for x in mn.args]) + print(s) + print(mn) assert(str(mn) == s) l = mn_sh4.fromstring(s, loc_db, None) assert(str(l) == s) a = mn_sh4.asm(l) - print [x for x in a] - print repr(b) + print([x for x in a]) + print(repr(b)) assert(b in a) # speed test -o = "" +o = b"" for s, l, in reg_tests_sh4: s = s[12:] b = h2i((l)) @@ -421,10 +423,10 @@ instr_num = 0 ts = time.time() while off < bs.getlen(): mn = mn_sh4.dis(bs, None, off) - print instr_num, off, mn.l, str(mn) + print(instr_num, off, mn.l, str(mn)) instr_num += 1 off += mn.l -print 'instr per sec:', instr_num / (time.time() - ts) +print('instr per sec:', instr_num // (time.time() - ts)) import cProfile -cProfile.run(r'mn_sh4.dis("\x17\xfe", None)') +cProfile.run(r'mn_sh4.dis(b"\x17\xfe", None)') diff --git a/test/arch/x86/arch.py b/test/arch/x86/arch.py index d2204d77..b4cebd28 100644 --- a/test/arch/x86/arch.py +++ b/test/arch/x86/arch.py @@ -1,5 +1,8 @@ +from __future__ import print_function import time from pdb import pm + +from miasm2.core.utils import decode_hex, encode_hex import miasm2.expression.expression as m2_expr from miasm2.arch.x86.arch import mn_x86, deref_mem_ad, \ base_expr, rmarg, print_size @@ -22,7 +25,7 @@ reg_and_id.update({'mylabel16': mylabel16, def h2i(s): - return int(s.replace(' ', '').decode('hex')[::].encode('hex'), 16) + return int(encode_hex(decode_hex(s.replace(' ', ''))[::]), 16) m16 = 16 # (16, 16) @@ -3101,56 +3104,58 @@ reg_tests = [ ] -test_file = {16: open('regression_test16_ia32.bin', 'w'), - 32: open('regression_test32_ia32.bin', 'w'), - 64: open('regression_test64_ia32.bin', 'w')} +test_file = { + 16: open('regression_test16_ia32.bin', 'wb'), + 32: open('regression_test32_ia32.bin', 'wb'), + 64: open('regression_test64_ia32.bin', 'wb') +} ts = time.time() for mode, s, l, in reg_tests: - print "-" * 80 + print("-" * 80) s = s[12:] - b = l.decode('hex') - print mode, repr(b) + b = decode_hex(l) + print(mode, repr(b)) mn = mn_x86.dis(b, mode) - print "dis args", [(str(x), x.size) for x in mn.args] - print s - print mn + print("dis args", [(str(x), x.size) for x in mn.args]) + print(s) + print(mn) assert(str(mn).strip() == s) - print 'fromstring', repr(s) + print('fromstring', repr(s)) l = mn_x86.fromstring(s, loc_db, mode) - print 'str args', [(str(x), x.size) for x in l.args] + print('str args', [(str(x), x.size) for x in l.args]) assert(str(l).strip(' ') == s) a = mn_x86.asm(l) - print 'asm result', [x for x in a] - print repr(b) + print('asm result', [x for x in a]) + print(repr(b)) for x in a: - print "BYTES", repr(x) + print("BYTES", repr(x)) test_file[mode].write(x) - test_file[mode].write("\x90" * 2) + test_file[mode].write(b"\x90" * 2) - print 'test re dis' + print('test re dis') for x in a: - print repr(x) + print(repr(x)) rl = mn_x86.dis(x, mode) assert(str(rl).strip(' ') == s) - print repr(b), a + print(repr(b), a) assert(b in a) -print 'TEST time', time.time() - ts +print('TEST time', time.time() - ts) # speed test thumb -o = "" +o = b"" mode_x = m32 for mode, s, l, in reg_tests: if mode != mode_x: continue s = s[12:] - b = l.decode('hex') + b = decode_hex(l) o += b while len(o) < 1000: o += o -open('x86_speed_reg_test.bin', 'w').write(o) +open('x86_speed_reg_test.bin', 'wb').write(o) def profile_dis(o): @@ -3163,12 +3168,12 @@ def profile_dis(o): # print instr_num, off, mn.l, str(mn) instr_num += 1 off += mn.l - print 'instr per sec:', instr_num / (time.time() - ts) + print('instr per sec:', instr_num // (time.time() - ts)) import cProfile cProfile.run('profile_dis(o)') # Test instruction representation with prefix -instr_bytes = '\x65\xc7\x00\x09\x00\x00\x00' +instr_bytes = b'\x65\xc7\x00\x09\x00\x00\x00' inst = mn_x86.dis(instr_bytes, 32, 0) assert(inst.b == instr_bytes) diff --git a/test/arch/x86/qemu/testqemu.py b/test/arch/x86/qemu/testqemu.py index dccd9c83..264a84b9 100644 --- a/test/arch/x86/qemu/testqemu.py +++ b/test/arch/x86/qemu/testqemu.py @@ -1,36 +1,42 @@ +from __future__ import print_function import os -import sys import struct import logging +from sys import stdout from pdb import pm +try: + stdout = stdout.buffer +except AttributeError: + pass + from miasm2.analysis.sandbox import Sandbox_Linux_x86_32 from miasm2.jitter.jitload import log_func from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE # Utils def parse_fmt(s): - fmt = s[:]+"\x00" + fmt = s[:]+b"\x00" out = [] i = 0 while i < len(fmt): - c = fmt[i] - if c != "%": + c = fmt[i:i+1] + if c != b"%": i+=1 continue - if fmt[i+1] == "%": + if fmt[i+1:i+2] == b"%": i+=2 continue j = 0 i+=1 - while fmt[i+j] in "0123456789$.-": + while fmt[i+j:i+j+1] in b"0123456789$.-": j+=1 - if fmt[i+j] in ['l']: + if fmt[i+j:i+j+1] in [b'l']: j +=1 - if fmt[i+j] == "h": + if fmt[i+j:i+j+1] == b"h": x = fmt[i+j:i+j+2] else: - x = fmt[i+j] + x = fmt[i+j:i+j+1] i+=j out.append(x) return out @@ -44,25 +50,24 @@ def xxx___printf_chk(jitter): raise RuntimeError("Not implemented") fmt = jitter.get_str_ansi(args.format) # Manage llx - fmt = fmt.replace("llx", "lx") - fmt = fmt.replace("%016lx", "%016z") + fmt = fmt.replace(b"llx", b"lx") + fmt = fmt.replace(b"%016lx", b"%016z") fmt_a = parse_fmt(fmt) esp = jitter.cpu.ESP args = [] i = 0 - for x in fmt_a: a = jitter.vm.get_u32(esp + 8 + 4*i) - if x == "s": + if x == b"s": a = jitter.get_str_ansi(a) - elif x.lower() in ("x", 'd'): + elif x in (b"x", b'X', b"d"): pass - elif x.lower() in ("f", "l"): + elif x.lower() in (b"f", b"l"): a2 = jitter.vm.get_u32(esp + 8 + 4*(i+1)) a = struct.unpack("d", struct.pack("Q", a2 << 32 | a))[0] i += 1 - elif x.lower() == 'z': + elif x.lower() == b'z': a2 = jitter.vm.get_u32(esp + 8 + 4*(i+1)) a = a2 << 32 | a i += 1 @@ -70,23 +75,22 @@ def xxx___printf_chk(jitter): raise RuntimeError("Not implemented format") args.append(a) i += 1 - - fmt = fmt.replace("%016z", "%016lx") + fmt = fmt.replace(b"%016z", b"%016lx") output = fmt%(tuple(args)) # NaN bad repr in Python - output = output.replace("nan", "-nan") + output = output.replace(b"nan", b"-nan") - if "\n" not in output: + if b"\n" not in output: raise RuntimeError("Format must end with a \\n") # Check with expected result - line = expected.next() - if output != line: - print "Expected:", line - print "Obtained:", output + line = next(expected) + if output != line.encode(): + print("Expected:", line) + print("Obtained:", output) raise RuntimeError("Bad semantic") - sys.stdout.write("[%d] %s" % (nb_tests, output)) + stdout.write(b"[%d] %s" % (nb_tests, output)) nb_tests += 1 jitter.func_ret_systemv(ret_ad, 0) @@ -100,10 +104,10 @@ def xxx_puts(jitter): ret_addr, args = jitter.func_args_systemv(['target']) output = jitter.get_str_ansi(args.target) # Check with expected result - line = expected.next() - if output != line.rstrip(): - print "Expected:", line - print "Obtained:", output + line = next(expected) + if output != line.rstrip().encode(): + print("Expected:", line) + print("Obtained:", output) raise RuntimeError("Bad semantic") return jitter.func_ret_systemv(ret_addr, 1) @@ -120,7 +124,7 @@ expected = open(options.expected) # Create sandbox sb = Sandbox_Linux_x86_32(options.filename, options, globals()) try: - addr = sb.elf.getsectionbyname(".symtab").symbols[options.funcname].value + addr = sb.elf.getsectionbyname(".symtab")[options.funcname].value except AttributeError: raise RuntimeError("The target binary must have a symtab section") @@ -129,7 +133,7 @@ log_func.setLevel(logging.ERROR) # Segmentation sb.jitter.cpu.set_segm_base(8, 0x7fff0000) sb.jitter.cpu.GS = 8 -sb.jitter.vm.add_memory_page(0x7fff0000 + 0x14, PAGE_READ | PAGE_WRITE, "AAAA") +sb.jitter.vm.add_memory_page(0x7fff0000 + 0x14, PAGE_READ | PAGE_WRITE, b"AAAA") # Run diff --git a/test/arch/x86/qemu/testqemu64.py b/test/arch/x86/qemu/testqemu64.py index bd82d414..4fe51992 100644 --- a/test/arch/x86/qemu/testqemu64.py +++ b/test/arch/x86/qemu/testqemu64.py @@ -1,36 +1,42 @@ +from __future__ import print_function import os -import sys import struct import logging +from sys import stdout from pdb import pm +try: + stdout = stdout.buffer +except AttributeError: + pass + from miasm2.analysis.sandbox import Sandbox_Linux_x86_64 from miasm2.jitter.jitload import log_func from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE # Utils def parse_fmt(s): - fmt = s[:]+"\x00" + fmt = s[:]+b"\x00" out = [] i = 0 while i < len(fmt): - c = fmt[i] - if c != "%": + c = fmt[i:i+1] + if c != b"%": i+=1 continue - if fmt[i+1] == "%": + if fmt[i+1:i+2] == b"%": i+=2 continue j = 0 i+=1 - while fmt[i+j] in "0123456789$.-": + while fmt[i+j:i+j+1] in b"0123456789$.-": j+=1 - if fmt[i+j] in ['l']: + if fmt[i+j:i+j+1] in [b'l']: j +=1 - if fmt[i+j] == "h": + if fmt[i+j:i+j+1] == b"h": x = fmt[i+j:i+j+2] else: - x = fmt[i+j] + x = fmt[i+j:i+j+1] i+=j out.append(x) return out @@ -44,8 +50,8 @@ def xxx___printf_chk(jitter): raise RuntimeError("Not implemented") fmt = jitter.get_str_ansi(args.format) # Manage llx - fmt = fmt.replace("llx", "lx") - fmt = fmt.replace("%016lx", "%016z") + fmt = fmt.replace(b"llx", b"lx") + fmt = fmt.replace(b"%016lx", b"%016z") fmt_a = parse_fmt(fmt) args = [] @@ -53,11 +59,11 @@ def xxx___printf_chk(jitter): for x in fmt_a: a = jitter.get_arg_n_systemv(2 + i) - if x == "s": + if x == b"s": a = jitter.get_str_ansi(a) - elif x.lower() in ("x", 'd', 'z'): + elif x in (b"x", b'X', b'd', b'z', b'Z'): pass - elif x.lower() in ("f", "l"): + elif x.lower() in (b"f","l"): a = struct.unpack("d", struct.pack("Q", a))[0] i += 1 else: @@ -65,22 +71,22 @@ def xxx___printf_chk(jitter): args.append(a) i += 1 - fmt = fmt.replace("%016z", "%016lx") + fmt = fmt.replace(b"%016z", b"%016lx") output = fmt%(tuple(args)) # NaN bad repr in Python - output = output.replace("nan", "-nan") + output = output.replace(b"nan", b"-nan") - if "\n" not in output: + if b"\n" not in output: raise RuntimeError("Format must end with a \\n") # Check with expected result - line = expected.next() - if output != line: - print "Expected:", line - print "Obtained:", output + line = next(expected) + if output != line.encode(): + print("Expected:", line) + print("Obtained:", output) raise RuntimeError("Bad semantic") - sys.stdout.write("[%d] %s" % (nb_tests, output)) + stdout.write(b"[%d] %s" % (nb_tests, output)) nb_tests += 1 jitter.func_ret_systemv(ret_ad, 0) @@ -94,10 +100,10 @@ def xxx_puts(jitter): ret_addr, args = jitter.func_args_systemv(['target']) output = jitter.get_str_ansi(args.target) # Check with expected result - line = expected.next() + line = next(expected) if output != line.rstrip(): - print "Expected:", line - print "Obtained:", output + print("Expected:", line) + print("Obtained:", output) raise RuntimeError("Bad semantic") return jitter.func_ret_systemv(ret_addr, 1) @@ -114,7 +120,7 @@ expected = open(options.expected) # Create sandbox sb = Sandbox_Linux_x86_64(options.filename, options, globals()) try: - addr = sb.elf.getsectionbyname(".symtab").symbols[options.funcname].value + addr = sb.elf.getsectionbyname(".symtab")[options.funcname].value except AttributeError: raise RuntimeError("The target binary must have a symtab section") @@ -123,7 +129,7 @@ log_func.setLevel(logging.ERROR) # Segmentation sb.jitter.cpu.set_segm_base(8, 0x7fff0000) sb.jitter.cpu.FS = 8 -sb.jitter.vm.add_memory_page(0x7fff0000 + 0x28, PAGE_READ | PAGE_WRITE, "AAAAAAAA") +sb.jitter.vm.add_memory_page(0x7fff0000 + 0x28, PAGE_READ | PAGE_WRITE, b"AAAAAAAA") # Run diff --git a/test/arch/x86/sem.py b/test/arch/x86/sem.py index 0783089d..c0cfc8f2 100755 --- a/test/arch/x86/sem.py +++ b/test/arch/x86/sem.py @@ -3,6 +3,11 @@ # Loosely based on ARM's sem.py +from __future__ import print_function +from builtins import range + +from future.utils import viewitems + import unittest import logging import copy @@ -30,11 +35,13 @@ def symb_exec(lbl, ir_arch, ircfg, inputstate, debug): symexec = SymbolicExecutionEngine(ir_arch, sympool) symexec.run_at(ircfg, lbl) if debug: - for k, v in symexec.symbols.items(): + for k, v in viewitems(symexec.symbols): if regs_init.get(k, None) != v: - print k, v - return {k: v for k, v in symexec.symbols.items() - if k not in EXCLUDE_REGS and regs_init.get(k, None) != v} + print(k, v) + return { + k: v for k, v in viewitems(symexec.symbols) + if k not in EXCLUDE_REGS and regs_init.get(k, None) != v + } def compute(ir, mode, asm, inputstate={}, debug=False): loc_db = LocationDB() @@ -60,7 +67,7 @@ def compute_txt(ir, mode, txt, inputstate={}, debug=False): op_add = lambda a, b: a+b op_sub = lambda a, b: a-b op_mul = lambda a, b: a*b -op_div = lambda a, b: a/b +op_div = lambda a, b: a //b op_and = lambda a, b: a&b op_or = lambda a, b: a|b @@ -72,8 +79,8 @@ def int_vec_op(op, elt_size, reg_size, arg1, arg2): assert(reg_size % elt_size == 0) ret = 0 mask = (1<<elt_size)-1 - nelts = reg_size/elt_size - for i in xrange(0, nelts): + nelts = reg_size // elt_size + for i in range(0, nelts): ret |= (op(arg1 & mask, arg2 & mask) & mask) << (i*elt_size) arg1 >>= elt_size arg2 >>= elt_size diff --git a/test/arch/x86/unit/access_xmm.py b/test/arch/x86/unit/access_xmm.py index 950c8b56..8354c30f 100644 --- a/test/arch/x86/unit/access_xmm.py +++ b/test/arch/x86/unit/access_xmm.py @@ -10,7 +10,7 @@ myjit = Machine("x86_32").jitter("python") assert myjit.cpu.XMM0 == 0 # Test set -myjit.cpu.XMM1 = 0x00112233445566778899aabbccddeeffL +myjit.cpu.XMM1 = 0x00112233445566778899aabbccddeeff # Ensure set has been correctly handled -assert myjit.cpu.XMM1 == 0x00112233445566778899aabbccddeeffL +assert myjit.cpu.XMM1 == 0x00112233445566778899aabbccddeeff diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py index 91da1942..a87fe278 100644 --- a/test/arch/x86/unit/asm_test.py +++ b/test/arch/x86/unit/asm_test.py @@ -1,6 +1,10 @@ +from builtins import str +from builtins import object import sys import os +from future.utils import viewitems + from miasm2.arch.x86.arch import mn_x86, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * @@ -46,10 +50,10 @@ class Asm_Test(object): loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) s = StrPatchwork() patches = asmblock.asm_resolve_final(mn_x86, blocks, loc_db) - for offset, raw in patches.items(): + for offset, raw in viewitems(patches): s[offset] = raw - s = str(s) + s = bytes(s) self.assembly = s def check(self): diff --git a/test/arch/x86/unit/mn_getset128.py b/test/arch/x86/unit/mn_getset128.py index a084d663..f20f452e 100644 --- a/test/arch/x86/unit/mn_getset128.py +++ b/test/arch/x86/unit/mn_getset128.py @@ -35,15 +35,15 @@ class Test_get_set_128(Asm_Test_32): assert self.myjit.cpu.get_gpreg()['XMM0'] == val def check(self): - assert self.myjit.cpu.XMM0 == 0xffffffffffffffff0000000000000000L + assert self.myjit.cpu.XMM0 == 0xffffffffffffffff0000000000000000 assert self.myjit.cpu.XMM1 == 0x11223345 # Check 128 get / set - assert self.myjit.cpu.get_gpreg()['XMM0'] == 0xffffffffffffffff0000000000000000L + assert self.myjit.cpu.get_gpreg()['XMM0'] == 0xffffffffffffffff0000000000000000 assert self.myjit.cpu.get_gpreg()['XMM1'] == 0x11223345 - assert self.myjit.cpu.get_gpreg()['XMM2'] == 0x11112222333344445555666677778888L - assert self.myjit.cpu.get_gpreg()['XMM2'] == 0x11112222333344445555666677778888L + assert self.myjit.cpu.get_gpreg()['XMM2'] == 0x11112222333344445555666677778888 + assert self.myjit.cpu.get_gpreg()['XMM2'] == 0x11112222333344445555666677778888 if __name__ == "__main__": diff --git a/test/arch/x86/unit/mn_pcmpeq.py b/test/arch/x86/unit/mn_pcmpeq.py index e934d6b5..b8eeafba 100755 --- a/test/arch/x86/unit/mn_pcmpeq.py +++ b/test/arch/x86/unit/mn_pcmpeq.py @@ -81,7 +81,7 @@ class Test_PCMPEQQ(Asm_Test_32): self.myjit.cpu.XMM0 = val def check(self): - assert self.myjit.cpu.XMM0 == 0xffffffffffffffff0000000000000000L + assert self.myjit.cpu.XMM0 == 0xffffffffffffffff0000000000000000 assert self.myjit.cpu.XMM1 == 0x11223345 diff --git a/test/arch/x86/unit/mn_pshufb.py b/test/arch/x86/unit/mn_pshufb.py index d10c18e3..9167b0c1 100755 --- a/test/arch/x86/unit/mn_pshufb.py +++ b/test/arch/x86/unit/mn_pshufb.py @@ -18,8 +18,8 @@ class Test_PSHUFB(Asm_Test_32): ''' def check(self): - assert self.myjit.cpu.MM0 == 0x1122334455667788L - assert self.myjit.cpu.MM1 == 0x8877665544332211L + assert self.myjit.cpu.MM0 == 0x1122334455667788 + assert self.myjit.cpu.MM1 == 0x8877665544332211 if __name__ == "__main__": diff --git a/test/arch/x86/unit/mn_psrl_psll.py b/test/arch/x86/unit/mn_psrl_psll.py index a5428dab..7d9572b0 100755 --- a/test/arch/x86/unit/mn_psrl_psll.py +++ b/test/arch/x86/unit/mn_psrl_psll.py @@ -22,10 +22,10 @@ class Test_PSRL(Asm_Test_32): ''' def check(self): - assert self.myjit.cpu.MM0 == 0x1122334455667788L - assert self.myjit.cpu.MM1 == 0x0112033405560778L - assert self.myjit.cpu.MM2 == 0x0112233405566778L - assert self.myjit.cpu.MM3 == 0x0112233445566778L + assert self.myjit.cpu.MM0 == 0x1122334455667788 + assert self.myjit.cpu.MM1 == 0x0112033405560778 + assert self.myjit.cpu.MM2 == 0x0112233405566778 + assert self.myjit.cpu.MM3 == 0x0112233445566778 class Test_PSLL(Asm_Test_32): TXT = ''' @@ -46,10 +46,10 @@ class Test_PSLL(Asm_Test_32): ''' def check(self): - assert self.myjit.cpu.MM0 == 0x1122334455667788L - assert self.myjit.cpu.MM1 == 0x1220344056607880L - assert self.myjit.cpu.MM2 == 0x1223344056677880L - assert self.myjit.cpu.MM3 == 0x1223344556677880L + assert self.myjit.cpu.MM0 == 0x1122334455667788 + assert self.myjit.cpu.MM1 == 0x1220344056607880 + assert self.myjit.cpu.MM2 == 0x1223344056677880 + assert self.myjit.cpu.MM3 == 0x1223344556677880 if __name__ == "__main__": diff --git a/test/arch/x86/unit/mn_pushpop.py b/test/arch/x86/unit/mn_pushpop.py index 6e9005ca..fedd197b 100755 --- a/test/arch/x86/unit/mn_pushpop.py +++ b/test/arch/x86/unit/mn_pushpop.py @@ -25,7 +25,7 @@ class Test_PUSHAD_32(Asm_Test_32): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" for reg_name in reversed(["EAX", "ECX", "EDX", "EBX", "ESP", "EBP", @@ -52,7 +52,7 @@ class Test_PUSHA_32(Asm_Test_32): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" for reg_name in reversed(["AX", "CX", "DX", "BX", "SP", "BP", @@ -79,7 +79,7 @@ class Test_PUSHA_16(Asm_Test_16): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" for reg_name in reversed(["AX", "CX", "DX", "BX", "SP", "BP", @@ -106,7 +106,7 @@ class Test_PUSHAD_16(Asm_Test_16): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" for reg_name in reversed(["EAX", "ECX", "EDX", "EBX", "ESP", "EBP", @@ -133,7 +133,7 @@ class Test_PUSH_mode32_32(Asm_Test_32): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" self.buf += pck32(0x11223344) TXT = ''' @@ -156,7 +156,7 @@ class Test_PUSH_mode32_16(Asm_Test_32): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" self.buf += pck16(0x1122) TXT = ''' @@ -179,7 +179,7 @@ class Test_PUSH_mode16_16(Asm_Test_16): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" self.buf += pck16(0x1122) TXT = ''' @@ -202,7 +202,7 @@ class Test_PUSH_mode16_32(Asm_Test_16): def test_init(self): init_regs(self) - self.buf = "" + self.buf = b"" self.buf += pck32(0x11223344) TXT = ''' diff --git a/test/arch/x86/unit/mn_seh.py b/test/arch/x86/unit/mn_seh.py index dd3fd4ef..1fa0900e 100755 --- a/test/arch/x86/unit/mn_seh.py +++ b/test/arch/x86/unit/mn_seh.py @@ -1,4 +1,5 @@ #! /usr/bin/env python2 +from __future__ import print_function import sys from miasm2.os_dep.win_api_x86_32_seh import fake_seh_handler, build_teb, \ @@ -15,7 +16,7 @@ class Test_SEH(Asm_Test_32): @staticmethod def deal_exception_priv(jitter): - print 'Exception Priv', hex(jitter.cpu.ESP) + print('Exception Priv', hex(jitter.cpu.ESP)) pc = fake_seh_handler(jitter, EXCEPTION_PRIV_INSTRUCTION) jitter.pc = pc jitter.cpu.EIP = pc diff --git a/test/core/asmblock.py b/test/core/asmblock.py index c3e1d11d..48e81e78 100644 --- a/test/core/asmblock.py +++ b/test/core/asmblock.py @@ -1,5 +1,10 @@ +from __future__ import print_function +from builtins import map from pdb import pm +from future.utils import viewitems + +from miasm2.core.utils import decode_hex from miasm2.analysis.machine import Machine from miasm2.analysis.binary import Container from miasm2.core.asmblock import AsmCFG, AsmConstraint, AsmBlock, \ @@ -9,7 +14,7 @@ from miasm2.core.graph import DiGraphSimplifier, MatchGraphJoker from miasm2.expression.expression import ExprId # Initial data: from 'samples/simple_test.bin' -data = "5589e583ec10837d08007509c745fc01100000eb73837d08017709c745fc02100000eb64837d08057709c745fc03100000eb55837d080774138b450801c083f80e7509c745fc04100000eb3c8b450801c083f80e7509c745fc05100000eb298b450883e03085c07409c745fc06100000eb16837d08427509c745fc07100000eb07c745fc081000008b45fcc9c3".decode("hex") +data = decode_hex("5589e583ec10837d08007509c745fc01100000eb73837d08017709c745fc02100000eb64837d08057709c745fc03100000eb55837d080774138b450801c083f80e7509c745fc04100000eb3c8b450801c083f80e7509c745fc05100000eb298b450883e03085c07409c745fc06100000eb16837d08427509c745fc07100000eb07c745fc081000008b45fcc9c3") cont = Container.from_string(data) # Test Disasm engine @@ -18,12 +23,12 @@ mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db) ## Disassembly of one block first_block = mdis.dis_block(0) assert len(first_block.lines) == 5 -print first_block +print(first_block) ## Test redisassemble asmcfg first_block_bis = mdis.dis_block(0) assert len(first_block.lines) == len(first_block_bis.lines) -print first_block_bis +print(first_block_bis) ## Disassembly of several block, with cache asmcfg = mdis.dis_multiblock(0) @@ -214,7 +219,7 @@ assert len(asmcfg.pendings) == 0 asmcfg.sanity_check() # Test block_merge -data2 = "31c0eb0c31c9750c31d2eb0c31ffebf831dbebf031edebfc31f6ebf031e4c3".decode("hex") +data2 = decode_hex("31c0eb0c31c9750c31d2eb0c31ffebf831dbebf031edebfc31f6ebf031e4c3") cont2 = Container.from_string(data2) mdis = machine.dis_engine(cont2.bin_stream, loc_db=cont2.loc_db) ## Elements to merge @@ -234,35 +239,35 @@ assert len(asmcfg) == 5 assert len(list(asmcfg.get_bad_blocks())) == 1 ### Check "special" asmcfg entry_asmcfg = asmcfg.heads() -bad_block_lbl = (lbl for lbl in entry_asmcfg - if isinstance(asmcfg.loc_key_to_block(lbl), AsmBlockBad)).next() +bad_block_lbl = next((lbl for lbl in entry_asmcfg + if isinstance(asmcfg.loc_key_to_block(lbl), AsmBlockBad))) entry_asmcfg.remove(bad_block_lbl) -alone_block = (asmcfg.loc_key_to_block(lbl) for lbl in entry_asmcfg - if len(asmcfg.successors(lbl)) == 0).next() +alone_block = next((asmcfg.loc_key_to_block(lbl) for lbl in entry_asmcfg + if len(asmcfg.successors(lbl)) == 0)) entry_asmcfg.remove(alone_block.loc_key) assert alone_block.lines[-1].name == "RET" assert len(alone_block.lines) == 2 ### Check resulting function entry_block = asmcfg.loc_key_to_block(entry_asmcfg.pop()) assert len(entry_block.lines) == 4 -assert map(str, entry_block.lines) == ['XOR EAX, EAX', +assert list(map(str, entry_block.lines)) == ['XOR EAX, EAX', 'XOR EBX, EBX', 'XOR ECX, ECX', 'JNZ loc_key_3'] assert len(asmcfg.successors(entry_block.loc_key)) == 2 assert len(entry_block.bto) == 2 -nextb = asmcfg.loc_key_to_block((cons.loc_key for cons in entry_block.bto - if cons.c_t == AsmConstraint.c_next).next()) -tob = asmcfg.loc_key_to_block((cons.loc_key for cons in entry_block.bto - if cons.c_t == AsmConstraint.c_to).next()) +nextb = asmcfg.loc_key_to_block(next((cons.loc_key for cons in entry_block.bto + if cons.c_t == AsmConstraint.c_next))) +tob = asmcfg.loc_key_to_block(next((cons.loc_key for cons in entry_block.bto + if cons.c_t == AsmConstraint.c_to))) assert len(nextb.lines) == 4 -assert map(str, nextb.lines) == ['XOR EDX, EDX', +assert list(map(str, nextb.lines)) == ['XOR EDX, EDX', 'XOR ESI, ESI', 'XOR EDI, EDI', 'JMP loc_key_4'] assert asmcfg.successors(nextb.loc_key) == [nextb.loc_key] assert len(tob.lines) == 2 -assert map(str, tob.lines) == ['XOR EBP, EBP', +assert list(map(str, tob.lines)) == ['XOR EBP, EBP', 'JMP loc_key_3'] assert asmcfg.successors(tob.loc_key) == [tob.loc_key] @@ -283,13 +288,13 @@ asmcfg.apply_splitting(mdis.loc_db) assert len(asmcfg) == 6 assert len(asmcfg.pendings) == 0 assert len(entry_block.lines) == 2 -assert map(str, entry_block.lines) == ['XOR EAX, EAX', +assert list(map(str, entry_block.lines)) == ['XOR EAX, EAX', 'XOR EBX, EBX'] assert len(asmcfg.successors(entry_block.loc_key)) == 1 lbl_newb = asmcfg.successors(entry_block.loc_key)[0] newb = asmcfg.loc_key_to_block(lbl_newb) assert len(newb.lines) == 2 -assert map(str, newb.lines) == ['XOR ECX, ECX', +assert list(map(str, newb.lines)) == ['XOR ECX, ECX', 'JNZ loc_key_3'] preds = asmcfg.predecessors(lbl_newb) assert len(preds) == 2 @@ -300,7 +305,7 @@ assert asmcfg.edges2constraint[(tob.loc_key, lbl_newb)] == AsmConstraint.c_to # Check double block split -data = "74097405b8020000007405b803000000b804000000c3".decode('hex') +data = decode_hex("74097405b8020000007405b803000000b804000000c3") cont = Container.from_string(data) mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db) asmcfg = mdis.dis_multiblock(0) @@ -322,7 +327,7 @@ matcher += bbl0 >> bblB solutions = list(matcher.match(asmcfg)) assert len(solutions) == 1 solution = solutions.pop() -for jbbl, label in solution.iteritems(): +for jbbl, label in viewitems(solution): offset = mdis.loc_db.get_location_offset(label) assert offset == int(jbbl._name, 16) diff --git a/test/core/graph.py b/test/core/graph.py index b71c3d51..484591b7 100644 --- a/test/core/graph.py +++ b/test/core/graph.py @@ -1,3 +1,4 @@ +from __future__ import print_function from miasm2.core.graph import * g = DiGraph() @@ -9,13 +10,13 @@ g.add_edge('a', 'c') g.add_edge('a', 'c') g.add_edge('c', 'c') -print g +print(g) -print [x for x in g.successors('a')] -print [x for x in g.predecessors('a')] -print [x for x in g.predecessors('b')] -print [x for x in g.predecessors('c')] -print [x for x in g.successors('c')] +print([x for x in g.successors('a')]) +print([x for x in g.predecessors('a')]) +print([x for x in g.predecessors('b')]) +print([x for x in g.predecessors('c')]) +print([x for x in g.successors('c')]) """ @@ -226,7 +227,7 @@ j2 = MatchGraphJoker(name="son") ### Check '>>' helper matcher = j1 >> j2 >> j1 ### Check __str__ -print matcher +print(matcher) ### Ensure form assert isinstance(matcher, MatchGraph) assert len(matcher.nodes()) == 2 diff --git a/test/core/interval.py b/test/core/interval.py index 97d45a39..76c95d66 100755 --- a/test/core/interval.py +++ b/test/core/interval.py @@ -1,6 +1,7 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from builtins import range from miasm2.core.interval import * from random import randint from pdb import pm @@ -107,7 +108,7 @@ assert(i_empty.hull() == (None, None)) def gen_random_interval(l=100): r = [] - for j in xrange(5): + for j in range(5): a = randint(0, l) b = a + randint(0, l) r.append((a, b)) @@ -117,7 +118,7 @@ def gen_random_interval(l=100): def check_add(r1, r2): i_sum = interval(r1) + interval(r2) for a, b in r1 + r2: - for i in xrange(a, b + 1): + for i in range(a, b + 1): assert(i in i_sum) @@ -126,7 +127,7 @@ def check_sub(r1, r2): i2 = interval(r2) i_sub = i1 - i2 for a, b in r1: - for i in xrange(a, b + 1): + for i in range(a, b + 1): if i in i2: assert(i not in i_sub) else: @@ -138,14 +139,14 @@ def check_and(r1, r2): i2 = interval(r2) i_and = i1 & i2 for a, b in r1: - for i in xrange(a, b + 1): + for i in range(a, b + 1): if i in i2: assert(i in i_and) else: assert(i not in i_and) -for i in xrange(1000): +for i in range(1000): r1 = gen_random_interval() r2 = gen_random_interval() r3 = gen_random_interval() diff --git a/test/core/locationdb.py b/test/core/locationdb.py index 61bc4563..3db760d8 100644 --- a/test/core/locationdb.py +++ b/test/core/locationdb.py @@ -1,3 +1,4 @@ +from builtins import str from miasm2.core.locationdb import LocationDB @@ -57,9 +58,9 @@ loc_db.consistency_check() # Names manipulation loc_key5 = loc_db.add_location() -name1 = "name1" -name2 = "name2" -name3 = "name3" +name1 = b"name1" +name2 = b"name2" +name3 = b"name3" assert len(loc_db.get_location_names(loc_key5)) == 0 loc_db.add_location_name(loc_key5, name1) loc_db.add_location_name(loc_key5, name2) diff --git a/test/core/parse_asm.py b/test/core/parse_asm.py index ddb195d2..ade9040d 100755 --- a/test/core/parse_asm.py +++ b/test/core/parse_asm.py @@ -1,6 +1,7 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from builtins import range import unittest @@ -69,7 +70,7 @@ class TestParseAsm(unittest.TestCase): asmcfg, loc_db) lbls = [] - for i in xrange(6): + for i in range(6): lbls.append(loc_db.get_name_location('lbl%d' % i)) # align test offset = loc_db.get_location_offset(lbls[5]) @@ -97,7 +98,7 @@ class TestParseAsm(unittest.TestCase): asmcfg, loc_db = parse_txt(mn_x86, 32, ASM0) lbls = [] - for i in xrange(2): + for i in range(2): lbls.append(loc_db.get_name_location('lbl%d' % i)) lbl2block = {} for block in asmcfg.blocks: diff --git a/test/core/sembuilder.py b/test/core/sembuilder.py index f7a96b89..53e9e60e 100644 --- a/test/core/sembuilder.py +++ b/test/core/sembuilder.py @@ -1,3 +1,4 @@ +from __future__ import print_function import inspect from pdb import pm @@ -50,18 +51,18 @@ ir = IR(loc_db) instr = Instr() res = test(ir, instr, a, b, c) -print "[+] Returned:" -print res -print "[+] DocString:", test.__doc__ +print("[+] Returned:") +print(res) +print("[+] DocString:", test.__doc__) -print "[+] Cur instr:" +print("[+] Cur instr:") for statement in res[0]: - print statement + print(statement) -print "[+] Blocks:" +print("[+] Blocks:") for irb in res[1]: - print irb.loc_key + print(irb.loc_key) for assignblk in irb: for expr in assignblk: - print expr - print + print(expr) + print() diff --git a/test/core/test_types.py b/test/core/test_types.py index 92867748..e3914185 100755 --- a/test/core/test_types.py +++ b/test/core/test_types.py @@ -2,8 +2,11 @@ # miasm2.core.types tests +from __future__ import print_function +from builtins import range import struct +from miasm2.core.utils import int_to_byte from miasm2.analysis.machine import Machine from miasm2.core.types import MemStruct, Num, Ptr, Str, \ Array, RawStruct, Union, \ @@ -40,7 +43,7 @@ addr_str = 0x1100 addr_str2 = 0x1200 addr_str3 = 0x1300 # Initialize all mem with 0xaa -jitter.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\xaa"*size) +jitter.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, b"\xaa"*size) # MemStruct tests @@ -64,7 +67,7 @@ assert mstruct.flags == 0 assert mstruct.other.val == 0 assert mstruct.s.val == 0 assert mstruct.i.val == 0 -mstruct.memset('\x11') +mstruct.memset(b'\x11') assert mstruct.num == 0x11111111 assert mstruct.flags == 0x11 assert mstruct.other.val == 0x11111111 @@ -122,10 +125,10 @@ assert memval == 8 memstr = Str().lval(jitter.vm, addr_str) memstr.val = "" assert memstr.val == "" -assert jitter.vm.get_mem(memstr.get_addr(), 1) == '\x00' +assert jitter.vm.get_mem(memstr.get_addr(), 1) == b'\x00' memstr.val = "lala" -assert jitter.vm.get_mem(memstr.get_addr(), memstr.get_size()) == 'lala\x00' -jitter.vm.set_mem(memstr.get_addr(), 'MIAMs\x00') +assert jitter.vm.get_mem(memstr.get_addr(), memstr.get_size()) == b'lala\x00' +jitter.vm.set_mem(memstr.get_addr(), b'MIAMs\x00') assert memstr.val == 'MIAMs' ## Ptr(Str()) manipulations @@ -148,7 +151,7 @@ memstr3 = Str("utf16").lval(jitter.vm, addr_str3) memstr3.val = "That's all folks!" assert memstr3.get_addr() != memstr.get_addr() assert memstr3.get_size() != memstr.get_size() # Size is different -assert str(memstr3) != str(memstr) # Mem representation is different +assert bytes(memstr3) != bytes(memstr) # Mem representation is different assert memstr3 != memstr # Encoding is different, so they are not eq assert memstr3.val == memstr.val # But the python value is the same @@ -163,13 +166,13 @@ memarray = Array(Num("I")).lval(jitter.vm, alloc_addr) memarray[0] = 0x02 assert memarray[0] == 0x02 assert jitter.vm.get_mem(memarray.get_addr(), - Num("I").size) == '\x02\x00\x00\x00' + Num("I").size) == b'\x02\x00\x00\x00' memarray[2] = 0xbbbbbbbb assert memarray[2] == 0xbbbbbbbb assert jitter.vm.get_mem(memarray.get_addr() + 2 * Num("I").size, - Num("I").size) == '\xbb\xbb\xbb\xbb' + Num("I").size) == b'\xbb\xbb\xbb\xbb' try: - s = str(memarray) + s = bytes(memarray) assert False, "Should raise" except (NotImplementedError, ValueError): pass @@ -194,16 +197,16 @@ except ValueError: memsarray = Array(Num("I"), 10).lval(jitter.vm) # And Array(type, size).lval generates statically sized types assert memsarray.sizeof() == Num("I").size * 10 -memsarray.memset('\xcc') +memsarray.memset(b'\xcc') assert memsarray[0] == 0xcccccccc assert len(memsarray) == 10 * 4 -assert str(memsarray) == '\xcc' * (4 * 10) +assert bytes(memsarray) == b'\xcc' * (4 * 10) for val in memsarray: assert val == 0xcccccccc assert list(memsarray) == [0xcccccccc] * 10 memsarray[0] = 2 assert memsarray[0] == 2 -assert str(memsarray) == '\x02\x00\x00\x00' + '\xcc' * (4 * 9) +assert bytes(memsarray) == b'\x02\x00\x00\x00' + b'\xcc' * (4 * 9) # Atypical fields (RawStruct and Array) @@ -214,7 +217,7 @@ class MyStruct2(MemStruct): ] ms2 = MyStruct2(jitter.vm) -ms2.memset('\xaa') +ms2.memset(b'\xaa') assert len(ms2) == 15 ## RawStruct @@ -241,7 +244,7 @@ for val in ms2.s2: ### Field assignment (MemSizedArray) array2 = Array(Num("B"), 10).lval(jitter.vm) -jitter.vm.set_mem(array2.get_addr(), '\x02'*10) +jitter.vm.set_mem(array2.get_addr(), b'\x02'*10) for val in array2: assert val == 2 ms2.s2 = array2 @@ -272,7 +275,7 @@ assert cont.one == 0 assert cont.last == 0 assert cont.instruct.foo == 0 assert cont.instruct.bar == 0 -cont.memset('\x11') +cont.memset(b'\x11') assert cont.one == 0x11 assert cont.last == 0x11 assert cont.instruct.foo == 0x11 @@ -286,7 +289,7 @@ assert cont.one == 0x01 assert cont.instruct.foo == 0x02 assert cont.instruct.bar == 0x03 assert cont.last == 0x04 -assert jitter.vm.get_mem(cont.get_addr(), len(cont)) == '\x01\x02\x03\x04' +assert jitter.vm.get_mem(cont.get_addr(), len(cont)) == b'\x01\x02\x03\x04' # Union test @@ -301,7 +304,7 @@ class UniStruct(MemStruct): ] uni = UniStruct(jitter.vm) -jitter.vm.set_mem(uni.get_addr(), ''.join(chr(x) for x in xrange(len(uni)))) +jitter.vm.set_mem(uni.get_addr(), b''.join(int_to_byte(x) for x in range(len(uni)))) assert len(uni) == 6 # 1 + max(InStruct.sizeof(), 4) + 1 assert uni.one == 0x00 assert uni.union.instruct.foo == 0x01 @@ -535,18 +538,18 @@ for idx, off in ((0, 0), (1, 2), (30, 60)): # Repr tests -print "Some struct reprs:\n" -print repr(mstruct), '\n' -print repr(ms2), '\n' -print repr(cont), '\n' -print repr(uni), '\n' -print repr(bit), '\n' -print repr(ideas), '\n' -print repr(Array(MyStruct2.get_type(), 2).lval(jitter.vm, addr)), '\n' -print repr(Num("f").lval(jitter.vm, addr)), '\n' -print repr(memarray) -print repr(memsarray) -print repr(memstr) -print repr(memstr3) - -print "\nOk" # That's all folks! +print("Some struct reprs:\n") +print(repr(mstruct), '\n') +print(repr(ms2), '\n') +print(repr(cont), '\n') +print(repr(uni), '\n') +print(repr(bit), '\n') +print(repr(ideas), '\n') +print(repr(Array(MyStruct2.get_type(), 2).lval(jitter.vm, addr)), '\n') +print(repr(Num("f").lval(jitter.vm, addr)), '\n') +print(repr(memarray)) +print(repr(memsarray)) +print(repr(memstr)) +print(repr(memstr3)) + +print("\nOk") # That's all folks! diff --git a/test/core/utils.py b/test/core/utils.py index b506f904..6f69fdf1 100755 --- a/test/core/utils.py +++ b/test/core/utils.py @@ -2,6 +2,8 @@ #-*- coding:utf-8 -*- +from __future__ import print_function +from builtins import range import unittest @@ -12,7 +14,7 @@ class TestUtils(unittest.TestCase): # Use a callback def logger(key): - print "DELETE", key + print("DELETE", key) # Create a 5/2 dictionary bd = BoundedDict(5, 2, initialdata={"element": "value"}, @@ -26,9 +28,9 @@ class TestUtils(unittest.TestCase): # Increase 'element2' use _ = bd["element2"] - for i in xrange(6): + for i in range(6): bd[i] = i - print "Insert %d -> %s" % (i, bd) + print("Insert %d -> %s" % (i, bd)) assert(len(bd) == 2) diff --git a/test/expr_type/test_chandler.py b/test/expr_type/test_chandler.py index 09c588cb..92ebd0f2 100644 --- a/test/expr_type/test_chandler.py +++ b/test/expr_type/test_chandler.py @@ -4,7 +4,11 @@ Regression test for objc * C Miasm expression to native expression * Miasm expression to type """ +from __future__ import print_function +from future.utils import viewitems +from past.builtins import cmp +from builtins import str from miasm2.expression.expression import ExprInt, ExprId, ExprMem from miasm2.expression.simplifications import expr_simp @@ -147,18 +151,18 @@ types_ast.add_c_decl(text_2) types_mngr = CTypesManagerNotPacked(types_ast, base_types) -for type_id, type_desc in types_mngr.types_ast._types.iteritems(): - print type_id +for type_id, type_desc in viewitems(types_mngr.types_ast._types): + print(type_id) obj = types_mngr.get_objc(type_id) - print obj - print repr(obj) + print(obj) + print(repr(obj)) types_mngr.check_objc(obj) -for type_id, type_desc in types_mngr.types_ast._typedefs.iteritems(): - print type_id +for type_id, type_desc in viewitems(types_mngr.types_ast._typedefs): + print(type_id) obj = types_mngr.get_objc(type_id) - print obj - print repr(obj) + print(obj) + print(repr(obj)) types_mngr.check_objc(obj) void_ptr = types_mngr.void_ptr @@ -200,9 +204,9 @@ ptr_recurse = ExprId("ptr_recurse", 64) obj_test_st = types_mngr.get_objc(CTypeStruct("test_st")) -print repr(obj_test_st) +print(repr(obj_test_st)) obj_test_context = types_mngr.get_objc(CTypeStruct("test_context")) -print repr(obj_test_context) +print(repr(obj_test_context)) assert obj_test_context.size > obj_test_st.size assert cmp(obj_test_st, obj_recurse) != 0 @@ -513,8 +517,8 @@ mychandler.updt_expr_types(expr_types) for (expr, result) in tests: - print "*" * 80 - print "Native expr:", expr + print("*" * 80) + print("Native expr:", expr) result = set(result) expr_c = mychandler.expr_to_c(expr) types = mychandler.expr_to_types(expr) @@ -524,7 +528,7 @@ for (expr, result) in tests: access_c_gen = ExprToAccessC(expr_types, types_mngr) computed = set() for c_str, ctype in mychandler.expr_to_c_and_types(expr): - print c_str, ctype + print(c_str, ctype) computed.add((str(ctype), c_str)) assert computed == result @@ -532,12 +536,12 @@ for (expr, result) in tests: for out_type, out_str in computed: parsed_expr = mychandler.c_to_expr(out_str) parsed_type = mychandler.c_to_type(out_str) - print "Access expr:", parsed_expr - print "Access type:", parsed_type + print("Access expr:", parsed_expr) + print("Access type:", parsed_type) ast = parse_access(out_str) access_c = ast_get_c_access_expr(ast, c_context) - print "Generated access:", access_c + print("Generated access:", access_c) parsed_expr_bis, parsed_type_bis = mychandler.exprc2expr.get_expr(access_c, c_context) assert parsed_expr_bis is not None @@ -551,5 +555,5 @@ for (expr, result) in tests: expr_new1 = expr_simp(parsed_expr) expr_new2 = expr_simp(expr) - print "\t", expr_new1 + print("\t", expr_new1) assert expr_new1 == expr_new2 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))') diff --git a/test/ir/ir.py b/test/ir/ir.py index 072c90f6..3dd95c3e 100644 --- a/test/ir/ir.py +++ b/test/ir/ir.py @@ -1,3 +1,5 @@ +from future.utils import viewitems + from miasm2.expression.expression import * from miasm2.ir.ir import AssignBlock from miasm2.expression.simplifications import expr_simp @@ -34,10 +36,11 @@ else: assert assignblk1.get_r() == set([id_b]) assert assignblk1.get_w() == set([id_a]) assert assignblk1.get_rw() == {id_a: set([id_b])} -assert assignblk1.keys() == [id_a] +assert list(assignblk1) == [id_a] assert dict(assignblk1) == {id_a: id_b} assert assignblk1[id_a] == id_b -assert list(assignblk1.iteritems()) == assignblk1.items() +assert list(viewitems(assignblk1)) == list(viewitems(assignblk1)) +assert set(assignblk1.iteritems()) == set(assignblk1.items()) ## Simplify assignblk3 = AssignBlock({id_a: id_b - id_b}) diff --git a/test/ir/ir2C.py b/test/ir/ir2C.py index 6df439c2..26683468 100755 --- a/test/ir/ir2C.py +++ b/test/ir/ir2C.py @@ -1,6 +1,7 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from builtins import range import unittest from miasm2.expression.expression import TOK_EQUAL @@ -16,7 +17,7 @@ class TestIrIr2C(unittest.TestCase): from miasm2.expression.expression import ExprInt, ExprOp from miasm2.ir.translators.C import Translator - args = [ExprInt(i, 32) for i in xrange(9)] + args = [ExprInt(i, 32) for i in range(9)] translator = Translator.to_language("C") # Unary operators diff --git a/test/ir/reduce_graph.py b/test/ir/reduce_graph.py index 75ff3410..f6ebad24 100644 --- a/test/ir/reduce_graph.py +++ b/test/ir/reduce_graph.py @@ -1,6 +1,10 @@ """Regression test module for DependencyGraph""" +from __future__ import print_function +from builtins import object from pdb import pm +from future.utils import viewitems + from miasm2.expression.expression import ExprId, ExprInt, ExprAssign, ExprCond, \ ExprLoc, LocKey @@ -162,7 +166,7 @@ for irb in [G1_RES_IRB0]: def cmp_ir_graph(g1, g2): - assert g1.blocks.items() == g2.blocks.items() + assert list(viewitems(g1.blocks)) == list(viewitems(g2.blocks)) assert set(g1.edges()) == set(g2.edges()) @@ -664,11 +668,11 @@ for i, (g_test, g_ref) in enumerate( ], 1): heads = g_test.heads() - print '*'*10, 'Test', i, "*"*10 + print('*'*10, 'Test', i, "*"*10) open('test_in_%d.dot' % i, 'w').write(g_test.dot()) open('test_ref_%d.dot' % i, 'w').write(g_ref.dot()) merge_blocks(g_test, heads) open('test_out_%d.dot' % i, 'w').write(g_test.dot()) cmp_ir_graph(g_test, g_ref) - print '\t', 'OK' + print('\t', 'OK') diff --git a/test/ir/symbexec.py b/test/ir/symbexec.py index 4f01ac3c..3ab99c91 100755 --- a/test/ir/symbexec.py +++ b/test/ir/symbexec.py @@ -1,6 +1,10 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from __future__ import print_function + +from future.utils import viewitems + import unittest @@ -184,18 +188,18 @@ class TestSymbExec(unittest.TestCase): del sb.symbols[id_a] sb.dump() del sb.symbols[ExprMem(id_a, 8)] - print "*"*40, 'Orig:' + print("*"*40, 'Orig:') sb.dump() sb_cp = sb.symbols.copy() - print "*"*40, 'Copy:' + print("*"*40, 'Copy:') sb_cp.dump() # Add symbol at address limit sb.apply_change(ExprMem(ExprInt(0xFFFFFFFE, 32), 32), id_c) sb.dump() found = False - for dst, src in sb.symbols.iteritems(): + for dst, src in viewitems(sb.symbols): if dst == ExprMem(ExprInt(0xFFFFFFFE, 32), 32) and src == id_c: found = True assert found @@ -205,7 +209,7 @@ class TestSymbExec(unittest.TestCase): sb.apply_change(ExprMem(ExprInt(0x7FFFFFFE, 32), 32), id_c) sb.dump() found = False - for dst, src in sb.symbols.iteritems(): + for dst, src in viewitems(sb.symbols): if dst == ExprMem(ExprInt(0x7FFFFFFE, 32), 32) and src == id_c: found = True assert found @@ -219,7 +223,7 @@ class TestSymbExec(unittest.TestCase): sb.apply_change(ExprMem(ExprInt(0x2, 32), 16), ExprMem(ExprInt(0x2, 32), 16)) sb.dump() found = False - for dst, src in sb.symbols.iteritems(): + for dst, src in viewitems(sb.symbols): if dst == ExprMem(ExprInt(0xFFFFFFFE, 32), 32) and src == id_e[16:48]: found = True assert found @@ -230,7 +234,7 @@ class TestSymbExec(unittest.TestCase): # Test memory full - print 'full' + print('full') arch_addr8 = ir_x86_32(loc_db) ircfg = arch_addr8.new_ircfg() # Hack to obtain tiny address space @@ -240,18 +244,18 @@ class TestSymbExec(unittest.TestCase): # Fulfill memory sb_addr8.apply_change(ExprMem(ExprInt(0, 5), 256), ExprInt(0, 256)) sb_addr8.dump() - variables = sb_addr8.symbols.items() + variables = list(viewitems(sb_addr8.symbols)) assert variables == [(ExprMem(ExprInt(0, 5), 256), ExprInt(0, 256))] - print sb_addr8.symbols.symbols_mem + print(sb_addr8.symbols.symbols_mem) sb_addr8.apply_change(ExprMem(ExprInt(0x5, 5), 256), ExprInt(0x123, 256)) sb_addr8.dump() - variables = sb_addr8.symbols.items() + variables = list(viewitems(sb_addr8.symbols)) assert variables == [(ExprMem(ExprInt(0x5, 5), 256), ExprInt(0x123, 256))] - print sb_addr8.symbols.symbols_mem + print(sb_addr8.symbols.symbols_mem) - print 'dump' + print('dump') sb_addr8.symbols.symbols_mem.dump() @@ -281,7 +285,7 @@ class TestSymbExec(unittest.TestCase): assert sb.symbols.symbols_mem.contains_partial(ExprMem(ExprInt(0xFFFFFFFE, 32), 32)) assert not sb.symbols.symbols_mem.contains_partial(ExprMem(ExprInt(0xFFFFFFFF, 32), 8)) - assert sb_addr8.symbols.keys() == [ExprMem(ExprInt(0x5, 5), 256)] + assert list(sb_addr8.symbols) == [ExprMem(ExprInt(0x5, 5), 256)] if __name__ == '__main__': diff --git a/test/ir/translators/smt2.py b/test/ir/translators/smt2.py index 2b5c8df3..78472d0a 100644 --- a/test/ir/translators/smt2.py +++ b/test/ir/translators/smt2.py @@ -10,14 +10,26 @@ c = ExprId('c', 16) d = ExprId('d', 8) e = ExprId('e', 1) -left = ExprCond(e + ExprOp('parity', a), - ExprMem(a * a, 64), - ExprMem(a, 64)) - -cond = ExprSlice(ExprSlice(ExprSlice(a, 0, 32) + b, 0, 16) * c, 0, 8) << ExprOp('>>>', d, ExprInt(0x5L, 8)) -right = ExprCond(cond, - a + ExprInt(0x64L, 64), - ExprInt(0x16L, 64)) +left = ExprCond( + e + ExprOp('parity', a), + ExprMem(a * a, 64), + ExprMem(a, 64) +) + +cond = ( + ExprSlice( + ExprSlice( + ExprSlice(a, 0, 32) + b, 0, 16 + ) * c, + 0, + 8 + ) << ExprOp('>>>', d, ExprInt(0x5, 8)) +) +right = ExprCond( + cond, + a + ExprInt(0x64, 64), + ExprInt(0x16, 64) +) e = ExprAssign(left, right) @@ -32,6 +44,7 @@ smt2 = t_smt2.to_smt2([t_smt2.from_expr(e)]) # parse smt2 string with z3 smt2_z3 = parse_smt2_string(smt2) + # initialise SMT solver s = Solver() diff --git a/test/ir/translators/z3_ir.py b/test/ir/translators/z3_ir.py index 4806ad96..68421bea 100644 --- a/test/ir/translators/z3_ir.py +++ b/test/ir/translators/z3_ir.py @@ -1,3 +1,4 @@ +from __future__ import print_function import z3 from miasm2.core.locationdb import LocationDB @@ -174,5 +175,5 @@ cnttrailzeros3 = translator1.from_expr(ExprOp("cnttrailzeros", ExprInt(0x8000, 3 cntleadzeros3 = translator1.from_expr(ExprOp("cntleadzeros", ExprInt(0x8000, 32))) assert(equiv(cnttrailzeros3, cntleadzeros3)) -print "TranslatorZ3 tests are OK." +print("TranslatorZ3 tests are OK.") diff --git a/test/jitter/bad_block.py b/test/jitter/bad_block.py index ae11e696..0756dfd5 100644 --- a/test/jitter/bad_block.py +++ b/test/jitter/bad_block.py @@ -1,4 +1,5 @@ import sys +from miasm2.core.utils import decode_hex from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_UNK_MNEMO from miasm2.analysis.machine import Machine @@ -15,7 +16,7 @@ jitter.init_stack() # nop # mov eax, 0x42 # XX -data = "90b842000000ffff90909090".decode('hex') +data = decode_hex("90b842000000ffff90909090") # Will raise memory error at 0x40000006 diff --git a/test/jitter/jit_options.py b/test/jitter/jit_options.py index a0ddbc11..91d59edd 100644 --- a/test/jitter/jit_options.py +++ b/test/jitter/jit_options.py @@ -1,5 +1,8 @@ +from __future__ import print_function import os import sys + +from miasm2.core.utils import decode_hex from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE from miasm2.analysis.machine import Machine from pdb import pm @@ -16,7 +19,7 @@ from pdb import pm # RET -data = "b810000000bb0100000083e8010f44cb75f8c3".decode("hex") +data = decode_hex("b810000000bb0100000083e8010f44cb75f8c3") run_addr = 0x40000000 def code_sentinelle(jitter): @@ -40,7 +43,7 @@ def init_jitter(): return myjit # Test 'max_exec_per_call' -print "[+] First run, to jit blocks" +print("[+] First run, to jit blocks") myjit = init_jitter() myjit.init_run(run_addr) myjit.continue_run() @@ -62,7 +65,7 @@ def cb(jitter): return False ## Second run -print "[+] Second run" +print("[+] Second run") myjit.push_uint32_t(0x1337beef) myjit.cpu.EAX = 0 myjit.init_run(run_addr) @@ -74,7 +77,7 @@ assert myjit.run is True assert myjit.cpu.EAX >= 0xA # Test 'jit_maxline' -print "[+] Run instr one by one" +print("[+] Run instr one by one") myjit = init_jitter() myjit.jit.options["jit_maxline"] = 1 myjit.jit.options["max_exec_per_call"] = 1 diff --git a/test/jitter/jitload.py b/test/jitter/jitload.py index 1a56099f..5473b7d2 100644 --- a/test/jitter/jitload.py +++ b/test/jitter/jitload.py @@ -1,12 +1,13 @@ import sys from pdb import pm +from miasm2.core.utils import decode_hex, encode_hex from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE from miasm2.analysis.machine import Machine from miasm2.expression.expression import ExprId, ExprAssign, ExprInt, ExprMem # Initial data: from 'example/samples/x86_32_sc.bin' -data = "8d49048d5b0180f90174058d5bffeb038d5b0189d8c3".decode("hex") +data = decode_hex("8d49048d5b0180f90174058d5bffeb038d5b0189d8c3") # Init jitter myjit = Machine("x86_32").jitter(sys.argv[1]) @@ -46,4 +47,4 @@ assert myjit.eval_expr(eax) == imm4 ## Changes must be passed on myjit.cpu instance assert myjit.cpu.EAX == 4 ## Memory -assert myjit.eval_expr(memdata).arg.arg == int(data[::-1].encode("hex"), 16) +assert myjit.eval_expr(memdata).arg.arg == int(encode_hex(data[::-1]), 16) diff --git a/test/jitter/jmp_out_mem.py b/test/jitter/jmp_out_mem.py index 93ae8304..ff137b84 100644 --- a/test/jitter/jmp_out_mem.py +++ b/test/jitter/jmp_out_mem.py @@ -1,4 +1,5 @@ import sys +from miasm2.core.utils import decode_hex from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_ACCESS_VIOL from miasm2.analysis.machine import Machine @@ -17,7 +18,7 @@ jitter.init_stack() # mov eax, 0x42 # jmp 0x20 -data = "90b842000000eb20".decode('hex') +data = decode_hex("90b842000000eb20") # Will raise memory error at 0x40000028 diff --git a/test/jitter/test_post_instr.py b/test/jitter/test_post_instr.py index 0aff667e..ab8f8a74 100644 --- a/test/jitter/test_post_instr.py +++ b/test/jitter/test_post_instr.py @@ -1,27 +1,31 @@ +from __future__ import print_function import sys + +from miasm2.core.utils import decode_hex from miasm2.analysis.machine import Machine -from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_BREAKPOINT_MEMORY, EXCEPT_ACCESS_VIOL +from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE, \ + EXCEPT_BREAKPOINT_MEMORY, EXCEPT_ACCESS_VIOL machine = Machine("x86_32") jitter = machine.jitter(sys.argv[1]) # Prepare stack and reset memory accesses to avoid an exception -jitter.vm.add_memory_page(0x10000, PAGE_READ|PAGE_WRITE, "\x00"*0x1000, "stack") -print jitter.vm +jitter.vm.add_memory_page(0x10000, PAGE_READ|PAGE_WRITE, b"\x00"*0x1000, "stack") +print(jitter.vm) jitter.cpu.ESP = 0x10000 + 0x1000 jitter.push_uint32_t(0x0) jitter.push_uint32_t(0x1337beef) jitter.vm.reset_memory_access() -print hex(jitter.vm.get_exception()) +print(hex(jitter.vm.get_exception())) # Add code, and keep memory write pending -jitter.vm.add_memory_page(0x1000, PAGE_READ|PAGE_WRITE, "\x00"*0x1000, "code page") +jitter.vm.add_memory_page(0x1000, PAGE_READ|PAGE_WRITE, b"\x00"*0x1000, "code page") # MOV EAX, 0x11223344 # RET -jitter.vm.set_mem(0x1000, "B844332211C3".decode('hex')) +jitter.vm.set_mem(0x1000, decode_hex("B844332211C3")) jitter.set_trace_log() diff --git a/test/jitter/vm_mngr.py b/test/jitter/vm_mngr.py index 87bc6f8f..3aa4105e 100644 --- a/test/jitter/vm_mngr.py +++ b/test/jitter/vm_mngr.py @@ -6,7 +6,7 @@ myjit = Machine("x86_32").jitter(sys.argv[1]) base_addr = 0x13371337 page_size = 0x1000 -data = "\x00" * page_size +data = b"\x00" * page_size rights = [0, PAGE_READ, PAGE_WRITE, PAGE_READ|PAGE_WRITE] shuffled_rights = [PAGE_READ, 0, PAGE_READ|PAGE_WRITE, PAGE_WRITE] diff --git a/test/os_dep/common.py b/test/os_dep/common.py index 5d525e32..52512075 100755 --- a/test/os_dep/common.py +++ b/test/os_dep/common.py @@ -1,6 +1,7 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from builtins import range import unittest import logging from miasm2.analysis.machine import Machine @@ -25,7 +26,7 @@ class TestCommonAPI(unittest.TestCase): heap.alloc(jit, 60) ptr = heap.alloc(jit, 10) heap.alloc(jit, 80) - for i in xrange(10): + for i in range(10): self.assertEqual(heap.get_size(jit.vm, ptr+i), 10) if __name__ == '__main__': diff --git a/test/os_dep/linux/stdlib.py b/test/os_dep/linux/stdlib.py index ab39a487..80b99969 100755 --- a/test/os_dep/linux/stdlib.py +++ b/test/os_dep/linux/stdlib.py @@ -19,12 +19,12 @@ class TestLinuxStdlib(unittest.TestCase): def test_xxx_sprintf(self): def alloc_str(s): - s += "\x00" + s += b"\x00" ptr = heap.alloc(jit, len(s)) jit.vm.set_mem(ptr, s) return ptr - fmt = alloc_str("'%s' %d") - str_ = alloc_str("coucou") + fmt = alloc_str(b"'%s' %d") + str_ = alloc_str(b"coucou") buf = heap.alloc(jit,1024) jit.push_uint32_t(1111) @@ -34,7 +34,7 @@ class TestLinuxStdlib(unittest.TestCase): jit.push_uint32_t(0) # ret_ad stdlib.xxx_sprintf(jit) ret = jit.get_str_ansi(buf) - self.assertEqual(ret, "'coucou' 1111") + self.assertEqual(ret, b"'coucou' 1111") if __name__ == '__main__': diff --git a/test/os_dep/linux/test_env.py b/test/os_dep/linux/test_env.py index 0c80571f..1e8e7678 100644 --- a/test/os_dep/linux/test_env.py +++ b/test/os_dep/linux/test_env.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import sys from pdb import pm @@ -6,7 +7,7 @@ from miasm2.analysis.sandbox import Sandbox_Linux_x86_32, Sandbox_Linux_x86_64,\ Sandbox_Linux_arml, Sandbox_Linux_aarch64l if len(sys.argv) < 2: - print "Usage: %s <arch> ..." % sys.argv[0] + print("Usage: %s <arch> ..." % sys.argv[0]) exit(0) arch = sys.argv[1] diff --git a/test/os_dep/win_api_x86_32.py b/test/os_dep/win_api_x86_32.py index f080ba89..2dcac61d 100755 --- a/test/os_dep/win_api_x86_32.py +++ b/test/os_dep/win_api_x86_32.py @@ -1,6 +1,7 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from builtins import range import unittest import logging from miasm2.analysis.machine import Machine @@ -27,12 +28,12 @@ class TestWinAPI(unittest.TestCase): def test_msvcrt_sprintf(self): def alloc_str(s): - s += "\x00" + s += b"\x00" ptr = heap.alloc(jit, len(s)) jit.vm.set_mem(ptr, s) return ptr - fmt = alloc_str("'%s' %d") - str_ = alloc_str("coucou") + fmt = alloc_str(b"'%s' %d") + str_ = alloc_str(b"coucou") buf = heap.alloc(jit,1024) jit.push_uint32_t(1111) @@ -42,13 +43,13 @@ class TestWinAPI(unittest.TestCase): jit.push_uint32_t(0) # ret_ad winapi.msvcrt_sprintf(jit) ret = jit.get_str_ansi(buf) - self.assertEqual(ret, "'coucou' 1111") + self.assertEqual(ret, b"'coucou' 1111") def test_msvcrt_swprintf(self): def alloc_str(s): s = s.encode("utf-16le") - s += "\x00\x00" + s += b"\x00\x00" ptr = heap.alloc(jit, len(s)) jit.vm.set_mem(ptr, s) return ptr @@ -63,7 +64,7 @@ class TestWinAPI(unittest.TestCase): jit.push_uint32_t(0) # ret_ad winapi.msvcrt_swprintf(jit) ret = jit.get_str_unic(buf) - self.assertEqual(ret, "'coucou' 1111") + self.assertEqual(ret, u"'coucou' 1111") def test_msvcrt_realloc(self): @@ -88,7 +89,7 @@ class TestWinAPI(unittest.TestCase): # Test with a buffer long enough addr = 0x80000 size = len(winapi.winobjs.cur_dir)+1 - jit.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\x00" * (size), "") + jit.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, b"\x00" * (size), "") jit.push_uint32_t(addr) # buf jit.push_uint32_t(size) # size jit.push_uint32_t(0) # @return @@ -98,7 +99,7 @@ class TestWinAPI(unittest.TestCase): self.assertEqual(len(dir_), size_ret) # Test with a buffer too small - jit.vm.set_mem(addr, "\xFF"*size) + jit.vm.set_mem(addr, b"\xFF"*size) jit.push_uint32_t(addr) # buf jit.push_uint32_t(5) # size jit.push_uint32_t(0) # @return @@ -215,7 +216,7 @@ class TestWinAPI(unittest.TestCase): self.assertTrue(vBool) # BOOL WINAPI Process32Next(_In_ HANDLE hSnapshot, _Out_ LPPROCESSENTRY32 lppe); - for i in xrange(3, -1, -1): + for i in range(3, -1, -1): jit.push_uint32_t(jit.stack_base) # lppe jit.push_uint32_t(hSnap) # hSnapshot jit.push_uint32_t(0) # @return diff --git a/test/test_all.py b/test/test_all.py index 008d837f..a8a0d599 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -1,5 +1,8 @@ #! /usr/bin/env python2 +from __future__ import print_function +from builtins import map +from builtins import range import argparse from distutils.spawn import find_executable import os @@ -52,6 +55,12 @@ testset += RegressionTest(["x86/arch.py"], base_dir="arch", "regression_test32_ia32.bin", "regression_test64_ia32.bin"]) +testset += RegressionTest(["arm/arch.py"], base_dir="arch") +testset += RegressionTest(["aarch64/arch.py"], base_dir="arch") +testset += RegressionTest(["sh4/arch.py"], base_dir="arch") +testset += RegressionTest(["msp430/arch.py"], base_dir="arch") +testset += RegressionTest(["mips32/arch.py"], base_dir="arch") + ### ArchUnit regression tests @@ -92,14 +101,9 @@ for script in ["x86/sem.py", "x86/unit/mn_getset128.py", "x86/unit/mn_cmov.py", "x86/unit/mn_rotsh.py", - "arm/arch.py", "arm/sem.py", "aarch64/unit/mn_ubfm.py", - "aarch64/arch.py", - "msp430/arch.py", "msp430/sem.py", - "sh4/arch.py", - "mips32/arch.py", "mips32/unit/mn_bcc.py", ]: for jitter in ArchUnitTest.jitter_engines: @@ -359,7 +363,7 @@ testset += RegressionTest(["depgraph.py"], base_dir="analysis", products=[fname for fnames in ( ["graph_test_%02d_00.dot" % test_nb, "graph_%02d.dot" % test_nb] - for test_nb in xrange(1, 18)) + for test_nb in range(1, 18)) for fname in fnames] + ["graph_test_%02d_%02d.dot" % (test_nb, res_nb) for (test_nb, res_nb) in ((3, 1), (5, 1), (8, 1), @@ -382,11 +386,11 @@ testset += RegressionTest(["range.py"], base_dir="analysis", testset += RegressionTest(["data_flow.py"], base_dir="analysis", products=[fname for fnames in ( ["simp_graph_%02d.dot" % test_nb, "graph_%02d.dot" % test_nb] - for test_nb in xrange(1, 18)) + for test_nb in range(1, 18)) for fname in fnames]) testset += RegressionTest(["unssa.py"], base_dir="analysis") -for i in xrange(1, 21): +for i in range(1, 21): input_name = "cst_propag/x86_32_sc_%d" % i bin_name = "samples/x86_32/%s.bin" % input_name test_x86_32_cst = SemanticTestAsm("x86_32", None, [input_name]) @@ -410,7 +414,7 @@ class TestDepgraph(RegressionTest): super(TestDepgraph, self).__init__([self.launcher], *args, **kwargs) self.base_dir = os.path.join(self.base_dir, "analysis") - self.products = ["sol_%d.dot" % i for i in xrange(nb_sol)] + self.products = ["sol_%d.dot" % i for i in range(nb_sol)] if implicit: expected_fname = "dg_test_%.2d_implicit_expected.json" self.tags.append(TAGS["z3"]) @@ -507,7 +511,7 @@ class ExampleShellcode(ExampleAssembler): super(ExampleShellcode, self).__init__(*args, **kwargs) self.command_line = ["shellcode.py", self.command_line[0]] + \ - map(Example.get_sample, self.command_line[1:3]) + \ + list(map(Example.get_sample, self.command_line[1:3])) + \ self.command_line[3:] self.products = [self.command_line[3], "graph.dot"] @@ -709,7 +713,7 @@ for options, nb_sol, tag in [([], 8, []), "-m", "x86_32", "0x0", "0x8b", "EAX"] + options, products=["sol_%d.dot" % nb - for nb in xrange(nb_sol)], + for nb in range(nb_sol)], tags=tag) for options, nb_sol, tag in [([], 4, []), @@ -719,7 +723,7 @@ for options, nb_sol, tag in [([], 4, []), "-m", "x86_32", "0x0", "0x19", "EAX"] + options, products=["sol_%d.dot" % nb - for nb in xrange(nb_sol)], + for nb in range(nb_sol)], depends=[test_x86_32_if_reg], tags=tag) @@ -761,17 +765,6 @@ for jitter in ExampleJitter.jitter_engines: ["--jitter", jitter], products=[Example.get_sample("box_upx_exe_unupx.bin")], tags=tags.get(jitter, [])) - if jitter != "python": - tags = tags.get(jitter, []) + [TAGS["long"], TAGS["linux"]] - ls_path = find_executable("ls") - file_path = find_executable("file") - # Launch simulation of "file /bin/ls", with access to libs and ld info - testset += ExampleJitter(["run_with_linuxenv.py", "-v", "-p", - '/(.*lib.*\.so(\.\d+)?)|(/etc/ld.so.*)|(.*magic.*)|(%s)' % ls_path, - ] + ["--jitter", jitter] + [ - file_path, ls_path, - ], - tags=tags) for script, dep in [(["x86_32.py", Example.get_sample("x86_32_sc.bin")], []), @@ -826,10 +819,10 @@ if __name__ == "__main__": action="store_true") parser.add_argument("-t", "--omit-tags", help="Omit tests based on tags \ (tag1,tag2). Available tags are %s. \ -By default, no tag is omitted." % ", ".join(TAGS.keys()), default="") +By default, no tag is omitted." % ", ".join(list(TAGS)), default="") parser.add_argument("-o", "--only-tags", help="Restrict to tests based on tags \ (tag1,tag2). Available tags are %s. \ -By default, all tag are considered." % ", ".join(TAGS.keys()), default="") +By default, all tag are considered." % ", ".join(list(TAGS)), default="") parser.add_argument("-n", "--do-not-clean", help="Do not clean tests products", action="store_true") args = parser.parse_args() @@ -848,14 +841,14 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") if not tag: continue if tag not in TAGS: - print "%(red)s[TAG]%(end)s" % cosmetics.colors, \ - "Unknown tag '%s'" % tag + print("%(red)s[TAG]%(end)s" % cosmetics.colors, \ + "Unknown tag '%s'" % tag) exit(-1) dest.append(TAGS[tag]) if exclude_tags and include_tags: - print "%(red)s[TAG]%(end)s" % cosmetics.colors, \ - "Omit and Only used together: whitelist mode" + print("%(red)s[TAG]%(end)s" % cosmetics.colors, \ + "Omit and Only used together: whitelist mode") # Handle coverage coveragerc = None @@ -863,8 +856,8 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") try: import coverage except ImportError: - print "%(red)s[Coverage]%(end)s " % cosmetics.colors + \ - "Python 'coverage' module is required" + print("%(red)s[Coverage]%(end)s " % cosmetics.colors + \ + "Python 'coverage' module is required") exit(-1) # Create directory @@ -875,7 +868,7 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") coveragerc = os.path.join(cov_dir, ".coveragerc") coverage = os.path.join(cov_dir, ".coverage") - from ConfigParser import ConfigParser + from configparser import ConfigParser from os.path import expanduser config = ConfigParser() @@ -894,7 +887,7 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") d = {"blue": cosmetics.colors['blue'], "end": cosmetics.colors['end'], "cov_dir": cov_dir} - print "[%(blue)sCoverage%(end)s] Report will be written in %(cov_dir)s" % d + print("[%(blue)sCoverage%(end)s] Report will be written in %(cov_dir)s" % d) # Handle llvm modularity llvm = True @@ -904,8 +897,8 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") llvm = False if llvm is False: - print "%(red)s[LLVM]%(end)s Python" % cosmetics.colors + \ - "'llvmlite' module is required for llvm tests" + print("%(red)s[LLVM]%(end)s Python" % cosmetics.colors + \ + "'llvmlite' module is required for llvm tests") # Remove llvm tests if TAGS["llvm"] not in exclude_tags: @@ -915,8 +908,8 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") try: import z3 except ImportError: - print "%(red)s[Z3]%(end)s " % cosmetics.colors + \ - "Z3 and its python binding are necessary for TranslatorZ3." + print("%(red)s[Z3]%(end)s " % cosmetics.colors + \ + "Z3 and its python binding are necessary for TranslatorZ3.") if TAGS["z3"] not in exclude_tags: exclude_tags.append(TAGS["z3"]) @@ -924,8 +917,8 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") try: import pycparser except ImportError: - print "%(red)s[PYCPARSER]%(end)s " % cosmetics.colors + \ - "pycparser are necessary for Objc." + print("%(red)s[PYCPARSER]%(end)s " % cosmetics.colors + \ + "pycparser are necessary for Objc.") if TAGS["cparser"] not in exclude_tags: exclude_tags.append(TAGS["cparser"]) @@ -952,13 +945,13 @@ By default, all tag are considered." % ", ".join(TAGS.keys()), default="") # Finalize testset.end(clean=not args.do_not_clean) - print + print() print (cosmetics.colors["green"] + "Result: %d/%d pass" % (len(test_ok), len(test_ok) + len(test_ko)) + cosmetics.colors["end"]) for test, error in test_ko: command_line = " ".join(test.command_line) - print cosmetics.colors["red"] + 'ERROR', cosmetics.colors["lightcyan"] + command_line + cosmetics.colors["end"] - print error + print(cosmetics.colors["red"] + 'ERROR', cosmetics.colors["lightcyan"] + command_line + cosmetics.colors["end"]) + print(error) # Exit with an error if at least a test failed exit(testset.tests_passed()) diff --git a/test/utils/cosmetics.py b/test/utils/cosmetics.py index e80e1f09..da7a6bc5 100644 --- a/test/utils/cosmetics.py +++ b/test/utils/cosmetics.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import platform @@ -33,23 +34,27 @@ def getTerminalSize(): WIDTH = getTerminalSize()[0] -colors = {"red": "\033[91;1m", - "end": "\033[0m", - "green": "\033[92;1m", - "lightcyan": "\033[96m", - "blue": "\033[94;1m"} +colors = { + "red": "\033[91;1m", + "end": "\033[0m", + "green": "\033[92;1m", + "lightcyan": "\033[96m", + "blue": "\033[94;1m" +} if is_win: - colors = {"red": "", - "end": "", - "green": "", - "lightcyan": "", - "blue": ""} + colors = { + "red": "", + "end": "", + "green": "", + "lightcyan": "", + "blue": "" + } def write_colored(text, color, already_printed=0): text_colored = colors[color] + text + colors["end"] - print " " * (WIDTH - already_printed - len(text)) + text_colored + print(" " * (WIDTH - already_printed - len(text)) + text_colored) def write_underline(text): - print "\033[4m" + text + colors["end"] + print("\033[4m" + text + colors["end"]) diff --git a/test/utils/multithread.py b/test/utils/multithread.py index 287b5ebd..d0874dd1 100644 --- a/test/utils/multithread.py +++ b/test/utils/multithread.py @@ -1,24 +1,25 @@ +from __future__ import print_function import sys -import cosmetics +from . import cosmetics import time def task_done(test, error, test_ok, test_ko): command_line = " ".join(test.command_line) if error is not None: - print cosmetics.colors["red"] + 'ERROR', - print cosmetics.colors["lightcyan"] + command_line + cosmetics.colors["end"] - print error + print(cosmetics.colors["red"] + 'ERROR', end=' ') + print(cosmetics.colors["lightcyan"] + command_line + cosmetics.colors["end"]) + print(error) test_ko.append((test, error)) else: - print cosmetics.colors["green"] + 'DONE', - print cosmetics.colors["lightcyan"] + command_line + cosmetics.colors["end"], - print "%ds" % (time.time() - test.start_time) + print(cosmetics.colors["green"] + 'DONE', end=' ') + print(cosmetics.colors["lightcyan"] + command_line + cosmetics.colors["end"], end=' ') + print("%ds" % (time.time() - test.start_time)) test_ok.append((test, error)) def task_new(test): command_line = " ".join(test.command_line) - print cosmetics.colors["lightcyan"], - print test.base_dir.upper(), command_line, - print cosmetics.colors["end"] + print(cosmetics.colors["lightcyan"], end=' ') + print(test.base_dir.upper(), command_line, end=' ') + print(cosmetics.colors["end"]) diff --git a/test/utils/testset.py b/test/utils/testset.py index 7b60e836..eee0e6f7 100644 --- a/test/utils/testset.py +++ b/test/utils/testset.py @@ -1,10 +1,12 @@ +from __future__ import print_function +from builtins import range import os import subprocess import sys import time from multiprocessing import cpu_count, Queue, Process -from test import Test +from .test import Test class Message(object): @@ -136,7 +138,7 @@ class TestSet(object): if len(self.tests) == 0: # Poison pills - for _ in xrange(self.cpu_c): + for _ in range(self.cpu_c): self.todo_queue.put(None) # All tasks done @@ -201,7 +203,7 @@ class TestSet(object): try: os.remove(product) except OSError: - print "Cleanning error: Unable to remove %s" % product + print("Cleanning error: Unable to remove %s" % product) def add_additional_args(self, args): """Add arguments to used on the test command line @@ -218,7 +220,7 @@ class TestSet(object): # Launch workers processes = [] - for _ in xrange(self.cpu_c): + for _ in range(self.cpu_c): p = Process(target=TestSet.worker, args=(self.todo_queue, self.message_queue, self.additional_args)) |