199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest some lldb platform commands.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprecht
1399451b44SJordan Rupprechtclass PlatformCommandTestCase(TestBase):
14addb5148SMed Ismail Bennani    NO_DEBUG_INFO_TESTCASE = True
1599451b44SJordan Rupprecht
1699451b44SJordan Rupprecht    @no_debug_info_test
1799451b44SJordan Rupprecht    def test_help_platform(self):
1899451b44SJordan Rupprecht        self.runCmd("help platform")
1999451b44SJordan Rupprecht
2099451b44SJordan Rupprecht    @no_debug_info_test
21091e760cSDavid Spickett    def test_help_shell_alias(self):
224e9e0488SMed Ismail Bennani        self.expect("help shell", substrs=["Run a shell command on the host.",
23091e760cSDavid Spickett                                           "shell <shell-command>",
24091e760cSDavid Spickett                                           "'shell' is an abbreviation"])
25091e760cSDavid Spickett        # "platform shell" has options. The "shell" alias for it does not.
26091e760cSDavid Spickett        self.expect("help shell", substrs=["Command Options:"], matching=False)
274e9e0488SMed Ismail Bennani
284e9e0488SMed Ismail Bennani    @no_debug_info_test
2999451b44SJordan Rupprecht    def test_list(self):
3099451b44SJordan Rupprecht        self.expect("platform list",
3199451b44SJordan Rupprecht                    patterns=['^Available platforms:'])
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht    @no_debug_info_test
3499451b44SJordan Rupprecht    def test_process_list(self):
3599451b44SJordan Rupprecht        self.expect("platform process list",
3699451b44SJordan Rupprecht                    substrs=['PID', 'TRIPLE', 'NAME'])
3799451b44SJordan Rupprecht
3899451b44SJordan Rupprecht    @no_debug_info_test
3999451b44SJordan Rupprecht    def test_process_info_with_no_arg(self):
4099451b44SJordan Rupprecht        """This is expected to fail and to return a proper error message."""
4199451b44SJordan Rupprecht        self.expect("platform process info", error=True,
4299451b44SJordan Rupprecht                    substrs=['one or more process id(s) must be specified'])
4399451b44SJordan Rupprecht
4499451b44SJordan Rupprecht    @no_debug_info_test
4599451b44SJordan Rupprecht    def test_status(self):
4699451b44SJordan Rupprecht        self.expect(
4799451b44SJordan Rupprecht            "platform status",
4899451b44SJordan Rupprecht            substrs=[
4999451b44SJordan Rupprecht                'Platform',
5099451b44SJordan Rupprecht                'Triple',
5199451b44SJordan Rupprecht                'OS Version',
5299451b44SJordan Rupprecht                'Hostname',
5399451b44SJordan Rupprecht                'Kernel',
5499451b44SJordan Rupprecht            ])
5599451b44SJordan Rupprecht
5699451b44SJordan Rupprecht    @expectedFailureAll(oslist=["windows"])
5799451b44SJordan Rupprecht    @no_debug_info_test
5899451b44SJordan Rupprecht    def test_shell(self):
5999451b44SJordan Rupprecht        """ Test that the platform shell command can invoke ls. """
6099451b44SJordan Rupprecht        triple = self.dbg.GetSelectedPlatform().GetTriple()
6199451b44SJordan Rupprecht        if re.match(".*-.*-windows", triple):
6299451b44SJordan Rupprecht            self.expect(
6399451b44SJordan Rupprecht                "platform shell dir c:\\", substrs=[
6499451b44SJordan Rupprecht                    "Windows", "Program Files"])
654e9e0488SMed Ismail Bennani            self.expect("shell dir c:\\", substrs=["Windows", "Program Files"])
6699451b44SJordan Rupprecht        elif re.match(".*-.*-.*-android", triple):
6799451b44SJordan Rupprecht            self.expect(
6899451b44SJordan Rupprecht                "platform shell ls /",
6999451b44SJordan Rupprecht                substrs=[
7099451b44SJordan Rupprecht                    "cache",
7199451b44SJordan Rupprecht                    "dev",
7299451b44SJordan Rupprecht                    "system"])
734e9e0488SMed Ismail Bennani            self.expect("shell ls /",
744e9e0488SMed Ismail Bennani                substrs=["cache", "dev", "system"])
7599451b44SJordan Rupprecht        else:
7699451b44SJordan Rupprecht            self.expect("platform shell ls /", substrs=["dev", "tmp", "usr"])
774e9e0488SMed Ismail Bennani            self.expect("shell ls /", substrs=["dev", "tmp", "usr"])
7899451b44SJordan Rupprecht
7999451b44SJordan Rupprecht    @no_debug_info_test
8099451b44SJordan Rupprecht    def test_shell_builtin(self):
8199451b44SJordan Rupprecht        """ Test a shell built-in command (echo) """
8299451b44SJordan Rupprecht        self.expect("platform shell echo hello lldb",
8399451b44SJordan Rupprecht                    substrs=["hello lldb"])
844e9e0488SMed Ismail Bennani        self.expect("shell echo hello lldb",
854e9e0488SMed Ismail Bennani                    substrs=["hello lldb"])
8699451b44SJordan Rupprecht
874e9e0488SMed Ismail Bennani
8899451b44SJordan Rupprecht    @no_debug_info_test
8999451b44SJordan Rupprecht    def test_shell_timeout(self):
9099451b44SJordan Rupprecht        """ Test a shell built-in command (sleep) that times out """
914e9e0488SMed Ismail Bennani        self.skipTest("Alias with option not supported by the command interpreter.")
924e9e0488SMed Ismail Bennani        self.expect("platform shell -t 1 -- sleep 15", error=True, substrs=[
934e9e0488SMed Ismail Bennani                    "error: timed out waiting for shell command to complete"])
944e9e0488SMed Ismail Bennani        self.expect("shell -t 1 --  sleep 3", error=True, substrs=[
9599451b44SJordan Rupprecht                    "error: timed out waiting for shell command to complete"])
96addb5148SMed Ismail Bennani
97addb5148SMed Ismail Bennani    @no_debug_info_test
98*66b829acSJonas Devlieghere    @skipIfRemote
99addb5148SMed Ismail Bennani    def test_host_shell_interpreter(self):
100addb5148SMed Ismail Bennani        """ Test the host platform shell with a different interpreter """
101addb5148SMed Ismail Bennani        self.build()
102addb5148SMed Ismail Bennani        exe = self.getBuildArtifact('a.out')
103addb5148SMed Ismail Bennani        self.expect("platform shell -h -s " + exe + " -- 'echo $0'",
104addb5148SMed Ismail Bennani                    substrs=['SUCCESS', 'a.out'])
105