1 """ 2 Test number of threads. 3 """ 4 5 import os, time 6 import unittest2 7 import lldb 8 from lldbtest import * 9 import lldbutil 10 11 class NumberOfThreadsTestCase(TestBase): 12 13 mydir = os.path.join("functionalities", "thread") 14 15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 16 @dsym_test 17 def test_with_dsym(self): 18 """Test number of threads.""" 19 self.buildDsym() 20 self.number_of_threads_test() 21 22 @expectedFailureFreeBSD("llvm.org/pr16696") # threaded inferior not yet implemented on FreeBSD 23 @dwarf_test 24 def test_with_dwarf(self): 25 """Test number of threads.""" 26 self.buildDwarf() 27 self.number_of_threads_test() 28 29 def setUp(self): 30 # Call super's setUp(). 31 TestBase.setUp(self) 32 # Find the line number to break inside main(). 33 self.line = line_number('main.c', '// Set break point at this line.') 34 35 def number_of_threads_test(self): 36 """Test number of threads.""" 37 exe = os.path.join(os.getcwd(), "a.out") 38 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 39 40 # This should create a breakpoint with 1 location. 41 lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1) 42 43 # The breakpoint list should show 3 locations. 44 self.expect("breakpoint list -f", "Breakpoint location shown correctly", 45 substrs = ["1: file = 'main.c', line = %d, locations = 1" % self.line]) 46 47 # Run the program. 48 self.runCmd("run", RUN_SUCCEEDED) 49 50 # Stopped once. 51 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 52 substrs = ["stop reason = breakpoint 1."]) 53 54 # Get the target process 55 target = self.dbg.GetSelectedTarget() 56 process = target.GetProcess() 57 58 # Get the number of threads 59 num_threads = process.GetNumThreads() 60 61 self.assertTrue(num_threads == 4, 'Number of expected threads and actual threads do not match.') 62 63 if __name__ == '__main__': 64 import atexit 65 lldb.SBDebugger.Initialize() 66 atexit.register(lambda: lldb.SBDebugger.Terminate()) 67 unittest2.main() 68