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