summaryrefslogtreecommitdiffstats
path: root/lldb/gtest
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2014-09-29 22:57:05 +0000
committerTodd Fiala <todd.fiala@gmail.com>2014-09-29 22:57:05 +0000
commite2109e732382ee5a8cc1e57cd54d9ecd2cfbb97a (patch)
treee12daf04b8f86d9cdbe6a15e2eb701c797cc2f07 /lldb/gtest
parent6bddb8c3a57ad79849f97c5775479e00bafb0c7e (diff)
downloadbcm5719-llvm-e2109e732382ee5a8cc1e57cd54d9ecd2cfbb97a.tar.gz
bcm5719-llvm-e2109e732382ee5a8cc1e57cd54d9ecd2cfbb97a.zip
thread state coordinator: added a thread resume request and related tests.
The thread resume block is executed in the normal flow of thread state queued event processing. The tests verify that it is executed when we track the thread to be stopped and skipped when we track it to already be running. llvm-svn: 218638
Diffstat (limited to 'lldb/gtest')
-rw-r--r--lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp b/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
index ddf82cc711a..f9ca339e4fa 100644
--- a/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
+++ b/lldb/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
@@ -14,6 +14,14 @@ namespace
{
// Do nothing.
}
+
+ void
+ StdoutLogger (const char *format, va_list args)
+ {
+ // Print to stdout.
+ vprintf (format, args);
+ printf ("\n");
+ }
}
TEST(ThreadStateCoordinatorTest, StopCoordinatorWorksNoPriorEvents)
@@ -433,3 +441,61 @@ TEST(ThreadStateCoordinatorTest, DeferredNotificationRemovedByResetForExec)
ASSERT_EQ (false, call_after_fired);
}
+
+TEST(ThreadStateCoordinatorTest, RequestThreadResumeCallsCallbackWhenThreadIsStopped)
+{
+ ThreadStateCoordinator coordinator(NOPLogger);
+
+ // Initialize thread to be in stopped state.
+ const lldb::tid_t TEST_TID = 1234;
+
+ coordinator.NotifyThreadStop (TEST_TID);
+ ASSERT_EQ (true, coordinator.ProcessNextEvent ());
+
+ // Request a resume.
+ lldb::tid_t resumed_tid = 0;
+ int resume_call_count = 0;
+
+ coordinator.RequestThreadResume (TEST_TID,
+ [&](lldb::tid_t tid)
+ {
+ ++resume_call_count;
+ resumed_tid = tid;
+ });
+
+ // Shouldn't be called yet.
+ ASSERT_EQ (0, resume_call_count);
+
+ // Process next event. After that, the resume request call should have fired.
+ ASSERT_EQ (true, coordinator.ProcessNextEvent ());
+ ASSERT_EQ (1, resume_call_count);
+ ASSERT_EQ (TEST_TID, resumed_tid);
+}
+
+TEST(ThreadStateCoordinatorTest, RequestThreadResumeIgnoresCallbackWhenThreadIsRunning)
+{
+ ThreadStateCoordinator coordinator(StdoutLogger);
+
+ // This thread will be assumed running (i.e. unknown, assumed running until marked stopped.)
+ const lldb::tid_t TEST_TID = 1234;
+
+ // Request a resume.
+ lldb::tid_t resumed_tid = 0;
+ int resume_call_count = 0;
+
+ coordinator.RequestThreadResume (TEST_TID,
+ [&](lldb::tid_t tid)
+ {
+ ++resume_call_count;
+ resumed_tid = tid;
+ });
+
+ // Shouldn't be called yet.
+ ASSERT_EQ (0, resume_call_count);
+
+ // Process next event.
+ ASSERT_EQ (true, coordinator.ProcessNextEvent ());
+
+ // The resume request should not have gone off because we think it is already running.
+ ASSERT_EQ (0, resume_call_count);
+}
OpenPOWER on IntegriCloud