blob: ac8d380850ef5933ac03021203f99ef4cfa1e620 [file] [log] [blame]
Caroline Tice8607f032011-01-29 00:19:53 +00001"""
2Test lldb logging.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class LogTestCase(TestBase):
11
12 mydir = "logging"
13
14 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
15 def test_with_dsym (self):
16 self.buildDsym ()
Johnny Chenec1ccca2011-01-29 00:52:54 +000017 self.command_log_tests ("dsym")
Caroline Tice8607f032011-01-29 00:19:53 +000018
19 def test_with_dwarf (self):
20 self.buildDwarf ()
Johnny Chenec1ccca2011-01-29 00:52:54 +000021 self.command_log_tests ("dwarf")
Caroline Tice8607f032011-01-29 00:19:53 +000022
Johnny Chenec1ccca2011-01-29 00:52:54 +000023 def command_log_tests (self, type):
Caroline Tice8607f032011-01-29 00:19:53 +000024 exe = os.path.join (os.getcwd(), "a.out")
25 self.expect("file " + exe,
26 patterns = [ "Current executable set to .*a.out" ])
27
Johnny Chene0ec9ea2011-03-04 01:35:22 +000028 log_file = os.path.join (os.getcwd(), "lldb-commands-log-%s-%s-%s.txt" % (type,
29 self.getCompiler(),
30 self.getArchitecture()))
Caroline Tice8607f032011-01-29 00:19:53 +000031
32 if (os.path.exists (log_file)):
33 os.remove (log_file)
34
35 self.runCmd ("log enable lldb commands -f " + log_file)
36
Johnny Chen72c40822011-04-21 20:55:57 +000037 self.runCmd ("command alias bp breakpoint")
Caroline Tice8607f032011-01-29 00:19:53 +000038
39 self.runCmd ("bp set -n main")
40
41 self.runCmd ("bp l")
42
43 expected_log_lines = [
Johnny Chen72c40822011-04-21 20:55:57 +000044 "com.apple.main-thread Processing command: command alias bp breakpoint\n",
45 "com.apple.main-thread HandleCommand, cmd_obj : 'command alias'\n",
46 "com.apple.main-thread HandleCommand, revised_command_line: 'command alias bp breakpoint'\n",
Caroline Tice8607f032011-01-29 00:19:53 +000047 "com.apple.main-thread HandleCommand, wants_raw_input:'True'\n",
48 "com.apple.main-thread HandleCommand, command line after removing command name(s): 'bp breakpoint'\n",
49 "\n",
50 "com.apple.main-thread Processing command: bp set -n main\n",
51 "com.apple.main-thread HandleCommand, cmd_obj : 'breakpoint set'\n",
52 "com.apple.main-thread HandleCommand, revised_command_line: 'breakpoint set -n main'\n",
53 "com.apple.main-thread HandleCommand, wants_raw_input:'False'\n",
54 "com.apple.main-thread HandleCommand, command line after removing command name(s): '-n main'\n",
55 "\n",
56 "com.apple.main-thread Processing command: bp l\n",
57 "com.apple.main-thread HandleCommand, cmd_obj : 'breakpoint list'\n",
58 "com.apple.main-thread HandleCommand, revised_command_line: 'breakpoint l'\n",
59 "com.apple.main-thread HandleCommand, wants_raw_input:'False'\n",
60 "com.apple.main-thread HandleCommand, command line after removing command name(s): ''\n",
61 "\n"
62 ]
63
64 self.assertTrue (os.path.isfile (log_file))
65
66 idx = 0
67 end = len (expected_log_lines)
68 f = open (log_file)
69 log_lines = f.readlines()
70 f.close ()
Johnny Chenec1ccca2011-01-29 00:52:54 +000071 self.runCmd("log disable lldb")
Caroline Tice8607f032011-01-29 00:19:53 +000072 os.remove (log_file)
73
74 err_msg = ""
75 success = True
76
77 if len (log_lines) != len (expected_log_lines):
78 success = False
79 err_msg = "Wrong number of lines in log file; expected: " + repr (len (expected_log_lines)) + " found: " + repr(len (log_lines))
80 else:
81 for line1, line2 in zip (log_lines, expected_log_lines):
82 if line1 != line2:
83 success = False
84 err_msg = "Expected '" + line2 + "'; Found '" + line1 + "'"
85 break
86
87 if not success:
88 self.fail (err_msg)
89
90
91if __name__ == '__main__':
92 import atexit
93 lldb.SBDebugger.Initialize()
94 atexit.register(lambda: lldb.SBDebugger.Terminate())
95 unittest2.main()
96