108 lines · python
1"""2Test some lldb platform commands.3"""4 5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class PlatformCommandTestCase(TestBase):13 NO_DEBUG_INFO_TESTCASE = True14 15 @no_debug_info_test16 def test_help_platform(self):17 self.runCmd("help platform")18 19 @no_debug_info_test20 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_test33 def test_list(self):34 self.expect("platform list", patterns=["^Available platforms:"])35 36 @no_debug_info_test37 def test_process_list(self):38 self.expect("platform process list", substrs=["PID", "TRIPLE", "NAME"])39 40 @no_debug_info_test41 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_test50 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_test64 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_test78 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_test84 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_test99 @skipIfRemote100 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