blob: da6430ad4ff76a1e281c66f52ea4b8bedc287e44 [file] [log] [blame]
Andrew Kaylor3bd2ebd2013-05-28 23:04:25 +00001"""
2Test number of threads.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class ExitDuringBreakpointTestCase(TestBase):
12
13 mydir = os.path.join("functionalities", "thread", "exit_during_break")
14
15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16 @expectedFailureDarwin("llvm.org/pr15824") # thread states not properly maintained
17 @dsym_test
18 def test_with_dsym(self):
19 """Test thread exit during breakpoint handling."""
20 self.buildDsym(dictionary=self.getBuildFlags())
21 self.exit_during_breakpoint_test()
22
23 @expectedFailureDarwin("llvm.org/pr15824") # thread states not properly maintained
Ed Maste4fd912f2013-07-25 17:17:15 +000024 @expectedFailureFreeBSD("llvm.org/pr16696") # threaded inferior not yet implemented on FreeBSD
Andrew Kaylor3bd2ebd2013-05-28 23:04:25 +000025 @dwarf_test
26 def test_with_dwarf(self):
27 """Test thread exit during breakpoint handling."""
28 self.buildDwarf(dictionary=self.getBuildFlags())
29 self.exit_during_breakpoint_test()
30
31 def setUp(self):
32 # Call super's setUp().
33 TestBase.setUp(self)
34 # Find the line number for our breakpoint.
35 self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
36
37 def exit_during_breakpoint_test(self):
38 """Test thread exit during breakpoint handling."""
39 exe = os.path.join(os.getcwd(), "a.out")
40 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
41
42 # This should create a breakpoint in the main thread.
43 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.breakpoint, num_expected_locations=1)
44
45 # The breakpoint list should show 1 location.
46 self.expect("breakpoint list -f", "Breakpoint location shown correctly",
Matt Kopec025bcc02013-06-17 19:00:31 +000047 substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.breakpoint])
Andrew Kaylor3bd2ebd2013-05-28 23:04:25 +000048
49 # Run the program.
50 self.runCmd("run", RUN_SUCCEEDED)
51
52 # The stop reason of the thread should be breakpoint.
53 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
54 substrs = ['stopped',
55 'stop reason = breakpoint'])
56
57 # Get the target process
58 target = self.dbg.GetSelectedTarget()
59 process = target.GetProcess()
60
61 # The exit probably occured during breakpoint handling, but it isn't
62 # guaranteed. The main thing we're testing here is that the debugger
63 # handles this cleanly is some way.
64
65 # Get the number of threads
66 num_threads = process.GetNumThreads()
67
68 # Make sure we see at least five threads
69 self.assertTrue(num_threads >= 5, 'Number of expected threads and actual threads do not match.')
70
71 # Get the thread objects
72 thread1 = process.GetThreadAtIndex(0)
73 thread2 = process.GetThreadAtIndex(1)
74 thread3 = process.GetThreadAtIndex(2)
75 thread4 = process.GetThreadAtIndex(3)
76 thread5 = process.GetThreadAtIndex(4)
77
78 # Make sure all threads are stopped
79 self.assertTrue(thread1.IsStopped(), "Thread 1 didn't stop during breakpoint")
80 self.assertTrue(thread2.IsStopped(), "Thread 2 didn't stop during breakpoint")
81 self.assertTrue(thread3.IsStopped(), "Thread 3 didn't stop during breakpoint")
82 self.assertTrue(thread4.IsStopped(), "Thread 4 didn't stop during breakpoint")
83 self.assertTrue(thread5.IsStopped(), "Thread 5 didn't stop during breakpoint")
84
85 # Run to completion
86 self.runCmd("continue")
87
88 # At this point, the inferior process should have exited.
89 self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
90
91if __name__ == '__main__':
92 import atexit
93 lldb.SBDebugger.Initialize()
94 atexit.register(lambda: lldb.SBDebugger.Terminate())
95 unittest2.main()