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