]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/darwin_log/format/TestDarwinLogMessageFormat.py
Vendor import of lldb trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / darwin_log / format / TestDarwinLogMessageFormat.py
1 """
2 Test DarwinLog log message formatting options provided by the
3 StructuredDataDarwinLog plugin.
4
5 These tests are currently only supported when running against Darwin
6 targets.
7 """
8
9 from __future__ import print_function
10
11 import lldb
12 import re
13
14 from lldbsuite.test import decorators
15 from lldbsuite.test import lldbtest
16 from lldbsuite.test import darwin_log
17
18
19 class TestDarwinLogMessageFormat(darwin_log.DarwinLogTestBase):
20
21     mydir = lldbtest.TestBase.compute_mydir(__file__)
22
23     def setUp(self):
24         # Call super's setUp().
25         super(TestDarwinLogMessageFormat, self).setUp()
26
27         # Source filename.
28         self.source = 'main.c'
29
30         # Output filename.
31         self.exe_name = self.getBuildArtifact("a.out")
32         self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
33
34         # Locate breakpoint.
35         self.line = lldbtest.line_number(self.source, '// break here')
36
37     def tearDown(self):
38         # Shut down the process if it's still running.
39         if self.child:
40             self.runCmd('process kill')
41             self.expect_prompt()
42             self.runCmd('quit')
43
44         # Let parent clean up
45         super(TestDarwinLogMessageFormat, self).tearDown()
46
47     # ==========================================================================
48     # Test settings around log message formatting
49     # ==========================================================================
50
51     REGEXES = [
52         re.compile(r"\[([^]]+)\] This is the log message."),  # Match log
53                                                               # with header.
54         re.compile(r"This is the log message."),  # Match no-header content.
55         re.compile(r"exited with status")         # Fallback if no log emitted.
56     ]
57
58     @decorators.skipUnlessDarwin
59     def test_display_without_header_works(self):
60         """Test that turning off log message headers works as advertised."""
61         self.do_test([], expect_regexes=self.REGEXES)
62
63         # We should not match the first pattern as we shouldn't have header
64         # content.
65         self.assertIsNotNone(self.child.match)
66         self.assertFalse((len(self.child.match.groups()) > 0) and
67                          (self.child.match.group(1) != ""),
68                          "we should not have seen a header")
69
70     @decorators.skipUnlessDarwin
71     def test_display_with_header_works(self):
72         """Test that displaying any header works."""
73         self.do_test(
74             ["--timestamp-relative", "--subsystem", "--category",
75              "--activity-chain"],
76             expect_regexes=self.REGEXES,
77             settings_commands=[
78                 "display-header true"
79             ])
80
81         # We should match the first pattern as we should have header
82         # content.
83         self.assertIsNotNone(self.child.match)
84         self.assertTrue((len(self.child.match.groups()) > 0) and
85                         (self.child.match.group(1) != ""),
86                         "we should have printed a header")
87
88     def assert_header_contains_timestamp(self, header):
89         fields = header.split(',')
90         self.assertGreater(len(fields), 0,
91                            "there should have been header content present")
92         self.assertRegexpMatches(fields[0],
93                                  r"^\d+:\d{2}:\d{2}.\d{9}$",
94                                  "time field should match expected format")
95
96     @decorators.skipUnlessDarwin
97     def test_header_timefield_only_works(self):
98         """Test that displaying a header with only the timestamp works."""
99         self.do_test(["--timestamp-relative"], expect_regexes=self.REGEXES)
100
101         # We should match the first pattern as we should have header
102         # content.
103         self.assertIsNotNone(self.child.match)
104         self.assertTrue((len(self.child.match.groups()) > 0) and
105                         (self.child.match.group(1) != ""),
106                         "we should have printed a header")
107         header = self.child.match.group(1)
108         self.assertEqual(len(header.split(',')), 1,
109                          "there should only be one header field")
110         self.assert_header_contains_timestamp(header)
111
112     @decorators.skipUnlessDarwin
113     def test_header_subsystem_only_works(self):
114         """Test that displaying a header with only the subsystem works."""
115         self.do_test(["--subsystem"], expect_regexes=self.REGEXES)
116
117         # We should match the first pattern as we should have header
118         # content.
119         self.assertIsNotNone(self.child.match)
120         self.assertTrue((len(self.child.match.groups()) > 0) and
121                         (self.child.match.group(1) != ""),
122                         "we should have printed a header")
123         header = self.child.match.group(1)
124         self.assertEqual(len(header.split(',')), 1,
125                          "there should only be one header field")
126         self.assertEquals(header,
127                           "subsystem=org.llvm.lldb.test.sub1")
128
129     @decorators.skipUnlessDarwin
130     def test_header_category_only_works(self):
131         """Test that displaying a header with only the category works."""
132         self.do_test(["--category"], expect_regexes=self.REGEXES)
133
134         # We should match the first pattern as we should have header
135         # content.
136         self.assertIsNotNone(self.child.match)
137         self.assertTrue((len(self.child.match.groups()) > 0) and
138                         (self.child.match.group(1) != ""),
139                         "we should have printed a header")
140         header = self.child.match.group(1)
141         self.assertEqual(len(header.split(',')), 1,
142                          "there should only be one header field")
143         self.assertEquals(header,
144                           "category=cat1")
145
146     @decorators.skipUnlessDarwin
147     def test_header_activity_chain_only_works(self):
148         """Test that displaying a header with only the activity chain works."""
149         self.do_test(["--activity-chain"], expect_regexes=self.REGEXES)
150
151         # We should match the first pattern as we should have header
152         # content.
153         self.assertIsNotNone(self.child.match)
154         self.assertTrue((len(self.child.match.groups()) > 0) and
155                         (self.child.match.group(1) != ""),
156                         "we should have printed a header")
157         header = self.child.match.group(1)
158         self.assertEqual(len(header.split(',')), 1,
159                          "there should only be one header field")
160         self.assertEquals(header,
161                           "activity-chain=parent-activity:child-activity")
162
163     # @decorators.skipUnlessDarwin
164     # def test_header_activity_no_chain_only_works(self):
165     #     """Test that displaying a header with only the activity works."""
166     #     self.do_test(
167     #         [],
168     #         expect_regexes=self.REGEXES,
169     #         settings_commands=[
170     #             "display-header true",
171     #             "format-include-timestamp false",
172     #             "format-include-activity true",
173     #             "format-include-category false",
174     #             "format-include-subsystem false",
175     #             "display-activity-chain false"
176     #         ])
177
178     #     # We should match the first pattern as we should have header
179     #     # content.
180     #     self.assertIsNotNone(self.child.match)
181     #     self.assertTrue((len(self.child.match.groups()) > 0) and
182     #                     (self.child.match.group(1) != ""),
183     #                     "we should have printed a header")
184     #     header = self.child.match.group(1)
185     #     self.assertEqual(len(header.split(',')), 1,
186     #                      "there should only be one header field")
187     #     self.assertEquals(header,
188     #                       "activity=child-activity")