xref: /llvm-project/lldb/test/API/api/multithreaded/TestMultithreaded.py (revision 186fac33d08b34be494caa58fe63972f69c6d6ab)
199451b44SJordan Rupprecht"""Test the lldb public C++ api breakpoint callbacks."""
299451b44SJordan Rupprecht
399451b44SJordan Rupprechtimport os
40da0966dSJonas Devlieghereimport subprocess
50da0966dSJonas Devlieghere
699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht
118be41c78SJordan Rupprecht@skipIfNoSBHeaders
1299451b44SJordan Rupprechtclass SBBreakpointCallbackCase(TestBase):
1399451b44SJordan Rupprecht    NO_DEBUG_INFO_TESTCASE = True
1499451b44SJordan Rupprecht
1599451b44SJordan Rupprecht    def setUp(self):
1699451b44SJordan Rupprecht        TestBase.setUp(self)
172238dcc3SJonas Devlieghere        self.generateSource("driver.cpp")
182238dcc3SJonas Devlieghere        self.generateSource("listener_test.cpp")
192238dcc3SJonas Devlieghere        self.generateSource("test_breakpoint_callback.cpp")
202238dcc3SJonas Devlieghere        self.generateSource("test_breakpoint_location_callback.cpp")
212238dcc3SJonas Devlieghere        self.generateSource("test_listener_event_description.cpp")
222238dcc3SJonas Devlieghere        self.generateSource("test_listener_event_process_state.cpp")
232238dcc3SJonas Devlieghere        self.generateSource("test_listener_resume.cpp")
242238dcc3SJonas Devlieghere        self.generateSource("test_stop-hook.cpp")
25*186fac33Sjimingham        self.generateSource("test_concurrent_unwind.cpp")
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht    @skipIfRemote
2899451b44SJordan Rupprecht    # clang-cl does not support throw or catch (llvm.org/pr24538)
2999451b44SJordan Rupprecht    @skipIfWindows
30bf93f4b8SJonas Devlieghere    @skipIfHostIncompatibleWithTarget
31a37672e2SJim Ingham    def test_python_stop_hook(self):
32a37672e2SJim Ingham        """Test that you can run a python command in a stop-hook when stdin is File based."""
332238dcc3SJonas Devlieghere        self.build_and_test("driver.cpp test_stop-hook.cpp", "test_python_stop_hook")
34a37672e2SJim Ingham
35a37672e2SJim Ingham    @skipIfRemote
36a37672e2SJim Ingham    # clang-cl does not support throw or catch (llvm.org/pr24538)
37a37672e2SJim Ingham    @skipIfWindows
38bf93f4b8SJonas Devlieghere    @skipIfHostIncompatibleWithTarget
3999451b44SJordan Rupprecht    def test_breakpoint_callback(self):
4099451b44SJordan Rupprecht        """Test the that SBBreakpoint callback is invoked when a breakpoint is hit."""
412238dcc3SJonas Devlieghere        self.build_and_test(
422238dcc3SJonas Devlieghere            "driver.cpp test_breakpoint_callback.cpp", "test_breakpoint_callback"
432238dcc3SJonas Devlieghere        )
4499451b44SJordan Rupprecht
4599451b44SJordan Rupprecht    @skipIfRemote
4699451b44SJordan Rupprecht    # clang-cl does not support throw or catch (llvm.org/pr24538)
4799451b44SJordan Rupprecht    @skipIfWindows
48bf93f4b8SJonas Devlieghere    @skipIfHostIncompatibleWithTarget
496f5d109fSLaura Chaparro-Gutierrez    def test_breakpoint_location_callback(self):
506f5d109fSLaura Chaparro-Gutierrez        """Test the that SBBreakpointLocation callback is invoked when a breakpoint is hit."""
512238dcc3SJonas Devlieghere        self.build_and_test(
522238dcc3SJonas Devlieghere            "driver.cpp test_breakpoint_location_callback.cpp",
532238dcc3SJonas Devlieghere            "test_breakpoint_location_callback",
542238dcc3SJonas Devlieghere        )
556f5d109fSLaura Chaparro-Gutierrez
566f5d109fSLaura Chaparro-Gutierrez    @skipIfRemote
576f5d109fSLaura Chaparro-Gutierrez    # clang-cl does not support throw or catch (llvm.org/pr24538)
586f5d109fSLaura Chaparro-Gutierrez    @skipIfWindows
5999451b44SJordan Rupprecht    @expectedFlakeyFreeBSD
60bf93f4b8SJonas Devlieghere    @skipIfHostIncompatibleWithTarget
6199451b44SJordan Rupprecht    def test_sb_api_listener_event_description(self):
6299451b44SJordan Rupprecht        """Test the description of an SBListener breakpoint event is valid."""
6399451b44SJordan Rupprecht        self.build_and_test(
642238dcc3SJonas Devlieghere            "driver.cpp listener_test.cpp test_listener_event_description.cpp",
652238dcc3SJonas Devlieghere            "test_listener_event_description",
662238dcc3SJonas Devlieghere        )
6799451b44SJordan Rupprecht
6899451b44SJordan Rupprecht    @skipIfRemote
6999451b44SJordan Rupprecht    # clang-cl does not support throw or catch (llvm.org/pr24538)
7099451b44SJordan Rupprecht    @skipIfWindows
7199451b44SJordan Rupprecht    @expectedFlakeyFreeBSD
72bf93f4b8SJonas Devlieghere    @skipIfHostIncompatibleWithTarget
7399451b44SJordan Rupprecht    def test_sb_api_listener_event_process_state(self):
7499451b44SJordan Rupprecht        """Test that a registered SBListener receives events when a process
7599451b44SJordan Rupprecht        changes state.
7699451b44SJordan Rupprecht        """
7799451b44SJordan Rupprecht        self.build_and_test(
782238dcc3SJonas Devlieghere            "driver.cpp listener_test.cpp test_listener_event_process_state.cpp",
792238dcc3SJonas Devlieghere            "test_listener_event_process_state",
802238dcc3SJonas Devlieghere        )
8199451b44SJordan Rupprecht
8299451b44SJordan Rupprecht    @skipIfRemote
8399451b44SJordan Rupprecht    # clang-cl does not support throw or catch (llvm.org/pr24538)
8499451b44SJordan Rupprecht    @skipIfWindows
8599451b44SJordan Rupprecht    @expectedFlakeyFreeBSD
8699451b44SJordan Rupprecht    @skipIf(oslist=["linux"])  # flakey
87bf93f4b8SJonas Devlieghere    @skipIfHostIncompatibleWithTarget
8899451b44SJordan Rupprecht    def test_sb_api_listener_resume(self):
8999451b44SJordan Rupprecht        """Test that a process can be resumed from a non-main thread."""
9099451b44SJordan Rupprecht        self.build_and_test(
912238dcc3SJonas Devlieghere            "driver.cpp listener_test.cpp test_listener_resume.cpp",
922238dcc3SJonas Devlieghere            "test_listener_resume",
932238dcc3SJonas Devlieghere        )
9499451b44SJordan Rupprecht
95*186fac33Sjimingham    @skipIfRemote
96*186fac33Sjimingham    # clang-cl does not support throw or catch (llvm.org/pr24538)
97*186fac33Sjimingham    @skipIfWindows
98*186fac33Sjimingham    @skipIfHostIncompatibleWithTarget
99*186fac33Sjimingham    def test_concurrent_unwind(self):
100*186fac33Sjimingham        """Test that you can run a python command in a stop-hook when stdin is File based."""
101*186fac33Sjimingham        self.build_and_test(
102*186fac33Sjimingham            "driver.cpp test_concurrent_unwind.cpp",
103*186fac33Sjimingham            "test_concurrent_unwind",
104*186fac33Sjimingham            inferior_source="deep_stack.cpp",
105*186fac33Sjimingham        )
106*186fac33Sjimingham
107*186fac33Sjimingham    def build_and_test(self, sources, test_name, inferior_source="inferior.cpp"):
10899451b44SJordan Rupprecht        """Build LLDB test from sources, and run expecting 0 exit code"""
10999451b44SJordan Rupprecht
11099451b44SJordan Rupprecht        # These tests link against host lldb API.
11199451b44SJordan Rupprecht        # Compiler's target triple must match liblldb triple
11299451b44SJordan Rupprecht        # because remote is disabled, we can assume that the os is the same
11399451b44SJordan Rupprecht        # still need to check architecture
11499451b44SJordan Rupprecht        if self.getLldbArchitecture() != self.getArchitecture():
11599451b44SJordan Rupprecht            self.skipTest(
1162238dcc3SJonas Devlieghere                "This test is only run if the target arch is the same as the lldb binary arch"
1172238dcc3SJonas Devlieghere            )
11899451b44SJordan Rupprecht
1192238dcc3SJonas Devlieghere        self.inferior = "inferior_program"
120*186fac33Sjimingham        self.buildProgram(inferior_source, self.inferior)
1212238dcc3SJonas Devlieghere        self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(self.inferior)))
12299451b44SJordan Rupprecht
12399451b44SJordan Rupprecht        self.buildDriver(sources, test_name)
1242238dcc3SJonas Devlieghere        self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(test_name)))
12599451b44SJordan Rupprecht
12699451b44SJordan Rupprecht        test_exe = self.getBuildArtifact(test_name)
12799451b44SJordan Rupprecht        exe = [test_exe, self.getBuildArtifact(self.inferior)]
12899451b44SJordan Rupprecht
1290da0966dSJonas Devlieghere        # check_call will raise a CalledProcessError if the executable doesn't
1300da0966dSJonas Devlieghere        # return exit code 0 to indicate success.  We can let this exception go
1310da0966dSJonas Devlieghere        # - the test harness will recognize it as a test failure.
1320da0966dSJonas Devlieghere        subprocess.check_call(exe)
13399451b44SJordan Rupprecht
13499451b44SJordan Rupprecht    def build_program(self, sources, program):
13599451b44SJordan Rupprecht        return self.buildDriver(sources, program)
136