2011-01-29 00:19:53 +00:00
|
|
|
"""
|
2014-03-19 23:55:54 +00:00
|
|
|
Test lldb logging. This test just makes sure logging doesn't crash, and produces some output.
|
2011-01-29 00:19:53 +00:00
|
|
|
"""
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import string
|
2011-01-29 00:19:53 +00:00
|
|
|
import lldb
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-01-29 00:19:53 +00:00
|
|
|
class LogTestCase(TestBase):
|
|
|
|
|
2013-12-10 23:19:29 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2015-03-20 09:43:20 +00:00
|
|
|
append_log_file = "lldb-commands-log-append.txt"
|
|
|
|
truncate_log_file = "lldb-commands-log-truncate.txt"
|
2018-02-05 11:30:46 +00:00
|
|
|
NO_DEBUG_INFO_TESTCASE = True
|
2015-03-20 09:43:20 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def classCleanup(cls):
|
|
|
|
"""Cleanup the test byproducts."""
|
|
|
|
cls.RemoveTempFile(cls.truncate_log_file)
|
|
|
|
cls.RemoveTempFile(cls.append_log_file)
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
def test(self):
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2011-01-29 00:19:53 +00:00
|
|
|
self.expect("file " + exe,
|
2016-09-06 20:57:50 +00:00
|
|
|
patterns=["Current executable set to .*a.out"])
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2018-02-05 11:30:46 +00:00
|
|
|
log_file = os.path.join(self.getBuildDir(), "lldb-commands-log.txt")
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
if (os.path.exists(log_file)):
|
|
|
|
os.remove(log_file)
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2013-08-01 18:51:08 +00:00
|
|
|
# By default, Debugger::EnableLog() will set log options to
|
|
|
|
# PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the
|
|
|
|
# threadnames here, so we enable just threadsafe (-t).
|
2016-09-06 20:57:50 +00:00
|
|
|
self.runCmd("log enable -t -f '%s' lldb commands" % (log_file))
|
|
|
|
|
|
|
|
self.runCmd("command alias bp breakpoint")
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.runCmd("bp set -n main")
|
|
|
|
|
|
|
|
self.runCmd("bp l")
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2014-02-12 23:46:08 +00:00
|
|
|
self.runCmd("log disable lldb")
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.assertTrue(os.path.isfile(log_file))
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
f = open(log_file)
|
2011-01-29 00:19:53 +00:00
|
|
|
log_lines = f.readlines()
|
2016-09-06 20:57:50 +00:00
|
|
|
f.close()
|
|
|
|
os.remove(log_file)
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.assertGreater(
|
|
|
|
len(log_lines),
|
|
|
|
0,
|
|
|
|
"Something was written to the log file.")
|
2011-01-29 00:19:53 +00:00
|
|
|
|
2015-03-20 09:43:20 +00:00
|
|
|
# Check that lldb truncates its log files
|
2016-09-06 20:57:50 +00:00
|
|
|
def test_log_truncate(self):
|
|
|
|
if (os.path.exists(self.truncate_log_file)):
|
|
|
|
os.remove(self.truncate_log_file)
|
2015-03-20 09:43:20 +00:00
|
|
|
|
|
|
|
# put something in our log file
|
|
|
|
with open(self.truncate_log_file, "w") as f:
|
|
|
|
for i in range(1, 1000):
|
|
|
|
f.write("bacon\n")
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.runCmd(
|
|
|
|
"log enable -t -f '%s' lldb commands" %
|
|
|
|
(self.truncate_log_file))
|
|
|
|
self.runCmd("help log")
|
|
|
|
self.runCmd("log disable lldb")
|
2015-03-20 09:43:20 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.assertTrue(os.path.isfile(self.truncate_log_file))
|
2015-03-20 09:43:20 +00:00
|
|
|
with open(self.truncate_log_file, "r") as f:
|
2016-09-06 20:57:50 +00:00
|
|
|
contents = f.read()
|
2015-03-20 09:43:20 +00:00
|
|
|
|
|
|
|
# check that it got removed
|
2016-01-15 20:45:06 +00:00
|
|
|
self.assertEquals(contents.find("bacon"), -1)
|
2015-03-20 09:43:20 +00:00
|
|
|
|
|
|
|
# Check that lldb can append to a log file
|
2016-09-06 20:57:50 +00:00
|
|
|
def test_log_append(self):
|
|
|
|
if (os.path.exists(self.append_log_file)):
|
|
|
|
os.remove(self.append_log_file)
|
2015-03-20 09:43:20 +00:00
|
|
|
|
|
|
|
# put something in our log file
|
|
|
|
with open(self.append_log_file, "w") as f:
|
|
|
|
f.write("bacon\n")
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.runCmd(
|
|
|
|
"log enable -t -a -f '%s' lldb commands" %
|
|
|
|
(self.append_log_file))
|
|
|
|
self.runCmd("help log")
|
|
|
|
self.runCmd("log disable lldb")
|
2015-03-20 09:43:20 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.assertTrue(os.path.isfile(self.append_log_file))
|
2015-03-20 09:43:20 +00:00
|
|
|
with open(self.append_log_file, "r") as f:
|
2016-09-06 20:57:50 +00:00
|
|
|
contents = f.read()
|
2015-03-20 09:43:20 +00:00
|
|
|
|
|
|
|
# check that it is still there
|
2016-01-15 20:45:06 +00:00
|
|
|
self.assertEquals(contents.find("bacon"), 0)
|