| 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 // Unit tests for event trace consumer base class. | 5 // Unit tests for event trace consumer base class. |
| 6 #include "base/win/event_trace_consumer.h" | 6 #include "base/win/event_trace_consumer.h" |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include <objbase.h> | 10 #include <objbase.h> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 ScopedHandle TestConsumer::sank_event_; | 76 ScopedHandle TestConsumer::sank_event_; |
| 77 EventQueue TestConsumer::events_; | 77 EventQueue TestConsumer::events_; |
| 78 | 78 |
| 79 class EtwTraceConsumerBaseTest: public testing::Test { | 79 class EtwTraceConsumerBaseTest: public testing::Test { |
| 80 public: | 80 public: |
| 81 EtwTraceConsumerBaseTest() | 81 EtwTraceConsumerBaseTest() |
| 82 : session_name_(StringPrintf(L"TestSession-%d", GetCurrentProcId())) { | 82 : session_name_(StringPrintf(L"TestSession-%d", GetCurrentProcId())) { |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual void SetUp() { | 85 void SetUp() override { |
| 86 // Cleanup any potentially dangling sessions. | 86 // Cleanup any potentially dangling sessions. |
| 87 EtwTraceProperties ignore; | 87 EtwTraceProperties ignore; |
| 88 EtwTraceController::Stop(session_name_.c_str(), &ignore); | 88 EtwTraceController::Stop(session_name_.c_str(), &ignore); |
| 89 | 89 |
| 90 // Allocate a new GUID for each provider test. | 90 // Allocate a new GUID for each provider test. |
| 91 ASSERT_HRESULT_SUCCEEDED(::CoCreateGuid(&test_provider_)); | 91 ASSERT_HRESULT_SUCCEEDED(::CoCreateGuid(&test_provider_)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual void TearDown() { | 94 void TearDown() override { |
| 95 // Cleanup any potentially dangling sessions. | 95 // Cleanup any potentially dangling sessions. |
| 96 EtwTraceProperties ignore; | 96 EtwTraceProperties ignore; |
| 97 EtwTraceController::Stop(session_name_.c_str(), &ignore); | 97 EtwTraceController::Stop(session_name_.c_str(), &ignore); |
| 98 } | 98 } |
| 99 | 99 |
| 100 protected: | 100 protected: |
| 101 GUID test_provider_; | 101 GUID test_provider_; |
| 102 std::wstring session_name_; | 102 std::wstring session_name_; |
| 103 }; | 103 }; |
| 104 | 104 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 TestConsumer consumer_; | 118 TestConsumer consumer_; |
| 119 ASSERT_HRESULT_SUCCEEDED( | 119 ASSERT_HRESULT_SUCCEEDED( |
| 120 consumer_.OpenRealtimeSession(session_name_.c_str())); | 120 consumer_.OpenRealtimeSession(session_name_.c_str())); |
| 121 ASSERT_HRESULT_FAILED(consumer_.Consume()); | 121 ASSERT_HRESULT_FAILED(consumer_.Consume()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 namespace { | 124 namespace { |
| 125 | 125 |
| 126 class EtwTraceConsumerRealtimeTest: public EtwTraceConsumerBaseTest { | 126 class EtwTraceConsumerRealtimeTest: public EtwTraceConsumerBaseTest { |
| 127 public: | 127 public: |
| 128 virtual void SetUp() { | 128 void SetUp() override { |
| 129 EtwTraceConsumerBaseTest::SetUp(); | 129 EtwTraceConsumerBaseTest::SetUp(); |
| 130 ASSERT_HRESULT_SUCCEEDED( | 130 ASSERT_HRESULT_SUCCEEDED( |
| 131 consumer_.OpenRealtimeSession(session_name_.c_str())); | 131 consumer_.OpenRealtimeSession(session_name_.c_str())); |
| 132 } | 132 } |
| 133 | 133 |
| 134 virtual void TearDown() { | 134 void TearDown() override { |
| 135 consumer_.Close(); | 135 consumer_.Close(); |
| 136 EtwTraceConsumerBaseTest::TearDown(); | 136 EtwTraceConsumerBaseTest::TearDown(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 DWORD ConsumerThread() { | 139 DWORD ConsumerThread() { |
| 140 ::SetEvent(consumer_ready_.Get()); | 140 ::SetEvent(consumer_ready_.Get()); |
| 141 return consumer_.Consume(); | 141 return consumer_.Consume(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 static DWORD WINAPI ConsumerThreadMainProc(void* arg) { | 144 static DWORD WINAPI ConsumerThreadMainProc(void* arg) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 namespace { | 255 namespace { |
| 256 | 256 |
| 257 // We run events through a file session to assert that | 257 // We run events through a file session to assert that |
| 258 // the content comes through. | 258 // the content comes through. |
| 259 class EtwTraceConsumerDataTest: public EtwTraceConsumerBaseTest { | 259 class EtwTraceConsumerDataTest: public EtwTraceConsumerBaseTest { |
| 260 public: | 260 public: |
| 261 EtwTraceConsumerDataTest() { | 261 EtwTraceConsumerDataTest() { |
| 262 } | 262 } |
| 263 | 263 |
| 264 virtual void SetUp() { | 264 void SetUp() override { |
| 265 EtwTraceConsumerBaseTest::SetUp(); | 265 EtwTraceConsumerBaseTest::SetUp(); |
| 266 | 266 |
| 267 EtwTraceProperties prop; | 267 EtwTraceProperties prop; |
| 268 EtwTraceController::Stop(session_name_.c_str(), &prop); | 268 EtwTraceController::Stop(session_name_.c_str(), &prop); |
| 269 | 269 |
| 270 // Create a temp dir for this test. | 270 // Create a temp dir for this test. |
| 271 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 271 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 272 // Construct a temp file name in our dir. | 272 // Construct a temp file name in our dir. |
| 273 temp_file_ = temp_dir_.path().Append(L"test.etl"); | 273 temp_file_ = temp_dir_.path().Append(L"test.etl"); |
| 274 } | 274 } |
| 275 | 275 |
| 276 virtual void TearDown() { | 276 void TearDown() override { |
| 277 EXPECT_TRUE(base::DeleteFile(temp_file_, false)); | 277 EXPECT_TRUE(base::DeleteFile(temp_file_, false)); |
| 278 | 278 |
| 279 EtwTraceConsumerBaseTest::TearDown(); | 279 EtwTraceConsumerBaseTest::TearDown(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 HRESULT LogEventToTempSession(PEVENT_TRACE_HEADER header) { | 282 HRESULT LogEventToTempSession(PEVENT_TRACE_HEADER header) { |
| 283 EtwTraceController controller; | 283 EtwTraceController controller; |
| 284 | 284 |
| 285 // Set up a file session. | 285 // Set up a file session. |
| 286 HRESULT hr = controller.StartFileSession(session_name_.c_str(), | 286 HRESULT hr = controller.StartFileSession(session_name_.c_str(), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 return; | 357 return; |
| 358 } | 358 } |
| 359 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; | 359 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; |
| 360 ASSERT_TRUE(trace != NULL); | 360 ASSERT_TRUE(trace != NULL); |
| 361 ASSERT_EQ(sizeof(kData), trace->MofLength); | 361 ASSERT_EQ(sizeof(kData), trace->MofLength); |
| 362 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); | 362 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); |
| 363 } | 363 } |
| 364 | 364 |
| 365 } // namespace win | 365 } // namespace win |
| 366 } // namespace base | 366 } // namespace base |
| OLD | NEW |