xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/sysroot/TestStdModuleSysroot.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test that we respect the sysroot when building the std module.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8import os
9
10
11class ImportStdModule(TestBase):
12    # We only emulate a fake libc++ in this test and don't use the real libc++,
13    # but we still add the libc++ category so that this test is only run in
14    # test configurations where libc++ is actually supposed to be tested.
15    @add_test_categories(["libc++"])
16    @skipIf(compiler=no_match("clang"))
17    @skipIfRemote  # This test messes with the platform, can't be run remotely.
18    def test(self):
19        self.build()
20
21        sysroot = os.path.join(os.getcwd(), "root")
22
23        # Set the sysroot.
24        self.runCmd(
25            "platform select --sysroot '" + sysroot + "' host", CURRENT_EXECUTABLE_SET
26        )
27
28        lldbutil.run_to_source_breakpoint(
29            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
30        )
31
32        self.runCmd("settings set target.import-std-module true")
33
34        # Call our custom function in our sysroot std module.
35        # If this gives us the correct result, then we used the sysroot.
36        # We rely on the default argument of -123 to make sure we actually have the C++ module.
37        # (We don't have default arguments in the debug information).
38        self.expect("expr std::myabs()", substrs=["(int) $0 = 123"])
39