Skip to content

Commit

Permalink
Make TestThreadStates more stable
Browse files Browse the repository at this point in the history
Summary:
Because of the large number of XFAILs TestThreadStates has decayed quite a bit. This commit does
the following:
- removes the "breakpoint list" expectations. Most tests have been failing on this, because the
  command output changed quite a while back. I remove it, because run_break_set_by_file_and_line
  already does a decent amount of checking
- fixup test_state_after_expression: this was calling the wrong function by mistake. As now the
  function actually tests something (which we know is broken), I needed to XFAIL it as well.
- replaces the sleep() with a proper wait-for-event functionality in parts which use async mode,
  to stabilize the one function that actually tests something.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D15233

llvm-svn: 254901
  • Loading branch information
labath committed Dec 7, 2015
1 parent d5a1f47 commit cb8ea4b
Showing 1 changed file with 11 additions and 25 deletions.
Expand Up @@ -36,10 +36,11 @@ def test_state_after_continue(self):
@skipIfDarwin # 'llvm.org/pr23669', cause Python crash randomly
@expectedFailureDarwin('llvm.org/pr23669')
@expectedFailureWindows("llvm.org/pr24660")
@unittest2.expectedFailure("llvm.org/pr16712") # thread states not properly maintained
def test_state_after_expression(self):
"""Test thread state after expression."""
self.build(dictionary=self.getBuildFlags(use_cpp11=False))
self.thread_state_after_continue_test()
self.thread_state_after_expression_test()

@unittest2.expectedFailure("llvm.org/pr16712") # thread states not properly maintained
@expectedFailureWindows("llvm.org/pr24668") # Breakpoints not resolved correctly
Expand Down Expand Up @@ -70,10 +71,6 @@ def thread_state_after_breakpoint_test(self):
# 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)

# The breakpoint list should show 1 breakpoint with 1 location.
self.expect("breakpoint list -f", "Breakpoint location shown correctly",
substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.break_1])

# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

Expand Down Expand Up @@ -102,6 +99,12 @@ def thread_state_after_breakpoint_test(self):
# Kill the process
self.runCmd("process kill")

def wait_for_running_event(self):
listener = self.dbg.GetListener()
if lldb.remote_platform:
lldbutil.expect_state_changes(self, listener, [lldb.eStateConnected])
lldbutil.expect_state_changes(self, listener, [lldb.eStateRunning])

def thread_state_after_continue_test(self):
"""Test thread state after continue."""
exe = os.path.join(os.getcwd(), "a.out")
Expand All @@ -111,10 +114,6 @@ def thread_state_after_continue_test(self):
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", 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.cpp', line = %d, exact_match = 0, locations = 1" % self.break_1])

# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

Expand All @@ -139,7 +138,7 @@ def thread_state_after_continue_test(self):
# 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)
self.wait_for_running_event()

# Check the thread state. It should be running.
self.assertFalse(thread.IsStopped(), "Thread state is \'stopped\' when it should be running.")
Expand All @@ -160,10 +159,6 @@ def thread_state_after_expression_test(self):
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", 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.cpp', line = %d, locations = 1" % self.break_1])

# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

Expand Down Expand Up @@ -204,10 +199,6 @@ def process_interrupt_test(self):
# 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)

# The breakpoint list should show 1 breakpoints with 1 location.
self.expect("breakpoint list -f", "Breakpoint location shown correctly",
substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.break_1])

# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

Expand All @@ -229,7 +220,7 @@ def process_interrupt_test(self):
# 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)
self.wait_for_running_event()

# Go back to synchronous interactions
self.dbg.SetAsync(False)
Expand Down Expand Up @@ -258,11 +249,6 @@ def thread_states_test(self):
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_2, num_expected_locations=1)

# The breakpoint list should show 2 breakpoints with 1 location each.
self.expect("breakpoint list -f", "Breakpoint location shown correctly",
substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.break_1,
"2: file = 'main.cpp', line = %d, locations = 1" % self.break_2])

# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

Expand Down Expand Up @@ -291,7 +277,7 @@ def thread_states_test(self):
# 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)
self.wait_for_running_event()

# Check the thread state. It should be running.
self.assertFalse(thread.IsStopped(), "Thread state is \'stopped\' when it should be running.")
Expand Down

0 comments on commit cb8ea4b

Please sign in to comment.