199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest the lldb platform Python API. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprechtimport lldb 799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass PlatformPythonTestCase(TestBase): 13*2238dcc3SJonas Devlieghere @add_test_categories(["pyapi"]) 1499451b44SJordan Rupprecht @no_debug_info_test 1599451b44SJordan Rupprecht def test_platform_list(self): 1699451b44SJordan Rupprecht """Test SBDebugger::GetNumPlatforms() & GetPlatformAtIndex() API""" 1799451b44SJordan Rupprecht # Verify the host platform is present by default. 1899451b44SJordan Rupprecht initial_num_platforms = self.dbg.GetNumPlatforms() 1999451b44SJordan Rupprecht self.assertGreater(initial_num_platforms, 0) 2099451b44SJordan Rupprecht host_platform = self.dbg.GetPlatformAtIndex(0) 21*2238dcc3SJonas Devlieghere self.assertTrue( 22*2238dcc3SJonas Devlieghere host_platform.IsValid() and host_platform.GetName() == "host", 23*2238dcc3SJonas Devlieghere "The host platform is present", 24*2238dcc3SJonas Devlieghere ) 2599451b44SJordan Rupprecht # Select another platform and verify that the platform is added to 2699451b44SJordan Rupprecht # the platform list. 2799451b44SJordan Rupprecht platform_idx = self.dbg.GetNumAvailablePlatforms() - 1 2899451b44SJordan Rupprecht if platform_idx < 1: 29*2238dcc3SJonas Devlieghere self.fail("No platforms other than host are available") 3099451b44SJordan Rupprecht platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(platform_idx) 31*2238dcc3SJonas Devlieghere platform_name = platform_data.GetValueForKey("name").GetStringValue(100) 32*2238dcc3SJonas Devlieghere self.assertNotEqual(platform_name, "host") 3399451b44SJordan Rupprecht self.dbg.SetCurrentPlatform(platform_name) 3499451b44SJordan Rupprecht selected_platform = self.dbg.GetSelectedPlatform() 3599451b44SJordan Rupprecht self.assertTrue(selected_platform.IsValid()) 3699451b44SJordan Rupprecht self.assertEqual(selected_platform.GetName(), platform_name) 3799451b44SJordan Rupprecht self.assertEqual(self.dbg.GetNumPlatforms(), initial_num_platforms + 1) 3899451b44SJordan Rupprecht platform_found = False 3999451b44SJordan Rupprecht for platform_idx in range(self.dbg.GetNumPlatforms()): 4099451b44SJordan Rupprecht platform = self.dbg.GetPlatformAtIndex(platform_idx) 4199451b44SJordan Rupprecht if platform.GetName() == platform_name: 4299451b44SJordan Rupprecht platform_found = True 4399451b44SJordan Rupprecht break 4499451b44SJordan Rupprecht self.assertTrue(platform_found) 4599451b44SJordan Rupprecht 46*2238dcc3SJonas Devlieghere @add_test_categories(["pyapi"]) 4799451b44SJordan Rupprecht @no_debug_info_test 4899451b44SJordan Rupprecht def test_host_is_connected(self): 4999451b44SJordan Rupprecht # We've already tested that this one IS the host platform. 5099451b44SJordan Rupprecht host_platform = self.dbg.GetPlatformAtIndex(0) 51*2238dcc3SJonas Devlieghere self.assertTrue( 52*2238dcc3SJonas Devlieghere host_platform.IsConnected(), "The host platform is always connected" 53*2238dcc3SJonas Devlieghere ) 5499451b44SJordan Rupprecht 55*2238dcc3SJonas Devlieghere @add_test_categories(["pyapi"]) 5699451b44SJordan Rupprecht @no_debug_info_test 5799451b44SJordan Rupprecht def test_available_platform_list(self): 5899451b44SJordan Rupprecht """Test SBDebugger::GetNumAvailablePlatforms() and GetAvailablePlatformInfoAtIndex() API""" 5999451b44SJordan Rupprecht num_platforms = self.dbg.GetNumAvailablePlatforms() 6099451b44SJordan Rupprecht self.assertGreater( 61*2238dcc3SJonas Devlieghere num_platforms, 0, "There should be at least one platform available" 62*2238dcc3SJonas Devlieghere ) 6399451b44SJordan Rupprecht 6499451b44SJordan Rupprecht for i in range(num_platforms): 6599451b44SJordan Rupprecht platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(i) 66*2238dcc3SJonas Devlieghere name_data = platform_data.GetValueForKey("name") 67*2238dcc3SJonas Devlieghere desc_data = platform_data.GetValueForKey("description") 68*2238dcc3SJonas Devlieghere self.assertTrue(name_data and name_data.IsValid(), "Platform has a name") 6999451b44SJordan Rupprecht self.assertEqual( 70*2238dcc3SJonas Devlieghere name_data.GetType(), 71*2238dcc3SJonas Devlieghere lldb.eStructuredDataTypeString, 72*2238dcc3SJonas Devlieghere "Platform name is a string", 73*2238dcc3SJonas Devlieghere ) 7499451b44SJordan Rupprecht self.assertTrue( 75*2238dcc3SJonas Devlieghere desc_data and desc_data.IsValid(), "Platform has a description" 76*2238dcc3SJonas Devlieghere ) 7799451b44SJordan Rupprecht self.assertEqual( 78*2238dcc3SJonas Devlieghere desc_data.GetType(), 79*2238dcc3SJonas Devlieghere lldb.eStructuredDataTypeString, 80*2238dcc3SJonas Devlieghere "Platform description is a string", 81*2238dcc3SJonas Devlieghere ) 82addb5148SMed Ismail Bennani 83*2238dcc3SJonas Devlieghere @add_test_categories(["pyapi"]) 84addb5148SMed Ismail Bennani @no_debug_info_test 8566b829acSJonas Devlieghere @skipIfRemote 86addb5148SMed Ismail Bennani def test_shell_interpreter(self): 87addb5148SMed Ismail Bennani """Test a shell with a custom interpreter""" 88addb5148SMed Ismail Bennani platform = self.dbg.GetSelectedPlatform() 89addb5148SMed Ismail Bennani self.assertTrue(platform.IsValid()) 90addb5148SMed Ismail Bennani 91*2238dcc3SJonas Devlieghere sh_cmd = lldb.SBPlatformShellCommand("/bin/zsh", "echo $0") 92*2238dcc3SJonas Devlieghere self.assertIn("/bin/zsh", sh_cmd.GetShell()) 93*2238dcc3SJonas Devlieghere self.assertIn("echo $0", sh_cmd.GetCommand()) 94addb5148SMed Ismail Bennani 95addb5148SMed Ismail Bennani self.build() 96*2238dcc3SJonas Devlieghere sh_cmd.SetShell(self.getBuildArtifact("a.out")) 97addb5148SMed Ismail Bennani err = platform.Run(sh_cmd) 98779bbbf2SDave Lee self.assertSuccess(err) 99addb5148SMed Ismail Bennani self.assertIn("SUCCESS", sh_cmd.GetOutput()) 100