Skip to content

Commit 9f0b5f9

Browse files
author
SYNOPSYS\georgiev
committed
[lldb/test] Added lldbutil function to test a breakpoint
Testing the breakpoint itself rather than the lldb string. Differential Revision: https://reviews.llvm.org/D111899
1 parent f5ca3ac commit 9f0b5f9

File tree

38 files changed

+103
-107
lines changed

38 files changed

+103
-107
lines changed

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

+51
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,57 @@ def check_breakpoint_result(
730730
(out_module_name,
731731
module_name))
732732

733+
def check_breakpoint(
734+
test,
735+
bpno,
736+
expected_locations = None,
737+
expected_resolved_count = None,
738+
expected_hit_count = None,
739+
location_id = None,
740+
expected_location_resolved = True,
741+
expected_location_hit_count = None):
742+
"""
743+
Test breakpoint or breakpoint location.
744+
Breakpoint resolved count is always checked. If not specified the assumption is that all locations
745+
should be resolved.
746+
To test a breakpoint location, breakpoint number (bpno) and location_id must be set. In this case
747+
the resolved count for a breakpoint is not tested by default. The location is expected to be resolved,
748+
unless expected_location_resolved is set to False.
749+
test - test context
750+
bpno - breakpoint number to test
751+
expected_locations - expected number of locations for this breakpoint. If 'None' this parameter is not tested.
752+
expected_resolved_count - expected resolved locations number for the breakpoint. If 'None' - all locations should be resolved.
753+
expected_hit_count - expected hit count for this breakpoint. If 'None' this parameter is not tested.
754+
location_id - If not 'None' sets the location ID for the breakpoint to test.
755+
expected_location_resolved - Extected resolved status for the location_id (True/False). Default - True.
756+
expected_location_hit_count - Expected hit count for the breakpoint at location_id. Must be set if the location_id parameter is set.
757+
"""
758+
759+
bkpt = test.target().FindBreakpointByID(bpno)
760+
test.assertTrue(bkpt.IsValid(), "Breakpoint is not valid.")
761+
762+
if expected_locations is not None:
763+
test.assertEquals(expected_locations, bkpt.GetNumLocations())
764+
765+
if expected_resolved_count is not None:
766+
test.assertEquals(expected_resolved_count, bkpt.GetNumResolvedLocations())
767+
else:
768+
expected_resolved_count = bkpt.GetNumLocations()
769+
if location_id is None:
770+
test.assertEquals(expected_resolved_count, bkpt.GetNumResolvedLocations())
771+
772+
if expected_hit_count is not None:
773+
test.assertEquals(expected_hit_count, bkpt.GetHitCount())
774+
775+
if location_id is not None:
776+
loc_bkpt = bkpt.FindLocationByID(location_id)
777+
test.assertTrue(loc_bkpt.IsValid(), "Breakpoint location is not valid.")
778+
test.assertEquals(loc_bkpt.IsResolved(), expected_location_resolved)
779+
if expected_location_hit_count is not None:
780+
test.assertEquals(expected_location_hit_count, loc_bkpt.GetHitCount())
781+
782+
783+
733784
# ==================================================
734785
# Utility functions related to Threads and Processes
735786
# ==================================================

lldb/test/API/commands/apropos/with-process/TestAproposWithProcess.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def test_apropos_with_process(self):
3737
substrs=['stopped', 'stop reason = breakpoint'])
3838

3939
# The breakpoint should have a hit count of 1.
40-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
41-
substrs=[' resolved, hit count = 1'])
40+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4241

4342
self.runCmd('apropos env')

lldb/test/API/commands/command/nested_alias/TestNestedAlias.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def test_nested_alias(self):
3737
substrs=['stopped', 'stop reason = breakpoint'])
3838

3939
# The breakpoint should have a hit count of 1.
40-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
41-
substrs=[' resolved, hit count = 1'])
40+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4241

4342
# This is the function to remove the custom aliases in order to have a
4443
# clean slate for the next test case.

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ def breakpoint_command_sequence(self):
242242
'stop reason = breakpoint'])
243243

244244
# The breakpoint should have a hit count of 2.
245-
self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE,
246-
substrs=['resolved, hit count = 2'])
245+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 2)
247246

