1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/trace_event/trace_config.h"
6 #include "testing/gtest/include/gtest/gtest.h"
9 namespace trace_event
{
13 const char kDefaultTraceConfigString
[] =
15 "\"enable_argument_filter\":false,"
16 "\"enable_sampling\":false,"
17 "\"enable_systrace\":false,"
18 "\"excluded_categories\":[\"*Debug\",\"*Test\"],"
19 "\"record_mode\":\"record-until-full\""
24 TEST(TraceConfigTest
, TraceConfigFromValidLegacyFormat
) {
25 // From trace options strings
26 TraceConfig
config("", "record-until-full");
27 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
28 EXPECT_FALSE(config
.IsSamplingEnabled());
29 EXPECT_FALSE(config
.IsSystraceEnabled());
30 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
31 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
33 config
= TraceConfig("", "record-continuously");
34 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
35 EXPECT_FALSE(config
.IsSamplingEnabled());
36 EXPECT_FALSE(config
.IsSystraceEnabled());
37 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
38 EXPECT_STREQ("record-continuously", config
.ToTraceOptionsString().c_str());
40 config
= TraceConfig("", "trace-to-console");
41 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
42 EXPECT_FALSE(config
.IsSamplingEnabled());
43 EXPECT_FALSE(config
.IsSystraceEnabled());
44 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
45 EXPECT_STREQ("trace-to-console", config
.ToTraceOptionsString().c_str());
47 config
= TraceConfig("", "record-as-much-as-possible");
48 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, config
.GetTraceRecordMode());
49 EXPECT_FALSE(config
.IsSamplingEnabled());
50 EXPECT_FALSE(config
.IsSystraceEnabled());
51 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
52 EXPECT_STREQ("record-as-much-as-possible",
53 config
.ToTraceOptionsString().c_str());
55 config
= TraceConfig("", "record-until-full, enable-sampling");
56 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
57 EXPECT_TRUE(config
.IsSamplingEnabled());
58 EXPECT_FALSE(config
.IsSystraceEnabled());
59 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
60 EXPECT_STREQ("record-until-full,enable-sampling",
61 config
.ToTraceOptionsString().c_str());
63 config
= TraceConfig("", "enable-systrace, record-continuously");
64 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
65 EXPECT_FALSE(config
.IsSamplingEnabled());
66 EXPECT_TRUE(config
.IsSystraceEnabled());
67 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
68 EXPECT_STREQ("record-continuously,enable-systrace",
69 config
.ToTraceOptionsString().c_str());
71 config
= TraceConfig("", "enable-argument-filter,record-as-much-as-possible");
72 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, config
.GetTraceRecordMode());
73 EXPECT_FALSE(config
.IsSamplingEnabled());
74 EXPECT_FALSE(config
.IsSystraceEnabled());
75 EXPECT_TRUE(config
.IsArgumentFilterEnabled());
76 EXPECT_STREQ("record-as-much-as-possible,enable-argument-filter",
77 config
.ToTraceOptionsString().c_str());
81 "enable-systrace,trace-to-console,enable-sampling,enable-argument-filter");
82 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
83 EXPECT_TRUE(config
.IsSamplingEnabled());
84 EXPECT_TRUE(config
.IsSystraceEnabled());
85 EXPECT_TRUE(config
.IsArgumentFilterEnabled());
87 "trace-to-console,enable-sampling,enable-systrace,enable-argument-filter",
88 config
.ToTraceOptionsString().c_str());
91 "", "record-continuously, record-until-full, trace-to-console");
92 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
93 EXPECT_FALSE(config
.IsSamplingEnabled());
94 EXPECT_FALSE(config
.IsSystraceEnabled());
95 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
96 EXPECT_STREQ("trace-to-console", config
.ToTraceOptionsString().c_str());
98 // From TraceRecordMode
99 config
= TraceConfig("", RECORD_UNTIL_FULL
);
100 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
101 EXPECT_FALSE(config
.IsSamplingEnabled());
102 EXPECT_FALSE(config
.IsSystraceEnabled());
103 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
104 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
106 config
= TraceConfig("", RECORD_CONTINUOUSLY
);
107 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
108 EXPECT_FALSE(config
.IsSamplingEnabled());
109 EXPECT_FALSE(config
.IsSystraceEnabled());
110 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
111 EXPECT_STREQ("record-continuously", config
.ToTraceOptionsString().c_str());
113 config
= TraceConfig("", ECHO_TO_CONSOLE
);
114 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
115 EXPECT_FALSE(config
.IsSamplingEnabled());
116 EXPECT_FALSE(config
.IsSystraceEnabled());
117 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
118 EXPECT_STREQ("trace-to-console", config
.ToTraceOptionsString().c_str());
120 config
= TraceConfig("", RECORD_AS_MUCH_AS_POSSIBLE
);
121 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, config
.GetTraceRecordMode());
122 EXPECT_FALSE(config
.IsSamplingEnabled());
123 EXPECT_FALSE(config
.IsSystraceEnabled());
124 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
125 EXPECT_STREQ("record-as-much-as-possible",
126 config
.ToTraceOptionsString().c_str());
128 // From category filter strings
129 config
= TraceConfig("-*Debug,-*Test", "");
130 EXPECT_STREQ("-*Debug,-*Test", config
.ToCategoryFilterString().c_str());
132 config
= TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*", "");
133 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
134 config
.ToCategoryFilterString().c_str());
136 config
= TraceConfig("only_inc_cat", "");
137 EXPECT_STREQ("only_inc_cat", config
.ToCategoryFilterString().c_str());
139 config
= TraceConfig("-only_exc_cat", "");
140 EXPECT_STREQ("-only_exc_cat", config
.ToCategoryFilterString().c_str());
142 config
= TraceConfig("disabled-by-default-cc,-excluded", "");
143 EXPECT_STREQ("disabled-by-default-cc,-excluded",
144 config
.ToCategoryFilterString().c_str());
146 config
= TraceConfig("disabled-by-default-cc,included", "");
147 EXPECT_STREQ("included,disabled-by-default-cc",
148 config
.ToCategoryFilterString().c_str());
150 config
= TraceConfig("DELAY(test.Delay1;16),included", "");
151 EXPECT_STREQ("included,DELAY(test.Delay1;16)",
152 config
.ToCategoryFilterString().c_str());
154 // From both trace options and category filter strings
155 config
= TraceConfig("", "");
156 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
157 EXPECT_FALSE(config
.IsSamplingEnabled());
158 EXPECT_FALSE(config
.IsSystraceEnabled());
159 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
160 EXPECT_STREQ("", config
.ToCategoryFilterString().c_str());
161 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
163 config
= TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*",
164 "enable-systrace, trace-to-console, enable-sampling");
165 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
166 EXPECT_TRUE(config
.IsSamplingEnabled());
167 EXPECT_TRUE(config
.IsSystraceEnabled());
168 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
169 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
170 config
.ToCategoryFilterString().c_str());
171 EXPECT_STREQ("trace-to-console,enable-sampling,enable-systrace",
172 config
.ToTraceOptionsString().c_str());
174 // From both trace options and category filter strings with spaces.
175 config
= TraceConfig(" included , -excluded, inc_pattern*, ,-exc_pattern* ",
176 "enable-systrace, ,trace-to-console, enable-sampling ");
177 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
178 EXPECT_TRUE(config
.IsSamplingEnabled());
179 EXPECT_TRUE(config
.IsSystraceEnabled());
180 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
181 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
182 config
.ToCategoryFilterString().c_str());
183 EXPECT_STREQ("trace-to-console,enable-sampling,enable-systrace",
184 config
.ToTraceOptionsString().c_str());
186 // From category filter string and TraceRecordMode
187 config
= TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*",
188 RECORD_CONTINUOUSLY
);
189 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
190 EXPECT_FALSE(config
.IsSystraceEnabled());
191 EXPECT_FALSE(config
.IsSamplingEnabled());
192 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
193 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
194 config
.ToCategoryFilterString().c_str());
195 EXPECT_STREQ("record-continuously", config
.ToTraceOptionsString().c_str());
198 TEST(TraceConfigTest
, TraceConfigFromInvalidLegacyStrings
) {
199 TraceConfig
config("", "foo-bar-baz");
200 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
201 EXPECT_FALSE(config
.IsSamplingEnabled());
202 EXPECT_FALSE(config
.IsSystraceEnabled());
203 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
204 EXPECT_STREQ("", config
.ToCategoryFilterString().c_str());
205 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
207 config
= TraceConfig("arbitrary-category", "foo-bar-baz, enable-systrace");
208 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
209 EXPECT_FALSE(config
.IsSamplingEnabled());
210 EXPECT_TRUE(config
.IsSystraceEnabled());
211 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
212 EXPECT_STREQ("arbitrary-category", config
.ToCategoryFilterString().c_str());
213 EXPECT_STREQ("record-until-full,enable-systrace",
214 config
.ToTraceOptionsString().c_str());
216 const char* const configs
[] = {
224 for (size_t i
= 0; i
< arraysize(configs
); i
++) {
225 TraceConfig
tc(configs
[i
], "");
226 EXPECT_EQ(0u, tc
.GetSyntheticDelayValues().size());
230 TEST(TraceConfigTest
, ConstructDefaultTraceConfig
) {
231 // Make sure that upon an empty string, we fall back to the default config.
233 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
234 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
235 EXPECT_FALSE(tc
.IsSamplingEnabled());
236 EXPECT_FALSE(tc
.IsSystraceEnabled());
237 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
238 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
240 EXPECT_FALSE(tc
.IsCategoryEnabled("Category1"));
241 EXPECT_FALSE(tc
.IsCategoryEnabled("not-excluded-category"));
242 EXPECT_FALSE(tc
.IsCategoryEnabled("CategoryTest"));
243 EXPECT_FALSE(tc
.IsCategoryEnabled("CategoryDebug"));
244 EXPECT_FALSE(tc
.IsCategoryEnabled("disabled-by-default-cc"));
246 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("Category1"));
247 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("not-excluded-category"));
248 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("CategoryTest"));
249 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("CategoryDebug"));
250 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
252 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("Category1,CategoryDebug"));
253 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("CategoryDebug,Category1"));
254 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("CategoryTest,not-excluded-category"));
255 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("CategoryDebug,CategoryTest"));
258 TEST(TraceConfigTest
, TraceConfigFromValidString
) {
259 // Using some non-empty config string.
260 const char config_string
[] =
262 "\"enable_argument_filter\":true,"
263 "\"enable_sampling\":true,"
264 "\"enable_systrace\":true,"
265 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"],"
266 "\"included_categories\":[\"included\","
268 "\"disabled-by-default-cc\"],"
269 "\"record_mode\":\"record-continuously\","
270 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]"
272 TraceConfig
tc(config_string
);
274 EXPECT_STREQ(config_string
, tc
.ToString().c_str());
275 EXPECT_EQ(RECORD_CONTINUOUSLY
, tc
.GetTraceRecordMode());
276 EXPECT_TRUE(tc
.IsSamplingEnabled());
277 EXPECT_TRUE(tc
.IsSystraceEnabled());
278 EXPECT_TRUE(tc
.IsArgumentFilterEnabled());
279 EXPECT_STREQ("included,inc_pattern*,disabled-by-default-cc,-excluded,"
280 "-exc_pattern*,DELAY(test.Delay1;16),DELAY(test.Delay2;32)",
281 tc
.ToCategoryFilterString().c_str());
283 EXPECT_TRUE(tc
.IsCategoryEnabled("included"));
284 EXPECT_TRUE(tc
.IsCategoryEnabled("inc_pattern_category"));
285 EXPECT_TRUE(tc
.IsCategoryEnabled("disabled-by-default-cc"));
286 EXPECT_FALSE(tc
.IsCategoryEnabled("excluded"));
287 EXPECT_FALSE(tc
.IsCategoryEnabled("exc_pattern_category"));
288 EXPECT_FALSE(tc
.IsCategoryEnabled("disabled-by-default-others"));
289 EXPECT_FALSE(tc
.IsCategoryEnabled("not-excluded-nor-included"));
291 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included"));
292 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("inc_pattern_category"));
293 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
294 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("excluded"));
295 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("exc_pattern_category"));
296 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("disabled-by-default-others"));
297 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("not-excluded-nor-included"));
299 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included,excluded"));
300 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("excluded,exc_pattern_category"));
301 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included,DELAY(test.Delay1;16)"));
302 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("DELAY(test.Delay1;16)"));
304 EXPECT_EQ(2u, tc
.GetSyntheticDelayValues().size());
305 EXPECT_STREQ("test.Delay1;16", tc
.GetSyntheticDelayValues()[0].c_str());
306 EXPECT_STREQ("test.Delay2;32", tc
.GetSyntheticDelayValues()[1].c_str());
308 const char config_string_2
[] = "{\"included_categories\":[\"*\"]}";
309 TraceConfig
tc2(config_string_2
);
310 EXPECT_TRUE(tc2
.IsCategoryEnabled("non-disabled-by-default-pattern"));
311 EXPECT_FALSE(tc2
.IsCategoryEnabled("disabled-by-default-pattern"));
312 EXPECT_TRUE(tc2
.IsCategoryGroupEnabled("non-disabled-by-default-pattern"));
313 EXPECT_FALSE(tc2
.IsCategoryGroupEnabled("disabled-by-default-pattern"));
317 EXPECT_STREQ(tc
.ToString().c_str(),
319 "\"enable_argument_filter\":false,"
320 "\"enable_sampling\":false,"
321 "\"enable_systrace\":false,"
322 "\"record_mode\":\"record-until-full\""
326 TEST(TraceConfigTest
, TraceConfigFromInvalidString
) {
327 // The config string needs to be a dictionary correctly formatted as a JSON
328 // string. Otherwise, it will fall back to the default initialization.
330 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
331 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
332 EXPECT_FALSE(tc
.IsSamplingEnabled());
333 EXPECT_FALSE(tc
.IsSystraceEnabled());
334 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
335 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
337 tc
= TraceConfig("This is an invalid config string.");
338 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
339 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
340 EXPECT_FALSE(tc
.IsSamplingEnabled());
341 EXPECT_FALSE(tc
.IsSystraceEnabled());
342 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
343 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
345 tc
= TraceConfig("[\"This\", \"is\", \"not\", \"a\", \"dictionary\"]");
346 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
347 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
348 EXPECT_FALSE(tc
.IsSamplingEnabled());
349 EXPECT_FALSE(tc
.IsSystraceEnabled());
350 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
351 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
353 tc
= TraceConfig("{\"record_mode\": invalid-value-needs-double-quote}");
354 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
355 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
356 EXPECT_FALSE(tc
.IsSamplingEnabled());
357 EXPECT_FALSE(tc
.IsSystraceEnabled());
358 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
359 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
361 // If the config string a dictionary formatted as a JSON string, it will
362 // initialize TraceConfig with best effort.
363 tc
= TraceConfig("{}");
364 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
365 EXPECT_FALSE(tc
.IsSamplingEnabled());
366 EXPECT_FALSE(tc
.IsSystraceEnabled());
367 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
368 EXPECT_STREQ("", tc
.ToCategoryFilterString().c_str());
370 tc
= TraceConfig("{\"arbitrary-key\":\"arbitrary-value\"}");
371 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
372 EXPECT_FALSE(tc
.IsSamplingEnabled());
373 EXPECT_FALSE(tc
.IsSystraceEnabled());
374 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
375 EXPECT_STREQ("", tc
.ToCategoryFilterString().c_str());
377 const char invalid_config_string
[] =
379 "\"enable_sampling\":\"true\","
380 "\"enable_systrace\":1,"
381 "\"excluded_categories\":[\"excluded\"],"
382 "\"included_categories\":\"not a list\","
383 "\"record_mode\":\"arbitrary-mode\","
384 "\"synthetic_delays\":[\"test.Delay1;16\","
386 "\"test.Delay2;32\"]"
388 tc
= TraceConfig(invalid_config_string
);
389 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
390 EXPECT_FALSE(tc
.IsSamplingEnabled());
391 EXPECT_FALSE(tc
.IsSystraceEnabled());
392 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
393 EXPECT_STREQ("-excluded,DELAY(test.Delay1;16),DELAY(test.Delay2;32)",
394 tc
.ToCategoryFilterString().c_str());
396 const char invalid_config_string_2
[] =
398 "\"included_categories\":[\"category\",\"disabled-by-default-pattern\"],"
399 "\"excluded_categories\":[\"category\",\"disabled-by-default-pattern\"]"
401 tc
= TraceConfig(invalid_config_string_2
);
402 EXPECT_TRUE(tc
.IsCategoryEnabled("category"));
403 EXPECT_TRUE(tc
.IsCategoryEnabled("disabled-by-default-pattern"));
404 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("category"));
405 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-pattern"));
408 TEST(TraceConfigTest
, MergingTraceConfigs
) {
411 TraceConfig
tc2("included,-excluded,inc_pattern*,-exc_pattern*", "");
414 "\"enable_argument_filter\":false,"
415 "\"enable_sampling\":false,"
416 "\"enable_systrace\":false,"
417 "\"excluded_categories\":["
418 "\"*Debug\",\"*Test\",\"excluded\",\"exc_pattern*\""
420 "\"record_mode\":\"record-until-full\""
422 tc
.ToString().c_str());
424 tc
= TraceConfig("DELAY(test.Delay1;16)", "");
425 tc2
= TraceConfig("DELAY(test.Delay2;32)", "");
427 EXPECT_EQ(2u, tc
.GetSyntheticDelayValues().size());
428 EXPECT_STREQ("test.Delay1;16", tc
.GetSyntheticDelayValues()[0].c_str());
429 EXPECT_STREQ("test.Delay2;32", tc
.GetSyntheticDelayValues()[1].c_str());
432 TEST(TraceConfigTest
, IsCategoryGroupEnabled
) {
433 // Enabling a disabled- category does not require all categories to be traced
435 TraceConfig
tc("disabled-by-default-cc,-excluded", "");
436 EXPECT_STREQ("disabled-by-default-cc,-excluded",
437 tc
.ToCategoryFilterString().c_str());
438 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
439 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("some_other_group"));
440 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("excluded"));
442 // Enabled a disabled- category and also including makes all categories to
443 // be traced require including.
444 tc
= TraceConfig("disabled-by-default-cc,included", "");
445 EXPECT_STREQ("included,disabled-by-default-cc",
446 tc
.ToCategoryFilterString().c_str());
447 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
448 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included"));
449 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("other_included"));
452 TEST(TraceConfigTest
, IsEmptyOrContainsLeadingOrTrailingWhitespace
) {
453 // Test that IsEmptyOrContainsLeadingOrTrailingWhitespace actually catches
454 // categories that are explicitly forbidden.
455 // This method is called in a DCHECK to assert that we don't have these types
456 // of strings as categories.
457 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
459 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
461 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
463 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
465 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
467 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
469 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
471 EXPECT_FALSE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
475 TEST(TraceConfigTest
, SetTraceOptionValues
) {
477 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
478 EXPECT_FALSE(tc
.IsSamplingEnabled());
479 EXPECT_FALSE(tc
.IsSystraceEnabled());
481 tc
.SetTraceRecordMode(RECORD_AS_MUCH_AS_POSSIBLE
);
482 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, tc
.GetTraceRecordMode());
485 EXPECT_TRUE(tc
.IsSamplingEnabled());
488 EXPECT_TRUE(tc
.IsSystraceEnabled());
491 } // namespace trace_event