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