| 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 <math.h> | 7 #include <math.h> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 flush_complete_event.Wait(); | 118 flush_complete_event.Wait(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void FlushMonitoring(WaitableEvent* flush_complete_event) { | 121 void FlushMonitoring(WaitableEvent* flush_complete_event) { |
| 122 TraceLog::GetInstance()->FlushButLeaveBufferIntact( | 122 TraceLog::GetInstance()->FlushButLeaveBufferIntact( |
| 123 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, | 123 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
| 124 base::Unretained(static_cast<TraceEventTestFixture*>(this)), | 124 base::Unretained(static_cast<TraceEventTestFixture*>(this)), |
| 125 base::Unretained(flush_complete_event))); | 125 base::Unretained(flush_complete_event))); |
| 126 } | 126 } |
| 127 | 127 |
| 128 virtual void SetUp() OVERRIDE { | 128 void SetUp() override { |
| 129 const char* name = PlatformThread::GetName(); | 129 const char* name = PlatformThread::GetName(); |
| 130 old_thread_name_ = name ? strdup(name) : NULL; | 130 old_thread_name_ = name ? strdup(name) : NULL; |
| 131 | 131 |
| 132 TraceLog::DeleteForTesting(); | 132 TraceLog::DeleteForTesting(); |
| 133 TraceLog* tracelog = TraceLog::GetInstance(); | 133 TraceLog* tracelog = TraceLog::GetInstance(); |
| 134 ASSERT_TRUE(tracelog); | 134 ASSERT_TRUE(tracelog); |
| 135 ASSERT_FALSE(tracelog->IsEnabled()); | 135 ASSERT_FALSE(tracelog->IsEnabled()); |
| 136 trace_buffer_.SetOutputCallback(json_output_.GetCallback()); | 136 trace_buffer_.SetOutputCallback(json_output_.GetCallback()); |
| 137 event_watch_notification_ = 0; | 137 event_watch_notification_ = 0; |
| 138 } | 138 } |
| 139 virtual void TearDown() OVERRIDE { | 139 void TearDown() override { |
| 140 if (TraceLog::GetInstance()) | 140 if (TraceLog::GetInstance()) |
| 141 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); | 141 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); |
| 142 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); | 142 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); |
| 143 free(old_thread_name_); | 143 free(old_thread_name_); |
| 144 old_thread_name_ = NULL; | 144 old_thread_name_ = NULL; |
| 145 // We want our singleton torn down after each test. | 145 // We want our singleton torn down after each test. |
| 146 TraceLog::DeleteForTesting(); | 146 TraceLog::DeleteForTesting(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 char* old_thread_name_; | 149 char* old_thread_name_; |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 } | 989 } |
| 990 | 990 |
| 991 // Tests the IsEnabled() state of TraceLog changes before callbacks. | 991 // Tests the IsEnabled() state of TraceLog changes before callbacks. |
| 992 class AfterStateChangeEnabledStateObserver | 992 class AfterStateChangeEnabledStateObserver |
| 993 : public TraceLog::EnabledStateObserver { | 993 : public TraceLog::EnabledStateObserver { |
| 994 public: | 994 public: |
| 995 AfterStateChangeEnabledStateObserver() {} | 995 AfterStateChangeEnabledStateObserver() {} |
| 996 virtual ~AfterStateChangeEnabledStateObserver() {} | 996 virtual ~AfterStateChangeEnabledStateObserver() {} |
| 997 | 997 |
| 998 // TraceLog::EnabledStateObserver overrides: | 998 // TraceLog::EnabledStateObserver overrides: |
| 999 virtual void OnTraceLogEnabled() OVERRIDE { | 999 void OnTraceLogEnabled() override { |
| 1000 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); | 1000 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 virtual void OnTraceLogDisabled() OVERRIDE { | 1003 void OnTraceLogDisabled() override { |
| 1004 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); | 1004 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); |
| 1005 } | 1005 } |
| 1006 }; | 1006 }; |
| 1007 | 1007 |
| 1008 TEST_F(TraceEventTestFixture, ObserversFireAfterStateChange) { | 1008 TEST_F(TraceEventTestFixture, ObserversFireAfterStateChange) { |
| 1009 AfterStateChangeEnabledStateObserver observer; | 1009 AfterStateChangeEnabledStateObserver observer; |
| 1010 TraceLog::GetInstance()->AddEnabledStateObserver(&observer); | 1010 TraceLog::GetInstance()->AddEnabledStateObserver(&observer); |
| 1011 | 1011 |
| 1012 TraceLog::GetInstance()->SetEnabled( | 1012 TraceLog::GetInstance()->SetEnabled( |
| 1013 CategoryFilter("*"), | 1013 CategoryFilter("*"), |
| 1014 TraceLog::RECORDING_MODE, | 1014 TraceLog::RECORDING_MODE, |
| 1015 TraceOptions()); | 1015 TraceOptions()); |
| 1016 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); | 1016 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); |
| 1017 | 1017 |
| 1018 TraceLog::GetInstance()->SetDisabled(); | 1018 TraceLog::GetInstance()->SetDisabled(); |
| 1019 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); | 1019 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); |
| 1020 | 1020 |
| 1021 TraceLog::GetInstance()->RemoveEnabledStateObserver(&observer); | 1021 TraceLog::GetInstance()->RemoveEnabledStateObserver(&observer); |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 // Tests that a state observer can remove itself during a callback. | 1024 // Tests that a state observer can remove itself during a callback. |
| 1025 class SelfRemovingEnabledStateObserver | 1025 class SelfRemovingEnabledStateObserver |
| 1026 : public TraceLog::EnabledStateObserver { | 1026 : public TraceLog::EnabledStateObserver { |
| 1027 public: | 1027 public: |
| 1028 SelfRemovingEnabledStateObserver() {} | 1028 SelfRemovingEnabledStateObserver() {} |
| 1029 virtual ~SelfRemovingEnabledStateObserver() {} | 1029 virtual ~SelfRemovingEnabledStateObserver() {} |
| 1030 | 1030 |
| 1031 // TraceLog::EnabledStateObserver overrides: | 1031 // TraceLog::EnabledStateObserver overrides: |
| 1032 virtual void OnTraceLogEnabled() OVERRIDE {} | 1032 void OnTraceLogEnabled() override {} |
| 1033 | 1033 |
| 1034 virtual void OnTraceLogDisabled() OVERRIDE { | 1034 void OnTraceLogDisabled() override { |
| 1035 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); | 1035 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); |
| 1036 } | 1036 } |
| 1037 }; | 1037 }; |
| 1038 | 1038 |
| 1039 TEST_F(TraceEventTestFixture, SelfRemovingObserver) { | 1039 TEST_F(TraceEventTestFixture, SelfRemovingObserver) { |
| 1040 ASSERT_EQ(0u, TraceLog::GetInstance()->GetObserverCountForTest()); | 1040 ASSERT_EQ(0u, TraceLog::GetInstance()->GetObserverCountForTest()); |
| 1041 | 1041 |
| 1042 SelfRemovingEnabledStateObserver observer; | 1042 SelfRemovingEnabledStateObserver observer; |
| 1043 TraceLog::GetInstance()->AddEnabledStateObserver(&observer); | 1043 TraceLog::GetInstance()->AddEnabledStateObserver(&observer); |
| 1044 EXPECT_EQ(1u, TraceLog::GetInstance()->GetObserverCountForTest()); | 1044 EXPECT_EQ(1u, TraceLog::GetInstance()->GetObserverCountForTest()); |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 EXPECT_FALSE(FindNamePhase("CCC", "P")); | 1912 EXPECT_FALSE(FindNamePhase("CCC", "P")); |
| 1913 EXPECT_FALSE(FindNamePhase("DDD", "P")); | 1913 EXPECT_FALSE(FindNamePhase("DDD", "P")); |
| 1914 | 1914 |
| 1915 Clear(); | 1915 Clear(); |
| 1916 } | 1916 } |
| 1917 | 1917 |
| 1918 class MyData : public ConvertableToTraceFormat { | 1918 class MyData : public ConvertableToTraceFormat { |
| 1919 public: | 1919 public: |
| 1920 MyData() {} | 1920 MyData() {} |
| 1921 | 1921 |
| 1922 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { | 1922 void AppendAsTraceFormat(std::string* out) const override { |
| 1923 out->append("{\"foo\":1}"); | 1923 out->append("{\"foo\":1}"); |
| 1924 } | 1924 } |
| 1925 | 1925 |
| 1926 private: | 1926 private: |
| 1927 virtual ~MyData() {} | 1927 virtual ~MyData() {} |
| 1928 DISALLOW_COPY_AND_ASSIGN(MyData); | 1928 DISALLOW_COPY_AND_ASSIGN(MyData); |
| 1929 }; | 1929 }; |
| 1930 | 1930 |
| 1931 TEST_F(TraceEventTestFixture, ConvertableTypes) { | 1931 TEST_F(TraceEventTestFixture, ConvertableTypes) { |
| 1932 TraceLog::GetInstance()->SetEnabled( | 1932 TraceLog::GetInstance()->SetEnabled( |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2196 dict = FindNamePhase("event15", "X"); | 2196 dict = FindNamePhase("event15", "X"); |
| 2197 ASSERT_TRUE(dict); | 2197 ASSERT_TRUE(dict); |
| 2198 dict->GetDictionary("args", &args_dict); | 2198 dict->GetDictionary("args", &args_dict); |
| 2199 ASSERT_TRUE(args_dict); | 2199 ASSERT_TRUE(args_dict); |
| 2200 EXPECT_TRUE(args_dict->GetInteger("timeticks_one", &int_value)); | 2200 EXPECT_TRUE(args_dict->GetInteger("timeticks_one", &int_value)); |
| 2201 EXPECT_EQ(1, int_value); | 2201 EXPECT_EQ(1, int_value); |
| 2202 } | 2202 } |
| 2203 | 2203 |
| 2204 class TraceEventCallbackTest : public TraceEventTestFixture { | 2204 class TraceEventCallbackTest : public TraceEventTestFixture { |
| 2205 public: | 2205 public: |
| 2206 virtual void SetUp() OVERRIDE { | 2206 void SetUp() override { |
| 2207 TraceEventTestFixture::SetUp(); | 2207 TraceEventTestFixture::SetUp(); |
| 2208 ASSERT_EQ(NULL, s_instance); | 2208 ASSERT_EQ(NULL, s_instance); |
| 2209 s_instance = this; | 2209 s_instance = this; |
| 2210 } | 2210 } |
| 2211 virtual void TearDown() OVERRIDE { | 2211 void TearDown() override { |
| 2212 TraceLog::GetInstance()->SetDisabled(); | 2212 TraceLog::GetInstance()->SetDisabled(); |
| 2213 ASSERT_TRUE(!!s_instance); | 2213 ASSERT_TRUE(!!s_instance); |
| 2214 s_instance = NULL; | 2214 s_instance = NULL; |
| 2215 TraceEventTestFixture::TearDown(); | 2215 TraceEventTestFixture::TearDown(); |
| 2216 } | 2216 } |
| 2217 | 2217 |
| 2218 protected: | 2218 protected: |
| 2219 // For TraceEventCallbackAndRecordingX tests. | 2219 // For TraceEventCallbackAndRecordingX tests. |
| 2220 void VerifyCallbackAndRecordedEvents(size_t expected_callback_count, | 2220 void VerifyCallbackAndRecordedEvents(size_t expected_callback_count, |
| 2221 size_t expected_recorded_count) { | 2221 size_t expected_recorded_count) { |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3072 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling); | 3072 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling); |
| 3073 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace); | 3073 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace); |
| 3074 } | 3074 } |
| 3075 } | 3075 } |
| 3076 } | 3076 } |
| 3077 } | 3077 } |
| 3078 | 3078 |
| 3079 | 3079 |
| 3080 } // namespace debug | 3080 } // namespace debug |
| 3081 } // namespace base | 3081 } // namespace base |
| OLD | NEW |