xref: /llvm-project/lldb/test/API/api/log/TestAPILog.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test API logging.
3"""
4
5import re
6
7import lldb
8import lldbsuite.test.lldbutil as lldbutil
9from lldbsuite.test.lldbtest import *
10
11
12class APILogTestCase(TestBase):
13    NO_DEBUG_INFO_TESTCASE = True
14
15    def test_api_log(self):
16        """Test API logging"""
17        logfile = self.getBuildArtifact("api-log.txt")
18
19        self.expect("log enable lldb api -f {}".format(logfile))
20
21        self.dbg.SetDefaultArchitecture(None)
22        self.dbg.GetScriptingLanguage(None)
23        target = self.dbg.CreateTarget(None)
24
25        self.assertTrue(os.path.isfile(logfile))
26        with open(logfile, "r") as f:
27            log = f.read()
28
29        # Find the SBDebugger's address.
30        debugger_addr = re.findall(
31            r"lldb::SBDebugger::GetScriptingLanguage\([^)]*\) \(0x([0-9a-fA-F]+),", log
32        )
33
34        # Make sure we've found a match.
35        self.assertTrue(debugger_addr, log)
36
37        # Make sure the GetScriptingLanguage matches.
38        self.assertTrue(
39            re.search(
40                r'lldb::SBDebugger::GetScriptingLanguage\([^)]*\) \(0x{}, ""\)'.format(
41                    debugger_addr[0]
42                ),
43                log,
44            ),
45            log,
46        )
47
48        # Make sure the address matches.
49        self.assertTrue(
50            re.search(
51                r'lldb::SBDebugger::CreateTarget\([^)]*\) \(0x{}, ""\)'.format(
52                    debugger_addr[0]
53                ),
54                log,
55            ),
56            log,
57        )
58