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

Side by Side 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: Rebase and addressed nyquist's comment. Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « build/android/pylib/junit/test_runner.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 json 5 import json
6 import logging 6 import logging
7 7
8 from pylib.base import base_test_result 8 from pylib.base import base_test_result
9 9
10 10
11 def GenerateResultsDict(test_run_result): 11 def GenerateResultsDict(test_run_result):
12 """Create a results dict from |test_run_result| suitable for writing to JSON. 12 """Create a results dict from |test_run_result| suitable for writing to JSON.
13 Args: 13 Args:
14 test_run_result: a base_test_result.TestRunResults object. 14 test_run_result: a base_test_result.TestRunResults object.
15 Returns: 15 Returns:
16 A results dict that mirrors the one generated by 16 A results dict that mirrors the one generated by
17 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. 17 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON.
18 """ 18 """
19 # Example json output.
20 # {
21 # "global_tags": [],
22 # "all_tests": [
23 # "test1",
24 # "test2",
25 # ],
26 # "disabled_tests": [],
27 # "per_iteration_data": [
28 # {
29 # "test1": [
30 # {
31 # "status": "SUCCESS",
32 # "elapsed_time_ms": 1,
33 # "output_snippet": "",
34 # "output_snippet_base64": "",
35 # "losless_snippet": "",
36 # },
37 # ],
38 # "test2": [
39 # {
40 # "status": "FAILURE",
41 # "elapsed_time_ms": 12,
42 # "output_snippet": "",
43 # "output_snippet_base64": "",
44 # "losless_snippet": "",
45 # },
46 # ],
47 # },
48 # ],
49 # }
50
19 assert isinstance(test_run_result, base_test_result.TestRunResults) 51 assert isinstance(test_run_result, base_test_result.TestRunResults)
20 52
21 def status_as_string(s): 53 def status_as_string(s):
22 if s == base_test_result.ResultType.PASS: 54 if s == base_test_result.ResultType.PASS:
23 return 'SUCCESS' 55 return 'SUCCESS'
24 elif s == base_test_result.ResultType.SKIP: 56 elif s == base_test_result.ResultType.SKIP:
25 return 'SKIPPED' 57 return 'SKIPPED'
26 elif s == base_test_result.ResultType.FAIL: 58 elif s == base_test_result.ResultType.FAIL:
27 return 'FAILURE' 59 return 'FAILURE'
28 elif s == base_test_result.ResultType.CRASH: 60 elif s == base_test_result.ResultType.CRASH:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 This emulates the format of the JSON emitted by 96 This emulates the format of the JSON emitted by
65 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. 97 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON.
66 98
67 Args: 99 Args:
68 test_run_result: a base_test_result.TestRunResults object. 100 test_run_result: a base_test_result.TestRunResults object.
69 file_path: The path to the JSON file to write. 101 file_path: The path to the JSON file to write.
70 """ 102 """
71 with open(file_path, 'w') as json_result_file: 103 with open(file_path, 'w') as json_result_file:
72 json_result_file.write(json.dumps(GenerateResultsDict(test_run_result))) 104 json_result_file.write(json.dumps(GenerateResultsDict(test_run_result)))
73 105
106
107 def ParseResultsFromJson(json_results):
108 """Creates a list of BaseTestResult objects from JSON.
109
110 Args:
111 json_results: A JSON dict in the format created by
112 GenerateJsonResultsFile.
113 """
114
115 def string_as_status(s):
116 if s == 'SUCCESS':
117 return base_test_result.ResultType.PASS
118 elif s == 'SKIPPED':
119 return base_test_result.ResultType.SKIP
120 elif s == 'FAILURE':
121 return base_test_result.ResultType.FAIL
122 elif s == 'CRASH':
123 return base_test_result.ResultType.CRASH
124 elif s == 'TIMEOUT':
125 return base_test_result.ResultType.TIMEOUT
126 else:
127 return base_test_result.ResultType.UNKNOWN
128
129 results_list = []
130 testsuite_runs = json_results['per_iteration_data']
131 for testsuite_run in testsuite_runs:
132 for test, test_runs in testsuite_run.iteritems():
133 results_list.extend(
134 [base_test_result.BaseTestResult(test,
135 string_as_status(tr['status']),
136 duration=tr['elapsed_time_ms'])
137 for tr in test_runs])
138 return results_list
139
OLDNEW
« no previous file with comments | « build/android/pylib/junit/test_runner.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698