Johnny Chen | 7f5f280 | 2010-08-02 21:26:00 +0000 | [diff] [blame] | 1 | """ |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 2 | Test some lldb help commands. |
Johnny Chen | 7f5f280 | 2010-08-02 21:26:00 +0000 | [diff] [blame] | 3 | |
| 4 | See also CommandInterpreter::OutputFormattedHelpText(). |
| 5 | """ |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 6 | |
Johnny Chen | 8c3f918 | 2010-07-01 00:18:39 +0000 | [diff] [blame] | 7 | import os, time |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 8 | import unittest2 |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 9 | import lldb |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 10 | from lldbtest import * |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 11 | |
Johnny Chen | cbb4be0 | 2010-09-01 19:59:58 +0000 | [diff] [blame] | 12 | class HelpCommandTestCase(TestBase): |
Johnny Chen | 119b53e | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 13 | |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 14 | mydir = "help" |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 15 | |
| 16 | def test_simplehelp(self): |
| 17 | """A simple test of 'help' command and its output.""" |
Johnny Chen | 74f26b8 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 18 | self.expect("help", |
| 19 | startstr = 'The following is a list of built-in, permanent debugger commands') |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 20 | |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 21 | self.expect("help", matching=False, |
| 22 | substrs = ['next']) |
| 23 | |
| 24 | self.expect("help -a", matching=True, |
| 25 | substrs = ['next']) |
| 26 | |
| 27 | def test_help_on_help(self): |
| 28 | """Testing the help on the help facility.""" |
| 29 | self.expect("help help", matching=True, |
| 30 | substrs = ['--show-aliases', |
| 31 | '--hide-user-commands']) |
| 32 | |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 33 | def version_number_string(self): |
| 34 | """Helper function to find the version number string of lldb.""" |
Peter Collingbourne | d6824de | 2011-06-20 19:06:45 +0000 | [diff] [blame] | 35 | plist = os.path.join(os.environ["LLDB_SRC"], "resources", "LLDB-Info.plist") |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 36 | try: |
| 37 | CFBundleVersionSegFound = False |
| 38 | with open(plist, 'r') as f: |
| 39 | for line in f: |
| 40 | if CFBundleVersionSegFound: |
| 41 | version_line = line.strip() |
| 42 | import re |
| 43 | m = re.match("<string>(.*)</string>", version_line) |
| 44 | if m: |
| 45 | version = m.group(1) |
| 46 | return version |
| 47 | else: |
| 48 | # Unsuccessful, let's juts break out of the for loop. |
| 49 | break |
| 50 | |
| 51 | if line.find("<key>CFBundleVersion</key>") != -1: |
| 52 | # Found our match. The next line contains our version |
| 53 | # string, for example: |
| 54 | # |
| 55 | # <string>38</string> |
| 56 | CFBundleVersionSegFound = True |
| 57 | |
| 58 | except: |
| 59 | # Just fallthrough... |
Johnny Chen | b13ee84 | 2011-01-07 00:17:44 +0000 | [diff] [blame] | 60 | import traceback |
| 61 | traceback.print_exc() |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 62 | pass |
| 63 | |
| 64 | # Use None to signify that we are not able to grok the version number. |
| 65 | return None |
| 66 | |
| 67 | |
Johnny Chen | ca7835c | 2012-05-26 00:32:39 +0000 | [diff] [blame] | 68 | def test_help_arch(self): |
| 69 | """Test 'help arch' which should list of supported architectures.""" |
| 70 | self.expect("help arch", |
| 71 | substrs = ['arm', 'x86_64', 'i386']) |
| 72 | |
Johnny Chen | 31c39da | 2010-12-23 20:21:44 +0000 | [diff] [blame] | 73 | def test_help_version(self): |
| 74 | """Test 'help version' and 'version' commands.""" |
| 75 | self.expect("help version", |
| 76 | substrs = ['Show version of LLDB debugger.']) |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 77 | version_str = self.version_number_string() |
Johnny Chen | 4cd2a8e | 2011-08-26 23:50:10 +0000 | [diff] [blame] | 78 | import re |
| 79 | match = re.match('[0-9]+', version_str) |
Daniel Malea | 3b92f00 | 2013-02-28 16:51:15 +0000 | [diff] [blame] | 80 | if sys.platform.startswith("darwin"): |
Greg Clayton | 1a400cf | 2013-04-03 00:04:27 +0000 | [diff] [blame] | 81 | search_regexp = ['lldb-' + (version_str if match else '[0-9]+')] |
Daniel Malea | 3b92f00 | 2013-02-28 16:51:15 +0000 | [diff] [blame] | 82 | else: |
| 83 | search_regexp = ['lldb version (\d|\.)+.*$'] |
| 84 | |
Johnny Chen | 31c39da | 2010-12-23 20:21:44 +0000 | [diff] [blame] | 85 | self.expect("version", |
Daniel Malea | 3b92f00 | 2013-02-28 16:51:15 +0000 | [diff] [blame] | 86 | patterns = search_regexp) |
Johnny Chen | 31c39da | 2010-12-23 20:21:44 +0000 | [diff] [blame] | 87 | |
Johnny Chen | 331eff3 | 2011-07-14 22:20:12 +0000 | [diff] [blame] | 88 | def test_help_should_not_crash_lldb(self): |
| 89 | """Command 'help disasm' should not crash lldb.""" |
| 90 | self.runCmd("help disasm", check=False) |
| 91 | self.runCmd("help unsigned-integer") |
| 92 | |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 93 | def test_help_should_not_hang_emacsshell(self): |
Johnny Chen | ecf9ded | 2010-09-07 16:19:35 +0000 | [diff] [blame] | 94 | """Command 'settings set term-width 0' should not hang the help command.""" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 95 | self.expect("settings set term-width 0", |
| 96 | COMMAND_FAILED_AS_EXPECTED, error=True, |
| 97 | substrs = ['error: 0 is out of range, valid values must be between']) |
| 98 | # self.runCmd("settings set term-width 0") |
Johnny Chen | 74f26b8 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 99 | self.expect("help", |
| 100 | startstr = 'The following is a list of built-in, permanent debugger commands') |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 101 | |
Johnny Chen | 5ec8fcb | 2012-05-07 23:04:49 +0000 | [diff] [blame] | 102 | def test_help_breakpoint_set(self): |
| 103 | """Test that 'help breakpoint set' does not print out redundant lines of: |
| 104 | 'breakpoint set [-s <shlib-name>] ...'.""" |
| 105 | self.expect("help breakpoint set", matching=False, |
| 106 | substrs = ['breakpoint set [-s <shlib-name>]']) |
| 107 | |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 108 | def test_help_image_dump_symtab_should_not_crash(self): |
| 109 | """Command 'help image dump symtab' should not crash lldb.""" |
Johnny Chen | 24f3490 | 2011-05-03 23:55:05 +0000 | [diff] [blame] | 110 | # 'image' is an alias for 'target modules'. |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 111 | self.expect("help image dump symtab", |
Johnny Chen | 5aceec3 | 2011-05-03 23:18:45 +0000 | [diff] [blame] | 112 | substrs = ['dump symtab', |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 113 | 'sort-order']) |
| 114 | |
Johnny Chen | 5237e90 | 2010-12-01 19:10:59 +0000 | [diff] [blame] | 115 | def test_help_image_du_sym_is_ambiguous(self): |
| 116 | """Command 'help image du sym' is ambiguous and spits out the list of candidates.""" |
| 117 | self.expect("help image du sym", |
| 118 | COMMAND_FAILED_AS_EXPECTED, error=True, |
| 119 | substrs = ['error: ambiguous command image du sym', |
| 120 | 'symfile', |
| 121 | 'symtab']) |
| 122 | |
| 123 | def test_help_image_du_line_should_work(self): |
| 124 | """Command 'help image du line' is not ambiguous and should work.""" |
Johnny Chen | 24f3490 | 2011-05-03 23:55:05 +0000 | [diff] [blame] | 125 | # 'image' is an alias for 'target modules'. |
Johnny Chen | 5237e90 | 2010-12-01 19:10:59 +0000 | [diff] [blame] | 126 | self.expect("help image du line", |
Daniel Malea | e7322b3 | 2013-07-03 19:29:46 +0000 | [diff] [blame^] | 127 | substrs = ['Dump the line table for one or more compilation units']) |
Johnny Chen | 5237e90 | 2010-12-01 19:10:59 +0000 | [diff] [blame] | 128 | |
Johnny Chen | 81ab3f5 | 2011-08-22 22:22:00 +0000 | [diff] [blame] | 129 | def test_help_target_variable_syntax(self): |
| 130 | """Command 'help target variable' should display <variable-name> ...""" |
| 131 | self.expect("help target variable", |
| 132 | substrs = ['<variable-name> [<variable-name> [...]]']) |
| 133 | |
Johnny Chen | 84128e6 | 2011-09-23 17:57:49 +0000 | [diff] [blame] | 134 | def test_help_watchpoint_and_its_args(self): |
| 135 | """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work.""" |
| 136 | self.expect("help watchpoint", |
| 137 | substrs = ['delete', 'disable', 'enable', 'list']) |
| 138 | self.expect("help watchpt-id", |
| 139 | substrs = ['<watchpt-id>']) |
| 140 | self.expect("help watchpt-id-list", |
| 141 | substrs = ['<watchpt-id-list>']) |
| 142 | |
Johnny Chen | 34ddc8d | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 143 | def test_help_watchpoint_set(self): |
Johnny Chen | 2ffa754 | 2012-02-08 22:37:48 +0000 | [diff] [blame] | 144 | """Test that 'help watchpoint set' prints out 'expression' and 'variable' |
| 145 | as the possible subcommands.""" |
Johnny Chen | 34ddc8d | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 146 | self.expect("help watchpoint set", |
Johnny Chen | 2ffa754 | 2012-02-08 22:37:48 +0000 | [diff] [blame] | 147 | substrs = ['The following subcommands are supported:'], |
| 148 | patterns = ['expression +--', |
| 149 | 'variable +--']) |
Johnny Chen | 34ddc8d | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 150 | |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 151 | |
| 152 | if __name__ == '__main__': |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 153 | import atexit |
Johnny Chen | 4657be6 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 154 | lldb.SBDebugger.Initialize() |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 155 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 156 | unittest2.main() |