2 Test basic DarwinLog functionality provided by the StructuredDataDarwinLog
5 These tests are currently only supported when running against Darwin
15 from lldbsuite.test import decorators
16 from lldbsuite.test import lldbtest
17 from lldbsuite.test import darwin_log
20 class TestDarwinLogFilterRegexMessage(darwin_log.DarwinLogEventBasedTestBase):
22 mydir = lldbtest.TestBase.compute_mydir(__file__)
24 @decorators.skipUnlessDarwin
25 @decorators.expectedFailureAll(oslist=["macosx"],
26 bugnumber="llvm.org/pr30299")
27 def test_filter_accept_message_full_match(self):
28 """Test that fall-through reject, accept regex whole message works."""
29 log_entries = self.do_test(
30 ["--no-match-accepts false",
31 # Note below, the four '\' characters are to get us two
32 # backslashes over on the gdb-remote side, which then
33 # becomes one as the cstr interprets it as an escape
34 # sequence. This needs to be rationalized. Initially I
35 # supported std::regex ECMAScript, which has the
36 # [[:digit:]] character classes and such. That was much
37 # more tenable. The backslashes have to travel through
38 # so many layers of escaping. (And note if you take
39 # off the Python raw string marker here, you need to put
40 # in 8 backslashes to go to two on the remote side.)
41 r'--filter "accept message regex log message sub2-cat\\\\d+"'])
43 # We should have received at least one log entry.
44 self.assertIsNotNone(log_entries,
45 "Log entry list should not be None.")
46 self.assertEqual(len(log_entries), 1,
47 "Should receive one log entry.")
48 self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2",
49 "First os_log call should have been skipped.")
51 @decorators.skipUnlessDarwin
52 @decorators.expectedFailureAll(oslist=["macosx"],
53 bugnumber="llvm.org/pr30299")
54 def test_filter_accept_message_partial_match(self):
55 """Test that fall-through reject, accept regex message via partial
57 log_entries = self.do_test(
58 ["--no-match-accepts false",
59 "--filter \"accept message regex [^-]+2\""])
61 # We should only see the second log message as we only accept
62 # that message contents.
63 self.assertIsNotNone(log_entries,
64 "Log entry list should not be None.")
65 self.assertEqual(len(log_entries), 1,
66 "Should receive one log entry.")
67 self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2",
68 "First os_log call should have been skipped.")
70 @decorators.skipUnlessDarwin
71 @decorators.expectedFailureAll(oslist=["macosx"],
72 bugnumber="llvm.org/pr30299")
73 def test_filter_reject_message_full_match(self):
74 """Test that fall-through accept, reject regex message works."""
75 log_entries = self.do_test(
76 ["--no-match-accepts true",
77 "--filter \"reject message regex log message sub1-cat1\""])
79 # We should only see the second log message as we rejected the first
80 # via message contents rejection.
81 self.assertIsNotNone(log_entries,
82 "Log entry list should not be None.")
83 self.assertEqual(len(log_entries), 1,
84 "Should receive one log entry.")
85 self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2",
86 "First os_log call should have been skipped.")
88 @decorators.skipUnlessDarwin
89 @decorators.expectedFailureAll(oslist=["macosx"],
90 bugnumber="llvm.org/pr30299")
91 def test_filter_reject_message_partial_match(self):
92 """Test that fall-through accept, reject regex message by partial
94 log_entries = self.do_test(
95 ["--no-match-accepts true",
96 "--filter \"reject message regex t1\""])
98 # We should only see the second log message as we rejected the first
99 # via partial message contents rejection.
100 self.assertIsNotNone(log_entries,
101 "Log entry list should not be None.")
102 self.assertEqual(len(log_entries), 1,
103 "Should receive one log entry.")
104 self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2",
105 "First os_log call should have been skipped.")
107 @decorators.skipUnlessDarwin
108 @decorators.expectedFailureAll(oslist=["macosx"],
109 bugnumber="llvm.org/pr30299")
110 def test_filter_accept_message_second_rule(self):
111 """Test that fall-through reject, accept regex message on second rule
113 log_entries = self.do_test(
114 ["--no-match-accepts false",
115 "--filter \"accept message regex non-existent\"",
116 "--filter \"accept message regex cat2\""])
118 # We should only see the second message since we reject by default,
119 # the first filter doesn't match any, and the second filter matches
120 # the message of the second log message.
121 self.assertIsNotNone(log_entries,
122 "Log entry list should not be None.")
123 self.assertEqual(len(log_entries), 1,
124 "Should receive one log entry.")
125 self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2",
126 "First os_log call should have been skipped.")