]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/logging/TestLogging.py
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / logging / TestLogging.py
1 """
2 Test lldb logging.  This test just makes sure logging doesn't crash, and produces some output.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import string
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16
17 class LogTestCase(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20     NO_DEBUG_INFO_TESTCASE = True
21
22     def setUp(self):
23         super(LogTestCase, self).setUp()
24         self.log_file = self.getBuildArtifact("log-file.txt")
25
26     def test(self):
27         self.build()
28         exe = self.getBuildArtifact("a.out")
29         self.expect("file " + exe,
30                     patterns=["Current executable set to .*a.out"])
31
32         log_file = os.path.join(self.getBuildDir(), "lldb-commands-log.txt")
33
34         if (os.path.exists(log_file)):
35             os.remove(log_file)
36
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))
41
42         self.runCmd("command alias bp breakpoint")
43
44         self.runCmd("bp set -n main")
45
46         self.runCmd("bp l")
47
48         self.runCmd("log disable lldb")
49
50         self.assertTrue(os.path.isfile(log_file))
51
52         f = open(log_file)
53         log_lines = f.readlines()
54         f.close()
55         os.remove(log_file)
56
57         self.assertGreater(
58             len(log_lines),
59             0,
60             "Something was written to the log file.")
61
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):
67                 f.write("bacon\n")
68
69         self.runCmd("log enable -t -f '%s' lldb commands" % self.log_file)
70         self.runCmd("help log")
71         self.runCmd("log disable lldb")
72
73         self.assertTrue(os.path.isfile(self.log_file))
74         with open(self.log_file, "r") as f:
75             contents = f.read()
76
77         # check that it got removed
78         self.assertEquals(contents.find("bacon"), -1)
79
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:
84             f.write("bacon\n")
85
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")
89
90         self.assertTrue(os.path.isfile(self.log_file))
91         with open(self.log_file, "r") as f:
92             contents = f.read()
93
94         # check that it is still there
95         self.assertEquals(contents.find("bacon"), 0)