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
|
"""Script to be invoked by GDB for testing decorable pretty printing.
"""
import gdb
import re
import sys
# Here we substitute in the pip_requirements verification code, so this test
# can remain a self contained test with little complexity. This is essentially an
# import we are generating into the file instead to avoid and complex importer logic.
# Start of pip verification code
@verify_requirements@
# End of pip verification code
expected_patterns = [
r'Decorable<MyDecorable\> with 3 elems',
r'vector of length 3.*\{ *123, *213, *312 *\}',
r'basic_string.* \= *"hello"',
r'basic_string.* \= *"world"',
]
up_pattern = r'std::unique_ptr<int\> = \{get\(\) \= 0x[0-9a-fA-F]+\}'
set_pattern = r'std::[__debug::]*set with 4 elements'
static_member_pattern = '128'
def search(pattern, s):
match = re.search(pattern, s)
assert match is not None, 'Did not find {!s} in {!s}'.format(pattern, s)
return match
def test_decorable():
gdb.execute('run')
gdb.execute('frame function main')
d1_str = gdb.execute('print d1', to_string=True)
for pattern in expected_patterns:
search(pattern, d1_str)
search(up_pattern, gdb.execute('print up', to_string=True))
search(set_pattern, gdb.execute('print set_type', to_string=True))
search(static_member_pattern, gdb.execute('print testClass::static_member', to_string=True))
def configure_gdb():
import os,subprocess,sys
cmd = 'python -c "import os,sys;print(os.linesep.join(sys.path).strip())"'
paths = subprocess.check_output(cmd,shell=True).decode("utf-8").split()
sys.path.extend(paths)
gdb.execute('source .gdbinit')
try:
verify_requirements('etc/pip/components/core.req', executable=f"@python_executable@")
except MissingRequirements as ex:
print(ex)
if __name__ == '__main__':
try:
configure_gdb()
test_decorable()
gdb.write('TEST PASSED\n')
except Exception as err:
gdb.write('TEST FAILED -- {!s}\n'.format(err))
gdb.execute('quit 1', to_string=True)
|