Johnny Chen | c640179 | 2011-03-30 21:19:59 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test some lldb platform commands. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class PlatformCommandTestCase(TestBase): |
| 11 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 12 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | c640179 | 2011-03-30 21:19:59 +0000 | [diff] [blame] | 13 | |
| 14 | def test_help_platform(self): |
| 15 | self.runCmd("help platform") |
| 16 | |
| 17 | def test_list(self): |
| 18 | self.expect("platform list", |
| 19 | patterns = ['^Available platforms:']) |
| 20 | |
| 21 | def test_process_list(self): |
| 22 | self.expect("platform process list", |
Jason Molenda | 75906f4 | 2014-10-02 06:17:15 +0000 | [diff] [blame] | 23 | substrs = ['PID', 'TRIPLE', 'NAME']) |
Johnny Chen | c640179 | 2011-03-30 21:19:59 +0000 | [diff] [blame] | 24 | |
Johnny Chen | fa92ecc | 2011-05-09 20:51:47 +0000 | [diff] [blame] | 25 | def test_process_info_with_no_arg(self): |
| 26 | """This is expected to fail and to return a proper error message.""" |
| 27 | self.expect("platform process info", error=True, |
| 28 | substrs = ['one or more process id(s) must be specified']) |
| 29 | |
Johnny Chen | c640179 | 2011-03-30 21:19:59 +0000 | [diff] [blame] | 30 | def test_status(self): |
| 31 | self.expect("platform status", |
| 32 | substrs = ['Platform', 'Triple', 'OS Version', 'Kernel', 'Hostname']) |
| 33 | |
Daniel Malea | bb247fb | 2013-08-27 21:01:01 +0000 | [diff] [blame] | 34 | def test_shell(self): |
| 35 | """ Test that the platform shell command can invoke ls. """ |
Zachary Turner | 57ee6d6 | 2014-12-08 21:50:05 +0000 | [diff] [blame^] | 36 | if sys.platform.startswith("win32"): |
| 37 | self.expect("platform shell dir c:\\", substrs = ["Windows", "Program Files"]) |
| 38 | else: |
| 39 | self.expect("platform shell ls /", substrs = ["dev", "tmp", "usr"]) |
Daniel Malea | bb247fb | 2013-08-27 21:01:01 +0000 | [diff] [blame] | 40 | |
| 41 | def test_shell_builtin(self): |
| 42 | """ Test a shell built-in command (echo) """ |
| 43 | self.expect("platform shell echo hello lldb", |
| 44 | substrs = ["hello lldb"]) |
| 45 | |
| 46 | #FIXME: re-enable once platform shell -t can specify the desired timeout |
| 47 | def test_shell_timeout(self): |
| 48 | """ Test a shell built-in command (sleep) that times out """ |
| 49 | self.skipTest("due to taking too long to complete.") |
| 50 | self.expect("platform shell sleep 15", error=True, |
| 51 | substrs = ["error: timed out waiting for shell command to complete"]) |
| 52 | |
Johnny Chen | c640179 | 2011-03-30 21:19:59 +0000 | [diff] [blame] | 53 | |
| 54 | if __name__ == '__main__': |
| 55 | import atexit |
| 56 | lldb.SBDebugger.Initialize() |
| 57 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 58 | unittest2.main() |