2 Test DarwinLog log message formatting options provided by the
3 StructuredDataDarwinLog plugin.
5 These tests are currently only supported when running against Darwin
9 from __future__ import print_function
14 from lldbsuite.test import decorators
15 from lldbsuite.test import lldbtest
16 from lldbsuite.test import darwin_log
19 class TestDarwinLogMessageFormat(darwin_log.DarwinLogTestBase):
21 mydir = lldbtest.TestBase.compute_mydir(__file__)
24 # Call super's setUp().
25 super(TestDarwinLogMessageFormat, self).setUp()
28 self.source = 'main.c'
31 self.exe_name = self.getBuildArtifact("a.out")
32 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
35 self.line = lldbtest.line_number(self.source, '// break here')
38 # Shut down the process if it's still running.
40 self.runCmd('process kill')
45 super(TestDarwinLogMessageFormat, self).tearDown()
47 # ==========================================================================
48 # Test settings around log message formatting
49 # ==========================================================================
52 re.compile(r"\[([^]]+)\] This is the log message."), # Match log
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.
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)
63 # We should not match the first pattern as we shouldn't have header
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")
70 @decorators.skipUnlessDarwin
71 def test_display_with_header_works(self):
72 """Test that displaying any header works."""
74 ["--timestamp-relative", "--subsystem", "--category",
76 expect_regexes=self.REGEXES,
81 # We should match the first pattern as we should have header
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")
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")
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)
101 # We should match the first pattern as we should have header
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)
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)
117 # We should match the first pattern as we should have header
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")
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)
134 # We should match the first pattern as we should have header
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,
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)
151 # We should match the first pattern as we should have header
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")
163 # @decorators.skipUnlessDarwin
164 # def test_header_activity_no_chain_only_works(self):
165 # """Test that displaying a header with only the activity works."""
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"
178 # # We should match the first pattern as we should have header
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")