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

Side by Side Diff: base/test/test_suite.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Add test for assert handlers nesting. Created 3 years, 8 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_suite.h ('k') | chrome/common/logging_chrome.cc » ('j') | 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 #include "base/test/test_suite.h" 5 #include "base/test/test_suite.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 // Do not add the result printer if output path already exists. It's an 232 // Do not add the result printer if output path already exists. It's an
233 // indicator there is a process printing to that file, and we're likely 233 // indicator there is a process printing to that file, and we're likely
234 // its child. Do not clobber the results in that case. 234 // its child. Do not clobber the results in that case.
235 if (PathExists(output_path)) { 235 if (PathExists(output_path)) {
236 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() 236 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe()
237 << " exists. Not adding test launcher result printer."; 237 << " exists. Not adding test launcher result printer.";
238 return; 238 return;
239 } 239 }
240 240
241 XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter; 241 printer_ = new XmlUnitTestResultPrinter;
242 CHECK(printer->Initialize(output_path)); 242 CHECK(printer_->Initialize(output_path));
243 testing::TestEventListeners& listeners = 243 testing::TestEventListeners& listeners =
244 testing::UnitTest::GetInstance()->listeners(); 244 testing::UnitTest::GetInstance()->listeners();
245 listeners.Append(printer); 245 listeners.Append(printer_);
246 } 246 }
247 247
248 // Don't add additional code to this method. Instead add it to 248 // Don't add additional code to this method. Instead add it to
249 // Initialize(). See bug 6436. 249 // Initialize(). See bug 6436.
250 int TestSuite::Run() { 250 int TestSuite::Run() {
251 #if defined(OS_IOS) 251 #if defined(OS_IOS)
252 RunTestsFromIOSApp(); 252 RunTestsFromIOSApp();
253 #endif 253 #endif
254 254
255 #if defined(OS_MACOSX) 255 #if defined(OS_MACOSX)
(...skipping 19 matching lines...) Expand all
275 // objects (such as NotificationService::current()) that Cocoa 275 // objects (such as NotificationService::current()) that Cocoa
276 // objects use to remove themselves as observers. 276 // objects use to remove themselves as observers.
277 scoped_pool.Recycle(); 277 scoped_pool.Recycle();
278 #endif 278 #endif
279 279
280 Shutdown(); 280 Shutdown();
281 281
282 return result; 282 return result;
283 } 283 }
284 284
285 // static 285 void TestSuite::UnitTestAssertHandler(const char* file,
286 void TestSuite::UnitTestAssertHandler(const std::string& str) { 286 int line,
287 const base::StringPiece summary,
288 const base::StringPiece stack_trace) {
287 #if defined(OS_ANDROID) 289 #if defined(OS_ANDROID)
288 // Correlating test stdio with logcat can be difficult, so we emit this 290 // Correlating test stdio with logcat can be difficult, so we emit this
289 // helpful little hint about what was running. Only do this for Android 291 // helpful little hint about what was running. Only do this for Android
290 // because other platforms don't separate out the relevant logs in the same 292 // because other platforms don't separate out the relevant logs in the same
291 // way. 293 // way.
292 const ::testing::TestInfo* const test_info = 294 const ::testing::TestInfo* const test_info =
293 ::testing::UnitTest::GetInstance()->current_test_info(); 295 ::testing::UnitTest::GetInstance()->current_test_info();
294 if (test_info) { 296 if (test_info) {
295 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." 297 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "."
296 << test_info->name(); 298 << test_info->name();
297 fflush(stderr); 299 fflush(stderr);
298 } 300 }
299 #endif // defined(OS_ANDROID) 301 #endif // defined(OS_ANDROID)
300 302
303 // XmlUnitTestResultPrinter inherits gtest format, where assert has summary
304 // and message. In GTest, summary is just a logged text, and message is a
305 // logged text, concatenated with stack trace of assert.
306 // Concatenate summary and stack_trace here, to pass it as a message.
307 if (printer_) {
308 const std::string summary_str = summary.as_string();
309 const std::string stack_trace_str = summary_str + stack_trace.as_string();
310 printer_->OnAssert(file, line, summary_str, stack_trace_str);
311 }
312
301 // The logging system actually prints the message before calling the assert 313 // The logging system actually prints the message before calling the assert
302 // handler. Just exit now to avoid printing too many stack traces. 314 // handler. Just exit now to avoid printing too many stack traces.
303 _exit(1); 315 _exit(1);
304 } 316 }
305 317
306 void TestSuite::SuppressErrorDialogs() { 318 void TestSuite::SuppressErrorDialogs() {
307 #if defined(OS_WIN) 319 #if defined(OS_WIN)
308 UINT new_flags = SEM_FAILCRITICALERRORS | 320 UINT new_flags = SEM_FAILCRITICALERRORS |
309 SEM_NOGPFAULTERRORBOX | 321 SEM_NOGPFAULTERRORBOX |
310 SEM_NOOPENFILEERRORBOX; 322 SEM_NOOPENFILEERRORBOX;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // Make sure we run with high resolution timer to minimize differences 364 // Make sure we run with high resolution timer to minimize differences
353 // between production code and test code. 365 // between production code and test code.
354 Time::EnableHighResolutionTimer(true); 366 Time::EnableHighResolutionTimer(true);
355 #endif // defined(OS_WIN) 367 #endif // defined(OS_WIN)
356 368
357 // In some cases, we do not want to see standard error dialogs. 369 // In some cases, we do not want to see standard error dialogs.
358 if (!debug::BeingDebugged() && 370 if (!debug::BeingDebugged() &&
359 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { 371 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) {
360 SuppressErrorDialogs(); 372 SuppressErrorDialogs();
361 debug::SetSuppressDebugUI(true); 373 debug::SetSuppressDebugUI(true);
362 logging::SetLogAssertHandler(UnitTestAssertHandler); 374 assert_handler_ = base::MakeUnique<logging::ScopedLogAssertHandler>(
375 base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this)));
363 } 376 }
364 377
365 base::test::InitializeICUForTesting(); 378 base::test::InitializeICUForTesting();
366 379
367 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, 380 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium,
368 // the locale is set via an OS X locale API and is never *_POSIX. 381 // the locale is set via an OS X locale API and is never *_POSIX.
369 // Some tests (such as those involving word break iterator) will behave 382 // Some tests (such as those involving word break iterator) will behave
370 // differently and fail if we use *POSIX locale. Setting it to en_US here 383 // differently and fail if we use *POSIX locale. Setting it to en_US here
371 // does not affect tests that explicitly overrides the locale for testing. 384 // does not affect tests that explicitly overrides the locale for testing.
372 // This can be an issue on all platforms other than Windows. 385 // This can be an issue on all platforms other than Windows.
(...skipping 26 matching lines...) Expand all
399 412
400 void TestSuite::Shutdown() { 413 void TestSuite::Shutdown() {
401 base::debug::StopProfiling(); 414 base::debug::StopProfiling();
402 415
403 // Clear the FeatureList that was created by Initialize(). 416 // Clear the FeatureList that was created by Initialize().
404 if (created_feature_list_) 417 if (created_feature_list_)
405 FeatureList::ClearInstanceForTesting(); 418 FeatureList::ClearInstanceForTesting();
406 } 419 }
407 420
408 } // namespace base 421 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_suite.h ('k') | chrome/common/logging_chrome.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698