1"""Test the lldb public C++ api breakpoint callbacks.""" 2 3import os 4import subprocess 5 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11@skipIfNoSBHeaders 12class SBBreakpointCallbackCase(TestBase): 13 NO_DEBUG_INFO_TESTCASE = True 14 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 26 @skipIfRemote 27 # clang-cl does not support throw or catch (llvm.org/pr24538) 28 @skipIfWindows 29 @skipIfHostIncompatibleWithTarget 30 def test_python_stop_hook(self): 31 """Test that you can run a python command in a stop-hook when stdin is File based.""" 32 self.build_and_test("driver.cpp test_stop-hook.cpp", "test_python_stop_hook") 33 34 @skipIfRemote 35 # clang-cl does not support throw or catch (llvm.org/pr24538) 36 @skipIfWindows 37 @skipIfHostIncompatibleWithTarget 38 def test_breakpoint_callback(self): 39 """Test the that SBBreakpoint callback is invoked when a breakpoint is hit.""" 40 self.build_and_test( 41 "driver.cpp test_breakpoint_callback.cpp", "test_breakpoint_callback" 42 ) 43 44 @skipIfRemote 45 # clang-cl does not support throw or catch (llvm.org/pr24538) 46 @skipIfWindows 47 @skipIfHostIncompatibleWithTarget 48 def test_breakpoint_location_callback(self): 49 """Test the that SBBreakpointLocation callback is invoked when a breakpoint is hit.""" 50 self.build_and_test( 51 "driver.cpp test_breakpoint_location_callback.cpp", 52 "test_breakpoint_location_callback", 53 ) 54 55 @skipIfRemote 56 # clang-cl does not support throw or catch (llvm.org/pr24538) 57 @skipIfWindows 58 @expectedFlakeyFreeBSD 59 @skipIfHostIncompatibleWithTarget 60 def test_sb_api_listener_event_description(self): 61 """Test the description of an SBListener breakpoint event is valid.""" 62 self.build_and_test( 63 "driver.cpp listener_test.cpp test_listener_event_description.cpp", 64 "test_listener_event_description", 65 ) 66 67 @skipIfRemote 68 # clang-cl does not support throw or catch (llvm.org/pr24538) 69 @skipIfWindows 70 @expectedFlakeyFreeBSD 71 @skipIfHostIncompatibleWithTarget 72 def test_sb_api_listener_event_process_state(self): 73 """Test that a registered SBListener receives events when a process 74 changes state. 75 """ 76 self.build_and_test( 77 "driver.cpp listener_test.cpp test_listener_event_process_state.cpp", 78 "test_listener_event_process_state", 79 ) 80 81 @skipIfRemote 82 # clang-cl does not support throw or catch (llvm.org/pr24538) 83 @skipIfWindows 84 @expectedFlakeyFreeBSD 85 @skipIf(oslist=["linux"]) # flakey 86 @skipIfHostIncompatibleWithTarget 87 def test_sb_api_listener_resume(self): 88 """Test that a process can be resumed from a non-main thread.""" 89 self.build_and_test( 90 "driver.cpp listener_test.cpp test_listener_resume.cpp", 91 "test_listener_resume", 92 ) 93 94 def build_and_test(self, sources, test_name, args=None): 95 """Build LLDB test from sources, and run expecting 0 exit code""" 96 97 # These tests link against host lldb API. 98 # Compiler's target triple must match liblldb triple 99 # because remote is disabled, we can assume that the os is the same 100 # still need to check architecture 101 if self.getLldbArchitecture() != self.getArchitecture(): 102 self.skipTest( 103 "This test is only run if the target arch is the same as the lldb binary arch" 104 ) 105 106 self.inferior = "inferior_program" 107 self.buildProgram("inferior.cpp", self.inferior) 108 self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(self.inferior))) 109 110 self.buildDriver(sources, test_name) 111 self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(test_name))) 112 113 test_exe = self.getBuildArtifact(test_name) 114 exe = [test_exe, self.getBuildArtifact(self.inferior)] 115 116 # check_call will raise a CalledProcessError if the executable doesn't 117 # return exit code 0 to indicate success. We can let this exception go 118 # - the test harness will recognize it as a test failure. 119 subprocess.check_call(exe) 120 121 def build_program(self, sources, program): 122 return self.buildDriver(sources, program) 123