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