2013-05-28 23:04:25 +00:00
|
|
|
"""
|
|
|
|
|
Test number of threads.
|
|
|
|
|
"""
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2013-05-28 23:04:25 +00:00
|
|
|
import lldb
|
2018-08-02 21:26:19 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
|
|
|
|
import lldbsuite.test.lldbutil as lldbutil
|
2013-05-28 23:04:25 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-28 23:04:25 +00:00
|
|
|
class ThreadExitTestCase(TestBase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
# Call super's setUp().
|
|
|
|
|
TestBase.setUp(self)
|
|
|
|
|
# Find the line numbers for our breakpoints.
|
|
|
|
|
self.break_1 = line_number('main.cpp', '// Set first breakpoint here')
|
|
|
|
|
self.break_2 = line_number('main.cpp', '// Set second breakpoint here')
|
|
|
|
|
self.break_3 = line_number('main.cpp', '// Set third breakpoint here')
|
|
|
|
|
self.break_4 = line_number('main.cpp', '// Set fourth breakpoint here')
|
|
|
|
|
|
2018-12-21 20:10:45 +00:00
|
|
|
@skipIfWindows # This is flakey on Windows: llvm.org/pr38373
|
2015-09-30 10:12:40 +00:00
|
|
|
def test(self):
|
2013-05-28 23:04:25 +00:00
|
|
|
"""Test thread exit handling."""
|
2021-12-30 11:22:26 +01:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2013-05-28 23:04:25 +00:00
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
|
|
# This should create a breakpoint with 1 location.
|
2016-01-22 23:54:41 +00:00
|
|
|
bp1_id = lldbutil.run_break_set_by_file_and_line(
|
|
|
|
|
self, "main.cpp", self.break_1, num_expected_locations=1)
|
|
|
|
|
bp2_id = lldbutil.run_break_set_by_file_and_line(
|
|
|
|
|
self, "main.cpp", self.break_2, num_expected_locations=1)
|
|
|
|
|
bp3_id = lldbutil.run_break_set_by_file_and_line(
|
|
|
|
|
self, "main.cpp", self.break_3, num_expected_locations=1)
|
|
|
|
|
bp4_id = lldbutil.run_break_set_by_file_and_line(
|
|
|
|
|
self, "main.cpp", self.break_4, num_expected_locations=1)
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# The breakpoint list should show 1 locations.
|
|
|
|
|
self.expect(
|
|
|
|
|
"breakpoint list -f",
|
|
|
|
|
"Breakpoint location shown correctly",
|
2015-05-18 16:08:06 +00:00
|
|
|
substrs=[
|
|
|
|
|
"1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
|
|
|
|
|
self.break_1,
|
|
|
|
|
"2: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
|
|
|
|
|
self.break_2,
|
|
|
|
|
"3: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
|
|
|
|
|
self.break_3,
|
|
|
|
|
"4: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
|
|
|
|
|
self.break_4])
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Run the program.
|
2015-07-01 23:56:30 +00:00
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
2013-05-28 23:04:25 +00:00
|
|
|
# Get the target process
|
|
|
|
|
target = self.dbg.GetSelectedTarget()
|
|
|
|
|
process = target.GetProcess()
|
|
|
|
|
|
2016-01-22 23:54:41 +00:00
|
|
|
stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(
|
|
|
|
|
process, bp1_id)
|
|
|
|
|
self.assertIsNotNone(stopped_thread,
|
|
|
|
|
"Process is not stopped at breakpoint 1")
|
|
|
|
|
|
2013-05-28 23:04:25 +00:00
|
|
|
# Get the number of threads
|
|
|
|
|
num_threads = process.GetNumThreads()
|
2016-01-22 23:54:41 +00:00
|
|
|
self.assertGreaterEqual(
|
|
|
|
|
num_threads,
|
|
|
|
|
2,
|
|
|
|
|
'Number of expected threads and actual threads do not match at breakpoint 1.')
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Run to the second breakpoint
|
|
|
|
|
self.runCmd("continue")
|
2016-01-22 23:54:41 +00:00
|
|
|
stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(
|
|
|
|
|
process, bp2_id)
|
|
|
|
|
self.assertIsNotNone(stopped_thread,
|
|
|
|
|
"Process is not stopped at breakpoint 2")
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Update the number of threads
|
2016-01-22 23:54:41 +00:00
|
|
|
new_num_threads = process.GetNumThreads()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
new_num_threads,
|
|
|
|
|
num_threads + 1,
|
|
|
|
|
'Number of expected threads did not increase by 1 at bp 2.')
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Run to the third breakpoint
|
|
|
|
|
self.runCmd("continue")
|
2016-01-22 23:54:41 +00:00
|
|
|
stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(
|
|
|
|
|
process, bp3_id)
|
|
|
|
|
self.assertIsNotNone(stopped_thread,
|
|
|
|
|
"Process is not stopped at breakpoint 3")
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Update the number of threads
|
2016-01-22 23:54:41 +00:00
|
|
|
new_num_threads = process.GetNumThreads()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
new_num_threads,
|
|
|
|
|
num_threads,
|
|
|
|
|
'Number of expected threads is not equal to original number of threads at bp 3.')
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Run to the fourth breakpoint
|
|
|
|
|
self.runCmd("continue")
|
2016-01-22 23:54:41 +00:00
|
|
|
stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(
|
|
|
|
|
process, bp4_id)
|
|
|
|
|
self.assertIsNotNone(stopped_thread,
|
|
|
|
|
"Process is not stopped at breakpoint 4")
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Update the number of threads
|
2016-01-22 23:54:41 +00:00
|
|
|
new_num_threads = process.GetNumThreads()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
new_num_threads,
|
|
|
|
|
num_threads - 1,
|
|
|
|
|
'Number of expected threads did not decrease by 1 at bp 4.')
|
2013-05-28 23:04:25 +00:00
|
|
|
|
|
|
|
|
# Run to completion
|
|
|
|
|
self.runCmd("continue")
|
|
|
|
|
|
|
|
|
|
# At this point, the inferior process should have exited.
|
2022-06-29 17:01:36 -07:00
|
|
|
self.assertState(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
|