[Lldb-commits] [lldb] r140890 - in /lldb/trunk/test: functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py functionalities/watchpoint/hello_watchlocation/main.cpp lldbtest.py

Johnny Chen johnny.chen at apple.com
Fri Sep 30 14:48:36 PDT 2011


Author: johnny
Date: Fri Sep 30 16:48:35 2011
New Revision: 140890

URL: http://llvm.org/viewvc/llvm-project?rev=140890&view=rev
Log:
o lldbtest.py:

Add a keyword argument 'endstr' to TestBase.expect() method to assert that the output
will end with 'endstr'.

Add TestBase.switch_to_thread_with_stop_reason(stop_reason) to select the thread with
the stop reason = 'stop_reason' as the current thread.

o TestWatchLocation.py:

Modified to switch to the stopped thread with stop reason = watchpoint and to evaluate
an expression with expected output for stronger assertion.

Modified:
    lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py
    lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/main.cpp
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py?rev=140890&r1=140889&r2=140890&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py (original)
+++ lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/TestWatchLocation.py Fri Sep 30 16:48:35 2011
@@ -62,6 +62,9 @@
         # incrmenting the global pool by 2.
         self.expect("frame variable -w write -x 1 -g g_char_ptr", WATCHPOINT_CREATED,
             substrs = ['Watchpoint created', 'size = 1', 'type = w'])
+        self.runCmd("expr unsigned val = *g_char_ptr; val")
+        self.expect(self.res.GetOutput().splitlines()[0], exe=False,
+            endstr = ' = 0')
 
         # Use the '-v' option to do verbose listing of the watchpoint.
         # The hit count should be 0 initially.
@@ -77,6 +80,13 @@
                        'stop reason = watchpoint',
                        self.violating_func])
 
+        # Switch to the thread stopped due to watchpoint and issue some commands.
+        self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
+        self.runCmd("thread backtrace")
+        self.runCmd("expr unsigned val = *g_char_ptr; val")
+        self.expect(self.res.GetOutput().splitlines()[0], exe=False,
+            endstr = ' = 1')
+
         # Use the '-v' option to do verbose listing of the watchpoint.
         # The hit count should now be 1.
         self.expect("watchpoint list -v",

Modified: lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/main.cpp?rev=140890&r1=140889&r2=140890&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/main.cpp (original)
+++ lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/main.cpp Fri Sep 30 16:48:35 2011
@@ -23,6 +23,8 @@
 void
 do_bad_thing_with_location(char *char_ptr, char new_val)
 {
+    unsigned what = new_val;
+    printf("new value written to location(%p) = %u\n", char_ptr, what);
     *char_ptr = new_val;
 }
 

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=140890&r1=140889&r2=140890&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri Sep 30 16:48:35 2011
@@ -962,6 +962,21 @@
 
         del self.dbg
 
+    def switch_to_thread_with_stop_reason(self, stop_reason):
+        """
+        Run the 'thread list' command, and select the thread with stop reason as
+        'stop_reason'.  If no such thread exists, no select action is done.
+        """
+        from lldbutil import stop_reason_to_str
+        self.runCmd('thread list')
+        output = self.res.GetOutput()
+        thread_line_pattern = re.compile("^[ *] thread #([0-9]+):.*stop reason = %s" %
+                                         stop_reason_to_str(stop_reason))
+        for line in output.splitlines():
+            matched = thread_line_pattern.match(line)
+            if matched:
+                self.runCmd('thread select %s' % matched.group(1))
+
     def runCmd(self, cmd, msg=None, check=True, trace=False):
         """
         Ask the command interpreter to handle the command and then check its
@@ -1000,7 +1015,7 @@
             self.assertTrue(self.res.Succeeded(),
                             msg if msg else CMD_MSG(cmd))
 
-    def expect(self, str, msg=None, patterns=None, startstr=None, substrs=None, trace=False, error=False, matching=True, exe=True):
+    def expect(self, str, msg=None, patterns=None, startstr=None, endstr=None, substrs=None, trace=False, error=False, matching=True, exe=True):
         """
         Similar to runCmd; with additional expect style output matching ability.
 
@@ -1056,6 +1071,14 @@
                 print >> sbuf, "%s start string: %s" % (heading, startstr)
                 print >> sbuf, "Matched" if matched else "Not matched"
 
+        # Look for endstr, if specified.
+        keepgoing = matched if matching else not matched
+        if endstr:
+            matched = output.endswith(endstr)
+            with recording(self, trace) as sbuf:
+                print >> sbuf, "%s end string: %s" % (heading, endstr)
+                print >> sbuf, "Matched" if matched else "Not matched"
+
         # Look for sub strings, if specified.
         keepgoing = matched if matching else not matched
         if substrs and keepgoing:
@@ -1110,14 +1133,15 @@
 
         err = sys.stderr
         err.write(val.GetName() + ":\n")
-        err.write('\t' + "TypeName      -> " + val.GetTypeName()            + '\n')
-        err.write('\t' + "ByteSize      -> " + str(val.GetByteSize())       + '\n')
-        err.write('\t' + "NumChildren   -> " + str(val.GetNumChildren())    + '\n')
-        err.write('\t' + "Value         -> " + str(val.GetValue())          + '\n')
-        err.write('\t' + "ValueType     -> " + value_type_to_str(val.GetValueType()) + '\n')
-        err.write('\t' + "Summary       -> " + str(val.GetSummary())        + '\n')
-        err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n')
-        err.write('\t' + "Location      -> " + val.GetLocation()            + '\n')
+        err.write('\t' + "TypeName         -> " + val.GetTypeName()            + '\n')
+        err.write('\t' + "ByteSize         -> " + str(val.GetByteSize())       + '\n')
+        err.write('\t' + "NumChildren      -> " + str(val.GetNumChildren())    + '\n')
+        err.write('\t' + "Value            -> " + str(val.GetValue())          + '\n')
+        err.write('\t' + "ValueAsUnsigned  -> " + str(val.GetValueAsUnsigned())+ '\n')
+        err.write('\t' + "ValueType        -> " + value_type_to_str(val.GetValueType()) + '\n')
+        err.write('\t' + "Summary          -> " + str(val.GetSummary())        + '\n')
+        err.write('\t' + "IsPointerType    -> " + str(val.TypeIsPointerType()) + '\n')
+        err.write('\t' + "Location         -> " + val.GetLocation()            + '\n')
 
     def DebugSBType(self, type):
         """Debug print a SBType object, if traceAlways is True."""





More information about the lldb-commits mailing list