OLD | NEW |
---|---|
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 class TraceEventTestFixture : public testing::Test { | 48 class TraceEventTestFixture : public testing::Test { |
49 public: | 49 public: |
50 // This fixture does not use SetUp() because the fixture must be manually set | 50 // This fixture does not use SetUp() because the fixture must be manually set |
51 // up multiple times when testing AtExit. Use ManualTestSetUp for this. | 51 // up multiple times when testing AtExit. Use ManualTestSetUp for this. |
52 void ManualTestSetUp(); | 52 void ManualTestSetUp(); |
53 void OnTraceDataCollected( | 53 void OnTraceDataCollected( |
54 const scoped_refptr<base::RefCountedString>& events_str); | 54 const scoped_refptr<base::RefCountedString>& events_str); |
55 void OnTraceNotification(int notification) { | 55 void OnTraceNotification(int notification) { |
56 if (notification & TraceLog::EVENT_WATCH_NOTIFICATION) | 56 if (notification & TraceLog::EVENT_WATCH_NOTIFICATION) |
57 ++event_watch_notification_; | 57 ++event_watch_notification_; |
58 notifications_received_ |= notification; | |
58 } | 59 } |
59 DictionaryValue* FindMatchingTraceEntry(const JsonKeyValue* key_values); | 60 DictionaryValue* FindMatchingTraceEntry(const JsonKeyValue* key_values); |
60 DictionaryValue* FindNamePhase(const char* name, const char* phase); | 61 DictionaryValue* FindNamePhase(const char* name, const char* phase); |
61 DictionaryValue* FindNamePhaseKeyValue(const char* name, | 62 DictionaryValue* FindNamePhaseKeyValue(const char* name, |
62 const char* phase, | 63 const char* phase, |
63 const char* key, | 64 const char* key, |
64 const char* value); | 65 const char* value); |
65 bool FindMatchingValue(const char* key, | 66 bool FindMatchingValue(const char* key, |
66 const char* value); | 67 const char* value); |
67 bool FindNonMatchingValue(const char* key, | 68 bool FindNonMatchingValue(const char* key, |
68 const char* value); | 69 const char* value); |
69 void Clear() { | 70 void Clear() { |
70 trace_parsed_.Clear(); | 71 trace_parsed_.Clear(); |
71 json_output_.json_output.clear(); | 72 json_output_.json_output.clear(); |
72 } | 73 } |
73 | 74 |
74 void BeginTrace() { | 75 void BeginTrace() { |
75 event_watch_notification_ = 0; | 76 event_watch_notification_ = 0; |
77 notifications_received_ = 0; | |
76 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), | 78 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), |
77 TraceLog::RECORD_UNTIL_FULL); | 79 TraceLog::RECORD_UNTIL_FULL); |
78 } | 80 } |
79 | 81 |
80 void EndTraceAndFlush() { | 82 void EndTraceAndFlush() { |
81 while (TraceLog::GetInstance()->IsEnabled()) | 83 while (TraceLog::GetInstance()->IsEnabled()) |
82 TraceLog::GetInstance()->SetDisabled(); | 84 TraceLog::GetInstance()->SetDisabled(); |
83 TraceLog::GetInstance()->Flush( | 85 TraceLog::GetInstance()->Flush( |
84 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, | 86 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
85 base::Unretained(this))); | 87 base::Unretained(this))); |
86 } | 88 } |
87 | 89 |
88 virtual void SetUp() OVERRIDE { | 90 virtual void SetUp() OVERRIDE { |
89 const char* name = PlatformThread::GetName(); | 91 const char* name = PlatformThread::GetName(); |
90 old_thread_name_ = name ? strdup(name) : NULL; | 92 old_thread_name_ = name ? strdup(name) : NULL; |
91 } | 93 } |
92 virtual void TearDown() OVERRIDE { | 94 virtual void TearDown() OVERRIDE { |
93 if (TraceLog::GetInstance()) | 95 if (TraceLog::GetInstance()) |
94 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); | 96 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); |
95 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); | 97 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); |
96 free(old_thread_name_); | 98 free(old_thread_name_); |
97 old_thread_name_ = NULL; | 99 old_thread_name_ = NULL; |
98 } | 100 } |
99 | 101 |
100 char* old_thread_name_; | 102 char* old_thread_name_; |
101 ListValue trace_parsed_; | 103 ListValue trace_parsed_; |
102 base::debug::TraceResultBuffer trace_buffer_; | 104 base::debug::TraceResultBuffer trace_buffer_; |
103 base::debug::TraceResultBuffer::SimpleOutput json_output_; | 105 base::debug::TraceResultBuffer::SimpleOutput json_output_; |
104 int event_watch_notification_; | 106 int event_watch_notification_; |
107 int notifications_received_; | |
105 | 108 |
106 private: | 109 private: |
107 // We want our singleton torn down after each test. | 110 // We want our singleton torn down after each test. |
108 ShadowingAtExitManager at_exit_manager_; | 111 ShadowingAtExitManager at_exit_manager_; |
109 Lock lock_; | 112 Lock lock_; |
110 }; | 113 }; |
111 | 114 |
112 void TraceEventTestFixture::ManualTestSetUp() { | 115 void TraceEventTestFixture::ManualTestSetUp() { |
113 TraceLog::DeleteForTesting(); | 116 TraceLog::DeleteForTesting(); |
114 TraceLog::Resurrect(); | 117 TraceLog::Resurrect(); |
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1659 TRACE_EVENT_INSTANT0("all", "before enable", TRACE_EVENT_SCOPE_THREAD); | 1662 TRACE_EVENT_INSTANT0("all", "before enable", TRACE_EVENT_SCOPE_THREAD); |
1660 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), | 1663 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), |
1661 TraceLog::RECORD_UNTIL_FULL); | 1664 TraceLog::RECORD_UNTIL_FULL); |
1662 TRACE_EVENT_INSTANT0("all", "before callback set", TRACE_EVENT_SCOPE_THREAD); | 1665 TRACE_EVENT_INSTANT0("all", "before callback set", TRACE_EVENT_SCOPE_THREAD); |
1663 TraceLog::GetInstance()->SetEventCallback(Callback); | 1666 TraceLog::GetInstance()->SetEventCallback(Callback); |
1664 TRACE_EVENT_INSTANT0("all", "event1", TRACE_EVENT_SCOPE_GLOBAL); | 1667 TRACE_EVENT_INSTANT0("all", "event1", TRACE_EVENT_SCOPE_GLOBAL); |
1665 TRACE_EVENT_INSTANT0("all", "event2", TRACE_EVENT_SCOPE_GLOBAL); | 1668 TRACE_EVENT_INSTANT0("all", "event2", TRACE_EVENT_SCOPE_GLOBAL); |
1666 TraceLog::GetInstance()->SetEventCallback(NULL); | 1669 TraceLog::GetInstance()->SetEventCallback(NULL); |
1667 TRACE_EVENT_INSTANT0("all", "after callback removed", | 1670 TRACE_EVENT_INSTANT0("all", "after callback removed", |
1668 TRACE_EVENT_SCOPE_GLOBAL); | 1671 TRACE_EVENT_SCOPE_GLOBAL); |
1669 EXPECT_EQ(2u, collected_events_.size()); | 1672 ASSERT_EQ(2u, collected_events_.size()); |
jar (doing other things)
2013/04/26 16:43:31
nice catch/correction.
| |
1670 EXPECT_EQ("event1", collected_events_[0]); | 1673 EXPECT_EQ("event1", collected_events_[0]); |
1671 EXPECT_EQ("event2", collected_events_[1]); | 1674 EXPECT_EQ("event2", collected_events_[1]); |
1672 } | 1675 } |
1673 | 1676 |
1677 TEST_F(TraceEventCallbackTest, TraceEventCallbackWhileFull) { | |
1678 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), | |
1679 TraceLog::RECORD_UNTIL_FULL); | |
1680 do { | |
1681 TRACE_EVENT_INSTANT0("all", "badger badger", TRACE_EVENT_SCOPE_GLOBAL); | |
1682 } while ((notifications_received_ & TraceLog::TRACE_BUFFER_FULL) == 0); | |
1683 TraceLog::GetInstance()->SetEventCallback(Callback); | |
1684 TRACE_EVENT_INSTANT0("all", "a snake", TRACE_EVENT_SCOPE_GLOBAL); | |
1685 TraceLog::GetInstance()->SetEventCallback(NULL); | |
1686 ASSERT_EQ(1u, collected_events_.size()); | |
1687 EXPECT_EQ("a snake", collected_events_[0]); | |
1688 } | |
1689 | |
1674 // TODO(dsinclair): Continuous Tracing unit test. | 1690 // TODO(dsinclair): Continuous Tracing unit test. |
1675 | 1691 |
1676 // Test the category filter. | 1692 // Test the category filter. |
1677 TEST_F(TraceEventTestFixture, CategoryFilter) { | 1693 TEST_F(TraceEventTestFixture, CategoryFilter) { |
1678 ManualTestSetUp(); | 1694 ManualTestSetUp(); |
1679 | 1695 |
1680 // Using the default filter. | 1696 // Using the default filter. |
1681 CategoryFilter default_cf = CategoryFilter( | 1697 CategoryFilter default_cf = CategoryFilter( |
1682 CategoryFilter::kDefaultCategoryFilterString); | 1698 CategoryFilter::kDefaultCategoryFilterString); |
1683 std::string category_filter_str = default_cf.ToString(); | 1699 std::string category_filter_str = default_cf.ToString(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1749 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( | 1765 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
1750 " bad_category ")); | 1766 " bad_category ")); |
1751 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( | 1767 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
1752 "")); | 1768 "")); |
1753 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( | 1769 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
1754 "good_category")); | 1770 "good_category")); |
1755 } | 1771 } |
1756 | 1772 |
1757 } // namespace debug | 1773 } // namespace debug |
1758 } // namespace base | 1774 } // namespace base |
OLD | NEW |