summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-10-28 17:43:26 +0000
committerZachary Turner <zturner@google.com>2015-10-28 17:43:26 +0000
commitc432c8f856e0bd84de980a9d9bb2d31b06fa95b1 (patch)
tree4efa528e074a6e2df782345e4cd97f5d85d038c4 /lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py
parenta8a3bd210086b50242903ed95048fe5e53897878 (diff)
downloadbcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.tar.gz
bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.zip
Move lldb/test to lldb/packages/Python/lldbsuite/test.
This is the conclusion of an effort to get LLDB's Python code structured into a bona-fide Python package. This has a number of benefits, but most notably the ability to more easily share Python code between different but related pieces of LLDB's Python infrastructure (for example, `scripts` can now share code with `test`). llvm-svn: 251532
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py b/lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py
new file mode 100644
index 00000000000..cb9d7fb53b6
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py
@@ -0,0 +1,63 @@
+"""Test function call thread safety."""
+
+from __future__ import print_function
+
+import use_lldb_suite
+
+import os, time
+import lldb
+import lldbutil
+from lldbtest import *
+
+class TestSafeFuncCalls(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line numbers that we will step to in main:
+ self.main_source = "main.c"
+
+ @skipUnlessDarwin
+ @add_test_categories(['pyapi'])
+ def test_with_python_api(self):
+ """Test function call thread safety."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ self.main_source_spec = lldb.SBFileSpec (self.main_source)
+ break1 = target.BreakpointCreateByName ("stopper", 'a.out')
+ self.assertTrue(break1, VALID_BREAKPOINT)
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+ threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
+ if len(threads) != 1:
+ self.fail ("Failed to stop at breakpoint 1.")
+
+ self.check_number_of_threads(process)
+
+ main_thread = lldb.SBThread()
+ select_thread = lldb.SBThread()
+ for idx in range (0, process.GetNumThreads()):
+ t = process.GetThreadAtIndex (idx)
+ if t.GetName() == "main thread":
+ main_thread = t
+ if t.GetName() == "select thread":
+ select_thread = t
+
+ self.assertTrue(main_thread.IsValid() and select_thread.IsValid(), "Got both expected threads")
+
+ self.safe_to_call_func_on_main_thread (main_thread)
+ self.safe_to_call_func_on_select_thread (select_thread)
+
+ def check_number_of_threads(self, process):
+ self.assertTrue(process.GetNumThreads() == 2, "Check that the process has two threads when sitting at the stopper() breakpoint")
+
+ def safe_to_call_func_on_main_thread (self, main_thread):
+ self.assertTrue(main_thread.SafeToCallFunctions() == True, "It is safe to call functions on the main thread")
+
+ def safe_to_call_func_on_select_thread (self, select_thread):
+ self.assertTrue(select_thread.SafeToCallFunctions() == False, "It is not safe to call functions on the select thread")
OpenPOWER on IntegriCloud