Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 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 "base/trace_event/trace_config.h" | 5 #include "base/trace_event/trace_config.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace base { | 8 namespace base { |
| 9 namespace trace_event { | 9 namespace trace_event { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const char kDefaultTraceConfigString[] = | 13 const char kDefaultTraceConfigString[] = |
| 14 "{" | 14 "{" |
| 15 "\"enable_argument_filter\":false," | 15 "\"enable_argument_filter\":false," |
| 16 "\"enable_sampling\":false," | 16 "\"enable_sampling\":false," |
| 17 "\"enable_systrace\":false," | 17 "\"enable_systrace\":false," |
| 18 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," | 18 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," |
| 19 "\"record_mode\":\"record-until-full\"" | 19 "\"record_mode\":\"record-until-full\"" |
| 20 "}"; | 20 "}"; |
| 21 | 21 |
| 22 const char kMemoryDumpTraceConfigString[] = | |
| 23 "{" | |
| 24 "\"enable_argument_filter\":false," | |
| 25 "\"enable_sampling\":false," | |
| 26 "\"enable_systrace\":false," | |
| 27 "\"included_categories\":[" | |
| 28 "\"disabled-by-default-memory-infra\"" | |
| 29 "]," | |
| 30 "\"memory_dump_config\":{" | |
| 31 "\"triggers\":[" | |
| 32 "{" | |
| 33 "\"level_of_detail\":\"low\"," | |
| 34 "\"periodic_interval_ms\":200" | |
| 35 "}," | |
| 36 "{" | |
| 37 "\"level_of_detail\":\"high\"," | |
| 38 "\"periodic_interval_ms\":2000" | |
| 39 "}" | |
| 40 "]" | |
| 41 "}," | |
| 42 "\"record_mode\":\"record-until-full\"" | |
| 43 "}"; | |
| 44 | |
| 45 const char kInvalidMemoryDumpTraceConfigString[] = | |
| 46 "{" | |
| 47 "\"enable_argument_filter\":false," | |
| 48 "\"enable_sampling\":false," | |
| 49 "\"enable_systrace\":false," | |
| 50 "\"memory_dump_config\":{" | |
| 51 "\"triggers\":[" | |
| 52 "{" | |
| 53 "\"level_of_detail\":\"low\"," | |
| 54 "\"periodic_interval_ms\":200" | |
| 55 "}" | |
| 56 "]" | |
| 57 "}," | |
| 58 "\"record_mode\":\"record-until-full\"" | |
| 59 "}"; | |
| 60 | |
| 22 } // namespace | 61 } // namespace |
| 23 | 62 |
| 24 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { | 63 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { |
| 25 // From trace options strings | 64 // From trace options strings |
| 26 TraceConfig config("", "record-until-full"); | 65 TraceConfig config("", "record-until-full"); |
| 27 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); | 66 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); |
| 28 EXPECT_FALSE(config.IsSamplingEnabled()); | 67 EXPECT_FALSE(config.IsSamplingEnabled()); |
| 29 EXPECT_FALSE(config.IsSystraceEnabled()); | 68 EXPECT_FALSE(config.IsSystraceEnabled()); |
| 30 EXPECT_FALSE(config.IsArgumentFilterEnabled()); | 69 EXPECT_FALSE(config.IsArgumentFilterEnabled()); |
| 31 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); | 70 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 tc.SetTraceRecordMode(RECORD_AS_MUCH_AS_POSSIBLE); | 520 tc.SetTraceRecordMode(RECORD_AS_MUCH_AS_POSSIBLE); |
| 482 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, tc.GetTraceRecordMode()); | 521 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, tc.GetTraceRecordMode()); |
| 483 | 522 |
| 484 tc.EnableSampling(); | 523 tc.EnableSampling(); |
| 485 EXPECT_TRUE(tc.IsSamplingEnabled()); | 524 EXPECT_TRUE(tc.IsSamplingEnabled()); |
| 486 | 525 |
| 487 tc.EnableSystrace(); | 526 tc.EnableSystrace(); |
| 488 EXPECT_TRUE(tc.IsSystraceEnabled()); | 527 EXPECT_TRUE(tc.IsSystraceEnabled()); |
| 489 } | 528 } |
| 490 | 529 |
| 530 TEST(TraceConfigTest, TraceConfigFromMemoryConfigString) { | |
| 531 TraceConfig tc(kMemoryDumpTraceConfigString); | |
| 532 EXPECT_STREQ(kMemoryDumpTraceConfigString, tc.ToString().c_str()); | |
| 533 EXPECT_TRUE(tc.IsCategoryGroupEnabled("disabled-by-default-memory-infra")); | |
| 534 EXPECT_EQ(2u, tc.memory_dump_config_.size()); | |
| 535 | |
| 536 EXPECT_EQ(200u, tc.memory_dump_config_[0].periodic_interval_ms); | |
| 537 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::LOW, | |
| 538 tc.memory_dump_config_[0].level_of_detail); | |
| 539 | |
| 540 EXPECT_EQ(2000u, tc.memory_dump_config_[1].periodic_interval_ms); | |
| 541 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::HIGH, | |
| 542 tc.memory_dump_config_[1].level_of_detail); | |
| 543 } | |
| 544 | |
| 545 TEST(TraceConfigTest, InvalidMemoryConfigString) { | |
|
Primiano Tucci (use gerrit)
2015/08/25 18:27:37
Not sure if this makes sense anymore. Instead have
ssid
2015/08/26 10:19:51
Made new test for this reason.
| |
| 546 TraceConfig tc(kInvalidMemoryDumpTraceConfigString); | |
| 547 EXPECT_EQ(std::string::npos, tc.ToString().find("memory_dump_config")); | |
| 548 EXPECT_EQ(0u, tc.memory_dump_config_.size()); | |
| 549 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-memory-infra")); | |
| 550 } | |
| 551 | |
| 491 } // namespace trace_event | 552 } // namespace trace_event |
| 492 } // namespace base | 553 } // namespace base |
| OLD | NEW |