Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1902)

Side by Side Diff: base/win/event_trace_consumer_unittest.cc

Issue 593113004: Remove implicit HANDLE conversions from base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return consumer_.Consume(); 142 return consumer_.Consume();
143 } 143 }
144 144
145 static DWORD WINAPI ConsumerThreadMainProc(void* arg) { 145 static DWORD WINAPI ConsumerThreadMainProc(void* arg) {
146 return reinterpret_cast<EtwTraceConsumerRealtimeTest*>(arg)-> 146 return reinterpret_cast<EtwTraceConsumerRealtimeTest*>(arg)->
147 ConsumerThread(); 147 ConsumerThread();
148 } 148 }
149 149
150 HRESULT StartConsumerThread() { 150 HRESULT StartConsumerThread() {
151 consumer_ready_.Set(::CreateEvent(NULL, TRUE, FALSE, NULL)); 151 consumer_ready_.Set(::CreateEvent(NULL, TRUE, FALSE, NULL));
152 EXPECT_TRUE(consumer_ready_ != NULL); 152 EXPECT_TRUE(consumer_ready_.IsValid());
153 consumer_thread_.Set(::CreateThread(NULL, 0, ConsumerThreadMainProc, this, 153 consumer_thread_.Set(::CreateThread(NULL, 0, ConsumerThreadMainProc, this,
154 0, NULL)); 154 0, NULL));
155 if (consumer_thread_.Get() == NULL) 155 if (consumer_thread_.Get() == NULL)
156 return HRESULT_FROM_WIN32(::GetLastError()); 156 return HRESULT_FROM_WIN32(::GetLastError());
157 157
158 HANDLE events[] = { consumer_ready_, consumer_thread_ }; 158 HANDLE events[] = { consumer_ready_.Get(), consumer_thread_.Get() };
159 DWORD result = ::WaitForMultipleObjects(arraysize(events), events, 159 DWORD result = ::WaitForMultipleObjects(arraysize(events), events,
160 FALSE, INFINITE); 160 FALSE, INFINITE);
161 switch (result) { 161 switch (result) {
162 case WAIT_OBJECT_0: 162 case WAIT_OBJECT_0:
163 // The event was set, the consumer_ is ready. 163 // The event was set, the consumer_ is ready.
164 return S_OK; 164 return S_OK;
165 case WAIT_OBJECT_0 + 1: { 165 case WAIT_OBJECT_0 + 1: {
166 // The thread finished. This may race with the event, so check 166 // The thread finished. This may race with the event, so check
167 // explicitly for the event here, before concluding there's trouble. 167 // explicitly for the event here, before concluding there's trouble.
168 if (::WaitForSingleObject(consumer_ready_, 0) == WAIT_OBJECT_0) 168 if (::WaitForSingleObject(consumer_ready_.Get(), 0) == WAIT_OBJECT_0)
169 return S_OK; 169 return S_OK;
170 DWORD exit_code = 0; 170 DWORD exit_code = 0;
171 if (::GetExitCodeThread(consumer_thread_, &exit_code)) 171 if (::GetExitCodeThread(consumer_thread_.Get(), &exit_code))
172 return exit_code; 172 return exit_code;
173 return HRESULT_FROM_WIN32(::GetLastError()); 173 return HRESULT_FROM_WIN32(::GetLastError());
174 } 174 }
175 default: 175 default:
176 return E_UNEXPECTED; 176 return E_UNEXPECTED;
177 } 177 }
178 } 178 }
179 179
180 // Waits for consumer_ thread to exit, and returns its exit code. 180 // Waits for consumer_ thread to exit, and returns its exit code.
181 HRESULT JoinConsumerThread() { 181 HRESULT JoinConsumerThread() {
182 if (::WaitForSingleObject(consumer_thread_, INFINITE) != WAIT_OBJECT_0) 182 if (::WaitForSingleObject(consumer_thread_.Get(), INFINITE) !=
183 WAIT_OBJECT_0) {
183 return HRESULT_FROM_WIN32(::GetLastError()); 184 return HRESULT_FROM_WIN32(::GetLastError());
185 }
184 186
185 DWORD exit_code = 0; 187 DWORD exit_code = 0;
186 if (::GetExitCodeThread(consumer_thread_, &exit_code)) 188 if (::GetExitCodeThread(consumer_thread_.Get(), &exit_code))
187 return exit_code; 189 return exit_code;
188 190
189 return HRESULT_FROM_WIN32(::GetLastError()); 191 return HRESULT_FROM_WIN32(::GetLastError());
190 } 192 }
191 193
192 TestConsumer consumer_; 194 TestConsumer consumer_;
193 ScopedHandle consumer_ready_; 195 ScopedHandle consumer_ready_;
194 ScopedHandle consumer_thread_; 196 ScopedHandle consumer_thread_;
195 }; 197 };
196 198
197 } // namespace 199 } // namespace
198 200
199 TEST_F(EtwTraceConsumerRealtimeTest, ConsumerReturnsWhenSessionClosed) { 201 TEST_F(EtwTraceConsumerRealtimeTest, ConsumerReturnsWhenSessionClosed) {
200 EtwTraceController controller; 202 EtwTraceController controller;
201 if (controller.StartRealtimeSession(session_name_.c_str(), 100 * 1024) == 203 if (controller.StartRealtimeSession(session_name_.c_str(), 100 * 1024) ==
202 E_ACCESSDENIED) { 204 E_ACCESSDENIED) {
203 VLOG(1) << "You must be an administrator to run this test on Vista"; 205 VLOG(1) << "You must be an administrator to run this test on Vista";
204 return; 206 return;
205 } 207 }
206 208
207 // Start the consumer_. 209 // Start the consumer_.
208 ASSERT_HRESULT_SUCCEEDED(StartConsumerThread()); 210 ASSERT_HRESULT_SUCCEEDED(StartConsumerThread());
209 211
210 // Wait around for the consumer_ thread a bit. 212 // Wait around for the consumer_ thread a bit.
211 ASSERT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(consumer_thread_, 50)); 213 ASSERT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(consumer_thread_.Get(), 50));
212 ASSERT_HRESULT_SUCCEEDED(controller.Stop(NULL)); 214 ASSERT_HRESULT_SUCCEEDED(controller.Stop(NULL));
213 215
214 // The consumer_ returns success on session stop. 216 // The consumer_ returns success on session stop.
215 ASSERT_HRESULT_SUCCEEDED(JoinConsumerThread()); 217 ASSERT_HRESULT_SUCCEEDED(JoinConsumerThread());
216 } 218 }
217 219
218 namespace { 220 namespace {
219 221
220 // {57E47923-A549-476f-86CA-503D57F59E62} 222 // {57E47923-A549-476f-86CA-503D57F59E62}
221 DEFINE_GUID( 223 DEFINE_GUID(
(...skipping 15 matching lines...) Expand all
237 239
238 EtwTraceProvider provider(test_provider_); 240 EtwTraceProvider provider(test_provider_);
239 ASSERT_EQ(ERROR_SUCCESS, provider.Register()); 241 ASSERT_EQ(ERROR_SUCCESS, provider.Register());
240 242
241 // Start the consumer_. 243 // Start the consumer_.
242 ASSERT_HRESULT_SUCCEEDED(StartConsumerThread()); 244 ASSERT_HRESULT_SUCCEEDED(StartConsumerThread());
243 ASSERT_EQ(0, TestConsumer::events_.size()); 245 ASSERT_EQ(0, TestConsumer::events_.size());
244 246
245 EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR); 247 EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR);
246 EXPECT_EQ(ERROR_SUCCESS, provider.Log(&event.header)); 248 EXPECT_EQ(ERROR_SUCCESS, provider.Log(&event.header));
247 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(TestConsumer::sank_event_, 249 EXPECT_EQ(WAIT_OBJECT_0,
248 INFINITE)); 250 ::WaitForSingleObject(TestConsumer::sank_event_.Get(), INFINITE));
249 ASSERT_HRESULT_SUCCEEDED(controller.Stop(NULL)); 251 ASSERT_HRESULT_SUCCEEDED(controller.Stop(NULL));
250 ASSERT_HRESULT_SUCCEEDED(JoinConsumerThread()); 252 ASSERT_HRESULT_SUCCEEDED(JoinConsumerThread());
251 ASSERT_NE(0u, TestConsumer::events_.size()); 253 ASSERT_NE(0u, TestConsumer::events_.size());
252 } 254 }
253 255
254 namespace { 256 namespace {
255 257
256 // We run events through a file session to assert that 258 // We run events through a file session to assert that
257 // the content comes through. 259 // the content comes through.
258 class EtwTraceConsumerDataTest: public EtwTraceConsumerBaseTest { 260 class EtwTraceConsumerDataTest: public EtwTraceConsumerBaseTest {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return; 358 return;
357 } 359 }
358 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; 360 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed";
359 ASSERT_TRUE(trace != NULL); 361 ASSERT_TRUE(trace != NULL);
360 ASSERT_EQ(sizeof(kData), trace->MofLength); 362 ASSERT_EQ(sizeof(kData), trace->MofLength);
361 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); 363 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData));
362 } 364 }
363 365
364 } // namespace win 366 } // namespace win
365 } // namespace base 367 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698