2 Test DarwinLog log message formatting options provided by the
3 StructuredDataDarwinLog plugin.
5 These tests are currently only supported when running against Darwin
13 from lldbsuite.test import decorators
14 from lldbsuite.test import lldbtest
15 from lldbsuite.test import darwin_log
18 class TestDarwinLogMessageFormat(darwin_log.DarwinLogTestBase):
20 mydir = lldbtest.TestBase.compute_mydir(__file__)
23 # Call super's setUp().
24 super(TestDarwinLogMessageFormat, self).setUp()
27 self.source = 'main.c'
30 self.exe_name = self.getBuildArtifact("a.out")
31 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
34 self.line = lldbtest.line_number(self.source, '// break here')
37 # Shut down the process if it's still running.
39 self.runCmd('process kill')
44 super(TestDarwinLogMessageFormat, self).tearDown()
46 # ==========================================================================
47 # Test settings around log message formatting
48 # ==========================================================================
51 re.compile(r"\[([^]]+)\] This is the log message."), # Match log
53 re.compile(r"This is the log message."), # Match no-header content.
54 re.compile(r"exited with status") # Fallback if no log emitted.
57 @decorators.skipUnlessDarwin
58 def test_display_without_header_works(self):
59 """Test that turning off log message headers works as advertised."""
60 self.do_test([], expect_regexes=self.REGEXES)
62 # We should not match the first pattern as we shouldn't have header
64 self.assertIsNotNone(self.child.match)
65 self.assertFalse((len(self.child.match.groups()) > 0) and
66 (self.child.match.group(1) != ""),
67 "we should not have seen a header")
69 @decorators.skipUnlessDarwin
70 def test_display_with_header_works(self):
71 """Test that displaying any header works."""
73 ["--timestamp-relative", "--subsystem", "--category",
75 expect_regexes=self.REGEXES,
80 # We should match the first pattern as we should have header
82 self.assertIsNotNone(self.child.match)
83 self.assertTrue((len(self.child.match.groups()) > 0) and
84 (self.child.match.group(1) != ""),
85 "we should have printed a header")
87 def assert_header_contains_timestamp(self, header):
88 fields = header.split(',')
89 self.assertGreater(len(fields), 0,
90 "there should have been header content present")
91 self.assertRegexpMatches(fields[0],
92 r"^\d+:\d{2}:\d{2}.\d{9}$",
93 "time field should match expected format")
95 @decorators.skipUnlessDarwin
96 def test_header_timefield_only_works(self):
97 """Test that displaying a header with only the timestamp works."""
98 self.do_test(["--timestamp-relative"], expect_regexes=self.REGEXES)
100 # We should match the first pattern as we should have header
102 self.assertIsNotNone(self.child.match)
103 self.assertTrue((len(self.child.match.groups()) > 0) and
104 (self.child.match.group(1) != ""),
105 "we should have printed a header")
106 header = self.child.match.group(1)
107 self.assertEqual(len(header.split(',')), 1,
108 "there should only be one header field")
109 self.assert_header_contains_timestamp(header)
111 @decorators.skipUnlessDarwin
112 def test_header_subsystem_only_works(self):
113 """Test that displaying a header with only the subsystem works."""
114 self.do_test(["--subsystem"], expect_regexes=self.REGEXES)
116 # We should match the first pattern as we should have header
118 self.assertIsNotNone(self.child.match)
119 self.assertTrue((len(self.child.match.groups()) > 0) and
120 (self.child.match.group(1) != ""),
121 "we should have printed a header")
122 header = self.child.match.group(1)
123 self.assertEqual(len(header.split(',')), 1,
124 "there should only be one header field")
125 self.assertEquals(header,
126 "subsystem=org.llvm.lldb.test.sub1")
128 @decorators.skipUnlessDarwin
129 def test_header_category_only_works(self):
130 """Test that displaying a header with only the category works."""
131 self.do_test(["--category"], expect_regexes=self.REGEXES)
133 # We should match the first pattern as we should have header
135 self.assertIsNotNone(self.child.match)
136 self.assertTrue((len(self.child.match.groups()) > 0) and
137 (self.child.match.group(1) != ""),
138 "we should have printed a header")
139 header = self.child.match.group(1)
140 self.assertEqual(len(header.split(',')), 1,
141 "there should only be one header field")
142 self.assertEquals(header,
145 @decorators.skipUnlessDarwin
146 def test_header_activity_chain_only_works(self):
147 """Test that displaying a header with only the activity chain works."""
148 self.do_test(["--activity-chain"], expect_regexes=self.REGEXES)
150 # We should match the first pattern as we should have header
152 self.assertIsNotNone(self.child.match)
153 self.assertTrue((len(self.child.match.groups()) > 0) and
154 (self.child.match.group(1) != ""),
155 "we should have printed a header")
156 header = self.child.match.group(1)
157 self.assertEqual(len(header.split(',')), 1,
158 "there should only be one header field")
159 self.assertEquals(header,
160 "activity-chain=parent-activity:child-activity")
162 # @decorators.skipUnlessDarwin
163 # def test_header_activity_no_chain_only_works(self):
164 # """Test that displaying a header with only the activity works."""
167 # expect_regexes=self.REGEXES,
168 # settings_commands=[
169 # "display-header true",
170 # "format-include-timestamp false",
171 # "format-include-activity true",
172 # "format-include-category false",
173 # "format-include-subsystem false",
174 # "display-activity-chain false"
177 # # We should match the first pattern as we should have header
179 # self.assertIsNotNone(self.child.match)
180 # self.assertTrue((len(self.child.match.groups()) > 0) and
181 # (self.child.match.group(1) != ""),
182 # "we should have printed a header")
183 # header = self.child.match.group(1)
184 # self.assertEqual(len(header.split(',')), 1,
185 # "there should only be one header field")
186 # self.assertEquals(header,
187 # "activity=child-activity")