2 Test lldb logging. This test just makes sure logging doesn't crash, and produces some output.
5 from __future__ import print_function
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
17 class LogTestCase(TestBase):
19 mydir = TestBase.compute_mydir(__file__)
20 NO_DEBUG_INFO_TESTCASE = True
23 super(LogTestCase, self).setUp()
24 self.log_file = self.getBuildArtifact("log-file.txt")
28 exe = self.getBuildArtifact("a.out")
29 self.expect("file " + exe,
30 patterns=["Current executable set to .*a.out"])
32 log_file = os.path.join(self.getBuildDir(), "lldb-commands-log.txt")
34 if (os.path.exists(log_file)):
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))
42 self.runCmd("command alias bp breakpoint")
44 self.runCmd("bp set -n main")
48 self.runCmd("log disable lldb")
50 self.assertTrue(os.path.isfile(log_file))
53 log_lines = f.readlines()
60 "Something was written to the log file.")
62 # Check that lldb truncates its log files
63 def test_log_truncate(self):
64 # put something in our log file
65 with open(self.log_file, "w") as f:
66 for i in range(1, 1000):
69 self.runCmd("log enable -t -f '%s' lldb commands" % self.log_file)
70 self.runCmd("help log")
71 self.runCmd("log disable lldb")
73 self.assertTrue(os.path.isfile(self.log_file))
74 with open(self.log_file, "r") as f:
77 # check that it got removed
78 self.assertEquals(contents.find("bacon"), -1)
80 # Check that lldb can append to a log file
81 def test_log_append(self):
82 # put something in our log file
83 with open(self.log_file, "w") as f:
86 self.runCmd( "log enable -t -a -f '%s' lldb commands" % self.log_file)
87 self.runCmd("help log")
88 self.runCmd("log disable lldb")
90 self.assertTrue(os.path.isfile(self.log_file))
91 with open(self.log_file, "r") as f:
94 # check that it is still there
95 self.assertEquals(contents.find("bacon"), 0)