[Lldb-commits] [lldb] r171869 - in /lldb/trunk/test/functionalities/thread: ./ Makefile TestNumThreads.py main.c
Matt Kopec
Matt.Kopec at intel.com
Tue Jan 8 09:29:00 PST 2013
Author: mkopec
Date: Tue Jan 8 11:29:00 2013
New Revision: 171869
URL: http://llvm.org/viewvc/llvm-project?rev=171869&view=rev
Log:
Add test to check the number of threads.
Added:
lldb/trunk/test/functionalities/thread/
lldb/trunk/test/functionalities/thread/Makefile
lldb/trunk/test/functionalities/thread/TestNumThreads.py
lldb/trunk/test/functionalities/thread/main.c
Added: lldb/trunk/test/functionalities/thread/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/Makefile?rev=171869&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/thread/Makefile (added)
+++ lldb/trunk/test/functionalities/thread/Makefile Tue Jan 8 11:29:00 2013
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+LDFLAGS := -lpthread
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/functionalities/thread/TestNumThreads.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/TestNumThreads.py?rev=171869&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/thread/TestNumThreads.py (added)
+++ lldb/trunk/test/functionalities/thread/TestNumThreads.py Tue Jan 8 11:29:00 2013
@@ -0,0 +1,66 @@
+"""
+Test number of threads.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+class NumberOfThreadsTestCase(TestBase):
+
+ mydir = os.path.join("functionalities", "thread")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ def test_with_dsym(self):
+ """Test number of threads."""
+ self.buildDsym()
+ self.number_of_threads_test()
+
+ @dwarf_test
+ def test_with_dwarf(self):
+ """Test number of threads."""
+ self.buildDwarf()
+ self.number_of_threads_test()
+
+ def setUp(self):
+ # 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.')
+
+ def number_of_threads_test(self):
+ """Test number of threads."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ 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)
+
+ # 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])
+
+ # Run the program.
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Stopped once.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ["stop reason = breakpoint 1."])
+
+ # Get the target process
+ target = self.dbg.GetSelectedTarget()
+ process = target.GetProcess()
+
+ # Get the number of threads
+ num_threads = process.GetNumThreads()
+
+ self.assertTrue(num_threads == 4, 'Number of expected threads and actual threads do not match.')
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/functionalities/thread/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/main.c?rev=171869&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/thread/main.c (added)
+++ lldb/trunk/test/functionalities/thread/main.c Tue Jan 8 11:29:00 2013
@@ -0,0 +1,58 @@
+#include <pthread.h>
+
+pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t mutex3 = PTHREAD_MUTEX_INITIALIZER;
+
+void *
+thread3 (void *input)
+{
+ pthread_mutex_unlock(&mutex2); // Set break point at this line.
+ pthread_mutex_unlock(&mutex1);
+ return NULL;
+}
+
+void *
+thread2 (void *input)
+{
+ pthread_mutex_unlock(&mutex3);
+ pthread_mutex_lock(&mutex2);
+ pthread_mutex_unlock(&mutex2);
+
+ return NULL;
+}
+
+void *
+thread1 (void *input)
+{
+ pthread_t thread_2;
+ pthread_create (&thread_2, NULL, thread2, NULL);
+
+ pthread_mutex_lock(&mutex1);
+ pthread_mutex_unlock(&mutex1);
+
+ pthread_join(thread_2, NULL);
+
+ return NULL;
+}
+
+int main ()
+{
+ pthread_t thread_1;
+ pthread_t thread_3;
+
+ pthread_mutex_lock (&mutex1);
+ pthread_mutex_lock (&mutex2);
+ pthread_mutex_lock (&mutex3);
+
+ pthread_create (&thread_1, NULL, thread1, NULL);
+
+ pthread_mutex_lock(&mutex3);
+ pthread_create (&thread_3, NULL, thread3, NULL);
+
+ pthread_join (thread_1, NULL);
+ pthread_join (thread_3, NULL);
+
+ return 0;
+
+}
More information about the lldb-commits
mailing list