[Lldb-commits] [lldb] r116270 - in /lldb/trunk/test: array_types/TestArrayTypes.py array_types/main.c lldbtest.py

Johnny Chen johnny.chen at apple.com
Mon Oct 11 16:52:19 PDT 2010


Author: johnny
Date: Mon Oct 11 18:52:19 2010
New Revision: 116270

URL: http://llvm.org/viewvc/llvm-project?rev=116270&view=rev
Log:
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

Modified:
    lldb/trunk/test/array_types/TestArrayTypes.py
    lldb/trunk/test/array_types/main.c
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/test/array_types/TestArrayTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=116270&r1=116269&r2=116270&view=diff
==============================================================================
--- lldb/trunk/test/array_types/TestArrayTypes.py (original)
+++ lldb/trunk/test/array_types/TestArrayTypes.py Mon Oct 11 18:52:19 2010
@@ -31,14 +31,20 @@
         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 @@
         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 @@
         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.

Modified: lldb/trunk/test/array_types/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/main.c?rev=116270&r1=116269&r2=116270&view=diff
==============================================================================
--- lldb/trunk/test/array_types/main.c (original)
+++ lldb/trunk/test/array_types/main.c Mon Oct 11 18:52:19 2010
@@ -39,7 +39,7 @@
         {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}}
     };

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=116270&r1=116269&r2=116270&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Mon Oct 11 18:52:19 2010
@@ -226,6 +226,15 @@
         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





More information about the lldb-commits mailing list