You've already forked llvm-project
mirror of
https://github.com/encounter/llvm-project.git
synced 2026-03-30 11:27:19 -07:00
c8fd130a2c
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
155 lines
7.4 KiB
Python
155 lines
7.4 KiB
Python
"""
|
|
Test that the Python operating system plugin works correctly
|
|
"""
|
|
|
|
import os, time
|
|
import re
|
|
import unittest2
|
|
import lldb
|
|
from lldbtest import *
|
|
import lldbutil
|
|
|
|
class PluginPythonOSPlugin(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
def test_python_os_plugin(self):
|
|
"""Test that the Python operating system plugin works correctly"""
|
|
self.build()
|
|
self.run_python_os_funcionality()
|
|
|
|
def run_python_os_step(self):
|
|
"""Test that the Python operating system plugin works correctly when single stepping a virtual thread"""
|
|
self.build()
|
|
self.run_python_os_step()
|
|
|
|
def verify_os_thread_registers(self, thread):
|
|
frame = thread.GetFrameAtIndex(0)
|
|
registers = frame.GetRegisters().GetValueAtIndex(0)
|
|
reg_value = thread.GetThreadID() + 1
|
|
for reg in registers:
|
|
self.assertTrue(reg.GetValueAsUnsigned() == reg_value, "Verify the registers contains the correct value")
|
|
reg_value = reg_value + 1
|
|
|
|
def run_python_os_funcionality(self):
|
|
"""Test that the Python operating system plugin works correctly"""
|
|
|
|
# Set debugger into synchronous mode
|
|
self.dbg.SetAsync(False)
|
|
|
|
# Create a target by the debugger.
|
|
cwd = os.getcwd()
|
|
exe = os.path.join(cwd, "a.out")
|
|
python_os_plugin_path = os.path.join(cwd, "operating_system.py")
|
|
target = self.dbg.CreateTarget(exe)
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
# Set breakpoints inside and outside methods that take pointers to the containing struct.
|
|
lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")
|
|
|
|
# Register our shared libraries for remote targets so they get automatically uploaded
|
|
arguments = None
|
|
environment = None
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
|
process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
# Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
|
|
thread = process.GetThreadByID(0x111111111);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");
|
|
thread = process.GetThreadByID(0x222222222);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 before we load the python OS plug-in");
|
|
thread = process.GetThreadByID(0x333333333);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 before we load the python OS plug-in");
|
|
|
|
|
|
# Now load the python OS plug-in which should update the thread list and we should have
|
|
# OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
|
|
command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
|
|
self.dbg.HandleCommand(command)
|
|
|
|
# Verify our OS plug-in threads showed up
|
|
thread = process.GetThreadByID(0x111111111);
|
|
self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");
|
|
self.verify_os_thread_registers(thread)
|
|
thread = process.GetThreadByID(0x222222222);
|
|
self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x222222222 after we load the python OS plug-in");
|
|
self.verify_os_thread_registers(thread)
|
|
thread = process.GetThreadByID(0x333333333);
|
|
self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x333333333 after we load the python OS plug-in");
|
|
self.verify_os_thread_registers(thread)
|
|
|
|
# Now clear the OS plug-in path to make the OS plug-in created threads dissappear
|
|
self.dbg.HandleCommand("settings clear target.process.python-os-plugin-path")
|
|
|
|
# Verify the threads are gone after unloading the python OS plug-in
|
|
thread = process.GetThreadByID(0x111111111);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 after we unload the python OS plug-in");
|
|
thread = process.GetThreadByID(0x222222222);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 after we unload the python OS plug-in");
|
|
thread = process.GetThreadByID(0x333333333);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 after we unload the python OS plug-in");
|
|
|
|
def run_python_os_step(self):
|
|
"""Test that the Python operating system plugin works correctly and allows single stepping of a virtual thread that is backed by a real thread"""
|
|
|
|
# Set debugger into synchronous mode
|
|
self.dbg.SetAsync(False)
|
|
|
|
# Create a target by the debugger.
|
|
cwd = os.getcwd()
|
|
exe = os.path.join(cwd, "a.out")
|
|
python_os_plugin_path = os.path.join(cwd, "operating_system2.py")
|
|
target = self.dbg.CreateTarget(exe)
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
# Set breakpoints inside and outside methods that take pointers to the containing struct.
|
|
lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")
|
|
|
|
# Register our shared libraries for remote targets so they get automatically uploaded
|
|
arguments = None
|
|
environment = None
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
|
process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
# Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
|
|
thread = process.GetThreadByID(0x111111111);
|
|
self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");
|
|
|
|
|
|
# Now load the python OS plug-in which should update the thread list and we should have
|
|
# OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
|
|
command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
|
|
self.dbg.HandleCommand(command)
|
|
|
|
# Verify our OS plug-in threads showed up
|
|
thread = process.GetThreadByID(0x111111111);
|
|
self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");
|
|
|
|
frame = thread.GetFrameAtIndex(0)
|
|
self.assertTrue(frame.IsValid(), "Make sure we get a frame from thread 0x111111111")
|
|
line_entry = frame.GetLineEntry()
|
|
|
|
self.assertTrue(line_entry.GetFileSpec().GetFilename() == 'main.c', "Make sure we stopped on line 5 in main.c")
|
|
self.assertTrue(line_entry.GetLine() == 5, "Make sure we stopped on line 5 in main.c")
|
|
|
|
# Now single step thread 0x111111111 and make sure it does what we need it to
|
|
thread.StepOver()
|
|
|
|
frame = thread.GetFrameAtIndex(0)
|
|
self.assertTrue(frame.IsValid(), "Make sure we get a frame from thread 0x111111111")
|
|
line_entry = frame.GetLineEntry()
|
|
|
|
self.assertTrue(line_entry.GetFileSpec().GetFilename() == 'main.c', "Make sure we stepped from line 5 to line 6 in main.c")
|
|
self.assertTrue(line_entry.GetLine() == 6, "Make sure we stepped from line 5 to line 6 in main.c")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import atexit
|
|
lldb.SBDebugger.Initialize()
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
unittest2.main()
|