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/test_launcher.h" | 5 #include "base/test/launcher/test_launcher.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/stringize_macros.h" | 29 #include "base/strings/stringize_macros.h" |
30 #include "base/strings/stringprintf.h" | 30 #include "base/strings/stringprintf.h" |
31 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
32 #include "base/test/launcher/test_results_tracker.h" | 32 #include "base/test/launcher/test_results_tracker.h" |
33 #include "base/test/sequenced_worker_pool_owner.h" | 33 #include "base/test/sequenced_worker_pool_owner.h" |
34 #include "base/test/test_switches.h" | 34 #include "base/test/test_switches.h" |
35 #include "base/test/test_timeouts.h" | 35 #include "base/test/test_timeouts.h" |
| 36 #include "base/thread_task_runner_handle.h" |
36 #include "base/threading/thread_checker.h" | 37 #include "base/threading/thread_checker.h" |
37 #include "base/time/time.h" | 38 #include "base/time/time.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
39 | 40 |
40 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
41 #include "base/mac/scoped_nsautorelease_pool.h" | 42 #include "base/mac/scoped_nsautorelease_pool.h" |
42 #endif | 43 #endif |
43 | 44 |
44 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
45 #include "base/win/windows_version.h" | 46 #include "base/win/windows_version.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 bool was_timeout, | 345 bool was_timeout, |
345 const std::string& output) { | 346 const std::string& output) { |
346 callback.Run(exit_code, elapsed_time, was_timeout, output); | 347 callback.Run(exit_code, elapsed_time, was_timeout, output); |
347 } | 348 } |
348 | 349 |
349 void DoLaunchChildTestProcess( | 350 void DoLaunchChildTestProcess( |
350 const CommandLine& command_line, | 351 const CommandLine& command_line, |
351 base::TimeDelta timeout, | 352 base::TimeDelta timeout, |
352 int flags, | 353 int flags, |
353 bool redirect_stdio, | 354 bool redirect_stdio, |
354 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 355 scoped_refptr<SequencedTaskRunner> task_runner, |
355 const TestLauncher::LaunchChildGTestProcessCallback& callback) { | 356 const TestLauncher::LaunchChildGTestProcessCallback& callback) { |
356 TimeTicks start_time = TimeTicks::Now(); | 357 TimeTicks start_time = TimeTicks::Now(); |
357 | 358 |
358 // Redirect child process output to a file. | 359 // Redirect child process output to a file. |
359 base::FilePath output_file; | 360 base::FilePath output_file; |
360 CHECK(base::CreateTemporaryFile(&output_file)); | 361 CHECK(base::CreateTemporaryFile(&output_file)); |
361 | 362 |
362 LaunchOptions options; | 363 LaunchOptions options; |
363 #if defined(OS_WIN) | 364 #if defined(OS_WIN) |
364 win::ScopedHandle handle; | 365 win::ScopedHandle handle; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 std::string output_file_contents; | 416 std::string output_file_contents; |
416 CHECK(base::ReadFileToString(output_file, &output_file_contents)); | 417 CHECK(base::ReadFileToString(output_file, &output_file_contents)); |
417 | 418 |
418 if (!base::DeleteFile(output_file, false)) { | 419 if (!base::DeleteFile(output_file, false)) { |
419 // This needs to be non-fatal at least for Windows. | 420 // This needs to be non-fatal at least for Windows. |
420 LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); | 421 LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); |
421 } | 422 } |
422 | 423 |
423 // Run target callback on the thread it was originating from, not on | 424 // Run target callback on the thread it was originating from, not on |
424 // a worker pool thread. | 425 // a worker pool thread. |
425 message_loop_proxy->PostTask( | 426 task_runner->PostTask(FROM_HERE, |
426 FROM_HERE, | 427 Bind(&RunCallback, |
427 Bind(&RunCallback, | 428 callback, |
428 callback, | 429 exit_code, |
429 exit_code, | 430 TimeTicks::Now() - start_time, |
430 TimeTicks::Now() - start_time, | 431 was_timeout, |
431 was_timeout, | 432 output_file_contents)); |
432 output_file_contents)); | |
433 } | 433 } |
434 | 434 |
435 } // namespace | 435 } // namespace |
436 | 436 |
437 const char kGTestFilterFlag[] = "gtest_filter"; | 437 const char kGTestFilterFlag[] = "gtest_filter"; |
438 const char kGTestHelpFlag[] = "gtest_help"; | 438 const char kGTestHelpFlag[] = "gtest_help"; |
439 const char kGTestListTestsFlag[] = "gtest_list_tests"; | 439 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
440 const char kGTestRepeatFlag[] = "gtest_repeat"; | 440 const char kGTestRepeatFlag[] = "gtest_repeat"; |
441 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; | 441 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; |
442 const char kGTestOutputFlag[] = "gtest_output"; | 442 const char kGTestOutputFlag[] = "gtest_output"; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // JSON summary. | 534 // JSON summary. |
535 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); | 535 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); |
536 | 536 |
537 worker_pool_owner_->pool()->PostWorkerTask( | 537 worker_pool_owner_->pool()->PostWorkerTask( |
538 FROM_HERE, | 538 FROM_HERE, |
539 Bind(&DoLaunchChildTestProcess, | 539 Bind(&DoLaunchChildTestProcess, |
540 new_command_line, | 540 new_command_line, |
541 timeout, | 541 timeout, |
542 flags, | 542 flags, |
543 redirect_stdio, | 543 redirect_stdio, |
544 MessageLoopProxy::current(), | 544 ThreadTaskRunnerHandle::Get(), |
545 Bind(&TestLauncher::OnLaunchTestProcessFinished, | 545 Bind(&TestLauncher::OnLaunchTestProcessFinished, |
546 Unretained(this), | 546 Unretained(this), |
547 callback))); | 547 callback))); |
548 } | 548 } |
549 | 549 |
550 void TestLauncher::OnTestFinished(const TestResult& result) { | 550 void TestLauncher::OnTestFinished(const TestResult& result) { |
551 ++test_finished_count_; | 551 ++test_finished_count_; |
552 | 552 |
553 bool print_snippet = false; | 553 bool print_snippet = false; |
554 std::string print_test_stdio("auto"); | 554 std::string print_test_stdio("auto"); |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 } | 1090 } |
1091 | 1091 |
1092 std::string snippet(full_output.substr(run_pos)); | 1092 std::string snippet(full_output.substr(run_pos)); |
1093 if (end_pos != std::string::npos) | 1093 if (end_pos != std::string::npos) |
1094 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1094 snippet = full_output.substr(run_pos, end_pos - run_pos); |
1095 | 1095 |
1096 return snippet; | 1096 return snippet; |
1097 } | 1097 } |
1098 | 1098 |
1099 } // namespace base | 1099 } // namespace base |
OLD | NEW |