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

Side by Side Diff: build/android/pylib/results/json_results.py

Issue 1376483002: [Android] Add --repeat for gtests and instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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 6
7 from pylib.base import base_test_result 7 from pylib.base import base_test_result
8 8
9 9
10 def GenerateResultsDict(test_run_result): 10 def GenerateResultsDict(test_run_results):
11 """Create a results dict from |test_run_result| suitable for writing to JSON. 11 """Create a results dict from |test_run_results| suitable for writing to JSON.
12 Args: 12 Args:
13 test_run_result: a base_test_result.TestRunResults object. 13 test_run_results: a list of base_test_result.TestRunResults objects.
14 Returns: 14 Returns:
15 A results dict that mirrors the one generated by 15 A results dict that mirrors the one generated by
16 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. 16 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON.
17 """ 17 """
18 # Example json output. 18 # Example json output.
19 # { 19 # {
20 # "global_tags": [], 20 # "global_tags": [],
21 # "all_tests": [ 21 # "all_tests": [
22 # "test1", 22 # "test1",
23 # "test2", 23 # "test2",
(...skipping 13 matching lines...) Expand all
37 # "test2": [ 37 # "test2": [
38 # { 38 # {
39 # "status": "FAILURE", 39 # "status": "FAILURE",
40 # "elapsed_time_ms": 12, 40 # "elapsed_time_ms": 12,
41 # "output_snippet": "", 41 # "output_snippet": "",
42 # "output_snippet_base64": "", 42 # "output_snippet_base64": "",
43 # "losless_snippet": "", 43 # "losless_snippet": "",
44 # }, 44 # },
45 # ], 45 # ],
46 # }, 46 # },
47 # {
48 # "test1": [
49 # {
50 # "status": "SUCCESS",
51 # "elapsed_time_ms": 1,
52 # "output_snippet": "",
53 # "output_snippet_base64": "",
54 # "losless_snippet": "",
55 # },
56 # ],
57 # "test2": [
58 # {
59 # "status": "FAILURE",
60 # "elapsed_time_ms": 12,
61 # "output_snippet": "",
62 # "output_snippet_base64": "",
63 # "losless_snippet": "",
64 # },
65 # ],
66 # },
67 # ...
47 # ], 68 # ],
48 # } 69 # }
49 70
50 assert isinstance(test_run_result, base_test_result.TestRunResults)
51
52 def status_as_string(s): 71 def status_as_string(s):
53 if s == base_test_result.ResultType.PASS: 72 if s == base_test_result.ResultType.PASS:
54 return 'SUCCESS' 73 return 'SUCCESS'
55 elif s == base_test_result.ResultType.SKIP: 74 elif s == base_test_result.ResultType.SKIP:
56 return 'SKIPPED' 75 return 'SKIPPED'
57 elif s == base_test_result.ResultType.FAIL: 76 elif s == base_test_result.ResultType.FAIL:
58 return 'FAILURE' 77 return 'FAILURE'
59 elif s == base_test_result.ResultType.CRASH: 78 elif s == base_test_result.ResultType.CRASH:
60 return 'CRASH' 79 return 'CRASH'
61 elif s == base_test_result.ResultType.TIMEOUT: 80 elif s == base_test_result.ResultType.TIMEOUT:
62 return 'TIMEOUT' 81 return 'TIMEOUT'
63 elif s == base_test_result.ResultType.UNKNOWN: 82 elif s == base_test_result.ResultType.UNKNOWN:
64 return 'UNKNOWN' 83 return 'UNKNOWN'
65 84
66 def generate_iteration_data(t): 85 all_tests = set()
67 return { 86 per_iteration_data = []
68 t.GetName(): [ 87 for test_run_result in test_run_results:
69 { 88 iteration_data = {
70 'status': status_as_string(t.GetType()), 89 t.GetName(): [{
71 'elapsed_time_ms': t.GetDuration(), 90 'status': status_as_string(t.GetType()),
72 'output_snippet': '', 91 'elapsed_time_ms': t.GetDuration(),
73 'losless_snippet': '', 92 'output_snippet': '',
74 'output_snippet_base64:': '', 93 'losless_snippet': '',
75 } 94 'output_snippet_base64:': '',
76 ] 95 }]
96 for t in test_run_result.GetAll()
77 } 97 }
78 98 all_tests = all_tests.union(set(iteration_data.iterkeys()))
79 all_tests_tuple, per_iteration_data_tuple = zip( 99 per_iteration_data.append(iteration_data)
80 *[(t.GetName(), generate_iteration_data(t))
81 for t in test_run_result.GetAll()])
82 100
83 return { 101 return {
84 'global_tags': [], 102 'global_tags': [],
85 'all_tests': list(all_tests_tuple), 103 'all_tests': sorted(list(all_tests)),
86 # TODO(jbudorick): Add support for disabled tests within base_test_result. 104 # TODO(jbudorick): Add support for disabled tests within base_test_result.
87 'disabled_tests': [], 105 'disabled_tests': [],
88 'per_iteration_data': list(per_iteration_data_tuple), 106 'per_iteration_data': per_iteration_data,
89 } 107 }
90 108
91 109
92 def GenerateJsonResultsFile(test_run_result, file_path): 110 def GenerateJsonResultsFile(test_run_result, file_path):
93 """Write |test_run_result| to JSON. 111 """Write |test_run_result| to JSON.
94 112
95 This emulates the format of the JSON emitted by 113 This emulates the format of the JSON emitted by
96 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. 114 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON.
97 115
98 Args: 116 Args:
(...skipping 30 matching lines...) Expand all
129 testsuite_runs = json_results['per_iteration_data'] 147 testsuite_runs = json_results['per_iteration_data']
130 for testsuite_run in testsuite_runs: 148 for testsuite_run in testsuite_runs:
131 for test, test_runs in testsuite_run.iteritems(): 149 for test, test_runs in testsuite_run.iteritems():
132 results_list.extend( 150 results_list.extend(
133 [base_test_result.BaseTestResult(test, 151 [base_test_result.BaseTestResult(test,
134 string_as_status(tr['status']), 152 string_as_status(tr['status']),
135 duration=tr['elapsed_time_ms']) 153 duration=tr['elapsed_time_ms'])
136 for tr in test_runs]) 154 for tr in test_runs])
137 return results_list 155 return results_list
138 156
OLDNEW
« no previous file with comments | « build/android/pylib/base/test_dispatcher.py ('k') | build/android/pylib/results/json_results_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698