Currently most of the test files have a separate dwarf and a separate dsym test with almost identical content (only the build step is different). With adding dwo symbol file handling to the test suit it would increase this to a 3-way duplication. The purpose of this change is to eliminate this redundancy with generating 2 test case (one dwarf and one dsym) for each test function specified (dwo handling will be added at a later commit). Main design goals: * There should be no boilerplate code in each test file to support the multiple debug info in most of the tests (custom scenarios are acceptable in special cases) so adding a new test case is easier and we can't miss one of the debug info type. * In case of a test failure, the debug symbols used during the test run have to be cleanly visible from the output of dotest.py to make debugging easier both from build bot logs and from local test runs * Each test case should have a unique, fully qualified name so we can run exactly 1 test with "-f <test-case>.<test-function>" syntax * Test output should be grouped based on test files the same way as it happens now (displaying dwarf/dsym results separately isn't preferable) Proposed solution (main logic in lldbtest.py, rest of them are test cases fixed up for the new style): * Have only 1 test fuction in the test files what will run for all debug info separately and this test function should call just "self.build(...)" to build an inferior with the right debug info * When a class is created by python (the class object, not the class instance), we will generate a new test method for each debug info format in the test class with the name "<test-function>_<debug-info>" and remove the original test method. This way unittest2 see multiple test methods (1 for each debug info, pretty much as of now) and will handle the test selection and the failure reporting correctly (the debug info will be visible from the end of the test name) * Add new annotation @no_debug_info_test to disable the generation of multiple tests for each debug info format when the test don't have an inferior Differential revision: http://reviews.llvm.org/D13028 llvm-svn: 248883
135 lines
6.1 KiB
Python
135 lines
6.1 KiB
Python
"""
|
|
Test stepping out from a function in a multi-threaded program.
|
|
"""
|
|
|
|
import os, time
|
|
import unittest2
|
|
import lldb
|
|
from lldbtest import *
|
|
import lldbutil
|
|
|
|
class ThreadStepOutTestCase(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
@skipIfLinux # Test occasionally times out on the Linux build bot
|
|
@expectedFailureLinux("llvm.org/pr23477") # Test occasionally times out on the Linux build bot
|
|
@expectedFailureFreeBSD("llvm.org/pr18066") # inferior does not exit
|
|
@expectedFailureWindows # Test crashes
|
|
def test_step_single_thread(self):
|
|
"""Test thread step out on one thread via command interpreter. """
|
|
self.build(dictionary=self.getBuildFlags())
|
|
self.step_out_test(self.step_out_single_thread_with_cmd)
|
|
|
|
@skipIfLinux # Test occasionally times out on the Linux build bot
|
|
@expectedFailureLinux("llvm.org/pr23477") # Test occasionally times out on the Linux build bot
|
|
@expectedFailureFreeBSD("llvm.org/pr19347") # 2nd thread stops at breakpoint
|
|
@expectedFailureWindows # Test crashes
|
|
def test_step_all_threads(self):
|
|
"""Test thread step out on all threads via command interpreter. """
|
|
self.build(dictionary=self.getBuildFlags())
|
|
self.step_out_test(self.step_out_all_threads_with_cmd)
|
|
|
|
@skipIfLinux # Test occasionally times out on the Linux build bot
|
|
@expectedFailureLinux("llvm.org/pr23477") # Test occasionally times out on the Linux build bot
|
|
@expectedFailureFreeBSD("llvm.org/pr19347")
|
|
@expectedFailureWindows("llvm.org/pr24681")
|
|
def test_python(self):
|
|
"""Test thread step out on one thread via Python API (dwarf)."""
|
|
self.build(dictionary=self.getBuildFlags())
|
|
self.step_out_test(self.step_out_with_python)
|
|
|
|
def setUp(self):
|
|
# Call super's setUp().
|
|
TestBase.setUp(self)
|
|
# Find the line number for our breakpoint.
|
|
self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
|
|
if "gcc" in self.getCompiler() or self.isIntelCompiler():
|
|
self.step_out_destination = line_number('main.cpp', '// Expect to stop here after step-out (icc and gcc)')
|
|
else:
|
|
self.step_out_destination = line_number('main.cpp', '// Expect to stop here after step-out (clang)')
|
|
|
|
def step_out_single_thread_with_cmd(self):
|
|
self.step_out_with_cmd("this-thread")
|
|
self.expect("thread backtrace all", "Thread location after step out is correct",
|
|
substrs = ["main.cpp:%d" % self.step_out_destination,
|
|
"main.cpp:%d" % self.breakpoint])
|
|
|
|
def step_out_all_threads_with_cmd(self):
|
|
self.step_out_with_cmd("all-threads")
|
|
self.expect("thread backtrace all", "Thread location after step out is correct",
|
|
substrs = ["main.cpp:%d" % self.step_out_destination])
|
|
|
|
def step_out_with_cmd(self, run_mode):
|
|
self.runCmd("thread select %d" % self.step_out_thread.GetIndexID())
|
|
self.runCmd("thread step-out -m %s" % run_mode)
|
|
self.expect("process status", "Expected stop reason to be step-out",
|
|
substrs = ["stop reason = step out"])
|
|
|
|
self.expect("thread list", "Selected thread did not change during step-out",
|
|
substrs = ["* thread #%d" % self.step_out_thread.GetIndexID()])
|
|
|
|
def step_out_with_python(self):
|
|
self.step_out_thread.StepOut()
|
|
|
|
reason = self.step_out_thread.GetStopReason()
|
|
self.assertEqual(lldb.eStopReasonPlanComplete, reason,
|
|
"Expected thread stop reason 'plancomplete', but got '%s'" % lldbutil.stop_reason_to_str(reason))
|
|
|
|
# Verify location after stepping out
|
|
frame = self.step_out_thread.GetFrameAtIndex(0)
|
|
desc = lldbutil.get_description(frame.GetLineEntry())
|
|
expect = "main.cpp:%d" % self.step_out_destination
|
|
self.assertTrue(expect in desc, "Expected %s but thread stopped at %s" % (expect, desc))
|
|
|
|
def step_out_test(self, step_out_func):
|
|
"""Test single thread step out of a function."""
|
|
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.cpp", self.breakpoint, num_expected_locations=1)
|
|
|
|
# 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) = ([], [])
|
|
lldbutil.sort_stopped_threads(self.inferior_process,
|
|
breakpoint_threads=breakpoint_threads,
|
|
other_threads=other_threads)
|
|
|
|
while len(breakpoint_threads) < 2:
|
|
self.runCmd("thread continue %s" % " ".join([str(x.GetIndexID()) for x in other_threads]))
|
|
lldbutil.sort_stopped_threads(self.inferior_process,
|
|
breakpoint_threads=breakpoint_threads,
|
|
other_threads=other_threads)
|
|
|
|
self.step_out_thread = breakpoint_threads[0]
|
|
|
|
# Step out of thread stopped at breakpoint
|
|
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)
|
|
|
|
if __name__ == '__main__':
|
|
import atexit
|
|
lldb.SBDebugger.Initialize()
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
unittest2.main()
|