Skip to content

Commit de3346a

Browse files
committed
Make test more robust. It's not guaranteed that a Variable remains usable after continuing the process
1 parent 26da45b commit de3346a

File tree

1 file changed

+71
-94
lines changed

1 file changed

+71
-94
lines changed

lldb/test/API/lang/swift/variables/consume_operator/TestSwiftConsumeOperator.py

Lines changed: 71 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -71,324 +71,301 @@ def get_var(self, name):
7171
return frame.FindVariable(name)
7272

7373
def do_check_copyable_value_test(self):
74-
# We haven't defined varK yet.
75-
varK = self.get_var('k')
76-
77-
self.assertIsNone(varK.value, "varK initialized too early?!")
74+
# We haven't defined k yet.
75+
self.assertIsNone(self.get_var('k').value, "k initialized too early?!")
7876

7977
# Go to break point 2. k should be valid.
8078
self.process.Continue()
81-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
79+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
8280

8381
# Go to breakpoint 3. k should no longer be valid.
8482
self.process.Continue()
85-
self.assertIsNone(varK.value, "K is live but was consumed?!")
83+
self.assertIsNone(self.get_var('k').value, "K is live but was consumed?!")
8684

8785
# Run so we hit the next breakpoint to jump to the next test's
8886
# breakpoint.
8987
self.process.Continue()
9088

9189
def do_check_copyable_var_test(self):
92-
# We haven't defined varK yet.
93-
varK = self.get_var('k')
94-
self.assertIsNone(varK.value, "varK initialized too early?!")
90+
# We haven't defined k yet.
91+
self.assertIsNone(self.get_var('k').value, "k initialized too early?!")
9592

9693
# Go to break point 2. k should be valid.
9794
self.process.Continue()
98-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
95+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
9996

10097
# Go to breakpoint 3. We invalidated k
10198
self.process.Continue()
102-
self.assertIsNone(varK.value, "K is live but was consumed?!")
99+
self.assertIsNone(self.get_var('k').value, "K is live but was consumed?!")
103100

104101
# Go to the last breakpoint and make sure that k is reinitialized
105102
# properly.
106103
self.process.Continue()
107-
self.assertGreater(varK.unsigned, 0, "varK not initialized")
104+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized")
108105

109106
# Run so we hit the next breakpoint to go to the next test.
110107
self.process.Continue()
111108

112109
def do_check_addressonly_value_test(self):
113-
# We haven't defined varK yet.
114-
varK = self.get_var('k')
115-
110+
# We haven't defined k yet.
116111
# Go to break point 2. k should be valid and m should not be. Since M is
117112
# a dbg.declare it is hard to test robustly that it is not initialized
118113
# so we don't do so. We have an additional llvm.dbg.addr test where we
119114
# move the other variable and show the correct behavior with
120115
# llvm.dbg.declare.
121116
self.process.Continue()
122-
self.assertGreater(varK.unsigned, 0, "var not initialized?!")
117+
self.assertGreater(self.get_var('k').unsigned, 0, "var not initialized?!")
123118

124119
# Go to breakpoint 3.
125120
self.process.Continue()
126-
self.assertEqual(varK.unsigned, 0,
127-
"dbg thinks varK is live despite move?!")
121+
self.assertEqual(self.get_var('k').unsigned, 0,
122+
"dbg thinks k is live despite move?!")
128123

129124
# Run so we hit the next breakpoint as part of the next test.
130125
self.process.Continue()
131126

132127
def do_check_addressonly_var_test(self):
133-
varK = self.get_var('k')
134-
135128
# Go to break point 2. k should be valid.
136129
self.process.Continue()
137-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
130+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
138131

139132
# Go to breakpoint 3. K was invalidated.
140133
self.process.Continue()
141-
self.assertIsNone(varK.value, "K is live but was consumed?!")
134+
self.assertIsNone(self.get_var('k').value, "K is live but was consumed?!")
142135

143136
# Go to the last breakpoint and make sure that k is reinitialized
144137
# properly.
145138
self.process.Continue()
146-
self.assertGreater(varK.unsigned, 0, "varK not initialized")
139+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized")
147140

148141
# Run so we hit the next breakpoint as part of the next test.
149142
self.process.Continue()
150143

