1""" 2Test that if we hit a breakpoint on two threads at the 3same time, one of which passes the condition, one not, 4we only have a breakpoint stop reason for the one that 5passed the condition. 6""" 7 8import lldb 9import lldbsuite.test.lldbutil as lldbutil 10from lldbsuite.test.decorators import * 11from lldbsuite.test.lldbtest import * 12 13 14class TestTwoHitsOneActual(TestBase): 15 16 NO_DEBUG_INFO_TESTCASE = True 17 18 @skipIf(oslist=["linux"], archs=["arm", "aarch64"]) 19 def test_two_hits_one_actual(self): 20 """There can be many tests in a test case - describe this test here.""" 21 self.build() 22 self.main_source_file = lldb.SBFileSpec("main.cpp") 23 self.sample_test() 24 25 def sample_test(self): 26 """You might use the test implementation in several ways, say so here.""" 27 28 (target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self, 29 "Set bkpt here to get started", self.main_source_file) 30 # This is working around a separate bug. If you hit a breakpoint and 31 # run an expression and it is the first expression you've ever run, on 32 # Darwin that will involve running the ObjC runtime parsing code, and we'll 33 # be in the middle of that when we do PerformAction on the other thread, 34 # which will cause the condition expression to fail. Calling another 35 # expression first works around this. 36 val_obj = main_thread.frame[0].EvaluateExpression("main_usec==1") 37 self.assertSuccess(val_obj.GetError(), "Ran our expression successfully") 38 self.assertEqual(val_obj.value, "true", "Value was true.") 39 # Set two breakpoints just to test the multiple location logic: 40 bkpt1 = target.BreakpointCreateBySourceRegex("Break here in the helper", self.main_source_file); 41 bkpt2 = target.BreakpointCreateBySourceRegex("Break here in the helper", self.main_source_file); 42 43 # This one will never be hit: 44 bkpt1.SetCondition("usec == 100") 45 # This one will only be hit on the main thread: 46 bkpt2.SetCondition("usec == 1") 47 48 # This is hard to test definitively, becuase it requires hitting 49 # a breakpoint on multiple threads at the same time. On Darwin, this 50 # will happen pretty much ever time we continue. What we are really 51 # asserting is that we only ever stop on one thread, so we approximate that 52 # by continuing 20 times and assert we only ever hit the first thread. Either 53 # this is a platform that only reports one hit at a time, in which case all 54 # this code is unused, or we actually didn't hit the other thread. 55 56 for idx in range(0, 20): 57 process.Continue() 58 for thread in process.threads: 59 if thread.id == main_thread.id: 60 self.assertEqual(thread.stop_reason, lldb.eStopReasonBreakpoint) 61 else: 62 self.assertEqual(thread.stop_reason, lldb.eStopReasonNone) 63 64 65