]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/TestDataFormatterStdMap.py
Vendor import of lldb trunk r321017:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-stl / libstdcpp / map / TestDataFormatterStdMap.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.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class StdMapDataFormatterTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Find the line number to break at.
24         self.line = line_number('main.cpp', '// Set break point at this line.')
25
26     @skipIfWindows  # libstdcpp not ported to Windows
27     @skipIfFreeBSD
28     @skipIfwatchOS  # libstdcpp not ported to watchos
29     def test_with_run_command(self):
30         """Test that that file and class static variables display correctly."""
31         self.build()
32         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33
34         lldbutil.run_break_set_by_source_regexp(
35             self, "Set break point at this line.")
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             self.runCmd('type filter clear', check=False)
50             self.runCmd('type synth clear', check=False)
51             self.runCmd(
52                 "settings set target.max-children-count 256",
53                 check=False)
54
55         # Execute the cleanup function during test case tear down.
56         self.addTearDownHook(cleanup)
57
58         self.runCmd("frame variable ii --show-types")
59
60         self.runCmd(
61             "type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e")
62
63         self.expect('frame variable ii',
64                     substrs=['map has 0 items',
65                              '{}'])
66
67         self.runCmd("c")
68
69         self.expect('frame variable ii',
70                     substrs=['map has 2 items',
71                              '[0] = ',
72                              'first = 0',
73                              'second = 0',
74                              '[1] = ',
75                              'first = 1',
76                              'second = 1'])
77
78         self.runCmd("c")
79
80         self.expect('frame variable ii',
81                     substrs=['map has 4 items',
82                              '[2] = ',
83                              'first = 2',
84                              'second = 0',
85                              '[3] = ',
86                              'first = 3',
87                              'second = 1'])
88
89         self.runCmd("c")
90
91         self.expect("frame variable ii",
92                     substrs=['map has 9 items',
93                              '[5] = ',
94                              'first = 5',
95                              'second = 0',
96                              '[7] = ',
97                              'first = 7',
98                              'second = 1'])
99
100         self.expect("p ii",
101                     substrs=['map has 9 items',
102                              '[5] = ',
103                              'first = 5',
104                              'second = 0',
105                              '[7] = ',
106                              'first = 7',
107                              'second = 1'])
108
109         # check access-by-index
110         self.expect("frame variable ii[0]",
111                     substrs=['first = 0',
112                              'second = 0'])
113         self.expect("frame variable ii[3]",
114                     substrs=['first =',
115                              'second ='])
116
117         self.expect("frame variable ii[8]", matching=True,
118                     substrs=['1234567'])
119
120         # check that MightHaveChildren() gets it right
121         self.assertTrue(
122             self.frame().FindVariable("ii").MightHaveChildren(),
123             "ii.MightHaveChildren() says False for non empty!")
124
125         # check that the expression parser does not make use of
126         # synthetic children instead of running code
127         # TOT clang has a fix for this, which makes the expression command here succeed
128         # since this would make the test fail or succeed depending on clang version in use
129         # this is safer commented for the time being
130         # self.expect("expression ii[8]", matching=False, error=True,
131         #            substrs = ['1234567'])
132
133         self.runCmd("c")
134
135         self.expect('frame variable ii',
136                     substrs=['map has 0 items',
137                              '{}'])
138
139         self.runCmd("frame variable si --show-types")
140
141         self.expect('frame variable si',
142                     substrs=['map has 0 items',
143                              '{}'])
144
145         self.runCmd("c")
146
147         self.expect('frame variable si',
148                     substrs=['map has 1 items',
149                              '[0] = ',
150                              'first = \"zero\"',
151                              'second = 0'])
152
153         self.runCmd("c")
154
155         self.expect("frame variable si",
156                     substrs=['map has 5 items',
157                              '[0] = ',
158                              'first = \"zero\"',
159                              'second = 0',
160                              '[1] = ',
161                              'first = \"one\"',
162                              'second = 1',
163                              '[2] = ',
164                              'first = \"two\"',
165                              'second = 2',
166                              '[3] = ',
167                              'first = \"three\"',
168                              'second = 3',
169                              '[4] = ',
170                              'first = \"four\"',
171                              'second = 4'])
172
173         self.expect("p si",
174                     substrs=['map has 5 items',
175                              '[0] = ',
176                              'first = \"zero\"',
177                              'second = 0',
178                              '[1] = ',
179                              'first = \"one\"',
180                              'second = 1',
181                              '[2] = ',
182                              'first = \"two\"',
183                              'second = 2',
184                              '[3] = ',
185                              'first = \"three\"',
186                              'second = 3',
187                              '[4] = ',
188                              'first = \"four\"',
189                              'second = 4'])
190
191         # check access-by-index
192         self.expect("frame variable si[0]",
193                     substrs=['first = ', 'four',
194                              'second = 4'])
195
196         # check that MightHaveChildren() gets it right
197         self.assertTrue(
198             self.frame().FindVariable("si").MightHaveChildren(),
199             "si.MightHaveChildren() says False for non empty!")
200
201         # check that the expression parser does not make use of
202         # synthetic children instead of running code
203         # TOT clang has a fix for this, which makes the expression command here succeed
204         # since this would make the test fail or succeed depending on clang version in use
205         # this is safer commented for the time being
206         # self.expect("expression si[0]", matching=False, error=True,
207         #            substrs = ['first = ', 'zero'])
208
209         self.runCmd("c")
210
211         self.expect('frame variable si',
212                     substrs=['map has 0 items',
213                              '{}'])
214
215         self.runCmd("frame variable is --show-types")
216
217         self.expect('frame variable is',
218                     substrs=['map has 0 items',
219                              '{}'])
220
221         self.runCmd("c")
222
223         self.expect("frame variable is",
224                     substrs=['map has 4 items',
225                              '[0] = ',
226                              'second = \"goofy\"',
227                              'first = 85',
228                              '[1] = ',
229                              'second = \"is\"',
230                              'first = 1',
231                              '[2] = ',
232                              'second = \"smart\"',
233                              'first = 2',
234                              '[3] = ',
235                              'second = \"!!!\"',
236                              'first = 3'])
237
238         self.expect("p is",
239                     substrs=['map has 4 items',
240                              '[0] = ',
241                              'second = \"goofy\"',
242                              'first = 85',
243                              '[1] = ',
244                              'second = \"is\"',
245                              'first = 1',
246                              '[2] = ',
247                              'second = \"smart\"',
248                              'first = 2',
249                              '[3] = ',
250                              'second = \"!!!\"',
251                              'first = 3'])
252
253         # check access-by-index
254         self.expect("frame variable is[0]",
255                     substrs=['first = ',
256                              'second ='])
257
258         # check that MightHaveChildren() gets it right
259         self.assertTrue(
260             self.frame().FindVariable("is").MightHaveChildren(),
261             "is.MightHaveChildren() says False for non empty!")
262
263         # check that the expression parser does not make use of
264         # synthetic children instead of running code
265         # TOT clang has a fix for this, which makes the expression command here succeed
266         # since this would make the test fail or succeed depending on clang version in use
267         # this is safer commented for the time being
268         # self.expect("expression is[0]", matching=False, error=True,
269         #            substrs = ['first = ', 'goofy'])
270
271         self.runCmd("c")
272
273         self.expect('frame variable is',
274                     substrs=['map has 0 items',
275                              '{}'])
276
277         self.runCmd("frame variable ss --show-types")
278
279         self.expect('frame variable ss',
280                     substrs=['map has 0 items',
281                              '{}'])
282
283         self.runCmd("c")
284
285         self.expect("frame variable ss",
286                     substrs=['map has 4 items',
287                              '[0] = ',
288                              'second = \"hello\"',
289                              'first = \"ciao\"',
290                              '[1] = ',
291                              'second = \"house\"',
292                              'first = \"casa\"',
293                              '[2] = ',
294                              'second = \"cat\"',
295                              'first = \"gatto\"',
296                              '[3] = ',
297                              'second = \"..is always a Mac!\"',
298                              'first = \"a Mac..\"'])
299
300         self.expect("p ss",
301                     substrs=['map has 4 items',
302                              '[0] = ',
303                              'second = \"hello\"',
304                              'first = \"ciao\"',
305                              '[1] = ',
306                              'second = \"house\"',
307                              'first = \"casa\"',
308                              '[2] = ',
309                              'second = \"cat\"',
310                              'first = \"gatto\"',
311                              '[3] = ',
312                              'second = \"..is always a Mac!\"',
313                              'first = \"a Mac..\"'])
314
315         # check access-by-index
316         self.expect("frame variable ss[3]",
317                     substrs=['gatto', 'cat'])
318
319         # check that MightHaveChildren() gets it right
320         self.assertTrue(
321             self.frame().FindVariable("ss").MightHaveChildren(),
322             "ss.MightHaveChildren() says False for non empty!")
323
324         # check that the expression parser does not make use of
325         # synthetic children instead of running code
326         # TOT clang has a fix for this, which makes the expression command here succeed
327         # since this would make the test fail or succeed depending on clang version in use
328         # this is safer commented for the time being
329         # self.expect("expression ss[3]", matching=False, error=True,
330         #            substrs = ['gatto'])
331
332         self.runCmd("c")
333
334         self.expect('frame variable ss',
335                     substrs=['map has 0 items',
336                              '{}'])