xref: /llvm-project/lldb/test/API/commands/log/basic/TestLogHandlers.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test lldb log handlers.
3"""
4
5import os
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class LogHandlerTestCase(TestBase):
13    NO_DEBUG_INFO_TESTCASE = True
14
15    def setUp(self):
16        TestBase.setUp(self)
17        self.log_file = self.getBuildArtifact("log-file.txt")
18        if os.path.exists(self.log_file):
19            os.remove(self.log_file)
20
21    def test_circular(self):
22        self.runCmd("log enable -b 5 -h circular lldb commands")
23        self.runCmd("bogus", check=False)
24        self.runCmd("log dump lldb -f {}".format(self.log_file))
25
26        with open(self.log_file, "r") as f:
27            log_lines = f.readlines()
28
29        self.assertEqual(len(log_lines), 5)
30
31        found_command_log_dump = False
32        found_command_bogus = False
33
34        for line in log_lines:
35            if "Processing command: log dump" in line:
36                found_command_log_dump = True
37            if "Processing command: bogus" in line:
38                found_command_bogus = True
39
40        self.assertTrue(found_command_log_dump)
41        self.assertFalse(found_command_bogus)
42
43    def test_circular_no_buffer_size(self):
44        self.expect(
45            "log enable -h circular lldb commands",
46            error=True,
47            substrs=["the circular buffer handler requires a non-zero buffer size"],
48        )
49
50    def test_dump_unsupported(self):
51        self.runCmd("log enable lldb commands -f {}".format(self.log_file))
52        self.expect(
53            "log dump lldb",
54            error=True,
55            substrs=["log channel 'lldb' does not support dumping"],
56        )
57