| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.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/format_macros.h" | 15 #include "base/format_macros.h" |
| 16 #include "base/json/json_file_value_serializer.h" | 16 #include "base/json/json_file_value_serializer.h" |
| 17 #include "base/json/string_escape.h" | 17 #include "base/json/string_escape.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/test/gtest_util.h" |
| 21 #include "base/test/launcher/test_launcher.h" | 22 #include "base/test/launcher/test_launcher.h" |
| 22 #include "base/values.h" | 23 #include "base/values.h" |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // The default output file for XML output. | 29 // The default output file for XML output. |
| 29 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( | 30 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( |
| 30 "test_detail.xml"); | 31 "test_detail.xml"); |
| 31 | 32 |
| 32 std::string TestNameWithoutDisabledPrefix(const std::string& test_name) { | |
| 33 std::string test_name_no_disabled(test_name); | |
| 34 ReplaceSubstringsAfterOffset(&test_name_no_disabled, 0, "DISABLED_", ""); | |
| 35 return test_name_no_disabled; | |
| 36 } | |
| 37 | |
| 38 // Converts the given epoch time in milliseconds to a date string in the ISO | 33 // Converts the given epoch time in milliseconds to a date string in the ISO |
| 39 // 8601 format, without the timezone information. | 34 // 8601 format, without the timezone information. |
| 40 // TODO(xyzzyz): Find a good place in Chromium to put it and refactor all uses | 35 // TODO(xyzzyz): Find a good place in Chromium to put it and refactor all uses |
| 41 // to point to it. | 36 // to point to it. |
| 42 std::string FormatTimeAsIso8601(base::Time time) { | 37 std::string FormatTimeAsIso8601(base::Time time) { |
| 43 base::Time::Exploded exploded; | 38 base::Time::Exploded exploded; |
| 44 time.UTCExplode(&exploded); | 39 time.UTCExplode(&exploded); |
| 45 return StringPrintf("%04d-%02d-%02dT%02d:%02d:%02d", | 40 return StringPrintf("%04d-%02d-%02dT%02d:%02d:%02d", |
| 46 exploded.year, | 41 exploded.year, |
| 47 exploded.month, | 42 exploded.month, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 223 |
| 229 void TestResultsTracker::AddDisabledTest(const std::string& test_name) { | 224 void TestResultsTracker::AddDisabledTest(const std::string& test_name) { |
| 230 // Record disabled test names without DISABLED_ prefix so that they are easy | 225 // Record disabled test names without DISABLED_ prefix so that they are easy |
| 231 // to compare with regular test names, e.g. before or after disabling. | 226 // to compare with regular test names, e.g. before or after disabling. |
| 232 disabled_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); | 227 disabled_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); |
| 233 } | 228 } |
| 234 | 229 |
| 235 void TestResultsTracker::AddTestResult(const TestResult& result) { | 230 void TestResultsTracker::AddTestResult(const TestResult& result) { |
| 236 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
| 237 | 232 |
| 233 // Record disabled test names without DISABLED_ prefix so that they are easy |
| 234 // to compare with regular test names, e.g. before or after disabling. |
| 238 per_iteration_data_[iteration_].results[ | 235 per_iteration_data_[iteration_].results[ |
| 239 result.full_name].test_results.push_back(result); | 236 TestNameWithoutDisabledPrefix(result.full_name)].test_results.push_back( |
| 237 result); |
| 240 } | 238 } |
| 241 | 239 |
| 242 void TestResultsTracker::PrintSummaryOfCurrentIteration() const { | 240 void TestResultsTracker::PrintSummaryOfCurrentIteration() const { |
| 243 TestStatusMap tests_by_status(GetTestStatusMapForCurrentIteration()); | 241 TestStatusMap tests_by_status(GetTestStatusMapForCurrentIteration()); |
| 244 | 242 |
| 245 PrintTests(tests_by_status[TestResult::TEST_FAILURE].begin(), | 243 PrintTests(tests_by_status[TestResult::TEST_FAILURE].begin(), |
| 246 tests_by_status[TestResult::TEST_FAILURE].end(), | 244 tests_by_status[TestResult::TEST_FAILURE].end(), |
| 247 "failed"); | 245 "failed"); |
| 248 PrintTests(tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].begin(), | 246 PrintTests(tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].begin(), |
| 249 tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].end(), | 247 tests_by_status[TestResult::TEST_FAILURE_ON_EXIT].end(), |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 TestResultsTracker::PerIterationData::PerIterationData() { | 451 TestResultsTracker::PerIterationData::PerIterationData() { |
| 454 } | 452 } |
| 455 | 453 |
| 456 TestResultsTracker::PerIterationData::PerIterationData( | 454 TestResultsTracker::PerIterationData::PerIterationData( |
| 457 const PerIterationData& other) = default; | 455 const PerIterationData& other) = default; |
| 458 | 456 |
| 459 TestResultsTracker::PerIterationData::~PerIterationData() { | 457 TestResultsTracker::PerIterationData::~PerIterationData() { |
| 460 } | 458 } |
| 461 | 459 |
| 462 } // namespace base | 460 } // namespace base |
| OLD | NEW |