Chromium Code Reviews| 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 from pylib.instrumentation import test_result | |
| 10 | 11 |
| 11 | 12 |
| 12 def GenerateResultsDict(test_run_results): | 13 def GenerateResultsDict(test_run_results): |
| 13 """Create a results dict from |test_run_results| suitable for writing to JSON. | 14 """Create a results dict from |test_run_results| suitable for writing to JSON. |
| 14 Args: | 15 Args: |
| 15 test_run_results: a list of base_test_result.TestRunResults objects. | 16 test_run_results: a list of base_test_result.TestRunResults objects. |
| 16 Returns: | 17 Returns: |
| 17 A results dict that mirrors the one generated by | 18 A results dict that mirrors the one generated by |
| 18 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. | 19 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
| 19 """ | 20 """ |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 all_tests = set() | 90 all_tests = set() |
| 90 per_iteration_data = [] | 91 per_iteration_data = [] |
| 91 for test_run_result in test_run_results: | 92 for test_run_result in test_run_results: |
| 92 iteration_data = collections.defaultdict(list) | 93 iteration_data = collections.defaultdict(list) |
| 93 if isinstance(test_run_result, list): | 94 if isinstance(test_run_result, list): |
| 94 results_iterable = itertools.chain(*(t.GetAll() for t in test_run_result)) | 95 results_iterable = itertools.chain(*(t.GetAll() for t in test_run_result)) |
| 95 else: | 96 else: |
| 96 results_iterable = test_run_result.GetAll() | 97 results_iterable = test_run_result.GetAll() |
| 97 | 98 |
| 98 for r in results_iterable: | 99 for r in results_iterable: |
| 99 iteration_data[r.GetName()].append({ | 100 result_dict = { |
| 100 'status': status_as_string(r.GetType()), | 101 'status': status_as_string(r.GetType()), |
| 101 'elapsed_time_ms': r.GetDuration(), | 102 'elapsed_time_ms': r.GetDuration(), |
| 102 'output_snippet': r.GetLog(), | 103 'output_snippet': r.GetLog(), |
| 103 'losless_snippet': '', | 104 'losless_snippet': '', |
| 104 'output_snippet_base64:': '', | 105 'output_snippet_base64:': '',} |
|
jbudorick
2016/08/17 04:14:30
Move the } back down, please.
BigBossZhiling
2016/08/17 23:20:03
Done.
| |
| 105 }) | 106 if type(r) == test_result.InstrumentationTestResult: |
|
jbudorick
2016/08/17 04:14:30
We shouldn't be querying the derived type. If you
BigBossZhiling
2016/08/17 23:20:03
Done.
| |
| 107 result_dict['tombstones'] = r.GetTombstones() | |
| 108 iteration_data[r.GetName()].append(result_dict) | |
| 106 | 109 |
| 107 all_tests = all_tests.union(set(iteration_data.iterkeys())) | 110 all_tests = all_tests.union(set(iteration_data.iterkeys())) |
| 108 per_iteration_data.append(iteration_data) | 111 per_iteration_data.append(iteration_data) |
| 109 | 112 |
| 110 return { | 113 return { |
| 111 'global_tags': [], | 114 'global_tags': [], |
| 112 'all_tests': sorted(list(all_tests)), | 115 'all_tests': sorted(list(all_tests)), |
| 113 # TODO(jbudorick): Add support for disabled tests within base_test_result. | 116 # TODO(jbudorick): Add support for disabled tests within base_test_result. |
| 114 'disabled_tests': [], | 117 'disabled_tests': [], |
| 115 'per_iteration_data': per_iteration_data, | 118 'per_iteration_data': per_iteration_data, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 testsuite_runs = json_results['per_iteration_data'] | 159 testsuite_runs = json_results['per_iteration_data'] |
| 157 for testsuite_run in testsuite_runs: | 160 for testsuite_run in testsuite_runs: |
| 158 for test, test_runs in testsuite_run.iteritems(): | 161 for test, test_runs in testsuite_run.iteritems(): |
| 159 results_list.extend( | 162 results_list.extend( |
| 160 [base_test_result.BaseTestResult(test, | 163 [base_test_result.BaseTestResult(test, |
| 161 string_as_status(tr['status']), | 164 string_as_status(tr['status']), |
| 162 duration=tr['elapsed_time_ms']) | 165 duration=tr['elapsed_time_ms']) |
| 163 for tr in test_runs]) | 166 for tr in test_runs]) |
| 164 return results_list | 167 return results_list |
| 165 | 168 |
| OLD | NEW |