summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-01-21 21:07:30 +0000
committerZachary Turner <zturner@google.com>2016-01-21 21:07:30 +0000
commit783550be6211b65de45c4c44eac339311f3ae1e2 (patch)
tree4827f9b6759311267e2f86d95c6426f76d6b6ae6 /lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
parentbef81f3a70028699965700e6b77dcb8952abcc85 (diff)
downloadbcm5719-llvm-783550be6211b65de45c4c44eac339311f3ae1e2.tar.gz
bcm5719-llvm-783550be6211b65de45c4c44eac339311f3ae1e2.zip
Remove assumptions that thread 0 is always the main thread.
Starting with Windows 10, the Windows loader is itself multi-threaded, meaning that the loader spins up a few threads to do process initialization before it executes main. Windows delivers these notifications asynchronously and they can come out of order, so we can't be sure that the first thread we get a notification about is actually the zero'th thread. This patch fixes this by requesting the thread stopped at the breakpoint that was specified, rather than getting thread 0 and verifying that it is stopped at a breakpoint. Differential Revision: http://reviews.llvm.org/D16247 llvm-svn: 258432
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py101
1 files changed, 16 insertions, 85 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py b/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
index 4938ec50453..11912c67be4 100644
--- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
@@ -69,28 +69,17 @@ class ThreadStateTestCase(TestBase):
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# This should create a breakpoint in the main thread.
- lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)
+ bp = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = breakpoint'])
-
# Get the target process
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
- # Get the number of threads
- num_threads = process.GetNumThreads()
-
- self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.')
-
- # Get the thread object
- thread = process.GetThreadAtIndex(0)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
# Make sure the thread is in the stopped state.
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.")
@@ -117,23 +106,12 @@ class ThreadStateTestCase(TestBase):
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = breakpoint'])
-
# Get the target process
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
- # Get the number of threads
- num_threads = process.GetNumThreads()
-
- self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.')
-
- # Get the thread object
- thread = process.GetThreadAtIndex(0)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
# Continue, the inferior will go into an infinite loop waiting for 'g_test' to change.
self.dbg.SetAsync(True)
@@ -162,23 +140,12 @@ class ThreadStateTestCase(TestBase):
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = breakpoint'])
-
# Get the target process
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
- # Get the number of threads
- num_threads = process.GetNumThreads()
-
- self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.')
-
- # Get the thread object
- thread = process.GetThreadAtIndex(0)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
# Get the inferior out of its loop
self.runCmd("expression g_test = 1")
@@ -202,20 +169,12 @@ class ThreadStateTestCase(TestBase):
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = breakpoint'])
-
# Get the target process
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
- # Get the number of threads
- num_threads = process.GetNumThreads()
-
- self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.')
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
# Continue, the inferior will go into an infinite loop waiting for 'g_test' to change.
self.dbg.SetAsync(True)
@@ -228,11 +187,7 @@ class ThreadStateTestCase(TestBase):
# Stop the process
self.runCmd("process interrupt")
- # The stop reason of the thread should be signal.
- self.expect("process status", STOPPED_DUE_TO_SIGNAL,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = signal'])
+ self.assertEqual(thread.GetStopReason(), lldb.eStopReasonSignal)
# Get the inferior out of its loop
self.runCmd("expression g_test = 1")
@@ -252,23 +207,11 @@ class ThreadStateTestCase(TestBase):
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = breakpoint'])
-
# Get the target process
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
-
- # Get the number of threads
- num_threads = process.GetNumThreads()
-
- self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.')
-
- # Get the thread object
- thread = process.GetThreadAtIndex(0)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
# Make sure the thread is in the stopped state.
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.")
@@ -289,11 +232,7 @@ class ThreadStateTestCase(TestBase):
# Stop the process
self.runCmd("process interrupt")
- # The stop reason of the thread should be signal.
- self.expect("process status", STOPPED_DUE_TO_SIGNAL,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = signal'])
+ self.assertEqual(thread.GetState(), lldb.eStopReasonSignal)
# Check the thread state
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after process stop.")
@@ -306,20 +245,12 @@ class ThreadStateTestCase(TestBase):
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after expression evaluation.")
self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after expression evaluation.")
- # The stop reason of the thread should be signal.
- self.expect("process status", STOPPED_DUE_TO_SIGNAL,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = signal'])
+ self.assertEqual(thread.GetState(), lldb.eStopReasonSignal)
# Run to breakpoint 2
self.runCmd("continue")
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- '* thread #1',
- 'stop reason = breakpoint'])
+ self.assertEqual(thread.GetState(), lldb.eStopReasonBreakpoint)
# Make sure both threads are stopped
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 2.")
@@ -329,4 +260,4 @@ class ThreadStateTestCase(TestBase):
self.runCmd("continue")
# At this point, the inferior process should have exited.
- self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
+ self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
OpenPOWER on IntegriCloud