예제 #1
0
def test_merge_point_extract_source_code():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1:'jitlog/test/data/code.py', 0x2: 2}))
    trace.add_instr(FlatOp(0, 'INT_ADD', ['i1','i2'], 'i3'))
    forest.extract_source_code_lines()
    assert forest.source_lines['jitlog/test/data/code.py'][2] == (4, 'return a + b')
예제 #2
0
def test_merge_point_extract_source_code():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 2}))
    trace.add_instr(FlatOp(0, 'INT_ADD', ['i1', 'i2'], 'i3'))
    forest.extract_source_code_lines()
    assert forest.source_lines['jitlog/test/data/code.py'][2] == (
        4, 'return a + b')
예제 #3
0
def test_merge_point_duplicate_source_lines():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    forest.extract_source_code_lines()
    assert forest.source_lines['jitlog/test/data/code.py'][5] == (4, 'c = a * 2')
    assert len(forest.source_lines['jitlog/test/data/code.py']) == 1
예제 #4
0
def test_merge_point_extract_multiple_lines():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(FlatOp(0, 'INT_MUL', ['i1','i2'], 'i3'))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 7}))
    forest.extract_source_code_lines()
    assert forest.source_lines['jitlog/test/data/code.py'][5] == (4, 'c = a * 2')
    assert forest.source_lines['jitlog/test/data/code.py'][6] == (8, 'd = c * 3')
    assert forest.source_lines['jitlog/test/data/code.py'][7] == (4, 'return d + 5')
예제 #5
0
def test_merge_point_duplicate_source_lines():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    forest.extract_source_code_lines()
    assert forest.source_lines['jitlog/test/data/code.py'][5] == (4,
                                                                  'c = a * 2')
    assert len(forest.source_lines['jitlog/test/data/code.py']) == 1
예제 #6
0
def test_merge_point_extract_multiple_lines():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(FlatOp(0, 'INT_MUL', ['i1', 'i2'], 'i3'))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 7}))
    forest.extract_source_code_lines()
    assert forest.source_lines['jitlog/test/data/code.py'][5] == (4,
                                                                  'c = a * 2')
    assert forest.source_lines['jitlog/test/data/code.py'][6] == (8,
                                                                  'd = c * 3')
    assert forest.source_lines['jitlog/test/data/code.py'][7] == (
        4, 'return d + 5')
예제 #7
0
def test_merge_point_encode():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1:'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(FlatOp(0, 'INT_MUL', ['i1','i2'], 'i3'))
    trace.add_instr(MergePoint({0x1:'jitlog/test/data/code.py', 0x2: 7}))
    trace.add_instr(MergePoint({0x1:'jitlog/test/data/code2.py', 0x2: 3}))
    forest.extract_source_code_lines()
    binary = trace.forest.encode_source_code_lines()
    parta = b'\x22\x19\x00\x00\x00jitlog/test/data/code2.py' \
            b'\x01\x00' \
            b'\x03\x00\x07\x13\x00\x00\x00self.unique = False'
    partb = b'\x22\x18\x00\x00\x00jitlog/test/data/code.py' \
            b'\x03\x00' \
            b'\x05\x00\x04\x09\x00\x00\x00c = a * 2' \
            b'\x06\x00\x08\x09\x00\x00\x00d = c * 3' \
            b'\x07\x00\x04\x0c\x00\x00\x00return d + 5'
    equals = binary == parta + partb
    if not equals:
        assert binary == partb + parta
예제 #8
0
def test_merge_point_encode():
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 5}))
    trace.add_instr(FlatOp(0, 'INT_MUL', ['i1', 'i2'], 'i3'))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code.py', 0x2: 7}))
    trace.add_instr(MergePoint({0x1: 'jitlog/test/data/code2.py', 0x2: 3}))
    forest.extract_source_code_lines()
    binary = trace.forest.encode_source_code_lines()
    parta = b'\x22\x19\x00\x00\x00jitlog/test/data/code2.py' \
            b'\x01\x00' \
            b'\x03\x00\x07\x13\x00\x00\x00self.unique = False'
    partb = b'\x22\x18\x00\x00\x00jitlog/test/data/code.py' \
            b'\x03\x00' \
            b'\x05\x00\x04\x09\x00\x00\x00c = a * 2' \
            b'\x06\x00\x08\x09\x00\x00\x00d = c * 3' \
            b'\x07\x00\x04\x0c\x00\x00\x00return d + 5'
    equals = binary == parta + partb
    if not equals:
        assert binary == partb + parta
예제 #9
0
def test_merge_point_extract_source_code(encoding,text,decoded,bom,tmpdir):
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    file = tmpdir.join("file"+encoding+".py")
    l = []
    if bom:
        l.append(bom)
    l.append("# coding: ".encode(encoding))
    l.append(encoding.encode(encoding))
    l.append("\r\n".encode(encoding))
    l.append("print(\"".encode(encoding))
    l.append(text)
    l.append("\")".encode(encoding))
    l.append("\r\n".encode(encoding))
    file.write_binary(b''.join(l))
    trace.add_instr(MergePoint({0x1: str(file), 0x2: 2}))
    forest.extract_source_code_lines()
    line = forest.source_lines[str(file)][2]
    if PY3:
        assert line == (0, "print(\"" + decoded + "\")")
    else:
        assert line == (0, "print(\"" + text + "\")")
예제 #10
0
def test_merge_point_extract_source_code(encoding, text, decoded, bom, tmpdir):
    forest = TraceForest(1)
    trace = forest.add_trace('loop', 0, 0)
    trace.start_mark(const.MARK_TRACE_OPT)
    file = tmpdir.join("file" + encoding + ".py")
    l = []
    if bom:
        l.append(bom)
    l.append("# coding: ".encode(encoding))
    l.append(encoding.encode(encoding))
    l.append("\r\n".encode(encoding))
    l.append("print(\"".encode(encoding))
    l.append(text)
    l.append("\")".encode(encoding))
    l.append("\r\n".encode(encoding))
    file.write_binary(b''.join(l))
    trace.add_instr(MergePoint({0x1: str(file), 0x2: 2}))
    forest.extract_source_code_lines()
    line = forest.source_lines[str(file)][2]
    if PY3:
        assert line == (0, "print(\"" + decoded + "\")")
    else:
        assert line == (0, "print(\"" + text + "\")")