1 """Test function call thread safety."""
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 from lldbsuite
.test
import lldbutil
10 class TestSafeFuncCalls(TestBase
):
12 @add_test_categories(["pyapi"])
13 def test_with_python_api(self
):
14 """Test function call thread safety."""
16 exe
= self
.getBuildArtifact("a.out")
18 target
= self
.dbg
.CreateTarget(exe
)
19 self
.assertTrue(target
, VALID_TARGET
)
20 self
.main_source_spec
= lldb
.SBFileSpec("main.c")
21 break1
= target
.BreakpointCreateByName("stopper", "a.out")
22 self
.assertTrue(break1
, VALID_BREAKPOINT
)
23 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
24 self
.assertTrue(process
, PROCESS_IS_VALID
)
25 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, break1
)
26 self
.assertEqual(len(threads
), 1, "Failed to stop at breakpoint 1.")
29 process
.GetNumThreads(),
31 "Check that the process has two threads when sitting at the stopper() breakpoint",
34 main_thread
= lldb
.SBThread()
35 select_thread
= lldb
.SBThread()
36 for idx
in range(0, process
.GetNumThreads()):
37 t
= process
.GetThreadAtIndex(idx
)
38 if t
.GetName() == "main thread":
40 if t
.GetName() == "select thread":
44 main_thread
.IsValid() and select_thread
.IsValid(),
45 "Got both expected threads",
49 main_thread
.SafeToCallFunctions(),
50 "It is safe to call functions on the main thread",
53 select_thread
.SafeToCallFunctions(),
55 "It is not safe to call functions on the select thread",