151144
def do_check_copyable_value_arg_test(self):
152145
# k is defined by the argument so it is valid.
153-
varK = self.get_var('k')
154-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
146+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
155147

156148
# Go to break point 2. k should be valid.
157149
self.process.Continue()
158-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
150+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
159151

160152
# Go to breakpoint 3. k should no longer be valid.
161153
self.process.Continue()
162-
#self.assertIsNone(varK.value, "K is live but was consumed?!")
154+
#self.assertIsNone(self.get_var('k').value, "K is live but was consumed?!")
163155

164156
# Run so we hit the next breakpoint to jump to the next test's
165157
# breakpoint.
166158
self.process.Continue()
167159

168160
def do_check_copyable_var_arg_test(self):
169161
# k is already defined and is an argument.
170-
varK = self.get_var('k')
171-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
162+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
172163

173164
# Go to break point 2. k should be valid.
174165
self.process.Continue()
175-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
166+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
176167

177168
# Go to breakpoint 3. We invalidated k
178169
self.process.Continue()
179-
self.assertIsNone(varK.value, "K is live but was consumed?!")
170+
self.assertIsNone(self.get_var('k').value, "K is live but was consumed?!")
180171

181172
# Go to the last breakpoint and make sure that k is reinitialized
182173
# properly.
183174
self.process.Continue()
184-
self.assertGreater(varK.unsigned, 0, "varK not initialized")
175+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized")
185176

186177
# Run so we hit the next breakpoint to go to the next test.
187178
self.process.Continue()
188179

189180
def do_check_addressonly_value_arg_test(self):
190181
# k is defined since it is an argument.
191-
varK = self.get_var('k')
192-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
182+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
193183

194184
# Go to break point 2. k should be valid and m should not be. Since M is
195185
# a dbg.declare it is hard to test robustly that it is not initialized
196186
# so we don't do so. We have an additional llvm.dbg.addr test where we
197187
# move the other variable and show the correct behavior with
198188
# llvm.dbg.declare.
199189
self.process.Continue()
200-
self.assertGreater(varK.unsigned, 0, "var not initialized?!")
190+
self.assertGreater(self.get_var('k').unsigned, 0, "var not initialized?!")
201191

202192
# Go to breakpoint 3.
203193
self.process.Continue()
204-
self.assertEqual(varK.unsigned, 0,
205-
"dbg thinks varK is live despite move?!")
194+
self.assertEqual(self.get_var('k').unsigned, 0,
195+
"dbg thinks k is live despite move?!")
206196

207197
# Run so we hit the next breakpoint as part of the next test.
208198
self.process.Continue()
209199

210200
def do_check_addressonly_var_arg_test(self):
211-
varK = self.get_var('k')
212-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
201+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
213202

214203
# Go to break point 2. k should be valid.
215204
self.process.Continue()
216-
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
205+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized?!")
217206

218207
# Go to breakpoint 3. K was invalidated.
219208
self.process.Continue()
220-
self.assertIsNone(varK.value, "K is live but was consumed?!")
209+
self.assertIsNone(self.get_var('k').value, "K is live but was consumed?!")
221210

222211
# Go to the last breakpoint and make sure that k is reinitialized
223212
# properly.
224213
self.process.Continue()
225214
# There is some sort of bug here. We should have the value here. For now
226215
# leave the next line commented out and validate we are not seeing the
227216
# value so we can detect change in behavior.
228-
self.assertGreater(varK.unsigned, 0, "varK not initialized")
217+
self.assertGreater(self.get_var('k').unsigned, 0, "k not initialized")
229218

230219
# Run so we hit the next breakpoint as part of the next test.
231220
self.process.Continue()
232221

233222
def do_check_copyable_value_ccf_true(self):
234-
varK = self.get_var('k')
235-
236-
# Check at our start point that we do not have any state for varK and
223+
# Check at our start point that we do not have any state for k and
237224
# then continue to our next breakpoint.
238-
self.assertIsNone(varK.value, "varK should not have a value?!")
225+
self.assertIsNone(self.get_var('k').value, "k should not have a value?!")
239226
self.process.Continue()
240227

241228
# At this breakpoint, k should be defined since we are going to do
242229
# something with it.
243-
self.assertIsNotNone(varK.value, "varK should have a value?!")
230+
self.assertIsNotNone(self.get_var('k').value, "k should have a value?!")
244231
self.process.Continue()
245232

