def test_to_json_meta_bridges(): forest = TraceForest(1) forest.resops = {15: 'guard_true'} trunk = forest.add_trace('loop', 0, 0) bridge1 = forest.add_trace('bridge', 1, 0) bridge2 = forest.add_trace('bridge', 2, 0) bridge3 = forest.add_trace('bridge', 3, 0) forest.descr_nmr_to_point_in_trace[10] = PointInTrace(trunk, None) forest.descr_nmr_to_point_in_trace[11] = PointInTrace(trunk, None) forest.descr_nmr_to_point_in_trace[12] = PointInTrace(bridge1, None) forest.descr_nmr_to_point_in_trace[13] = PointInTrace(bridge2, None) # trunk.set_addr_bounds(99, 100) bridge1.set_addr_bounds(100, 101) bridge2.set_addr_bounds(200, 201) bridge3.set_addr_bounds(300, 301) # forest.stitch_bridge(10, 100) forest.stitch_bridge(11, 200) forest.stitch_bridge(12, 300) # stage = trunk.start_mark(const.MARK_TRACE_OPT) j = LogMetaSerializer().to_representation(FakeJitLog(forest)) assert len(j['bridges']) == 4 bridges = j['bridges'] assert bridges[0] == {10: 100, 11: 200} assert bridges[1] == {12: 300} assert bridges[2] == {} assert bridges[3] == {}
def test_to_json_meta_links(): forest = TraceForest(1) forest.resops = { 15: 'guard_true' } trunk = forest.add_trace('loop', 0, 0) bridge1 = forest.add_trace('bridge', 1, 0) bridge2 = forest.add_trace('bridge', 2, 0) bridge3 = forest.add_trace('bridge', 3, 0) op = FlatOp(0,'',[],None,0,0) op.index = 42 forest.descr_nmr_to_point_in_trace[10] = PointInTrace(trunk, op) forest.descr_nmr_to_point_in_trace[11] = PointInTrace(trunk, None) forest.descr_nmr_to_point_in_trace[12] = PointInTrace(bridge1, None) forest.descr_nmr_to_point_in_trace[13] = PointInTrace(bridge2, None) # trunk.set_addr_bounds(99,100) bridge1.set_addr_bounds(100,101) bridge2.set_addr_bounds(200,201) bridge3.set_addr_bounds(300,301) # forest.stitch_bridge(10, 100) forest.stitch_bridge(11, 200) forest.stitch_bridge(12, 300) # stage = trunk.start_mark(const.MARK_TRACE_OPT) j = LogMetaSerializer().to_representation(forest) assert len(j['links']) == 2 links = j['links'] assert links[0] == {42: 1, 0: 2} assert links[1] == {0: 3}
def test_to_json_meta_info(): forest = TraceForest(1, False, 'x86') forest.resops = {15: 'divide'} trace = forest.add_trace('loop', 0, 0) trace.counter = 42 stage = trace.start_mark(const.MARK_TRACE_OPT) stage.append_op(MergePoint({const.MP_SCOPE[0]: 'my_func'})) json = LogMetaSerializer().to_representation(FakeJitLog(forest)) del json['bridges'] # do not care for this test assert json == \ { 'resops': { 15: 'divide' }, 'traces': { 0: { 'scope': 'my_func', 'filename': None, 'lineno': 0, 'type': 'loop', 'counter_points': { 'enter': 42 } } }, 'word_size': 8, 'machine': 'x86' }
def test_to_json_meta_info(): forest = TraceForest(1, False, 'x86') forest.resops = { 15: 'divide' } trace = forest.add_trace('loop', 0, 0, 'john') trace.counter = 42 stage = trace.start_mark(const.MARK_TRACE_OPT) stage.append_op(MergePoint({const.MP_SCOPE[0]: 'my_func' })) json = LogMetaSerializer().to_representation(forest) assert json == \ { 'resops': { 15: 'divide' }, 'traces': { 0: { 'scope': 'my_func', 'filename': None, 'lineno': 0, 'type': 'loop', 'counter_points': { 0: 42 }, 'jd_name': 'john', 'stamp': 0 } }, 'word_size': 8, 'machine': 'x86', 'links': {}, }
def forest(): forest = TraceForest(1) forest.resops = DEFAULT_TEST_RESOPS return forest