1"""
2Test some lldb platform commands.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class PlatformCommandTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    @no_debug_info_test
18    def test_help_platform(self):
19        self.runCmd("help platform")
20
21    @no_debug_info_test
22    def test_help_platform(self):
23        self.expect("help shell", substrs=["Run a shell command on the host.",
24                                           "shell <shell-command>"])
25
26
27    @no_debug_info_test
28    def test_list(self):
29        self.expect("platform list",
30                    patterns=['^Available platforms:'])
31
32    @no_debug_info_test
33    def test_process_list(self):
34        self.expect("platform process list",
35                    substrs=['PID', 'TRIPLE', 'NAME'])
36
37    @no_debug_info_test
38    def test_process_info_with_no_arg(self):
39        """This is expected to fail and to return a proper error message."""
40        self.expect("platform process info", error=True,
41                    substrs=['one or more process id(s) must be specified'])
42
43    @no_debug_info_test
44    def test_status(self):
45        self.expect(
46            "platform status",
47            substrs=[
48                'Platform',
49                'Triple',
50                'OS Version',
51                'Hostname',
52                'Kernel',
53            ])
54
55    @expectedFailureAll(oslist=["windows"])
56    @no_debug_info_test
57    def test_shell(self):
58        """ Test that the platform shell command can invoke ls. """
59        triple = self.dbg.GetSelectedPlatform().GetTriple()
60        if re.match(".*-.*-windows", triple):
61            self.expect(
62                "platform shell dir c:\\", substrs=[
63                    "Windows", "Program Files"])
64            self.expect("shell dir c:\\", substrs=["Windows", "Program Files"])
65        elif re.match(".*-.*-.*-android", triple):
66            self.expect(
67                "platform shell ls /",
68                substrs=[
69                    "cache",
70                    "dev",
71                    "system"])
72            self.expect("shell ls /",
73                substrs=["cache", "dev", "system"])
74        else:
75            self.expect("platform shell ls /", substrs=["dev", "tmp", "usr"])
76            self.expect("shell ls /", substrs=["dev", "tmp", "usr"])
77
78    @no_debug_info_test
79    def test_shell_builtin(self):
80        """ Test a shell built-in command (echo) """
81        self.expect("platform shell echo hello lldb",
82                    substrs=["hello lldb"])
83        self.expect("shell echo hello lldb",
84                    substrs=["hello lldb"])
85
86
87    @no_debug_info_test
88    def test_shell_timeout(self):
89        """ Test a shell built-in command (sleep) that times out """
90        self.skipTest("Alias with option not supported by the command interpreter.")
91        self.expect("platform shell -t 1 -- sleep 15", error=True, substrs=[
92                    "error: timed out waiting for shell command to complete"])
93        self.expect("shell -t 1 --  sleep 3", error=True, substrs=[
94                    "error: timed out waiting for shell command to complete"])
95