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" |
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/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "base/test/launcher/test_launcher.h" | 17 #include "base/test/launcher/test_launcher.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 | 21 |
21 // See https://groups.google.com/a/chromium.org/d/msg/chromium-dev/nkdTP7sstSc/u
T3FaE_sgkAJ . | 22 // See https://groups.google.com/a/chromium.org/d/msg/chromium-dev/nkdTP7sstSc/u
T3FaE_sgkAJ . |
22 using ::operator<<; | 23 using ::operator<<; |
23 | 24 |
24 namespace { | 25 namespace { |
(...skipping 15 matching lines...) Expand all Loading... |
40 fprintf(stdout, | 41 fprintf(stdout, |
41 "%" PRIuS " test%s %s:\n", | 42 "%" PRIuS " test%s %s:\n", |
42 count, | 43 count, |
43 count != 1 ? "s" : "", | 44 count != 1 ? "s" : "", |
44 description.c_str()); | 45 description.c_str()); |
45 for (InputIterator i = first; i != last; ++i) | 46 for (InputIterator i = first; i != last; ++i) |
46 fprintf(stdout, " %s\n", (*i).c_str()); | 47 fprintf(stdout, " %s\n", (*i).c_str()); |
47 fflush(stdout); | 48 fflush(stdout); |
48 } | 49 } |
49 | 50 |
| 51 std::string TestNameWithoutDisabledPrefix(const std::string& test_name) { |
| 52 std::string test_name_no_disabled(test_name); |
| 53 ReplaceSubstringsAfterOffset(&test_name_no_disabled, 0, "DISABLED_", ""); |
| 54 return test_name_no_disabled; |
| 55 } |
| 56 |
50 } // namespace | 57 } // namespace |
51 | 58 |
52 TestResultsTracker::TestResultsTracker() : iteration_(-1), out_(NULL) { | 59 TestResultsTracker::TestResultsTracker() : iteration_(-1), out_(NULL) { |
53 } | 60 } |
54 | 61 |
55 TestResultsTracker::~TestResultsTracker() { | 62 TestResultsTracker::~TestResultsTracker() { |
56 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
57 | 64 |
58 if (!out_) | 65 if (!out_) |
59 return; | 66 return; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 155 } |
149 | 156 |
150 void TestResultsTracker::OnTestIterationStarting() { | 157 void TestResultsTracker::OnTestIterationStarting() { |
151 DCHECK(thread_checker_.CalledOnValidThread()); | 158 DCHECK(thread_checker_.CalledOnValidThread()); |
152 | 159 |
153 // Start with a fresh state for new iteration. | 160 // Start with a fresh state for new iteration. |
154 iteration_++; | 161 iteration_++; |
155 per_iteration_data_.push_back(PerIterationData()); | 162 per_iteration_data_.push_back(PerIterationData()); |
156 } | 163 } |
157 | 164 |
| 165 void TestResultsTracker::AddTest(const std::string& test_name) { |
| 166 // Record disabled test names without DISABLED_ prefix so that they are easy |
| 167 // to compare with regular test names, e.g. before or after disabling. |
| 168 all_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); |
| 169 } |
| 170 |
| 171 void TestResultsTracker::AddDisabledTest(const std::string& test_name) { |
| 172 // Record disabled test names without DISABLED_ prefix so that they are easy |
| 173 // to compare with regular test names, e.g. before or after disabling. |
| 174 disabled_tests_.insert(TestNameWithoutDisabledPrefix(test_name)); |
| 175 } |
| 176 |
158 void TestResultsTracker::AddTestResult(const TestResult& result) { | 177 void TestResultsTracker::AddTestResult(const TestResult& result) { |
159 DCHECK(thread_checker_.CalledOnValidThread()); | 178 DCHECK(thread_checker_.CalledOnValidThread()); |
160 | 179 |
161 per_iteration_data_[iteration_].results[ | 180 per_iteration_data_[iteration_].results[ |
162 result.full_name].test_results.push_back(result); | 181 result.full_name].test_results.push_back(result); |
163 } | 182 } |
164 | 183 |
165 void TestResultsTracker::PrintSummaryOfCurrentIteration() const { | 184 void TestResultsTracker::PrintSummaryOfCurrentIteration() const { |
166 std::map<TestResult::Status, std::set<std::string> > tests_by_status; | 185 std::map<TestResult::Status, std::set<std::string> > tests_by_status; |
167 | 186 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 264 |
246 ListValue* global_tags = new ListValue; | 265 ListValue* global_tags = new ListValue; |
247 summary_root->Set("global_tags", global_tags); | 266 summary_root->Set("global_tags", global_tags); |
248 | 267 |
249 for (std::set<std::string>::const_iterator i = global_tags_.begin(); | 268 for (std::set<std::string>::const_iterator i = global_tags_.begin(); |
250 i != global_tags_.end(); | 269 i != global_tags_.end(); |
251 ++i) { | 270 ++i) { |
252 global_tags->AppendString(*i); | 271 global_tags->AppendString(*i); |
253 } | 272 } |
254 | 273 |
| 274 ListValue* all_tests = new ListValue; |
| 275 summary_root->Set("all_tests", all_tests); |
| 276 |
| 277 for (std::set<std::string>::const_iterator i = all_tests_.begin(); |
| 278 i != all_tests_.end(); |
| 279 ++i) { |
| 280 all_tests->AppendString(*i); |
| 281 } |
| 282 |
| 283 ListValue* disabled_tests = new ListValue; |
| 284 summary_root->Set("disabled_tests", disabled_tests); |
| 285 |
| 286 for (std::set<std::string>::const_iterator i = disabled_tests_.begin(); |
| 287 i != disabled_tests_.end(); |
| 288 ++i) { |
| 289 disabled_tests->AppendString(*i); |
| 290 } |
| 291 |
255 ListValue* per_iteration_data = new ListValue; | 292 ListValue* per_iteration_data = new ListValue; |
256 summary_root->Set("per_iteration_data", per_iteration_data); | 293 summary_root->Set("per_iteration_data", per_iteration_data); |
257 | 294 |
258 for (int i = 0; i <= iteration_; i++) { | 295 for (int i = 0; i <= iteration_; i++) { |
259 DictionaryValue* current_iteration_data = new DictionaryValue; | 296 DictionaryValue* current_iteration_data = new DictionaryValue; |
260 per_iteration_data->Append(current_iteration_data); | 297 per_iteration_data->Append(current_iteration_data); |
261 | 298 |
262 for (PerIterationData::ResultsMap::const_iterator j = | 299 for (PerIterationData::ResultsMap::const_iterator j = |
263 per_iteration_data_[i].results.begin(); | 300 per_iteration_data_[i].results.begin(); |
264 j != per_iteration_data_[i].results.end(); | 301 j != per_iteration_data_[i].results.end(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { | 346 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { |
310 } | 347 } |
311 | 348 |
312 TestResultsTracker::PerIterationData::PerIterationData() { | 349 TestResultsTracker::PerIterationData::PerIterationData() { |
313 } | 350 } |
314 | 351 |
315 TestResultsTracker::PerIterationData::~PerIterationData() { | 352 TestResultsTracker::PerIterationData::~PerIterationData() { |
316 } | 353 } |
317 | 354 |
318 } // namespace base | 355 } // namespace base |
OLD | NEW |