xref: /llvm-project/lldb/test/API/python_api/sbplatform/TestSBPlatform.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
10ec88d03SPavel Labath"""Test the SBPlatform APIs."""
20ec88d03SPavel Labath
30ec88d03SPavel Labathfrom lldbsuite.test.decorators import *
40ec88d03SPavel Labathfrom lldbsuite.test.lldbtest import *
50ec88d03SPavel Labath
6*2238dcc3SJonas Devlieghere
70ec88d03SPavel Labathclass SBPlatformAPICase(TestBase):
80ec88d03SPavel Labath    NO_DEBUG_INFO_TESTCASE = True
90ec88d03SPavel Labath
10ba3d84d8SJonas Devlieghere    @skipIfRemote  # Remote environment not supported.
110ec88d03SPavel Labath    def test_run(self):
120ec88d03SPavel Labath        self.build()
130ec88d03SPavel Labath        plat = lldb.SBPlatform.GetHostPlatform()
140ec88d03SPavel Labath
150ec88d03SPavel Labath        os.environ["MY_TEST_ENV_VAR"] = "SBPlatformAPICase.test_run"
16*2238dcc3SJonas Devlieghere
170ec88d03SPavel Labath        def cleanup():
180ec88d03SPavel Labath            del os.environ["MY_TEST_ENV_VAR"]
19*2238dcc3SJonas Devlieghere
200ec88d03SPavel Labath        self.addTearDownHook(cleanup)
210ec88d03SPavel Labath        cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
22779bbbf2SDave Lee        self.assertSuccess(plat.Run(cmd))
230ec88d03SPavel Labath        self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", cmd.GetOutput())
2490342453SPavel Labath
2590342453SPavel Labath    def test_SetSDKRoot(self):
2690342453SPavel Labath        plat = lldb.SBPlatform("remote-linux")  # arbitrary choice
2790342453SPavel Labath        self.assertTrue(plat)
2890342453SPavel Labath        plat.SetSDKRoot(self.getBuildDir())
29af921006SPavel Labath        self.dbg.SetSelectedPlatform(plat)
30*2238dcc3SJonas Devlieghere        self.expect("platform status", substrs=["Sysroot:", self.getBuildDir()])
31af921006SPavel Labath
32af921006SPavel Labath    def test_SetCurrentPlatform_floating(self):
33af921006SPavel Labath        # floating platforms cannot be referenced by name until they are
34af921006SPavel Labath        # associated with a debugger
35af921006SPavel Labath        floating_platform = lldb.SBPlatform("remote-netbsd")
36af921006SPavel Labath        floating_platform.SetWorkingDirectory(self.getBuildDir())
37af921006SPavel Labath        self.assertSuccess(self.dbg.SetCurrentPlatform("remote-netbsd"))
38af921006SPavel Labath        dbg_platform = self.dbg.GetSelectedPlatform()
39af921006SPavel Labath        self.assertEqual(dbg_platform.GetName(), "remote-netbsd")
40af921006SPavel Labath        self.assertIsNone(dbg_platform.GetWorkingDirectory())
41af921006SPavel Labath
42af921006SPavel Labath    def test_SetCurrentPlatform_associated(self):
43af921006SPavel Labath        # associated platforms are found by name-based lookup
44af921006SPavel Labath        floating_platform = lldb.SBPlatform("remote-netbsd")
45af921006SPavel Labath        floating_platform.SetWorkingDirectory(self.getBuildDir())
46af921006SPavel Labath        orig_platform = self.dbg.GetSelectedPlatform()
47af921006SPavel Labath
48af921006SPavel Labath        self.dbg.SetSelectedPlatform(floating_platform)
49af921006SPavel Labath        self.dbg.SetSelectedPlatform(orig_platform)
50af921006SPavel Labath        self.assertSuccess(self.dbg.SetCurrentPlatform("remote-netbsd"))
51af921006SPavel Labath        dbg_platform = self.dbg.GetSelectedPlatform()
52af921006SPavel Labath        self.assertEqual(dbg_platform.GetName(), "remote-netbsd")
53af921006SPavel Labath        self.assertEqual(dbg_platform.GetWorkingDirectory(), self.getBuildDir())
54