<div dir="ltr">Yea, that's a good idea. Thanks for the suggestion</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jan 22, 2016 at 4:05 PM Jim Ingham <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Would you mind adding a comment telling people how to do this correctly to the "Writing test cases" section of the README-testsuite?<br>
<br>
Jim<br>
<br>
> On Jan 22, 2016, at 3:54 PM, Zachary Turner via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: zturner<br>
> Date: Fri Jan 22 17:54:41 2016<br>
> New Revision: 258586<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=258586&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=258586&view=rev</a><br>
> Log:<br>
> More fixes related to counting threads on Windows.<br>
><br>
> The Windows 10 loader spawns threads at startup, so<br>
> tests which count threads or assume that a given user<br>
> thread will be at a specific index are incorrect in<br>
> this case. The fix here is to use the standard mechanisms<br>
> for getting the stopped thread (which is all we are<br>
> really interested in anyway) and correlating them with<br>
> the breakpoints that were set, and doing checks against<br>
> those things.<br>
><br>
> This fixes about 6 tests on Windows 10.<br>
><br>
> Modified:<br>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py<br>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py<br>
> lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py<br>
><br>
> Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py?rev=258586&r1=258585&r2=258586&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py?rev=258586&r1=258585&r2=258586&view=diff</a><br>
> ==============================================================================<br>
> --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py (original)<br>
> +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py Fri Jan 22 17:54:41 2016<br>
> @@ -18,14 +18,12 @@ class ExitDuringStepTestCase(TestBase):<br>
> @expectedFailureDarwin("<a href="http://llvm.org/pr15824" rel="noreferrer" target="_blank">llvm.org/pr15824</a>") # thread states not properly maintained<br>
> @expectedFailureFreeBSD("<a href="http://llvm.org/pr18190" rel="noreferrer" target="_blank">llvm.org/pr18190</a>") # thread states not properly maintained<br>
> @expectedFailureLinux("<a href="http://llvm.org/pr15824" rel="noreferrer" target="_blank">llvm.org/pr15824</a>") # thread states not properly maintained<br>
> - @expectedFailureWindows("<a href="http://llvm.org/pr24681" rel="noreferrer" target="_blank">llvm.org/pr24681</a>")<br>
> def test_thread_state_is_stopped(self):<br>
> """Test thread exit during step handling."""<br>
> self.build(dictionary=self.getBuildFlags())<br>
> self.exit_during_step_base("thread step-in -m all-threads", 'stop reason = step in', True)<br>
><br>
> @skipIfFreeBSD # <a href="http://llvm.org/pr21411" rel="noreferrer" target="_blank">llvm.org/pr21411</a>: test is hanging<br>
> - @expectedFailureWindows("<a href="http://llvm.org/pr24681" rel="noreferrer" target="_blank">llvm.org/pr24681</a>")<br>
> @expectedFlakeyAndroid("<a href="http://llvm.org/pr26206" rel="noreferrer" target="_blank">llvm.org/pr26206</a>")<br>
> def test(self):<br>
> """Test thread exit during step handling."""<br>
> @@ -33,7 +31,6 @@ class ExitDuringStepTestCase(TestBase):<br>
> self.exit_during_step_base("thread step-inst -m all-threads", 'stop reason = instruction step', False)<br>
><br>
> @skipIfFreeBSD # <a href="http://llvm.org/pr21411" rel="noreferrer" target="_blank">llvm.org/pr21411</a>: test is hanging<br>
> - @expectedFailureWindows("<a href="http://llvm.org/pr24681" rel="noreferrer" target="_blank">llvm.org/pr24681</a>")<br>
> @expectedFlakeyAndroid("<a href="http://llvm.org/pr26206" rel="noreferrer" target="_blank">llvm.org/pr26206</a>")<br>
> def test_step_over(self):<br>
> """Test thread exit during step-over handling."""<br>
> @@ -41,7 +38,6 @@ class ExitDuringStepTestCase(TestBase):<br>
> self.exit_during_step_base("thread step-over -m all-threads", 'stop reason = step over', False)<br>
><br>
> @skipIfFreeBSD # <a href="http://llvm.org/pr21411" rel="noreferrer" target="_blank">llvm.org/pr21411</a>: test is hanging<br>
> - @expectedFailureWindows("<a href="http://llvm.org/pr24681" rel="noreferrer" target="_blank">llvm.org/pr24681</a>")<br>
> @expectedFlakeyAndroid("<a href="http://llvm.org/pr26206" rel="noreferrer" target="_blank">llvm.org/pr26206</a>")<br>
> def test_step_in(self):<br>
> """Test thread exit during step-in handling."""<br>
> @@ -79,37 +75,16 @@ class ExitDuringStepTestCase(TestBase):<br>
> target = self.dbg.GetSelectedTarget()<br>
> process = target.GetProcess()<br>
><br>
> - # Get the number of threads<br>
> num_threads = process.GetNumThreads()<br>
> -<br>
> # Make sure we see all three threads<br>
> - self.assertTrue(num_threads == 3, 'Number of expected threads and actual threads do not match.')<br>
> + self.assertGreaterEqual(num_threads, 3, 'Number of expected threads and actual threads do not match.')<br>
><br>
> - # Get the thread objects<br>
> - thread1 = process.GetThreadAtIndex(0)<br>
> - thread2 = process.GetThreadAtIndex(1)<br>
> - thread3 = process.GetThreadAtIndex(2)<br>
> -<br>
> - # Make sure all threads are stopped<br>
> - if test_thread_state:<br>
> - self.assertTrue(thread1.IsStopped(), "Thread 1 didn't stop during breakpoint")<br>
> - self.assertTrue(thread2.IsStopped(), "Thread 2 didn't stop during breakpoint")<br>
> - self.assertTrue(thread3.IsStopped(), "Thread 3 didn't stop during breakpoint")<br>
> - return<br>
> -<br>
> - # Find the thread that is stopped at the breakpoint<br>
> - stepping_thread = None<br>
> - for thread in process:<br>
> - expected_bp_desc = "breakpoint %s." % self.bp_num<br>
> - stop_desc = thread.GetStopDescription(100)<br>
> - if stop_desc and (expected_bp_desc in stop_desc):<br>
> - stepping_thread = thread<br>
> - break<br>
> - self.assertTrue(stepping_thread != None, "unable to find thread stopped at %s" % expected_bp_desc)<br>
> + stepping_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(process, self.bp_num)<br>
> + self.assertIsNotNone(stepping_thread, "Could not find a thread stopped at the breakpoint")<br>
><br>
> current_line = self.breakpoint<br>
> stepping_frame = stepping_thread.GetFrameAtIndex(0)<br>
> - self.assertTrue(current_line == stepping_frame.GetLineEntry().GetLine(), "Starting line for stepping doesn't match breakpoint line.")<br>
> + self.assertEqual(current_line, stepping_frame.GetLineEntry().GetLine(), "Starting line for stepping doesn't match breakpoint line.")<br>
><br>
> # Keep stepping until we've reached our designated continue point<br>
> while current_line != self.continuepoint:<br>
> @@ -125,16 +100,16 @@ class ExitDuringStepTestCase(TestBase):<br>
><br>
> current_line = frame.GetLineEntry().GetLine()<br>
><br>
> - self.assertTrue(current_line >= self.breakpoint, "Stepped to unexpected line, " + str(current_line))<br>
> - self.assertTrue(current_line <= self.continuepoint, "Stepped to unexpected line, " + str(current_line))<br>
> + self.assertGreaterEqual(current_line, self.breakpoint, "Stepped to unexpected line, " + str(current_line))<br>
> + self.assertLessEqual(current_line, self.continuepoint, "Stepped to unexpected line, " + str(current_line))<br>
><br>
> self.runCmd("thread list")<br>
><br>
> # Update the number of threads<br>
> - num_threads = process.GetNumThreads()<br>
> + new_num_threads = process.GetNumThreads()<br>
><br>
> # Check to see that we reduced the number of threads as expected<br>
> - self.assertTrue(num_threads == 2, 'Number of expected threads and actual threads do not match after thread exit.')<br>
> + self.assertEqual(new_num_threads, num_threads-1, 'Number of threads did not reduce by 1 after thread exit.')<br>
><br>
> self.expect("thread list", 'Process state is stopped due to step',<br>
> substrs = ['stopped',<br>
> @@ -144,4 +119,4 @@ class ExitDuringStepTestCase(TestBase):<br>
> self.runCmd("continue")<br>
><br>
> # At this point, the inferior process should have exited.<br>
> - self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)<br>
> + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)<br>
><br>
> Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py?rev=258586&r1=258585&r2=258586&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py?rev=258586&r1=258585&r2=258586&view=diff</a><br>
> ==============================================================================<br>
> --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py (original)<br>
> +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/TestThreadExit.py Fri Jan 22 17:54:41 2016<br>
> @@ -24,7 +24,6 @@ class ThreadExitTestCase(TestBase):<br>
> self.break_3 = line_number('main.cpp', '// Set third breakpoint here')<br>
> self.break_4 = line_number('main.cpp', '// Set fourth breakpoint here')<br>
><br>
> - @expectedFailureWindows("<a href="http://llvm.org/pr24681" rel="noreferrer" target="_blank">llvm.org/pr24681</a>")<br>
> def test(self):<br>
> """Test thread exit handling."""<br>
> self.build(dictionary=self.getBuildFlags())<br>
> @@ -32,10 +31,10 @@ class ThreadExitTestCase(TestBase):<br>
> self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)<br>
><br>
> # This should create a breakpoint with 1 location.<br>
> - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)<br>
> - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_2, num_expected_locations=1)<br>
> - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_3, num_expected_locations=1)<br>
> - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_4, num_expected_locations=1)<br>
> + bp1_id = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1)<br>
> + bp2_id = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_2, num_expected_locations=1)<br>
> + bp3_id = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_3, num_expected_locations=1)<br>
> + bp4_id = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_4, num_expected_locations=1)<br>
><br>
> # The breakpoint list should show 1 locations.<br>
> self.expect("breakpoint list -f", "Breakpoint location shown correctly",<br>
> @@ -46,71 +45,46 @@ class ThreadExitTestCase(TestBase):<br>
><br>
> # Run the program.<br>
> self.runCmd("run", RUN_SUCCEEDED)<br>
> -<br>
> - # The stop reason of the thread should be breakpoint 1.<br>
> - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 1",<br>
> - substrs = ['stopped',<br>
> - '* thread #1',<br>
> - 'stop reason = breakpoint 1',<br>
> - 'thread #2'])<br>
> -<br>
> # Get the target process<br>
> target = self.dbg.GetSelectedTarget()<br>
> process = target.GetProcess()<br>
><br>
> + stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(process, bp1_id)<br>
> + self.assertIsNotNone(stopped_thread, "Process is not stopped at breakpoint 1")<br>
> +<br>
> # Get the number of threads<br>
> num_threads = process.GetNumThreads()<br>
> -<br>
> - self.assertTrue(num_threads == 2, 'Number of expected threads and actual threads do not match at breakpoint 1.')<br>
> + self.assertGreaterEqual(num_threads, 2, 'Number of expected threads and actual threads do not match at breakpoint 1.')<br>
><br>
> # Run to the second breakpoint<br>
> self.runCmd("continue")<br>
> -<br>
> - # The stop reason of the thread should be breakpoint 1.<br>
> - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 2",<br>
> - substrs = ['stopped',<br>
> - 'thread #1',<br>
> - 'thread #2',<br>
> - 'stop reason = breakpoint 2',<br>
> - 'thread #3'])<br>
> + stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(process, bp2_id)<br>
> + self.assertIsNotNone(stopped_thread, "Process is not stopped at breakpoint 2")<br>
><br>
> # Update the number of threads<br>
> - num_threads = process.GetNumThreads()<br>
> -<br>
> - self.assertTrue(num_threads == 3, 'Number of expected threads and actual threads do not match at breakpoint 2.')<br>
> + new_num_threads = process.GetNumThreads()<br>
> + self.assertEqual(new_num_threads, num_threads+1, 'Number of expected threads did not increase by 1 at bp 2.')<br>
><br>
> # Run to the third breakpoint<br>
> self.runCmd("continue")<br>
> -<br>
> - # The stop reason of the thread should be breakpoint 3.<br>
> - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 3",<br>
> - substrs = ['stopped',<br>
> - 'thread #1',<br>
> - 'stop reason = breakpoint 3',<br>
> - 'thread #3',<br>
> - ])<br>
> + stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(process, bp3_id)<br>
> + self.assertIsNotNone(stopped_thread, "Process is not stopped at breakpoint 3")<br>
><br>
> # Update the number of threads<br>
> - num_threads = process.GetNumThreads()<br>
> -<br>
> - self.assertTrue(num_threads == 2, 'Number of expected threads and actual threads do not match at breakpoint 3.')<br>
> + new_num_threads = process.GetNumThreads()<br>
> + self.assertEqual(new_num_threads, num_threads, 'Number of expected threads is not equal to original number of threads at bp 3.')<br>
><br>
> # Run to the fourth breakpoint<br>
> self.runCmd("continue")<br>
> -<br>
> - # The stop reason of the thread should be breakpoint 4.<br>
> - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 4",<br>
> - substrs = ['stopped',<br>
> - 'thread #1',<br>
> - 'stop reason = breakpoint 4'])<br>
> + stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(process, bp4_id)<br>
> + self.assertIsNotNone(stopped_thread, "Process is not stopped at breakpoint 4")<br>
><br>
> # Update the number of threads<br>
> - num_threads = process.GetNumThreads()<br>
> -<br>
> - self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match at breakpoint 4.')<br>
> + new_num_threads = process.GetNumThreads()<br>
> + self.assertEqual(new_num_threads, num_threads-1, 'Number of expected threads did not decrease by 1 at bp 4.')<br>
><br>
> # Run to completion<br>
> self.runCmd("continue")<br>
><br>
> # At this point, the inferior process should have exited.<br>
> - self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)<br>
> + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)<br>
><br>
> Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py?rev=258586&r1=258585&r2=258586&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py?rev=258586&r1=258585&r2=258586&view=diff</a><br>
> ==============================================================================<br>
> --- lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py (original)<br>
> +++ lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py Fri Jan 22 17:54:41 2016<br>
> @@ -548,7 +548,7 @@ def get_stopped_thread(process, reason):<br>
> return None<br>
> return threads[0]<br>
><br>
> -def get_threads_stopped_at_breakpoint (process, bkpt):<br>
> +def get_threads_stopped_at_breakpoint_id(process, bpid):<br>
> """ For a stopped process returns the thread stopped at the breakpoint passed in bkpt"""<br>
> stopped_threads = []<br>
> threads = []<br>
> @@ -561,13 +561,16 @@ def get_threads_stopped_at_breakpoint (p<br>
> for thread in stopped_threads:<br>
> # Make sure we've hit our breakpoint...<br>
> break_id = thread.GetStopReasonDataAtIndex (0)<br>
> - if break_id == bkpt.GetID():<br>
> + if break_id == bpid:<br>
> threads.append(thread)<br>
><br>
> return threads<br>
><br>
> -def get_one_thread_stopped_at_breakpoint(process, bkpt, require_exactly_one = True):<br>
> - threads = get_threads_stopped_at_breakpoint(process, bkpt)<br>
> +def get_threads_stopped_at_breakpoint (process, bkpt):<br>
> + return get_threads_stopped_at_breakpoint_id(process, bkpt.GetID())<br>
> +<br>
> +def get_one_thread_stopped_at_breakpoint_id(process, bpid, require_exactly_one = True):<br>
> + threads = get_threads_stopped_at_breakpoint_id(process, bpid)<br>
> if len(threads) == 0:<br>
> return None<br>
> if require_exactly_one and len(threads) != 1:<br>
> @@ -575,6 +578,9 @@ def get_one_thread_stopped_at_breakpoint<br>
><br>
> return threads[0]<br>
><br>
> +def get_one_thread_stopped_at_breakpoint(process, bkpt, require_exactly_one = True):<br>
> + return get_one_thread_stopped_at_breakpoint_id(bkpt.GetID(), require_exactly_one)<br>
> +<br>
> def is_thread_crashed (test, thread):<br>
> """In the test suite we dereference a null pointer to simulate a crash. The way this is<br>
> reported depends on the platform."""<br>
><br>
><br>
> _______________________________________________<br>
> lldb-commits mailing list<br>
> <a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
<br>
</blockquote></div>