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 controller. | 5 // Unit tests for event trace controller. |
6 | 6 |
7 #include <objbase.h> | 7 #include <objbase.h> |
8 #include <initguid.h> | 8 #include <initguid.h> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/process.h" | 14 #include "base/process.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "base/win/event_trace_controller.h" | 17 #include "base/win/event_trace_controller.h" |
18 #include "base/win/event_trace_provider.h" | 18 #include "base/win/event_trace_provider.h" |
19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
| 22 namespace base { |
| 23 namespace win { |
| 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 using base::win::EtwTraceController; | |
25 using base::win::EtwTraceProvider; | |
26 using base::win::EtwTraceProperties; | |
27 | |
28 DEFINE_GUID(kGuidNull, | 27 DEFINE_GUID(kGuidNull, |
29 0x0000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0); | 28 0x0000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0); |
30 | 29 |
31 const ULONG kTestProviderFlags = 0xCAFEBABE; | 30 const ULONG kTestProviderFlags = 0xCAFEBABE; |
32 | 31 |
33 class TestingProvider: public EtwTraceProvider { | 32 class TestingProvider: public EtwTraceProvider { |
34 public: | 33 public: |
35 explicit TestingProvider(const GUID& provider_name) | 34 explicit TestingProvider(const GUID& provider_name) |
36 : EtwTraceProvider(provider_name) { | 35 : EtwTraceProvider(provider_name) { |
37 callback_event_.Set(::CreateEvent(NULL, TRUE, FALSE, NULL)); | 36 callback_event_.Set(::CreateEvent(NULL, TRUE, FALSE, NULL)); |
38 } | 37 } |
39 | 38 |
40 void WaitForCallback() { | 39 void WaitForCallback() { |
41 ::WaitForSingleObject(callback_event_.Get(), INFINITE); | 40 ::WaitForSingleObject(callback_event_.Get(), INFINITE); |
42 ::ResetEvent(callback_event_.Get()); | 41 ::ResetEvent(callback_event_.Get()); |
43 } | 42 } |
44 | 43 |
45 private: | 44 private: |
46 virtual void OnEventsEnabled() { | 45 virtual void OnEventsEnabled() { |
47 ::SetEvent(callback_event_.Get()); | 46 ::SetEvent(callback_event_.Get()); |
48 } | 47 } |
49 virtual void PostEventsDisabled() { | 48 virtual void PostEventsDisabled() { |
50 ::SetEvent(callback_event_.Get()); | 49 ::SetEvent(callback_event_.Get()); |
51 } | 50 } |
52 | 51 |
53 base::win::ScopedHandle callback_event_; | 52 ScopedHandle callback_event_; |
54 | 53 |
55 DISALLOW_COPY_AND_ASSIGN(TestingProvider); | 54 DISALLOW_COPY_AND_ASSIGN(TestingProvider); |
56 }; | 55 }; |
57 | 56 |
58 } // namespace | 57 } // namespace |
59 | 58 |
60 TEST(EtwTracePropertiesTest, Initialization) { | 59 TEST(EtwTracePropertiesTest, Initialization) { |
61 EtwTraceProperties prop; | 60 EtwTraceProperties prop; |
62 | 61 |
63 EVENT_TRACE_PROPERTIES* p = prop.get(); | 62 EVENT_TRACE_PROPERTIES* p = prop.get(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 102 |
104 std::wstring name2(1024, L'A'); | 103 std::wstring name2(1024, L'A'); |
105 ASSERT_HRESULT_FAILED(prop.SetLoggerFileName(name2.c_str())); | 104 ASSERT_HRESULT_FAILED(prop.SetLoggerFileName(name2.c_str())); |
106 ASSERT_HRESULT_FAILED(prop.SetLoggerName(name2.c_str())); | 105 ASSERT_HRESULT_FAILED(prop.SetLoggerName(name2.c_str())); |
107 } | 106 } |
108 | 107 |
109 namespace { | 108 namespace { |
110 | 109 |
111 class EtwTraceControllerTest : public testing::Test { | 110 class EtwTraceControllerTest : public testing::Test { |
112 public: | 111 public: |
113 EtwTraceControllerTest() : session_name_( | 112 EtwTraceControllerTest() |
114 base::StringPrintf(L"TestSession-%d", base::Process::Current().pid())) { | 113 : session_name_( |
| 114 StringPrintf(L"TestSession-%d", Process::Current().pid())) { |
115 } | 115 } |
116 | 116 |
117 virtual void SetUp() { | 117 virtual void SetUp() { |
118 EtwTraceProperties ignore; | 118 EtwTraceProperties ignore; |
119 EtwTraceController::Stop(session_name_.c_str(), &ignore); | 119 EtwTraceController::Stop(session_name_.c_str(), &ignore); |
120 | 120 |
121 // Allocate a new provider name GUID for each test. | 121 // Allocate a new provider name GUID for each test. |
122 ASSERT_HRESULT_SUCCEEDED(::CoCreateGuid(&test_provider_)); | 122 ASSERT_HRESULT_SUCCEEDED(::CoCreateGuid(&test_provider_)); |
123 } | 123 } |
124 | 124 |
(...skipping 29 matching lines...) Expand all Loading... |
154 | 154 |
155 EXPECT_TRUE(NULL != controller.session()); | 155 EXPECT_TRUE(NULL != controller.session()); |
156 EXPECT_STREQ(session_name_.c_str(), controller.session_name()); | 156 EXPECT_STREQ(session_name_.c_str(), controller.session_name()); |
157 | 157 |
158 EXPECT_HRESULT_SUCCEEDED(controller.Stop(NULL)); | 158 EXPECT_HRESULT_SUCCEEDED(controller.Stop(NULL)); |
159 EXPECT_EQ(NULL, controller.session()); | 159 EXPECT_EQ(NULL, controller.session()); |
160 EXPECT_STREQ(L"", controller.session_name()); | 160 EXPECT_STREQ(L"", controller.session_name()); |
161 } | 161 } |
162 | 162 |
163 TEST_F(EtwTraceControllerTest, StartFileSession) { | 163 TEST_F(EtwTraceControllerTest, StartFileSession) { |
164 base::ScopedTempDir temp_dir; | 164 ScopedTempDir temp_dir; |
165 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 165 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
166 FilePath temp; | 166 FilePath temp; |
167 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), &temp)); | 167 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), &temp)); |
168 | 168 |
169 EtwTraceController controller; | 169 EtwTraceController controller; |
170 HRESULT hr = controller.StartFileSession(session_name_.c_str(), | 170 HRESULT hr = controller.StartFileSession(session_name_.c_str(), |
171 temp.value().c_str()); | 171 temp.value().c_str()); |
172 if (hr == E_ACCESSDENIED) { | 172 if (hr == E_ACCESSDENIED) { |
173 VLOG(1) << "You must be an administrator to run this test on Vista"; | 173 VLOG(1) << "You must be an administrator to run this test on Vista"; |
174 file_util::Delete(temp, false); | 174 file_util::Delete(temp, false); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 EXPECT_EQ(kTestProviderFlags, provider.enable_flags()); | 227 EXPECT_EQ(kTestProviderFlags, provider.enable_flags()); |
228 | 228 |
229 EXPECT_HRESULT_SUCCEEDED(controller.Stop(NULL)); | 229 EXPECT_HRESULT_SUCCEEDED(controller.Stop(NULL)); |
230 | 230 |
231 provider.WaitForCallback(); | 231 provider.WaitForCallback(); |
232 | 232 |
233 // Session should have wound down. | 233 // Session should have wound down. |
234 EXPECT_EQ(0, provider.enable_level()); | 234 EXPECT_EQ(0, provider.enable_level()); |
235 EXPECT_EQ(0, provider.enable_flags()); | 235 EXPECT_EQ(0, provider.enable_flags()); |
236 } | 236 } |
| 237 |
| 238 } // namespace win |
| 239 } // namespace base |
OLD | NEW |