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
203 lines
8.7 KiB
Python
203 lines
8.7 KiB
Python
"""
|
|
Test some target commands: create, list, select, variable.
|
|
"""
|
|
|
|
import unittest2
|
|
import lldb
|
|
import sys
|
|
from lldbtest import *
|
|
import lldbutil
|
|
|
|
class targetCommandTestCase(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
def setUp(self):
|
|
# Call super's setUp().
|
|
TestBase.setUp(self)
|
|
# Find the line numbers for our breakpoints.
|
|
self.line_b = line_number('b.c', '// Set break point at this line.')
|
|
self.line_c = line_number('c.c', '// Set break point at this line.')
|
|
|
|
def test_target_command(self):
|
|
"""Test some target commands: create, list, select."""
|
|
da = {'C_SOURCES': 'a.c', 'EXE': 'a.out'}
|
|
self.build(dictionary=da)
|
|
self.addTearDownCleanup(dictionary=da)
|
|
|
|
db = {'C_SOURCES': 'b.c', 'EXE': 'b.out'}
|
|
self.build(dictionary=db)
|
|
self.addTearDownCleanup(dictionary=db)
|
|
|
|
dc = {'C_SOURCES': 'c.c', 'EXE': 'c.out'}
|
|
self.build(dictionary=dc)
|
|
self.addTearDownCleanup(dictionary=dc)
|
|
|
|
self.do_target_command()
|
|
|
|
# rdar://problem/9763907
|
|
# 'target variable' command fails if the target program has been run
|
|
def test_target_variable_command(self):
|
|
"""Test 'target variable' command before and after starting the inferior."""
|
|
d = {'C_SOURCES': 'globals.c', 'EXE': 'globals'}
|
|
self.build(dictionary=d)
|
|
self.addTearDownCleanup(dictionary=d)
|
|
|
|
self.do_target_variable_command('globals')
|
|
|
|
def test_target_variable_command_no_fail(self):
|
|
"""Test 'target variable' command before and after starting the inferior."""
|
|
d = {'C_SOURCES': 'globals.c', 'EXE': 'globals'}
|
|
self.build(dictionary=d)
|
|
self.addTearDownCleanup(dictionary=d)
|
|
|
|
self.do_target_variable_command_no_fail('globals')
|
|
|
|
def do_target_command(self):
|
|
"""Exercise 'target create', 'target list', 'target select' commands."""
|
|
exe_a = os.path.join(os.getcwd(), "a.out")
|
|
exe_b = os.path.join(os.getcwd(), "b.out")
|
|
exe_c = os.path.join(os.getcwd(), "c.out")
|
|
|
|
self.runCmd("target list")
|
|
output = self.res.GetOutput()
|
|
if output.startswith("No targets"):
|
|
# We start from index 0.
|
|
base = 0
|
|
else:
|
|
# Find the largest index of the existing list.
|
|
import re
|
|
pattern = re.compile("target #(\d+):")
|
|
for line in reversed(output.split(os.linesep)):
|
|
match = pattern.search(line)
|
|
if match:
|
|
# We will start from (index + 1) ....
|
|
base = int(match.group(1), 10) + 1
|
|
#print "base is:", base
|
|
break;
|
|
|
|
self.runCmd("target create " + exe_a, CURRENT_EXECUTABLE_SET)
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
self.runCmd("target create " + exe_b, CURRENT_EXECUTABLE_SET)
|
|
lldbutil.run_break_set_by_file_and_line (self, 'b.c', self.line_b, num_expected_locations=1, loc_exact=True)
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
self.runCmd("target create " + exe_c, CURRENT_EXECUTABLE_SET)
|
|
lldbutil.run_break_set_by_file_and_line (self, 'c.c', self.line_c, num_expected_locations=1, loc_exact=True)
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
self.runCmd("target list")
|
|
|
|
self.runCmd("target select %d" % base)
|
|
self.runCmd("thread backtrace")
|
|
|
|
self.runCmd("target select %d" % (base + 2))
|
|
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
|
|
substrs = ['c.c:%d' % self.line_c,
|
|
'stop reason = breakpoint'])
|
|
|
|
self.runCmd("target select %d" % (base + 1))
|
|
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
|
|
substrs = ['b.c:%d' % self.line_b,
|
|
'stop reason = breakpoint'])
|
|
|
|
self.runCmd("target list")
|
|
|
|
def do_target_variable_command(self, exe_name):
|
|
"""Exercise 'target variable' command before and after starting the inferior."""
|
|
self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
|
|
|
|
self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ["my_global_char", "'X'"])
|
|
self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_global_str', '"abc"'])
|
|
self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_static_int', '228'])
|
|
self.expect("target variable my_global_str_ptr", matching=False,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str_ptr", matching=True,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['a'])
|
|
|
|
self.runCmd("b main")
|
|
self.runCmd("run")
|
|
|
|
self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_global_str', '"abc"'])
|
|
self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_static_int', '228'])
|
|
self.expect("target variable my_global_str_ptr", matching=False,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str_ptr", matching=True,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['a'])
|
|
self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ["my_global_char", "'X'"])
|
|
|
|
self.runCmd("c")
|
|
|
|
# rdar://problem/9763907
|
|
# 'target variable' command fails if the target program has been run
|
|
self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_global_str', '"abc"'])
|
|
self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_static_int', '228'])
|
|
self.expect("target variable my_global_str_ptr", matching=False,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str_ptr", matching=True,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['a'])
|
|
self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ["my_global_char", "'X'"])
|
|
|
|
def do_target_variable_command_no_fail(self, exe_name):
|
|
"""Exercise 'target variable' command before and after starting the inferior."""
|
|
self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
|
|
|
|
self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ["my_global_char", "'X'"])
|
|
self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_global_str', '"abc"'])
|
|
self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_static_int', '228'])
|
|
self.expect("target variable my_global_str_ptr", matching=False,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str_ptr", matching=True,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['a'])
|
|
|
|
self.runCmd("b main")
|
|
self.runCmd("run")
|
|
|
|
# New feature: you don't need to specify the variable(s) to 'target vaiable'.
|
|
# It will find all the global and static variables in the current compile unit.
|
|
self.expect("target variable",
|
|
substrs = ['my_global_char',
|
|
'my_global_str',
|
|
'my_global_str_ptr',
|
|
'my_static_int'])
|
|
|
|
self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_global_str', '"abc"'])
|
|
self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['my_static_int', '228'])
|
|
self.expect("target variable my_global_str_ptr", matching=False,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str_ptr", matching=True,
|
|
substrs = ['"abc"'])
|
|
self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ['a'])
|
|
self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY,
|
|
substrs = ["my_global_char", "'X'"])
|
|
|
|
if __name__ == '__main__':
|
|
import atexit
|
|
lldb.SBDebugger.Initialize()
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
unittest2.main()
|