[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / commands / thread / backtrace / TestThreadBacktraceRepeat.py
blob9678bd42999b31ffd018c936c535a105e0b93bec
1 """
2 Test that we page getting a long backtrace on more than one thread
3 """
6 import lldb
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class TestThreadBacktracePage(TestBase):
13 NO_DEBUG_INFO_TESTCASE = True
15 def test_thread_backtrace_one_thread(self):
16 """Run a simplified version of the test that just hits one breakpoint and
17 doesn't care about synchronizing the two threads - hopefully this will
18 run on more systems."""
20 def test_thread_backtrace_one_thread(self):
21 self.build()
23 self.inferior_target,
24 self.process,
25 thread,
26 bkpt,
27 ) = lldbutil.run_to_source_breakpoint(
28 self, self.bkpt_string, lldb.SBFileSpec("main.cpp"), only_one_thread=False
31 # We hit the breakpoint on at least one thread. If we hit it on both threads
32 # simultaneously, we are ready to run our tests. Otherwise, suspend the thread
33 # that hit the breakpoint, and continue till the second thread hits
34 # the breakpoint:
36 (breakpoint_threads, other_threads) = ([], [])
37 lldbutil.sort_stopped_threads(
38 self.process,
39 breakpoint_threads=breakpoint_threads,
40 other_threads=other_threads,
42 self.assertGreater(
43 len(breakpoint_threads), 0, "We hit at least one breakpoint thread"
45 self.assertGreater(len(breakpoint_threads[0].frames), 2, "I can go up")
46 thread_id = breakpoint_threads[0].idx
47 name = breakpoint_threads[0].frame[1].name.split("(")[0]
48 self.check_one_thread(thread_id, name)
50 def setUp(self):
51 # Call super's setUp().
52 TestBase.setUp(self)
53 # Find the line number for our breakpoint.
54 self.bkpt_string = "// Set breakpoint here"
56 def check_one_thread(self, thread_id, func_name):
57 # Now issue some thread backtrace commands and make sure they
58 # get the right answer back.
59 interp = self.dbg.GetCommandInterpreter()
60 result = lldb.SBCommandReturnObject()
62 # Run the real backtrace, remember to pass True for add_to_history since
63 # we don't generate repeat commands for commands that aren't going into the history.
64 interp.HandleCommand(
65 "thread backtrace --count 10 {0}".format(thread_id), result, True
67 self.assertTrue(result.Succeeded(), "bt with count succeeded")
68 # There should be 11 lines:
69 lines = result.GetOutput().splitlines()
70 self.assertEqual(len(lines), 11, "Got the right number of lines")
71 # First frame is stop_here:
72 self.assertNotEqual(lines[1].find("stop_here"), -1, "Found Stop Here")
73 for line in lines[2:10]:
74 self.assertNotEqual(
75 line.find(func_name),
76 -1,
77 "Name {0} not found in line: {1}".format(func_name, line),
79 # The last entry should be 43:
80 self.assertNotEqual(lines[10].find("count=43"), -1, "First show ends at 43")
82 # Now try a repeat, and make sure we get 10 more on this thread:
83 # import pdb; pdb.set_trace()
84 interp.HandleCommand("", result, True)
85 self.assertTrue(
86 result.Succeeded(), "repeat command failed: {0}".format(result.GetError())
88 lines = result.GetOutput().splitlines()
89 self.assertEqual(len(lines), 11, "Repeat got 11 lines")
90 # Every line should now be the recurse function:
91 for line in lines[1:10]:
92 self.assertNotEqual(line.find(func_name), -1, "Name in every line")
93 self.assertNotEqual(lines[10].find("count=33"), -1, "Last one is now 33")
95 def check_two_threads(
96 self, result_str, thread_id_1, name_1, thread_id_2, name_2, start_idx, end_idx
98 # We should have 2 occurrences ot the thread header:
99 self.assertEqual(
100 result_str.count("thread #{0}".format(thread_id_1)), 1, "One for thread 1"
102 self.assertEqual(
103 result_str.count("thread #{0}".format(thread_id_2)), 1, "One for thread 2"
105 # We should have 10 occurrences of each name:
106 self.assertEqual(result_str.count(name_1), 10, "Found 10 of {0}".format(name_1))
107 self.assertEqual(result_str.count(name_2), 10, "Found 10 of {0}".format(name_1))
108 # There should be two instances of count=<start_idx> and none of count=<start-1>:
109 self.assertEqual(
110 result_str.count("count={0}".format(start_idx)),
112 "Two instances of start_idx",
114 self.assertEqual(
115 result_str.count("count={0}".format(start_idx - 1)),
117 "No instances of start_idx - 1",
119 # There should be two instances of count=<end_idx> and none of count=<end_idx+1>:
120 self.assertEqual(
121 result_str.count("count={0}".format(end_idx)), 2, "Two instances of end_idx"
123 self.assertEqual(
124 result_str.count("count={0}".format(end_idx + 1)),
126 "No instances after end idx",
129 # The setup of this test was copied from the step-out test, and I can't tell from
130 # the comments whether it was getting two threads to the same breakpoint that was
131 # problematic, or the step-out part. This test stops at the rendevous point so I'm
132 # removing the skipIfLinux to see if we see any flakiness in just this part of the test.
133 @skipIfWindows # This test will hang on windows llvm.org/pr21753
134 @expectedFailureAll(oslist=["windows"])
135 @expectedFailureNetBSD
136 def test_thread_backtrace_two_threads(self):
137 """Test that repeat works even when backtracing on more than one thread."""
138 self.build()
140 self.inferior_target,
141 self.process,
142 thread,
143 bkpt,
144 ) = lldbutil.run_to_source_breakpoint(
145 self, self.bkpt_string, lldb.SBFileSpec("main.cpp"), only_one_thread=False
148 # We hit the breakpoint on at least one thread. If we hit it on both threads
149 # simultaneously, we are ready to run our tests. Otherwise, suspend the thread
150 # that hit the breakpoint, and continue till the second thread hits
151 # the breakpoint:
153 (breakpoint_threads, other_threads) = ([], [])
154 lldbutil.sort_stopped_threads(
155 self.process,
156 breakpoint_threads=breakpoint_threads,
157 other_threads=other_threads,
159 if len(breakpoint_threads) == 1:
160 success = thread.Suspend()
161 self.assertTrue(success, "Couldn't suspend a thread")
162 breakpoint_threads = lldbutil.continue_to_breakpoint(self.process, bkpt)
163 self.assertEqual(len(breakpoint_threads), 2, "Second thread stopped")
165 # Figure out which thread is which:
166 thread_id_1 = breakpoint_threads[0].idx
167 self.assertGreater(len(breakpoint_threads[0].frames), 2, "I can go up")
168 name_1 = breakpoint_threads[0].frame[1].name.split("(")[0]
170 thread_id_2 = breakpoint_threads[1].idx
171 self.assertGreater(len(breakpoint_threads[1].frames), 2, "I can go up")
172 name_2 = breakpoint_threads[1].frame[1].name.split("(")[0]
174 # Check that backtrace and repeat works on one thread, then works on the second
175 # when we switch to it:
176 self.check_one_thread(thread_id_1, name_1)
177 self.check_one_thread(thread_id_2, name_2)
179 # The output is looking right at this point, let's just do a couple more quick checks
180 # to see we handle two threads and a start count:
181 interp = self.dbg.GetCommandInterpreter()
182 result = lldb.SBCommandReturnObject()
184 interp.HandleCommand(
185 "thread backtrace --count 10 --start 10 {0} {1}".format(
186 thread_id_1, thread_id_2
188 result,
189 True,
191 self.assertTrue(result.Succeeded(), "command succeeded for two threads")
193 result.Clear()
194 interp.HandleCommand("", result, True)
195 self.assertTrue(result.Succeeded(), "repeat command succeeded for two threads")
196 result_str = result.GetOutput()
197 self.check_two_threads(
198 result_str, thread_id_1, name_1, thread_id_2, name_2, 23, 32
201 # Finally make sure the repeat repeats:
202 result.Clear()
203 interp.HandleCommand("", result, True)
204 self.assertTrue(result.Succeeded(), "repeat command succeeded for two threads")
205 result_str = result.GetOutput()
206 self.check_two_threads(
207 result_str, thread_id_1, name_1, thread_id_2, name_2, 13, 22