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