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 from slave import recipe_api | 5 from slave import recipe_api |
6 | 6 |
| 7 ISOLATE_SERVER = 'https://isolateserver.appspot.com' |
| 8 |
7 class IsolateApi(recipe_api.RecipeApi): | 9 class IsolateApi(recipe_api.RecipeApi): |
8 """APIs for interacting with isolates.""" | 10 """APIs for interacting with isolates.""" |
9 | 11 |
| 12 def __init__(self, **kwargs): |
| 13 super(IsolateApi, self).__init__(**kwargs) |
| 14 self._manifest_hashes = {} |
| 15 |
| 16 def set_isolate_environment(self, config): |
| 17 """Modifies the passed Config (which should generally be api.chromium.c) |
| 18 to set up the appropriate GYP_DEFINES to upload isolates to the isolate |
| 19 server during the build. This must be called early in your recipe; |
| 20 definitely before the checkout and runhooks steps.""" |
| 21 assert config.gyp_env.GYP_DEFINES['component'] != 'shared_library', ( |
| 22 "isolates don't work with the component build yet; see crbug.com/333473") |
| 23 config.gyp_env.GYP_DEFINES['test_isolation_mode'] = 'hashtable' |
| 24 config.gyp_env.GYP_DEFINES['test_isolation_outdir'] = ISOLATE_SERVER |
| 25 |
10 @recipe_api.inject_test_data | 26 @recipe_api.inject_test_data |
11 def manifest_to_hash(self, targets): | 27 def manifest_to_hash(self, targets): |
12 """Returns a step which runs manifest_to_hash.py against the given array | 28 """Returns a step which runs manifest_to_hash.py against the given array |
13 of targets. Assigns the result to the swarm_hashes factory property. | 29 of targets. Assigns the result to the swarm_hashes factory property. |
14 (This implies this step can currently only be run once per recipe.)""" | 30 (This implies this step can currently only be run once per recipe.)""" |
15 def followup_fn(step_result): | 31 def followup_fn(step_result): |
| 32 self._manifest_hashes = step_result.json.output |
16 step_result.presentation.properties['swarm_hashes'] = ( | 33 step_result.presentation.properties['swarm_hashes'] = ( |
17 step_result.json.output) | 34 self._manifest_hashes) |
18 return self.m.python( | 35 return self.m.python( |
19 'manifest_to_hash', | 36 'manifest_to_hash', |
20 self.m.path.build('scripts', 'slave', 'swarming', 'manifest_to_hash.py'), | 37 self.m.path.build('scripts', 'slave', 'swarming', 'manifest_to_hash.py'), |
21 ['--target', self.m.chromium.c.build_config_fs, | 38 ['--target', self.m.chromium.c.build_config_fs, |
22 '--output-json', self.m.json.output(), | 39 '--output-json', self.m.json.output(), |
23 ] + targets, | 40 ] + targets, |
24 followup_fn=followup_fn) | 41 followup_fn=followup_fn) |
| 42 |
| 43 @property |
| 44 def manifest_hashes(self): |
| 45 """Returns the dictionary of hashes that have been produced during this |
| 46 run. These come either from the incoming swarm_hashes factory property, |
| 47 or from calling manifest_to_hash, above, at some point during the |
| 48 run.""" |
| 49 return self.m.properties.get('swarm_hashes', self._manifest_hashes) |
| 50 |
| 51 def run_isolate_test(self, test, args=None, name=None, **runtest_kwargs): |
| 52 """Runs a test which has previously been uploaded to the isolate server. |
| 53 Expects to find the test 'test' as a key in the manifest_hashes |
| 54 dictionary. Delegates to api.chromium.runtests; see that method for a |
| 55 more complete description of the supported arguments.""" |
| 56 isolate_hash = self.manifest_hashes[test] |
| 57 |
| 58 name = name or test |
| 59 |
| 60 # TODO(kbr): will need this later. Comment out for now for code coverage. |
| 61 # The step name must end in 'test' or 'tests' in order for the results to |
| 62 # automatically show up on the flakiness dashboard. |
| 63 # if not (name.endswith('test') or name.endswith('tests')): |
| 64 # name = '%s_tests' % name |
| 65 |
| 66 if not args: |
| 67 args = [] |
| 68 |
| 69 full_args = [ |
| 70 '-H', |
| 71 isolate_hash, |
| 72 '-I', |
| 73 ISOLATE_SERVER |
| 74 ] + args |
| 75 |
| 76 return self.m.chromium.runtests( |
| 77 self.m.path.checkout('tools', 'swarming_client', 'run_isolated.py'), |
| 78 args=full_args, |
| 79 name=name, |
| 80 **runtest_kwargs) |
OLD | NEW |