forked from OSchip/llvm-project
Add a utility function to lldbtest.py to return the line number of a matched string
within a file. This is to be used within the test case to avoid hardcoded line number. array_types/TestArrayTypes.py is modified first to use this pattern. Other test modules to follow. rdar://problem/8537816 Testsuite: don't set breakpoints by exact file & line number llvm-svn: 116270
This commit is contained in:
parent
48ed37d98e
commit
47ceb03210
|
|
@ -31,14 +31,20 @@ class ArrayTypesTestCase(TestBase):
|
|||
self.buildDwarf()
|
||||
self.array_types_python()
|
||||
|
||||
def setUp(self):
|
||||
super(ArrayTypesTestCase, self).setUp()
|
||||
# Find the line number to break inside main().
|
||||
self.line = line_number('main.c', '// Set break point at this line.')
|
||||
|
||||
def array_types(self):
|
||||
"""Test 'frame variable var_name' on some variables with array types."""
|
||||
exe = os.path.join(os.getcwd(), "a.out")
|
||||
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
||||
|
||||
# Break on line 42 inside main().
|
||||
self.expect("breakpoint set -f main.c -l 42", BREAKPOINT_CREATED,
|
||||
startstr = "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")
|
||||
self.expect("breakpoint set -f main.c -l %d" % self.line,
|
||||
BREAKPOINT_CREATED,
|
||||
startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
|
||||
self.line)
|
||||
|
||||
self.runCmd("run", RUN_SUCCEEDED)
|
||||
|
||||
|
|
@ -88,14 +94,14 @@ class ArrayTypesTestCase(TestBase):
|
|||
target = self.dbg.CreateTarget(exe)
|
||||
self.assertTrue(target.IsValid(), VALID_TARGET)
|
||||
|
||||
breakpoint = target.BreakpointCreateByLocation("main.c", 42)
|
||||
breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
|
||||
self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
|
||||
|
||||
# Sanity check the print representation of breakpoint.
|
||||
bp = repr(breakpoint)
|
||||
self.expect(bp, msg="Breakpoint looks good", exe=False,
|
||||
substrs = ["file ='main.c'",
|
||||
"line = 42",
|
||||
"line = %d" % self.line,
|
||||
"locations = 1"])
|
||||
self.expect(bp, msg="Breakpoint is not resolved as yet", exe=False, matching=False,
|
||||
substrs = ["resolved = 1"])
|
||||
|
|
@ -129,7 +135,7 @@ class ArrayTypesTestCase(TestBase):
|
|||
bp = repr(breakpoint)
|
||||
self.expect(bp, "Breakpoint looks good and is resolved", exe=False,
|
||||
substrs = ["file ='main.c'",
|
||||
"line = 42",
|
||||
"line = %d" % self.line,
|
||||
"locations = 1"])
|
||||
|
||||
# Sanity check the print representation of frame.
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ int main (int argc, char const *argv[])
|
|||
{1,2},
|
||||
{3,4}
|
||||
};
|
||||
struct point_tag points_2_4_matrix[2][4] = {
|
||||
struct point_tag points_2_4_matrix[2][4] = { // Set break point at this line.
|
||||
{{ 1, 2}, { 3, 4}, { 5, 6}, { 7, 8}},
|
||||
{{11,22}, {33,44}, {55,66}, {77,88}}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -226,6 +226,15 @@ def system(*popenargs, **kwargs):
|
|||
raise CalledProcessError(retcode, cmd)
|
||||
return output
|
||||
|
||||
def line_number(filename, string_to_match):
|
||||
"""Helper function to return the line number of the first matched string."""
|
||||
with open(filename, 'r') as f:
|
||||
for i, line in enumerate(f):
|
||||
if line.find(string_to_match) != -1:
|
||||
# Found our match.
|
||||
return i
|
||||
return -1
|
||||
|
||||
def pointer_size():
|
||||
"""Return the pointer size of the host system."""
|
||||
import ctypes
|
||||
|
|
|
|||
Loading…
Reference in New Issue