136 lines · python
1"""Test the lldb public C++ api breakpoint callbacks."""2 3import os4import subprocess5 6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11@skipIfNoSBHeaders12class SBBreakpointCallbackCase(TestBase):13 NO_DEBUG_INFO_TESTCASE = True14 15 def setUp(self):16 TestBase.setUp(self)17 self.generateSource("driver.cpp")18 self.generateSource("listener_test.cpp")19 self.generateSource("test_breakpoint_callback.cpp")20 self.generateSource("test_breakpoint_location_callback.cpp")21 self.generateSource("test_listener_event_description.cpp")22 self.generateSource("test_listener_event_process_state.cpp")23 self.generateSource("test_listener_resume.cpp")24 self.generateSource("test_stop-hook.cpp")25 self.generateSource("test_concurrent_unwind.cpp")26 27 @skipIfRemote28 # clang-cl does not support throw or catch (llvm.org/pr24538)29 @skipIfWindows30 @skipIfHostIncompatibleWithTarget31 def test_python_stop_hook(self):32 """Test that you can run a python command in a stop-hook when stdin is File based."""33 self.build_and_test("driver.cpp test_stop-hook.cpp", "test_python_stop_hook")34 35 @skipIfRemote36 # clang-cl does not support throw or catch (llvm.org/pr24538)37 @skipIfWindows38 @skipIfHostIncompatibleWithTarget39 def test_breakpoint_callback(self):40 """Test the that SBBreakpoint callback is invoked when a breakpoint is hit."""41 self.build_and_test(42 "driver.cpp test_breakpoint_callback.cpp", "test_breakpoint_callback"43 )44 45 @skipIfRemote46 # clang-cl does not support throw or catch (llvm.org/pr24538)47 @skipIfWindows48 @skipIfHostIncompatibleWithTarget49 def test_breakpoint_location_callback(self):50 """Test the that SBBreakpointLocation callback is invoked when a breakpoint is hit."""51 self.build_and_test(52 "driver.cpp test_breakpoint_location_callback.cpp",53 "test_breakpoint_location_callback",54 )55 56 @skipIfRemote57 # clang-cl does not support throw or catch (llvm.org/pr24538)58 @skipIfWindows59 @expectedFlakeyFreeBSD60 @skipIfHostIncompatibleWithTarget61 def test_sb_api_listener_event_description(self):62 """Test the description of an SBListener breakpoint event is valid."""63 self.build_and_test(64 "driver.cpp listener_test.cpp test_listener_event_description.cpp",65 "test_listener_event_description",66 )67 68 @skipIfRemote69 # clang-cl does not support throw or catch (llvm.org/pr24538)70 @skipIfWindows71 @expectedFlakeyFreeBSD72 @skipIfHostIncompatibleWithTarget73 def test_sb_api_listener_event_process_state(self):74 """Test that a registered SBListener receives events when a process75 changes state.76 """77 self.build_and_test(78 "driver.cpp listener_test.cpp test_listener_event_process_state.cpp",79 "test_listener_event_process_state",80 )81 82 @skipIfRemote83 # clang-cl does not support throw or catch (llvm.org/pr24538)84 @skipIfWindows85 @expectedFlakeyFreeBSD86 @skipIf(oslist=["linux"]) # flakey87 @skipIfHostIncompatibleWithTarget88 def test_sb_api_listener_resume(self):89 """Test that a process can be resumed from a non-main thread."""90 self.build_and_test(91 "driver.cpp listener_test.cpp test_listener_resume.cpp",92 "test_listener_resume",93 )94 95 @skipIfRemote96 # clang-cl does not support throw or catch (llvm.org/pr24538)97 @skipIfWindows98 @skipIfHostIncompatibleWithTarget99 def test_concurrent_unwind(self):100 """Test that you can run a python command in a stop-hook when stdin is File based."""101 self.build_and_test(102 "driver.cpp test_concurrent_unwind.cpp",103 "test_concurrent_unwind",104 inferior_source="deep_stack.cpp",105 )106 107 def build_and_test(self, sources, test_name, inferior_source="inferior.cpp"):108 """Build LLDB test from sources, and run expecting 0 exit code"""109 110 # These tests link against host lldb API.111 # Compiler's target triple must match liblldb triple112 # because remote is disabled, we can assume that the os is the same113 # still need to check architecture114 if self.getLldbArchitecture() != self.getArchitecture():115 self.skipTest(116 "This test is only run if the target arch is the same as the lldb binary arch"117 )118 119 self.inferior = "inferior_program"120 self.buildProgram(inferior_source, self.inferior)121 self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(self.inferior)))122 123 self.buildDriver(sources, test_name)124 self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(test_name)))125 126 test_exe = self.getBuildArtifact(test_name)127 exe = [test_exe, self.getBuildArtifact(self.inferior)]128 129 # check_call will raise a CalledProcessError if the executable doesn't130 # return exit code 0 to indicate success. We can let this exception go131 # - the test harness will recognize it as a test failure.132 subprocess.check_call(exe)133 134 def build_program(self, sources, program):135 return self.buildDriver(sources, program)136