Index: build/android/pylib/results/json_results.py |
diff --git a/build/android/pylib/results/json_results.py b/build/android/pylib/results/json_results.py |
index c34244e324952518e3f6ec14ce2b9b63ca15ac1c..65664e3da097eca45d0e0614356ad3db617a3d91 100644 |
--- a/build/android/pylib/results/json_results.py |
+++ b/build/android/pylib/results/json_results.py |
@@ -16,6 +16,38 @@ def GenerateResultsDict(test_run_result): |
A results dict that mirrors the one generated by |
base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
""" |
+ # Example json output. |
+ # { |
+ # "global_tags": [], |
+ # "all_tests": [ |
+ # "test1", |
+ # "test2", |
+ # ], |
+ # "disabled_tests": [], |
+ # "per_iteration_data": [ |
+ # { |
+ # "test1": [ |
+ # { |
+ # "status": "SUCCESS", |
+ # "elapsed_time_ms": 1, |
+ # "output_snippet": "", |
+ # "output_snippet_base64": "", |
+ # "losless_snippet": "", |
+ # }, |
+ # ], |
+ # "test2": [ |
+ # { |
+ # "status": "FAILURE", |
+ # "elapsed_time_ms": 12, |
+ # "output_snippet": "", |
+ # "output_snippet_base64": "", |
+ # "losless_snippet": "", |
+ # }, |
+ # ], |
+ # }, |
+ # ], |
+ # } |
+ |
assert isinstance(test_run_result, base_test_result.TestRunResults) |
def status_as_string(s): |
@@ -71,3 +103,37 @@ def GenerateJsonResultsFile(test_run_result, file_path): |
with open(file_path, 'w') as json_result_file: |
json_result_file.write(json.dumps(GenerateResultsDict(test_run_result))) |
+ |
+def ParseResultsFromJson(json_results): |
+ """Creates a list of BaseTestResult objects from JSON. |
+ |
+ Args: |
+ json_results: A JSON dict in the format created by |
+ GenerateJsonResultsFile. |
+ """ |
+ |
+ def string_as_status(s): |
+ if s == 'SUCCESS': |
+ return base_test_result.ResultType.PASS |
+ elif s == 'SKIPPED': |
+ return base_test_result.ResultType.SKIP |
+ elif s == 'FAILURE': |
+ return base_test_result.ResultType.FAIL |
+ elif s == 'CRASH': |
+ return base_test_result.ResultType.CRASH |
+ elif s == 'TIMEOUT': |
+ return base_test_result.ResultType.TIMEOUT |
+ else: |
+ return base_test_result.ResultType.UNKNOWN |
+ |
+ results_list = [] |
+ testsuite_runs = json_results['per_iteration_data'] |
+ for testsuite_run in testsuite_runs: |
+ for test, test_runs in testsuite_run.iteritems(): |
+ results_list.extend( |
+ [base_test_result.BaseTestResult(test, |
+ string_as_status(tr['status']), |
+ duration=tr['elapsed_time_ms']) |
+ for tr in test_runs]) |
+ return results_list |
+ |