Chromium Code Reviews| 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/macros.h" | 8 #include "base/macros.h" |
| 8 #include "base/trace_event/memory_dump_manager.h" | 9 #include "base/trace_event/memory_dump_manager.h" |
| 9 #include "base/trace_event/trace_config.h" | 10 #include "base/trace_event/trace_config.h" |
| 10 #include "base/trace_event/trace_config_memory_test_util.h" | 11 #include "base/trace_event/trace_config_memory_test_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 namespace trace_event { | 15 namespace trace_event { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const char kDefaultTraceConfigString[] = | 19 const char kDefaultTraceConfigString[] = |
| 19 "{" | 20 "{" |
| 20 "\"enable_argument_filter\":false," | 21 "\"enable_argument_filter\":false," |
| 21 "\"enable_sampling\":false," | 22 "\"enable_sampling\":false," |
| 22 "\"enable_systrace\":false," | 23 "\"enable_systrace\":false," |
| 23 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," | 24 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," |
| 24 "\"record_mode\":\"record-until-full\"" | 25 "\"record_mode\":\"record-until-full\"" |
| 25 "}"; | 26 "}"; |
| 27 | |
| 28 const char kCustomTraceConfigString[] = | |
| 29 "{" | |
| 30 "\"enable_argument_filter\":true," | |
| 31 "\"enable_sampling\":true," | |
| 32 "\"enable_systrace\":true," | |
| 33 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," | |
| 34 "\"included_categories\":[\"included\"," | |
| 35 "\"inc_pattern*\"," | |
| 36 "\"disabled-by-default-cc\"," | |
| 37 "\"disabled-by-default-memory-infra\"]," | |
| 38 "\"memory_dump_config\":{" | |
| 39 "\"triggers\":[" | |
| 40 "{\"mode\":\"light\",\"periodic_interval_ms\":50}," | |
| 41 "{\"mode\":\"detailed\",\"periodic_interval_ms\":1000}" | |
| 42 "]" | |
| 43 "}," | |
| 44 "\"record_mode\":\"record-continuously\"," | |
| 45 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]" | |
| 46 "}"; | |
| 47 | |
| 26 } // namespace | 48 } // namespace |
| 27 | 49 |
| 28 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { | 50 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { |
| 29 // From trace options strings | 51 // From trace options strings |
| 30 TraceConfig config("", "record-until-full"); | 52 TraceConfig config("", "record-until-full"); |
| 31 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); | 53 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); |
| 32 EXPECT_FALSE(config.IsSamplingEnabled()); | 54 EXPECT_FALSE(config.IsSamplingEnabled()); |
| 33 EXPECT_FALSE(config.IsSystraceEnabled()); | 55 EXPECT_FALSE(config.IsSystraceEnabled()); |
| 34 EXPECT_FALSE(config.IsArgumentFilterEnabled()); | 56 EXPECT_FALSE(config.IsArgumentFilterEnabled()); |
| 35 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); | 57 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest")); | 274 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest")); |
| 253 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug")); | 275 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug")); |
| 254 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-cc")); | 276 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-cc")); |
| 255 | 277 |
| 256 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug")); | 278 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug")); |
| 257 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1")); | 279 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1")); |
| 258 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,not-excluded-category")); | 280 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,not-excluded-category")); |
| 259 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,CategoryTest")); | 281 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,CategoryTest")); |
| 260 } | 282 } |
| 261 | 283 |
| 284 TEST(TraceConfigTest, TraceConfigFromDict) { | |
| 285 // Passing in empty dictionary will not result in default trace config. | |
| 286 DictionaryValue dict; | |
| 287 TraceConfig tc(dict); | |
| 288 EXPECT_STRNE(kDefaultTraceConfigString, tc.ToString().c_str()); | |
| 289 EXPECT_EQ(RECORD_UNTIL_FULL, tc.GetTraceRecordMode()); | |
| 290 EXPECT_FALSE(tc.IsSamplingEnabled()); | |
| 291 EXPECT_FALSE(tc.IsSystraceEnabled()); | |
| 292 EXPECT_FALSE(tc.IsArgumentFilterEnabled()); | |
| 293 EXPECT_STREQ("", tc.ToCategoryFilterString().c_str()); | |
| 294 | |
| 295 scoped_ptr<Value> default_value(JSONReader::Read(kDefaultTraceConfigString)); | |
| 296 DCHECK(default_value); | |
| 297 const DictionaryValue* default_dict = nullptr; | |
| 298 bool is_dict = default_value->GetAsDictionary(&default_dict); | |
| 299 DCHECK(is_dict); | |
| 300 TraceConfig default_tc(*default_dict); | |
| 301 EXPECT_STREQ(kDefaultTraceConfigString, default_tc.ToString().c_str()); | |
| 302 EXPECT_EQ(RECORD_UNTIL_FULL, default_tc.GetTraceRecordMode()); | |
| 303 EXPECT_FALSE(default_tc.IsSamplingEnabled()); | |
| 304 EXPECT_FALSE(default_tc.IsSystraceEnabled()); | |
| 305 EXPECT_FALSE(default_tc.IsArgumentFilterEnabled()); | |
| 306 EXPECT_STREQ("-*Debug,-*Test", default_tc.ToCategoryFilterString().c_str()); | |
| 307 | |
| 308 scoped_ptr<Value> custom_value(JSONReader::Read(kCustomTraceConfigString)); | |
| 309 DCHECK(custom_value); | |
| 310 const DictionaryValue* custom_dict = nullptr; | |
| 311 DCHECK(custom_value->GetAsDictionary(&custom_dict)); | |
|
fgorski
2016/03/17 23:44:48
this line gets compiled out in release builds.
Zhen Wang
2016/03/18 00:02:39
Thanks! Fixed.
| |
| 312 TraceConfig custom_tc(*custom_dict); | |
| 313 EXPECT_STREQ(kCustomTraceConfigString, custom_tc.ToString().c_str()); | |
| 314 EXPECT_EQ(RECORD_CONTINUOUSLY, custom_tc.GetTraceRecordMode()); | |
| 315 EXPECT_TRUE(custom_tc.IsSamplingEnabled()); | |
| 316 EXPECT_TRUE(custom_tc.IsSystraceEnabled()); | |
| 317 EXPECT_TRUE(custom_tc.IsArgumentFilterEnabled()); | |
| 318 EXPECT_STREQ("included,inc_pattern*," | |
| 319 "disabled-by-default-cc,disabled-by-default-memory-infra," | |
| 320 "-excluded,-exc_pattern*," | |
| 321 "DELAY(test.Delay1;16),DELAY(test.Delay2;32)", | |
| 322 custom_tc.ToCategoryFilterString().c_str()); | |
| 323 } | |
| 324 | |
| 262 TEST(TraceConfigTest, TraceConfigFromValidString) { | 325 TEST(TraceConfigTest, TraceConfigFromValidString) { |
| 263 // Using some non-empty config string. | 326 // Using some non-empty config string. |
| 264 const char config_string[] = | 327 const char config_string[] = |
| 265 "{" | 328 "{" |
| 266 "\"enable_argument_filter\":true," | 329 "\"enable_argument_filter\":true," |
| 267 "\"enable_sampling\":true," | 330 "\"enable_sampling\":true," |
| 268 "\"enable_systrace\":true," | 331 "\"enable_systrace\":true," |
| 269 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," | 332 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," |
| 270 "\"included_categories\":[\"included\"," | 333 "\"included_categories\":[\"included\"," |
| 271 "\"inc_pattern*\"," | 334 "\"inc_pattern*\"," |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 | 588 |
| 526 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { | 589 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { |
| 527 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); | 590 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); |
| 528 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); | 591 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); |
| 529 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); | 592 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); |
| 530 EXPECT_EQ(2u, tc.memory_dump_config_.size()); | 593 EXPECT_EQ(2u, tc.memory_dump_config_.size()); |
| 531 } | 594 } |
| 532 | 595 |
| 533 } // namespace trace_event | 596 } // namespace trace_event |
| 534 } // namespace base | 597 } // namespace base |
| OLD | NEW |