| 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_results_tracker.h" | 5 #include "base/test/launcher/test_results_tracker.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 175 } |
| 176 | 176 |
| 177 void TestResultsTracker::AddTestResult(const TestResult& result) { | 177 void TestResultsTracker::AddTestResult(const TestResult& result) { |
| 178 DCHECK(thread_checker_.CalledOnValidThread()); | 178 DCHECK(thread_checker_.CalledOnValidThread()); |
| 179 | 179 |
| 180 per_iteration_data_[iteration_].results[ | 180 per_iteration_data_[iteration_].results[ |
| 181 result.full_name].test_results.push_back(result); | 181 result.full_name].test_results.push_back(result); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void TestResultsTracker::PrintSummaryOfCurrentIteration() const { | 184 void TestResultsTracker::PrintSummaryOfCurrentIteration() const { |
| 185 std::map<TestResult::Status, std::set<std::string> > tests_by_status; | 185 TestStatusMap tests_by_status(GetTestStatusMapForCurrentIteration()); |
| 186 | |
| 187 for (PerIterationData::ResultsMap::const_iterator j = | |
| 188 per_iteration_data_[iteration_].results.begin(); | |
| 189 j != per_iteration_data_[iteration_].results.end(); | |
| 190 ++j) { | |
| 191 // Use the last test result as the final one. | |
| 192 TestResult result = j->second.test_results.back(); | |
| 193 tests_by_status[result.status].insert(result.full_name); | |
| 194 } | |
| 195 | 186 |
| 196 PrintTests(tests_by_status[TestResult::TEST_FAILURE].begin(), | 187 PrintTests(tests_by_status[TestResult::TEST_FAILURE].begin(), |
| 197 tests_by_status[TestResult::TEST_FAILURE].end(), | 188 tests_by_status[TestResult::TEST_FAILURE].end(), |
| 198 "failed"); | 189 "failed"); |
| 199 PrintTests(tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].begin(), | 190 PrintTests(tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].begin(), |
| 200 tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].end(), | 191 tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].end(), |
| 201 "failed on exit"); | 192 "failed on exit"); |
| 202 PrintTests(tests_by_status[TestResult::TEST_TIMEOUT].begin(), | 193 PrintTests(tests_by_status[TestResult::TEST_TIMEOUT].begin(), |
| 203 tests_by_status[TestResult::TEST_TIMEOUT].end(), | 194 tests_by_status[TestResult::TEST_TIMEOUT].end(), |
| 204 "timed out"); | 195 "timed out"); |
| 205 PrintTests(tests_by_status[TestResult::TEST_CRASH].begin(), | 196 PrintTests(tests_by_status[TestResult::TEST_CRASH].begin(), |
| 206 tests_by_status[TestResult::TEST_CRASH].end(), | 197 tests_by_status[TestResult::TEST_CRASH].end(), |
| 207 "crashed"); | 198 "crashed"); |
| 208 PrintTests(tests_by_status[TestResult::TEST_SKIPPED].begin(), | 199 PrintTests(tests_by_status[TestResult::TEST_SKIPPED].begin(), |
| 209 tests_by_status[TestResult::TEST_SKIPPED].end(), | 200 tests_by_status[TestResult::TEST_SKIPPED].end(), |
| 210 "skipped"); | 201 "skipped"); |
| 211 PrintTests(tests_by_status[TestResult::TEST_UNKNOWN].begin(), | 202 PrintTests(tests_by_status[TestResult::TEST_UNKNOWN].begin(), |
| 212 tests_by_status[TestResult::TEST_UNKNOWN].end(), | 203 tests_by_status[TestResult::TEST_UNKNOWN].end(), |
| 213 "had unknown result"); | 204 "had unknown result"); |
| 214 } | 205 } |
| 215 | 206 |
| 216 void TestResultsTracker::PrintSummaryOfAllIterations() const { | 207 void TestResultsTracker::PrintSummaryOfAllIterations() const { |
| 217 DCHECK(thread_checker_.CalledOnValidThread()); | 208 DCHECK(thread_checker_.CalledOnValidThread()); |
| 218 | 209 |
| 219 std::map<TestResult::Status, std::set<std::string> > tests_by_status; | 210 TestStatusMap tests_by_status(GetTestStatusMapForAllIterations()); |
| 220 | |
| 221 for (int i = 0; i <= iteration_; i++) { | |
| 222 for (PerIterationData::ResultsMap::const_iterator j = | |
| 223 per_iteration_data_[i].results.begin(); | |
| 224 j != per_iteration_data_[i].results.end(); | |
| 225 ++j) { | |
| 226 // Use the last test result as the final one. | |
| 227 TestResult result = j->second.test_results.back(); | |
| 228 tests_by_status[result.status].insert(result.full_name); | |
| 229 } | |
| 230 } | |
| 231 | 211 |
| 232 fprintf(stdout, "Summary of all test iterations:\n"); | 212 fprintf(stdout, "Summary of all test iterations:\n"); |
| 233 fflush(stdout); | 213 fflush(stdout); |
| 234 | 214 |
| 235 PrintTests(tests_by_status[TestResult::TEST_FAILURE].begin(), | 215 PrintTests(tests_by_status[TestResult::TEST_FAILURE].begin(), |
| 236 tests_by_status[TestResult::TEST_FAILURE].end(), | 216 tests_by_status[TestResult::TEST_FAILURE].end(), |
| 237 "failed"); | 217 "failed"); |
| 238 PrintTests(tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].begin(), | 218 PrintTests(tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].begin(), |
| 239 tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].end(), | 219 tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].end(), |
| 240 "failed on exit"); | 220 "failed on exit"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 test_result_value->SetString("output_snippet_base64", | 313 test_result_value->SetString("output_snippet_base64", |
| 334 base64_output_snippet); | 314 base64_output_snippet); |
| 335 } | 315 } |
| 336 } | 316 } |
| 337 } | 317 } |
| 338 | 318 |
| 339 JSONFileValueSerializer serializer(path); | 319 JSONFileValueSerializer serializer(path); |
| 340 return serializer.Serialize(*summary_root); | 320 return serializer.Serialize(*summary_root); |
| 341 } | 321 } |
| 342 | 322 |
| 323 TestResultsTracker::TestStatusMap |
| 324 TestResultsTracker::GetTestStatusMapForCurrentIteration() const { |
| 325 TestStatusMap tests_by_status; |
| 326 GetTestStatusForIteration(iteration_, &tests_by_status); |
| 327 return tests_by_status; |
| 328 } |
| 329 |
| 330 TestResultsTracker::TestStatusMap |
| 331 TestResultsTracker::GetTestStatusMapForAllIterations() const { |
| 332 TestStatusMap tests_by_status; |
| 333 for (int i = 0; i <= iteration_; i++) |
| 334 GetTestStatusForIteration(i, &tests_by_status); |
| 335 return tests_by_status; |
| 336 } |
| 337 |
| 338 void TestResultsTracker::GetTestStatusForIteration( |
| 339 int iteration, TestStatusMap* map) const { |
| 340 for (PerIterationData::ResultsMap::const_iterator j = |
| 341 per_iteration_data_[iteration].results.begin(); |
| 342 j != per_iteration_data_[iteration].results.end(); |
| 343 ++j) { |
| 344 // Use the last test result as the final one. |
| 345 const TestResult& result = j->second.test_results.back(); |
| 346 (*map)[result.status].insert(result.full_name); |
| 347 } |
| 348 } |
| 349 |
| 343 TestResultsTracker::AggregateTestResult::AggregateTestResult() { | 350 TestResultsTracker::AggregateTestResult::AggregateTestResult() { |
| 344 } | 351 } |
| 345 | 352 |
| 346 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { | 353 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { |
| 347 } | 354 } |
| 348 | 355 |
| 349 TestResultsTracker::PerIterationData::PerIterationData() { | 356 TestResultsTracker::PerIterationData::PerIterationData() { |
| 350 } | 357 } |
| 351 | 358 |
| 352 TestResultsTracker::PerIterationData::~PerIterationData() { | 359 TestResultsTracker::PerIterationData::~PerIterationData() { |
| 353 } | 360 } |
| 354 | 361 |
| 355 } // namespace base | 362 } // namespace base |
| OLD | NEW |