1 // Copyright 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/memory_dump_manager.h"
6 #include "base/trace_event/trace_config.h"
7 #include "base/trace_event/trace_config_memory_test_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
11 namespace trace_event
{
15 const char kDefaultTraceConfigString
[] =
17 "\"enable_argument_filter\":false,"
18 "\"enable_sampling\":false,"
19 "\"enable_systrace\":false,"
20 "\"excluded_categories\":[\"*Debug\",\"*Test\"],"
21 "\"record_mode\":\"record-until-full\""
25 TEST(TraceConfigTest
, TraceConfigFromValidLegacyFormat
) {
26 // From trace options strings
27 TraceConfig
config("", "record-until-full");
28 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
29 EXPECT_FALSE(config
.IsSamplingEnabled());
30 EXPECT_FALSE(config
.IsSystraceEnabled());
31 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
32 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
34 config
= TraceConfig("", "record-continuously");
35 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
36 EXPECT_FALSE(config
.IsSamplingEnabled());
37 EXPECT_FALSE(config
.IsSystraceEnabled());
38 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
39 EXPECT_STREQ("record-continuously", config
.ToTraceOptionsString().c_str());
41 config
= TraceConfig("", "trace-to-console");
42 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
43 EXPECT_FALSE(config
.IsSamplingEnabled());
44 EXPECT_FALSE(config
.IsSystraceEnabled());
45 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
46 EXPECT_STREQ("trace-to-console", config
.ToTraceOptionsString().c_str());
48 config
= TraceConfig("", "record-as-much-as-possible");
49 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, config
.GetTraceRecordMode());
50 EXPECT_FALSE(config
.IsSamplingEnabled());
51 EXPECT_FALSE(config
.IsSystraceEnabled());
52 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
53 EXPECT_STREQ("record-as-much-as-possible",
54 config
.ToTraceOptionsString().c_str());
56 config
= TraceConfig("", "record-until-full, enable-sampling");
57 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
58 EXPECT_TRUE(config
.IsSamplingEnabled());
59 EXPECT_FALSE(config
.IsSystraceEnabled());
60 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
61 EXPECT_STREQ("record-until-full,enable-sampling",
62 config
.ToTraceOptionsString().c_str());
64 config
= TraceConfig("", "enable-systrace, record-continuously");
65 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
66 EXPECT_FALSE(config
.IsSamplingEnabled());
67 EXPECT_TRUE(config
.IsSystraceEnabled());
68 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
69 EXPECT_STREQ("record-continuously,enable-systrace",
70 config
.ToTraceOptionsString().c_str());
72 config
= TraceConfig("", "enable-argument-filter,record-as-much-as-possible");
73 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, config
.GetTraceRecordMode());
74 EXPECT_FALSE(config
.IsSamplingEnabled());
75 EXPECT_FALSE(config
.IsSystraceEnabled());
76 EXPECT_TRUE(config
.IsArgumentFilterEnabled());
77 EXPECT_STREQ("record-as-much-as-possible,enable-argument-filter",
78 config
.ToTraceOptionsString().c_str());
82 "enable-systrace,trace-to-console,enable-sampling,enable-argument-filter");
83 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
84 EXPECT_TRUE(config
.IsSamplingEnabled());
85 EXPECT_TRUE(config
.IsSystraceEnabled());
86 EXPECT_TRUE(config
.IsArgumentFilterEnabled());
88 "trace-to-console,enable-sampling,enable-systrace,enable-argument-filter",
89 config
.ToTraceOptionsString().c_str());
92 "", "record-continuously, record-until-full, trace-to-console");
93 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
94 EXPECT_FALSE(config
.IsSamplingEnabled());
95 EXPECT_FALSE(config
.IsSystraceEnabled());
96 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
97 EXPECT_STREQ("trace-to-console", config
.ToTraceOptionsString().c_str());
99 // From TraceRecordMode
100 config
= TraceConfig("", RECORD_UNTIL_FULL
);
101 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
102 EXPECT_FALSE(config
.IsSamplingEnabled());
103 EXPECT_FALSE(config
.IsSystraceEnabled());
104 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
105 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
107 config
= TraceConfig("", RECORD_CONTINUOUSLY
);
108 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
109 EXPECT_FALSE(config
.IsSamplingEnabled());
110 EXPECT_FALSE(config
.IsSystraceEnabled());
111 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
112 EXPECT_STREQ("record-continuously", config
.ToTraceOptionsString().c_str());
114 config
= TraceConfig("", ECHO_TO_CONSOLE
);
115 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
116 EXPECT_FALSE(config
.IsSamplingEnabled());
117 EXPECT_FALSE(config
.IsSystraceEnabled());
118 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
119 EXPECT_STREQ("trace-to-console", config
.ToTraceOptionsString().c_str());
121 config
= TraceConfig("", RECORD_AS_MUCH_AS_POSSIBLE
);
122 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, config
.GetTraceRecordMode());
123 EXPECT_FALSE(config
.IsSamplingEnabled());
124 EXPECT_FALSE(config
.IsSystraceEnabled());
125 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
126 EXPECT_STREQ("record-as-much-as-possible",
127 config
.ToTraceOptionsString().c_str());
129 // From category filter strings
130 config
= TraceConfig("-*Debug,-*Test", "");
131 EXPECT_STREQ("-*Debug,-*Test", config
.ToCategoryFilterString().c_str());
133 config
= TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*", "");
134 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
135 config
.ToCategoryFilterString().c_str());
137 config
= TraceConfig("only_inc_cat", "");
138 EXPECT_STREQ("only_inc_cat", config
.ToCategoryFilterString().c_str());
140 config
= TraceConfig("-only_exc_cat", "");
141 EXPECT_STREQ("-only_exc_cat", config
.ToCategoryFilterString().c_str());
143 config
= TraceConfig("disabled-by-default-cc,-excluded", "");
144 EXPECT_STREQ("disabled-by-default-cc,-excluded",
145 config
.ToCategoryFilterString().c_str());
147 config
= TraceConfig("disabled-by-default-cc,included", "");
148 EXPECT_STREQ("included,disabled-by-default-cc",
149 config
.ToCategoryFilterString().c_str());
151 config
= TraceConfig("DELAY(test.Delay1;16),included", "");
152 EXPECT_STREQ("included,DELAY(test.Delay1;16)",
153 config
.ToCategoryFilterString().c_str());
155 // From both trace options and category filter strings
156 config
= TraceConfig("", "");
157 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
158 EXPECT_FALSE(config
.IsSamplingEnabled());
159 EXPECT_FALSE(config
.IsSystraceEnabled());
160 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
161 EXPECT_STREQ("", config
.ToCategoryFilterString().c_str());
162 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
164 config
= TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*",
165 "enable-systrace, trace-to-console, enable-sampling");
166 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
167 EXPECT_TRUE(config
.IsSamplingEnabled());
168 EXPECT_TRUE(config
.IsSystraceEnabled());
169 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
170 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
171 config
.ToCategoryFilterString().c_str());
172 EXPECT_STREQ("trace-to-console,enable-sampling,enable-systrace",
173 config
.ToTraceOptionsString().c_str());
175 // From both trace options and category filter strings with spaces.
176 config
= TraceConfig(" included , -excluded, inc_pattern*, ,-exc_pattern* ",
177 "enable-systrace, ,trace-to-console, enable-sampling ");
178 EXPECT_EQ(ECHO_TO_CONSOLE
, config
.GetTraceRecordMode());
179 EXPECT_TRUE(config
.IsSamplingEnabled());
180 EXPECT_TRUE(config
.IsSystraceEnabled());
181 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
182 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
183 config
.ToCategoryFilterString().c_str());
184 EXPECT_STREQ("trace-to-console,enable-sampling,enable-systrace",
185 config
.ToTraceOptionsString().c_str());
187 // From category filter string and TraceRecordMode
188 config
= TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*",
189 RECORD_CONTINUOUSLY
);
190 EXPECT_EQ(RECORD_CONTINUOUSLY
, config
.GetTraceRecordMode());
191 EXPECT_FALSE(config
.IsSystraceEnabled());
192 EXPECT_FALSE(config
.IsSamplingEnabled());
193 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
194 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
195 config
.ToCategoryFilterString().c_str());
196 EXPECT_STREQ("record-continuously", config
.ToTraceOptionsString().c_str());
199 TEST(TraceConfigTest
, TraceConfigFromInvalidLegacyStrings
) {
200 TraceConfig
config("", "foo-bar-baz");
201 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
202 EXPECT_FALSE(config
.IsSamplingEnabled());
203 EXPECT_FALSE(config
.IsSystraceEnabled());
204 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
205 EXPECT_STREQ("", config
.ToCategoryFilterString().c_str());
206 EXPECT_STREQ("record-until-full", config
.ToTraceOptionsString().c_str());
208 config
= TraceConfig("arbitrary-category", "foo-bar-baz, enable-systrace");
209 EXPECT_EQ(RECORD_UNTIL_FULL
, config
.GetTraceRecordMode());
210 EXPECT_FALSE(config
.IsSamplingEnabled());
211 EXPECT_TRUE(config
.IsSystraceEnabled());
212 EXPECT_FALSE(config
.IsArgumentFilterEnabled());
213 EXPECT_STREQ("arbitrary-category", config
.ToCategoryFilterString().c_str());
214 EXPECT_STREQ("record-until-full,enable-systrace",
215 config
.ToTraceOptionsString().c_str());
217 const char* const configs
[] = {
225 for (size_t i
= 0; i
< arraysize(configs
); i
++) {
226 TraceConfig
tc(configs
[i
], "");
227 EXPECT_EQ(0u, tc
.GetSyntheticDelayValues().size());
231 TEST(TraceConfigTest
, ConstructDefaultTraceConfig
) {
232 // Make sure that upon an empty string, we fall back to the default config.
234 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
235 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
236 EXPECT_FALSE(tc
.IsSamplingEnabled());
237 EXPECT_FALSE(tc
.IsSystraceEnabled());
238 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
239 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
241 EXPECT_FALSE(tc
.IsCategoryEnabled("Category1"));
242 EXPECT_FALSE(tc
.IsCategoryEnabled("not-excluded-category"));
243 EXPECT_FALSE(tc
.IsCategoryEnabled("CategoryTest"));
244 EXPECT_FALSE(tc
.IsCategoryEnabled("CategoryDebug"));
245 EXPECT_FALSE(tc
.IsCategoryEnabled("disabled-by-default-cc"));
247 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("Category1"));
248 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("not-excluded-category"));
249 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("CategoryTest"));
250 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("CategoryDebug"));
251 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
253 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("Category1,CategoryDebug"));
254 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("CategoryDebug,Category1"));
255 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("CategoryTest,not-excluded-category"));
256 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("CategoryDebug,CategoryTest"));
259 TEST(TraceConfigTest
, TraceConfigFromValidString
) {
260 // Using some non-empty config string.
261 const char config_string
[] =
263 "\"enable_argument_filter\":true,"
264 "\"enable_sampling\":true,"
265 "\"enable_systrace\":true,"
266 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"],"
267 "\"included_categories\":[\"included\","
269 "\"disabled-by-default-cc\"],"
270 "\"record_mode\":\"record-continuously\","
271 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]"
273 TraceConfig
tc(config_string
);
275 EXPECT_STREQ(config_string
, tc
.ToString().c_str());
276 EXPECT_EQ(RECORD_CONTINUOUSLY
, tc
.GetTraceRecordMode());
277 EXPECT_TRUE(tc
.IsSamplingEnabled());
278 EXPECT_TRUE(tc
.IsSystraceEnabled());
279 EXPECT_TRUE(tc
.IsArgumentFilterEnabled());
280 EXPECT_STREQ("included,inc_pattern*,disabled-by-default-cc,-excluded,"
281 "-exc_pattern*,DELAY(test.Delay1;16),DELAY(test.Delay2;32)",
282 tc
.ToCategoryFilterString().c_str());
284 EXPECT_TRUE(tc
.IsCategoryEnabled("included"));
285 EXPECT_TRUE(tc
.IsCategoryEnabled("inc_pattern_category"));
286 EXPECT_TRUE(tc
.IsCategoryEnabled("disabled-by-default-cc"));
287 EXPECT_FALSE(tc
.IsCategoryEnabled("excluded"));
288 EXPECT_FALSE(tc
.IsCategoryEnabled("exc_pattern_category"));
289 EXPECT_FALSE(tc
.IsCategoryEnabled("disabled-by-default-others"));
290 EXPECT_FALSE(tc
.IsCategoryEnabled("not-excluded-nor-included"));
292 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included"));
293 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("inc_pattern_category"));
294 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
295 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("excluded"));
296 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("exc_pattern_category"));
297 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("disabled-by-default-others"));
298 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("not-excluded-nor-included"));
300 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included,excluded"));
301 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("excluded,exc_pattern_category"));
302 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included,DELAY(test.Delay1;16)"));
303 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("DELAY(test.Delay1;16)"));
305 EXPECT_EQ(2u, tc
.GetSyntheticDelayValues().size());
306 EXPECT_STREQ("test.Delay1;16", tc
.GetSyntheticDelayValues()[0].c_str());
307 EXPECT_STREQ("test.Delay2;32", tc
.GetSyntheticDelayValues()[1].c_str());
309 const char config_string_2
[] = "{\"included_categories\":[\"*\"]}";
310 TraceConfig
tc2(config_string_2
);
311 EXPECT_TRUE(tc2
.IsCategoryEnabled("non-disabled-by-default-pattern"));
312 EXPECT_FALSE(tc2
.IsCategoryEnabled("disabled-by-default-pattern"));
313 EXPECT_TRUE(tc2
.IsCategoryGroupEnabled("non-disabled-by-default-pattern"));
314 EXPECT_FALSE(tc2
.IsCategoryGroupEnabled("disabled-by-default-pattern"));
318 EXPECT_STREQ(tc
.ToString().c_str(),
320 "\"enable_argument_filter\":false,"
321 "\"enable_sampling\":false,"
322 "\"enable_systrace\":false,"
323 "\"record_mode\":\"record-until-full\""
327 TEST(TraceConfigTest
, TraceConfigFromInvalidString
) {
328 // The config string needs to be a dictionary correctly formatted as a JSON
329 // string. Otherwise, it will fall back to the default initialization.
331 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
332 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
333 EXPECT_FALSE(tc
.IsSamplingEnabled());
334 EXPECT_FALSE(tc
.IsSystraceEnabled());
335 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
336 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
338 tc
= TraceConfig("This is an invalid config string.");
339 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
340 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
341 EXPECT_FALSE(tc
.IsSamplingEnabled());
342 EXPECT_FALSE(tc
.IsSystraceEnabled());
343 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
344 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
346 tc
= TraceConfig("[\"This\", \"is\", \"not\", \"a\", \"dictionary\"]");
347 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
348 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
349 EXPECT_FALSE(tc
.IsSamplingEnabled());
350 EXPECT_FALSE(tc
.IsSystraceEnabled());
351 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
352 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
354 tc
= TraceConfig("{\"record_mode\": invalid-value-needs-double-quote}");
355 EXPECT_STREQ(kDefaultTraceConfigString
, tc
.ToString().c_str());
356 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
357 EXPECT_FALSE(tc
.IsSamplingEnabled());
358 EXPECT_FALSE(tc
.IsSystraceEnabled());
359 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
360 EXPECT_STREQ("-*Debug,-*Test", tc
.ToCategoryFilterString().c_str());
362 // If the config string a dictionary formatted as a JSON string, it will
363 // initialize TraceConfig with best effort.
364 tc
= TraceConfig("{}");
365 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
366 EXPECT_FALSE(tc
.IsSamplingEnabled());
367 EXPECT_FALSE(tc
.IsSystraceEnabled());
368 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
369 EXPECT_STREQ("", tc
.ToCategoryFilterString().c_str());
371 tc
= TraceConfig("{\"arbitrary-key\":\"arbitrary-value\"}");
372 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
373 EXPECT_FALSE(tc
.IsSamplingEnabled());
374 EXPECT_FALSE(tc
.IsSystraceEnabled());
375 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
376 EXPECT_STREQ("", tc
.ToCategoryFilterString().c_str());
378 const char invalid_config_string
[] =
380 "\"enable_sampling\":\"true\","
381 "\"enable_systrace\":1,"
382 "\"excluded_categories\":[\"excluded\"],"
383 "\"included_categories\":\"not a list\","
384 "\"record_mode\":\"arbitrary-mode\","
385 "\"synthetic_delays\":[\"test.Delay1;16\","
387 "\"test.Delay2;32\"]"
389 tc
= TraceConfig(invalid_config_string
);
390 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
391 EXPECT_FALSE(tc
.IsSamplingEnabled());
392 EXPECT_FALSE(tc
.IsSystraceEnabled());
393 EXPECT_FALSE(tc
.IsArgumentFilterEnabled());
394 EXPECT_STREQ("-excluded,DELAY(test.Delay1;16),DELAY(test.Delay2;32)",
395 tc
.ToCategoryFilterString().c_str());
397 const char invalid_config_string_2
[] =
399 "\"included_categories\":[\"category\",\"disabled-by-default-pattern\"],"
400 "\"excluded_categories\":[\"category\",\"disabled-by-default-pattern\"]"
402 tc
= TraceConfig(invalid_config_string_2
);
403 EXPECT_TRUE(tc
.IsCategoryEnabled("category"));
404 EXPECT_TRUE(tc
.IsCategoryEnabled("disabled-by-default-pattern"));
405 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("category"));
406 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-pattern"));
409 TEST(TraceConfigTest
, MergingTraceConfigs
) {
412 TraceConfig
tc2("included,-excluded,inc_pattern*,-exc_pattern*", "");
415 "\"enable_argument_filter\":false,"
416 "\"enable_sampling\":false,"
417 "\"enable_systrace\":false,"
418 "\"excluded_categories\":["
419 "\"*Debug\",\"*Test\",\"excluded\",\"exc_pattern*\""
421 "\"record_mode\":\"record-until-full\""
423 tc
.ToString().c_str());
425 tc
= TraceConfig("DELAY(test.Delay1;16)", "");
426 tc2
= TraceConfig("DELAY(test.Delay2;32)", "");
428 EXPECT_EQ(2u, tc
.GetSyntheticDelayValues().size());
429 EXPECT_STREQ("test.Delay1;16", tc
.GetSyntheticDelayValues()[0].c_str());
430 EXPECT_STREQ("test.Delay2;32", tc
.GetSyntheticDelayValues()[1].c_str());
433 TEST(TraceConfigTest
, IsCategoryGroupEnabled
) {
434 // Enabling a disabled- category does not require all categories to be traced
436 TraceConfig
tc("disabled-by-default-cc,-excluded", "");
437 EXPECT_STREQ("disabled-by-default-cc,-excluded",
438 tc
.ToCategoryFilterString().c_str());
439 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
440 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("some_other_group"));
441 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("excluded"));
443 // Enabled a disabled- category and also including makes all categories to
444 // be traced require including.
445 tc
= TraceConfig("disabled-by-default-cc,included", "");
446 EXPECT_STREQ("included,disabled-by-default-cc",
447 tc
.ToCategoryFilterString().c_str());
448 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("disabled-by-default-cc"));
449 EXPECT_TRUE(tc
.IsCategoryGroupEnabled("included"));
450 EXPECT_FALSE(tc
.IsCategoryGroupEnabled("other_included"));
453 TEST(TraceConfigTest
, IsEmptyOrContainsLeadingOrTrailingWhitespace
) {
454 // Test that IsEmptyOrContainsLeadingOrTrailingWhitespace actually catches
455 // categories that are explicitly forbidden.
456 // This method is called in a DCHECK to assert that we don't have these types
457 // of strings as categories.
458 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
460 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
462 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
464 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
466 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
468 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
470 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
472 EXPECT_FALSE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
476 TEST(TraceConfigTest
, SetTraceOptionValues
) {
478 EXPECT_EQ(RECORD_UNTIL_FULL
, tc
.GetTraceRecordMode());
479 EXPECT_FALSE(tc
.IsSamplingEnabled());
480 EXPECT_FALSE(tc
.IsSystraceEnabled());
482 tc
.SetTraceRecordMode(RECORD_AS_MUCH_AS_POSSIBLE
);
483 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE
, tc
.GetTraceRecordMode());
486 EXPECT_TRUE(tc
.IsSamplingEnabled());
489 EXPECT_TRUE(tc
.IsSystraceEnabled());
492 TEST(TraceConfigTest
, TraceConfigFromMemoryConfigString
) {
494 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(200, 2000);
495 TraceConfig
tc(tc_str
);
496 EXPECT_EQ(tc_str
, tc
.ToString());
497 EXPECT_TRUE(tc
.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory
));
498 EXPECT_EQ(2u, tc
.memory_dump_config_
.size());
500 EXPECT_EQ(200u, tc
.memory_dump_config_
[0].periodic_interval_ms
);
501 EXPECT_EQ(MemoryDumpLevelOfDetail::LIGHT
,
502 tc
.memory_dump_config_
[0].level_of_detail
);
504 EXPECT_EQ(2000u, tc
.memory_dump_config_
[1].periodic_interval_ms
);
505 EXPECT_EQ(MemoryDumpLevelOfDetail::DETAILED
,
506 tc
.memory_dump_config_
[1].level_of_detail
);
509 TEST(TraceConfigTest
, EmptyMemoryDumpConfigTest
) {
510 // Empty trigger list should also be specified when converting back to string.
511 TraceConfig
tc(TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers());
512 EXPECT_EQ(TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers(),
514 EXPECT_EQ(0u, tc
.memory_dump_config_
.size());
517 TEST(TraceConfigTest
, LegacyStringToMemoryDumpConfig
) {
518 TraceConfig
tc(MemoryDumpManager::kTraceCategory
, "");
519 EXPECT_TRUE(tc
.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory
));
520 EXPECT_NE(std::string::npos
, tc
.ToString().find("memory_dump_config"));
521 EXPECT_EQ(2u, tc
.memory_dump_config_
.size());
524 } // namespace trace_event