| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
| 10 #include "base/trace_event/trace_config.h" | 11 #include "base/trace_event/trace_config.h" |
| 11 #include "base/trace_event/trace_config_memory_test_util.h" | 12 #include "base/trace_event/trace_config_memory_test_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 namespace trace_event { | 16 namespace trace_event { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kDefaultTraceConfigString[] = | 20 const char kDefaultTraceConfigString[] = |
| 20 "{" | 21 "{" |
| 21 "\"enable_argument_filter\":false," | 22 "\"enable_argument_filter\":false," |
| 22 "\"enable_sampling\":false," | 23 "\"enable_sampling\":false," |
| 23 "\"enable_systrace\":false," | 24 "\"enable_systrace\":false," |
| 24 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," | 25 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," |
| 25 "\"record_mode\":\"record-until-full\"" | 26 "\"record_mode\":\"record-until-full\"" |
| 26 "}"; | 27 "}"; |
| 27 | 28 |
| 28 const char kCustomTraceConfigString[] = | 29 const char kCustomTraceConfigString[] = |
| 29 "{" | 30 "{" |
| 30 "\"enable_argument_filter\":true," | 31 "\"enable_argument_filter\":true," |
| 31 "\"enable_sampling\":true," | 32 "\"enable_sampling\":true," |
| 32 "\"enable_systrace\":true," | 33 "\"enable_systrace\":true," |
| 34 "\"event_filters\":[" |
| 35 "{" |
| 36 "\"excluded_categories\":[\"unfiltered_cat\"]," |
| 37 "\"filter_args\":{\"event_name_whitelist\":[\"a snake\",\"a dog\"]}," |
| 38 "\"filter_predicate\":\"event_whitelist_predicate\"," |
| 39 "\"included_categories\":[\"*\"]" |
| 40 "}" |
| 41 "]," |
| 33 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," | 42 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," |
| 34 "\"included_categories\":[\"included\"," | 43 "\"included_categories\":[\"included\"," |
| 35 "\"inc_pattern*\"," | 44 "\"inc_pattern*\"," |
| 36 "\"disabled-by-default-cc\"," | 45 "\"disabled-by-default-cc\"," |
| 37 "\"disabled-by-default-memory-infra\"]," | 46 "\"disabled-by-default-memory-infra\"]," |
| 38 "\"memory_dump_config\":{" | 47 "\"memory_dump_config\":{" |
| 39 "\"heap_profiler_options\":{" | 48 "\"heap_profiler_options\":{" |
| 40 "\"breakdown_threshold_bytes\":10240" | 49 "\"breakdown_threshold_bytes\":10240" |
| 41 "}," | 50 "}," |
| 42 "\"triggers\":[" | 51 "\"triggers\":[" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1")); | 284 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1")); |
| 276 EXPECT_TRUE(tc.IsCategoryGroupEnabled("not-excluded-category")); | 285 EXPECT_TRUE(tc.IsCategoryGroupEnabled("not-excluded-category")); |
| 277 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest")); | 286 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest")); |
| 278 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug")); | 287 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug")); |
| 279 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-cc")); | 288 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-cc")); |
| 280 | 289 |
| 281 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug")); | 290 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug")); |
| 282 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1")); | 291 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1")); |
| 283 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,not-excluded-category")); | 292 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,not-excluded-category")); |
| 284 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,CategoryTest")); | 293 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,CategoryTest")); |
| 294 |
| 295 EXPECT_TRUE(tc.event_filters().empty()); |
| 285 } | 296 } |
| 286 | 297 |
| 287 TEST(TraceConfigTest, TraceConfigFromDict) { | 298 TEST(TraceConfigTest, TraceConfigFromDict) { |
| 288 // Passing in empty dictionary will not result in default trace config. | 299 // Passing in empty dictionary will not result in default trace config. |
| 289 DictionaryValue dict; | 300 DictionaryValue dict; |
| 290 TraceConfig tc(dict); | 301 TraceConfig tc(dict); |
| 291 EXPECT_STRNE(kDefaultTraceConfigString, tc.ToString().c_str()); | 302 EXPECT_STRNE(kDefaultTraceConfigString, tc.ToString().c_str()); |
| 292 EXPECT_EQ(RECORD_UNTIL_FULL, tc.GetTraceRecordMode()); | 303 EXPECT_EQ(RECORD_UNTIL_FULL, tc.GetTraceRecordMode()); |
| 293 EXPECT_FALSE(tc.IsSamplingEnabled()); | 304 EXPECT_FALSE(tc.IsSamplingEnabled()); |
| 294 EXPECT_FALSE(tc.IsSystraceEnabled()); | 305 EXPECT_FALSE(tc.IsSystraceEnabled()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 custom_tc.ToCategoryFilterString().c_str()); | 339 custom_tc.ToCategoryFilterString().c_str()); |
| 329 } | 340 } |
| 330 | 341 |
| 331 TEST(TraceConfigTest, TraceConfigFromValidString) { | 342 TEST(TraceConfigTest, TraceConfigFromValidString) { |
| 332 // Using some non-empty config string. | 343 // Using some non-empty config string. |
| 333 const char config_string[] = | 344 const char config_string[] = |
| 334 "{" | 345 "{" |
| 335 "\"enable_argument_filter\":true," | 346 "\"enable_argument_filter\":true," |
| 336 "\"enable_sampling\":true," | 347 "\"enable_sampling\":true," |
| 337 "\"enable_systrace\":true," | 348 "\"enable_systrace\":true," |
| 349 "\"event_filters\":[" |
| 350 "{" |
| 351 "\"excluded_categories\":[\"unfiltered_cat\"]," |
| 352 "\"filter_args\":{\"event_name_whitelist\":[\"a snake\",\"a dog\"]}," |
| 353 "\"filter_predicate\":\"event_whitelist_predicate\"," |
| 354 "\"included_categories\":[\"*\"]" |
| 355 "}" |
| 356 "]," |
| 338 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," | 357 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," |
| 339 "\"included_categories\":[\"included\"," | 358 "\"included_categories\":[\"included\"," |
| 340 "\"inc_pattern*\"," | 359 "\"inc_pattern*\"," |
| 341 "\"disabled-by-default-cc\"]," | 360 "\"disabled-by-default-cc\"]," |
| 342 "\"record_mode\":\"record-continuously\"," | 361 "\"record_mode\":\"record-continuously\"," |
| 343 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]" | 362 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]" |
| 344 "}"; | 363 "}"; |
| 345 TraceConfig tc(config_string); | 364 TraceConfig tc(config_string); |
| 346 | 365 |
| 347 EXPECT_STREQ(config_string, tc.ToString().c_str()); | 366 EXPECT_STREQ(config_string, tc.ToString().c_str()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 371 | 390 |
| 372 EXPECT_TRUE(tc.IsCategoryGroupEnabled("included,excluded")); | 391 EXPECT_TRUE(tc.IsCategoryGroupEnabled("included,excluded")); |
| 373 EXPECT_FALSE(tc.IsCategoryGroupEnabled("excluded,exc_pattern_category")); | 392 EXPECT_FALSE(tc.IsCategoryGroupEnabled("excluded,exc_pattern_category")); |
| 374 EXPECT_TRUE(tc.IsCategoryGroupEnabled("included,DELAY(test.Delay1;16)")); | 393 EXPECT_TRUE(tc.IsCategoryGroupEnabled("included,DELAY(test.Delay1;16)")); |
| 375 EXPECT_FALSE(tc.IsCategoryGroupEnabled("DELAY(test.Delay1;16)")); | 394 EXPECT_FALSE(tc.IsCategoryGroupEnabled("DELAY(test.Delay1;16)")); |
| 376 | 395 |
| 377 EXPECT_EQ(2u, tc.GetSyntheticDelayValues().size()); | 396 EXPECT_EQ(2u, tc.GetSyntheticDelayValues().size()); |
| 378 EXPECT_STREQ("test.Delay1;16", tc.GetSyntheticDelayValues()[0].c_str()); | 397 EXPECT_STREQ("test.Delay1;16", tc.GetSyntheticDelayValues()[0].c_str()); |
| 379 EXPECT_STREQ("test.Delay2;32", tc.GetSyntheticDelayValues()[1].c_str()); | 398 EXPECT_STREQ("test.Delay2;32", tc.GetSyntheticDelayValues()[1].c_str()); |
| 380 | 399 |
| 400 EXPECT_EQ(tc.event_filters().size(), 1u); |
| 401 const TraceConfig::EventFilterConfig& event_filter = tc.event_filters()[0]; |
| 402 EXPECT_STREQ(event_filter.predicate_name().c_str(), |
| 403 "event_whitelist_predicate"); |
| 404 EXPECT_EQ(event_filter.included_categories().size(), 1u); |
| 405 EXPECT_STREQ(event_filter.included_categories()[0].c_str(), "*"); |
| 406 EXPECT_EQ(event_filter.excluded_categories().size(), 1u); |
| 407 EXPECT_STREQ(event_filter.excluded_categories()[0].c_str(), "unfiltered_cat"); |
| 408 EXPECT_TRUE(event_filter.filter_args()); |
| 409 |
| 410 std::string json_out; |
| 411 base::JSONWriter::Write(*event_filter.filter_args(), &json_out); |
| 412 EXPECT_STREQ(json_out.c_str(), |
| 413 "{\"event_name_whitelist\":[\"a snake\",\"a dog\"]}"); |
| 414 |
| 381 const char config_string_2[] = "{\"included_categories\":[\"*\"]}"; | 415 const char config_string_2[] = "{\"included_categories\":[\"*\"]}"; |
| 382 TraceConfig tc2(config_string_2); | 416 TraceConfig tc2(config_string_2); |
| 383 EXPECT_TRUE(tc2.IsCategoryEnabled("non-disabled-by-default-pattern")); | 417 EXPECT_TRUE(tc2.IsCategoryEnabled("non-disabled-by-default-pattern")); |
| 384 EXPECT_FALSE(tc2.IsCategoryEnabled("disabled-by-default-pattern")); | 418 EXPECT_FALSE(tc2.IsCategoryEnabled("disabled-by-default-pattern")); |
| 385 EXPECT_TRUE(tc2.IsCategoryGroupEnabled("non-disabled-by-default-pattern")); | 419 EXPECT_TRUE(tc2.IsCategoryGroupEnabled("non-disabled-by-default-pattern")); |
| 386 EXPECT_FALSE(tc2.IsCategoryGroupEnabled("disabled-by-default-pattern")); | 420 EXPECT_FALSE(tc2.IsCategoryGroupEnabled("disabled-by-default-pattern")); |
| 387 | 421 |
| 388 // Clear | 422 // Clear |
| 389 tc.Clear(); | 423 tc.Clear(); |
| 390 EXPECT_STREQ(tc.ToString().c_str(), | 424 EXPECT_STREQ(tc.ToString().c_str(), |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); | 638 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); |
| 605 EXPECT_EQ(2u, tc.memory_dump_config_.triggers.size()); | 639 EXPECT_EQ(2u, tc.memory_dump_config_.triggers.size()); |
| 606 EXPECT_EQ(TraceConfig::MemoryDumpConfig::HeapProfiler | 640 EXPECT_EQ(TraceConfig::MemoryDumpConfig::HeapProfiler |
| 607 ::kDefaultBreakdownThresholdBytes, | 641 ::kDefaultBreakdownThresholdBytes, |
| 608 tc.memory_dump_config_.heap_profiler_options | 642 tc.memory_dump_config_.heap_profiler_options |
| 609 .breakdown_threshold_bytes); | 643 .breakdown_threshold_bytes); |
| 610 } | 644 } |
| 611 | 645 |
| 612 } // namespace trace_event | 646 } // namespace trace_event |
| 613 } // namespace base | 647 } // namespace base |
| OLD | NEW |