summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/subsystem/TestDarwinLogFilterRegexSubsystem.py
blob: 9fc8b85caad5430c473a65e251b9a80373cb6994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
Test basic DarwinLog functionality provided by the StructuredDataDarwinLog
plugin.

These tests are currently only supported when running against Darwin
targets.
"""

from __future__ import print_function

import lldb

from lldbsuite.test import decorators
from lldbsuite.test import lldbtest
from lldbsuite.test import darwin_log


class TestDarwinLogFilterRegexSubsystem(darwin_log.DarwinLogTestBase):

    mydir = lldbtest.TestBase.compute_mydir(__file__)

    def setUp(self):
        # Call super's setUp().
        super(TestDarwinLogFilterRegexSubsystem, self).setUp()

        # Source filename.
        self.source = 'main.c'

        # Output filename.
        self.exe_name = self.getBuildArtifact("a.out")
        self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}

        # Locate breakpoint.
        self.line = lldbtest.line_number(self.source, '// break here')

    def tearDown(self):
        # Shut down the process if it's still running.
        if self.child:
            self.runCmd('process kill')
            self.expect_prompt()
            self.runCmd('quit')

        # Let parent clean up
        super(TestDarwinLogFilterRegexSubsystem, self).tearDown()

    # ==========================================================================
    # basic filter tests
    # ==========================================================================

    @decorators.skipUnlessDarwin
    def test_fallthrough_reject(self):
        """Test that a single fall-through reject regex rule rejects all logging."""
        self.do_test(
            ["--no-match-accepts false"]
        )

        # We should not match any log lines.
        self.assertIsNotNone(self.child.match)
        self.assertFalse((len(self.child.match.groups()) > 0) and
                         (self.child.match.group(1) in ["sub1", "sub2"]),
                         "log line should not have been received")

    # ==========================================================================
    # subsystem filter tests
    # ==========================================================================

    @decorators.skipUnlessDarwin
    def test_filter_accept_subsystem_full_match(self):
        """Test that fall-through reject, accept regex single subsystem works."""
        self.do_test(
            ["--no-match-accepts false",
             "--filter \"accept subsystem regex org.llvm.lldb.test.sub2\""]
        )

        # We should only see the second log message as we only accept
        # that subsystem.
        self.assertIsNotNone(self.child.match)
        self.assertTrue(
            (len(
                self.child.match.groups()) > 0) and (
                self.child.match.group(1) == "sub2"),
            "first log line should not be present, second log line "
            "should be")

    @decorators.skipUnlessDarwin
    def test_filter_accept_subsystem_partial_match(self):
        """Test that fall-through reject, accept regex subsystem via partial-match works."""
        self.do_test(
            ["--no-match-accepts false",
             "--filter \"accept subsystem regex org.llvm.+.sub2\""]
        )

        # We should only see the second log message as we only accept
        # that subsystem.
        self.assertIsNotNone(self.child.match)
        self.assertTrue(
            (len(
                self.child.match.groups()) > 0) and (
                self.child.match.group(1) == "sub2"),
            "first log line should not be present, second log line "
            "should be")

    @decorators.skipUnlessDarwin
    def test_filter_reject_subsystem_full_match(self):
        """Test that fall-through accept, reject regex subsystem works."""
        self.do_test(
            ["--no-match-accepts true",
             "--filter \"reject subsystem regex org.llvm.lldb.test.sub1\""]
        )

        # We should only see the second log message as we rejected the first
        # via subsystem rejection.
        self.assertIsNotNone(self.child.match)
        self.assertTrue(
            (len(
                self.child.match.groups()) > 0) and (
                self.child.match.group(1) == "sub2"),
            "first log line should not be present, second log line "
            "should be")

    @decorators.skipUnlessDarwin
    def test_filter_reject_subsystem_partial_match(self):
        """Test that fall-through accept, reject regex subsystem by partial match works."""
        self.do_test(
            ["--no-match-accepts true",
             "--filter \"reject subsystem regex org.*sub1\""]
        )

        # We should only see the second log message as we rejected the first
        # via subsystem rejection.
        self.assertIsNotNone(self.child.match)
        self.assertTrue(
            (len(
                self.child.match.groups()) > 0) and (
                self.child.match.group(1) == "sub2"),
            "first log line should not be present, second log line "
            "should be")

    @decorators.skipUnlessDarwin
    def test_filter_accept_subsystem_second_rule(self):
        """Test that fall-through reject, accept regex subsystem on second rule works."""
        self.do_test(
            ["--no-match-accepts false",
             "--filter \"accept subsystem regex non-existent\"",
             "--filter \"accept subsystem regex org.llvm.lldb.test.sub2\""
             ]
        )

        # We should only see the second message since we reject by default,
        # the first filter doesn't match any, and the second filter matches
        # the subsystem of the second log message.
        self.assertIsNotNone(self.child.match)
        self.assertTrue(
            (len(
                self.child.match.groups()) > 0) and (
                self.child.match.group(1) == "sub2"),
            "first log line should not be present, second log line "
            "should be")
OpenPOWER on IntegriCloud