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