246233
# At this breakpoint, we are now in the conditional control flow part of
247234
# the loop. Make sure that we can see k still.
248-
self.assertIsNotNone(varK.value, "varK should have a value?!")
235+
self.assertIsNotNone(self.get_var('k').value, "k should have a value?!")
249236
self.process.Continue()
250237

251238
# Ok, we just performed the move. k should not be no longer initialized.
252-
self.assertIsNone(varK.value, "varK should not have a value?!")
239+
self.assertIsNone(self.get_var('k').value, "k should not have a value?!")
253240
self.process.Continue()
254241

255242
# Finally we left the conditional control flow part of the function. k
256243
# should still be None.
257-
self.assertIsNone(varK.value, "varK should not have a value!")
244+
self.assertIsNone(self.get_var('k').value, "k should not have a value!")
258245

259246
# Run again so we go and run to the next test.
260247
self.process.Continue()
261248

262249
def do_check_copyable_value_ccf_false(self):
263-
varK = self.get_var('k')
264-
265-
# Check at our start point that we do not have any state for varK and
250+
# Check at our start point that we do not have any state for k and
266251
# then continue to our next breakpoint.
267-
self.assertIsNone(varK.value, "varK should not have a value?!")
252+
self.assertIsNone(self.get_var('k').value, "k should not have a value?!")
268253
self.process.Continue()
269254

270255
# At this breakpoint, k should be defined since we are going to do
271256
# something with it.
272-
self.assertIsNotNone(varK.value, "varK should have a value?!")
257+
self.assertIsNotNone(self.get_var('k').value, "k should have a value?!")
273258
self.process.Continue()
274259

275260
# At this breakpoint, we are now past the end of the conditional
276261
# statement. We know due to the move checking that k can not have any
277262
# uses that are reachable from the move. So it is safe to always not
278263
# provide the value here.
279-
self.assertIsNone(varK.value, "varK should have a value?!")
264+
self.assertIsNone(self.get_var('k').value, "k should have a value?!")
280265

281266
# Run again so we go and run to the next test.
282267
self.process.Continue()
283268

284269
def do_check_copyable_var_ccf_true_reinit_out_block(self):
285-
varK = self.get_var('k')
286-
287270
# At first we should not have a value for k.
288-
self.assertEqual(varK.unsigned, 0, "varK should be nullptr!")
271+
self.assertEqual(self.get_var('k').unsigned, 0, "k should be nullptr!")
289272
self.process.Continue()
290273

291274
# Now we are in the conditional true block. K should be defined since we
292275
# are on the move itself.
293-
self.assertGreater(varK.unsigned, 0, "varK should not be nullptr!")
276+
self.assertGreater(self.get_var('k').unsigned, 0, "k should not be nullptr!")
294277
self.process.Continue()
295278

296279
# Now we have executed the move and we are about to run code using
297280
# m. Make sure that K is not available!
298-
self.assertEqual(varK.unsigned, 0,
299-
"varK was already consumed! Should be nullptr")
281+
self.assertEqual(self.get_var('k').unsigned, 0,
282+
"k was already consumed! Should be nullptr")
300283
self.process.Continue()
301284

302285
# We are now out of the conditional lexical block on the line of code
303286
# that redefines k. k should still be not available.
304-
self.assertEqual(varK.unsigned, 0,
305-
"varK was already consumed! Should be nullptr")
287+
self.assertEqual(self.get_var('k').unsigned, 0,
288+
"k was already consumed! Should be nullptr")
306289
self.process.Continue()
307290

308291
# Ok, we have now reinit k and are about to call a method on it. We
309292
# should be valid now.
310-
self.assertGreater(varK.unsigned, 0,
311-
"varK should have be reinitialized?!")
293+
self.assertGreater(self.get_var('k').unsigned, 0,
294+
"k should have be reinitialized?!")
312295

313296
# Run again so we go and run to the next test.
314297
self.process.Continue()
315298

316299
def do_check_copyable_var_ccf_true_reinit_in_block(self):
317-
varK = self.get_var('k')
318-
319300
# At first we should not have a value for k.
320-
self.assertEqual(varK.unsigned, 0, "varK should be nullptr!")
301+
self.assertEqual(self.get_var('k').unsigned, 0, "k should be nullptr!")
321302
self.process.Continue()
322303

