bec5a955f30765299dde93e3178387168de98eb2
[openbsd] /
1 """
2 Test basic DarwinLog functionality provided by the StructuredDataDarwinLog
3 plugin.
4
5 These tests are currently only supported when running against Darwin
6 targets.
7 """
8
9
10 import lldb
11
12 from lldbsuite.test import decorators
13 from lldbsuite.test import lldbtest
14 from lldbsuite.test import darwin_log
15
16
17 class TestDarwinLogFilterRegexActivityChain(darwin_log.DarwinLogTestBase):
18
19     mydir = lldbtest.TestBase.compute_mydir(__file__)
20
21     def setUp(self):
22         # Call super's setUp().
23         super(TestDarwinLogFilterRegexActivityChain, self).setUp()
24
25         # Source filename.
26         self.source = 'main.c'
27
28         # Output filename.
29         self.exe_name = self.getBuildArtifact("a.out")
30         self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
31
32         # Locate breakpoint.
33         self.line = lldbtest.line_number(self.source, '// break here')
34
35     def tearDown(self):
36         # Shut down the process if it's still running.
37         if self.child:
38             self.runCmd('process kill')
39             self.expect_prompt()
40             self.runCmd('quit')
41
42         # Let parent clean up
43         super(TestDarwinLogFilterRegexActivityChain, self).tearDown()
44
45     # ==========================================================================
46     # activity-chain filter tests
47     # ==========================================================================
48
49     @decorators.skipUnlessDarwin
50     def test_filter_accept_activity_chain_full_match(self):
51         """Test that fall-through reject, accept full-match activity chain works."""
52         self.do_test(
53             ["--no-match-accepts false",
54              "--filter \"accept activity-chain regex "
55              "parent-activity:child-activity\""])
56
57         # We should only see the second log message as we only accept
58         # that activity.
59         self.assertIsNotNone(self.child.match)
60         self.assertTrue(
61             (len(
62                 self.child.match.groups()) > 1) and (
63                 self.child.match.group(2) == "cat2"),
64             "first log line should not be present, second log line "
65             "should be")
66
67     @decorators.skipUnlessDarwin
68     def test_filter_accept_activity_chain_partial_match(self):
69         """Test that fall-through reject, accept activity-chain via partial match works."""
70         self.do_test(
71             ["--no-match-accepts false",
72              "--filter \"accept activity-chain regex :child-activity\""])
73
74         # We should only see the second log message as we only accept
75         # that activity.
76         self.assertIsNotNone(self.child.match)
77         self.assertTrue(
78             (len(
79                 self.child.match.groups()) > 1) and (
80                 self.child.match.group(2) == "cat2"),
81             "first log line should not be present, second log line "
82             "should be")
83
84     @decorators.skipUnlessDarwin
85     def test_filter_reject_activity_chain_full_match(self):
86         """Test that fall-through accept, reject activity-chain works."""
87         self.do_test(
88             ["--no-match-accepts true",
89              "--filter \"reject activity-chain regex parent-activity:child-..tivity\""])
90
91         # We should only see the second log message as we rejected the first
92         # via activity-chain rejection.
93         self.assertIsNotNone(self.child.match)
94         self.assertTrue(
95             (len(
96                 self.child.match.groups()) > 1) and (
97                 self.child.match.group(2) == "cat1"),
98             "first log line should not be present, second log line "
99             "should be")
100
101     @decorators.skipUnlessDarwin
102     def test_filter_reject_activity_chain_partial_match(self):
103         """Test that fall-through accept, reject activity-chain by partial match works."""
104         self.do_test(
105             ["--no-match-accepts true",
106              "--filter \"reject activity-chain regex ^p[^:]+$\""])
107
108         # We should only see the second log message as we rejected the first
109         # via activity-chain rejection.
110         self.assertIsNotNone(self.child.match)
111         self.assertTrue(
112             (len(
113                 self.child.match.groups()) > 1) and (
114                 self.child.match.group(2) == "cat2"),
115             "first log line should not be present, second log line "
116             "should be")
117
118     @decorators.skipUnlessDarwin
119     def test_filter_accept_activity_chain_second_rule(self):
120         """Test that fall-through reject, accept activity-chain on second rule works."""
121         self.do_test(
122             ["--no-match-accepts false",
123              "--filter \"accept activity-chain regex non-existent\"",
124              "--filter \"accept activity-chain regex child-activity\""])
125
126         # We should only see the second message since we reject by default,
127         # the first filter doesn't match any, and the second filter matches
128         # the activity-chain of the second log message.
129         self.assertIsNotNone(self.child.match)
130         self.assertTrue(
131             (len(
132                 self.child.match.groups()) > 1) and (
133                 self.child.match.group(2) == "cat2"),
134             "first log line should not be present, second log line "
135             "should be")