forked from OSchip/llvm-project
				
			Modernize TestThreadStepOut.py
This test was timing out on the swift CI bots. I didn't see any obvious reason for that, and the test hasn't had problems on greendragon. OTOH, it was a bit oddly written, and needed modernizing, so I did that. Differential Revision: https://reviews.llvm.org/D69453
This commit is contained in:
		
							parent
							
								
									0f6ed432d5
								
							
						
					
					
						commit
						651b5e725e
					
				| 
						 | 
					@ -68,7 +68,9 @@ class ThreadStepOutTestCase(TestBase):
 | 
				
			||||||
        # Call super's setUp().
 | 
					        # Call super's setUp().
 | 
				
			||||||
        TestBase.setUp(self)
 | 
					        TestBase.setUp(self)
 | 
				
			||||||
        # Find the line number for our breakpoint.
 | 
					        # Find the line number for our breakpoint.
 | 
				
			||||||
        self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
 | 
					        self.bkpt_string = '// Set breakpoint here'
 | 
				
			||||||
 | 
					        self.breakpoint = line_number('main.cpp', self.bkpt_string)       
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if "gcc" in self.getCompiler() or self.isIntelCompiler():
 | 
					        if "gcc" in self.getCompiler() or self.isIntelCompiler():
 | 
				
			||||||
            self.step_out_destination = line_number(
 | 
					            self.step_out_destination = line_number(
 | 
				
			||||||
                'main.cpp', '// Expect to stop here after step-out (icc and gcc)')
 | 
					                'main.cpp', '// Expect to stop here after step-out (icc and gcc)')
 | 
				
			||||||
