| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import collections | 5 import collections |
| 6 import itertools | 6 import itertools |
| 7 import json | 7 import json |
| 8 | 8 |
| 9 from pylib.base import base_test_result | 9 from pylib.base import base_test_result |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return 'FAILURE' | 80 return 'FAILURE' |
| 81 elif s == base_test_result.ResultType.CRASH: | 81 elif s == base_test_result.ResultType.CRASH: |
| 82 return 'CRASH' | 82 return 'CRASH' |
| 83 elif s == base_test_result.ResultType.TIMEOUT: | 83 elif s == base_test_result.ResultType.TIMEOUT: |
| 84 return 'TIMEOUT' | 84 return 'TIMEOUT' |
| 85 elif s == base_test_result.ResultType.UNKNOWN: | 85 elif s == base_test_result.ResultType.UNKNOWN: |
| 86 return 'UNKNOWN' | 86 return 'UNKNOWN' |
| 87 | 87 |
| 88 all_tests = set() | 88 all_tests = set() |
| 89 per_iteration_data = [] | 89 per_iteration_data = [] |
| 90 base_links = {} |
| 90 for test_run_result in test_run_results: | 91 for test_run_result in test_run_results: |
| 91 iteration_data = collections.defaultdict(list) | 92 iteration_data = collections.defaultdict(list) |
| 92 if isinstance(test_run_result, list): | 93 if isinstance(test_run_result, list): |
| 93 results_iterable = itertools.chain(*(t.GetAll() for t in test_run_result)) | 94 results_iterable = itertools.chain(*(t.GetAll() for t in test_run_result)) |
| 95 base_links.update({ |
| 96 k: v for tr in test_run_result for k, v in tr.GetLinks().items()}) |
| 94 else: | 97 else: |
| 95 results_iterable = test_run_result.GetAll() | 98 results_iterable = test_run_result.GetAll() |
| 99 base_links.update(test_run_result.GetLinks()) |
| 96 | 100 |
| 97 for r in results_iterable: | 101 for r in results_iterable: |
| 98 result_dict = { | 102 result_dict = { |
| 99 'status': status_as_string(r.GetType()), | 103 'status': status_as_string(r.GetType()), |
| 100 'elapsed_time_ms': r.GetDuration(), | 104 'elapsed_time_ms': r.GetDuration(), |
| 101 'output_snippet': r.GetLog(), | 105 'output_snippet': r.GetLog(), |
| 102 'losless_snippet': '', | 106 'losless_snippet': '', |
| 103 'output_snippet_base64': '', | 107 'output_snippet_base64': '', |
| 104 'tombstones': r.GetTombstonesUrl() or '', | 108 'links': r.GetLinks(), |
| 105 'logcat_url': r.GetLogcatUrl() or '', | |
| 106 } | 109 } |
| 107 iteration_data[r.GetName()].append(result_dict) | 110 iteration_data[r.GetName()].append(result_dict) |
| 108 | 111 |
| 109 all_tests = all_tests.union(set(iteration_data.iterkeys())) | 112 all_tests = all_tests.union(set(iteration_data.iterkeys())) |
| 110 per_iteration_data.append(iteration_data) | 113 per_iteration_data.append(iteration_data) |
| 111 | 114 |
| 112 return { | 115 return { |
| 113 'global_tags': [], | 116 'global_tags': [], |
| 114 'all_tests': sorted(list(all_tests)), | 117 'all_tests': sorted(list(all_tests)), |
| 115 # TODO(jbudorick): Add support for disabled tests within base_test_result. | 118 # TODO(jbudorick): Add support for disabled tests within base_test_result. |
| 116 'disabled_tests': [], | 119 'disabled_tests': [], |
| 117 'per_iteration_data': per_iteration_data, | 120 'per_iteration_data': per_iteration_data, |
| 121 'links': base_links, |
| 118 } | 122 } |
| 119 | 123 |
| 120 | 124 |
| 121 def GenerateJsonResultsFile(test_run_result, file_path): | 125 def GenerateJsonResultsFile(test_run_result, file_path): |
| 122 """Write |test_run_result| to JSON. | 126 """Write |test_run_result| to JSON. |
| 123 | 127 |
| 124 This emulates the format of the JSON emitted by | 128 This emulates the format of the JSON emitted by |
| 125 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. | 129 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
| 126 | 130 |
| 127 Args: | 131 Args: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 158 testsuite_runs = json_results['per_iteration_data'] | 162 testsuite_runs = json_results['per_iteration_data'] |
| 159 for testsuite_run in testsuite_runs: | 163 for testsuite_run in testsuite_runs: |
| 160 for test, test_runs in testsuite_run.iteritems(): | 164 for test, test_runs in testsuite_run.iteritems(): |
| 161 results_list.extend( | 165 results_list.extend( |
| 162 [base_test_result.BaseTestResult(test, | 166 [base_test_result.BaseTestResult(test, |
| 163 string_as_status(tr['status']), | 167 string_as_status(tr['status']), |
| 164 duration=tr['elapsed_time_ms']) | 168 duration=tr['elapsed_time_ms']) |
| 165 for tr in test_runs]) | 169 for tr in test_runs]) |
| 166 return results_list | 170 return results_list |
| 167 | 171 |
| OLD | NEW |