blob: b2e936268934f199ea26e2d0fef9e5237293e79d [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 Tillerd625d812015-04-08 15:52:35 -0700105 if platform.system() == 'Windows':
106 plat = 'windows'
107 else:
108 plat = 'posix'
Craig Tillere9c959d2015-01-18 10:23:26 -0800109 with open('tools/run_tests/tests.json') as f:
Craig Tiller06b4ff22015-01-18 11:01:25 -0800110 js = json.load(f)
Craig Tillerd625d812015-04-08 15:52:35 -0700111 self.binaries = [tgt
112 for tgt in js
113 if tgt['language'] == test_lang and
114 plat in tgt['platforms']]
Craig Tillerc7449162015-01-16 14:42:10 -0800115
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100116 def test_specs(self, config, travis):
Craig Tiller547db2b2015-01-30 14:08:39 -0800117 out = []
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100118 for target in self.binaries:
119 if travis and target['flaky']:
120 continue
121 binary = 'bins/%s/%s' % (config.build_config, target['name'])
Craig Tiller49f61322015-03-03 13:02:11 -0800122 out.append(config.job_spec([binary], [binary]))
Craig Tiller547db2b2015-01-30 14:08:39 -0800123 return out
Craig Tillerc7449162015-01-16 14:42:10 -0800124
125 def make_targets(self):
126 return ['buildtests_%s' % self.make_target]
127
128 def build_steps(self):
129 return []
130
murgatroid99132ce6a2015-03-04 17:29:14 -0800131 def supports_multi_config(self):
132 return True
133
134 def __str__(self):
135 return self.make_target
136
Craig Tiller99775822015-01-30 13:07:16 -0800137
murgatroid992c8d5162015-01-26 10:41:21 -0800138class NodeLanguage(object):
139
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100140 def test_specs(self, config, travis):
Craig Tiller49f61322015-03-03 13:02:11 -0800141 return [config.job_spec(['tools/run_tests/run_node.sh'], None)]
murgatroid992c8d5162015-01-26 10:41:21 -0800142
143 def make_targets(self):
murgatroid99c2791652015-01-26 11:33:39 -0800144 return ['static_c']
murgatroid992c8d5162015-01-26 10:41:21 -0800145
146 def build_steps(self):
147 return [['tools/run_tests/build_node.sh']]
Craig Tillerc7449162015-01-16 14:42:10 -0800148
murgatroid99132ce6a2015-03-04 17:29:14 -0800149 def supports_multi_config(self):
150 return False
151
152 def __str__(self):
153 return 'node'
154
Craig Tiller99775822015-01-30 13:07:16 -0800155
Craig Tillerc7449162015-01-16 14:42:10 -0800156class PhpLanguage(object):
157
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100158 def test_specs(self, config, travis):
Craig Tiller49f61322015-03-03 13:02:11 -0800159 return [config.job_spec(['src/php/bin/run_tests.sh'], None)]
Craig Tillerc7449162015-01-16 14:42:10 -0800160
161 def make_targets(self):
murgatroid99564b9442015-01-26 11:07:59 -0800162 return ['static_c']
Craig Tillerc7449162015-01-16 14:42:10 -0800163
164 def build_steps(self):
165 return [['tools/run_tests/build_php.sh']]
166
murgatroid99132ce6a2015-03-04 17:29:14 -0800167 def supports_multi_config(self):
168 return False
169
170 def __str__(self):
171 return 'php'
172
Craig Tillerc7449162015-01-16 14:42:10 -0800173
Nathaniel Manista840615e2015-01-22 20:31:47 +0000174class PythonLanguage(object):
175
Craig Tiller49f61322015-03-03 13:02:11 -0800176 def __init__(self):
177 with open('tools/run_tests/python_tests.json') as f:
178 self._tests = json.load(f)
179
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100180 def test_specs(self, config, travis):
Masood Malekghassemib2d4a8d2015-03-05 17:04:18 -0800181 modules = [config.job_spec(['tools/run_tests/run_python.sh', '-m',
182 test['module']], None)
183 for test in self._tests if 'module' in test]
184 files = [config.job_spec(['tools/run_tests/run_python.sh',
185 test['file']], None)
186 for test in self._tests if 'file' in test]
187 return files + modules
Nathaniel Manista840615e2015-01-22 20:31:47 +0000188
189 def make_targets(self):
Masood Malekghassemib2d4a8d2015-03-05 17:04:18 -0800190 return ['static_c', 'grpc_python_plugin']
Nathaniel Manista840615e2015-01-22 20:31:47 +0000191
192 def build_steps(self):
193 return [['tools/run_tests/build_python.sh']]
194
murgatroid99132ce6a2015-03-04 17:29:14 -0800195 def supports_multi_config(self):
196 return False
197
198 def __str__(self):
199 return 'python'
200
Craig Tillerd625d812015-04-08 15:52:35 -0700201
murgatroid996a4c4fa2015-02-27 12:08:57 -0800202class RubyLanguage(object):
203
204 def test_specs(self, config, travis):
Craig Tiller49f61322015-03-03 13:02:11 -0800205 return [config.job_spec(['tools/run_tests/run_ruby.sh'], None)]
murgatroid996a4c4fa2015-02-27 12:08:57 -0800206
207 def make_targets(self):
208 return ['static_c']
209
210 def build_steps(self):
211 return [['tools/run_tests/build_ruby.sh']]
212
murgatroid99132ce6a2015-03-04 17:29:14 -0800213 def supports_multi_config(self):
214 return False
215
216 def __str__(self):
217 return 'ruby'
218
Craig Tillerd625d812015-04-08 15:52:35 -0700219
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800220class CSharpLanguage(object):
221
222 def test_specs(self, config, travis):
223 return [config.job_spec('tools/run_tests/run_csharp.sh', None)]
224
225 def make_targets(self):
226 return ['grpc_csharp_ext']
227
228 def build_steps(self):
229 return [['tools/run_tests/build_csharp.sh']]
Nathaniel Manista840615e2015-01-22 20:31:47 +0000230
murgatroid99132ce6a2015-03-04 17:29:14 -0800231 def supports_multi_config(self):
232 return False
233
234 def __str__(self):
235 return 'csharp'
236
Craig Tillerd625d812015-04-08 15:52:35 -0700237
Nicolas "Pixel" Noblefd2b0932015-03-26 00:26:29 +0100238class Build(object):
239
240 def test_specs(self, config, travis):
241 return []
242
243 def make_targets(self):
244 return ['all']
245
246 def build_steps(self):
247 return []
248
249 def supports_multi_config(self):
250 return True
251
252 def __str__(self):
253 return self.make_target
254
255
Craig Tiller738c3342015-01-12 14:28:33 -0800256# different configurations we can run under
257_CONFIGS = {
Craig Tillerb50d1662015-01-15 17:28:21 -0800258 'dbg': SimpleConfig('dbg'),
259 'opt': SimpleConfig('opt'),
David Klempner1d0302d2015-02-04 16:08:01 -0800260 'tsan': SimpleConfig('tsan', environ={
261 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt'}),
Craig Tillerb50d1662015-01-15 17:28:21 -0800262 'msan': SimpleConfig('msan'),
Craig Tiller96bd5f62015-02-13 09:04:13 -0800263 'ubsan': SimpleConfig('ubsan'),
Craig Tiller547db2b2015-01-30 14:08:39 -0800264 'asan': SimpleConfig('asan', environ={
David Klempner1d0302d2015-02-04 16:08:01 -0800265 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt'}),
Craig Tillerb50d1662015-01-15 17:28:21 -0800266 'gcov': SimpleConfig('gcov'),
Craig Tiller1a305b12015-02-18 13:37:06 -0800267 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']),
Craig Tillerb50d1662015-01-15 17:28:21 -0800268 'helgrind': ValgrindConfig('dbg', 'helgrind')
269 }
Craig Tiller738c3342015-01-12 14:28:33 -0800270
271
Nicolas "Pixel" Noble1fb5e822015-03-16 06:20:37 +0100272_DEFAULT = ['opt']
Craig Tillerc7449162015-01-16 14:42:10 -0800273_LANGUAGES = {
Craig Tillere9c959d2015-01-18 10:23:26 -0800274 'c++': CLanguage('cxx', 'c++'),
275 'c': CLanguage('c', 'c'),
murgatroid992c8d5162015-01-26 10:41:21 -0800276 'node': NodeLanguage(),
Nathaniel Manista840615e2015-01-22 20:31:47 +0000277 'php': PhpLanguage(),
278 'python': PythonLanguage(),
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800279 'ruby': RubyLanguage(),
Nicolas "Pixel" Noblefd2b0932015-03-26 00:26:29 +0100280 'csharp': CSharpLanguage(),
281 'build': Build(),
Craig Tillereb272bc2015-01-30 13:13:14 -0800282 }
Nicolas Nobleddef2462015-01-06 18:08:25 -0800283
284# parse command line
285argp = argparse.ArgumentParser(description='Run grpc tests.')
286argp.add_argument('-c', '--config',
Craig Tiller738c3342015-01-12 14:28:33 -0800287 choices=['all'] + sorted(_CONFIGS.keys()),
Nicolas Nobleddef2462015-01-06 18:08:25 -0800288 nargs='+',
Craig Tillerb29797b2015-01-12 13:51:54 -0800289 default=_DEFAULT)
Nicolas Nobleddef2462015-01-06 18:08:25 -0800290argp.add_argument('-n', '--runs_per_test', default=1, type=int)
Craig Tillerfe406ec2015-02-24 13:55:12 -0800291argp.add_argument('-r', '--regex', default='.*', type=str)
Craig Tillerc2c79212015-02-16 12:00:01 -0800292argp.add_argument('-j', '--jobs', default=1000, type=int)
Craig Tiller8451e872015-02-27 09:25:51 -0800293argp.add_argument('-s', '--slowdown', default=1.0, type=float)
ctiller3040cb72015-01-07 12:13:17 -0800294argp.add_argument('-f', '--forever',
295 default=False,
296 action='store_const',
297 const=True)
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100298argp.add_argument('-t', '--travis',
299 default=False,
300 action='store_const',
301 const=True)
Nicolas Noble044db742015-01-14 16:57:24 -0800302argp.add_argument('--newline_on_success',
303 default=False,
304 action='store_const',
305 const=True)
Craig Tiller686fb262015-01-15 07:39:09 -0800306argp.add_argument('-l', '--language',
Craig Tillerc7449162015-01-16 14:42:10 -0800307 choices=sorted(_LANGUAGES.keys()),
Craig Tiller686fb262015-01-15 07:39:09 -0800308 nargs='+',
Craig Tillerc7449162015-01-16 14:42:10 -0800309 default=sorted(_LANGUAGES.keys()))
Nicolas Nobleddef2462015-01-06 18:08:25 -0800310args = argp.parse_args()
311
312# grab config
Craig Tiller738c3342015-01-12 14:28:33 -0800313run_configs = set(_CONFIGS[cfg]
314 for cfg in itertools.chain.from_iterable(
315 _CONFIGS.iterkeys() if x == 'all' else [x]
316 for x in args.config))
317build_configs = set(cfg.build_config for cfg in run_configs)
Craig Tillerf1973b02015-01-16 12:32:13 -0800318
Craig Tillerc7449162015-01-16 14:42:10 -0800319make_targets = []
320languages = set(_LANGUAGES[l] for l in args.language)
murgatroid99132ce6a2015-03-04 17:29:14 -0800321
322if len(build_configs) > 1:
323 for language in languages:
324 if not language.supports_multi_config():
325 print language, 'does not support multiple build configurations'
326 sys.exit(1)
327
Craig Tiller5058c692015-04-08 09:42:04 -0700328if platform.system() == 'Windows':
329 def make_jobspec(cfg, targets):
330 return jobset.JobSpec(['nmake', '/f', 'Grpc.mak', 'CONFIG=%s' % cfg] + targets,
331 cwd='vsprojects\\vs2013')
332else:
333 def make_jobspec(cfg, targets):
334 return jobset.JobSpec(['make',
335 '-j', '%d' % (multiprocessing.cpu_count() + 1),
336 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' %
337 args.slowdown,
338 'CONFIG=%s' % cfg] + targets)
339
340build_steps = [make_jobspec(cfg,
341 list(set(itertools.chain.from_iterable(
342 l.make_targets() for l in languages))))
343 for cfg in build_configs]
344build_steps.extend(set(
murgatroid99132ce6a2015-03-04 17:29:14 -0800345 jobset.JobSpec(cmdline, environ={'CONFIG': cfg})
346 for cfg in build_configs
Craig Tiller547db2b2015-01-30 14:08:39 -0800347 for l in languages
Craig Tiller5058c692015-04-08 09:42:04 -0700348 for cmdline in l.build_steps()))
Craig Tiller547db2b2015-01-30 14:08:39 -0800349one_run = set(
350 spec
351 for config in run_configs
352 for language in args.language
Nicolas "Pixel" Noble9db7c3b2015-02-27 06:03:00 +0100353 for spec in _LANGUAGES[language].test_specs(config, args.travis)
Craig Tillerfe406ec2015-02-24 13:55:12 -0800354 if re.search(args.regex, spec.shortname))
Craig Tillerf1973b02015-01-16 12:32:13 -0800355
Nicolas Nobleddef2462015-01-06 18:08:25 -0800356runs_per_test = args.runs_per_test
ctiller3040cb72015-01-07 12:13:17 -0800357forever = args.forever
Nicolas Nobleddef2462015-01-06 18:08:25 -0800358
Nicolas Nobleddef2462015-01-06 18:08:25 -0800359
Craig Tiller71735182015-01-15 17:07:13 -0800360class TestCache(object):
Craig Tillerb50d1662015-01-15 17:28:21 -0800361 """Cache for running tests."""
362
David Klempner25739582015-02-11 15:57:32 -0800363 def __init__(self, use_cache_results):
Craig Tiller71735182015-01-15 17:07:13 -0800364 self._last_successful_run = {}
David Klempner25739582015-02-11 15:57:32 -0800365 self._use_cache_results = use_cache_results
Craig Tiller71735182015-01-15 17:07:13 -0800366
367 def should_run(self, cmdline, bin_hash):
Craig Tiller71735182015-01-15 17:07:13 -0800368 if cmdline not in self._last_successful_run:
369 return True
370 if self._last_successful_run[cmdline] != bin_hash:
371 return True
David Klempner25739582015-02-11 15:57:32 -0800372 if not self._use_cache_results:
373 return True
Craig Tiller71735182015-01-15 17:07:13 -0800374 return False
375
376 def finished(self, cmdline, bin_hash):
Craig Tiller547db2b2015-01-30 14:08:39 -0800377 self._last_successful_run[cmdline] = bin_hash
Craig Tillerc1f11622015-02-25 09:09:59 -0800378 self.save()
Craig Tiller71735182015-01-15 17:07:13 -0800379
380 def dump(self):
Craig Tillerb50d1662015-01-15 17:28:21 -0800381 return [{'cmdline': k, 'hash': v}
382 for k, v in self._last_successful_run.iteritems()]
Craig Tiller71735182015-01-15 17:07:13 -0800383
384 def parse(self, exdump):
385 self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump)
386
387 def save(self):
388 with open('.run_tests_cache', 'w') as f:
Craig Tiller261dd982015-01-16 16:41:45 -0800389 f.write(json.dumps(self.dump()))
Craig Tiller71735182015-01-15 17:07:13 -0800390
Craig Tiller1cc11db2015-01-15 22:50:50 -0800391 def maybe_load(self):
392 if os.path.exists('.run_tests_cache'):
393 with open('.run_tests_cache') as f:
Craig Tiller261dd982015-01-16 16:41:45 -0800394 self.parse(json.loads(f.read()))
Craig Tiller71735182015-01-15 17:07:13 -0800395
396
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100397def _build_and_run(check_cancelled, newline_on_success, travis, cache):
ctiller3040cb72015-01-07 12:13:17 -0800398 """Do one pass of building & running tests."""
murgatroid99666450e2015-01-26 13:03:31 -0800399 # build latest sequentially
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100400 if not jobset.run(build_steps, maxjobs=1,
401 newline_on_success=newline_on_success, travis=travis):
Craig Tillerd86a3942015-01-14 12:48:54 -0800402 return 1
ctiller3040cb72015-01-07 12:13:17 -0800403
404 # run all the tests
Craig Tillerc7449162015-01-16 14:42:10 -0800405 all_runs = itertools.chain.from_iterable(
406 itertools.repeat(one_run, runs_per_test))
407 if not jobset.run(all_runs, check_cancelled,
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100408 newline_on_success=newline_on_success, travis=travis,
Craig Tillerc2c79212015-02-16 12:00:01 -0800409 maxjobs=min(args.jobs, min(c.maxjobs for c in run_configs)),
Craig Tillerc7449162015-01-16 14:42:10 -0800410 cache=cache):
Craig Tillerd86a3942015-01-14 12:48:54 -0800411 return 2
412
413 return 0
ctiller3040cb72015-01-07 12:13:17 -0800414
415
David Klempner25739582015-02-11 15:57:32 -0800416test_cache = TestCache(runs_per_test == 1)
Craig Tiller547db2b2015-01-30 14:08:39 -0800417test_cache.maybe_load()
Craig Tiller71735182015-01-15 17:07:13 -0800418
ctiller3040cb72015-01-07 12:13:17 -0800419if forever:
Nicolas Noble044db742015-01-14 16:57:24 -0800420 success = True
ctiller3040cb72015-01-07 12:13:17 -0800421 while True:
Craig Tiller42bc87c2015-02-23 08:50:19 -0800422 dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples'])
ctiller3040cb72015-01-07 12:13:17 -0800423 initial_time = dw.most_recent_change()
424 have_files_changed = lambda: dw.most_recent_change() != initial_time
Nicolas Noble044db742015-01-14 16:57:24 -0800425 previous_success = success
Craig Tiller71735182015-01-15 17:07:13 -0800426 success = _build_and_run(check_cancelled=have_files_changed,
Nicolas Nobleb09078f2015-01-14 18:06:05 -0800427 newline_on_success=False,
Craig Tiller71735182015-01-15 17:07:13 -0800428 cache=test_cache) == 0
Nicolas Noble044db742015-01-14 16:57:24 -0800429 if not previous_success and success:
Nicolas Nobleb09078f2015-01-14 18:06:05 -0800430 jobset.message('SUCCESS',
431 'All tests are now passing properly',
432 do_newline=True)
Nicolas Noble044db742015-01-14 16:57:24 -0800433 jobset.message('IDLE', 'No change detected')
ctiller3040cb72015-01-07 12:13:17 -0800434 while not have_files_changed():
435 time.sleep(1)
436else:
Craig Tiller71735182015-01-15 17:07:13 -0800437 result = _build_and_run(check_cancelled=lambda: False,
438 newline_on_success=args.newline_on_success,
Nicolas "Pixel" Noblea7df3f92015-02-26 22:07:04 +0100439 travis=args.travis,
Craig Tiller71735182015-01-15 17:07:13 -0800440 cache=test_cache)
Nicolas Nobleb09078f2015-01-14 18:06:05 -0800441 if result == 0:
442 jobset.message('SUCCESS', 'All tests passed', do_newline=True)
443 else:
444 jobset.message('FAILED', 'Some tests failed', do_newline=True)
445 sys.exit(result)