[Lldb-commits] [lldb] r180828 - Refactoring thread state tests to show individual failures
Andrew Kaylor
andrew.kaylor at intel.com
Tue Apr 30 16:39:15 PDT 2013
Author: akaylor
Date: Tue Apr 30 18:39:14 2013
New Revision: 180828
URL: http://llvm.org/viewvc/llvm-project?rev=180828&view=rev
Log:
Refactoring thread state tests to show individual failures
Modified:
lldb/trunk/test/functionalities/thread/state/TestThreadStates.py
lldb/trunk/test/functionalities/thread/state/main.c
Modified: lldb/trunk/test/functionalities/thread/state/TestThreadStates.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/state/TestThreadStates.py?rev=180828&r1=180827&r2=180828&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/state/TestThreadStates.py (original)
+++ lldb/trunk/test/functionalities/thread/state/TestThreadStates.py Tue Apr 30 18:39:14 2013
@@ -15,15 +15,71 @@ class StopThreadsTestCase(TestBase):
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
@unittest2.expectedFailure("PR-15824") # thread states not properly maintained
- def test_with_dsym(self):
- """Test thread states."""
+ def test_state_after_breakpoint_with_dsym(self):
+ """Test thread state after breakpoint."""
+ self.buildDsym()
+ self.thread_state_after_breakpoint_test()
+
+ @dwarf_test
+ @unittest2.expectedFailure("PR-15824") # thread states not properly maintained
+ def test_state_after_breakpoint_with_dwarf(self):
+ """Test thread state after breakpoint."""
+ self.buildDwarf()
+ self.thread_state_after_breakpoint_test()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ def test_state_after_continue_with_dsym(self):
+ """Test thread state after continue."""
+ self.buildDsym()
+ self.thread_state_after_continue_test()
+
+ @dwarf_test
+ def test_state_after_continue_with_dwarf(self):
+ """Test thread state after continue."""
+ self.buildDwarf()
+ self.thread_state_after_continue_test()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ def test_state_after_expression_with_dsym(self):
+ """Test thread state after expression."""
+ self.buildDsym()
+ self.thread_state_after_continue_test()
+
+ @dwarf_test
+ def test_state_after_expression_with_dwarf(self):
+ """Test thread state after expression."""
+ self.buildDwarf()
+ self.thread_state_after_continue_test()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ @unittest2.expectedFailure("PR-15824") # thread states not properly maintained
+ def test_process_interrupt_with_dsym(self):
+ """Test process interrupt."""
+ self.buildDsym()
+ self.process_interrupt_test()
+
+ @dwarf_test
+ @unittest2.expectedFailure("PR-15824") # thread states not properly maintained
+ def test_process_interrupt_with_dwarf(self):
+ """Test process interrupt."""
+ self.buildDwarf()
+ self.process_interrupt_test()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ @unittest2.expectedFailure("PR-15824") # thread states not properly maintained
+ def test_process_state_with_dsym(self):
+ """Test thread states (comprehensive)."""
self.buildDsym()
self.thread_states_test()
@dwarf_test
@unittest2.expectedFailure("PR-15824") # thread states not properly maintained
- def test_with_dwarf(self):
- """Test thread states."""
+ def test_process_state_with_dwarf(self):
+ """Test thread states (comprehensive)."""
self.buildDwarf()
self.thread_states_test()
@@ -34,8 +90,195 @@ class StopThreadsTestCase(TestBase):
self.break_1 = line_number('main.c', '// Set first breakpoint here')
self.break_2 = line_number('main.c', '// Set second breakpoint here')
+ def thread_state_after_breakpoint_test(self):
+ """Test thread state after breakpoint."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ 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.c", self.break_1, num_expected_locations=1)
+
+ # The breakpoint list should show 1 breakpoint with 1 location.
+ self.expect("breakpoint list -f", "Breakpoint location shown correctly",
+ substrs = ["1: file ='main.c', line = %d, locations = 1" % self.break_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)
+
+ # Make sure the thread is in the stopped state.
+ self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.")
+ self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' during breakpoint 1.")
+
+ # Kill the process
+ self.runCmd("process kill")
+
+ def thread_state_after_continue_test(self):
+ """Test thread state after continue."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ 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.c", self.break_1, num_expected_locations=1)
+ lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_2, num_expected_locations=1)
+
+ # The breakpoint list should show 1 breakpoints with 1 location.
+ self.expect("breakpoint list -f", "Breakpoint location shown correctly",
+ substrs = ["1: file ='main.c', line = %d, locations = 1" % self.break_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)
+
+ # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change.
+ self.dbg.SetAsync(True)
+ self.runCmd("continue")
+ time.sleep(1)
+
+ # Check the thread state. It should be running.
+ self.assertFalse(thread.IsStopped(), "Thread state is \'stopped\' when it should be running.")
+ self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' when it should be running.")
+
+ # Go back to synchronous interactions
+ self.dbg.SetAsync(False)
+
+ # Kill the process
+ self.runCmd("process kill")
+
+ def thread_state_after_expression_test(self):
+ """Test thread state after expression."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ 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.c", self.break_1, num_expected_locations=1)
+ lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_2, num_expected_locations=1)
+
+ # The breakpoint list should show 1 breakpoints with 1 location.
+ self.expect("breakpoint list -f", "Breakpoint location shown correctly",
+ substrs = ["1: file ='main.c', line = %d, locations = 1" % self.break_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)
+
+ # Get the inferior out of its loop
+ self.runCmd("expression g_test = 1")
+
+ # Check the thread state
+ self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after expression evaluation.")
+ self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after expression evaluation.")
+
+ # Let the process run to completion
+ self.runCmd("process continue")
+
+
+ def process_interrupt_test(self):
+ """Test process interrupt and continue."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ 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.c", self.break_1, num_expected_locations=1)
+
+ # The breakpoint list should show 1 breakpoints with 1 location.
+ self.expect("breakpoint list -f", "Breakpoint location shown correctly",
+ substrs = ["1: file ='main.c', line = %d, locations = 1" % self.break_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.')
+
+ # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change.
+ self.dbg.SetAsync(True)
+ self.runCmd("continue")
+ time.sleep(1)
+
+ # Go back to synchronous interactions
+ self.dbg.SetAsync(False)
+
+ # 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'])
+
+ # Get the inferior out of its loop
+ self.runCmd("expression g_test = 1")
+
+ # Run to completion
+ self.runCmd("continue")
+
def thread_states_test(self):
- """Test thread states."""
+ """Test thread states (comprehensive)."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
@@ -94,7 +337,6 @@ class StopThreadsTestCase(TestBase):
'* thread #1',
'stop reason = signal'])
-
# Check the thread state
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after process stop.")
self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after process stop.")
@@ -106,9 +348,21 @@ class StopThreadsTestCase(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'])
+
# 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'])
+
# Make sure both threads are stopped
self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 2.")
self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' during breakpoint 2.")
Modified: lldb/trunk/test/functionalities/thread/state/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/state/main.c?rev=180828&r1=180827&r2=180828&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/state/main.c (original)
+++ lldb/trunk/test/functionalities/thread/state/main.c Tue Apr 30 18:39:14 2013
@@ -25,8 +25,11 @@ int doNothing()
{
int temp = 0; // Set first breakpoint here
- while (!g_test)
- ++temp;
+ while (!g_test && temp < 5)
+ {
+ ++temp;
+ sleep(1);
+ }
return temp; // Set second breakpoint here
}
More information about the lldb-commits
mailing list