c1dfd15c6bdc61de494f7a7443b0a636f4e07ffa
[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 TestDarwinLogFilterMatchActivityChain(darwin_log.DarwinLogTestBase):
18
19     mydir = lldbtest.TestBase.compute_mydir(__file__)
20
21     def setUp(self):
22         # Call super's setUp().
23         super(TestDarwinLogFilterMatchActivityChain, 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(TestDarwinLogFilterMatchActivityChain, self).tearDown()
44
45     # ==========================================================================
46     # activity-chain filter tests
47     # ==========================================================================
48
49     @decorators.skipUnlessDarwin
50     def test_filter_accept_activity_chain_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 match "
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_reject_activity_chain_partial_match(self):
69         """Test that fall-through reject, doesn't accept only partial match of activity-chain."""
70         self.do_test(
71             ["--no-match-accepts false",
72              # Match the second fully.
73              "--filter \"accept activity-chain match parent-activity:child-activity\"",
74              "--filter \"accept activity-chain match parent-ac\""])                      # Only partially match the first.
75
76         # We should only see the second log message as we only accept
77         # that activity.
78         self.assertIsNotNone(self.child.match)
79         self.assertTrue(
80             (len(
81                 self.child.match.groups()) > 1) and (
82                 self.child.match.group(2) == "cat2"),
83             "first log line should not be present, second log line "
84             "should be")
85
86     @decorators.skipUnlessDarwin
87     def test_filter_reject_activity_chain_full_match(self):
88         """Test that fall-through accept, reject match activity-chain works."""
89         self.do_test(
90             ["--no-match-accepts true",
91              "--filter \"reject activity-chain match parent-activity\""])
92
93         # We should only see the second log message as we rejected the first
94         # via activity-chain rejection.
95         self.assertIsNotNone(self.child.match)
96         self.assertTrue(
97             (len(
98                 self.child.match.groups()) > 1) and (
99                 self.child.match.group(2) == "cat2"),
100             "first log line should not be present, second log line "
101             "should be")
102
103     @decorators.skipUnlessDarwin
104     def test_filter_accept_activity_chain_second_rule(self):
105         """Test that fall-through reject, accept activity-chain on second rule works."""
106         self.do_test(
107             ["--no-match-accepts false",
108              "--filter \"accept activity-chain match non-existent\"",
109              "--filter \"accept activity-chain match parent-activity:child-activity\""])
110
111         # We should only see the second message since we reject by default,
112         # the first filter doesn't match any, and the second filter matches
113         # the activity-chain of the second log message.
114         self.assertIsNotNone(self.child.match)
115         self.assertTrue(
116             (len(
117                 self.child.match.groups()) > 1) and (
118                 self.child.match.group(2) == "cat2"),
119             "first log line should not be present, second log line "
120             "should be")