]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-stl / libstdcpp / vector / TestDataFormatterStdVector.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 StdVectorDataFormatterTestCase(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     @skipIfFreeBSD
27     @skipIfWindows  # libstdcpp not ported to Windows
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         # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
58         self.expect("frame variable numbers",
59                     substrs=['numbers = size=0'])
60
61         self.runCmd("c")
62
63         # first value added
64         self.expect("frame variable numbers",
65                     substrs=['numbers = size=1',
66                              '[0] = 1',
67                              '}'])
68
69         # add some more data
70         self.runCmd("c")
71
72         self.expect("frame variable numbers",
73                     substrs=['numbers = size=4',
74                              '[0] = 1',
75                              '[1] = 12',
76                              '[2] = 123',
77                              '[3] = 1234',
78                              '}'])
79
80         self.expect("p numbers",
81                     substrs=['$', 'size=4',
82                              '[0] = 1',
83                              '[1] = 12',
84                              '[2] = 123',
85                              '[3] = 1234',
86                              '}'])
87
88         # check access to synthetic children
89         self.runCmd(
90             "type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
91         self.expect('frame variable numbers',
92                     substrs=['item 0 is 1'])
93
94         self.runCmd(
95             "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
96         #import time
97         # time.sleep(19)
98         self.expect('frame variable numbers',
99                     substrs=['item 0 is 1'])
100         # move on with synths
101         self.runCmd("type summary delete std::int_vect")
102         self.runCmd("type summary delete int_vect")
103
104         # add some more data
105         self.runCmd("c")
106
107         self.expect("frame variable numbers",
108                     substrs=['numbers = size=7',
109                              '[0] = 1',
110                              '[1] = 12',
111                              '[2] = 123',
112                              '[3] = 1234',
113                              '[4] = 12345',
114                              '[5] = 123456',
115                              '[6] = 1234567',
116                              '}'])
117
118         self.expect("p numbers",
119                     substrs=['$', 'size=7',
120                              '[0] = 1',
121                              '[1] = 12',
122                              '[2] = 123',
123                              '[3] = 1234',
124                              '[4] = 12345',
125                              '[5] = 123456',
126                              '[6] = 1234567',
127                              '}'])
128
129         # check access-by-index
130         self.expect("frame variable numbers[0]",
131                     substrs=['1'])
132         self.expect("frame variable numbers[1]",
133                     substrs=['12'])
134         self.expect("frame variable numbers[2]",
135                     substrs=['123'])
136         self.expect("frame variable numbers[3]",
137                     substrs=['1234'])
138
139         # but check that expression does not rely on us
140         # (when expression gets to call into STL code correctly, we will have to find
141         # another way to check this)
142         self.expect("expression numbers[6]", matching=False, error=True,
143                     substrs=['1234567'])
144
145         # check that MightHaveChildren() gets it right
146         self.assertTrue(
147             self.frame().FindVariable("numbers").MightHaveChildren(),
148             "numbers.MightHaveChildren() says False for non empty!")
149
150         # clear out the vector and see that we do the right thing once again
151         self.runCmd("c")
152
153         self.expect("frame variable numbers",
154                     substrs=['numbers = size=0'])
155
156         self.runCmd("c")
157
158         # first value added
159         self.expect("frame variable numbers",
160                     substrs=['numbers = size=1',
161                              '[0] = 7',
162                              '}'])
163
164         # check if we can display strings
165         self.runCmd("c")
166
167         self.expect("frame variable strings",
168                     substrs=['goofy',
169                              'is',
170                              'smart'])
171
172         self.expect("p strings",
173                     substrs=['goofy',
174                              'is',
175                              'smart'])
176
177         # test summaries based on synthetic children
178         self.runCmd(
179             "type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
180         self.expect("frame variable strings",
181                     substrs=['vector has 3 items',
182                              'goofy',
183                              'is',
184                              'smart'])
185
186         self.expect("p strings",
187                     substrs=['vector has 3 items',
188                              'goofy',
189                              'is',
190                              'smart'])
191
192         self.runCmd("c")
193
194         self.expect("frame variable strings",
195                     substrs=['vector has 4 items'])
196
197         # check access-by-index
198         self.expect("frame variable strings[0]",
199                     substrs=['goofy'])
200         self.expect("frame variable strings[1]",
201                     substrs=['is'])
202
203         # but check that expression does not rely on us
204         # (when expression gets to call into STL code correctly, we will have to find
205         # another way to check this)
206         self.expect("expression strings[0]", matching=False, error=True,
207                     substrs=['goofy'])
208
209         # check that MightHaveChildren() gets it right
210         self.assertTrue(
211             self.frame().FindVariable("strings").MightHaveChildren(),
212             "strings.MightHaveChildren() says False for non empty!")
213
214         self.runCmd("c")
215
216         self.expect("frame variable strings",
217                     substrs=['vector has 0 items'])