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/debug/trace_event_unittest.cc

Issue 18338004: Don't use StaticMemorySingletonTraits for TraceLog. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: use LeakySingletonTraits as TraceLog is used on non-joinable threads Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_impl.cc ('k') | base/debug/trace_event_win_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/debug/trace_event_unittest.h" 5 #include "base/debug/trace_event_unittest.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 const char* name = PlatformThread::GetName(); 97 const char* name = PlatformThread::GetName();
98 old_thread_name_ = name ? strdup(name) : NULL; 98 old_thread_name_ = name ? strdup(name) : NULL;
99 notifications_received_ = 0; 99 notifications_received_ = 0;
100 } 100 }
101 virtual void TearDown() OVERRIDE { 101 virtual void TearDown() OVERRIDE {
102 if (TraceLog::GetInstance()) 102 if (TraceLog::GetInstance())
103 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); 103 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled());
104 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); 104 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : "");
105 free(old_thread_name_); 105 free(old_thread_name_);
106 old_thread_name_ = NULL; 106 old_thread_name_ = NULL;
107 // We want our singleton torn down after each test.
108 TraceLog::DeleteForTesting();
107 } 109 }
108 110
109 char* old_thread_name_; 111 char* old_thread_name_;
110 ListValue trace_parsed_; 112 ListValue trace_parsed_;
111 base::debug::TraceResultBuffer trace_buffer_; 113 base::debug::TraceResultBuffer trace_buffer_;
112 base::debug::TraceResultBuffer::SimpleOutput json_output_; 114 base::debug::TraceResultBuffer::SimpleOutput json_output_;
113 int event_watch_notification_; 115 int event_watch_notification_;
114 int notifications_received_; 116 int notifications_received_;
115 117
116 private: 118 private:
117 // We want our singleton torn down after each test. 119 // We want our singleton torn down after each test.
118 ShadowingAtExitManager at_exit_manager_; 120 ShadowingAtExitManager at_exit_manager_;
119 Lock lock_; 121 Lock lock_;
120 }; 122 };
121 123
122 void TraceEventTestFixture::ManualTestSetUp() { 124 void TraceEventTestFixture::ManualTestSetUp() {
123 TraceLog::DeleteForTesting(); 125 TraceLog::DeleteForTesting();
124 TraceLog::Resurrect();
125 TraceLog* tracelog = TraceLog::GetInstance(); 126 TraceLog* tracelog = TraceLog::GetInstance();
126 ASSERT_TRUE(tracelog); 127 ASSERT_TRUE(tracelog);
127 ASSERT_FALSE(tracelog->IsEnabled()); 128 ASSERT_FALSE(tracelog->IsEnabled());
128 tracelog->SetNotificationCallback( 129 tracelog->SetNotificationCallback(
129 base::Bind(&TraceEventTestFixture::OnTraceNotification, 130 base::Bind(&TraceEventTestFixture::OnTraceNotification,
130 base::Unretained(this))); 131 base::Unretained(this)));
131 trace_buffer_.SetOutputCallback(json_output_.GetCallback()); 132 trace_buffer_.SetOutputCallback(json_output_.GetCallback());
132 } 133 }
133 134
134 void TraceEventTestFixture::OnTraceDataCollected( 135 void TraceEventTestFixture::OnTraceDataCollected(
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 EndTraceAndFlush(); 1515 EndTraceAndFlush();
1515 1516
1516 { 1517 {
1517 const DictionaryValue* item = NULL; 1518 const DictionaryValue* item = NULL;
1518 ListValue& trace_parsed = trace_parsed_; 1519 ListValue& trace_parsed = trace_parsed_;
1519 EXPECT_FIND_("disabled-by-default-cc"); 1520 EXPECT_FIND_("disabled-by-default-cc");
1520 EXPECT_FIND_("other_included"); 1521 EXPECT_FIND_("other_included");
1521 } 1522 }
1522 } 1523 }
1523 1524
1524 // Test trace calls made after tracing singleton shut down.
scheib 2013/07/08 22:58:57 I was initially hesitant to remove this test- but
jam 2013/07/08 23:03:10 Done.
1525 //
1526 // The singleton is destroyed by our base::AtExitManager, but there can be
1527 // code still executing as the C++ static objects are destroyed. This test
1528 // forces the singleton to destroy early, and intentinally makes trace calls
1529 // afterwards.
1530 TEST_F(TraceEventTestFixture, AtExit) {
1531 // Repeat this test a few times. Besides just showing robustness, it also
1532 // allows us to test that events at shutdown do not appear with valid events
1533 // recorded after the system is started again.
1534 for (int i = 0; i < 4; i++) {
1535 // Scope to contain the then destroy the TraceLog singleton.
1536 {
1537 base::ShadowingAtExitManager exit_manager_will_destroy_singletons;
1538
1539 // Setup TraceLog singleton inside this test's exit manager scope
1540 // so that it will be destroyed when this scope closes.
1541 ManualTestSetUp();
1542
1543 TRACE_EVENT_INSTANT0("all", "not recorded; system not enabled",
1544 TRACE_EVENT_SCOPE_THREAD);
1545
1546 BeginTrace();
1547
1548 TRACE_EVENT_INSTANT0("all", "is recorded 1; system has been enabled",
1549 TRACE_EVENT_SCOPE_THREAD);
1550 // Trace calls that will cache pointers to categories; they're valid here
1551 TraceCallsWithCachedCategoryPointersPointers(
1552 "is recorded 2; system has been enabled");
1553
1554 EndTraceAndFlush();
1555 } // scope to destroy singleton
1556 ASSERT_FALSE(TraceLog::GetInstance());
1557
1558 // Now that singleton is destroyed, check what trace events were recorded
1559 const DictionaryValue* item = NULL;
1560 ListValue& trace_parsed = trace_parsed_;
1561 EXPECT_FIND_("is recorded 1");
1562 EXPECT_FIND_("is recorded 2");
1563 EXPECT_NOT_FIND_("not recorded");
1564
1565 // Make additional trace event calls on the shutdown system. They should
1566 // all pass cleanly, but the data not be recorded. We'll verify that next
1567 // time around the loop (the only way to flush the trace buffers).
1568 TRACE_EVENT_BEGIN_ETW("not recorded; system shutdown", 0, NULL);
1569 TRACE_EVENT_END_ETW("not recorded; system shutdown", 0, NULL);
1570 TRACE_EVENT_INSTANT_ETW("not recorded; system shutdown", 0, NULL);
1571 TRACE_EVENT0("all", "not recorded; system shutdown");
1572 TRACE_EVENT_INSTANT0("all", "not recorded; system shutdown",
1573 TRACE_EVENT_SCOPE_THREAD);
1574 TRACE_EVENT_BEGIN0("all", "not recorded; system shutdown");
1575 TRACE_EVENT_END0("all", "not recorded; system shutdown");
1576
1577 TRACE_EVENT0("new category 0!", "not recorded; system shutdown");
1578 TRACE_EVENT_INSTANT0("new category 1!", "not recorded; system shutdown",
1579 TRACE_EVENT_SCOPE_THREAD);
1580 TRACE_EVENT_BEGIN0("new category 2!", "not recorded; system shutdown");
1581 TRACE_EVENT_END0("new category 3!", "not recorded; system shutdown");
1582
1583 // Cached categories should be safe to check, and still disable traces
1584 TraceCallsWithCachedCategoryPointersPointers(
1585 "not recorded; system shutdown");
1586 }
1587 }
1588
1589 TEST_F(TraceEventTestFixture, NormallyNoDeepCopy) { 1525 TEST_F(TraceEventTestFixture, NormallyNoDeepCopy) {
1590 // Test that the TRACE_EVENT macros do not deep-copy their string. If they 1526 // Test that the TRACE_EVENT macros do not deep-copy their string. If they
1591 // do so it may indicate a performance regression, but more-over it would 1527 // do so it may indicate a performance regression, but more-over it would
1592 // make the DEEP_COPY overloads redundant. 1528 // make the DEEP_COPY overloads redundant.
1593 ManualTestSetUp(); 1529 ManualTestSetUp();
1594 1530
1595 std::string name_string("event name"); 1531 std::string name_string("event name");
1596 1532
1597 BeginTrace(); 1533 BeginTrace();
1598 TRACE_EVENT_INSTANT0("category", name_string.c_str(), 1534 TRACE_EVENT_INSTANT0("category", name_string.c_str(),
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( 2073 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2138 " bad_category ")); 2074 " bad_category "));
2139 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( 2075 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2140 "")); 2076 ""));
2141 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( 2077 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2142 "good_category")); 2078 "good_category"));
2143 } 2079 }
2144 2080
2145 } // namespace debug 2081 } // namespace debug
2146 } // namespace base 2082 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_impl.cc ('k') | base/debug/trace_event_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698