Skip to content

Commit 0f82133

Browse files
committed
[lldb] Add assertStopReason helper function
Add a function to make it easier to debug a test failure caused by an unexpected stop reason. This is similar to the assertState helper that was added in ce825e4. Before: self.assertEqual(stop_reason, lldb.eStopReasonInstrumentation) AssertionError: 5 != 10 After: self.assertStopReason(stop_reason, lldb.eStopReasonInstrumentation) AssertionError: signal (5) != instrumentation (10) Differential revision: https://reviews.llvm.org/D131083
1 parent 3716107 commit 0f82133

File tree

31 files changed

+70
-56
lines changed

31 files changed

+70
-56
lines changed

lldb/docs/resources/test.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,15 @@ A better way to write the test above would be using LLDB's testing function
323323
asserts are available. LLDB also has a few custom asserts that are tailored
324324
to our own data types.
325325

326-
+-----------------------------------------------+---------------------------------------------------------------+
326+
+-----------------------------------------------+-----------------------------------------------------------------+
327327
| **Assert** | **Description** |
328-
+-----------------------------------------------+---------------------------------------------------------------+
328+
+-----------------------------------------------+-----------------------------------------------------------------+
329329
| ``assertSuccess`` | Assert that an ``lldb.SBError`` is in the "success" state. |
330-
+-----------------------------------------------+---------------------------------------------------------------+
330+
+-----------------------------------------------+-----------------------------------------------------------------+
331331
| ``assertState`` | Assert that two states (``lldb.eState*``) are equal. |
332-
+-----------------------------------------------+---------------------------------------------------------------+
332+
+-----------------------------------------------+-----------------------------------------------------------------+
333+
| ``assertStopReason`` | Assert that two stop reasons (``lldb.eStopReason*``) are equal. |
334+
+-----------------------------------------------+-----------------------------------------------------------------+
333335

334336
If you can't find a specific assert that fits your needs and you fall back
335337
to a generic assert, make sure you put useful information into the assert's

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,14 @@ def assertState(self, first, second, msg=None):
24742474
lldbutil.state_type_to_str(second), second)
24752475
self.fail(self._formatMessage(msg, error))
24762476

