OLD | NEW |
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 contextlib | 5 import contextlib |
6 import copy | 6 import copy |
| 7 import itertools |
7 import json | 8 import json |
8 | 9 |
9 from infra.libs.infra_types import freeze, thaw | 10 from recipe_engine.types import freeze |
10 from recipe_engine import recipe_api | 11 from recipe_engine import recipe_api |
11 from recipe_engine import util as recipe_util | 12 from recipe_engine import util as recipe_util |
12 | 13 |
13 from . import builders | 14 from . import builders |
14 from . import steps | 15 from . import steps |
15 | 16 |
16 | 17 |
17 class ChromiumTestsApi(recipe_api.RecipeApi): | 18 class ChromiumTestsApi(recipe_api.RecipeApi): |
18 def __init__(self, *args, **kwargs): | 19 def __init__(self, *args, **kwargs): |
19 super(ChromiumTestsApi, self).__init__(*args, **kwargs) | 20 super(ChromiumTestsApi, self).__init__(*args, **kwargs) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 test_spec_file = bot_config.get('testing', {}).get( | 147 test_spec_file = bot_config.get('testing', {}).get( |
147 'test_spec_file', '%s.json' % mastername) | 148 'test_spec_file', '%s.json' % mastername) |
148 | 149 |
149 # TODO(phajdan.jr): Bots should have no generators instead. | 150 # TODO(phajdan.jr): Bots should have no generators instead. |
150 if bot_config.get('disable_tests'): | 151 if bot_config.get('disable_tests'): |
151 return {} | 152 return {} |
152 return self.read_test_spec(self.m, test_spec_file) | 153 return self.read_test_spec(self.m, test_spec_file) |
153 | 154 |
154 def get_master_dict_with_dynamic_tests( | 155 def get_master_dict_with_dynamic_tests( |
155 self, mastername, buildername, test_spec, scripts_compile_targets): | 156 self, mastername, buildername, test_spec, scripts_compile_targets): |
156 # Make an independent copy so that we don't overwrite global state | 157 # We manually thaw the path to the elements we are modifying, since the |
157 # with updates made dynamically based on the test specs. | 158 # builders are frozen. |
158 master_dict = thaw(self.builders.get(mastername, {})) | 159 master_dict = dict(self.builders[mastername]) |
159 bot_config = master_dict.get('builders', {}).get(buildername) | 160 builders = master_dict['builders'] = dict(master_dict['builders']) |
160 | 161 bot_config = builders[buildername] |
161 for loop_buildername, builder_dict in master_dict.get( | 162 for loop_buildername in builders: |
162 'builders', {}).iteritems(): | 163 builder_dict = builders[loop_buildername] = ( |
163 builder_dict['tests'] = self.generate_tests_from_test_spec( | 164 dict(builders[loop_buildername])) |
164 self.m, test_spec, builder_dict, | 165 builders[loop_buildername]['tests'] = ( |
165 loop_buildername, mastername, | 166 self.generate_tests_from_test_spec( |
166 # TODO(phajdan.jr): Get enable_swarming value from builder_dict. | 167 self.m, test_spec, builder_dict, loop_buildername, mastername, |
167 # Above should remove the need to get bot_config and buildername | 168 # TODO(phajdan.jr): Get enable_swarming value from builder_dict. |
168 # in this method. | 169 # Above should remove the need to get bot_config and buildername |
169 bot_config.get('enable_swarming', False), | 170 # in this method. |
170 scripts_compile_targets, builder_dict.get('test_generators', [])) | 171 bot_config.get('enable_swarming', False), |
| 172 scripts_compile_targets, builder_dict.get('test_generators', []) |
| 173 )) |
171 | 174 |
172 return freeze(master_dict) | 175 return freeze(master_dict) |
173 | 176 |
174 def prepare_checkout(self, mastername, buildername): | 177 def prepare_checkout(self, mastername, buildername): |
175 bot_config = self.get_bot_config(mastername, buildername) | 178 bot_config = self.get_bot_config(mastername, buildername) |
176 | 179 |
177 update_step = self.ensure_checkout(mastername, buildername) | 180 update_step = self.ensure_checkout(mastername, buildername) |
178 | 181 |
179 self.set_up_swarming(mastername, buildername) | 182 self.set_up_swarming(mastername, buildername) |
180 self.runhooks(mastername, buildername, update_step) | 183 self.runhooks(mastername, buildername, update_step) |
(...skipping 11 matching lines...) Expand all Loading... |
192 mastername, buildername, test_spec, scripts_compile_targets) | 195 mastername, buildername, test_spec, scripts_compile_targets) |
193 | 196 |
194 if self.m.chromium.c.lto: | 197 if self.m.chromium.c.lto: |
195 self.m.chromium.download_lto_plugin() | 198 self.m.chromium.download_lto_plugin() |
196 | 199 |
197 return update_step, master_dict, test_spec | 200 return update_step, master_dict, test_spec |
198 | 201 |
199 def generate_tests_from_test_spec(self, api, test_spec, builder_dict, | 202 def generate_tests_from_test_spec(self, api, test_spec, builder_dict, |
200 buildername, mastername, enable_swarming, scripts_compile_targets, | 203 buildername, mastername, enable_swarming, scripts_compile_targets, |
201 generators): | 204 generators): |
202 tests = builder_dict.get('tests', []) | 205 tests = builder_dict.get('tests', ()) |
203 # TODO(phajdan.jr): Switch everything to scripts generators and simplify. | 206 # TODO(phajdan.jr): Switch everything to scripts generators and simplify. |
204 for generator in generators: | 207 for generator in generators: |
205 tests = ( | 208 tests = ( |
206 list(generator(api, mastername, buildername, test_spec, | 209 tuple(generator(api, mastername, buildername, test_spec, |
207 enable_swarming=enable_swarming, | 210 enable_swarming=enable_swarming, |
208 scripts_compile_targets=scripts_compile_targets)) + | 211 scripts_compile_targets=scripts_compile_targets)) + |
209 tests) | 212 tests) |
210 return tests | 213 return tests |
211 | 214 |
212 def read_test_spec(self, api, test_spec_file): | 215 def read_test_spec(self, api, test_spec_file): |
213 test_spec_path = api.path['checkout'].join('testing', 'buildbot', | 216 test_spec_path = api.path['checkout'].join('testing', 'buildbot', |
214 test_spec_file) | 217 test_spec_file) |
215 test_spec_result = api.json.read( | 218 test_spec_result = api.json.read( |
216 'read test spec', | 219 'read test spec', |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 self.m.gclient.c.revisions[solution] = str( | 547 self.m.gclient.c.revisions[solution] = str( |
545 bot_update_json['properties'][revision]) | 548 bot_update_json['properties'][revision]) |
546 self.m.bot_update.ensure_checkout( | 549 self.m.bot_update.ensure_checkout( |
547 force=True, patch=False, update_presentation=False) | 550 force=True, patch=False, update_presentation=False) |
548 self.m.chromium.runhooks(name='runhooks (without patch)') | 551 self.m.chromium.runhooks(name='runhooks (without patch)') |
549 | 552 |
550 def run_tests_and_deapply_as_needed(self, mastername, api, tests, | 553 def run_tests_and_deapply_as_needed(self, mastername, api, tests, |
551 bot_update_step): | 554 bot_update_step): |
552 def deapply_patch_fn(failing_tests): | 555 def deapply_patch_fn(failing_tests): |
553 self.deapply_patch(bot_update_step) | 556 self.deapply_patch(bot_update_step) |
554 compile_targets = list(self.m.itertools.chain( | 557 compile_targets = list(itertools.chain( |
555 *[t.compile_targets(api) for t in failing_tests])) | 558 *[t.compile_targets(api) for t in failing_tests])) |
556 if compile_targets: | 559 if compile_targets: |
557 # Remove duplicate targets. | 560 # Remove duplicate targets. |
558 compile_targets = sorted(set(compile_targets)) | 561 compile_targets = sorted(set(compile_targets)) |
559 failing_swarming_tests = [ | 562 failing_swarming_tests = [ |
560 t.isolate_target for t in failing_tests if t.uses_swarming] | 563 t.isolate_target for t in failing_tests if t.uses_swarming] |
561 if failing_swarming_tests: | 564 if failing_swarming_tests: |
562 self.m.isolate.clean_isolated_files(self.m.chromium.output_dir) | 565 self.m.isolate.clean_isolated_files(self.m.chromium.output_dir) |
563 self.run_mb_and_compile(compile_targets, failing_swarming_tests, | 566 self.run_mb_and_compile(compile_targets, failing_swarming_tests, |
564 ' (without patch)') | 567 ' (without patch)') |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 def get_compile_targets_for_scripts(self): | 755 def get_compile_targets_for_scripts(self): |
753 return self.m.python( | 756 return self.m.python( |
754 name='get compile targets for scripts', | 757 name='get compile targets for scripts', |
755 script=self.m.path['checkout'].join( | 758 script=self.m.path['checkout'].join( |
756 'testing', 'scripts', 'get_compile_targets.py'), | 759 'testing', 'scripts', 'get_compile_targets.py'), |
757 args=[ | 760 args=[ |
758 '--output', self.m.json.output(), | 761 '--output', self.m.json.output(), |
759 '--', | 762 '--', |
760 ] + self.get_common_args_for_scripts(), | 763 ] + self.get_common_args_for_scripts(), |
761 step_test_data=lambda: self.m.json.test_api.output({})) | 764 step_test_data=lambda: self.m.json.test_api.output({})) |
OLD | NEW |