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 | |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 21 | def version_number_string(self): |
| 22 | """Helper function to find the version number string of lldb.""" |
| 23 | plist = os.path.join(os.getcwd(), os.pardir, os.pardir, "resources", "LLDB-info.plist") |
| 24 | try: |
| 25 | CFBundleVersionSegFound = False |
| 26 | with open(plist, 'r') as f: |
| 27 | for line in f: |
| 28 | if CFBundleVersionSegFound: |
| 29 | version_line = line.strip() |
| 30 | import re |
| 31 | m = re.match("<string>(.*)</string>", version_line) |
| 32 | if m: |
| 33 | version = m.group(1) |
| 34 | return version |
| 35 | else: |
| 36 | # Unsuccessful, let's juts break out of the for loop. |
| 37 | break |
| 38 | |
| 39 | if line.find("<key>CFBundleVersion</key>") != -1: |
| 40 | # Found our match. The next line contains our version |
| 41 | # string, for example: |
| 42 | # |
| 43 | # <string>38</string> |
| 44 | CFBundleVersionSegFound = True |
| 45 | |
| 46 | except: |
| 47 | # Just fallthrough... |
Johnny Chen | b13ee84 | 2011-01-07 00:17:44 +0000 | [diff] [blame] | 48 | import traceback |
| 49 | traceback.print_exc() |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 50 | pass |
| 51 | |
| 52 | # Use None to signify that we are not able to grok the version number. |
| 53 | return None |
| 54 | |
| 55 | |
Johnny Chen | 31c39da | 2010-12-23 20:21:44 +0000 | [diff] [blame] | 56 | def test_help_version(self): |
| 57 | """Test 'help version' and 'version' commands.""" |
| 58 | self.expect("help version", |
| 59 | substrs = ['Show version of LLDB debugger.']) |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 60 | version_str = self.version_number_string() |
Johnny Chen | 31c39da | 2010-12-23 20:21:44 +0000 | [diff] [blame] | 61 | self.expect("version", |
Johnny Chen | 8493989 | 2011-01-06 00:03:01 +0000 | [diff] [blame] | 62 | patterns = ['LLDB-' + (version_str if version_str else '[0-9]+')]) |
Johnny Chen | 31c39da | 2010-12-23 20:21:44 +0000 | [diff] [blame] | 63 | |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 64 | def test_help_should_not_hang_emacsshell(self): |
Johnny Chen | ecf9ded | 2010-09-07 16:19:35 +0000 | [diff] [blame] | 65 | """Command 'settings set term-width 0' should not hang the help command.""" |
| 66 | self.runCmd("settings set term-width 0") |
Johnny Chen | 74f26b8 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 67 | self.expect("help", |
| 68 | startstr = 'The following is a list of built-in, permanent debugger commands') |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 69 | |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 70 | def test_help_image_dump_symtab_should_not_crash(self): |
| 71 | """Command 'help image dump symtab' should not crash lldb.""" |
Johnny Chen | 24f3490 | 2011-05-03 23:55:05 +0000 | [diff] [blame^] | 72 | # 'image' is an alias for 'target modules'. |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 73 | self.expect("help image dump symtab", |
Johnny Chen | 5aceec3 | 2011-05-03 23:18:45 +0000 | [diff] [blame] | 74 | substrs = ['dump symtab', |
Johnny Chen | 65045f2 | 2010-10-08 17:21:27 +0000 | [diff] [blame] | 75 | 'sort-order']) |
| 76 | |
Johnny Chen | 5237e90 | 2010-12-01 19:10:59 +0000 | [diff] [blame] | 77 | def test_help_image_du_sym_is_ambiguous(self): |
| 78 | """Command 'help image du sym' is ambiguous and spits out the list of candidates.""" |
| 79 | self.expect("help image du sym", |
| 80 | COMMAND_FAILED_AS_EXPECTED, error=True, |
| 81 | substrs = ['error: ambiguous command image du sym', |
| 82 | 'symfile', |
| 83 | 'symtab']) |
| 84 | |
| 85 | def test_help_image_du_line_should_work(self): |
| 86 | """Command 'help image du line' is not ambiguous and should work.""" |
Johnny Chen | 24f3490 | 2011-05-03 23:55:05 +0000 | [diff] [blame^] | 87 | # 'image' is an alias for 'target modules'. |
Johnny Chen | 5237e90 | 2010-12-01 19:10:59 +0000 | [diff] [blame] | 88 | self.expect("help image du line", |
Johnny Chen | 5aceec3 | 2011-05-03 23:18:45 +0000 | [diff] [blame] | 89 | substrs = ['Dump the debug symbol file for one or more target modules']) |
Johnny Chen | 5237e90 | 2010-12-01 19:10:59 +0000 | [diff] [blame] | 90 | |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 91 | |
| 92 | if __name__ == '__main__': |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 93 | import atexit |
Johnny Chen | 4657be6 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 94 | lldb.SBDebugger.Initialize() |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 95 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 96 | unittest2.main() |