2 Test lldb logging. This test just makes sure logging doesn't crash, and produces some output.
8 from lldbsuite
.test
.decorators
import *
9 from lldbsuite
.test
.lldbtest
import *
10 from lldbsuite
.test
import lldbutil
13 class LogTestCase(TestBase
):
14 NO_DEBUG_INFO_TESTCASE
= True
17 super(LogTestCase
, self
).setUp()
18 self
.log_file
= self
.getBuildArtifact("log-file.txt")
20 def test_file_writing(self
):
22 exe
= self
.getBuildArtifact("a.out")
23 self
.expect("file " + exe
, patterns
=["Current executable set to .*a.out"])
25 if os
.path
.exists(self
.log_file
):
26 os
.remove(self
.log_file
)
28 # By default, Debugger::EnableLog() will set log options to
29 # PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the
30 # threadnames here, so we enable just threadsafe (-t).
31 self
.runCmd("log enable -f '%s' lldb commands" % (self
.log_file
))
33 self
.runCmd("command alias bp breakpoint")
35 self
.runCmd("bp set -n main")
39 self
.runCmd("log disable lldb")
41 self
.assertTrue(os
.path
.isfile(self
.log_file
))
43 with
open(self
.log_file
, "r") as f
:
45 os
.remove(self
.log_file
)
47 self
.assertGreater(len(log_lines
), 0, "Something was written to the log file.")
49 # Check that lldb truncates its log files
50 def test_log_truncate(self
):
51 # put something in our log file
52 with
open(self
.log_file
, "w") as f
:
53 for i
in range(1, 1000):
56 self
.runCmd("log enable -f '%s' lldb commands" % self
.log_file
)
57 self
.runCmd("help log")
58 self
.runCmd("log disable lldb")
60 self
.assertTrue(os
.path
.isfile(self
.log_file
))
61 with
open(self
.log_file
, "r") as f
:
64 # check that it got removed
65 self
.assertEquals(contents
.find("bacon"), -1)
67 # Check that lldb can append to a log file
68 def test_log_append(self
):
69 # put something in our log file
70 with
open(self
.log_file
, "w") as f
:
73 self
.runCmd("log enable -a -f '%s' lldb commands" % self
.log_file
)
74 self
.runCmd("help log")
75 self
.runCmd("log disable lldb")
77 self
.assertTrue(os
.path
.isfile(self
.log_file
))
78 with
open(self
.log_file
, "r") as f
:
81 # check that it is still there
82 self
.assertEquals(contents
.find("bacon"), 0)
84 # Enable all log options and check that nothing crashes.
86 def test_all_log_options(self
):
87 if os
.path
.exists(self
.log_file
):
88 os
.remove(self
.log_file
)
91 "log enable -v -s -T -p -n -S -F -f '%s' lldb commands" % self
.log_file
93 self
.runCmd("help log")
94 self
.runCmd("log disable lldb")
96 self
.assertTrue(os
.path
.isfile(self
.log_file
))