xref: /llvm-project/lldb/test/API/api/multithreaded/TestMultithreaded.py (revision 186fac33d08b34be494caa58fe63972f69c6d6ab)
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        self.generateSource("test_concurrent_unwind.cpp")
26
27    @skipIfRemote
28    # clang-cl does not support throw or catch (llvm.org/pr24538)
29    @skipIfWindows
30    @skipIfHostIncompatibleWithTarget
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", "test_python_stop_hook")
34
35    @skipIfRemote
36    # clang-cl does not support throw or catch (llvm.org/pr24538)
37    @skipIfWindows
38    @skipIfHostIncompatibleWithTarget
39    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    @skipIfRemote
46    # clang-cl does not support throw or catch (llvm.org/pr24538)
47    @skipIfWindows
48    @skipIfHostIncompatibleWithTarget
49    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    @skipIfRemote
57    # clang-cl does not support throw or catch (llvm.org/pr24538)
58    @skipIfWindows
59    @expectedFlakeyFreeBSD
60    @skipIfHostIncompatibleWithTarget
61    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    @skipIfRemote
69    # clang-cl does not support throw or catch (llvm.org/pr24538)
70    @skipIfWindows
71    @expectedFlakeyFreeBSD
72    @skipIfHostIncompatibleWithTarget
73    def test_sb_api_listener_event_process_state(self):
74        """Test that a registered SBListener receives events when a process
75        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    @skipIfRemote
83    # clang-cl does not support throw or catch (llvm.org/pr24538)
84    @skipIfWindows
85    @expectedFlakeyFreeBSD
86    @skipIf(oslist=["linux"])  # flakey
87    @skipIfHostIncompatibleWithTarget
88    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    @skipIfRemote
96    # clang-cl does not support throw or catch (llvm.org/pr24538)
97    @skipIfWindows
98    @skipIfHostIncompatibleWithTarget
99    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 triple
112        # because remote is disabled, we can assume that the os is the same
113        # still need to check architecture
114        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't
130        # return exit code 0 to indicate success.  We can let this exception go
131        # - 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