| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/launcher/unit_test_launcher.h" | 5 #include "base/test/launcher/unit_test_launcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 JoinString(test_names, ":")); | 114 JoinString(test_names, ":")); |
| 115 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); | 115 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); |
| 116 | 116 |
| 117 return new_cmd_line; | 117 return new_cmd_line; |
| 118 } | 118 } |
| 119 | 119 |
| 120 std::string GetWrapperForChildGTestProcess() override { | 120 std::string GetWrapperForChildGTestProcess() override { |
| 121 return std::string(); | 121 return std::string(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void RelaunchTests(TestLauncher* test_launcher, |
| 125 const std::vector<std::string>& test_names, |
| 126 int launch_flags) override { |
| 127 // Relaunch requested tests in parallel, but only use single |
| 128 // test per batch for more precise results (crashes, etc). |
| 129 for (const std::string& test_name : test_names) { |
| 130 std::vector<std::string> batch; |
| 131 batch.push_back(test_name); |
| 132 RunUnitTestsBatch(test_launcher, this, batch, launch_flags); |
| 133 } |
| 134 } |
| 135 |
| 124 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); | 136 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); |
| 125 }; | 137 }; |
| 126 | 138 |
| 127 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { | 139 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { |
| 128 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) | 140 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) |
| 129 return true; | 141 return true; |
| 130 | 142 |
| 131 std::string switch_value = | 143 std::string switch_value = |
| 132 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 144 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
| 133 if (!StringToInt(switch_value, result) || *result < 1) { | 145 if (!StringToInt(switch_value, result) || *result < 1) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 for (size_t i = 0; i < final_results.size(); i++) { | 307 for (size_t i = 0; i < final_results.size(); i++) { |
| 296 if (final_results[i].status != TestResult::TEST_SUCCESS) { | 308 if (final_results[i].status != TestResult::TEST_SUCCESS) { |
| 297 has_non_success_test = true; | 309 has_non_success_test = true; |
| 298 break; | 310 break; |
| 299 } | 311 } |
| 300 } | 312 } |
| 301 | 313 |
| 302 if (!has_non_success_test && exit_code != 0) { | 314 if (!has_non_success_test && exit_code != 0) { |
| 303 // This is a bit surprising case: all tests are marked as successful, | 315 // This is a bit surprising case: all tests are marked as successful, |
| 304 // but the exit code was not zero. This can happen e.g. under memory | 316 // but the exit code was not zero. This can happen e.g. under memory |
| 305 // tools that report leaks this way. | 317 // tools that report leaks this way. Mark all tests as a failure on exit, |
| 306 | 318 // and for more precise info they'd need to be retried serially. |
| 307 if (final_results.size() == 1) { | 319 for (size_t i = 0; i < final_results.size(); i++) |
| 308 // Easy case. One test only so we know the non-zero exit code | 320 final_results[i].status = TestResult::TEST_FAILURE_ON_EXIT; |
| 309 // was caused by that one test. | |
| 310 final_results[0].status = TestResult::TEST_FAILURE_ON_EXIT; | |
| 311 } else { | |
| 312 // Harder case. Discard the results and request relaunching all | |
| 313 // tests without batching. This will trigger above branch on | |
| 314 // relaunch leading to more precise results. | |
| 315 LOG(WARNING) << "Not sure which test caused non-zero exit code, " | |
| 316 << "relaunching all of them without batching."; | |
| 317 | |
| 318 for (size_t i = 0; i < final_results.size(); i++) | |
| 319 tests_to_relaunch->push_back(final_results[i].full_name); | |
| 320 | |
| 321 return false; | |
| 322 } | |
| 323 } | 321 } |
| 324 | 322 |
| 325 for (size_t i = 0; i < final_results.size(); i++) { | 323 for (size_t i = 0; i < final_results.size(); i++) { |
| 326 // Fix the output snippet after possible changes to the test result. | 324 // Fix the output snippet after possible changes to the test result. |
| 327 final_results[i].output_snippet = | 325 final_results[i].output_snippet = |
| 328 GetTestOutputSnippet(final_results[i], output); | 326 GetTestOutputSnippet(final_results[i], output); |
| 329 test_launcher->OnTestFinished(final_results[i]); | 327 test_launcher->OnTestFinished(final_results[i]); |
| 330 called_any_callback = true; | 328 called_any_callback = true; |
| 331 } | 329 } |
| 332 } else { | 330 } else { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 const GTestCallbackState& callback_state, | 364 const GTestCallbackState& callback_state, |
| 367 int exit_code, | 365 int exit_code, |
| 368 const TimeDelta& elapsed_time, | 366 const TimeDelta& elapsed_time, |
| 369 bool was_timeout, | 367 bool was_timeout, |
| 370 const std::string& output) { | 368 const std::string& output) { |
| 371 std::vector<std::string> tests_to_relaunch; | 369 std::vector<std::string> tests_to_relaunch; |
| 372 ProcessTestResults(callback_state.test_launcher, callback_state.test_names, | 370 ProcessTestResults(callback_state.test_launcher, callback_state.test_names, |
| 373 callback_state.output_file, output, exit_code, was_timeout, | 371 callback_state.output_file, output, exit_code, was_timeout, |
| 374 &tests_to_relaunch); | 372 &tests_to_relaunch); |
| 375 | 373 |
| 376 // Relaunch requested tests in parallel, but only use single | 374 if (!tests_to_relaunch.empty()) { |
| 377 // test per batch for more precise results (crashes, test passes | 375 callback_state.platform_delegate->RelaunchTests( |
| 378 // but non-zero exit codes etc). | 376 callback_state.test_launcher, |
| 379 for (size_t i = 0; i < tests_to_relaunch.size(); i++) { | 377 tests_to_relaunch, |
| 380 std::vector<std::string> batch; | 378 callback_state.launch_flags); |
| 381 batch.push_back(tests_to_relaunch[i]); | |
| 382 RunUnitTestsBatch(callback_state.test_launcher, | |
| 383 callback_state.platform_delegate, | |
| 384 batch, | |
| 385 callback_state.launch_flags); | |
| 386 } | 379 } |
| 387 | 380 |
| 388 // The temporary file's directory is also temporary. | 381 // The temporary file's directory is also temporary. |
| 389 DeleteFile(callback_state.output_file.DirName(), true); | 382 DeleteFile(callback_state.output_file.DirName(), true); |
| 390 } | 383 } |
| 391 | 384 |
| 392 void SerialGTestCallback( | 385 void SerialGTestCallback( |
| 393 const GTestCallbackState& callback_state, | 386 const GTestCallbackState& callback_state, |
| 394 const std::vector<std::string>& test_names, | 387 const std::vector<std::string>& test_names, |
| 395 int exit_code, | 388 int exit_code, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 FROM_HERE, | 580 FROM_HERE, |
| 588 Bind(&RunUnitTestsSerially, | 581 Bind(&RunUnitTestsSerially, |
| 589 test_launcher, | 582 test_launcher, |
| 590 platform_delegate_, | 583 platform_delegate_, |
| 591 test_names, | 584 test_names, |
| 592 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); | 585 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); |
| 593 return test_names.size(); | 586 return test_names.size(); |
| 594 } | 587 } |
| 595 | 588 |
| 596 } // namespace base | 589 } // namespace base |
| OLD | NEW |