| 
						 | 
					@ -129,56 +131,27 @@ class ThreadStepOutTestCase(TestBase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def step_out_test(self, step_out_func):
 | 
					    def step_out_test(self, step_out_func):
 | 
				
			||||||
        """Test single thread step out of a function."""
 | 
					        """Test single thread step out of a function."""
 | 
				
			||||||
        exe = self.getBuildArtifact("a.out")
 | 
					        (self.inferior_target, self.inferior_process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
 | 
				
			||||||
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 | 
					            self, self.bkpt_string, lldb.SBFileSpec('main.cpp'), only_one_thread = False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # This should create a breakpoint in the main thread.
 | 
					        # We hit the breakpoint on at least one thread.  If we hit it on both threads
 | 
				
			||||||
        lldbutil.run_break_set_by_file_and_line(
 | 
					        # simultaneously, we can try the step out.  Otherwise, suspend the thread
 | 
				
			||||||
            self, "main.cpp", self.breakpoint, num_expected_locations=1)
 | 
					        # that hit the breakpoint, and continue till the second thread hits
 | 
				
			||||||
 | 
					        # the breakpoint:
 | 
				
			||||||
        # The breakpoint list should show 1 location.
 | 
					 | 
				
			||||||
        self.expect(
 | 
					 | 
				
			||||||
            "breakpoint list -f",
 | 
					 | 
				
			||||||
            "Breakpoint location shown correctly",
 | 
					 | 
				
			||||||
            substrs=[
 | 
					 | 
				
			||||||
                "1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
 | 
					 | 
				
			||||||
                self.breakpoint])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Run the program.
 | 
					 | 
				
			||||||
        self.runCmd("run", RUN_SUCCEEDED)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Get the target process
 | 
					 | 
				
			||||||
        self.inferior_target = self.dbg.GetSelectedTarget()
 | 
					 | 
				
			||||||
        self.inferior_process = self.inferior_target.GetProcess()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Get the number of threads, ensure we see all three.
 | 
					 | 
				
			||||||
        num_threads = self.inferior_process.GetNumThreads()
 | 
					 | 
				
			||||||
        self.assertEqual(
 | 
					 | 
				
			||||||
            num_threads,
 | 
					 | 
				
			||||||
            3,
 | 
					 | 
				
			||||||
            'Number of expected threads and actual threads do not match.')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        (breakpoint_threads, other_threads) = ([], [])
 | 
					        (breakpoint_threads, other_threads) = ([], [])
 | 
				
			||||||
        lldbutil.sort_stopped_threads(self.inferior_process,
 | 
					        lldbutil.sort_stopped_threads(self.inferior_process,
 | 
				
			||||||
                                      breakpoint_threads=breakpoint_threads,
 | 
					                                      breakpoint_threads=breakpoint_threads,
 | 
				
			||||||
                                      other_threads=other_threads)
 | 
					                                      other_threads=other_threads)
 | 
				
			||||||
 | 
					        if len(breakpoint_threads) == 1:
 | 
				
			||||||
        while len(breakpoint_threads) < 2:
 | 
					            success = thread.Suspend()
 | 
				
			||||||
            self.runCmd("thread continue %s" %
 | 
					            self.assertTrue(success, "Couldn't suspend a thread")
 | 
				
			||||||
                        " ".join([str(x.GetIndexID()) for x in other_threads]))
 | 
					            bkpt_threads = lldbutil.continue_to_breakpoint(bkpt)
 | 
				
			||||||
            lldbutil.sort_stopped_threads(
 | 
					            self.assertEqual(len(bkpt_threads), 1, "Second thread stopped")
 | 
				
			||||||
                self.inferior_process,
 | 
					            success = thread.Resume()
 | 
				
			||||||
                breakpoint_threads=breakpoint_threads,
 | 
					            self.assertTrue(success, "Couldn't resume a thread")
 | 
				
			||||||
                other_threads=other_threads)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.step_out_thread = breakpoint_threads[0]
 | 
					        self.step_out_thread = breakpoint_threads[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Step out of thread stopped at breakpoint
 | 
					        # Step out of thread stopped at breakpoint
 | 
				
			||||||
        step_out_func()
 | 
					        step_out_func()
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Run to completion
 | 
					 | 
				
			||||||
        self.runCmd("continue")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # At this point, the inferior process should have exited.
 | 
					 | 
				
			||||||
        self.assertTrue(self.inferior_process.GetState() ==
 | 
					 | 
				
			||||||
                        lldb.eStateExited, PROCESS_EXITED)
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -760,7 +760,7 @@ def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
 | 
				
			||||||
    test.assertTrue(target, "Target: %s is not valid."%(exe_name))
 | 
					    test.assertTrue(target, "Target: %s is not valid."%(exe_name))
 | 
				
			||||||
    return target
 | 
					    return target
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
 | 
					def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None, only_one_thread = True):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Launch the process, and do not stop at the entry point.
 | 
					    # Launch the process, and do not stop at the entry point.
 | 
				
			||||||
    if not launch_info:
 | 
					    if not launch_info:
 | 
				
			||||||
| 
						 | 
					@ -778,14 +778,20 @@ def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
 | 
				
			||||||
    threads = get_threads_stopped_at_breakpoint(
 | 
					    threads = get_threads_stopped_at_breakpoint(
 | 
				
			||||||
                process, bkpt)
 | 
					                process, bkpt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    test.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
 | 
					    num_threads = len(threads)
 | 
				
			||||||
 | 
					    if only_one_thread:
 | 
				
			||||||
 | 
					        test.assertEqual(num_threads, 1, "Expected 1 thread to stop at breakpoint, %d did."%(num_threads))
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        test.assertGreater(num_threads, 0, "No threads stopped at breakpoint")
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
    thread = threads[0]
 | 
					    thread = threads[0]
 | 
				
			||||||
    return (target, process, thread, bkpt)
 | 
					    return (target, process, thread, bkpt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
 | 
					def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
 | 
				
			||||||
                            exe_name = "a.out",
 | 
					                            exe_name = "a.out",
 | 
				
			||||||
                            bkpt_module = None,
 | 
					                            bkpt_module = None,
 | 
				
			||||||
                            in_cwd = True):
 | 
					                            in_cwd = True,
 | 
				
			||||||
 | 
					                            only_one_thread = True):
 | 
				
			||||||
    """Start up a target, using exe_name as the executable, and run it to
 | 
					    """Start up a target, using exe_name as the executable, and run it to
 | 
				
			||||||
       a breakpoint set by name on bkpt_name restricted to bkpt_module.
 | 
					       a breakpoint set by name on bkpt_name restricted to bkpt_module.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -807,6 +813,11 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
 | 
				
			||||||
       If successful it returns a tuple with the target process and
 | 
					       If successful it returns a tuple with the target process and
 | 
				
			||||||
       thread that hit the breakpoint, and the breakpoint that we set
 | 
					       thread that hit the breakpoint, and the breakpoint that we set
 | 
				
			||||||
       for you.
 | 
					       for you.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					       If only_one_thread is true, we require that there be only one
 | 
				
			||||||
 | 
					       thread stopped at the breakpoint.  Otherwise we only require one
 | 
				
			||||||
 | 
					       or more threads stop there.  If there are more than one, we return
 | 
				
			||||||
 | 
					       the first thread that stopped.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
 | 
					    target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
 | 
				
			||||||
| 
						 | 
					@ -816,12 +827,13 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    test.assertTrue(breakpoint.GetNumLocations() > 0,
 | 
					    test.assertTrue(breakpoint.GetNumLocations() > 0,
 | 
				
			||||||
                    "No locations found for name breakpoint: '%s'."%(bkpt_name))
 | 
					                    "No locations found for name breakpoint: '%s'."%(bkpt_name))
 | 
				
			||||||
    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
 | 
					    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
 | 
					def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
 | 
				
			||||||
                             launch_info = None, exe_name = "a.out",
 | 
					                             launch_info = None, exe_name = "a.out",
 | 
				
			||||||
                             bkpt_module = None,
 | 
					                             bkpt_module = None,
 | 
				
			||||||
                             in_cwd = True):
 | 
					                             in_cwd = True,
 | 
				
			||||||
 | 
					                             only_one_thread = True):
 | 
				
			||||||
    """Start up a target, using exe_name as the executable, and run it to
 | 
					    """Start up a target, using exe_name as the executable, and run it to
 | 
				
			||||||
       a breakpoint set by source regex bkpt_pattern.
 | 
					       a breakpoint set by source regex bkpt_pattern.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -835,12 +847,13 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
 | 
				
			||||||
    test.assertTrue(breakpoint.GetNumLocations() > 0,
 | 
					    test.assertTrue(breakpoint.GetNumLocations() > 0,
 | 
				
			||||||
        'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
 | 
					        'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
 | 
				
			||||||
        %(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
 | 
					        %(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
 | 
				
			||||||
    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
 | 
					    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
 | 
					def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
 | 
				
			||||||
                           launch_info = None, exe_name = "a.out",
 | 
					                           launch_info = None, exe_name = "a.out",
 | 
				
			||||||
                           bkpt_module = None,
 | 
					                           bkpt_module = None,
 | 
				
			||||||
                           in_cwd = True):
 | 
					                           in_cwd = True,
 | 
				
			||||||
 | 
					                           only_one_thread = True):
 | 
				
			||||||
    """Start up a target, using exe_name as the executable, and run it to
 | 
					    """Start up a target, using exe_name as the executable, and run it to
 | 
				
			||||||
       a breakpoint set by (source_spec, line_number(, column)).
 | 
					       a breakpoint set by (source_spec, line_number(, column)).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -855,7 +868,7 @@ def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
 | 
				
			||||||
        'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
 | 
					        'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
 | 
				
			||||||
        %(source_spec.GetFilename(), line_number, column,
 | 
					        %(source_spec.GetFilename(), line_number, column,
 | 
				
			||||||
          source_spec.GetDirectory()))
 | 
					          source_spec.GetDirectory()))
 | 
				
			||||||
    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
 | 
					    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def continue_to_breakpoint(process, bkpt):
 | 
					def continue_to_breakpoint(process, bkpt):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue