[Lldb-commits] [lldb] r264846 - Fix flakyness in TestWatchpointMultipleThreads

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 30 01:43:54 PDT 2016


Author: labath
Date: Wed Mar 30 03:43:54 2016
New Revision: 264846

URL: http://llvm.org/viewvc/llvm-project?rev=264846&view=rev
Log:
Fix flakyness in TestWatchpointMultipleThreads

Summary:
the inferior in the test deliberately does not lock a mutex when accessing the watched variable.
The reason for that is unclear as, based on the logs, the original intention of the test was to
check whether watchpoints get propagated to newly created threads, which should work fine even
with a mutex. Furthermore, in the unlikely event (which I have still observed happening from time
to time) that two threads do manage the execute the "critical section" simultaneously, the test
will fail, as it is expecting the watchpoint "hit count" to be 1, but in this case it will be 2.

Given this, I have simply chose to lock the mutex always, so that we have more predictible
behavior. Watchpoints being hit simultaneously is still (and correctly!) tested by
TestConcurrentEvents.

Reviewers: clayborg, jingham

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D18558

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py?rev=264846&r1=264845&r2=264846&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/TestWatchpointMultipleThreads.py Wed Mar 30 03:43:54 2016
@@ -58,9 +58,6 @@ class WatchpointForMultipleThreadsTestCa
                        'stop reason = breakpoint'])
 
         # Now let's set a write-type watchpoint for variable 'g_val'.
-        # The main.cpp, by design, misbehaves by not following the agreed upon
-        # protocol of using a mutex while accessing the global pool and by not
-        # writing to the variable.
         self.expect("watchpoint set variable -w write g_val", WATCHPOINT_CREATED,
             substrs = ['Watchpoint created', 'size = 4', 'type = w'])
 
@@ -102,9 +99,6 @@ class WatchpointForMultipleThreadsTestCa
                        'stop reason = breakpoint'])
 
         # Now let's set a write-type watchpoint for variable 'g_val'.
-        # The main.cpp, by design, misbehaves by not following the agreed upon
-        # protocol of using a mutex while accessing the global pool and by not
-        # writing to the variable.
         self.expect("watchpoint set variable -w write g_val", WATCHPOINT_CREATED,
             substrs = ['Watchpoint created', 'size = 4', 'type = w'])
 

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp?rev=264846&r1=264845&r2=264846&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/watchpoint/multiple_threads/main.cpp Wed Mar 30 03:43:54 2016
@@ -23,8 +23,7 @@ uint32_t
 access_pool (bool flag = false)
 {
     static std::mutex g_access_mutex;
-    if (!flag)
-        g_access_mutex.lock();
+    g_access_mutex.lock();
 
     uint32_t old_val = g_val;
     if (flag)
@@ -33,17 +32,14 @@ access_pool (bool flag = false)
         g_val = old_val + 1;
     }
 
-    if (!flag)
-        g_access_mutex.unlock();
+    g_access_mutex.unlock();
     return g_val;
 }
 
 void
 thread_func (uint32_t thread_index)
 {
-    // Break here in order to allow the thread
-    // to inherit the global watchpoint state.
-    printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index);
+    printf ("%s (thread index = %u) starting...\n", __FUNCTION__, thread_index);
 
     uint32_t count = 0;
     uint32_t val;




More information about the lldb-commits mailing list