blob: 6013f1163b9bb8687cd156e3a5c1bf934db51fb9 [file] [log] [blame]
David Klempnerf94838b2015-02-02 16:56:46 -08001#!/usr/bin/python2.7
Craig Tillerc2c79212015-02-16 12:00:01 -08002# 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 Nobleddef2462015-01-06 18:08:25 -080031"""Run tests in parallel."""
32
33import argparse
34import glob
35import itertools
Craig Tiller261dd982015-01-16 16:41:45 -080036import json
Nicolas Nobleddef2462015-01-06 18:08:25 -080037import multiprocessing
Craig Tiller1cc11db2015-01-15 22:50:50 -080038import os
Craig Tillerfe406ec2015-02-24 13:55:12 -080039import re
Nicolas Nobleddef2462015-01-06 18:08:25 -080040import sys
ctiller3040cb72015-01-07 12:13:17 -080041import time
Craig Tiller5058c692015-04-08 09:42:04 -070042import platform
Nicolas Nobleddef2462015-01-06 18:08:25 -080043
44import jobset
ctiller3040cb72015-01-07 12:13:17 -080045import watch_dirs
Nicolas Nobleddef2462015-01-06 18:08:25 -080046
Craig Tillerb50d1662015-01-15 17:28:21 -080047
Craig Tiller2cc2b842015-02-27 11:38:31 -080048ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
49os.chdir(ROOT)
50
51
Craig Tiller738c3342015-01-12 14:28:33 -080052# SimpleConfig: just compile with CONFIG=config, and run the binary to test
53class SimpleConfig(object):
Craig Tillerb50d1662015-01-15 17:28:21 -080054
murgatroid99132ce6a2015-03-04 17:29:14 -080055 def __init__(self, config, environ=None):
56 if environ is None:
57 environ = {}
Craig Tiller738c3342015-01-12 14:28:33 -080058 self.build_config = config
Craig Tillere68de0e2015-01-26 08:44:00 -080059 self.maxjobs = 2 * multiprocessing.cpu_count()
Craig Tillerc7449162015-01-16 14:42:10 -080060 self.allow_hashing = (config != 'gcov')
Craig Tiller547db2b2015-01-30 14:08:39 -080061 self.environ = environ
murgatroid99132ce6a2015-03-04 17:29:14 -080062 self.environ['CONFIG'] = config
Craig Tiller738c3342015-01-12 14:28:33 -080063
Craig Tiller49f61322015-03-03 13:02:11 -080064 def job_spec(self, cmdline, hash_targets):
65 """Construct a jobset.JobSpec for a test under this config
66
67 Args:
68 cmdline: a list of strings specifying the command line the test
69 would like to run
70 hash_targets: either None (don't do caching of test results), or
71 a list of strings specifying files to include in a
72 binary hash to check if a test has changed
73 -- if used, all artifacts needed to run the test must
74 be listed
75 """
76 return jobset.JobSpec(cmdline=cmdline,
Craig Tiller547db2b2015-01-30 14:08:39 -080077 environ=self.environ,
78 hash_targets=hash_targets
79 if self.allow_hashing else None)
Craig Tiller738c3342015-01-12 14:28:33 -080080
81
82# ValgrindConfig: compile with some CONFIG=config, but use valgrind to run
83class ValgrindConfig(object):
Craig Tillerb50d1662015-01-15 17:28:21 -080084
murgatroid99132ce6a2015-03-04 17:29:14 -080085 def __init__(self, config, tool, args=None):
86 if args is None:
87 args = []
Craig Tiller738c3342015-01-12 14:28:33 -080088 self.build_config = config
Craig Tiller2aa4d642015-01-14 15:59:44 -080089 self.tool = tool
Craig Tiller1a305b12015-02-18 13:37:06 -080090 self.args = args
Craig Tillere68de0e2015-01-26 08:44:00 -080091 self.maxjobs = 2 * multiprocessing.cpu_count()
Craig Tillerc7449162015-01-16 14:42:10 -080092 self.allow_hashing = False
Craig Tiller738c3342015-01-12 14:28:33 -080093
Craig Tiller49f61322015-03-03 13:02:11 -080094 def job_spec(self, cmdline, hash_targets):
Craig Tiller1a305b12015-02-18 13:37:06 -080095 return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] +
Craig Tiller49f61322015-03-03 13:02:11 -080096 self.args + cmdline,
Craig Tiller1a305b12015-02-18 13:37:06 -080097 shortname='valgrind %s' % binary,
98 hash_targets=None)
Craig Tiller738c3342015-01-12 14:28:33 -080099
100
Craig Tillerc7449162015-01-16 14:42:10 -0800101class CLanguage(object):
102
Craig Tillere9c959d2015-01-18 10:23:26 -0800103 def __init__(self, make_target, test_lang):
Craig Tillerc7449162015-01-16 14:42:10 -0800104 self.make_target = make_target
Craig Tillere9c959d2015-01-18 10:23:26 -0800105 with open('tools/run_tests/tests.json') as f:
Craig Tiller06b4ff22015-01-18 11:01:25 -0800106 js = json.load(f)
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100107 self.binaries = [tgt for tgt in js if tgt['language'] == test_lang]
Craig Tillerc7449162015-01-16 14:42:10 -0800108
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100109 def test_specs(self, config, travis):
Craig Tiller547db2b2015-01-30 14:08:39 -0800110 out = []
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100111 for target in self.binaries:
112 if travis and target['flaky']:
113 continue
114 binary = 'bins/%s/%s' % (config.build_config, target['name'])
Craig Tiller49f61322015-03-03 13:02:11 -0800115 out.append(config.job_spec([binary], [binary]))
Craig Tiller547db2b2015-01-30 14:08:39 -0800116 return out
Craig Tillerc7449162015-01-16 14:42:10 -0800117
118 def make_targets(self):
119 return ['buildtests_%s' % self.make_target]
120
121 def build_steps(self):
122 return []
123
murgatroid99132ce6a2015-03-04 17:29:14 -0800124 def supports_multi_config(self):
125 return True
126
127 def __str__(self):
128 return self.make_target
129
Craig Tiller99775822015-01-30 13:07:16 -0800130
murgatroid992c8d5162015-01-26 10:41:21 -0800131class NodeLanguage(object):
132
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100133 def test_specs(self, config, travis):
Craig Tiller49f61322015-03-03 13:02:11 -0800134 return [config.job_spec(['tools/run_tests/run_node.sh'], None)]
murgatroid992c8d5162015-01-26 10:41:21 -0800135
136 def make_targets(self):
murgatroid99c2791652015-01-26 11:33:39 -0800137 return ['static_c']
murgatroid992c8d5162015-01-26 10:41:21 -0800138
139 def build_steps(self):
140 return [['tools/run_tests/build_node.sh']]
Craig Tillerc7449162015-01-16 14:42:10 -0800141
murgatroid99132ce6a2015-03-04 17:29:14 -0800142 def supports_multi_config(self):
143 return False
144
145 def __str__(self):
146 return 'node'
147
Craig Tiller99775822015-01-30 13:07:16 -0800148
Craig Tillerc7449162015-01-16 14:42:10 -0800149class PhpLanguage(object):
150
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100151 def test_specs(self, config, travis):
Craig Tiller49f61322015-03-03 13:02:11 -0800152 return [config.job_spec(['src/php/bin/run_tests.sh'], None)]
Craig Tillerc7449162015-01-16 14:42:10 -0800153
154 def make_targets(self):
murgatroid99564b9442015-01-26 11:07:59 -0800155 return ['static_c']
Craig Tillerc7449162015-01-16 14:42:10 -0800156
157 def build_steps(self):
158 return [['tools/run_tests/build_php.sh']]
159
murgatroid99132ce6a2015-03-04 17:29:14 -0800160 def supports_multi_config(self):
161 return False
162
163 def __str__(self):
164 return 'php'
165
Craig Tillerc7449162015-01-16 14:42:10 -0800166
Nathaniel Manista840615e2015-01-22 20:31:47 +0000167class PythonLanguage(object):
168
Craig Tiller49f61322015-03-03 13:02:11 -0800169 def __init__(self):
170 with open('tools/run_tests/python_tests.json') as f:
171 self._tests = json.load(f)
172
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100173 def test_specs(self, config, travis):
Masood Malekghassemib2d4a8d2015-03-05 17:04:18 -0800174 modules = [config.job_spec(['tools/run_tests/run_python.sh', '-m',
175 test['module']], None)
176 for test in self._tests if 'module' in test]
177 files = [config.job_spec(['tools/run_tests/run_python.sh',
178 test['file']], None)
179 for test in self._tests if 'file' in test]
180 return files + modules
Nathaniel Manista840615e2015-01-22 20:31:47 +0000181
182 def make_targets(self):
Masood Malekghassemib2d4a8d2015-03-05 17:04:18 -0800183 return ['static_c', 'grpc_python_plugin']
Nathaniel Manista840615e2015-01-22 20:31:47 +0000184
185 def build_steps(self):
186 return [['tools/run_tests/build_python.sh']]
187
murgatroid99132ce6a2015-03-04 17:29:14 -0800188 def supports_multi_config(self):
189 return False
190
191 def __str__(self):
192 return 'python'
193
murgatroid996a4c4fa2015-02-27 12:08:57 -0800194class RubyLanguage(object):
195
196 def test_specs(self, config, travis):
Craig Tiller49f61322015-03-03 13:02:11 -0800197 return [config.job_spec(['tools/run_tests/run_ruby.sh'], None)]
murgatroid996a4c4fa2015-02-27 12:08:57 -0800198
199 def make_targets(self):
200 return ['static_c']
201
202 def build_steps(self):
203 return [['tools/run_tests/build_ruby.sh']]
204
murgatroid99132ce6a2015-03-04 17:29:14 -0800205 def supports_multi_config(self):
206 return False
207
208 def __str__(self):
209 return 'ruby'
210
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800211class CSharpLanguage(object):
212
213 def test_specs(self, config, travis):
214 return [config.job_spec('tools/run_tests/run_csharp.sh', None)]
215
216 def make_targets(self):
217 return ['grpc_csharp_ext']
218
219 def build_steps(self):
220 return [['tools/run_tests/build_csharp.sh']]
Nathaniel Manista840615e2015-01-22 20:31:47 +0000221
murgatroid99132ce6a2015-03-04 17:29:14 -0800222 def supports_multi_config(self):
223 return False
224
225 def __str__(self):
226 return 'csharp'
227
Nicolas "Pixel" Noblefd2b0932015-03-26 00:26:29 +0100228class Build(object):
229
230 def test_specs(self, config, travis):
231 return []
232
233 def make_targets(self):
234 return ['all']
235
236 def build_steps(self):
237 return []
238
239 def supports_multi_config(self):
240 return True
241
242 def __str__(self):
243 return self.make_target
244
245
Craig Tiller738c3342015-01-12 14:28:33 -0800246# different configurations we can run under
247_CONFIGS = {
Craig Tillerb50d1662015-01-15 17:28:21 -0800248 'dbg': SimpleConfig('dbg'),
249 'opt': SimpleConfig('opt'),
David Klempner1d0302d2015-02-04 16:08:01 -0800250 'tsan': SimpleConfig('tsan', environ={
251 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt'}),
Craig Tillerb50d1662015-01-15 17:28:21 -0800252 'msan': SimpleConfig('msan'),
Craig Tiller96bd5f62015-02-13 09:04:13 -0800253 'ubsan': SimpleConfig('ubsan'),
Craig Tiller547db2b2015-01-30 14:08:39 -0800254 'asan': SimpleConfig('asan', environ={
David Klempner1d0302d2015-02-04 16:08:01 -0800255 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt'}),
Craig Tillerb50d1662015-01-15 17:28:21 -0800256 'gcov': SimpleConfig('gcov'),
Craig Tiller1a305b12015-02-18 13:37:06 -0800257 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']),
Craig Tillerb50d1662015-01-15 17:28:21 -0800258 'helgrind': ValgrindConfig('dbg', 'helgrind')
259 }
Craig Tiller738c3342015-01-12 14:28:33 -0800260
261
Nicolas "Pixel" Noble1fb5e822015-03-16 06:20:37 +0100262_DEFAULT = ['opt']
Craig Tillerc7449162015-01-16 14:42:10 -0800263_LANGUAGES = {
Craig Tillere9c959d2015-01-18 10:23:26 -0800264 'c++': CLanguage('cxx', 'c++'),
265 'c': CLanguage('c', 'c'),
murgatroid992c8d5162015-01-26 10:41:21 -0800266 'node': NodeLanguage(),
Nathaniel Manista840615e2015-01-22 20:31:47 +0000267 'php': PhpLanguage(),
268 'python': PythonLanguage(),
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800269 'ruby': RubyLanguage(),
Nicolas "Pixel" Noblefd2b0932015-03-26 00:26:29 +0100270 'csharp': CSharpLanguage(),
271 'build': Build(),
Craig Tillereb272bc2015-01-30 13:13:14 -0800272 }
Nicolas Nobleddef2462015-01-06 18:08:25 -0800273
274# parse command line
275argp = argparse.ArgumentParser(description='Run grpc tests.')
276argp.add_argument('-c', '--config',
Craig Tiller738c3342015-01-12 14:28:33 -0800277 choices=['all'] + sorted(_CONFIGS.keys()),
Nicolas Nobleddef2462015-01-06 18:08:25 -0800278 nargs='+',
Craig Tillerb29797b2015-01-12 13:51:54 -0800279 default=_DEFAULT)
Nicolas Nobleddef2462015-01-06 18:08:25 -0800280argp.add_argument('-n', '--runs_per_test', default=1, type=int)
Craig Tillerfe406ec2015-02-24 13:55:12 -0800281argp.add_argument('-r', '--regex', default='.*', type=str)
Craig Tillerc2c79212015-02-16 12:00:01 -0800282argp.add_argument('-j', '--jobs', default=1000, type=int)
Craig Tiller8451e872015-02-27 09:25:51 -0800283argp.add_argument('-s', '--slowdown', default=1.0, type=float)
ctiller3040cb72015-01-07 12:13:17 -0800284argp.add_argument('-f', '--forever',
285 default=False,
286 action='store_const',
287 const=True)
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100288argp.add_argument('-t', '--travis',
289 default=False,
290 action='store_const',
291 const=True)
Nicolas Noble044db742015-01-14 16:57:24 -0800292argp.add_argument('--newline_on_success',
293 default=False,
294 action='store_const',
295 const=True)
Craig Tiller686fb262015-01-15 07:39:09 -0800296argp.add_argument('-l', '--language',
Craig Tillerc7449162015-01-16 14:42:10 -0800297 choices=sorted(_LANGUAGES.keys()),
Craig Tiller686fb262015-01-15 07:39:09 -0800298 nargs='+',
Craig Tillerc7449162015-01-16 14:42:10 -0800299 default=sorted(_LANGUAGES.keys()))
Nicolas Nobleddef2462015-01-06 18:08:25 -0800300args = argp.parse_args()
301
302# grab config
Craig Tiller738c3342015-01-12 14:28:33 -0800303run_configs = set(_CONFIGS[cfg]
304 for cfg in itertools.chain.from_iterable(
305 _CONFIGS.iterkeys() if x == 'all' else [x]
306 for x in args.config))
307build_configs = set(cfg.build_config for cfg in run_configs)
Craig Tillerf1973b02015-01-16 12:32:13 -0800308
Craig Tillerc7449162015-01-16 14:42:10 -0800309make_targets = []
310languages = set(_LANGUAGES[l] for l in args.language)
murgatroid99132ce6a2015-03-04 17:29:14 -0800311
312if len(build_configs) > 1:
313 for language in languages:
314 if not language.supports_multi_config():
315 print language, 'does not support multiple build configurations'
316 sys.exit(1)
317
Craig Tiller5058c692015-04-08 09:42:04 -0700318if platform.system() == 'Windows':
319 def make_jobspec(cfg, targets):
320 return jobset.JobSpec(['nmake', '/f', 'Grpc.mak', 'CONFIG=%s' % cfg] + targets,
321 cwd='vsprojects\\vs2013')
322else:
323 def make_jobspec(cfg, targets):
324 return jobset.JobSpec(['make',
325 '-j', '%d' % (multiprocessing.cpu_count() + 1),
326 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' %
327 args.slowdown,
328 'CONFIG=%s' % cfg] + targets)
329
330build_steps = [make_jobspec(cfg,
331 list(set(itertools.chain.from_iterable(
332 l.make_targets() for l in languages))))
333 for cfg in build_configs]
334build_steps.extend(set(
murgatroid99132ce6a2015-03-04 17:29:14 -0800335 jobset.JobSpec(cmdline, environ={'CONFIG': cfg})
336 for cfg in build_configs
Craig Tiller547db2b2015-01-30 14:08:39 -0800337 for l in languages
Craig Tiller5058c692015-04-08 09:42:04 -0700338 for cmdline in l.build_steps()))
Craig Tiller547db2b2015-01-30 14:08:39 -0800339one_run = set(
340 spec
341 for config in run_configs
342 for language in args.language
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100343 for spec in _LANGUAGES[language].test_specs(config, args.travis)
Craig Tillerfe406ec2015-02-24 13:55:12 -0800344 if re.search(args.regex, spec.shortname))
Craig Tillerf1973b02015-01-16 12:32:13 -0800345
Nicolas Nobleddef2462015-01-06 18:08:25 -0800346runs_per_test = args.runs_per_test
ctiller3040cb72015-01-07 12:13:17 -0800347forever = args.forever
Nicolas Nobleddef2462015-01-06 18:08:25 -0800348
Nicolas Nobleddef2462015-01-06 18:08:25 -0800349
Craig Tiller71735182015-01-15 17:07:13 -0800350class TestCache(object):
Craig Tillerb50d1662015-01-15 17:28:21 -0800351 """Cache for running tests."""
352
David Klempner25739582015-02-11 15:57:32 -0800353 def __init__(self, use_cache_results):
Craig Tiller71735182015-01-15 17:07:13 -0800354 self._last_successful_run = {}
David Klempner25739582015-02-11 15:57:32 -0800355 self._use_cache_results = use_cache_results
Craig Tiller71735182015-01-15 17:07:13 -0800356
357 def should_run(self, cmdline, bin_hash):
Craig Tiller71735182015-01-15 17:07:13 -0800358 if cmdline not in self._last_successful_run:
359 return True
360 if self._last_successful_run[cmdline] != bin_hash:
361 return True
David Klempner25739582015-02-11 15:57:32 -0800362 if not self._use_cache_results:
363 return True
Craig Tiller71735182015-01-15 17:07:13 -0800364 return False
365
366 def finished(self, cmdline, bin_hash):
Craig Tiller547db2b2015-01-30 14:08:39 -0800367 self._last_successful_run[cmdline] = bin_hash
Craig Tillerc1f11622015-02-25 09:09:59 -0800368 self.save()
Craig Tiller71735182015-01-15 17:07:13 -0800369
370 def dump(self):
Craig Tillerb50d1662015-01-15 17:28:21 -0800371 return [{'cmdline': k, 'hash': v}
372 for k, v in self._last_successful_run.iteritems()]
Craig Tiller71735182015-01-15 17:07:13 -0800373
374 def parse(self, exdump):
375 self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump)
376
377 def save(self):
378 with open('.run_tests_cache', 'w') as f:
Craig Tiller261dd982015-01-16 16:41:45 -0800379 f.write(json.dumps(self.dump()))
Craig Tiller71735182015-01-15 17:07:13 -0800380
Craig Tiller1cc11db2015-01-15 22:50:50 -0800381 def maybe_load(self):
382 if os.path.exists('.run_tests_cache'):
383 with open('.run_tests_cache') as f:
Craig Tiller261dd982015-01-16 16:41:45 -0800384 self.parse(json.loads(f.read()))
Craig Tiller71735182015-01-15 17:07:13 -0800385
386
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100387def _build_and_run(check_cancelled, newline_on_success, travis, cache):
ctiller3040cb72015-01-07 12:13:17 -0800388 """Do one pass of building & running tests."""
murgatroid99666450e2015-01-26 13:03:31 -0800389 # build latest sequentially
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100390 if not jobset.run(build_steps, maxjobs=1,
391 newline_on_success=newline_on_success, travis=travis):
Craig Tillerd86a3942015-01-14 12:48:54 -0800392 return 1
ctiller3040cb72015-01-07 12:13:17 -0800393
394 # run all the tests
Craig Tillerc7449162015-01-16 14:42:10 -0800395 all_runs = itertools.chain.from_iterable(
396 itertools.repeat(one_run, runs_per_test))
397 if not jobset.run(all_runs, check_cancelled,
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100398 newline_on_success=newline_on_success, travis=travis,
Craig Tillerc2c79212015-02-16 12:00:01 -0800399 maxjobs=min(args.jobs, min(c.maxjobs for c in run_configs)),
Craig Tillerc7449162015-01-16 14:42:10 -0800400 cache=cache):
Craig Tillerd86a3942015-01-14 12:48:54 -0800401 return 2
402
403 return 0
ctiller3040cb72015-01-07 12:13:17 -0800404
405
David Klempner25739582015-02-11 15:57:32 -0800406test_cache = TestCache(runs_per_test == 1)
Craig Tiller547db2b2015-01-30 14:08:39 -0800407test_cache.maybe_load()
Craig Tiller71735182015-01-15 17:07:13 -0800408
ctiller3040cb72015-01-07 12:13:17 -0800409if forever:
Nicolas Noble044db742015-01-14 16:57:24 -0800410 success = True
ctiller3040cb72015-01-07 12:13:17 -0800411 while True:
Craig Tiller42bc87c2015-02-23 08:50:19 -0800412 dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples'])
ctiller3040cb72015-01-07 12:13:17 -0800413 initial_time = dw.most_recent_change()
414 have_files_changed = lambda: dw.most_recent_change() != initial_time
Nicolas Noble044db742015-01-14 16:57:24 -0800415 previous_success = success
Craig Tiller71735182015-01-15 17:07:13 -0800416 success = _build_and_run(check_cancelled=have_files_changed,
Nicolas Nobleb09078f2015-01-14 18:06:05 -0800417 newline_on_success=False,
Craig Tiller71735182015-01-15 17:07:13 -0800418 cache=test_cache) == 0
Nicolas Noble044db742015-01-14 16:57:24 -0800419 if not previous_success and success:
Nicolas Nobleb09078f2015-01-14 18:06:05 -0800420 jobset.message('SUCCESS',
421 'All tests are now passing properly',
422 do_newline=True)
Nicolas Noble044db742015-01-14 16:57:24 -0800423 jobset.message('IDLE', 'No change detected')
ctiller3040cb72015-01-07 12:13:17 -0800424 while not have_files_changed():
425 time.sleep(1)
426else:
Craig Tiller71735182015-01-15 17:07:13 -0800427 result = _build_and_run(check_cancelled=lambda: False,
428 newline_on_success=args.newline_on_success,
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100429 travis=args.travis,
Craig Tiller71735182015-01-15 17:07:13 -0800430 cache=test_cache)
Nicolas Nobleb09078f2015-01-14 18:06:05 -0800431 if result == 0:
432 jobset.message('SUCCESS', 'All tests passed', do_newline=True)
433 else:
434 jobset.message('FAILED', 'Some tests failed', do_newline=True)
435 sys.exit(result)