248247
def breakpoint_command_script_parameters(self):
249248
"""Test that the frame and breakpoint location are being properly passed to the script breakpoint command function."""
@@ -264,7 +263,7 @@ def breakpoint_command_script_parameters(self):
264263

265264
self.expect(side_effect.frame, exe=False, startstr="frame #0:")
266265
self.expect(side_effect.bp_loc, exe=False,
267-
patterns=["1.* where = .*main .* resolved, hit count = 1"])
266+
patterns=["1.* where = .*main .* resolved,( hardware,)? hit count = 1"])
268267

269268
def breakpoint_commands_on_creation(self):
270269
"""Test that setting breakpoint commands when creating the breakpoint works"""

lldb/test/API/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def breakpoint_ignore_count(self):
7676

7777
# Also check the hit count, which should be 2, due to ignore count of
7878
# 1.
79-
self.expect("breakpoint list -f", BREAKPOINT_HIT_THRICE,
80-
substrs=["resolved = 1",
81-
"hit count = 2"])
79+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 2)
8280

8381
# The frame #0 should correspond to main.c:37, the executable statement
8482
# in function name 'c'. And frame #2 should point to main.c:45.
@@ -97,9 +95,7 @@ def breakpoint_ignore_count(self):
9795

9896
# Also check the hit count, which should be 2, due to ignore count of
9997
# 1.
100-
self.expect("breakpoint list -f", BREAKPOINT_HIT_THRICE,
101-
substrs=["resolved = 1",
102-
"hit count = 4"])
98+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 4)
10399

104100
# The frame #0 should correspond to main.c:37, the executable statement
105101
# in function name 'c'. And frame #2 should point to main.c:45.

lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,7 @@ def breakpoint_locations_test(self):
187187

188188
# At this point, 1.1 has a hit count of 0 and the other a hit count of
189189
# 1".
190-
self.expect(
191-
"breakpoint list -f",
192-
"The breakpoints should report correct hit counts",
193-
patterns=[
194-
"1\.1: .+ unresolved, hit count = 0 +Options: disabled",
195-
"1\.2: .+ resolved, hit count = 1",
196-
"1\.3: .+ resolved, hit count = 1"])
190+
lldbutil.check_breakpoint(self, bpno = 1, expected_locations = 3, expected_resolved_count = 2, expected_hit_count = 2)
191+
lldbutil.check_breakpoint(self, bpno = 1, location_id = 1, expected_location_resolved = False, expected_location_hit_count = 0)
192+
lldbutil.check_breakpoint(self, bpno = 1, location_id = 2, expected_location_resolved = True, expected_location_hit_count = 1)
193+
lldbutil.check_breakpoint(self, bpno = 1, location_id = 3, expected_location_resolved = True, expected_location_hit_count = 1)

lldb/test/API/functionalities/dead-strip/TestDeadStrip.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def test(self):
4242
'stop reason = breakpoint'])
4343

4444
# The breakpoint should have a hit count of 1.
45-
self.expect("breakpoint list -f 1", BREAKPOINT_HIT_ONCE,
46-
substrs=[' resolved, hit count = 1'])
45+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4746

4847
self.runCmd("continue")
4948

@@ -54,5 +53,4 @@ def test(self):
5453
'stop reason = breakpoint'])
5554

5655
# The breakpoint should have a hit count of 1.
57-
self.expect("breakpoint list -f 3", BREAKPOINT_HIT_ONCE,
58-
substrs=[' resolved, hit count = 1'])
56+
lldbutil.check_breakpoint(self, bpno = 3, expected_hit_count = 1)

lldb/test/API/functionalities/load_unload/TestLoadUnload.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ def run_load_unload(self):
316316
'stop reason = breakpoint'])
317317

318318
# The breakpoint should have a hit count of 1.
319-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
320-
substrs=[' resolved, hit count = 1'])
319+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
321320

322321
# Issue the 'continue' command. We should stop agaian at a_function.
323322
# The stop reason of the thread should be breakpoint and at a_function.
@@ -331,8 +330,7 @@ def run_load_unload(self):
331330
'stop reason = breakpoint'])
332331

333332
# The breakpoint should have a hit count of 2.
334-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
335-
substrs=[' resolved, hit count = 2'])
333+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 2)
336334

337335
def test_step_over_load(self):
338336
self.setSvr4Support(False)

