Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 1 | """ |
Jim Ingham | c49d0d4 | 2014-03-19 23:55:54 +0000 | [diff] [blame^] | 2 | Test lldb logging. This test just makes sure logging doesn't crash, and produces some output. |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class LogTestCase(TestBase): |
| 11 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 12 | mydir = TestBase.compute_mydir(__file__) |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 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, |
Greg Clayton | c1b2ccf | 2013-01-08 00:01:36 +0000 | [diff] [blame] | 31 | os.path.basename(self.getCompiler()), |
Johnny Chen | e0ec9ea | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 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 | |
Michael Sartain | c205243 | 2013-08-01 18:51:08 +0000 | [diff] [blame] | 37 | # 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 Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 41 | |
Johnny Chen | 72c4082 | 2011-04-21 20:55:57 +0000 | [diff] [blame] | 42 | self.runCmd ("command alias bp breakpoint") |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 43 | |
| 44 | self.runCmd ("bp set -n main") |
| 45 | |
| 46 | self.runCmd ("bp l") |
| 47 | |
Greg Clayton | c7d8885 | 2014-02-12 23:46:08 +0000 | [diff] [blame] | 48 | self.runCmd("log disable lldb") |
| 49 | |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 50 | self.assertTrue (os.path.isfile (log_file)) |
| 51 | |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 52 | f = open (log_file) |
| 53 | log_lines = f.readlines() |
| 54 | f.close () |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 55 | os.remove (log_file) |
| 56 | |
Jim Ingham | c49d0d4 | 2014-03-19 23:55:54 +0000 | [diff] [blame^] | 57 | self.assertTrue(log_lines > 0, "Something was written to the log file.") |
Caroline Tice | 8607f03 | 2011-01-29 00:19:53 +0000 | [diff] [blame] | 58 | |
| 59 | if __name__ == '__main__': |
| 60 | import atexit |
| 61 | lldb.SBDebugger.Initialize() |
| 62 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 63 | unittest2.main() |
| 64 | |