diff options
author | Todd Fiala <todd.fiala@gmail.com> | 2014-10-02 19:03:06 +0000 |
---|---|---|
committer | Todd Fiala <todd.fiala@gmail.com> | 2014-10-02 19:03:06 +0000 |
commit | 325111bcc6ee751e16faeeca405ed4b103b2ffce (patch) | |
tree | 3055cbd4e49abda4c12181d84b2f48aa0afe1384 /lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp | |
parent | 2b60cd1b6831d7e95578eb8901495480e9aa301b (diff) | |
download | bcm5719-llvm-325111bcc6ee751e16faeeca405ed4b103b2ffce.tar.gz bcm5719-llvm-325111bcc6ee751e16faeeca405ed4b103b2ffce.zip |
thread state coordinator: added simpler deferred stop notification method.
Now that ThreadStateCoordinator errors out on threads in unexpected states,
it has enough information to know which threads need stop requests fired
when we want to do a deferred callback on a thread's behalf. This change
adds a new method, CallAfterRunningThreadsStop(...), which no longer
takes a set of thread ids that require stop requests. It's much harder
to misuse this method and (with newer error logic) it's harder to
correctly use the original method. Expect the original method that takes
the set of thread ids to stop to disappear in the near future.
Adds several tests for CallAfterRunningThreadsStop().
llvm-svn: 218897
Diffstat (limited to 'lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp')
-rw-r--r-- | lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp b/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp index 3be6805f3bf..a6bc40fd622 100644 --- a/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp +++ b/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp @@ -170,6 +170,15 @@ ASSERT_EQ (true, HasError ()); } void + CallAfterRunningThreadsStop (lldb::tid_t deferred_tid) + { + m_coordinator.CallAfterRunningThreadsStop (deferred_tid, + GetStopRequestFunction (), + GetDeferredStopNotificationFunction (), + GetErrorFunction ()); + } + + void NotifyThreadCreate (lldb::tid_t stopped_tid, bool thread_is_stopped) { m_coordinator.NotifyThreadCreate (stopped_tid, thread_is_stopped, GetErrorFunction ()); @@ -671,3 +680,94 @@ TEST_F (ThreadStateCoordinatorTest, ResumedThreadAlreadyMarkedDoesNotHoldUpPendi ASSERT_EQ (true, DidFireDeferredNotification ()); ASSERT_EQ (TRIGGERING_TID, GetDeferredNotificationTID ()); } + +TEST_F (ThreadStateCoordinatorTest, CallAfterRunningThreadsStopFiresWhenNoRunningThreads) +{ + // Let the coordinator know about our thread. + SetupKnownStoppedThread (TRIGGERING_TID); + + // Notify we have a trigger that needs to be fired when all running threads have stopped. + CallAfterRunningThreadsStop (TRIGGERING_TID); + + // Notification trigger shouldn't go off yet. + ASSERT_EQ (false, DidFireDeferredNotification ()); + + // Process next event. This will pick up the call after threads stop event. + ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS (); + + // Now the trigger should have fired, since there were no threads that needed to first stop. + ASSERT_EQ (true, DidFireDeferredNotification ()); + ASSERT_EQ (TRIGGERING_TID, GetDeferredNotificationTID ()); + + // And no stop requests should have been made. + ASSERT_EQ (0, GetRequestedStopCount ()); +} + +TEST_F (ThreadStateCoordinatorTest, CallAfterRunningThreadsStopRequestsTwoPendingStops) +{ + // Let the coordinator know about our threads. + SetupKnownStoppedThread (TRIGGERING_TID); + SetupKnownRunningThread (PENDING_STOP_TID); + SetupKnownRunningThread (PENDING_STOP_TID_02); + + // Notify we have a trigger that needs to be fired when all running threads have stopped. + CallAfterRunningThreadsStop (TRIGGERING_TID); + + // Notification trigger shouldn't go off yet. + ASSERT_EQ (false, DidFireDeferredNotification ()); + + // Process next event. This will pick up the call after threads stop event. + ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS (); + + // We should have two stop requests for the two threads currently running. + ASSERT_EQ (2, GetRequestedStopCount ()); + ASSERT_EQ (true, DidRequestStopForTid (PENDING_STOP_TID)); + ASSERT_EQ (true, DidRequestStopForTid (PENDING_STOP_TID_02)); + + // But the deferred stop notification should not have fired yet. + ASSERT_EQ (false, DidFireDeferredNotification ()); + + // Now notify the two threads stopped. + NotifyThreadStop (PENDING_STOP_TID); + ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS (); + ASSERT_EQ (false, DidFireDeferredNotification ()); + + NotifyThreadStop (PENDING_STOP_TID_02); + ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS (); + + // Now the trigger should have fired, since there were no threads that needed to first stop. + ASSERT_EQ (true, DidFireDeferredNotification ()); + ASSERT_EQ (TRIGGERING_TID, GetDeferredNotificationTID ()); +} + +TEST_F (ThreadStateCoordinatorTest, CallAfterRunningThreadsStopRequestsStopTwoOtherThreadsOneRunning) +{ + // Let the coordinator know about our threads. PENDING_STOP_TID_02 will already be stopped. + SetupKnownStoppedThread (TRIGGERING_TID); + SetupKnownRunningThread (PENDING_STOP_TID); + SetupKnownStoppedThread (PENDING_STOP_TID_02); + + // Notify we have a trigger that needs to be fired when all running threads have stopped. + CallAfterRunningThreadsStop (TRIGGERING_TID); + + // Notification trigger shouldn't go off yet. + ASSERT_EQ (false, DidFireDeferredNotification ()); + + // Process next event. This will pick up the call after threads stop event. + ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS (); + + // We should have two stop requests for the two threads currently running. + ASSERT_EQ (1, GetRequestedStopCount ()); + ASSERT_EQ (true, DidRequestStopForTid (PENDING_STOP_TID)); + + // But the deferred stop notification should not have fired yet. + ASSERT_EQ (false, DidFireDeferredNotification ()); + + // Now notify the two threads stopped. + NotifyThreadStop (PENDING_STOP_TID); + ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS (); + + // Now the trigger should have fired, since there were no threads that needed to first stop. + ASSERT_EQ (true, DidFireDeferredNotification ()); + ASSERT_EQ (TRIGGERING_TID, GetDeferredNotificationTID ()); +} |