aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py
blob: db426cac6e59e238d278230d5d3ced7649d66439 (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
"""
Test lldb data formatter subsystem.
"""

from __future__ import print_function



import os, time
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil

class CategoriesDataFormatterTestCase(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    def setUp(self):
        # Call super's setUp().
        TestBase.setUp(self)
        # Find the line number to break at.
        self.line = line_number('main.cpp', '// Set break point at this line.')

    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
            substrs = ['stopped',
                       'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case (most of these categories do not
        # exist anymore, but we just make sure we delete all of them)
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type category delete Category1', check=False)
            self.runCmd('type category delete Category2', check=False)
            self.runCmd('type category delete NewCategory', check=False)
            self.runCmd("type category delete CircleCategory", check=False)
            self.runCmd("type category delete RectangleStarCategory", check=False)
            self.runCmd("type category delete BaseCategory", check=False)


        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        # Add a summary to a new category and check that it works
        self.runCmd("type summary add Rectangle --summary-string \"ARectangle\" -w NewCategory")

        self.expect("frame variable r1 r2 r3", matching=False,
            substrs = ['r1 = ARectangle',
                       'r2 = ARectangle',
                       'r3 = ARectangle'])
        
        self.runCmd("type category enable NewCategory")

        self.expect("frame variable r1 r2 r3", matching=True,
                    substrs = ['r1 = ARectangle',
                               'r2 = ARectangle',
                               'r3 = ARectangle'])
        
        # Disable the category and check that the old stuff is there
        self.runCmd("type category disable NewCategory")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = {',
                               'r2 = {',
                               'r3 = {'])

        # Re-enable the category and check that it works
        self.runCmd("type category enable NewCategory")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = ARectangle',
                               'r2 = ARectangle',
                               'r3 = ARectangle'])

        # Delete the category and the old stuff should be there
        self.runCmd("type category delete NewCategory")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = {',
                               'r2 = {',
                               'r3 = {'])

        # Add summaries to two different categories and check that we can switch
        self.runCmd("type summary add --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle -w Category1")
        self.runCmd("type summary add --python-script \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2")

        # check that enable A B is the same as enable B enable A
        self.runCmd("type category enable Category1 Category2")
        
        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Width = ',
                               'r2 = Width = ',
                               'r3 = Width = '])

        self.runCmd("type category disable Category1")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Area = ',
                               'r2 = Area = ',
                               'r3 = Area = '])

        # switch again

        self.runCmd("type category enable Category1")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Width = ',
                               'r2 = Width = ',
                               'r3 = Width = '])

        # Re-enable the category and show that the preference is persisted
        self.runCmd("type category disable Category2")
        self.runCmd("type category enable Category2")
        
        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Area = ',
                               'r2 = Area = ',
                               'r3 = Area = '])

        # Now delete the favorite summary
        self.runCmd("type summary delete Rectangle -w Category2")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Width = ',
                               'r2 = Width = ',
                               'r3 = Width = '])

        # Delete the summary from the default category (that does not have it)
        self.runCmd("type summary delete Rectangle", check=False)

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Width = ',
                               'r2 = Width = ',
                               'r3 = Width = '])

        # Now add another summary to another category and switch back and forth
        self.runCmd("type category delete Category1 Category2")

        self.runCmd("type summary add Rectangle -w Category1 --summary-string \"Category1\"")
        self.runCmd("type summary add Rectangle -w Category2 --summary-string \"Category2\"")

        self.runCmd("type category enable Category2")
        self.runCmd("type category enable Category1")
        
        self.runCmd("type summary list -w Category1")
        
        self.expect("frame variable r1 r2 r3",
                substrs = ['r1 = Category1',
                           'r2 = Category1',
                           'r3 = Category1'])

        self.runCmd("type category disable Category1")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Category2',
                               'r2 = Category2',
                               'r3 = Category2'])

        # Check that re-enabling an enabled category works
        self.runCmd("type category enable Category1")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Category1',
                               'r2 = Category1',
                               'r3 = Category1'])

        self.runCmd("type category delete Category1")
        self.runCmd("type category delete Category2")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = {',
                               'r2 = {',
                               'r3 = {'])

        # Check that multiple summaries can go into one category 
        self.runCmd("type summary add -w Category1 --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle")
        self.runCmd("type summary add -w Category1 --summary-string \"Radius = ${var.r}\" Circle")
        
        self.runCmd("type category enable Category1")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Width = ',
                               'r2 = Width = ',
                               'r3 = Width = '])

        self.expect("frame variable c1 c2 c3",
                    substrs = ['c1 = Radius = ',
                               'c2 = Radius = ',
                               'c3 = Radius = '])

        self.runCmd("type summary delete Circle -w Category1")
            
        self.expect("frame variable c1 c2 c3",
                    substrs = ['c1 = {',
                               'c2 = {',
                               'c3 = {'])

        # Add a regex based summary to a category
        self.runCmd("type summary add -w Category1 --summary-string \"Radius = ${var.r}\" -x Circle")

        self.expect("frame variable r1 r2 r3",
                    substrs = ['r1 = Width = ',
                               'r2 = Width = ',
                               'r3 = Width = '])

        self.expect("frame variable c1 c2 c3",
                    substrs = ['c1 = Radius = ',
                               'c2 = Radius = ',
                               'c3 = Radius = '])

        # Delete it
        self.runCmd("type summary delete Circle -w Category1")

        self.expect("frame variable c1 c2 c3",
                    substrs = ['c1 = {',
                               'c2 = {',
                               'c3 = {'])
        
        # Change a summary inside a category and check that the change is reflected
        self.runCmd("type summary add Circle -w Category1 --summary-string \"summary1\"")

        self.expect("frame variable c1 c2 c3",
                    substrs = ['c1 = summary1',
                               'c2 = summary1',
                               'c3 = summary1'])

        self.runCmd("type summary add Circle -w Category1 --summary-string \"summary2\"")
        
        self.expect("frame variable c1 c2 c3",
                    substrs = ['c1 = summary2',
                               'c2 = summary2',
                               'c3 = summary2'])

        # Check that our order of priority works. Start by clearing categories
        self.runCmd("type category delete Category1")

        self.runCmd("type summary add Shape -w BaseCategory --summary-string \"AShape\"")
        self.runCmd("type category enable BaseCategory")

        self.expect("print (Shape*)&c1",
            substrs = ['AShape'])
        self.expect("print (Shape*)&r1",
            substrs = ['AShape'])
        self.expect("print (Shape*)c_ptr",
            substrs = ['AShape'])
        self.expect("print (Shape*)r_ptr",
            substrs = ['AShape'])

        self.runCmd("type summary add Circle -w CircleCategory --summary-string \"ACircle\"")
        self.runCmd("type summary add Rectangle -w RectangleCategory --summary-string \"ARectangle\"")
        self.runCmd("type category enable CircleCategory")

        self.expect("frame variable c1",
                    substrs = ['ACircle'])
        self.expect("frame variable c_ptr",
                    substrs = ['ACircle'])

        self.runCmd("type summary add \"Rectangle *\" -w RectangleStarCategory --summary-string \"ARectangleStar\"")
        self.runCmd("type category enable RectangleStarCategory")

        self.expect("frame variable c1 r1 c_ptr r_ptr",
                substrs = ['ACircle',
                           'ARectangleStar'])

        self.runCmd("type category enable RectangleCategory")

        self.expect("frame variable c1 r1 c_ptr r_ptr",
                    substrs = ['ACircle',
                               'ACircle',
                               'ARectangle'])

        # Check that abruptly deleting an enabled category does not crash us
        self.runCmd("type category delete RectangleCategory")

        self.expect("frame variable c1 r1 c_ptr r_ptr",
                    substrs = ['ACircle',
                               '(Rectangle) r1 = ', 'w = 5', 'h = 6',
                               'ACircle',
                               'ARectangleStar'])
        
        # check that list commands work
        self.expect("type category list",
                substrs = ['RectangleStarCategory (enabled)'])

        self.expect("type summary list",
                substrs = ['ARectangleStar'])

        # Disable a category and check that it fallsback
        self.runCmd("type category disable CircleCategory")
        
        # check that list commands work
        self.expect("type category list",
                    substrs = ['CircleCategory (disabled'])

        self.expect("frame variable c1 r_ptr",
                    substrs = ['AShape',
                               'ARectangleStar'])

        # check that filters work into categories
        self.runCmd("type filter add Rectangle --child w --category RectangleCategory")
        self.runCmd("type category enable RectangleCategory")
        self.runCmd("type summary add Rectangle --category RectangleCategory --summary-string \" \" -e")
        self.expect('frame variable r2',
            substrs = ['w = 9'])
        self.runCmd("type summary add Rectangle --summary-string \" \" -e")
        self.expect('frame variable r2', matching=False,
                    substrs = ['h = 16'])

        # Now delete all categories
        self.runCmd("type category delete CircleCategory RectangleStarCategory BaseCategory RectangleCategory")

        # check that a deleted category with filter does not blow us up
        self.expect('frame variable r2',
                    substrs = ['w = 9',
                               'h = 16'])

        # and also validate that one can print formatters for a language
        self.expect('type summary list -l c++', substrs=['vector', 'map', 'list', 'string'])