1"""
2Test DarwinLog "source include debug-level" functionality provided by the
3StructuredDataDarwinLog plugin.
4
5These tests are currently only supported when running against Darwin
6targets.
7"""
8
9
10import lldb
11
12from lldbsuite.test import decorators
13from lldbsuite.test import lldbtest
14from lldbsuite.test import darwin_log
15
16
17class TestDarwinLogSourceDebug(darwin_log.DarwinLogTestBase):
18
19    mydir = lldbtest.TestBase.compute_mydir(__file__)
20
21    def setUp(self):
22        # Call super's setUp().
23        super(TestDarwinLogSourceDebug, 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        # Indicate we want strict-sources behavior.
36        self.strict_sources = True
37
38    def tearDown(self):
39        # Shut down the process if it's still running.
40        if self.child:
41            self.runCmd('process kill')
42            self.expect_prompt()
43            self.runCmd('quit')
44
45        # Let parent clean up
46        super(TestDarwinLogSourceDebug, self).tearDown()
47
48    # ==========================================================================
49    # source include/exclude debug filter tests
50    # ==========================================================================
51
52    @decorators.skipUnlessDarwin
53    def test_source_default_exclude_debug(self):
54        """Test that default excluding of debug-level log messages works."""
55        self.do_test([])
56
57        # We should only see the second log message as the first is a
58        # debug-level message and we're not including debug-level messages.
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_source_explicitly_include_debug(self):
69        """Test that explicitly including debug-level log messages works."""
70        self.do_test(["--debug"])
71
72        # We should only see the second log message as the first is a
73        # debug-level message and we're not including debug-level messages.
74        self.assertIsNotNone(self.child.match)
75        self.assertTrue((len(self.child.match.groups()) > 1) and
76                        (self.child.match.group(2) == "cat1"),
77                        "first log line should be present since we're "
78                        "including debug-level log messages")
79