2 Test basic DarwinLog functionality provided by the StructuredDataDarwinLog
5 These tests are currently only supported when running against Darwin
12 from lldbsuite.test import decorators
13 from lldbsuite.test import lldbtest
14 from lldbsuite.test import darwin_log
17 class TestDarwinLogFilterRegexSubsystem(darwin_log.DarwinLogTestBase):
19 mydir = lldbtest.TestBase.compute_mydir(__file__)
22 # Call super's setUp().
23 super(TestDarwinLogFilterRegexSubsystem, self).setUp()
26 self.source = 'main.c'
29 self.exe_name = self.getBuildArtifact("a.out")
30 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
33 self.line = lldbtest.line_number(self.source, '// break here')
36 # Shut down the process if it's still running.
38 self.runCmd('process kill')
43 super(TestDarwinLogFilterRegexSubsystem, self).tearDown()
45 # ==========================================================================
47 # ==========================================================================
49 @decorators.skipUnlessDarwin
50 def test_fallthrough_reject(self):
51 """Test that a single fall-through reject regex rule rejects all logging."""
53 ["--no-match-accepts false"]
56 # We should not match any log lines.
57 self.assertIsNotNone(self.child.match)
58 self.assertFalse((len(self.child.match.groups()) > 0) and
59 (self.child.match.group(1) in ["sub1", "sub2"]),
60 "log line should not have been received")
62 # ==========================================================================
63 # subsystem filter tests
64 # ==========================================================================
66 @decorators.skipUnlessDarwin
67 def test_filter_accept_subsystem_full_match(self):
68 """Test that fall-through reject, accept regex single subsystem works."""
70 ["--no-match-accepts false",
71 "--filter \"accept subsystem regex org.llvm.lldb.test.sub2\""]
74 # We should only see the second log message as we only accept
76 self.assertIsNotNone(self.child.match)
79 self.child.match.groups()) > 0) and (
80 self.child.match.group(1) == "sub2"),
81 "first log line should not be present, second log line "
84 @decorators.skipUnlessDarwin
85 def test_filter_accept_subsystem_partial_match(self):
86 """Test that fall-through reject, accept regex subsystem via partial-match works."""
88 ["--no-match-accepts false",
89 "--filter \"accept subsystem regex org.llvm.+.sub2\""]
92 # We should only see the second log message as we only accept
94 self.assertIsNotNone(self.child.match)
97 self.child.match.groups()) > 0) and (
98 self.child.match.group(1) == "sub2"),
99 "first log line should not be present, second log line "
102 @decorators.skipUnlessDarwin
103 def test_filter_reject_subsystem_full_match(self):
104 """Test that fall-through accept, reject regex subsystem works."""
106 ["--no-match-accepts true",
107 "--filter \"reject subsystem regex org.llvm.lldb.test.sub1\""]
110 # We should only see the second log message as we rejected the first
111 # via subsystem rejection.
112 self.assertIsNotNone(self.child.match)
115 self.child.match.groups()) > 0) and (
116 self.child.match.group(1) == "sub2"),
117 "first log line should not be present, second log line "
120 @decorators.skipUnlessDarwin
121 def test_filter_reject_subsystem_partial_match(self):
122 """Test that fall-through accept, reject regex subsystem by partial match works."""
124 ["--no-match-accepts true",
125 "--filter \"reject subsystem regex org.*sub1\""]
128 # We should only see the second log message as we rejected the first
129 # via subsystem rejection.
130 self.assertIsNotNone(self.child.match)
133 self.child.match.groups()) > 0) and (
134 self.child.match.group(1) == "sub2"),
135 "first log line should not be present, second log line "
138 @decorators.skipUnlessDarwin
139 def test_filter_accept_subsystem_second_rule(self):
140 """Test that fall-through reject, accept regex subsystem on second rule works."""
142 ["--no-match-accepts false",
143 "--filter \"accept subsystem regex non-existent\"",
144 "--filter \"accept subsystem regex org.llvm.lldb.test.sub2\""
148 # We should only see the second message since we reject by default,
149 # the first filter doesn't match any, and the second filter matches
150 # the subsystem of the second log message.
151 self.assertIsNotNone(self.child.match)
154 self.child.match.groups()) > 0) and (
155 self.child.match.group(1) == "sub2"),
156 "first log line should not be present, second log line "