| 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 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/environment.h" | 12 #include "base/environment.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
| 17 #include "base/hash.h" | 17 #include "base/hash.h" |
| 18 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 19 #include "base/location.h" | 19 #include "base/location.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "base/metrics/histogram_macros_local.h" |
| 25 #include "base/metrics/statistics_recorder.h" |
| 24 #include "base/process/kill.h" | 26 #include "base/process/kill.h" |
| 25 #include "base/process/launch.h" | 27 #include "base/process/launch.h" |
| 26 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
| 27 #include "base/single_thread_task_runner.h" | 29 #include "base/single_thread_task_runner.h" |
| 28 #include "base/strings/pattern.h" | 30 #include "base/strings/pattern.h" |
| 29 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
| 30 #include "base/strings/string_split.h" | 32 #include "base/strings/string_split.h" |
| 31 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
| 32 #include "base/strings/stringize_macros.h" | 34 #include "base/strings/stringize_macros.h" |
| 33 #include "base/strings/stringprintf.h" | 35 #include "base/strings/stringprintf.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; | 70 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; |
| 69 // The environment variable name for the test shard index. | 71 // The environment variable name for the test shard index. |
| 70 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; | 72 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; |
| 71 | 73 |
| 72 namespace { | 74 namespace { |
| 73 | 75 |
| 74 // Global tag for test runs where the results are incomplete or unreliable | 76 // Global tag for test runs where the results are incomplete or unreliable |
| 75 // for any reason, e.g. early exit because of too many broken tests. | 77 // for any reason, e.g. early exit because of too many broken tests. |
| 76 const char kUnreliableResultsTag[] = "UNRELIABLE_RESULTS"; | 78 const char kUnreliableResultsTag[] = "UNRELIABLE_RESULTS"; |
| 77 | 79 |
| 80 // Name of the local histogram to measure test output size. |
| 81 const char kOutputSizeHistogramName[] = "TestLauncher.TestOutputSize"; |
| 82 |
| 78 // Maximum time of no output after which we print list of processes still | 83 // Maximum time of no output after which we print list of processes still |
| 79 // running. This deliberately doesn't use TestTimeouts (which is otherwise | 84 // running. This deliberately doesn't use TestTimeouts (which is otherwise |
| 80 // a recommended solution), because they can be increased. This would defeat | 85 // a recommended solution), because they can be increased. This would defeat |
| 81 // the purpose of this timeout, which is 1) to avoid buildbot "no output for | 86 // the purpose of this timeout, which is 1) to avoid buildbot "no output for |
| 82 // X seconds" timeout killing the process 2) help communicate status of | 87 // X seconds" timeout killing the process 2) help communicate status of |
| 83 // the test launcher to people looking at the output (no output for a long | 88 // the test launcher to people looking at the output (no output for a long |
| 84 // time is mysterious and gives no info about what is happening) 3) help | 89 // time is mysterious and gives no info about what is happening) 3) help |
| 85 // debugging in case the process hangs anyway. | 90 // debugging in case the process hangs anyway. |
| 86 const int kOutputTimeoutSeconds = 15; | 91 const int kOutputTimeoutSeconds = 15; |
| 87 | 92 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 ThreadTaskRunnerHandle::Get()->PostTask( | 540 ThreadTaskRunnerHandle::Get()->PostTask( |
| 536 FROM_HERE, Bind(&TestLauncher::RunTestIteration, Unretained(this))); | 541 FROM_HERE, Bind(&TestLauncher::RunTestIteration, Unretained(this))); |
| 537 | 542 |
| 538 RunLoop().Run(); | 543 RunLoop().Run(); |
| 539 | 544 |
| 540 if (requested_cycles != 1) | 545 if (requested_cycles != 1) |
| 541 results_tracker_.PrintSummaryOfAllIterations(); | 546 results_tracker_.PrintSummaryOfAllIterations(); |
| 542 | 547 |
| 543 MaybeSaveSummaryAsJSON(std::vector<std::string>()); | 548 MaybeSaveSummaryAsJSON(std::vector<std::string>()); |
| 544 | 549 |
| 550 std::string output_histogram; |
| 551 StatisticsRecorder::WriteGraph(kOutputSizeHistogramName, &output_histogram); |
| 552 fprintf(stdout, "%s", output_histogram.c_str()); |
| 553 fflush(stdout); |
| 554 |
| 545 return run_result_; | 555 return run_result_; |
| 546 } | 556 } |
| 547 | 557 |
| 548 void TestLauncher::LaunchChildGTestProcess( | 558 void TestLauncher::LaunchChildGTestProcess( |
| 549 const CommandLine& command_line, | 559 const CommandLine& command_line, |
| 550 const std::string& wrapper, | 560 const std::string& wrapper, |
| 551 TimeDelta timeout, | 561 TimeDelta timeout, |
| 552 const LaunchOptions& options, | 562 const LaunchOptions& options, |
| 553 const GTestProcessCompletedCallback& completed_callback, | 563 const GTestProcessCompletedCallback& completed_callback, |
| 554 const GTestProcessLaunchedCallback& launched_callback) { | 564 const GTestProcessLaunchedCallback& launched_callback) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 570 Bind(&TestLauncher::OnLaunchTestProcessFinished, Unretained(this), | 580 Bind(&TestLauncher::OnLaunchTestProcessFinished, Unretained(this), |
| 571 completed_callback), | 581 completed_callback), |
| 572 launched_callback)); | 582 launched_callback)); |
| 573 } | 583 } |
| 574 | 584 |
| 575 void TestLauncher::OnTestFinished(const TestResult& original_result) { | 585 void TestLauncher::OnTestFinished(const TestResult& original_result) { |
| 576 ++test_finished_count_; | 586 ++test_finished_count_; |
| 577 | 587 |
| 578 TestResult result(original_result); | 588 TestResult result(original_result); |
| 579 | 589 |
| 590 LOCAL_HISTOGRAM_CUSTOM_COUNTS( |
| 591 kOutputSizeHistogramName, result.output_snippet.length(), |
| 592 1, 10000000, 50); |
| 580 if (result.output_snippet.length() > kOutputSnippetBytesLimit) { | 593 if (result.output_snippet.length() > kOutputSnippetBytesLimit) { |
| 581 if (result.status == TestResult::TEST_SUCCESS) | 594 if (result.status == TestResult::TEST_SUCCESS) |
| 582 result.status = TestResult::TEST_EXCESSIVE_OUTPUT; | 595 result.status = TestResult::TEST_EXCESSIVE_OUTPUT; |
| 583 result.output_snippet = StringPrintf( | 596 result.output_snippet = StringPrintf( |
| 584 "<truncated (%" PRIuS " bytes)>\n", result.output_snippet.length()) + | 597 "<truncated (%" PRIuS " bytes)>\n", result.output_snippet.length()) + |
| 585 result.output_snippet.substr( | 598 result.output_snippet.substr( |
| 586 result.output_snippet.length() - kOutputSnippetLinesLimit) + | 599 result.output_snippet.length() - kOutputSnippetLinesLimit) + |
| 587 "\n"; | 600 "\n"; |
| 588 } | 601 } |
| 589 | 602 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 | 952 |
| 940 // CPU-related tags. | 953 // CPU-related tags. |
| 941 #if defined(ARCH_CPU_32_BITS) | 954 #if defined(ARCH_CPU_32_BITS) |
| 942 results_tracker_.AddGlobalTag("CPU_32_BITS"); | 955 results_tracker_.AddGlobalTag("CPU_32_BITS"); |
| 943 #endif | 956 #endif |
| 944 | 957 |
| 945 #if defined(ARCH_CPU_64_BITS) | 958 #if defined(ARCH_CPU_64_BITS) |
| 946 results_tracker_.AddGlobalTag("CPU_64_BITS"); | 959 results_tracker_.AddGlobalTag("CPU_64_BITS"); |
| 947 #endif | 960 #endif |
| 948 | 961 |
| 962 StatisticsRecorder::Initialize(); |
| 963 |
| 949 return true; | 964 return true; |
| 950 } | 965 } |
| 951 | 966 |
| 952 void TestLauncher::RunTests() { | 967 void TestLauncher::RunTests() { |
| 953 std::vector<std::string> test_names; | 968 std::vector<std::string> test_names; |
| 954 for (size_t i = 0; i < tests_.size(); i++) { | 969 for (size_t i = 0; i < tests_.size(); i++) { |
| 955 std::string test_name = FormatFullTestName( | 970 std::string test_name = FormatFullTestName( |
| 956 tests_[i].test_case_name, tests_[i].test_name); | 971 tests_[i].test_case_name, tests_[i].test_name); |
| 957 | 972 |
| 958 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); | 973 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 } | 1173 } |
| 1159 | 1174 |
| 1160 std::string snippet(full_output.substr(run_pos)); | 1175 std::string snippet(full_output.substr(run_pos)); |
| 1161 if (end_pos != std::string::npos) | 1176 if (end_pos != std::string::npos) |
| 1162 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1177 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1163 | 1178 |
| 1164 return snippet; | 1179 return snippet; |
| 1165 } | 1180 } |
| 1166 | 1181 |
| 1167 } // namespace base | 1182 } // namespace base |
| OLD | NEW |