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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
13 #include "base/json/string_escape.h" | 13 #include "base/json/string_escape.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/test/launcher/test_launcher.h" | 17 #include "base/test/launcher/test_launcher.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // The default output file for XML output. | 24 // The default output file for XML output. |
25 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( | 25 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( |
26 "test_detail.xml"); | 26 "test_detail.xml"); |
27 | 27 |
28 // Utility function to print a list of test names. Uses iterator to be | |
29 // compatible with different containers, like vector and set. | |
30 template<typename InputIterator> | |
31 void PrintTests(InputIterator first, | |
32 InputIterator last, | |
33 const std::string& description) { | |
34 size_t count = std::distance(first, last); | |
35 if (count == 0) | |
36 return; | |
37 | |
38 fprintf(stdout, | |
39 "%" PRIuS " test%s %s:\n", | |
40 count, | |
41 count != 1 ? "s" : "", | |
42 description.c_str()); | |
43 for (InputIterator i = first; i != last; ++i) | |
44 fprintf(stdout, " %s\n", (*i).c_str()); | |
45 fflush(stdout); | |
46 } | |
47 | |
48 std::string TestNameWithoutDisabledPrefix(const std::string& test_name) { | 28 std::string TestNameWithoutDisabledPrefix(const std::string& test_name) { |
49 std::string test_name_no_disabled(test_name); | 29 std::string test_name_no_disabled(test_name); |
50 ReplaceSubstringsAfterOffset(&test_name_no_disabled, 0, "DISABLED_", ""); | 30 ReplaceSubstringsAfterOffset(&test_name_no_disabled, 0, "DISABLED_", ""); |
51 return test_name_no_disabled; | 31 return test_name_no_disabled; |
52 } | 32 } |
53 | 33 |
54 } // namespace | 34 } // namespace |
55 | 35 |
56 TestResultsTracker::TestResultsTracker() : iteration_(-1), out_(NULL) { | 36 TestResultsTracker::TestResultsTracker() : iteration_(-1), out_(NULL) { |
57 } | 37 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 132 } |
153 | 133 |
154 void TestResultsTracker::OnTestIterationStarting() { | 134 void TestResultsTracker::OnTestIterationStarting() { |
155 DCHECK(thread_checker_.CalledOnValidThread()); | 135 DCHECK(thread_checker_.CalledOnValidThread()); |
156 | 136 |
157 // Start with a fresh state for new iteration. | 137 // Start with a fresh state for new iteration. |
158 iteration_++; | 138 iteration_++; |
159 per_iteration_data_.push_back(PerIterationData()); | 139 per_iteration_data_.push_back(PerIterationData()); |
160 } | 140 } |
161 | 141 |
162 void TestResultsTracker::AddTest(const std::string& test_name) { | 142 void TestResultsTracker::AddTest( |
| 143 const std::string& test_name, const std::string& file, int line) { |
163 // Record disabled test names without DISABLED_ prefix so that they are easy | 144 // Record disabled test names without DISABLED_ prefix so that they are easy |
164 // to compare with regular test names, e.g. before or after disabling. | 145 // to compare with regular test names, e.g. before or after disabling. |
165 all_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); | 146 all_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); |
| 147 |
| 148 test_locations_.insert(std::make_pair( |
| 149 TestNameWithoutDisabledPrefix(test_name), CodeLocation(file, line))); |
166 } | 150 } |
167 | 151 |
168 void TestResultsTracker::AddDisabledTest(const std::string& test_name) { | 152 void TestResultsTracker::AddDisabledTest(const std::string& test_name) { |
169 // Record disabled test names without DISABLED_ prefix so that they are easy | 153 // Record disabled test names without DISABLED_ prefix so that they are easy |
170 // to compare with regular test names, e.g. before or after disabling. | 154 // to compare with regular test names, e.g. before or after disabling. |
171 disabled_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); | 155 disabled_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); |
172 } | 156 } |
173 | 157 |
174 void TestResultsTracker::AddTestResult(const TestResult& result) { | 158 void TestResultsTracker::AddTestResult(const TestResult& result) { |
175 DCHECK(thread_checker_.CalledOnValidThread()); | 159 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 for (PerIterationData::ResultsMap::const_iterator j = | 315 for (PerIterationData::ResultsMap::const_iterator j = |
332 per_iteration_data_[iteration].results.begin(); | 316 per_iteration_data_[iteration].results.begin(); |
333 j != per_iteration_data_[iteration].results.end(); | 317 j != per_iteration_data_[iteration].results.end(); |
334 ++j) { | 318 ++j) { |
335 // Use the last test result as the final one. | 319 // Use the last test result as the final one. |
336 const TestResult& result = j->second.test_results.back(); | 320 const TestResult& result = j->second.test_results.back(); |
337 (*map)[result.status].insert(result.full_name); | 321 (*map)[result.status].insert(result.full_name); |
338 } | 322 } |
339 } | 323 } |
340 | 324 |
| 325 // Utility function to print a list of test names. Uses iterator to be |
| 326 // compatible with different containers, like vector and set. |
| 327 template<typename InputIterator> |
| 328 void TestResultsTracker::PrintTests(InputIterator first, |
| 329 InputIterator last, |
| 330 const std::string& description) const { |
| 331 size_t count = std::distance(first, last); |
| 332 if (count == 0) |
| 333 return; |
| 334 |
| 335 fprintf(stdout, |
| 336 "%" PRIuS " test%s %s:\n", |
| 337 count, |
| 338 count != 1 ? "s" : "", |
| 339 description.c_str()); |
| 340 for (InputIterator i = first; i != last; ++i) { |
| 341 fprintf(stdout, |
| 342 " %s (%s:%d)\n", |
| 343 (*i).c_str(), |
| 344 test_locations_.at(*i).file.c_str(), |
| 345 test_locations_.at(*i).line); |
| 346 } |
| 347 fflush(stdout); |
| 348 } |
| 349 |
| 350 |
341 TestResultsTracker::AggregateTestResult::AggregateTestResult() { | 351 TestResultsTracker::AggregateTestResult::AggregateTestResult() { |
342 } | 352 } |
343 | 353 |
344 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { | 354 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { |
345 } | 355 } |
346 | 356 |
347 TestResultsTracker::PerIterationData::PerIterationData() { | 357 TestResultsTracker::PerIterationData::PerIterationData() { |
348 } | 358 } |
349 | 359 |
350 TestResultsTracker::PerIterationData::~PerIterationData() { | 360 TestResultsTracker::PerIterationData::~PerIterationData() { |
351 } | 361 } |
352 | 362 |
353 } // namespace base | 363 } // namespace base |
OLD | NEW |