199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest some lldb platform commands. 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 PlatformCommandTestCase(TestBase): 13addb5148SMed Ismail Bennani NO_DEBUG_INFO_TESTCASE = True 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprecht @no_debug_info_test 1699451b44SJordan Rupprecht def test_help_platform(self): 1799451b44SJordan Rupprecht self.runCmd("help platform") 1899451b44SJordan Rupprecht 1999451b44SJordan Rupprecht @no_debug_info_test 20091e760cSDavid Spickett def test_help_shell_alias(self): 21*2238dcc3SJonas Devlieghere self.expect( 22*2238dcc3SJonas Devlieghere "help shell", 23*2238dcc3SJonas Devlieghere substrs=[ 24*2238dcc3SJonas Devlieghere "Run a shell command on the host.", 25091e760cSDavid Spickett "shell <shell-command>", 26*2238dcc3SJonas Devlieghere "'shell' is an abbreviation", 27*2238dcc3SJonas Devlieghere ], 28*2238dcc3SJonas Devlieghere ) 29091e760cSDavid Spickett # "platform shell" has options. The "shell" alias for it does not. 30091e760cSDavid Spickett self.expect("help shell", substrs=["Command Options:"], matching=False) 314e9e0488SMed Ismail Bennani 324e9e0488SMed Ismail Bennani @no_debug_info_test 3399451b44SJordan Rupprecht def test_list(self): 34*2238dcc3SJonas Devlieghere self.expect("platform list", patterns=["^Available platforms:"]) 3599451b44SJordan Rupprecht 3699451b44SJordan Rupprecht @no_debug_info_test 3799451b44SJordan Rupprecht def test_process_list(self): 38*2238dcc3SJonas Devlieghere self.expect("platform process list", substrs=["PID", "TRIPLE", "NAME"]) 3999451b44SJordan Rupprecht 4099451b44SJordan Rupprecht @no_debug_info_test 4199451b44SJordan Rupprecht def test_process_info_with_no_arg(self): 4299451b44SJordan Rupprecht """This is expected to fail and to return a proper error message.""" 43*2238dcc3SJonas Devlieghere self.expect( 44*2238dcc3SJonas Devlieghere "platform process info", 45*2238dcc3SJonas Devlieghere error=True, 46*2238dcc3SJonas Devlieghere substrs=["one or more process id(s) must be specified"], 47*2238dcc3SJonas Devlieghere ) 4899451b44SJordan Rupprecht 4999451b44SJordan Rupprecht @no_debug_info_test 5099451b44SJordan Rupprecht def test_status(self): 5199451b44SJordan Rupprecht self.expect( 5299451b44SJordan Rupprecht "platform status", 5399451b44SJordan Rupprecht substrs=[ 54*2238dcc3SJonas Devlieghere "Platform", 55*2238dcc3SJonas Devlieghere "Triple", 56*2238dcc3SJonas Devlieghere "OS Version", 57*2238dcc3SJonas Devlieghere "Hostname", 58*2238dcc3SJonas Devlieghere "Kernel", 59*2238dcc3SJonas Devlieghere ], 60*2238dcc3SJonas Devlieghere ) 6199451b44SJordan Rupprecht 6299451b44SJordan Rupprecht @expectedFailureAll(oslist=["windows"]) 6399451b44SJordan Rupprecht @no_debug_info_test 6499451b44SJordan Rupprecht def test_shell(self): 6599451b44SJordan Rupprecht """Test that the platform shell command can invoke ls.""" 6699451b44SJordan Rupprecht triple = self.dbg.GetSelectedPlatform().GetTriple() 6799451b44SJordan Rupprecht if re.match(".*-.*-windows", triple): 68*2238dcc3SJonas Devlieghere self.expect("platform shell dir c:\\", substrs=["Windows", "Program Files"]) 694e9e0488SMed Ismail Bennani self.expect("shell dir c:\\", substrs=["Windows", "Program Files"]) 7099451b44SJordan Rupprecht elif re.match(".*-.*-.*-android", triple): 71*2238dcc3SJonas Devlieghere self.expect("platform shell ls /", substrs=["cache", "dev", "system"]) 72*2238dcc3SJonas Devlieghere self.expect("shell ls /", substrs=["cache", "dev", "system"]) 7399451b44SJordan Rupprecht else: 7499451b44SJordan Rupprecht self.expect("platform shell ls /", substrs=["dev", "tmp", "usr"]) 754e9e0488SMed Ismail Bennani self.expect("shell ls /", substrs=["dev", "tmp", "usr"]) 7699451b44SJordan Rupprecht 7799451b44SJordan Rupprecht @no_debug_info_test 7899451b44SJordan Rupprecht def test_shell_builtin(self): 7999451b44SJordan Rupprecht """Test a shell built-in command (echo)""" 80*2238dcc3SJonas Devlieghere self.expect("platform shell echo hello lldb", substrs=["hello lldb"]) 81*2238dcc3SJonas Devlieghere self.expect("shell echo hello lldb", substrs=["hello lldb"]) 824e9e0488SMed Ismail Bennani 8399451b44SJordan Rupprecht @no_debug_info_test 8499451b44SJordan Rupprecht def test_shell_timeout(self): 8599451b44SJordan Rupprecht """Test a shell built-in command (sleep) that times out""" 864e9e0488SMed Ismail Bennani self.skipTest("Alias with option not supported by the command interpreter.") 87*2238dcc3SJonas Devlieghere self.expect( 88*2238dcc3SJonas Devlieghere "platform shell -t 1 -- sleep 15", 89*2238dcc3SJonas Devlieghere error=True, 90*2238dcc3SJonas Devlieghere substrs=["error: timed out waiting for shell command to complete"], 91*2238dcc3SJonas Devlieghere ) 92*2238dcc3SJonas Devlieghere self.expect( 93*2238dcc3SJonas Devlieghere "shell -t 1 -- sleep 3", 94*2238dcc3SJonas Devlieghere error=True, 95*2238dcc3SJonas Devlieghere substrs=["error: timed out waiting for shell command to complete"], 96*2238dcc3SJonas Devlieghere ) 97addb5148SMed Ismail Bennani 98addb5148SMed Ismail Bennani @no_debug_info_test 9966b829acSJonas Devlieghere @skipIfRemote 100addb5148SMed Ismail Bennani def test_host_shell_interpreter(self): 101addb5148SMed Ismail Bennani """Test the host platform shell with a different interpreter""" 102addb5148SMed Ismail Bennani self.build() 103*2238dcc3SJonas Devlieghere exe = self.getBuildArtifact("a.out") 104*2238dcc3SJonas Devlieghere self.expect( 105*2238dcc3SJonas Devlieghere "platform shell -h -s " + exe + " -- 'echo $0'", 106*2238dcc3SJonas Devlieghere substrs=["SUCCESS", "a.out"], 107*2238dcc3SJonas Devlieghere ) 108