lldb/test/API/functionalities/memory/cache/TestMemoryCache.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def test_memory_cache(self):
3838
substrs=['stopped', 'stop reason = breakpoint'])
3939

4040
# The breakpoint should have a hit count of 1.
41-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
42-
substrs=[' resolved, hit count = 1'])
41+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4342

4443
# Read a chunk of memory containing &my_ints[0]. The number of bytes read
4544
# must be greater than m_L2_cache_line_byte_size to make sure the L1

lldb/test/API/functionalities/memory/find/TestMemoryFind.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def test_memory_find(self):
3737
substrs=['stopped', 'stop reason = breakpoint'])
3838

3939
# The breakpoint should have a hit count of 1.
40-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
41-
substrs=[' resolved, hit count = 1'])
40+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4241

4342
# Test the memory find commands.
4443

lldb/test/API/functionalities/memory/read/TestMemoryRead.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def build_run_stop(self):
3939
substrs=['stopped', 'stop reason = breakpoint'])
4040

4141
# The breakpoint should have a hit count of 1.
42-
self.expect("breakpoint list -f",
43-
BREAKPOINT_HIT_ONCE,
44-
substrs=[' resolved, hit count = 1'])
42+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4543

4644
@no_debug_info_test
4745
def test_memory_read(self):

lldb/test/API/lang/c/anonymous/TestAnonymous.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,4 @@ def common_setup(self, line):
166166
'stop reason = breakpoint'])
167167

168168
# The breakpoint should have a hit count of 1.
169-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
170-
substrs=[' resolved, hit count = 1'])
169+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

lldb/test/API/lang/c/array_types/TestArrayTypes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def test_and_run_command(self):
4242
'stop reason = breakpoint'])
4343

4444
# The breakpoint should have a hit count of 1.
45-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
46-
substrs=['resolved, hit count = 1'])
45+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4746

4847
# Issue 'variable list' command on several array-type variables.
4948

lldb/test/API/lang/c/conflicting-symbol/TestConflictingSymbol.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def test_conflicting_symbols(self):
4646
substrs=['stopped',
4747
'stop reason = breakpoint'])
4848

49-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
50-
substrs=[' resolved, hit count = 1'])
49+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
5150

5251
# This should display correctly.
5352
self.expect(
@@ -63,8 +62,7 @@ def test_conflicting_symbols(self):
6362
substrs=['stopped',
6463
'stop reason = breakpoint'])
6564

66-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
67-
substrs=[' resolved, hit count = 1'])
65+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
6866

6967
self.expect(
7068
"expr (unsigned long long)conflicting_symbol",
@@ -79,8 +77,7 @@ def test_conflicting_symbols(self):
7977
substrs=['stopped',
8078
'stop reason = breakpoint'])
8179

82-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
83-
substrs=[' resolved, hit count = 1'])
80+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
8481

8582
self.expect(
8683
"expr (unsigned long long)conflicting_symbol",

lldb/test/API/lang/c/const_variables/TestConstVariables.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def test_and_run_command(self):
3535
'stop reason = breakpoint'])
3636

3737
# The breakpoint should have a hit count of 1.
38-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
39-
substrs=[' resolved, hit count = 1'])
38+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4039

4140
self.runCmd("next")
4241
self.runCmd("next")

lldb/test/API/lang/c/enum_types/TestEnumTypes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def test_command_line(self):
5858
'stop reason = breakpoint'])
5959

6060
# The breakpoint should have a hit count of 1.
61-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
62-
substrs=[' resolved, hit count = 1'])
61+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
6362

6463
# Look up information about the 'enum_test_days' enum type.
6564
# Check for correct display.

lldb/test/API/lang/c/forward/TestForwardDeclaration.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def do_test(self, dictionary=None):
3030
'stop reason = breakpoint'])
3131

3232
# The breakpoint should have a hit count of 1.
33-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
34-
substrs=[' resolved, hit count = 1'])
33+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
3534

3635
# This should display correctly.
3736
# Note that the member fields of a = 1 and b = 2 is by design.

lldb/test/API/lang/c/function_types/TestFunctionTypes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,4 @@ def runToBreakpoint(self):
8282
'stop reason = breakpoint'])
8383

8484
# The breakpoint should have a hit count of 1.
85-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
86-
substrs=[' resolved, hit count = 1'])
85+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

