Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2102)

Unified Diff: build/android/pylib/results/json_results.py

Issue 1003463002: Add json output to Junit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bdac35b13130cdeeceadaa31cccfc39f546af3c2 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": "".
jbudorick 2015/03/12 19:41:49 nit: .?
mikecase (-- gone --) 2015/03/13 01:07:23 Done.
+ # },
+ # ],
+ # "test2": [
+ # {
+ # "status": "FAILURE",
+ # "elapsed_time_ms": 12,
+ # "output_snippet": "",
+ # "output_snippet_base64": "",
+ # "losless_snippet": "".
jbudorick 2015/03/12 19:41:49 nit: .?
mikecase (-- gone --) 2015/03/13 01:07:23 Done.
+ # },
+ # ],
+ # },
+ # ],
+ # }
+
assert isinstance(test_run_result, base_test_result.TestRunResults)
def status_as_string(s):
@@ -71,3 +103,39 @@ 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
+ elif s == 'UNKNOWN':
jbudorick 2015/03/12 19:41:49 This should just be an else case.
mikecase (-- gone --) 2015/03/13 01:07:23 Done.
+ return base_test_result.ResultType.UNKNOWN
+
+ results_list = []
+ testsuite_runs = json_results['per_iteration_data']
+ for testsuite_run in testsuite_runs:
+ for test in testsuite_run:
jbudorick 2015/03/12 19:41:49 for test, test_runs in testsuite_run.iteritems():
mikecase (-- gone --) 2015/03/13 01:07:23 Done.
+ test_runs = testsuite_run[test]
+ for test_run in test_runs:
+ name = test
jbudorick 2015/03/12 19:41:49 Why does this exist?
mikecase (-- gone --) 2015/03/13 01:07:23 Done.
+ test_type = string_as_status(test_run['status'])
+ duration_ms = test_run['elapsed_time_ms']
+ results_list.append(base_test_result.BaseTestResult(
+ name, test_type, duration=duration_ms))
+ return results_list
+

Powered by Google App Engine
This is Rietveld 408576698