From 47ceb0321033e08b2332baec7bf522851fcaff06 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Mon, 11 Oct 2010 23:52:19 +0000 Subject: [PATCH] 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 --- lldb/test/array_types/TestArrayTypes.py | 18 ++++++++++++------ lldb/test/array_types/main.c | 2 +- lldb/test/lldbtest.py | 9 +++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lldb/test/array_types/TestArrayTypes.py b/lldb/test/array_types/TestArrayTypes.py index 3f3a448e685c..010afa7a98f3 100644 --- a/lldb/test/array_types/TestArrayTypes.py +++ b/lldb/test/array_types/TestArrayTypes.py @@ -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. diff --git a/lldb/test/array_types/main.c b/lldb/test/array_types/main.c index f395df522100..5f0680a43b84 100644 --- a/lldb/test/array_types/main.c +++ b/lldb/test/array_types/main.c @@ -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}} }; diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index e2f18a9b4014..915cfd54fe12 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -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