blob: 11d4321c05a98c89462d6dd9c372df651eefcc56 [file] [log] [blame]
Caroline Tice8607f032011-01-29 00:19:53 +00001"""
Jim Inghamc49d0d42014-03-19 23:55:54 +00002Test lldb logging. This test just makes sure logging doesn't crash, and produces some output.
Caroline Tice8607f032011-01-29 00:19:53 +00003"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class LogTestCase(TestBase):
11
Greg Clayton4570d3e2013-12-10 23:19:29 +000012 mydir = TestBase.compute_mydir(__file__)
Caroline Tice8607f032011-01-29 00:19:53 +000013
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
Michael Sartainc2052432013-08-01 18:51:08 +000037 # By default, Debugger::EnableLog() will set log options to
38 # PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the
39 # threadnames here, so we enable just threadsafe (-t).
40 self.runCmd ("log enable -t -f '%s' lldb commands" % (log_file))
Caroline Tice8607f032011-01-29 00:19:53 +000041
Johnny Chen72c40822011-04-21 20:55:57 +000042 self.runCmd ("command alias bp breakpoint")
Caroline Tice8607f032011-01-29 00:19:53 +000043
44 self.runCmd ("bp set -n main")
45
46 self.runCmd ("bp l")
47
Greg Claytonc7d88852014-02-12 23:46:08 +000048 self.runCmd("log disable lldb")
49
Caroline Tice8607f032011-01-29 00:19:53 +000050 self.assertTrue (os.path.isfile (log_file))
51
Caroline Tice8607f032011-01-29 00:19:53 +000052 f = open (log_file)
53 log_lines = f.readlines()
54 f.close ()
Caroline Tice8607f032011-01-29 00:19:53 +000055 os.remove (log_file)
56
Jim Inghamc49d0d42014-03-19 23:55:54 +000057 self.assertTrue(log_lines > 0, "Something was written to the log file.")
Caroline Tice8607f032011-01-29 00:19:53 +000058
59if __name__ == '__main__':
60 import atexit
61 lldb.SBDebugger.Initialize()
62 atexit.register(lambda: lldb.SBDebugger.Terminate())
63 unittest2.main()
64