323304
# Now we are in the conditional true block. K should be defined since we
324305
# are on the move itself.
325-
self.assertGreater(varK.unsigned, 0, "varK should not be nullptr!")
306+
self.assertGreater(self.get_var('k').unsigned, 0, "k should not be nullptr!")
326307
self.process.Continue()
327308

328309
# Now we have executed the move and we are about to reinit k but have
329310
# not yet. Make sure we are not available!
330-
self.assertEqual(varK.unsigned, 0,
331-
"varK was already consumed! Should be nullptr")
311+
self.assertEqual(self.get_var('k').unsigned, 0,
312+
"k was already consumed! Should be nullptr")
332313
self.process.Continue()
333314

334315
# We are now still inside the conditional part of the code, but have
335-
# reinitialized varK.
336-
self.assertGreater(varK.unsigned, 0,
337-
"varK was reinit! Should be valid value!")
316+
# reinitialized k.
317+
self.assertGreater(self.get_var('k').unsigned, 0,
318+
"k was reinit! Should be valid value!")
338319
self.process.Continue()
339320

340321
# We now have left the conditional part of the function. k should still
341322
# be available.
342-
self.assertGreater(varK.unsigned, 0,
343-
"varK should have be reinitialized?!")
323+
self.assertGreater(self.get_var('k').unsigned, 0,
324+
"k should have be reinitialized?!")
344325

345326
# Run again so we go and run to the next test.
346327
self.process.Continue()
347328

348329
def do_check_copyable_var_ccf_false_reinit_out_block(self):
349-
varK = self.get_var('k')
350-
351330
# At first we should not have a value for k.
352-
self.assertEqual(varK.unsigned, 0, "varK should be nullptr!")
331+
self.assertEqual(self.get_var('k').unsigned, 0, "k should be nullptr!")
353332
self.process.Continue()
354333

355-
# Now we are right above the beginning of the false check. varK should
334+
# Now we are right above the beginning of the false check. k should
356335
# still be valid.
357-
self.assertGreater(varK.unsigned, 0, "varK should not be nullptr!")
336+
self.assertGreater(self.get_var('k').unsigned, 0, "k should not be nullptr!")
358337
self.process.Continue()
359338

360339
# Now we are after the conditional part of the code on the reinit
361340
# line. Since this is reachable from the move and we haven't reinit yet,
362341
# k should not be available.
363-
self.assertEqual(varK.unsigned, 0,
364-
"varK was already consumed! Should be nullptr")
342+
self.assertEqual(self.get_var('k').unsigned, 0,
343+
"k was already consumed! Should be nullptr")
365344
self.process.Continue()
366345

367346
# Ok, we have now reinit k and are about to call a method on it. We
368347
# should be valid now.
369-
self.assertGreater(varK.unsigned, 0,
370-
"varK should have be reinitialized?!")
348+
self.assertGreater(self.get_var('k').unsigned, 0,
349+
"k should have be reinitialized?!")
371350

372351
# Run again so we go and run to the next test.
373352
self.process.Continue()
374353

375354
def do_check_copyable_var_ccf_false_reinit_in_block(self):
376-
varK = self.get_var('k')
377-
378355
# At first we should not have a value for k.
379-
self.assertEqual(varK.unsigned, 0, "varK should be nullptr!")
356+
self.assertEqual(self.get_var('k').unsigned, 0, "k should be nullptr!")
380357
self.process.Continue()
381358

382-
# Now we are on the doSomething above the false check. So varK should be
359+
# Now we are on the doSomething above the false check. So k should be
383360
# valid.
384-
self.assertGreater(varK.unsigned, 0, "varK should not be nullptr!")
361+
self.assertGreater(self.get_var('k').unsigned, 0, "k should not be nullptr!")
385362
self.process.Continue()
386363

387364
# Now we are after the conditional scope. Since k was reinitialized in
388-
# the conditional scope, along all paths we are valid so varK should
365+
# the conditional scope, along all paths we are valid so k should
389366
# still be available.
390-
self.assertGreater(varK.unsigned, 0,
391-
"varK should not be nullptr?!")
367+
self.assertGreater(self.get_var('k').unsigned, 0,
368+
"k should not be nullptr?!")
392369

393370
# Run again so we go and run to the next test.
394371
self.process.Continue()

0 commit comments

Comments
 (0)