[Lldb-commits] [lldb] r218558 - thread state coordinator: added test for notify after two pending thread stops.

Todd Fiala todd.fiala at gmail.com
Fri Sep 26 18:11:18 PDT 2014


Author: tfiala
Date: Fri Sep 26 20:11:17 2014
New Revision: 218558

URL: http://llvm.org/viewvc/llvm-project?rev=218558&view=rev
Log:
thread state coordinator: added test for notify after two pending thread stops.

Glad I did - caught a bug where the auto variable was not a reference
to a set and instead was a copy.  I need to review rules on that!

Modified:
    lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
    lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp

Modified: lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp?rev=218558&r1=218557&r2=218558&view=diff
==============================================================================
--- lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp (original)
+++ lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp Fri Sep 26 20:11:17 2014
@@ -111,6 +111,67 @@ TEST(ThreadStateCoordinatorTest, CallAft
     ASSERT_EQ (TRIGGERING_TID, reported_firing_tid);
 }
 
+TEST(ThreadStateCoordinatorTest, CallAfterThreadsStopFiresWhenTwoPendingStops)
+{
+    ThreadStateCoordinator coordinator(NOPLogger);
+
+    const lldb::tid_t TRIGGERING_TID = 4105;
+    const lldb::tid_t PENDING_STOP_TID = 3;
+    const lldb::tid_t PENDING_STOP_TID_02 = 29016;
+
+    ThreadStateCoordinator::ThreadIDSet pending_stop_tids { PENDING_STOP_TID, PENDING_STOP_TID_02 };
+
+    bool call_after_fired = false;
+    lldb::tid_t reported_firing_tid = 0;
+
+    int request_thread_stop_calls = 0;
+    ThreadStateCoordinator::ThreadIDSet request_thread_stop_tids;
+
+    // Notify we have a trigger that needs to be fired when all threads in the wait tid set have stopped.
+    coordinator.CallAfterThreadsStop (TRIGGERING_TID,
+                                      pending_stop_tids,
+                                      [&](lldb::tid_t tid) {
+                                          ++request_thread_stop_calls;
+                                          request_thread_stop_tids.insert (tid);
+
+                                      },
+                                      [&](lldb::tid_t tid) {
+                                          call_after_fired = true;
+                                          reported_firing_tid = tid;
+                                      });
+
+    // Neither trigger should have gone off yet.
+    ASSERT_EQ (false, call_after_fired);
+    ASSERT_EQ (0, request_thread_stop_calls);
+
+    // Process next event.
+    ASSERT_EQ (true, coordinator.ProcessNextEvent ());
+
+    // Now the request thread stops should have been called for the pending stop tids.
+    ASSERT_EQ (2, request_thread_stop_calls);
+    ASSERT_EQ (1, request_thread_stop_tids.count (PENDING_STOP_TID));
+    ASSERT_EQ (1, request_thread_stop_tids.count (PENDING_STOP_TID_02));
+
+    // But we still shouldn't have the deferred signal call go off yet.  Need to wait for the stop to be reported.
+    ASSERT_EQ (false, call_after_fired);
+
+    // Report the that the first pending stop occurred.
+    coordinator.NotifyThreadStop (PENDING_STOP_TID);
+    ASSERT_EQ (true, coordinator.ProcessNextEvent ());
+
+    // Shouldn't take effect until after both pending threads are notified.
+    ASSERT_EQ (false, call_after_fired);
+
+    // Report the that the first pending stop occurred.
+    coordinator.NotifyThreadStop (PENDING_STOP_TID_02);
+    ASSERT_EQ (false, call_after_fired);
+    ASSERT_EQ (true, coordinator.ProcessNextEvent ());
+
+    // Deferred signal notification should have fired now.
+    ASSERT_EQ (true, call_after_fired);
+    ASSERT_EQ (TRIGGERING_TID, reported_firing_tid);
+}
+
 TEST(ThreadStateCoordinatorTest, CallAfterThreadsStopFiresWhenPendingAlreadyStopped)
 {
     ThreadStateCoordinator coordinator(NOPLogger);

Modified: lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp?rev=218558&r1=218557&r2=218558&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp Fri Sep 26 20:11:17 2014
@@ -255,7 +255,7 @@ ThreadStateCoordinator::ThreadDidStop (l
     {
         EventCallAfterThreadsStop *call_after_event = static_cast<EventCallAfterThreadsStop*> (m_pending_notification_sp.get ());
 
-        auto remaining_stop_tids = call_after_event->GetRemainingWaitTIDs ();
+        ThreadIDSet &remaining_stop_tids = call_after_event->GetRemainingWaitTIDs ();
 
         // Remove this tid if it was in it.
         remaining_stop_tids.erase (tid);





More information about the lldb-commits mailing list