20645fbc63e7594d85d9c8ebc3c7d88b42c63675
[openbsd] /
1 """
2 Test number of threads.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class MultipleBreakpointTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def setUp(self):
18         # Call super's setUp().
19         TestBase.setUp(self)
20         # Find the line number for our breakpoint.
21         self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
22
23     @expectedFailureAll(
24         oslist=["linux"],
25         bugnumber="llvm.org/pr15824 thread states not properly maintained")
26     @expectedFailureAll(
27         oslist=lldbplatformutil.getDarwinOSTriples(),
28         bugnumber="llvm.org/pr15824 thread states not properly maintained and <rdar://problem/28557237>")
29     @expectedFailureAll(
30         oslist=["freebsd"],
31         bugnumber="llvm.org/pr18190 thread states not properly maintained")
32     @skipIfWindows # This is flakey on Windows: llvm.org/pr24668, llvm.org/pr38373
33     @expectedFailureNetBSD
34     def test(self):
35         """Test simultaneous breakpoints in multiple threads."""
36         self.build(dictionary=self.getBuildFlags())
37         exe = self.getBuildArtifact("a.out")
38         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
39
40         # This should create a breakpoint in the main thread.
41         lldbutil.run_break_set_by_file_and_line(
42             self, "main.cpp", self.breakpoint, num_expected_locations=1)
43
44         # Run the program.
45         self.runCmd("run", RUN_SUCCEEDED)
46
47         # The stop reason of the thread should be breakpoint.
48         # The breakpoint may be hit in either thread 2 or thread 3.
49         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
50                     substrs=['stopped',
51                              'stop reason = breakpoint'])
52
53         # Get the target process
54         target = self.dbg.GetSelectedTarget()
55         process = target.GetProcess()
56
57         # Get the number of threads
58         num_threads = process.GetNumThreads()
59
60         # Make sure we see all three threads
61         self.assertTrue(
62             num_threads >= 3,
63             'Number of expected threads and actual threads do not match.')
64
65         # Get the thread objects
66         thread1 = process.GetThreadAtIndex(0)
67         thread2 = process.GetThreadAtIndex(1)
68         thread3 = process.GetThreadAtIndex(2)
69
70         # Make sure both threads are stopped
71         self.assertTrue(
72             thread1.IsStopped(),
73             "Primary thread didn't stop during breakpoint")
74         self.assertTrue(
75             thread2.IsStopped(),
76             "Secondary thread didn't stop during breakpoint")
77         self.assertTrue(
78             thread3.IsStopped(),
79             "Tertiary thread didn't stop during breakpoint")
80
81         # Delete the first breakpoint then continue
82         self.runCmd("breakpoint delete 1")
83
84         # Run to completion
85         self.runCmd("continue")
86
87         # At this point, the inferior process should have exited.
88         self.assertTrue(
89             process.GetState() == lldb.eStateExited,
90             PROCESS_EXITED)