diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-21 17:22:01 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-21 17:22:01 +0000 |
commit | 345aac62e63801a0ebe956960e379f570def2903 (patch) | |
tree | c317dd3418b90d2ad40c2ff538c93a10ff4a1a84 /base | |
parent | 8d9243ac8531935066edbc69e988d052e4e13cda (diff) | |
download | chromium_src-345aac62e63801a0ebe956960e379f570def2903.zip chromium_src-345aac62e63801a0ebe956960e379f570def2903.tar.gz chromium_src-345aac62e63801a0ebe956960e379f570def2903.tar.bz2 |
GTTF: Move logic related to "what to do next" out of TestResultsTracker
This is a preparation for making TestLauncher retry tests.
BUG=236893
R=sky@chromium.org
Review URL: https://codereview.chromium.org/29733004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/test/launcher/test_launcher.cc | 110 | ||||
-rw-r--r-- | base/test/launcher/test_launcher.h | 18 | ||||
-rw-r--r-- | base/test/launcher/test_results_tracker.cc | 98 | ||||
-rw-r--r-- | base/test/launcher/test_results_tracker.h | 26 |
4 files changed, 127 insertions, 125 deletions
diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc index b1315c0..21952a7 100644 --- a/base/test/launcher/test_launcher.cc +++ b/base/test/launcher/test_launcher.cc @@ -206,7 +206,11 @@ TestLauncher::TestLauncher(TestLauncherDelegate* launcher_delegate) : launcher_delegate_(launcher_delegate), total_shards_(1), shard_index_(0), - cycles_(1) { + cycles_(1), + test_started_count_(0), + test_finished_count_(0), + test_success_count_(0), + run_result_(true) { } bool TestLauncher::Run(int argc, char** argv) { @@ -236,13 +240,9 @@ bool TestLauncher::Run(int argc, char** argv) { &watcher)); #endif // defined(OS_POSIX) - bool success = true; MessageLoop::current()->PostTask( FROM_HERE, - Bind(&TestLauncher::RunTestIteration, - Unretained(this), - &success, - true)); + Bind(&TestLauncher::RunTestIteration, Unretained(this))); MessageLoop::current()->Run(); @@ -258,7 +258,7 @@ bool TestLauncher::Run(int argc, char** argv) { } } - return success; + return run_result_; } bool TestLauncher::Init() { @@ -349,15 +349,15 @@ void TestLauncher::RunTests() { if (num_runnable_tests++ % total_shards_ != shard_index_) continue; - results_tracker_.OnTestStarted(test_name); + test_started_count_++; MessageLoop::current()->PostTask( FROM_HERE, Bind(&TestLauncherDelegate::RunTest, Unretained(launcher_delegate_), test_case, test_info, - Bind(&TestResultsTracker::AddTestResult, - Unretained(&results_tracker_)))); + Bind(&TestLauncher::OnTestFinished, + Unretained(this)))); } } @@ -368,18 +368,11 @@ void TestLauncher::RunTests() { MessageLoop::current()->PostTask( FROM_HERE, - Bind(&TestResultsTracker::OnAllTestsStarted, - Unretained(&results_tracker_))); + Bind(&TestLauncher::OnAllTestsStarted, + Unretained(this))); } -void TestLauncher::RunTestIteration(bool* final_result, - bool run_tests_success) { - if (!run_tests_success) { - // Signal failure, but continue to run all requested test iterations. - // With the summary of all iterations at the end this is a good default. - *final_result = false; - } - +void TestLauncher::RunTestIteration() { if (cycles_ == 0) { MessageLoop::current()->Quit(); return; @@ -388,15 +381,86 @@ void TestLauncher::RunTestIteration(bool* final_result, // Special value "-1" means "repeat indefinitely". cycles_ = (cycles_ == -1) ? cycles_ : cycles_ - 1; + test_started_count_ = 0; + test_finished_count_ = 0; + test_success_count_ = 0; + results_tracker_.OnTestIterationStarting(); launcher_delegate_->OnTestIterationStarting(); - results_tracker_.OnTestIterationStarting( - Bind(&TestLauncher::RunTestIteration, Unretained(this), final_result)); - MessageLoop::current()->PostTask( FROM_HERE, Bind(&TestLauncher::RunTests, Unretained(this))); } +void TestLauncher::OnAllTestsStarted() { + if (test_started_count_ == 0) { + fprintf(stdout, "0 tests run\n"); + fflush(stdout); + + // No tests have actually been started, so kick off the next iteration. + MessageLoop::current()->PostTask( + FROM_HERE, + Bind(&TestLauncher::RunTestIteration, Unretained(this))); + } +} + +void TestLauncher::OnTestFinished(const TestResult& result) { + ++test_finished_count_; + + if (result.status == TestResult::TEST_SUCCESS) { + ++test_success_count_; + } else { + fprintf(stdout, "%s", result.output_snippet.c_str()); + fflush(stdout); + } + + results_tracker_.AddTestResult(result); + + // TODO(phajdan.jr): Align counter (padding). + std::string status_line( + StringPrintf("[%" PRIuS "/%" PRIuS "] %s ", + test_finished_count_, + test_started_count_, + result.GetFullName().c_str())); + if (result.completed()) { + status_line.append(StringPrintf("(%" PRId64 " ms)", + result.elapsed_time.InMilliseconds())); + } else if (result.status == TestResult::TEST_TIMEOUT) { + status_line.append("(TIMED OUT)"); + } else if (result.status == TestResult::TEST_CRASH) { + status_line.append("(CRASHED)"); + } else if (result.status == TestResult::TEST_SKIPPED) { + status_line.append("(SKIPPED)"); + } else if (result.status == TestResult::TEST_UNKNOWN) { + status_line.append("(UNKNOWN)"); + } else { + // Fail very loudly so it's not ignored. + CHECK(false) << "Unhandled test result status: " << result.status; + } + fprintf(stdout, "%s\n", status_line.c_str()); + fflush(stdout); + + if (test_finished_count_ == test_started_count_) { + // The current iteration is done. + fprintf(stdout, "%" PRIuS " test%s run\n", + test_finished_count_, + test_finished_count_ > 1 ? "s" : ""); + fflush(stdout); + + results_tracker_.PrintSummaryOfCurrentIteration(); + + if (test_success_count_ != test_finished_count_) { + // Signal failure, but continue to run all requested test iterations. + // With the summary of all iterations at the end this is a good default. + run_result_ = false; + } + + // Kick off the next iteration. + MessageLoop::current()->PostTask( + FROM_HERE, + Bind(&TestLauncher::RunTestIteration, Unretained(this))); + } +} + std::string GetTestOutputSnippet(const TestResult& result, const std::string& full_output) { size_t run_pos = full_output.find(std::string("[ RUN ] ") + diff --git a/base/test/launcher/test_launcher.h b/base/test/launcher/test_launcher.h index a910a2a..36b6ca7 100644 --- a/base/test/launcher/test_launcher.h +++ b/base/test/launcher/test_launcher.h @@ -86,7 +86,11 @@ class TestLauncher { // Runs all tests in current iteration. Uses callbacks to communicate success. void RunTests(); - void RunTestIteration(bool* final_result, bool run_tests_success); + void RunTestIteration(); + + void OnAllTestsStarted(); + + void OnTestFinished(const TestResult& result); TestLauncherDelegate* launcher_delegate_; @@ -100,6 +104,18 @@ class TestLauncher { std::string positive_test_filter_; std::string negative_test_filter_; + // Number of tests started in this iteration. + size_t test_started_count_; + + // Number of tests finished in this iteration. + size_t test_finished_count_; + + // Number of tests successfully finished in this iteration. + size_t test_success_count_; + + // Result to be returned from Run. + bool run_result_; + TestResultsTracker results_tracker_; DISALLOW_COPY_AND_ASSIGN(TestLauncher); diff --git a/base/test/launcher/test_results_tracker.cc b/base/test/launcher/test_results_tracker.cc index 849194a..fcb6db1 100644 --- a/base/test/launcher/test_results_tracker.cc +++ b/base/test/launcher/test_results_tracker.cc @@ -133,94 +133,29 @@ bool TestResultsTracker::Init(const CommandLine& command_line) { return true; } -void TestResultsTracker::OnTestIterationStarting( - const TestsResultCallback& callback) { +void TestResultsTracker::OnTestIterationStarting() { DCHECK(thread_checker_.CalledOnValidThread()); // Start with a fresh state for new iteration. iteration_++; per_iteration_data_.push_back(PerIterationData()); - DCHECK_EQ(per_iteration_data_.size(), static_cast<size_t>(iteration_ + 1)); - - per_iteration_data_[iteration_].callback = callback; -} - -void TestResultsTracker::OnTestStarted(const std::string& name) { - DCHECK(thread_checker_.CalledOnValidThread()); - ++per_iteration_data_[iteration_].test_started_count; -} - -void TestResultsTracker::OnAllTestsStarted() { - DCHECK(thread_checker_.CalledOnValidThread()); - - if (per_iteration_data_[iteration_].test_started_count == 0) { - fprintf(stdout, "0 tests run\n"); - fflush(stdout); - - // No tests have actually been started, so fire the callback - // to avoid a hang. - per_iteration_data_[iteration_].callback.Run(true); - } } void TestResultsTracker::AddTestResult(const TestResult& result) { DCHECK(thread_checker_.CalledOnValidThread()); - ++per_iteration_data_[iteration_].test_run_count; per_iteration_data_[iteration_].results[result.test_case_name].push_back( result); - - if (result.status != TestResult::TEST_SUCCESS) { - fprintf(stdout, "%s", result.output_snippet.c_str()); - fflush(stdout); - } - - // TODO(phajdan.jr): Align counter (padding). - std::string status_line( - StringPrintf("[%" PRIuS "/%" PRIuS "] %s ", - per_iteration_data_[iteration_].test_run_count, - per_iteration_data_[iteration_].test_started_count, - result.GetFullName().c_str())); - if (result.completed()) { - status_line.append(StringPrintf("(%" PRId64 " ms)", - result.elapsed_time.InMilliseconds())); - } else if (result.status == TestResult::TEST_TIMEOUT) { - status_line.append("(TIMED OUT)"); - } else if (result.status == TestResult::TEST_CRASH) { - status_line.append("(CRASHED)"); - } else if (result.status == TestResult::TEST_SKIPPED) { - status_line.append("(SKIPPED)"); - } else if (result.status == TestResult::TEST_UNKNOWN) { - status_line.append("(UNKNOWN)"); - } else { - // Fail very loudly so it's not ignored. - CHECK(false) << "Unhandled test result status: " << result.status; - } - fprintf(stdout, "%s\n", status_line.c_str()); - fflush(stdout); - per_iteration_data_[iteration_].tests_by_status[result.status].push_back( result.GetFullName()); +} - if (per_iteration_data_[iteration_].test_run_count == - per_iteration_data_[iteration_].test_started_count) { - fprintf(stdout, "%" PRIuS " test%s run\n", - per_iteration_data_[iteration_].test_run_count, - per_iteration_data_[iteration_].test_run_count > 1 ? "s" : ""); - fflush(stdout); - - PrintTestsByStatus(TestResult::TEST_FAILURE, "failed"); - PrintTestsByStatus(TestResult::TEST_TIMEOUT, "timed out"); - PrintTestsByStatus(TestResult::TEST_CRASH, "crashed"); - PrintTestsByStatus(TestResult::TEST_SKIPPED, "skipped"); - PrintTestsByStatus(TestResult::TEST_UNKNOWN, "had unknown result"); - - bool success = (per_iteration_data_[iteration_].tests_by_status[ - TestResult::TEST_SUCCESS].size() == - per_iteration_data_[iteration_].test_run_count); - - per_iteration_data_[iteration_].callback.Run(success); - } +void TestResultsTracker::PrintSummaryOfCurrentIteration() const { + PrintTestsByStatus(TestResult::TEST_FAILURE, "failed"); + PrintTestsByStatus(TestResult::TEST_TIMEOUT, "timed out"); + PrintTestsByStatus(TestResult::TEST_CRASH, "crashed"); + PrintTestsByStatus(TestResult::TEST_SKIPPED, "skipped"); + PrintTestsByStatus(TestResult::TEST_UNKNOWN, "had unknown result"); } void TestResultsTracker::PrintSummaryOfAllIterations() const { @@ -295,21 +230,22 @@ bool TestResultsTracker::SaveSummaryAsJSON(const FilePath& path) const { return serializer.Serialize(*summary_root); } -TestResultsTracker::PerIterationData::PerIterationData() - : test_started_count(0), - test_run_count(0) { +TestResultsTracker::PerIterationData::PerIterationData() { } TestResultsTracker::PerIterationData::~PerIterationData() { } -void TestResultsTracker::PrintTestsByStatus(TestResult::Status status, - const std::string& description) { +void TestResultsTracker::PrintTestsByStatus( + TestResult::Status status, + const std::string& description) const { DCHECK(thread_checker_.CalledOnValidThread()); - const std::vector<std::string>& tests = - per_iteration_data_[iteration_].tests_by_status[status]; - PrintTests(tests.begin(), tests.end(), description); + PerIterationData::StatusMap::const_iterator i( + per_iteration_data_[iteration_].tests_by_status.find(status)); + if (i == per_iteration_data_[iteration_].tests_by_status.end()) + return; + PrintTests(i->second.begin(), i->second.end(), description); } } // namespace base diff --git a/base/test/launcher/test_results_tracker.h b/base/test/launcher/test_results_tracker.h index 112fbb2..d33c480 100644 --- a/base/test/launcher/test_results_tracker.h +++ b/base/test/launcher/test_results_tracker.h @@ -30,8 +30,6 @@ class FilePath; // detailed failure messages either. class TestResultsTracker { public: - typedef Callback<void(bool)> TestsResultCallback; - TestResultsTracker(); ~TestResultsTracker(); @@ -39,20 +37,15 @@ class TestResultsTracker { // calling any other methods. Returns true on success. bool Init(const CommandLine& command_line) WARN_UNUSED_RESULT; - // Called when a test iteration is starting. |callback| will be called - // be the result tracker at the end of that iteration. - void OnTestIterationStarting(const TestsResultCallback& callback); - - // Called when test named |name| is scheduled to be started. - void OnTestStarted(const std::string& name); - - // Called when all tests that were to be started have been scheduled - // to be started. - void OnAllTestsStarted(); + // Called when a test iteration is starting. + void OnTestIterationStarting(); // Adds |result| to the stored test results. void AddTestResult(const TestResult& result); + // Prints a summary of current test iteration to stdout. + void PrintSummaryOfCurrentIteration() const; + // Prints a summary of all test iterations (not just the last one) to stdout. void PrintSummaryOfAllIterations() const; @@ -72,18 +65,11 @@ class TestResultsTracker { // List of full names of failed tests. typedef std::map<TestResult::Status, std::vector<std::string> > StatusMap; StatusMap tests_by_status; - - size_t test_started_count; - - // Total number of tests run. - size_t test_run_count; - - TestsResultCallback callback; }; // Prints a list of tests that finished with |status|. void PrintTestsByStatus(TestResult::Status status, - const std::string& description); + const std::string& description) const; ThreadChecker thread_checker_; |