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