2477+
"""Assert two stop reasons are equal"""
2478+
def assertStopReason(self, first, second, msg=None):
2479+
if first != second:
2480+
error = "{} ({}) != {} ({})".format(
2481+
lldbutil.stop_reason_to_str(first), first,
2482+
lldbutil.stop_reason_to_str(second), second)
2483+
self.fail(self._formatMessage(msg, error))
2484+
24772485
def createTestTarget(self, file_path=None, msg=None,
24782486
load_dependent_modules=True):
24792487
"""

lldb/packages/Python/lldbsuite/test/lldbutil.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def stop_reason_to_str(enum):
266266
return "plancomplete"
267267
elif enum == lldb.eStopReasonThreadExiting:
268268
return "threadexiting"
269+
elif enum == lldb.eStopReasonInstrumentation:
270+
return "instrumentation"
271+
elif enum == lldb.eStopReasonProcessorTrace:
272+
return "processortrace"
269273
else:
270274
raise Exception("Unknown StopReason enum")
271275

lldb/test/API/commands/process/continue_to_bkpt/TestContinueToBkpts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def continue_and_check(self, stop_list, bkpt_to_hit, loc_to_hit = 0):
3232
for elem in stop_list:
3333
command += " -b {0}".format(elem)
3434
self.expect(command)
35-
self.assertEqual(self.thread.stop_reason, lldb.eStopReasonBreakpoint, "Hit a breakpoint")
35+
self.assertStopReason(self.thread.stop_reason, lldb.eStopReasonBreakpoint, "Hit a breakpoint")
3636
self.assertEqual(self.thread.GetStopReasonDataAtIndex(0), bkpt_to_hit, "Hit the right breakpoint")
3737
if loc_to_hit != 0:
3838
self.assertEqual(self.thread.GetStopReasonDataAtIndex(1), loc_to_hit, "Hit the right location")

lldb/test/API/commands/watchpoints/multiple_hits/TestMultipleHits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ def test(self):
4545

4646
process.Continue();
4747
self.assertState(process.GetState(), lldb.eStateStopped)
48-
self.assertEqual(thread.GetStopReason(), lldb.eStopReasonWatchpoint)
48+
self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonWatchpoint)
4949

lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test(self):
5656
self.assertTrue(read_watchpoint, "Failed to set read watchpoint.")
5757

5858
thread.StepOver()
59-
self.assertEquals(thread.GetStopReason(), lldb.eStopReasonWatchpoint,
59+
self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonWatchpoint,
6060
STOPPED_DUE_TO_WATCHPOINT)
6161
self.assertEquals(thread.GetStopDescription(20), 'watchpoint 1')
6262

@@ -83,7 +83,7 @@ def test(self):
8383
self.assertSuccess(error, "Error while setting watchpoint")
8484

8585
thread.StepOver()
86-
self.assertEquals(thread.GetStopReason(), lldb.eStopReasonWatchpoint,
86+
self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonWatchpoint,
8787
STOPPED_DUE_TO_WATCHPOINT)
8888
self.assertEquals(thread.GetStopDescription(20), 'watchpoint 2')
8989

@@ -108,6 +108,6 @@ def step_inst_for_watchpoint(self, wp_id):
108108
"Watchpoint ID didn't match.")
109109
watchpoint_hit = True
110110
else:
111-
self.assertEquals(stop_reason, lldb.eStopReasonPlanComplete,
111+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete,
112112
STOPPED_DUE_TO_STEP_IN)
113113
self.assertTrue(watchpoint_hit, "Watchpoint never hit.")

lldb/test/API/commands/watchpoints/watchpoint_count/TestWatchpointCount.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def test_watchpoint_count(self):
3333
process.Continue()
3434

3535
stop_reason = thread.GetStopReason()
36-
self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "watchpoint for x1 not hit")
36+
self.assertStopReason(stop_reason, lldb.eStopReasonWatchpoint, "watchpoint for x1 not hit")
3737
stop_reason_descr = thread.GetStopDescription(256)
3838
self.assertEqual(stop_reason_descr, "watchpoint 1")
3939

4040
process.Continue()
4141
stop_reason = thread.GetStopReason()
42-
self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "watchpoint for x2 not hit")
42+
self.assertStopReason(stop_reason, lldb.eStopReasonWatchpoint, "watchpoint for x2 not hit")
4343
stop_reason_descr = thread.GetStopDescription(256)
4444
self.assertEqual(stop_reason_descr, "watchpoint 2")

lldb/test/API/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ def do_test(self, test_enable):
5656

5757
stop_reason = thread.GetStopReason()
5858

59-
self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.")
59+
self.assertStopReason(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.")
6060

6161
if test_enable:
6262
wp.SetEnabled(True)
6363
self.assertTrue(wp.IsEnabled(), "The watchpoint thinks it is still disabled.")
6464
process.Continue()
6565
stop_reason = thread.GetStopReason()
66-
self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint")
66+
self.assertStopReason(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint")
6767

lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ def test_break_on_lambda_capture(self):
4949
process.Continue()
5050
for thread in process.threads:
5151
if thread.id == main_thread.id:
52-
self.assertEqual(thread.stop_reason, lldb.eStopReasonBreakpoint)
52+
self.assertStopReason(thread.stop_reason, lldb.eStopReasonBreakpoint)
5353
else:
54-
self.assertEqual(thread.stop_reason, lldb.eStopReasonNone)
54+
self.assertStopReason(thread.stop_reason, lldb.eStopReasonNone)

lldb/test/API/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ def test_step_over(self):
8989
self.thread.StepOver()
9090
# We should be stopped at the breakpoint_2 line with stop plan complete reason
9191
self.assertState(self.process.GetState(), lldb.eStateStopped)
92-
self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete)
92+
self.assertStopReason(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete)
9393

9494
self.thread.StepOver()
9595
# We should be stopped at the breakpoint_3 line with stop plan complete reason
9696
self.assertState(self.process.GetState(), lldb.eStateStopped)
97-
self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete)
97+
self.assertStopReason(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete)
9898

9999
self.thread.StepOver()
100100
# We should be stopped at the breakpoint_4
101101
self.assertState(self.process.GetState(), lldb.eStateStopped)
102-
self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonBreakpoint)
102+
self.assertStopReason(self.thread.GetStopReason(), lldb.eStopReasonBreakpoint)
103103
thread1 = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoint4)
104104
self.assertEquals(self.thread, thread1, "Didn't stop at breakpoint 4.")
105105

0 commit comments

Comments
 (0)