xref: /llvm-project/lldb/test/API/commands/platform/basic/TestPlatformCommand.py (revision 99451b4453688a94c6014cac233d371ab4cc342d)
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_list(self):
23        self.expect("platform list",
24                    patterns=['^Available platforms:'])
25
26    @no_debug_info_test
27    def test_process_list(self):
28        self.expect("platform process list",
29                    substrs=['PID', 'TRIPLE', 'NAME'])
30
31    @no_debug_info_test
32    def test_process_info_with_no_arg(self):
33        """This is expected to fail and to return a proper error message."""
34        self.expect("platform process info", error=True,
35                    substrs=['one or more process id(s) must be specified'])
36
37    @no_debug_info_test
38    def test_status(self):
39        self.expect(
40            "platform status",
41            substrs=[
42                'Platform',
43                'Triple',
44                'OS Version',
45                'Hostname',
46                'Kernel',
47            ])
48
49    @expectedFailureAll(oslist=["windows"])
50    @no_debug_info_test
51    def test_shell(self):
52        """ Test that the platform shell command can invoke ls. """
53        triple = self.dbg.GetSelectedPlatform().GetTriple()
54        if re.match(".*-.*-windows", triple):
55            self.expect(
56                "platform shell dir c:\\", substrs=[
57                    "Windows", "Program Files"])
58        elif re.match(".*-.*-.*-android", triple):
59            self.expect(
60                "platform shell ls /",
61                substrs=[
62                    "cache",
63                    "dev",
64                    "system"])
65        else:
66            self.expect("platform shell ls /", substrs=["dev", "tmp", "usr"])
67
68    @no_debug_info_test
69    def test_shell_builtin(self):
70        """ Test a shell built-in command (echo) """
71        self.expect("platform shell echo hello lldb",
72                    substrs=["hello lldb"])
73
74    # FIXME: re-enable once platform shell -t can specify the desired timeout
75    @no_debug_info_test
76    def test_shell_timeout(self):
77        """ Test a shell built-in command (sleep) that times out """
78        self.skipTest("due to taking too long to complete.")
79        self.expect("platform shell sleep 15", error=True, substrs=[
80                    "error: timed out waiting for shell command to complete"])
81