| 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 #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 Loading... |
| 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 printer_ = new XmlUnitTestResultPrinter; | 241 XmlUnitTestResultPrinter* 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 Loading... |
| 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 void TestSuite::UnitTestAssertHandler(const char* file, | 285 // static |
| 286 int line, | 286 void TestSuite::UnitTestAssertHandler(const std::string& str) { |
| 287 const base::StringPiece summary, | |
| 288 const base::StringPiece stack_trace) { | |
| 289 #if defined(OS_ANDROID) | 287 #if defined(OS_ANDROID) |
| 290 // Correlating test stdio with logcat can be difficult, so we emit this | 288 // Correlating test stdio with logcat can be difficult, so we emit this |
| 291 // helpful little hint about what was running. Only do this for Android | 289 // helpful little hint about what was running. Only do this for Android |
| 292 // because other platforms don't separate out the relevant logs in the same | 290 // because other platforms don't separate out the relevant logs in the same |
| 293 // way. | 291 // way. |
| 294 const ::testing::TestInfo* const test_info = | 292 const ::testing::TestInfo* const test_info = |
| 295 ::testing::UnitTest::GetInstance()->current_test_info(); | 293 ::testing::UnitTest::GetInstance()->current_test_info(); |
| 296 if (test_info) { | 294 if (test_info) { |
| 297 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." | 295 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." |
| 298 << test_info->name(); | 296 << test_info->name(); |
| 299 fflush(stderr); | 297 fflush(stderr); |
| 300 } | 298 } |
| 301 #endif // defined(OS_ANDROID) | 299 #endif // defined(OS_ANDROID) |
| 302 | 300 |
| 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 | |
| 313 // The logging system actually prints the message before calling the assert | 301 // The logging system actually prints the message before calling the assert |
| 314 // handler. Just exit now to avoid printing too many stack traces. | 302 // handler. Just exit now to avoid printing too many stack traces. |
| 315 _exit(1); | 303 _exit(1); |
| 316 } | 304 } |
| 317 | 305 |
| 318 void TestSuite::SuppressErrorDialogs() { | 306 void TestSuite::SuppressErrorDialogs() { |
| 319 #if defined(OS_WIN) | 307 #if defined(OS_WIN) |
| 320 UINT new_flags = SEM_FAILCRITICALERRORS | | 308 UINT new_flags = SEM_FAILCRITICALERRORS | |
| 321 SEM_NOGPFAULTERRORBOX | | 309 SEM_NOGPFAULTERRORBOX | |
| 322 SEM_NOOPENFILEERRORBOX; | 310 SEM_NOOPENFILEERRORBOX; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 // Make sure we run with high resolution timer to minimize differences | 352 // Make sure we run with high resolution timer to minimize differences |
| 365 // between production code and test code. | 353 // between production code and test code. |
| 366 Time::EnableHighResolutionTimer(true); | 354 Time::EnableHighResolutionTimer(true); |
| 367 #endif // defined(OS_WIN) | 355 #endif // defined(OS_WIN) |
| 368 | 356 |
| 369 // In some cases, we do not want to see standard error dialogs. | 357 // In some cases, we do not want to see standard error dialogs. |
| 370 if (!debug::BeingDebugged() && | 358 if (!debug::BeingDebugged() && |
| 371 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { | 359 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
| 372 SuppressErrorDialogs(); | 360 SuppressErrorDialogs(); |
| 373 debug::SetSuppressDebugUI(true); | 361 debug::SetSuppressDebugUI(true); |
| 374 assert_handler_ = base::MakeUnique<logging::ScopedLogAssertHandler>( | 362 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 375 base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this))); | |
| 376 } | 363 } |
| 377 | 364 |
| 378 base::test::InitializeICUForTesting(); | 365 base::test::InitializeICUForTesting(); |
| 379 | 366 |
| 380 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, | 367 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, |
| 381 // the locale is set via an OS X locale API and is never *_POSIX. | 368 // the locale is set via an OS X locale API and is never *_POSIX. |
| 382 // Some tests (such as those involving word break iterator) will behave | 369 // Some tests (such as those involving word break iterator) will behave |
| 383 // differently and fail if we use *POSIX locale. Setting it to en_US here | 370 // differently and fail if we use *POSIX locale. Setting it to en_US here |
| 384 // does not affect tests that explicitly overrides the locale for testing. | 371 // does not affect tests that explicitly overrides the locale for testing. |
| 385 // This can be an issue on all platforms other than Windows. | 372 // This can be an issue on all platforms other than Windows. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 412 | 399 |
| 413 void TestSuite::Shutdown() { | 400 void TestSuite::Shutdown() { |
| 414 base::debug::StopProfiling(); | 401 base::debug::StopProfiling(); |
| 415 | 402 |
| 416 // Clear the FeatureList that was created by Initialize(). | 403 // Clear the FeatureList that was created by Initialize(). |
| 417 if (created_feature_list_) | 404 if (created_feature_list_) |
| 418 FeatureList::ClearInstanceForTesting(); | 405 FeatureList::ClearInstanceForTesting(); |
| 419 } | 406 } |
| 420 | 407 |
| 421 } // namespace base | 408 } // namespace base |
| OLD | NEW |