blob: 28cfb7669c14c05dc1ea1f5fafbabbbbd73c8542 [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")
Johnny Chen24086bc2012-04-06 19:54:10 +000015 @dsym_test
Caroline Tice8607f032011-01-29 00:19:53 +000016 def test_with_dsym (self):
17 self.buildDsym ()
Johnny Chenec1ccca2011-01-29 00:52:54 +000018 self.command_log_tests ("dsym")
Caroline Tice8607f032011-01-29 00:19:53 +000019
Johnny Chen24086bc2012-04-06 19:54:10 +000020 @dwarf_test
Caroline Tice8607f032011-01-29 00:19:53 +000021 def test_with_dwarf (self):
22 self.buildDwarf ()
Johnny Chenec1ccca2011-01-29 00:52:54 +000023 self.command_log_tests ("dwarf")
Caroline Tice8607f032011-01-29 00:19:53 +000024
Johnny Chenec1ccca2011-01-29 00:52:54 +000025 def command_log_tests (self, type):
Caroline Tice8607f032011-01-29 00:19:53 +000026 exe = os.path.join (os.getcwd(), "a.out")
27 self.expect("file " + exe,
28 patterns = [ "Current executable set to .*a.out" ])
29
Johnny Chene0ec9ea2011-03-04 01:35:22 +000030 log_file = os.path.join (os.getcwd(), "lldb-commands-log-%s-%s-%s.txt" % (type,
Greg Claytonc1b2ccf2013-01-08 00:01:36 +000031 os.path.basename(self.getCompiler()),
Johnny Chene0ec9ea2011-03-04 01:35:22 +000032 self.getArchitecture()))
Caroline Tice8607f032011-01-29 00:19:53 +000033
34 if (os.path.exists (log_file)):
35 os.remove (log_file)
36
Greg Claytonc1b2ccf2013-01-08 00:01:36 +000037 self.runCmd ("log enable -f '%s' lldb commands" % (log_file))
Caroline Tice8607f032011-01-29 00:19:53 +000038
Johnny Chen72c40822011-04-21 20:55:57 +000039 self.runCmd ("command alias bp breakpoint")
Caroline Tice8607f032011-01-29 00:19:53 +000040
41 self.runCmd ("bp set -n main")
42
43 self.runCmd ("bp l")
44
45 expected_log_lines = [
Daniel Maleab90c3682012-11-21 20:12:12 +000046 "Processing command: command alias bp breakpoint\n",
47 "HandleCommand, cmd_obj : 'command alias'\n",
48 "HandleCommand, revised_command_line: 'command alias bp breakpoint'\n",
49 "HandleCommand, wants_raw_input:'True'\n",
50 "HandleCommand, command line after removing command name(s): 'bp breakpoint'\n",
51 "HandleCommand, command succeeded\n",
52 "Processing command: bp set -n main\n",
53 "HandleCommand, cmd_obj : 'breakpoint set'\n",
54 "HandleCommand, revised_command_line: 'breakpoint set -n main'\n",
55 "HandleCommand, wants_raw_input:'False'\n",
56 "HandleCommand, command line after removing command name(s): '-n main'\n",
57 "HandleCommand, command succeeded\n",
58 "Processing command: bp l\n",
59 "HandleCommand, cmd_obj : 'breakpoint list'\n",
60 "HandleCommand, revised_command_line: 'breakpoint l'\n",
61 "HandleCommand, wants_raw_input:'False'\n",
62 "HandleCommand, command line after removing command name(s): ''\n",
63 "HandleCommand, command succeeded\n",
Caroline Tice8607f032011-01-29 00:19:53 +000064 ]
65
Daniel Maleab90c3682012-11-21 20:12:12 +000066 # com.apple.main-thread identifier appears on darwin only
67 if sys.platform.startswith("darwin"):
68 expected_log_lines = ['com.apple.main-thread ' + x for x in expected_log_lines]
69
Caroline Tice8607f032011-01-29 00:19:53 +000070 self.assertTrue (os.path.isfile (log_file))
71
72 idx = 0
73 end = len (expected_log_lines)
74 f = open (log_file)
75 log_lines = f.readlines()
76 f.close ()
Johnny Chenec1ccca2011-01-29 00:52:54 +000077 self.runCmd("log disable lldb")
Caroline Tice8607f032011-01-29 00:19:53 +000078 os.remove (log_file)
79
80 err_msg = ""
81 success = True
82
83 if len (log_lines) != len (expected_log_lines):
84 success = False
85 err_msg = "Wrong number of lines in log file; expected: " + repr (len (expected_log_lines)) + " found: " + repr(len (log_lines))
86 else:
87 for line1, line2 in zip (log_lines, expected_log_lines):
88 if line1 != line2:
89 success = False
90 err_msg = "Expected '" + line2 + "'; Found '" + line1 + "'"
91 break
92
93 if not success:
94 self.fail (err_msg)
95
96
97if __name__ == '__main__':
98 import atexit
99 lldb.SBDebugger.Initialize()
100 atexit.register(lambda: lldb.SBDebugger.Terminate())
101 unittest2.main()
102