OLD | NEW |
1 import json | 1 import json |
2 | 2 |
3 from recipe_engine import recipe_test_api | 3 from recipe_engine import recipe_test_api |
4 | 4 |
5 from .util import GTestResults, TestResults | 5 from .util import GTestResults, TestResults |
6 | 6 |
7 class TestUtilsTestApi(recipe_test_api.RecipeTestApi): | 7 class TestUtilsTestApi(recipe_test_api.RecipeTestApi): |
8 @recipe_test_api.placeholder_step_data | 8 @recipe_test_api.placeholder_step_data |
9 def test_results(self, test_results, retcode=None): | 9 def test_results(self, test_results, retcode=None): |
10 return self.m.json.output(test_results.as_jsonish(), retcode) | 10 return self.m.json.output(test_results.as_jsonish(), retcode) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 retcode = None if passing else 1 | 106 retcode = None if passing else 1 |
107 return self.raw_gtest_output(canned_jsonish, retcode) | 107 return self.raw_gtest_output(canned_jsonish, retcode) |
108 | 108 |
109 def raw_gtest_output(self, jsonish, retcode): | 109 def raw_gtest_output(self, jsonish, retcode): |
110 t = GTestResults(jsonish) | 110 t = GTestResults(jsonish) |
111 ret = self.gtest_results(t) | 111 ret = self.gtest_results(t) |
112 ret.retcode = retcode | 112 ret.retcode = retcode |
113 return ret | 113 return ret |
114 | 114 |
115 def canned_isolated_script_output(self, passing, is_win, swarming=False, | 115 def generate_simplified_json_results(self, shards, isolated_script_passing, |
116 shards=1, swarming_internal_failure=False, | 116 valid): |
117 isolated_script_passing=True, valid=True, | |
118 missing_shards=[], | |
119 empty_shards=[], | |
120 output_chartjson=False, | |
121 benchmark_enabled=True): | |
122 """Produces a test results' compatible json for isolated script tests. """ | |
123 per_shard_results = [] | 117 per_shard_results = [] |
124 per_shard_chartjson_results = [] | |
125 for i in xrange(shards): | 118 for i in xrange(shards): |
126 jsonish_results = {} | 119 jsonish_results = {} |
127 chartjsonish_results = {} | |
128 jsonish_results['valid'] = valid | 120 jsonish_results['valid'] = valid |
129 # Keep shard 0's results equivalent to the old code to minimize | 121 # Keep shard 0's results equivalent to the old code to minimize |
130 # expectation diffs. | 122 # expectation diffs. |
131 idx = 1 + (2 * i) | 123 idx = 1 + (2 * i) |
132 tests_run = ['test%d.Test%d' % (idx, idx), | 124 tests_run = ['test%d.Test%d' % (idx, idx), |
133 'test%d.Test%d' % (idx + 1, idx + 1)] | 125 'test%d.Test%d' % (idx + 1, idx + 1)] |
134 if isolated_script_passing: | 126 if isolated_script_passing: |
135 jsonish_results['failures'] = [] | 127 jsonish_results['failures'] = [] |
136 jsonish_results['successes'] = tests_run | 128 jsonish_results['successes'] = tests_run |
137 else: | 129 else: |
138 jsonish_results['failures'] = tests_run | 130 jsonish_results['failures'] = tests_run |
139 jsonish_results['successes'] = [] | 131 jsonish_results['successes'] = [] |
140 jsonish_results['times'] = {t : 0.1 for t in tests_run} | 132 jsonish_results['times'] = {t : 0.1 for t in tests_run} |
| 133 per_shard_results.append(jsonish_results) |
| 134 return per_shard_results |
| 135 |
| 136 def generate_json_test_results(self, shards, isolated_script_passing, |
| 137 valid): |
| 138 per_shard_results = [] |
| 139 for i in xrange(shards): |
| 140 jsonish_results = { |
| 141 'interrupted': False, |
| 142 'path_delimiter': '.', |
| 143 'version': 3, |
| 144 'seconds_since_epoch': 14000000 + i, |
| 145 'num_failures_by_type': { |
| 146 'FAIL': 0, |
| 147 'PASS': 0 |
| 148 } |
| 149 } |
| 150 if not valid: |
| 151 del jsonish_results['path_delimiter'] |
| 152 idx = 1 + (2 * i) |
| 153 if isolated_script_passing: |
| 154 tests_run = { |
| 155 'test_common': { |
| 156 'Test%d' % idx: { |
| 157 'expected': 'PASS', |
| 158 'actual': 'PASS', |
| 159 }, |
| 160 }, |
| 161 'test%d' % idx: { |
| 162 'Test%d' % idx: { |
| 163 'expected': 'PASS', |
| 164 'actual': 'PASS', |
| 165 }, |
| 166 'Test%d' % (idx + 1): { |
| 167 'expected': 'FAIL', |
| 168 'actual': 'FAIL', |
| 169 }, |
| 170 } |
| 171 } |
| 172 jsonish_results['num_failures_by_type']['PASS'] = 2 |
| 173 else: |
| 174 tests_run = { |
| 175 'test%d' % idx: { |
| 176 'Test%d' % idx: { |
| 177 'expected': 'FAIL', |
| 178 'actual': 'PASS', |
| 179 }, |
| 180 'Test%d' % (idx + 1): { |
| 181 'expected': 'PASS', |
| 182 'actual': 'FAIL', |
| 183 }, |
| 184 } |
| 185 } |
| 186 |
| 187 jsonish_results['num_failures_by_type']['FAIL'] = 2 |
| 188 jsonish_results['tests'] = tests_run |
| 189 per_shard_results.append(jsonish_results) |
| 190 return per_shard_results |
| 191 |
| 192 def canned_isolated_script_output(self, passing, is_win, swarming=False, |
| 193 shards=1, swarming_internal_failure=False, |
| 194 isolated_script_passing=True, valid=True, |
| 195 missing_shards=[], |
| 196 empty_shards=[], |
| 197 output_chartjson=False, |
| 198 use_json_test_format=False, |
| 199 benchmark_enabled=True): |
| 200 """Produces a test results' compatible json for isolated script tests. """ |
| 201 per_shard_results = [] |
| 202 per_shard_chartjson_results = [] |
| 203 for i in xrange(shards): |
| 204 chartjsonish_results = {} |
| 205 idx = 1 + (2 * i) |
141 chartjsonish_results['dummy'] = 'dummy%d' % i | 206 chartjsonish_results['dummy'] = 'dummy%d' % i |
142 chartjsonish_results['enabled'] = benchmark_enabled | 207 chartjsonish_results['enabled'] = benchmark_enabled |
143 chartjsonish_results['charts'] = {'entry%d' % idx: 'chart%d' % idx, | 208 chartjsonish_results['charts'] = {'entry%d' % idx: 'chart%d' % idx, |
144 'entry%d' % (idx + 1): 'chart%d' % (idx + 1)} | 209 'entry%d' % (idx + 1): 'chart%d' % (idx + 1)} |
145 per_shard_results.append(jsonish_results) | |
146 per_shard_chartjson_results.append(chartjsonish_results) | 210 per_shard_chartjson_results.append(chartjsonish_results) |
| 211 if use_json_test_format: |
| 212 per_shard_results = self.generate_json_test_results( |
| 213 shards, isolated_script_passing, valid) |
| 214 else: |
| 215 per_shard_results = self.generate_simplified_json_results( |
| 216 shards, isolated_script_passing, valid) |
147 if swarming: | 217 if swarming: |
148 jsonish_shards = [] | 218 jsonish_shards = [] |
149 files_dict = {} | 219 files_dict = {} |
150 for i in xrange(shards): | 220 for i in xrange(shards): |
151 jsonish_shards.append({ | 221 jsonish_shards.append({ |
152 'failure': not passing, | 222 'failure': not passing, |
153 'internal_failure': swarming_internal_failure, | 223 'internal_failure': swarming_internal_failure, |
154 'exit_code': '1' if not passing or swarming_internal_failure else '0' | 224 'exit_code': '1' if not passing or swarming_internal_failure else '0' |
155 }) | 225 }) |
156 swarming_path = str(i) | 226 swarming_path = str(i) |
(...skipping 16 matching lines...) Expand all Loading... |
173 if not chartjson_output_missing and output_chartjson: | 243 if not chartjson_output_missing and output_chartjson: |
174 files_dict[chartjson_swarming_path] = \ | 244 files_dict[chartjson_swarming_path] = \ |
175 '' if chartjson_output_empty \ | 245 '' if chartjson_output_empty \ |
176 else json.dumps(per_shard_chartjson_results[i]) | 246 else json.dumps(per_shard_chartjson_results[i]) |
177 | 247 |
178 jsonish_summary = {'shards': jsonish_shards} | 248 jsonish_summary = {'shards': jsonish_shards} |
179 files_dict['summary.json'] = json.dumps(jsonish_summary) | 249 files_dict['summary.json'] = json.dumps(jsonish_summary) |
180 return self.m.raw_io.output_dir(files_dict) | 250 return self.m.raw_io.output_dir(files_dict) |
181 else: | 251 else: |
182 return self.m.json.output(per_shard_results[0]) | 252 return self.m.json.output(per_shard_results[0]) |
OLD | NEW |