diff options
| author | Adrian McCarthy <amccarth@google.com> | 2015-05-14 21:07:59 +0000 |
|---|---|---|
| committer | Adrian McCarthy <amccarth@google.com> | 2015-05-14 21:07:59 +0000 |
| commit | d26b0c4d31ef4088a8d9db77366d637704917338 (patch) | |
| tree | b6cb5dd4318b70db6ec29a3eafd335ec02d2627e /lldb/test/functionalities/thread | |
| parent | c324b92c3557b0981d38c9ee7920f2c7ab0856c8 (diff) | |
| download | bcm5719-llvm-d26b0c4d31ef4088a8d9db77366d637704917338.tar.gz bcm5719-llvm-d26b0c4d31ef4088a8d9db77366d637704917338.zip | |
Enable multithreaded debugging on Windows.
llvm-svn: 237392
Diffstat (limited to 'lldb/test/functionalities/thread')
| -rw-r--r-- | lldb/test/functionalities/thread/Makefile | 2 | ||||
| -rw-r--r-- | lldb/test/functionalities/thread/TestNumThreads.py | 10 | ||||
| -rw-r--r-- | lldb/test/functionalities/thread/main.c | 57 | ||||
| -rw-r--r-- | lldb/test/functionalities/thread/main.cpp | 50 |
4 files changed, 57 insertions, 62 deletions
diff --git a/lldb/test/functionalities/thread/Makefile b/lldb/test/functionalities/thread/Makefile index dcbe9b37437..644e2971a2c 100644 --- a/lldb/test/functionalities/thread/Makefile +++ b/lldb/test/functionalities/thread/Makefile @@ -1,5 +1,5 @@ LEVEL = ../../make -C_SOURCES := main.c +CXX_SOURCES := main.cpp ENABLE_THREADS := YES include $(LEVEL)/Makefile.rules diff --git a/lldb/test/functionalities/thread/TestNumThreads.py b/lldb/test/functionalities/thread/TestNumThreads.py index d2156399d61..824956be8d4 100644 --- a/lldb/test/functionalities/thread/TestNumThreads.py +++ b/lldb/test/functionalities/thread/TestNumThreads.py @@ -29,7 +29,7 @@ class NumberOfThreadsTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break inside main(). - self.line = line_number('main.c', '// Set break point at this line.') + self.line = line_number('main.cpp', '// Set break point at this line.') def number_of_threads_test(self): """Test number of threads.""" @@ -37,11 +37,11 @@ class NumberOfThreadsTestCase(TestBase): self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # This should create a breakpoint with 1 location. - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1) + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1) # The breakpoint list should show 3 locations. self.expect("breakpoint list -f", "Breakpoint location shown correctly", - substrs = ["1: file = 'main.c', line = %d, locations = 1" % self.line]) + substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.line]) # Run the program. self.runCmd("run", RUN_SUCCEEDED) @@ -57,7 +57,9 @@ class NumberOfThreadsTestCase(TestBase): # Get the number of threads num_threads = process.GetNumThreads() - self.assertTrue(num_threads == 4, 'Number of expected threads and actual threads do not match.') + # Using std::thread may involve extra threads, so we assert that there are + # at least 4 rather than exactly 4. + self.assertTrue(num_threads >= 4, 'Number of expected threads and actual threads do not match.') if __name__ == '__main__': import atexit diff --git a/lldb/test/functionalities/thread/main.c b/lldb/test/functionalities/thread/main.c deleted file mode 100644 index b1fec81c11b..00000000000 --- a/lldb/test/functionalities/thread/main.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <pthread.h> - -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; - -void * -thread3 (void *input) -{ - pthread_mutex_lock(&mutex); - pthread_cond_signal(&cond); // Set break point at this line. - pthread_mutex_unlock(&mutex); - return NULL; -} - -void * -thread2 (void *input) -{ - pthread_mutex_lock(&mutex); - pthread_cond_signal(&cond); - pthread_cond_wait(&cond, &mutex); - pthread_mutex_unlock(&mutex); - return NULL; -} - -void * -thread1 (void *input) -{ - pthread_t thread_2; - pthread_create (&thread_2, NULL, thread2, NULL); - - pthread_join(thread_2, NULL); - - return NULL; -} - -int main () -{ - pthread_t thread_1; - pthread_t thread_3; - - pthread_mutex_lock (&mutex); - - pthread_create (&thread_1, NULL, thread1, NULL); - - pthread_cond_wait (&cond, &mutex); - - pthread_create (&thread_3, NULL, thread3, NULL); - - pthread_cond_wait (&cond, &mutex); - - pthread_mutex_unlock (&mutex); - - pthread_join (thread_1, NULL); - pthread_join (thread_3, NULL); - - return 0; -} diff --git a/lldb/test/functionalities/thread/main.cpp b/lldb/test/functionalities/thread/main.cpp new file mode 100644 index 00000000000..6a0ea4e0d11 --- /dev/null +++ b/lldb/test/functionalities/thread/main.cpp @@ -0,0 +1,50 @@ +#include <condition_variable> +#include <mutex> +#include <thread> + +std::mutex mutex; +std::condition_variable cond; + +void * +thread3(void *input) +{ + std::unique_lock<std::mutex> lock(mutex); + cond.notify_all(); // Set break point at this line. + return NULL; +} + +void * +thread2(void *input) +{ + std::unique_lock<std::mutex> lock(mutex); + cond.notify_all(); + cond.wait(lock); + return NULL; +} + +void * +thread1(void *input) +{ + std::thread thread_2(thread2, nullptr); + thread_2.join(); + + return NULL; +} + +int main() +{ + std::unique_lock<std::mutex> lock(mutex); + + std::thread thread_1(thread1, nullptr); + cond.wait(lock); + + std::thread thread_3(thread3, nullptr); + cond.wait(lock); + + lock.unlock(); + + thread_1.join(); + thread_3.join(); + + return 0; +} |

