| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/process.h" | 16 #include "base/process.h" |
| 17 #include "base/scoped_temp_dir.h" | 17 #include "base/scoped_temp_dir.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/win/event_trace_controller.h" | 19 #include "base/win/event_trace_controller.h" |
| 20 #include "base/win/event_trace_provider.h" | 20 #include "base/win/event_trace_provider.h" |
| 21 #include "base/win/scoped_com_initializer.h" |
| 21 #include "base/win/scoped_handle.h" | 22 #include "base/win/scoped_handle.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 #include <initguid.h> // NOLINT - has to be last | 25 #include <initguid.h> // NOLINT - has to be last |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 using base::win::EtwMofEvent; | 29 using base::win::EtwMofEvent; |
| 29 using base::win::EtwTraceController; | 30 using base::win::EtwTraceController; |
| 30 using base::win::EtwTraceConsumerBase; | 31 using base::win::EtwTraceConsumerBase; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ASSERT_HRESULT_SUCCEEDED(::CoCreateGuid(&test_provider_)); | 97 ASSERT_HRESULT_SUCCEEDED(::CoCreateGuid(&test_provider_)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 virtual void TearDown() { | 100 virtual void TearDown() { |
| 100 // Cleanup any potentially danging sessions. | 101 // Cleanup any potentially danging sessions. |
| 101 EtwTraceProperties ignore; | 102 EtwTraceProperties ignore; |
| 102 EtwTraceController::Stop(session_name_.c_str(), &ignore); | 103 EtwTraceController::Stop(session_name_.c_str(), &ignore); |
| 103 } | 104 } |
| 104 | 105 |
| 105 protected: | 106 protected: |
| 107 base::win::ScopedCOMInitializer com_initializer_; |
| 106 GUID test_provider_; | 108 GUID test_provider_; |
| 107 std::wstring session_name_; | 109 std::wstring session_name_; |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 } // namespace | 112 } // namespace |
| 111 | 113 |
| 112 TEST_F(EtwTraceConsumerBaseTest, Initialize) { | 114 TEST_F(EtwTraceConsumerBaseTest, Initialize) { |
| 113 TestConsumer consumer_; | 115 TestConsumer consumer_; |
| 114 } | 116 } |
| 115 | 117 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 238 } |
| 237 | 239 |
| 238 namespace { | 240 namespace { |
| 239 | 241 |
| 240 // {57E47923-A549-476f-86CA-503D57F59E62} | 242 // {57E47923-A549-476f-86CA-503D57F59E62} |
| 241 DEFINE_GUID(kTestEventType, | 243 DEFINE_GUID(kTestEventType, |
| 242 0x57e47923, 0xa549, 0x476f, 0x86, 0xca, 0x50, 0x3d, 0x57, 0xf5, 0x9e, 0x62); | 244 0x57e47923, 0xa549, 0x476f, 0x86, 0xca, 0x50, 0x3d, 0x57, 0xf5, 0x9e, 0x62); |
| 243 | 245 |
| 244 } // namespace | 246 } // namespace |
| 245 | 247 |
| 246 // Fails consistently on Vista. http://crbug.com/127671 | 248 TEST_F(EtwTraceConsumerRealtimeTest, ConsumeEvent) { |
| 247 TEST_F(EtwTraceConsumerRealtimeTest, DISABLED_ConsumeEvent) { | |
| 248 EtwTraceController controller; | 249 EtwTraceController controller; |
| 249 HRESULT hr = controller.StartRealtimeSession(session_name_.c_str(), | 250 HRESULT hr = controller.StartRealtimeSession(session_name_.c_str(), |
| 250 100 * 1024); | 251 100 * 1024); |
| 251 if (hr == E_ACCESSDENIED) { | 252 if (hr == E_ACCESSDENIED) { |
| 252 VLOG(1) << "You must be an administrator to run this test on Vista"; | 253 VLOG(1) << "You must be an administrator to run this test on Vista"; |
| 253 return; | 254 return; |
| 254 } | 255 } |
| 255 | 256 |
| 256 ASSERT_HRESULT_SUCCEEDED(controller.EnableProvider(test_provider_, | 257 ASSERT_HRESULT_SUCCEEDED(controller.EnableProvider(test_provider_, |
| 257 TRACE_LEVEL_VERBOSE, 0xFFFFFFFF)); | 258 TRACE_LEVEL_VERBOSE, 0xFFFFFFFF)); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 HRESULT hr = RoundTripEvent(&event.header, &trace); | 375 HRESULT hr = RoundTripEvent(&event.header, &trace); |
| 375 if (hr == E_ACCESSDENIED) { | 376 if (hr == E_ACCESSDENIED) { |
| 376 VLOG(1) << "You must be an administrator to run this test on Vista"; | 377 VLOG(1) << "You must be an administrator to run this test on Vista"; |
| 377 return; | 378 return; |
| 378 } | 379 } |
| 379 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; | 380 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; |
| 380 ASSERT_TRUE(NULL != trace); | 381 ASSERT_TRUE(NULL != trace); |
| 381 ASSERT_EQ(sizeof(kData), trace->MofLength); | 382 ASSERT_EQ(sizeof(kData), trace->MofLength); |
| 382 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); | 383 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); |
| 383 } | 384 } |
| OLD | NEW |