7
7
from lldbsuite .test .decorators import *
8
8
from lldbsuite .test .lldbtest import *
9
9
from lldbsuite .test import lldbutil
10
-
10
+ import random
11
11
12
12
@skipIfLinux # llvm.org/pr25924, sometimes generating SIGSEGV
13
13
class EventAPITestCase (TestBase ):
@@ -20,6 +20,7 @@ def setUp(self):
20
20
self .line = line_number (
21
21
"main.c" , '// Find the line number of function "c" here.'
22
22
)
23
+ random .seed ()
23
24
24
25
@expectedFailureAll (
25
26
oslist = ["linux" ], bugnumber = "llvm.org/pr23730 Flaky, fails ~1/10 cases"
@@ -318,6 +319,7 @@ def wait_for_next_event(self, expected_state, test_shadow=False):
318
319
"""Wait for an event from self.primary & self.shadow listener.
319
320
If test_shadow is true, we also check that the shadow listener only
320
321
receives events AFTER the primary listener does."""
322
+ import stop_hook
321
323
# Waiting on the shadow listener shouldn't have events yet because
322
324
# we haven't fetched them for the primary listener yet:
323
325
event = lldb .SBEvent ()
@@ -328,12 +330,23 @@ def wait_for_next_event(self, expected_state, test_shadow=False):
328
330
329
331
# But there should be an event for the primary listener:
330
332
success = self .primary_listener .WaitForEvent (5 , event )
333
+
331
334
self .assertTrue (success , "Primary listener got the event" )
332
335
333
336
state = lldb .SBProcess .GetStateFromEvent (event )
337
+ primary_event_type = event .GetType ()
334
338
restart = False
335
339
if state == lldb .eStateStopped :
336
340
restart = lldb .SBProcess .GetRestartedFromEvent (event )
341
+ # This counter is matching the stop hooks, which don't get run
342
+ # for auto-restarting stops.
343
+ if not restart :
344
+ self .stop_counter += 1
345
+ self .assertEqual (
346
+ stop_hook .StopHook .counter [self .instance ],
347
+ self .stop_counter ,
348
+ "matching stop hook" ,
349
+ )
337
350
338
351
if expected_state is not None :
339
352
self .assertEqual (
@@ -344,15 +357,18 @@ def wait_for_next_event(self, expected_state, test_shadow=False):
344
357
# listener:
345
358
success = self .shadow_listener .WaitForEvent (5 , event )
346
359
self .assertTrue (success , "Shadow listener got event too" )
360
+ shadow_event_type = event .GetType ()
361
+ self .assertEqual (
362
+ primary_event_type , shadow_event_type , "It was the same event type"
363
+ )
347
364
self .assertEqual (
348
- state , lldb .SBProcess .GetStateFromEvent (event ), "It was the same event "
365
+ state , lldb .SBProcess .GetStateFromEvent (event ), "It was the same state "
349
366
)
350
367
self .assertEqual (
351
368
restart ,
352
369
lldb .SBProcess .GetRestartedFromEvent (event ),
353
370
"It was the same restarted" ,
354
371
)
355
-
356
372
return state , restart
357
373
358
374
@expectedFlakeyLinux ("llvm.org/pr23730" ) # Flaky, fails ~1/100 cases
@@ -386,6 +402,20 @@ def test_shadow_listener(self):
386
402
)
387
403
self .dbg .SetAsync (True )
388
404
405
+ # Now make our stop hook - we want to ensure it stays up to date with
406
+ # the events. We can't get our hands on the stop-hook instance directly,
407
+ # so we'll pass in an instance key, and use that to retrieve the data from
408
+ # this instance of the stop hook:
409
+ self .instance = f"Key{ random .randint (0 ,10000 )} "
410
+ stop_hook_path = os .path .join (self .getSourceDir (), "stop_hook.py" )
411
+ self .runCmd (f"command script import { stop_hook_path } " )
412
+ import stop_hook
413
+
414
+ self .runCmd (
415
+ f"target stop-hook add -P stop_hook.StopHook -k instance -v { self .instance } "
416
+ )
417
+ self .stop_counter = 0
418
+
389
419
self .process = target .Launch (launch_info , error )
390
420
self .assertSuccess (error , "Process launched successfully" )
391
421
@@ -395,6 +425,7 @@ def test_shadow_listener(self):
395
425
# Events in the launch sequence might be platform dependent, so don't
396
426
# expect any particular event till we get the stopped:
397
427
state = lldb .eStateInvalid
428
+
398
429
while state != lldb .eStateStopped :
399
430
state , restart = self .wait_for_next_event (None , False )
400
431
@@ -412,8 +443,6 @@ def test_shadow_listener(self):
412
443
self .cur_thread .GetStopReasonDataAtIndex (0 ),
413
444
"Hit the right breakpoint" ,
414
445
)
415
- # Disable the first breakpoint so it doesn't get in the way...
416
- bkpt1 .SetEnabled (False )
417
446
418
447
self .cur_thread .StepOver ()
419
448
# We'll run the test for "shadow listener blocked by primary listener
@@ -450,4 +479,9 @@ def test_shadow_listener(self):
450
479
)
451
480
if state == lldb .eStateStopped and not restarted :
452
481
self .process .Continue ()
482
+
453
483
state , restarted = self .wait_for_next_event (None , False )
484
+
485
+ # Now make sure we agree with the stop hook counter:
486
+ self .assertEqual (self .stop_counter , stop_hook .StopHook .counter [self .instance ])
487
+ self .assertEqual (stop_hook .StopHook .non_stops [self .instance ], 0 , "No non stops" )
0 commit comments