Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb logging. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class LogTestCase(TestBase): |
| 11 | |
| 12 | mydir = "logging" |
| 13 | |
| 14 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame^] | 15 | @dsym_test |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 16 | def test_with_dsym (self): |
| 17 | self.buildDsym () |
Johnny Chen | ec1ccca | 2011-01-29 00:52:54 +0000 | [diff] [blame] | 18 | self.command_log_tests ("dsym") |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 19 | |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame^] | 20 | @dwarf_test |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 21 | def test_with_dwarf (self): |
| 22 | self.buildDwarf () |
Johnny Chen | ec1ccca | 2011-01-29 00:52:54 +0000 | [diff] [blame] | 23 | self.command_log_tests ("dwarf") |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 24 | |
Johnny Chen | ec1ccca | 2011-01-29 00:52:54 +0000 | [diff] [blame] | 25 | def command_log_tests (self, type): |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 26 | exe = os.path.join (os.getcwd(), "a.out") |
| 27 | self.expect("file " + exe, |
| 28 | patterns = [ "Current executable set to .*a.out" ]) |
| 29 | |
Johnny Chen | e0ec9ea | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 30 | log_file = os.path.join (os.getcwd(), "lldb-commands-log-%s-%s-%s.txt" % (type, |
| 31 | self.getCompiler(), |
| 32 | self.getArchitecture())) |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 33 | |
| 34 | if (os.path.exists (log_file)): |
| 35 | os.remove (log_file) |
| 36 | |
| 37 | self.runCmd ("log enable lldb commands -f " + log_file) |
| 38 | |
Johnny Chen | 72c4082 | 2011-04-21 20:55:57 +0000 | [diff] [blame] | 39 | self.runCmd ("command alias bp breakpoint") |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 40 | |
| 41 | self.runCmd ("bp set -n main") |
| 42 | |
| 43 | self.runCmd ("bp l") |
| 44 | |
| 45 | expected_log_lines = [ |
Johnny Chen | 72c4082 | 2011-04-21 20:55:57 +0000 | [diff] [blame] | 46 | "com.apple.main-thread Processing command: command alias bp breakpoint\n", |
| 47 | "com.apple.main-thread HandleCommand, cmd_obj : 'command alias'\n", |
| 48 | "com.apple.main-thread HandleCommand, revised_command_line: 'command alias bp breakpoint'\n", |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 49 | "com.apple.main-thread HandleCommand, wants_raw_input:'True'\n", |
| 50 | "com.apple.main-thread HandleCommand, command line after removing command name(s): 'bp breakpoint'\n", |
Johnny Chen | 6890537 | 2011-08-25 21:51:45 +0000 | [diff] [blame] | 51 | "com.apple.main-thread HandleCommand, command succeeded\n", |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 52 | "com.apple.main-thread Processing command: bp set -n main\n", |
| 53 | "com.apple.main-thread HandleCommand, cmd_obj : 'breakpoint set'\n", |
| 54 | "com.apple.main-thread HandleCommand, revised_command_line: 'breakpoint set -n main'\n", |
| 55 | "com.apple.main-thread HandleCommand, wants_raw_input:'False'\n", |
| 56 | "com.apple.main-thread HandleCommand, command line after removing command name(s): '-n main'\n", |
Johnny Chen | 6890537 | 2011-08-25 21:51:45 +0000 | [diff] [blame] | 57 | "com.apple.main-thread HandleCommand, command succeeded\n", |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 58 | "com.apple.main-thread Processing command: bp l\n", |
| 59 | "com.apple.main-thread HandleCommand, cmd_obj : 'breakpoint list'\n", |
| 60 | "com.apple.main-thread HandleCommand, revised_command_line: 'breakpoint l'\n", |
| 61 | "com.apple.main-thread HandleCommand, wants_raw_input:'False'\n", |
| 62 | "com.apple.main-thread HandleCommand, command line after removing command name(s): ''\n", |
Johnny Chen | 6890537 | 2011-08-25 21:51:45 +0000 | [diff] [blame] | 63 | "com.apple.main-thread HandleCommand, command succeeded\n", |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 64 | ] |
| 65 | |
| 66 | self.assertTrue (os.path.isfile (log_file)) |
| 67 | |
| 68 | idx = 0 |
| 69 | end = len (expected_log_lines) |
| 70 | f = open (log_file) |
| 71 | log_lines = f.readlines() |
| 72 | f.close () |
Johnny Chen | ec1ccca | 2011-01-29 00:52:54 +0000 | [diff] [blame] | 73 | self.runCmd("log disable lldb") |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 74 | os.remove (log_file) |
| 75 | |
| 76 | err_msg = "" |
| 77 | success = True |
| 78 | |
| 79 | if len (log_lines) != len (expected_log_lines): |
| 80 | success = False |
| 81 | err_msg = "Wrong number of lines in log file; expected: " + repr (len (expected_log_lines)) + " found: " + repr(len (log_lines)) |
| 82 | else: |
| 83 | for line1, line2 in zip (log_lines, expected_log_lines): |
| 84 | if line1 != line2: |
| 85 | success = False |
| 86 | err_msg = "Expected '" + line2 + "'; Found '" + line1 + "'" |
| 87 | break |
| 88 | |
| 89 | if not success: |
| 90 | self.fail (err_msg) |
| 91 | |
| 92 | |
| 93 | if __name__ == '__main__': |
| 94 | import atexit |
| 95 | lldb.SBDebugger.Initialize() |
| 96 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 97 | unittest2.main() |
| 98 | |