]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-script / TestDataFormatterScript.py
1 """
2 Test lldb data formatter subsystem.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14
15 class ScriptDataFormatterTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def test_with_run_command(self):
20         """Test data formatter commands."""
21         self.build()
22         self.data_formatter_commands()
23
24     def setUp(self):
25         # Call super's setUp().
26         TestBase.setUp(self)
27         # Find the line number to break at.
28         self.line = line_number('main.cpp', '// Set break point at this line.')
29
30     def data_formatter_commands(self):
31         """Test that that file and class static variables display correctly."""
32         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33
34         lldbutil.run_break_set_by_file_and_line(
35             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
36
37         self.runCmd("run", RUN_SUCCEEDED)
38
39         # The stop reason of the thread should be breakpoint.
40         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
41                     substrs=['stopped',
42                              'stop reason = breakpoint'])
43
44         # This is the function to remove the custom formats in order to have a
45         # clean slate for the next test case.
46         def cleanup():
47             self.runCmd('type format clear', check=False)
48             self.runCmd('type summary clear', check=False)
49
50         # Execute the cleanup function during test case tear down.
51         self.addTearDownHook(cleanup)
52
53         # Set the script here to ease the formatting
54         script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'Hello from Python, \' + a_val + \' time\'; return str + (\'!\' if a_val == \'1\' else \'s!\');'
55
56         self.runCmd(
57             "type summary add i_am_cool --python-script \"%s\"" %
58             script)
59         self.expect('type summary list i_am_cool', substrs=[script])
60
61         self.expect("frame variable one",
62                     substrs=['Hello from Python',
63                              '1 time!'])
64
65         self.expect("frame variable two",
66                     substrs=['Hello from Python',
67                              '4 times!'])
68
69         self.runCmd("n")  # skip ahead to make values change
70
71         self.expect("frame variable three",
72                     substrs=['Hello from Python, 10 times!',
73                              'Hello from Python, 4 times!'])
74
75         self.runCmd("n")  # skip ahead to make values change
76
77         self.expect("frame variable two",
78                     substrs=['Hello from Python',
79                              '1 time!'])
80
81         script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'int says \' + a_val; return str;'
82
83         # Check that changes in the script are immediately reflected
84         self.runCmd(
85             "type summary add i_am_cool --python-script \"%s\"" %
86             script)
87
88         self.expect("frame variable two",
89                     substrs=['int says 1'])
90
91         self.expect("frame variable twoptr",
92                     substrs=['int says 1'])
93
94         # Change the summary
95         self.runCmd(
96             "type summary add --summary-string \"int says ${var.integer}, and float says ${var.floating}\" i_am_cool")
97
98         self.expect("frame variable two",
99                     substrs=['int says 1',
100                              'and float says 2.71'])
101         # Try it for pointers
102         self.expect("frame variable twoptr",
103                     substrs=['int says 1',
104                              'and float says 2.71'])
105
106         # Force a failure for pointers
107         self.runCmd(
108             "type summary add i_am_cool -p --python-script \"%s\"" %
109             script)
110
111         self.expect("frame variable twoptr", matching=False,
112                     substrs=['and float says 2.71'])
113
114         script = 'return \'Python summary\''
115
116         self.runCmd(
117             "type summary add --name test_summary --python-script \"%s\"" %
118             script)
119
120         # attach the Python named summary to someone
121         self.expect("frame variable one --summary test_summary",
122                     substrs=['Python summary'])
123
124         # should not bind to the type
125         self.expect("frame variable two", matching=False,
126                     substrs=['Python summary'])
127
128         # and should not stick to the variable
129         self.expect("frame variable one", matching=False,
130                     substrs=['Python summary'])
131
132         self.runCmd(
133             "type summary add i_am_cool --summary-string \"Text summary\"")
134
135         # should be temporary only
136         self.expect("frame variable one", matching=False,
137                     substrs=['Python summary'])
138
139         # use the type summary
140         self.expect("frame variable two",
141                     substrs=['Text summary'])
142
143         self.runCmd("n")  # skip ahead to make values change
144
145         # both should use the type summary now
146         self.expect("frame variable one",
147                     substrs=['Text summary'])
148
149         self.expect("frame variable two",
150                     substrs=['Text summary'])
151
152         # disable type summary for pointers, and make a Python regex summary
153         self.runCmd(
154             "type summary add i_am_cool -p --summary-string \"Text summary\"")
155         self.runCmd("type summary add -x cool --python-script \"%s\"" % script)
156
157         # variables should stick to the type summary
158         self.expect("frame variable one",
159                     substrs=['Text summary'])
160
161         self.expect("frame variable two",
162                     substrs=['Text summary'])
163
164         # array and pointer should match the Python one
165         self.expect("frame variable twoptr",
166                     substrs=['Python summary'])
167
168         self.expect("frame variable array",
169                     substrs=['Python summary'])
170
171         # return pointers to the type summary
172         self.runCmd(
173             "type summary add i_am_cool --summary-string \"Text summary\"")
174
175         self.expect("frame variable one",
176                     substrs=['Text summary'])
177
178         self.expect("frame variable two",
179                     substrs=['Text summary'])
180
181         self.expect("frame variable twoptr",
182                     substrs=['Text summary'])
183
184         self.expect("frame variable array",
185                     substrs=['Python summary'])