Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: base/trace_event/trace_config_unittest.cc

Issue 1765153002: Update DevTools Tracing.Start to accept trace config as a parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fix for primiano and petrcermak's comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 DCHECK(default_value->GetAsDictionary(&default_dict));
Primiano Tucci (use gerrit) 2016/03/15 12:22:41 Don't put code with side effects in DHCEKC. I expe
Zhen Wang 2016/03/15 16:53:55 Ah, right. Thanks! done.
299 TraceConfig default_tc(*default_dict);
300 EXPECT_STREQ(kDefaultTraceConfigString, default_tc.ToString().c_str());
301 EXPECT_EQ(RECORD_UNTIL_FULL, default_tc.GetTraceRecordMode());
302 EXPECT_FALSE(default_tc.IsSamplingEnabled());
303 EXPECT_FALSE(default_tc.IsSystraceEnabled());
304 EXPECT_FALSE(default_tc.IsArgumentFilterEnabled());
305 EXPECT_STREQ("-*Debug,-*Test", default_tc.ToCategoryFilterString().c_str());
306
307 scoped_ptr<Value> custom_value(JSONReader::Read(kCustomTraceConfigString));
308 DCHECK(custom_value);
309 const DictionaryValue* custom_dict = nullptr;
310 DCHECK(custom_value->GetAsDictionary(&custom_dict));
311 TraceConfig custom_tc(*custom_dict);
312 EXPECT_STREQ(kCustomTraceConfigString, custom_tc.ToString().c_str());
313 EXPECT_EQ(RECORD_CONTINUOUSLY, custom_tc.GetTraceRecordMode());
314 EXPECT_TRUE(custom_tc.IsSamplingEnabled());
315 EXPECT_TRUE(custom_tc.IsSystraceEnabled());
316 EXPECT_TRUE(custom_tc.IsArgumentFilterEnabled());
317 EXPECT_STREQ("included,inc_pattern*,"
318 "disabled-by-default-cc,disabled-by-default-memory-infra,"
319 "-excluded,-exc_pattern*,"
320 "DELAY(test.Delay1;16),DELAY(test.Delay2;32)",
321 custom_tc.ToCategoryFilterString().c_str());
322 }
323
262 TEST(TraceConfigTest, TraceConfigFromValidString) { 324 TEST(TraceConfigTest, TraceConfigFromValidString) {
263 // Using some non-empty config string. 325 // Using some non-empty config string.
264 const char config_string[] = 326 const char config_string[] =
265 "{" 327 "{"
266 "\"enable_argument_filter\":true," 328 "\"enable_argument_filter\":true,"
267 "\"enable_sampling\":true," 329 "\"enable_sampling\":true,"
268 "\"enable_systrace\":true," 330 "\"enable_systrace\":true,"
269 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," 331 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"],"
270 "\"included_categories\":[\"included\"," 332 "\"included_categories\":[\"included\","
271 "\"inc_pattern*\"," 333 "\"inc_pattern*\","
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 587
526 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { 588 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) {
527 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); 589 TraceConfig tc(MemoryDumpManager::kTraceCategory, "");
528 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); 590 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory));
529 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); 591 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config"));
530 EXPECT_EQ(2u, tc.memory_dump_config_.size()); 592 EXPECT_EQ(2u, tc.memory_dump_config_.size());
531 } 593 }
532 594
533 } // namespace trace_event 595 } // namespace trace_event
534 } // namespace base 596 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698