lldb/test/API/lang/c/global_variables/TestGlobalVariables.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def test_c_global_variables(self):
6565
'stop reason = breakpoint'])
6666

6767
# The breakpoint should have a hit count of 1.
68-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
69-
substrs=[' resolved, hit count = 1'])
68+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
7069

7170
# Test that the statically initialized variable can also be
7271
# inspected *with* a process.

lldb/test/API/lang/c/local_variables/TestLocalVariables.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def test_c_local_variables(self):
4848
'stop reason = breakpoint'])
4949

5050
# The breakpoint should have a hit count of 1.
51-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
52-
substrs=[' resolved, hit count = 1'])
51+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
5352

5453
self.expect("frame variable i", VARIABLES_DISPLAYED_CORRECTLY,
5554
substrs=['(unsigned int) i = 10'])

lldb/test/API/lang/c/modules/TestCModules.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def test_expr(self):
3939
'stop reason = breakpoint'])
4040

4141
# The breakpoint should have a hit count of 1.
42-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
43-
substrs=[' resolved, hit count = 1'])
42+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4443

4544
# Enable logging of the imported AST.
4645
log_file = self.getBuildArtifact("lldb-ast-log.txt")

lldb/test/API/lang/c/register_variables/TestRegisterVariables.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def test_and_run_command(self):
5050
'stop reason = breakpoint'])
5151

5252
# The breakpoint should have a hit count of 1.
53-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
54-
substrs=[' resolved, hit count = 1'])
53+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
5554

5655
# Try some variables that should be visible
5756
frame = self.dbg.GetSelectedTarget().GetProcess(
@@ -77,8 +76,7 @@ def test_and_run_command(self):
7776
'stop reason = breakpoint'])
7877

7978
# The breakpoint should have a hit count of 1.
80-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
81-
substrs=[' resolved, hit count = 1'])
79+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
8280

8381
# Try some variables that should be visible
8482
frame = self.dbg.GetSelectedTarget().GetProcess(
@@ -104,8 +102,7 @@ def test_and_run_command(self):
104102
'stop reason = breakpoint'])
105103

106104
# The breakpoint should have a hit count of 1.
107-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
108-
substrs=[' resolved, hit count = 1'])
105+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
109106

110107
# Try some variables that should be visible
111108
frame = self.dbg.GetSelectedTarget().GetProcess(

lldb/test/API/lang/c/set_values/TestSetValues.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def test(self):
5252
'stop reason = breakpoint'])
5353

5454
# The breakpoint should have a hit count of 1.
55-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
56-
substrs=[' resolved, hit count = 1'])
55+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
5756

5857
# main.c:15
5958
# Check that 'frame variable --show-types' displays the correct data

lldb/test/API/lang/c/shared_lib/TestSharedLib.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,4 @@ def common_setup(self, preload_symbols = True):
9595
'stop reason = breakpoint'])
9696

9797
# The breakpoint should have a hit count of 1.
98-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
99-
substrs=[' resolved, hit count = 1'])
98+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,4 @@ def common_setup(self):
8484
'stop reason = breakpoint'])
8585

8686
# The breakpoint should have a hit count of 1.
87-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
88-
substrs=[' resolved, hit count = 1'])
87+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

lldb/test/API/lang/cpp/class_types/TestClassTypes.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def test_with_run_command(self):
4444
'stop reason = breakpoint'])
4545

4646
# The breakpoint should have a hit count of 1.
47-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
48-
substrs=[' resolved, hit count = 1'])
47+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
4948

5049
# We should be stopped on the ctor function of class C.
5150
self.expect(
@@ -141,8 +140,7 @@ def test_with_expr_parser(self):
141140
'stop reason = breakpoint'])
142141

143142
# The breakpoint should have a hit count of 1.
144-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
145-
substrs=[' resolved, hit count = 1'])
143+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
146144

147145
# Continue on inside the ctor() body...
148146
self.runCmd("register read pc")

lldb/test/API/lang/cpp/inlines/TestInlines.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ def runToBreakpoint(self):
5454
'stop reason = breakpoint'])
5555

5656
# The breakpoint should have a hit count of 1.
57-
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
58-
substrs=[' resolved, hit count = 1'])
57+
lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

0 commit comments

Comments
 (0)