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

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

Issue 1814043002: Revert of Update DevTools Tracing.Start to accept trace config as a parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « base/trace_event/trace_config.cc ('k') | components/tracing/trace_config_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
8 #include "base/macros.h" 7 #include "base/macros.h"
9 #include "base/trace_event/memory_dump_manager.h" 8 #include "base/trace_event/memory_dump_manager.h"
10 #include "base/trace_event/trace_config.h" 9 #include "base/trace_event/trace_config.h"
11 #include "base/trace_event/trace_config_memory_test_util.h" 10 #include "base/trace_event/trace_config_memory_test_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 12
14 namespace base { 13 namespace base {
15 namespace trace_event { 14 namespace trace_event {
16 15
17 namespace { 16 namespace {
18 17
19 const char kDefaultTraceConfigString[] = 18 const char kDefaultTraceConfigString[] =
20 "{" 19 "{"
21 "\"enable_argument_filter\":false," 20 "\"enable_argument_filter\":false,"
22 "\"enable_sampling\":false," 21 "\"enable_sampling\":false,"
23 "\"enable_systrace\":false," 22 "\"enable_systrace\":false,"
24 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," 23 "\"excluded_categories\":[\"*Debug\",\"*Test\"],"
25 "\"record_mode\":\"record-until-full\"" 24 "\"record_mode\":\"record-until-full\""
26 "}"; 25 "}";
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
48 } // namespace 26 } // namespace
49 27
50 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { 28 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) {
51 // From trace options strings 29 // From trace options strings
52 TraceConfig config("", "record-until-full"); 30 TraceConfig config("", "record-until-full");
53 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); 31 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode());
54 EXPECT_FALSE(config.IsSamplingEnabled()); 32 EXPECT_FALSE(config.IsSamplingEnabled());
55 EXPECT_FALSE(config.IsSystraceEnabled()); 33 EXPECT_FALSE(config.IsSystraceEnabled());
56 EXPECT_FALSE(config.IsArgumentFilterEnabled()); 34 EXPECT_FALSE(config.IsArgumentFilterEnabled());
57 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); 35 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str());
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest")); 252 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest"));
275 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug")); 253 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug"));
276 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-cc")); 254 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-cc"));
277 255
278 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug")); 256 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug"));
279 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1")); 257 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1"));
280 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,not-excluded-category")); 258 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,not-excluded-category"));
281 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,CategoryTest")); 259 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,CategoryTest"));
282 } 260 }
283 261
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));
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
325 TEST(TraceConfigTest, TraceConfigFromValidString) { 262 TEST(TraceConfigTest, TraceConfigFromValidString) {
326 // Using some non-empty config string. 263 // Using some non-empty config string.
327 const char config_string[] = 264 const char config_string[] =
328 "{" 265 "{"
329 "\"enable_argument_filter\":true," 266 "\"enable_argument_filter\":true,"
330 "\"enable_sampling\":true," 267 "\"enable_sampling\":true,"
331 "\"enable_systrace\":true," 268 "\"enable_systrace\":true,"
332 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," 269 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"],"
333 "\"included_categories\":[\"included\"," 270 "\"included_categories\":[\"included\","
334 "\"inc_pattern*\"," 271 "\"inc_pattern*\","
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 525
589 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { 526 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) {
590 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); 527 TraceConfig tc(MemoryDumpManager::kTraceCategory, "");
591 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); 528 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory));
592 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); 529 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config"));
593 EXPECT_EQ(2u, tc.memory_dump_config_.size()); 530 EXPECT_EQ(2u, tc.memory_dump_config_.size());
594 } 531 }
595 532
596 } // namespace trace_event 533 } // namespace trace_event
597 } // namespace base 534 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_config.cc ('k') | components/tracing/trace_config_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698