1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
from cStringIO import StringIO
from rpython.jit.backend.tool.viewcode import format_code_dump_with_labels
from rpython.jit.backend.tool.viewcode import find_objdump
import os
import py
import tempfile
from rpython.tool.udir import udir
def test_format_code_dump_with_labels():
lines = StringIO("""
aa00 <.data>:
aa00: one
aa01: two
aa03: three
aa04: for
aa05: five
aa06: six
aa0c: seven
aa12: eight
""".strip()).readlines()
#
label_list = [(0x00, 'AAA'), (0x03, 'BBB'), (0x0c, 'CCC')]
lines = format_code_dump_with_labels(0xAA00, lines, label_list)
out = ''.join(lines)
assert out == """
aa00 <.data>:
AAA
aa00: one
aa01: two
BBB
aa03: three
aa04: for
aa05: five
aa06: six
CCC
aa0c: seven
aa12: eight
""".strip()
def test_format_code_dump_with_labels_no_labels():
input = """
aa00 <.data>:
aa00: one
aa01: two
aa03: three
aa04: for
aa05: five
aa06: six
aa0c: seven
aa12: eight
""".strip()
lines = StringIO(input).readlines()
#
lines = format_code_dump_with_labels(0xAA00, lines, label_list=None)
out = ''.join(lines)
assert out.strip() == input
def test_find_objdump():
old = os.environ['PATH']
os.environ['PATH'] = ''
py.test.raises(Exception, find_objdump)
#
path = udir.join('objdump')
print >>path, 'hello world'
os.environ['PATH'] = path.dirname
assert find_objdump() == 'objdump'
#
os.environ['PATH'] = old
|