David Klempner | f94838b | 2015-02-02 16:56:46 -0800 | [diff] [blame] | 1 | #!/usr/bin/python2.7 |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 2 | # Copyright 2015, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 31 | """Run tests in parallel.""" |
| 32 | |
| 33 | import argparse |
| 34 | import glob |
| 35 | import itertools |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 36 | import json |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 37 | import multiprocessing |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 38 | import os |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 39 | import re |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 40 | import sys |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 41 | import time |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 42 | |
| 43 | import jobset |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 44 | import watch_dirs |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 45 | |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 46 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 47 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
| 48 | class SimpleConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 49 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 50 | def __init__(self, config, environ={}): |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 51 | self.build_config = config |
Craig Tiller | e68de0e | 2015-01-26 08:44:00 -0800 | [diff] [blame] | 52 | self.maxjobs = 2 * multiprocessing.cpu_count() |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 53 | self.allow_hashing = (config != 'gcov') |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 54 | self.environ = environ |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 55 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 56 | def job_spec(self, binary, hash_targets): |
| 57 | return jobset.JobSpec(cmdline=[binary], |
| 58 | environ=self.environ, |
| 59 | hash_targets=hash_targets |
| 60 | if self.allow_hashing else None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 61 | |
| 62 | |
| 63 | # ValgrindConfig: compile with some CONFIG=config, but use valgrind to run |
| 64 | class ValgrindConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 65 | |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 66 | def __init__(self, config, tool, args=[]): |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 67 | self.build_config = config |
Craig Tiller | 2aa4d64 | 2015-01-14 15:59:44 -0800 | [diff] [blame] | 68 | self.tool = tool |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 69 | self.args = args |
Craig Tiller | e68de0e | 2015-01-26 08:44:00 -0800 | [diff] [blame] | 70 | self.maxjobs = 2 * multiprocessing.cpu_count() |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 71 | self.allow_hashing = False |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 72 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 73 | def job_spec(self, binary, hash_targets): |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 74 | return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] + |
| 75 | self.args + [binary], |
| 76 | shortname='valgrind %s' % binary, |
| 77 | hash_targets=None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 78 | |
| 79 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 80 | class CLanguage(object): |
| 81 | |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 82 | def __init__(self, make_target, test_lang): |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 83 | self.make_target = make_target |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 84 | with open('tools/run_tests/tests.json') as f: |
Craig Tiller | 06b4ff2 | 2015-01-18 11:01:25 -0800 | [diff] [blame] | 85 | js = json.load(f) |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 86 | self.binaries = [tgt['name'] |
| 87 | for tgt in js |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 88 | if tgt['language'] == test_lang] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 89 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 90 | def test_specs(self, config): |
| 91 | out = [] |
| 92 | for name in self.binaries: |
| 93 | binary = 'bins/%s/%s' % (config.build_config, name) |
| 94 | out.append(config.job_spec(binary, [binary])) |
| 95 | return out |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 96 | |
| 97 | def make_targets(self): |
| 98 | return ['buildtests_%s' % self.make_target] |
| 99 | |
| 100 | def build_steps(self): |
| 101 | return [] |
| 102 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 103 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 104 | class NodeLanguage(object): |
| 105 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 106 | def test_specs(self, config): |
| 107 | return [config.job_spec('tools/run_tests/run_node.sh', None)] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 108 | |
| 109 | def make_targets(self): |
murgatroid99 | c279165 | 2015-01-26 11:33:39 -0800 | [diff] [blame] | 110 | return ['static_c'] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 111 | |
| 112 | def build_steps(self): |
| 113 | return [['tools/run_tests/build_node.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 114 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 115 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 116 | class PhpLanguage(object): |
| 117 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 118 | def test_specs(self, config): |
| 119 | return [config.job_spec('src/php/bin/run_tests.sh', None)] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 120 | |
| 121 | def make_targets(self): |
murgatroid99 | 564b944 | 2015-01-26 11:07:59 -0800 | [diff] [blame] | 122 | return ['static_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 123 | |
| 124 | def build_steps(self): |
| 125 | return [['tools/run_tests/build_php.sh']] |
| 126 | |
| 127 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 128 | class PythonLanguage(object): |
| 129 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 130 | def test_specs(self, config): |
| 131 | return [config.job_spec('tools/run_tests/run_python.sh', None)] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 132 | |
| 133 | def make_targets(self): |
| 134 | return[] |
| 135 | |
| 136 | def build_steps(self): |
| 137 | return [['tools/run_tests/build_python.sh']] |
| 138 | |
| 139 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 140 | # different configurations we can run under |
| 141 | _CONFIGS = { |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 142 | 'dbg': SimpleConfig('dbg'), |
| 143 | 'opt': SimpleConfig('opt'), |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 144 | 'tsan': SimpleConfig('tsan', environ={ |
| 145 | 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 146 | 'msan': SimpleConfig('msan'), |
Craig Tiller | 96bd5f6 | 2015-02-13 09:04:13 -0800 | [diff] [blame] | 147 | 'ubsan': SimpleConfig('ubsan'), |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 148 | 'asan': SimpleConfig('asan', environ={ |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 149 | 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 150 | 'gcov': SimpleConfig('gcov'), |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 151 | 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 152 | 'helgrind': ValgrindConfig('dbg', 'helgrind') |
| 153 | } |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 154 | |
| 155 | |
Craig Tiller | b29797b | 2015-01-12 13:51:54 -0800 | [diff] [blame] | 156 | _DEFAULT = ['dbg', 'opt'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 157 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 158 | 'c++': CLanguage('cxx', 'c++'), |
| 159 | 'c': CLanguage('c', 'c'), |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 160 | 'node': NodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 161 | 'php': PhpLanguage(), |
| 162 | 'python': PythonLanguage(), |
Craig Tiller | eb272bc | 2015-01-30 13:13:14 -0800 | [diff] [blame] | 163 | } |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 164 | |
| 165 | # parse command line |
| 166 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 167 | argp.add_argument('-c', '--config', |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 168 | choices=['all'] + sorted(_CONFIGS.keys()), |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 169 | nargs='+', |
Craig Tiller | b29797b | 2015-01-12 13:51:54 -0800 | [diff] [blame] | 170 | default=_DEFAULT) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 171 | argp.add_argument('-n', '--runs_per_test', default=1, type=int) |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 172 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 173 | argp.add_argument('-j', '--jobs', default=1000, type=int) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 174 | argp.add_argument('-f', '--forever', |
| 175 | default=False, |
| 176 | action='store_const', |
| 177 | const=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 178 | argp.add_argument('--newline_on_success', |
| 179 | default=False, |
| 180 | action='store_const', |
| 181 | const=True) |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 182 | argp.add_argument('-l', '--language', |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 183 | choices=sorted(_LANGUAGES.keys()), |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 184 | nargs='+', |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 185 | default=sorted(_LANGUAGES.keys())) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 186 | args = argp.parse_args() |
| 187 | |
| 188 | # grab config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 189 | run_configs = set(_CONFIGS[cfg] |
| 190 | for cfg in itertools.chain.from_iterable( |
| 191 | _CONFIGS.iterkeys() if x == 'all' else [x] |
| 192 | for x in args.config)) |
| 193 | build_configs = set(cfg.build_config for cfg in run_configs) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 194 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 195 | make_targets = [] |
| 196 | languages = set(_LANGUAGES[l] for l in args.language) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 197 | build_steps = [jobset.JobSpec(['make', |
| 198 | '-j', '%d' % (multiprocessing.cpu_count() + 1), |
| 199 | 'CONFIG=%s' % cfg] + list(set( |
| 200 | itertools.chain.from_iterable( |
| 201 | l.make_targets() for l in languages)))) |
| 202 | for cfg in build_configs] + list(set( |
| 203 | jobset.JobSpec(cmdline) |
| 204 | for l in languages |
| 205 | for cmdline in l.build_steps())) |
| 206 | one_run = set( |
| 207 | spec |
| 208 | for config in run_configs |
| 209 | for language in args.language |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 210 | for spec in _LANGUAGES[language].test_specs(config) |
| 211 | if re.search(args.regex, spec.shortname)) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 212 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 213 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 214 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 215 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 216 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 217 | class TestCache(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 218 | """Cache for running tests.""" |
| 219 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 220 | def __init__(self, use_cache_results): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 221 | self._last_successful_run = {} |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 222 | self._use_cache_results = use_cache_results |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 223 | |
| 224 | def should_run(self, cmdline, bin_hash): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 225 | if cmdline not in self._last_successful_run: |
| 226 | return True |
| 227 | if self._last_successful_run[cmdline] != bin_hash: |
| 228 | return True |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 229 | if not self._use_cache_results: |
| 230 | return True |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 231 | return False |
| 232 | |
| 233 | def finished(self, cmdline, bin_hash): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 234 | self._last_successful_run[cmdline] = bin_hash |
Craig Tiller | c1f1162 | 2015-02-25 09:09:59 -0800 | [diff] [blame^] | 235 | self.save() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 236 | |
| 237 | def dump(self): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 238 | return [{'cmdline': k, 'hash': v} |
| 239 | for k, v in self._last_successful_run.iteritems()] |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 240 | |
| 241 | def parse(self, exdump): |
| 242 | self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump) |
| 243 | |
| 244 | def save(self): |
| 245 | with open('.run_tests_cache', 'w') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 246 | f.write(json.dumps(self.dump())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 247 | |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 248 | def maybe_load(self): |
| 249 | if os.path.exists('.run_tests_cache'): |
| 250 | with open('.run_tests_cache') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 251 | self.parse(json.loads(f.read())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 252 | |
| 253 | |
| 254 | def _build_and_run(check_cancelled, newline_on_success, cache): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 255 | """Do one pass of building & running tests.""" |
murgatroid99 | 666450e | 2015-01-26 13:03:31 -0800 | [diff] [blame] | 256 | # build latest sequentially |
murgatroid99 | c279165 | 2015-01-26 11:33:39 -0800 | [diff] [blame] | 257 | if not jobset.run(build_steps, maxjobs=1): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 258 | return 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 259 | |
| 260 | # run all the tests |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 261 | all_runs = itertools.chain.from_iterable( |
| 262 | itertools.repeat(one_run, runs_per_test)) |
| 263 | if not jobset.run(all_runs, check_cancelled, |
| 264 | newline_on_success=newline_on_success, |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 265 | maxjobs=min(args.jobs, min(c.maxjobs for c in run_configs)), |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 266 | cache=cache): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 267 | return 2 |
| 268 | |
| 269 | return 0 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 270 | |
| 271 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 272 | test_cache = TestCache(runs_per_test == 1) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 273 | test_cache.maybe_load() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 274 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 275 | if forever: |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 276 | success = True |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 277 | while True: |
| 278 | dw = watch_dirs.DirWatcher(['src', 'include', 'test']) |
| 279 | initial_time = dw.most_recent_change() |
| 280 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 281 | previous_success = success |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 282 | success = _build_and_run(check_cancelled=have_files_changed, |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 283 | newline_on_success=False, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 284 | cache=test_cache) == 0 |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 285 | if not previous_success and success: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 286 | jobset.message('SUCCESS', |
| 287 | 'All tests are now passing properly', |
| 288 | do_newline=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 289 | jobset.message('IDLE', 'No change detected') |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 290 | while not have_files_changed(): |
| 291 | time.sleep(1) |
| 292 | else: |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 293 | result = _build_and_run(check_cancelled=lambda: False, |
| 294 | newline_on_success=args.newline_on_success, |
| 295 | cache=test_cache) |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 296 | if result == 0: |
| 297 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 298 | else: |
| 299 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
| 300 | sys.exit(result) |