]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / thread_exit / TestThreadExit.py
1 """
2 Test number of threads.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class ThreadExitTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line numbers for our breakpoints.
22         self.break_1 = line_number('main.cpp', '// Set first breakpoint here')
23         self.break_2 = line_number('main.cpp', '// Set second breakpoint here')
24         self.break_3 = line_number('main.cpp', '// Set third breakpoint here')
25         self.break_4 = line_number('main.cpp', '// Set fourth breakpoint here')
26
27     @expectedFailureWindows("llvm.org/pr24681")
28     def test(self):
29         """Test thread exit handling."""
30         self.build(dictionary=self.getBuildFlags())
31         exe = os.path.join(os.getcwd(), "a.out")
32         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
33
34         # This should create a breakpoint with 1 location.
35         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)
36         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_2, num_expected_locations=1)
37         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_3, num_expected_locations=1)
38         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_4, num_expected_locations=1)
39
40         # The breakpoint list should show 1 locations.
41         self.expect("breakpoint list -f", "Breakpoint location shown correctly",
42             substrs = ["1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.break_1,
43                        "2: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.break_2,
44                        "3: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.break_3,
45                        "4: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.break_4])
46
47         # Run the program.
48         self.runCmd("run", RUN_SUCCEEDED)
49
50         # The stop reason of the thread should be breakpoint 1.
51         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 1",
52             substrs = ['stopped',
53                        '* thread #1',
54                        'stop reason = breakpoint 1',
55                        'thread #2'])
56
57         # Get the target process
58         target = self.dbg.GetSelectedTarget()
59         process = target.GetProcess()
60
61         # Get the number of threads
62         num_threads = process.GetNumThreads()
63
64         self.assertTrue(num_threads == 2, 'Number of expected threads and actual threads do not match at breakpoint 1.')
65
66         # Run to the second breakpoint
67         self.runCmd("continue")
68
69         # The stop reason of the thread should be breakpoint 1.
70         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 2",
71             substrs = ['stopped',
72                        'thread #1',
73                        'thread #2',
74                        'stop reason = breakpoint 2',
75                        'thread #3'])
76
77         # Update the number of threads
78         num_threads = process.GetNumThreads()
79
80         self.assertTrue(num_threads == 3, 'Number of expected threads and actual threads do not match at breakpoint 2.')
81
82         # Run to the third breakpoint
83         self.runCmd("continue")
84
85         # The stop reason of the thread should be breakpoint 3.
86         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 3",
87             substrs = ['stopped',
88                        'thread #1',
89                        'stop reason = breakpoint 3',
90                        'thread #3',
91                        ])
92
93         # Update the number of threads
94         num_threads = process.GetNumThreads()
95
96         self.assertTrue(num_threads == 2, 'Number of expected threads and actual threads do not match at breakpoint 3.')
97
98         # Run to the fourth breakpoint
99         self.runCmd("continue")
100
101         # The stop reason of the thread should be breakpoint 4.
102         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 4",
103             substrs = ['stopped',
104                        'thread #1',
105                        'stop reason = breakpoint 4'])
106
107         # Update the number of threads
108         num_threads = process.GetNumThreads()
109
110         self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match at breakpoint 4.')
111
112         # Run to completion
113         self.runCmd("continue")
114
115         # At this point, the inferior process should have exited.
116         self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)