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" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 fflush(stdout); | 232 fflush(stdout); |
233 } | 233 } |
234 | 234 |
235 void TestResultsTracker::AddGlobalTag(const std::string& tag) { | 235 void TestResultsTracker::AddGlobalTag(const std::string& tag) { |
236 global_tags_.insert(tag); | 236 global_tags_.insert(tag); |
237 } | 237 } |
238 | 238 |
239 bool TestResultsTracker::SaveSummaryAsJSON(const FilePath& path) const { | 239 bool TestResultsTracker::SaveSummaryAsJSON(const FilePath& path) const { |
240 scoped_ptr<DictionaryValue> summary_root(new DictionaryValue); | 240 scoped_ptr<DictionaryValue> summary_root(new DictionaryValue); |
241 | 241 |
242 ListValue* global_tags = new ListValue; | 242 scoped_ptr<ListValue> global_tags(new ListValue); |
243 summary_root->Set("global_tags", global_tags); | 243 for (const auto& global_tag : global_tags_) { |
| 244 global_tags->AppendString(global_tag); |
| 245 } |
| 246 summary_root->Set("global_tags", global_tags.Pass()); |
244 | 247 |
245 for (std::set<std::string>::const_iterator i = global_tags_.begin(); | 248 scoped_ptr<ListValue> all_tests(new ListValue); |
246 i != global_tags_.end(); | 249 for (const auto& test : all_tests_) { |
247 ++i) { | 250 all_tests->AppendString(test); |
248 global_tags->AppendString(*i); | |
249 } | 251 } |
| 252 summary_root->Set("all_tests", all_tests.Pass()); |
250 | 253 |
251 ListValue* all_tests = new ListValue; | 254 scoped_ptr<ListValue> disabled_tests(new ListValue); |
252 summary_root->Set("all_tests", all_tests); | 255 for (const auto& disabled_test : disabled_tests_) { |
| 256 disabled_tests->AppendString(disabled_test); |
| 257 } |
| 258 summary_root->Set("disabled_tests", disabled_tests.Pass()); |
253 | 259 |
254 for (std::set<std::string>::const_iterator i = all_tests_.begin(); | 260 scoped_ptr<ListValue> per_iteration_data(new ListValue); |
255 i != all_tests_.end(); | |
256 ++i) { | |
257 all_tests->AppendString(*i); | |
258 } | |
259 | |
260 ListValue* disabled_tests = new ListValue; | |
261 summary_root->Set("disabled_tests", disabled_tests); | |
262 | |
263 for (std::set<std::string>::const_iterator i = disabled_tests_.begin(); | |
264 i != disabled_tests_.end(); | |
265 ++i) { | |
266 disabled_tests->AppendString(*i); | |
267 } | |
268 | |
269 ListValue* per_iteration_data = new ListValue; | |
270 summary_root->Set("per_iteration_data", per_iteration_data); | |
271 | 261 |
272 for (int i = 0; i <= iteration_; i++) { | 262 for (int i = 0; i <= iteration_; i++) { |
273 DictionaryValue* current_iteration_data = new DictionaryValue; | 263 scoped_ptr<DictionaryValue> current_iteration_data(new DictionaryValue); |
274 per_iteration_data->Append(current_iteration_data); | |
275 | 264 |
276 for (PerIterationData::ResultsMap::const_iterator j = | 265 for (PerIterationData::ResultsMap::const_iterator j = |
277 per_iteration_data_[i].results.begin(); | 266 per_iteration_data_[i].results.begin(); |
278 j != per_iteration_data_[i].results.end(); | 267 j != per_iteration_data_[i].results.end(); |
279 ++j) { | 268 ++j) { |
280 ListValue* test_results = new ListValue; | 269 scoped_ptr<ListValue> test_results(new ListValue); |
281 current_iteration_data->SetWithoutPathExpansion(j->first, test_results); | |
282 | 270 |
283 for (size_t k = 0; k < j->second.test_results.size(); k++) { | 271 for (size_t k = 0; k < j->second.test_results.size(); k++) { |
284 const TestResult& test_result = j->second.test_results[k]; | 272 const TestResult& test_result = j->second.test_results[k]; |
285 | 273 |
286 DictionaryValue* test_result_value = new DictionaryValue; | 274 scoped_ptr<DictionaryValue> test_result_value(new DictionaryValue); |
287 test_results->Append(test_result_value); | |
288 | 275 |
289 test_result_value->SetString("status", test_result.StatusAsString()); | 276 test_result_value->SetString("status", test_result.StatusAsString()); |
290 test_result_value->SetInteger( | 277 test_result_value->SetInteger( |
291 "elapsed_time_ms", | 278 "elapsed_time_ms", |
292 static_cast<int>(test_result.elapsed_time.InMilliseconds())); | 279 static_cast<int>(test_result.elapsed_time.InMilliseconds())); |
293 | 280 |
294 // There are no guarantees about character encoding of the output | 281 // There are no guarantees about character encoding of the output |
295 // snippet. Escape it and record whether it was losless. | 282 // snippet. Escape it and record whether it was losless. |
296 // It's useful to have the output snippet as string in the summary | 283 // It's useful to have the output snippet as string in the summary |
297 // for easy viewing. | 284 // for easy viewing. |
298 std::string escaped_output_snippet; | 285 std::string escaped_output_snippet; |
299 bool losless_snippet = EscapeJSONString( | 286 bool losless_snippet = EscapeJSONString( |
300 test_result.output_snippet, false, &escaped_output_snippet); | 287 test_result.output_snippet, false, &escaped_output_snippet); |
301 test_result_value->SetString("output_snippet", | 288 test_result_value->SetString("output_snippet", |
302 escaped_output_snippet); | 289 escaped_output_snippet); |
303 test_result_value->SetBoolean("losless_snippet", losless_snippet); | 290 test_result_value->SetBoolean("losless_snippet", losless_snippet); |
304 | 291 |
305 // Also include the raw version (base64-encoded so that it can be safely | 292 // Also include the raw version (base64-encoded so that it can be safely |
306 // JSON-serialized - there are no guarantees about character encoding | 293 // JSON-serialized - there are no guarantees about character encoding |
307 // of the snippet). This can be very useful piece of information when | 294 // of the snippet). This can be very useful piece of information when |
308 // debugging a test failure related to character encoding. | 295 // debugging a test failure related to character encoding. |
309 std::string base64_output_snippet; | 296 std::string base64_output_snippet; |
310 Base64Encode(test_result.output_snippet, &base64_output_snippet); | 297 Base64Encode(test_result.output_snippet, &base64_output_snippet); |
311 test_result_value->SetString("output_snippet_base64", | 298 test_result_value->SetString("output_snippet_base64", |
312 base64_output_snippet); | 299 base64_output_snippet); |
| 300 test_results->Append(test_result_value.Pass()); |
313 } | 301 } |
| 302 |
| 303 current_iteration_data->SetWithoutPathExpansion(j->first, |
| 304 test_results.Pass()); |
314 } | 305 } |
| 306 per_iteration_data->Append(current_iteration_data.Pass()); |
| 307 summary_root->Set("per_iteration_data", per_iteration_data.Pass()); |
315 } | 308 } |
316 | 309 |
317 JSONFileValueSerializer serializer(path); | 310 JSONFileValueSerializer serializer(path); |
318 return serializer.Serialize(*summary_root); | 311 return serializer.Serialize(*summary_root); |
319 } | 312 } |
320 | 313 |
321 TestResultsTracker::TestStatusMap | 314 TestResultsTracker::TestStatusMap |
322 TestResultsTracker::GetTestStatusMapForCurrentIteration() const { | 315 TestResultsTracker::GetTestStatusMapForCurrentIteration() const { |
323 TestStatusMap tests_by_status; | 316 TestStatusMap tests_by_status; |
324 GetTestStatusForIteration(iteration_, &tests_by_status); | 317 GetTestStatusForIteration(iteration_, &tests_by_status); |
(...skipping 26 matching lines...) Expand all Loading... |
351 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { | 344 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { |
352 } | 345 } |
353 | 346 |
354 TestResultsTracker::PerIterationData::PerIterationData() { | 347 TestResultsTracker::PerIterationData::PerIterationData() { |
355 } | 348 } |
356 | 349 |
357 TestResultsTracker::PerIterationData::~PerIterationData() { | 350 TestResultsTracker::PerIterationData::~PerIterationData() { |
358 } | 351 } |
359 | 352 |
360 } // namespace base | 353 } // namespace base |
OLD | NEW |