Debian Codegraph @

rpython/jit/backend/x86/tool/test/test_viewcode.py

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