xref: /llvm-project/lldb/test/API/api/multithreaded/TestMultithreaded.py (revision 266c90fec899356aa2c88f1e614d40d554db6fb3)
1"""Test the lldb public C++ api breakpoint callbacks."""
2
3from __future__ import print_function
4
5# __package__ = "lldbsuite.test"
6
7
8import os
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class SBBreakpointCallbackCase(TestBase):
15
16    NO_DEBUG_INFO_TESTCASE = True
17
18    def setUp(self):
19        TestBase.setUp(self)
20        self.generateSource('driver.cpp')
21        self.generateSource('listener_test.cpp')
22        self.generateSource('test_breakpoint_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    mydir = TestBase.compute_mydir(__file__)
29
30    @skipIfRemote
31    @skipIfNoSBHeaders
32    # clang-cl does not support throw or catch (llvm.org/pr24538)
33    @skipIfWindows
34    @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr48370')
35    def test_python_stop_hook(self):
36        """Test that you can run a python command in a stop-hook when stdin is File based. """
37        self.build_and_test('driver.cpp test_stop-hook.cpp',
38                            'test_python_stop_hook')
39
40    @skipIfRemote
41    @skipIfNoSBHeaders
42    # clang-cl does not support throw or catch (llvm.org/pr24538)
43    @skipIfWindows
44    def test_breakpoint_callback(self):
45        """Test the that SBBreakpoint callback is invoked when a breakpoint is hit. """
46        self.build_and_test('driver.cpp test_breakpoint_callback.cpp',
47                            'test_breakpoint_callback')
48
49    @skipIfRemote
50    @skipIfNoSBHeaders
51    # clang-cl does not support throw or catch (llvm.org/pr24538)
52    @skipIfWindows
53    @expectedFlakeyFreeBSD
54    def test_sb_api_listener_event_description(self):
55        """ Test the description of an SBListener breakpoint event is valid."""
56        self.build_and_test(
57            'driver.cpp listener_test.cpp test_listener_event_description.cpp',
58            'test_listener_event_description')
59
60    @skipIfRemote
61    @skipIfNoSBHeaders
62    # clang-cl does not support throw or catch (llvm.org/pr24538)
63    @skipIfWindows
64    @expectedFlakeyFreeBSD
65    def test_sb_api_listener_event_process_state(self):
66        """ Test that a registered SBListener receives events when a process
67            changes state.
68        """
69        self.build_and_test(
70            'driver.cpp listener_test.cpp test_listener_event_process_state.cpp',
71            'test_listener_event_process_state')
72
73    @skipIfRemote
74    @skipIfNoSBHeaders
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        if self.TraceOn():
113            print("Running test %s" % " ".join(exe))
114            check_call(exe, env=env)
115        else:
116            with open(os.devnull, 'w') as fnull:
117                check_call(exe, env=env, stdout=fnull, stderr=fnull)
118
119    def build_program(self, sources, program):
120        return self.buildDriver(sources, program)
121