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

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

Issue 202993003: Fix "unreachable code" warnings (MSVC warning 4702) in base/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/test/trace_event_analyzer.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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_ != NULL);
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 HRESULT hr = S_OK;
159 HANDLE events[] = { consumer_ready_, consumer_thread_ }; 158 HANDLE events[] = { consumer_ready_, consumer_thread_ };
160 DWORD result = ::WaitForMultipleObjects(arraysize(events), events, 159 DWORD result = ::WaitForMultipleObjects(arraysize(events), events,
161 FALSE, INFINITE); 160 FALSE, INFINITE);
162 switch (result) { 161 switch (result) {
163 case WAIT_OBJECT_0: 162 case WAIT_OBJECT_0:
164 // The event was set, the consumer_ is ready. 163 // The event was set, the consumer_ is ready.
165 return S_OK; 164 return S_OK;
166 case WAIT_OBJECT_0 + 1: { 165 case WAIT_OBJECT_0 + 1: {
167 // The thread finished. This may race with the event, so check 166 // The thread finished. This may race with the event, so check
168 // explicitly for the event here, before concluding there's trouble. 167 // explicitly for the event here, before concluding there's trouble.
169 if (::WaitForSingleObject(consumer_ready_, 0) == WAIT_OBJECT_0) 168 if (::WaitForSingleObject(consumer_ready_, 0) == WAIT_OBJECT_0)
170 return S_OK; 169 return S_OK;
171 DWORD exit_code = 0; 170 DWORD exit_code = 0;
172 if (::GetExitCodeThread(consumer_thread_, &exit_code)) 171 if (::GetExitCodeThread(consumer_thread_, &exit_code))
173 return exit_code; 172 return exit_code;
174 return HRESULT_FROM_WIN32(::GetLastError()); 173 return HRESULT_FROM_WIN32(::GetLastError());
175 break;
176 } 174 }
177 default: 175 default:
178 return E_UNEXPECTED; 176 return E_UNEXPECTED;
179 break;
180 } 177 }
181
182 return hr;
183 } 178 }
184 179
185 // Waits for consumer_ thread to exit, and returns its exit code. 180 // Waits for consumer_ thread to exit, and returns its exit code.
186 HRESULT JoinConsumerThread() { 181 HRESULT JoinConsumerThread() {
187 if (::WaitForSingleObject(consumer_thread_, INFINITE) != WAIT_OBJECT_0) 182 if (::WaitForSingleObject(consumer_thread_, INFINITE) != WAIT_OBJECT_0)
188 return HRESULT_FROM_WIN32(::GetLastError()); 183 return HRESULT_FROM_WIN32(::GetLastError());
189 184
190 DWORD exit_code = 0; 185 DWORD exit_code = 0;
191 if (::GetExitCodeThread(consumer_thread_, &exit_code)) 186 if (::GetExitCodeThread(consumer_thread_, &exit_code))
192 return exit_code; 187 return exit_code;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } // namespace 225 } // namespace
231 226
232 TEST_F(EtwTraceConsumerRealtimeTest, ConsumeEvent) { 227 TEST_F(EtwTraceConsumerRealtimeTest, ConsumeEvent) {
233 EtwTraceController controller; 228 EtwTraceController controller;
234 if (controller.StartRealtimeSession(session_name_.c_str(), 100 * 1024) == 229 if (controller.StartRealtimeSession(session_name_.c_str(), 100 * 1024) ==
235 E_ACCESSDENIED) { 230 E_ACCESSDENIED) {
236 VLOG(1) << "You must be an administrator to run this test on Vista"; 231 VLOG(1) << "You must be an administrator to run this test on Vista";
237 return; 232 return;
238 } 233 }
239 234
240 ASSERT_HRESULT_SUCCEEDED(controller.EnableProvider(test_provider_, 235 ASSERT_HRESULT_SUCCEEDED(controller.EnableProvider(
241 TRACE_LEVEL_VERBOSE, 0xFFFFFFFF)); 236 test_provider_, TRACE_LEVEL_VERBOSE, 0xFFFFFFFF));
Peter Kasting 2014/03/19 21:34:51 I forgot to fix this in my style change when I fix
242 237
243 EtwTraceProvider provider(test_provider_); 238 EtwTraceProvider provider(test_provider_);
244 ASSERT_EQ(ERROR_SUCCESS, provider.Register()); 239 ASSERT_EQ(ERROR_SUCCESS, provider.Register());
245 240
246 // Start the consumer_. 241 // Start the consumer_.
247 ASSERT_HRESULT_SUCCEEDED(StartConsumerThread()); 242 ASSERT_HRESULT_SUCCEEDED(StartConsumerThread());
248 ASSERT_EQ(0, TestConsumer::events_.size()); 243 ASSERT_EQ(0, TestConsumer::events_.size());
249 244
250 EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR); 245 EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR);
251 EXPECT_EQ(ERROR_SUCCESS, provider.Log(&event.header)); 246 EXPECT_EQ(ERROR_SUCCESS, provider.Log(&event.header));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return; 356 return;
362 } 357 }
363 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; 358 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed";
364 ASSERT_TRUE(trace != NULL); 359 ASSERT_TRUE(trace != NULL);
365 ASSERT_EQ(sizeof(kData), trace->MofLength); 360 ASSERT_EQ(sizeof(kData), trace->MofLength);
366 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); 361 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData));
367 } 362 }
368 363
369 } // namespace win 364 } // namespace win
370 } // namespace base 365 } // namespace base
OLDNEW
« no previous file with comments | « base/test/trace_event_analyzer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698