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