blob: 6b27d6f875fbe5295fbde89708d829d1185a498e [file] [log] [blame]
Tsuyoshi Ozawa4e0238d2016-09-20 05:56:10 +09001#!/usr/bin/env python
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2015 gRPC authors.
Craig Tillerc2c79212015-02-16 12:00:01 -08003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
Craig Tillerc2c79212015-02-16 12:00:01 -08007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Craig Tillerc2c79212015-02-16 12:00:01 -08009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Nicolas Nobleddef2462015-01-06 18:08:25 -080015"""Run tests in parallel."""
16
siddharthshukla0589e532016-07-07 16:08:01 +020017from __future__ import print_function
18
Nicolas Nobleddef2462015-01-06 18:08:25 -080019import argparse
Craig Tiller9279ac22016-01-20 17:05:23 -080020import ast
Masood Malekghassemi3b5b2062016-06-02 20:27:20 -070021import collections
Nicolas Nobleddef2462015-01-06 18:08:25 -080022import glob
23import itertools
Craig Tiller261dd982015-01-16 16:41:45 -080024import json
David Garcia Quintas0727c102017-02-21 10:48:35 -080025import logging
Nicolas Nobleddef2462015-01-06 18:08:25 -080026import multiprocessing
Craig Tiller1cc11db2015-01-15 22:50:50 -080027import os
Masood Malekghassemi3b5b2062016-06-02 20:27:20 -070028import os.path
Craig Tiller38fb8de2016-07-13 08:23:32 -070029import pipes
David Garcia Quintas79e389f2015-06-02 17:49:42 -070030import platform
31import random
Craig Tillerfe406ec2015-02-24 13:55:12 -080032import re
Craig Tiller82875232015-09-25 13:57:34 -070033import socket
David Garcia Quintas79e389f2015-06-02 17:49:42 -070034import subprocess
Nicolas Nobleddef2462015-01-06 18:08:25 -080035import sys
Craig Tillerf0a293e2015-10-12 10:05:50 -070036import tempfile
37import traceback
ctiller3040cb72015-01-07 12:13:17 -080038import time
siddharthshukla0589e532016-07-07 16:08:01 +020039from six.moves import urllib
Jan Tattermusch03c01062015-12-11 14:28:56 -080040import uuid
Siddharth Shuklad194f592017-03-11 19:12:43 +010041import six
Nicolas Nobleddef2462015-01-06 18:08:25 -080042
Jan Tattermusch5c79a312016-12-20 11:02:50 +010043import python_utils.jobset as jobset
44import python_utils.report_utils as report_utils
45import python_utils.watch_dirs as watch_dirs
Craig Tiller7dc4ea62017-02-02 16:08:05 -080046import python_utils.start_port_server as start_port_server
Matt Kwong52ff9862017-04-17 13:56:51 -070047try:
ncteisen888093c2017-12-11 18:00:40 -080048 from python_utils.upload_test_results import upload_results_to_bq
Matt Kwong52ff9862017-04-17 13:56:51 -070049except (ImportError):
ncteisen888093c2017-12-11 18:00:40 -080050 pass # It's ok to not import because this is only necessary to upload results to BQ.
Craig Tillerb361b4e2016-01-06 11:44:17 -080051
ncteisen888093c2017-12-11 18:00:40 -080052gcp_utils_dir = os.path.abspath(
53 os.path.join(os.path.dirname(__file__), '../gcp/utils'))
David Garcia Quintasfaafa4d2017-06-06 14:52:17 -070054sys.path.append(gcp_utils_dir)
David Garcia Quintasfaafa4d2017-06-06 14:52:17 -070055
Jan Tattermusch3b5121b2016-02-22 17:41:05 -080056_ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
57os.chdir(_ROOT)
Craig Tiller2cc2b842015-02-27 11:38:31 -080058
Craig Tiller8f18ee62016-07-18 08:00:33 -070059_FORCE_ENVIRON_FOR_WRAPPERS = {
ncteisen888093c2017-12-11 18:00:40 -080060 'GRPC_VERBOSITY': 'DEBUG',
Craig Tiller8f18ee62016-07-18 08:00:33 -070061}
Craig Tiller06805272015-06-11 14:46:47 -070062
Craig Tiller123f1372016-06-15 15:06:14 -070063_POLLING_STRATEGIES = {
ncteisen888093c2017-12-11 18:00:40 -080064 'linux': ['epollex', 'epollsig', 'epoll1', 'poll', 'poll-cv'],
65 'mac': ['poll'],
Craig Tiller123f1372016-06-15 15:06:14 -070066}
67
Craig Tiller9992bdb2017-09-06 15:00:31 -070068BigQueryTestData = collections.namedtuple('BigQueryTestData', 'name flaky cpu')
69
70
71def get_bqtest_data(limit=None):
ncteisen888093c2017-12-11 18:00:40 -080072 import big_query_utils
Craig Tillerd16abf82017-06-07 08:58:55 -070073
ncteisen888093c2017-12-11 18:00:40 -080074 bq = big_query_utils.create_big_query()
75 query = """
David Garcia Quintas48623592017-08-02 18:15:22 -070076SELECT
77 filtered_test_name,
Craig Tiller120d4fd2017-09-07 12:25:25 -070078 SUM(result != 'PASSED' AND result != 'SKIPPED') > 0 as flaky,
Craig Tillerf7617bb2017-09-13 09:47:28 -070079 MAX(cpu_measured) + 0.01 as cpu
David Garcia Quintas48623592017-08-02 18:15:22 -070080 FROM (
81 SELECT
82 REGEXP_REPLACE(test_name, r'/\d+', '') AS filtered_test_name,
Craig Tiller9992bdb2017-09-06 15:00:31 -070083 result, cpu_measured
David Garcia Quintas48623592017-08-02 18:15:22 -070084 FROM
85 [grpc-testing:jenkins_test_results.aggregate_results]
86 WHERE
87 timestamp >= DATE_ADD(CURRENT_DATE(), -1, "WEEK")
ncteisen888093c2017-12-11 18:00:40 -080088 AND platform = '""" + platform_string() + """'
David Garcia Quintas48623592017-08-02 18:15:22 -070089 AND NOT REGEXP_MATCH(job_name, '.*portability.*') )
90GROUP BY
Craig Tillerf7617bb2017-09-13 09:47:28 -070091 filtered_test_name"""
ncteisen888093c2017-12-11 18:00:40 -080092 if limit:
93 query += " limit {}".format(limit)
94 query_job = big_query_utils.sync_query_job(bq, 'grpc-testing', query)
95 page = bq.jobs().getQueryResults(
96 pageToken=None, **query_job['jobReference']).execute(num_retries=3)
97 test_data = [
98 BigQueryTestData(row['f'][0]['v'], row['f'][1]['v'] == 'true',
99 float(row['f'][2]['v'])) for row in page['rows']
100 ]
101 return test_data
David Garcia Quintasfaafa4d2017-06-06 14:52:17 -0700102
103
Craig Tillerd50993d2015-08-05 08:04:36 -0700104def platform_string():
ncteisen888093c2017-12-11 18:00:40 -0800105 return jobset.platform_string()
Craig Tillerd50993d2015-08-05 08:04:36 -0700106
107
Craig Tiller38fb8de2016-07-13 08:23:32 -0700108_DEFAULT_TIMEOUT_SECONDS = 5 * 60
109
ncteisen888093c2017-12-11 18:00:40 -0800110
David Garcia Quintas03920252017-02-15 12:51:21 -0800111def run_shell_command(cmd, env=None, cwd=None):
ncteisen888093c2017-12-11 18:00:40 -0800112 try:
113 subprocess.check_output(cmd, shell=True, env=env, cwd=cwd)
114 except subprocess.CalledProcessError as e:
115 logging.exception(
116 "Error while running command '%s'. Exit status %d. Output:\n%s",
117 e.cmd, e.returncode, e.output)
118 raise
119
Craig Tiller38fb8de2016-07-13 08:23:32 -0700120
Alexander Polcyndbfcd452017-10-01 15:34:29 -0700121def max_parallel_tests_for_current_platform():
ncteisen888093c2017-12-11 18:00:40 -0800122 # Too much test parallelization has only been seen to be a problem
123 # so far on windows.
124 if jobset.platform_string() == 'windows':
125 return 64
126 return 1024
127
Alexander Polcyndbfcd452017-10-01 15:34:29 -0700128
Craig Tiller738c3342015-01-12 14:28:33 -0800129# SimpleConfig: just compile with CONFIG=config, and run the binary to test
Craig Tillera0f85172016-01-20 15:56:06 -0800130class Config(object):
Craig Tillerb50d1662015-01-15 17:28:21 -0800131
ncteisen888093c2017-12-11 18:00:40 -0800132 def __init__(self,
133 config,
134 environ=None,
135 timeout_multiplier=1,
136 tool_prefix=[],
137 iomgr_platform='native'):
138 if environ is None:
139 environ = {}
140 self.build_config = config
141 self.environ = environ
142 self.environ['CONFIG'] = config
143 self.tool_prefix = tool_prefix
144 self.timeout_multiplier = timeout_multiplier
145 self.iomgr_platform = iomgr_platform
Craig Tiller738c3342015-01-12 14:28:33 -0800146
ncteisen888093c2017-12-11 18:00:40 -0800147 def job_spec(self,
148 cmdline,
149 timeout_seconds=_DEFAULT_TIMEOUT_SECONDS,
150 shortname=None,
151 environ={},
152 cpu_cost=1.0,
153 flaky=False):
154 """Construct a jobset.JobSpec for a test under this config
Craig Tiller49f61322015-03-03 13:02:11 -0800155
156 Args:
157 cmdline: a list of strings specifying the command line the test
158 would like to run
Craig Tiller49f61322015-03-03 13:02:11 -0800159 """
ncteisen888093c2017-12-11 18:00:40 -0800160 actual_environ = self.environ.copy()
161 for k, v in environ.items():
162 actual_environ[k] = v
163 if not flaky and shortname and shortname in flaky_tests:
164 flaky = True
165 if shortname in shortname_to_cpu:
166 cpu_cost = shortname_to_cpu[shortname]
167 return jobset.JobSpec(
168 cmdline=self.tool_prefix + cmdline,
169 shortname=shortname,
170 environ=actual_environ,
171 cpu_cost=cpu_cost,
172 timeout_seconds=(self.timeout_multiplier * timeout_seconds
173 if timeout_seconds else None),
174 flake_retries=4 if flaky or args.allow_flakes else 0,
175 timeout_retries=1 if flaky or args.allow_flakes else 0)
Craig Tiller738c3342015-01-12 14:28:33 -0800176
177
ncteisen888093c2017-12-11 18:00:40 -0800178def get_c_tests(travis, test_lang):
179 out = []
180 platforms_str = 'ci_platforms' if travis else 'platforms'
181 with open('tools/run_tests/generated/tests.json') as f:
182 js = json.load(f)
183 return [
184 tgt for tgt in js
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800185 if tgt['language'] == test_lang and platform_string() in
186 tgt[platforms_str] and not (travis and tgt['flaky'])
ncteisen888093c2017-12-11 18:00:40 -0800187 ]
murgatroid99cf08daf2015-09-21 15:33:16 -0700188
murgatroid99fafeeb32015-09-22 09:13:03 -0700189
Jan Tattermusch77db4322016-02-20 20:19:35 -0800190def _check_compiler(compiler, supported_compilers):
ncteisen888093c2017-12-11 18:00:40 -0800191 if compiler not in supported_compilers:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800192 raise Exception(
193 'Compiler %s not supported (on this platform).' % compiler)
Jan Tattermuschb2531e22016-03-25 16:14:41 -0700194
195
196def _check_arch(arch, supported_archs):
ncteisen888093c2017-12-11 18:00:40 -0800197 if arch not in supported_archs:
198 raise Exception('Architecture %s not supported.' % arch)
Jan Tattermusch77db4322016-02-20 20:19:35 -0800199
200
Jan Tattermuschc4cbe392016-02-22 19:29:38 -0800201def _is_use_docker_child():
ncteisen888093c2017-12-11 18:00:40 -0800202 """Returns True if running running as a --use_docker child."""
203 return True if os.getenv('RUN_TESTS_COMMAND') else False
Jan Tattermuschc4cbe392016-02-22 19:29:38 -0800204
205
ncteisen888093c2017-12-11 18:00:40 -0800206_PythonConfigVars = collections.namedtuple('_ConfigVars', [
207 'shell', 'builder', 'builder_prefix_arguments', 'venv_relative_python',
208 'toolchain', 'runner'
209])
siddharthshukla2135a1b2016-08-04 02:11:53 +0200210
211
212def _python_config_generator(name, major, minor, bits, config_vars):
ncteisen888093c2017-12-11 18:00:40 -0800213 return PythonConfig(
214 name, config_vars.shell + config_vars.builder +
215 config_vars.builder_prefix_arguments + [
216 _python_pattern_function(major=major, minor=minor, bits=bits)
217 ] + [name] + config_vars.venv_relative_python + config_vars.toolchain,
218 config_vars.shell + config_vars.runner +
219 [os.path.join(name, config_vars.venv_relative_python[0])])
siddharthshukla2135a1b2016-08-04 02:11:53 +0200220
221
222def _pypy_config_generator(name, major, config_vars):
ncteisen888093c2017-12-11 18:00:40 -0800223 return PythonConfig(
224 name,
225 config_vars.shell + config_vars.builder +
226 config_vars.builder_prefix_arguments + [
227 _pypy_pattern_function(major=major)
228 ] + [name] + config_vars.venv_relative_python + config_vars.toolchain,
229 config_vars.shell + config_vars.runner +
230 [os.path.join(name, config_vars.venv_relative_python[0])])
siddharthshukla2135a1b2016-08-04 02:11:53 +0200231
232
233def _python_pattern_function(major, minor, bits):
ncteisen888093c2017-12-11 18:00:40 -0800234 # Bit-ness is handled by the test machine's environment
235 if os.name == "nt":
236 if bits == "64":
237 return '/c/Python{major}{minor}/python.exe'.format(
238 major=major, minor=minor, bits=bits)
239 else:
240 return '/c/Python{major}{minor}_{bits}bits/python.exe'.format(
241 major=major, minor=minor, bits=bits)
siddharthshukla2135a1b2016-08-04 02:11:53 +0200242 else:
ncteisen888093c2017-12-11 18:00:40 -0800243 return 'python{major}.{minor}'.format(major=major, minor=minor)
siddharthshukla2135a1b2016-08-04 02:11:53 +0200244
245
246def _pypy_pattern_function(major):
ncteisen888093c2017-12-11 18:00:40 -0800247 if major == '2':
248 return 'pypy'
249 elif major == '3':
250 return 'pypy3'
251 else:
252 raise ValueError("Unknown PyPy major version")
siddharthshukla2135a1b2016-08-04 02:11:53 +0200253
254
Craig Tillerc7449162015-01-16 14:42:10 -0800255class CLanguage(object):
256
ncteisen888093c2017-12-11 18:00:40 -0800257 def __init__(self, make_target, test_lang):
258 self.make_target = make_target
259 self.platform = platform_string()
260 self.test_lang = test_lang
Craig Tillerc7449162015-01-16 14:42:10 -0800261
ncteisen888093c2017-12-11 18:00:40 -0800262 def configure(self, config, args):
263 self.config = config
264 self.args = args
Craig Tillerb38197e2016-02-26 10:14:54 -0800265 if self.platform == 'windows':
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800266 _check_compiler(
267 self.args.compiler,
268 ['default', 'cmake', 'cmake_vs2015', 'cmake_vs2017'])
ncteisen888093c2017-12-11 18:00:40 -0800269 _check_arch(self.args.arch, ['default', 'x64', 'x86'])
270 self._cmake_generator_option = 'Visual Studio 15 2017' if self.args.compiler == 'cmake_vs2017' else 'Visual Studio 14 2015'
271 self._cmake_arch_option = 'x64' if self.args.arch == 'x64' else 'Win32'
272 self._use_cmake = True
273 self._make_options = []
274 elif self.args.compiler == 'cmake':
275 _check_arch(self.args.arch, ['default'])
276 self._use_cmake = True
277 self._docker_distro = 'jessie'
278 self._make_options = []
Craig Tillerca62ff02016-02-24 22:22:57 -0800279 else:
ncteisen888093c2017-12-11 18:00:40 -0800280 self._use_cmake = False
281 self._docker_distro, self._make_options = self._compiler_options(
282 self.args.use_docker, self.args.compiler)
283 if args.iomgr_platform == "uv":
284 cflags = '-DGRPC_UV -DGRPC_UV_THREAD_CHECK'
285 try:
286 cflags += subprocess.check_output(
287 ['pkg-config', '--cflags', 'libuv']).strip() + ' '
288 except (subprocess.CalledProcessError, OSError):
289 pass
290 try:
291 ldflags = subprocess.check_output(
292 ['pkg-config', '--libs', 'libuv']).strip() + ' '
293 except (subprocess.CalledProcessError, OSError):
294 ldflags = '-luv '
295 self._make_options += [
296 'EXTRA_CPPFLAGS={}'.format(cflags),
297 'EXTRA_LDLIBS={}'.format(ldflags)
298 ]
ncteisend439b4e2017-09-11 17:57:18 -0700299
ncteisen888093c2017-12-11 18:00:40 -0800300 def test_specs(self):
301 out = []
302 binaries = get_c_tests(self.args.travis, self.test_lang)
303 for target in binaries:
304 if self._use_cmake and target.get('boringssl', False):
305 # cmake doesn't build boringssl tests
306 continue
307 auto_timeout_scaling = target.get('auto_timeout_scaling', True)
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800308 polling_strategies = (_POLLING_STRATEGIES.get(
309 self.platform, ['all']) if target.get('uses_polling', True) else
310 ['none'])
ncteisen888093c2017-12-11 18:00:40 -0800311 if self.args.iomgr_platform == 'uv':
312 polling_strategies = ['all']
313 for polling_strategy in polling_strategies:
314 env = {
315 'GRPC_DEFAULT_SSL_ROOTS_FILE_PATH':
316 _ROOT + '/src/core/tsi/test_creds/ca.pem',
317 'GRPC_POLL_STRATEGY':
318 polling_strategy,
319 'GRPC_VERBOSITY':
320 'DEBUG'
321 }
322 resolver = os.environ.get('GRPC_DNS_RESOLVER', None)
323 if resolver:
324 env['GRPC_DNS_RESOLVER'] = resolver
325 shortname_ext = '' if polling_strategy == 'all' else ' GRPC_POLL_STRATEGY=%s' % polling_strategy
326 if polling_strategy in target.get('excluded_poll_engines', []):
327 continue
Craig Tillerc7449162015-01-16 14:42:10 -0800328
ncteisen888093c2017-12-11 18:00:40 -0800329 timeout_scaling = 1
330 if auto_timeout_scaling:
331 config = self.args.config
332 if ('asan' in config or config == 'msan' or
333 config == 'tsan' or config == 'ubsan' or
334 config == 'helgrind' or config == 'memcheck'):
335 # Scale overall test timeout if running under various sanitizers.
336 # scaling value is based on historical data analysis
337 timeout_scaling *= 3
338 elif polling_strategy == 'poll-cv':
339 # scale test timeout if running with poll-cv
340 # sanitizer and poll-cv scaling is not cumulative to ensure
341 # reasonable timeout values.
342 # TODO(jtattermusch): based on historical data and 5min default
343 # test timeout poll-cv scaling is currently not useful.
344 # Leaving here so it can be reintroduced if the default test timeout
345 # is decreased in the future.
346 timeout_scaling *= 1
Craig Tillerc7449162015-01-16 14:42:10 -0800347
ncteisen888093c2017-12-11 18:00:40 -0800348 if self.config.build_config in target['exclude_configs']:
349 continue
350 if self.args.iomgr_platform in target.get('exclude_iomgrs', []):
351 continue
352 if self.platform == 'windows':
353 binary = 'cmake/build/%s/%s.exe' % (
354 _MSBUILD_CONFIG[self.config.build_config],
355 target['name'])
356 else:
357 if self._use_cmake:
358 binary = 'cmake/build/%s' % target['name']
359 else:
360 binary = 'bins/%s/%s' % (self.config.build_config,
361 target['name'])
362 cpu_cost = target['cpu_cost']
363 if cpu_cost == 'capacity':
364 cpu_cost = multiprocessing.cpu_count()
365 if os.path.isfile(binary):
366 list_test_command = None
367 filter_test_command = None
Jan Tattermuschc895fe02016-01-20 09:13:09 -0800368
ncteisen888093c2017-12-11 18:00:40 -0800369 # these are the flag defined by gtest and benchmark framework to list
370 # and filter test runs. We use them to split each individual test
371 # into its own JobSpec, and thus into its own process.
372 if 'benchmark' in target and target['benchmark']:
373 with open(os.devnull, 'w') as fnull:
374 tests = subprocess.check_output(
375 [binary, '--benchmark_list_tests'],
376 stderr=fnull)
377 for line in tests.split('\n'):
378 test = line.strip()
379 if not test: continue
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800380 cmdline = [binary,
381 '--benchmark_filter=%s$' % test
ncteisen888093c2017-12-11 18:00:40 -0800382 ] + target['args']
383 out.append(
384 self.config.job_spec(
385 cmdline,
386 shortname='%s %s' % (' '.join(cmdline),
387 shortname_ext),
388 cpu_cost=cpu_cost,
ncteisene2612aa2017-12-19 15:00:35 -0800389 timeout_seconds=target.get(
390 'timeout_seconds',
391 _DEFAULT_TIMEOUT_SECONDS) *
ncteisen888093c2017-12-11 18:00:40 -0800392 timeout_scaling,
393 environ=env))
394 elif 'gtest' in target and target['gtest']:
395 # here we parse the output of --gtest_list_tests to build up a complete
396 # list of the tests contained in a binary for each test, we then
397 # add a job to run, filtering for just that test.
398 with open(os.devnull, 'w') as fnull:
399 tests = subprocess.check_output(
400 [binary, '--gtest_list_tests'], stderr=fnull)
401 base = None
402 for line in tests.split('\n'):
403 i = line.find('#')
404 if i >= 0: line = line[:i]
405 if not line: continue
406 if line[0] != ' ':
407 base = line.strip()
408 else:
409 assert base is not None
410 assert line[1] == ' '
411 test = base + line.strip()
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800412 cmdline = [binary,
413 '--gtest_filter=%s' % test
ncteisen888093c2017-12-11 18:00:40 -0800414 ] + target['args']
415 out.append(
416 self.config.job_spec(
417 cmdline,
418 shortname='%s %s' % (' '.join(cmdline),
419 shortname_ext),
420 cpu_cost=cpu_cost,
421 timeout_seconds=target.get(
422 'timeout_seconds',
423 _DEFAULT_TIMEOUT_SECONDS) *
424 timeout_scaling,
425 environ=env))
426 else:
427 cmdline = [binary] + target['args']
428 shortname = target.get('shortname', ' '.join(
429 pipes.quote(arg) for arg in cmdline))
430 shortname += shortname_ext
431 out.append(
432 self.config.job_spec(
433 cmdline,
434 shortname=shortname,
435 cpu_cost=cpu_cost,
436 flaky=target.get('flaky', False),
437 timeout_seconds=target.get(
438 'timeout_seconds', _DEFAULT_TIMEOUT_SECONDS)
439 * timeout_scaling,
440 environ=env))
441 elif self.args.regex == '.*' or self.platform == 'windows':
442 print('\nWARNING: binary not found, skipping', binary)
443 return sorted(out)
murgatroid99256d3df2015-09-21 16:58:02 -0700444
ncteisen888093c2017-12-11 18:00:40 -0800445 def make_targets(self):
446 if self.platform == 'windows':
447 # don't build tools on windows just yet
448 return ['buildtests_%s' % self.make_target]
449 return [
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800450 'buildtests_%s' % self.make_target,
451 'tools_%s' % self.make_target, 'check_epollexclusive'
ncteisen888093c2017-12-11 18:00:40 -0800452 ]
Craig Tillerc7449162015-01-16 14:42:10 -0800453
ncteisen888093c2017-12-11 18:00:40 -0800454 def make_options(self):
455 return self._make_options
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +0200456
ncteisen888093c2017-12-11 18:00:40 -0800457 def pre_build_steps(self):
458 if self.platform == 'windows':
459 return [[
460 'tools\\run_tests\\helper_scripts\\pre_build_cmake.bat',
461 self._cmake_generator_option, self._cmake_arch_option
462 ]]
463 elif self._use_cmake:
464 return [['tools/run_tests/helper_scripts/pre_build_cmake.sh']]
465 else:
466 return []
murgatroid99a3e244f2015-09-22 11:25:53 -0700467
ncteisen888093c2017-12-11 18:00:40 -0800468 def build_steps(self):
469 return []
Jan Tattermuschd4726c12016-02-23 16:57:36 -0800470
ncteisen888093c2017-12-11 18:00:40 -0800471 def post_tests_steps(self):
472 if self.platform == 'windows':
473 return []
474 else:
475 return [['tools/run_tests/helper_scripts/post_tests_c.sh']]
Jan Tattermusch9bb70622016-03-18 10:28:54 -0700476
ncteisen888093c2017-12-11 18:00:40 -0800477 def makefile_name(self):
478 if self._use_cmake:
479 return 'cmake/build/Makefile'
480 else:
481 return 'Makefile'
Jan Tattermuschc4cbe392016-02-22 19:29:38 -0800482
ncteisen888093c2017-12-11 18:00:40 -0800483 def _clang_make_options(self, version_suffix=''):
484 return [
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800485 'CC=clang%s' % version_suffix,
486 'CXX=clang++%s' % version_suffix,
487 'LD=clang%s' % version_suffix,
488 'LDXX=clang++%s' % version_suffix
ncteisen888093c2017-12-11 18:00:40 -0800489 ]
Jan Tattermuschc4cbe392016-02-22 19:29:38 -0800490
ncteisen888093c2017-12-11 18:00:40 -0800491 def _gcc_make_options(self, version_suffix):
492 return [
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800493 'CC=gcc%s' % version_suffix,
494 'CXX=g++%s' % version_suffix,
495 'LD=gcc%s' % version_suffix,
496 'LDXX=g++%s' % version_suffix
ncteisen888093c2017-12-11 18:00:40 -0800497 ]
Jan Tattermusch788ee232016-01-26 12:19:44 -0800498
ncteisen888093c2017-12-11 18:00:40 -0800499 def _compiler_options(self, use_docker, compiler):
500 """Returns docker distro and make options to use for given compiler."""
501 if not use_docker and not _is_use_docker_child():
502 _check_compiler(compiler, ['default'])
503
504 if compiler == 'gcc4.9' or compiler == 'default':
505 return ('jessie', [])
506 elif compiler == 'gcc4.8':
507 return ('jessie', self._gcc_make_options(version_suffix='-4.8'))
508 elif compiler == 'gcc5.3':
509 return ('ubuntu1604', [])
510 elif compiler == 'gcc_musl':
511 return ('alpine', [])
512 elif compiler == 'clang3.4':
513 # on ubuntu1404, clang-3.4 alias doesn't exist, just use 'clang'
514 return ('ubuntu1404', self._clang_make_options())
515 elif compiler == 'clang3.5':
516 return ('jessie', self._clang_make_options(version_suffix='-3.5'))
517 elif compiler == 'clang3.6':
518 return ('ubuntu1604',
519 self._clang_make_options(version_suffix='-3.6'))
520 elif compiler == 'clang3.7':
521 return ('ubuntu1604',
522 self._clang_make_options(version_suffix='-3.7'))
523 else:
524 raise Exception('Compiler %s not supported.' % compiler)
525
526 def dockerfile_dir(self):
527 return 'tools/dockerfile/test/cxx_%s_%s' % (
528 self._docker_distro, _docker_arch_suffix(self.args.arch))
529
530 def __str__(self):
531 return self.make_target
murgatroid99132ce6a2015-03-04 17:29:14 -0800532
Craig Tillercc0535d2015-12-08 15:14:47 -0800533
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700534# This tests Node on grpc/grpc-node and will become the standard for Node testing
535class RemoteNodeLanguage(object):
536
ncteisen888093c2017-12-11 18:00:40 -0800537 def __init__(self):
538 self.platform = platform_string()
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700539
ncteisen888093c2017-12-11 18:00:40 -0800540 def configure(self, config, args):
541 self.config = config
542 self.args = args
543 # Note: electron ABI only depends on major and minor version, so that's all
544 # we should specify in the compiler argument
545 _check_compiler(self.args.compiler, [
546 'default', 'node0.12', 'node4', 'node5', 'node6', 'node7', 'node8',
547 'electron1.3', 'electron1.6'
548 ])
549 if self.args.compiler == 'default':
550 self.runtime = 'node'
551 self.node_version = '8'
552 else:
553 if self.args.compiler.startswith('electron'):
554 self.runtime = 'electron'
555 self.node_version = self.args.compiler[8:]
556 else:
557 self.runtime = 'node'
558 # Take off the word "node"
559 self.node_version = self.args.compiler[4:]
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700560
ncteisen888093c2017-12-11 18:00:40 -0800561 # TODO: update with Windows/electron scripts when available for grpc/grpc-node
562 def test_specs(self):
563 if self.platform == 'windows':
564 return [
565 self.config.job_spec(
566 ['tools\\run_tests\\helper_scripts\\run_node.bat'])
567 ]
568 else:
569 return [
570 self.config.job_spec(
571 ['tools/run_tests/helper_scripts/run_grpc-node.sh'],
572 None,
573 environ=_FORCE_ENVIRON_FOR_WRAPPERS)
574 ]
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700575
ncteisen888093c2017-12-11 18:00:40 -0800576 def pre_build_steps(self):
577 return []
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700578
ncteisen888093c2017-12-11 18:00:40 -0800579 def make_targets(self):
580 return []
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700581
ncteisen888093c2017-12-11 18:00:40 -0800582 def make_options(self):
583 return []
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700584
ncteisen888093c2017-12-11 18:00:40 -0800585 def build_steps(self):
586 return []
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700587
ncteisen888093c2017-12-11 18:00:40 -0800588 def post_tests_steps(self):
589 return []
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700590
ncteisen888093c2017-12-11 18:00:40 -0800591 def makefile_name(self):
592 return 'Makefile'
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700593
ncteisen888093c2017-12-11 18:00:40 -0800594 def dockerfile_dir(self):
595 return 'tools/dockerfile/test/node_jessie_%s' % _docker_arch_suffix(
596 self.args.arch)
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700597
ncteisen888093c2017-12-11 18:00:40 -0800598 def __str__(self):
599 return 'grpc-node'
Matt Kwonge2e7cf42017-09-15 11:17:04 -0700600
601
Craig Tillerc7449162015-01-16 14:42:10 -0800602class PhpLanguage(object):
603
ncteisen888093c2017-12-11 18:00:40 -0800604 def configure(self, config, args):
605 self.config = config
606 self.args = args
607 _check_compiler(self.args.compiler, ['default'])
608 self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true']
Jan Tattermusch77db4322016-02-20 20:19:35 -0800609
ncteisen888093c2017-12-11 18:00:40 -0800610 def test_specs(self):
611 return [
612 self.config.job_spec(
613 ['src/php/bin/run_tests.sh'],
614 environ=_FORCE_ENVIRON_FOR_WRAPPERS)
615 ]
Craig Tillerc7449162015-01-16 14:42:10 -0800616
ncteisen888093c2017-12-11 18:00:40 -0800617 def pre_build_steps(self):
618 return []
murgatroid99256d3df2015-09-21 16:58:02 -0700619
ncteisen888093c2017-12-11 18:00:40 -0800620 def make_targets(self):
621 return ['static_c', 'shared_c']
Craig Tillerc7449162015-01-16 14:42:10 -0800622
ncteisen888093c2017-12-11 18:00:40 -0800623 def make_options(self):
624 return self._make_options
Jan Tattermuschc895fe02016-01-20 09:13:09 -0800625
ncteisen888093c2017-12-11 18:00:40 -0800626 def build_steps(self):
627 return [['tools/run_tests/helper_scripts/build_php.sh']]
Craig Tillerc7449162015-01-16 14:42:10 -0800628
ncteisen888093c2017-12-11 18:00:40 -0800629 def post_tests_steps(self):
630 return [['tools/run_tests/helper_scripts/post_tests_php.sh']]
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +0200631
ncteisen888093c2017-12-11 18:00:40 -0800632 def makefile_name(self):
633 return 'Makefile'
murgatroid99a3e244f2015-09-22 11:25:53 -0700634
ncteisen888093c2017-12-11 18:00:40 -0800635 def dockerfile_dir(self):
636 return 'tools/dockerfile/test/php_jessie_%s' % _docker_arch_suffix(
637 self.args.arch)
Jan Tattermusch788ee232016-01-26 12:19:44 -0800638
ncteisen888093c2017-12-11 18:00:40 -0800639 def __str__(self):
640 return 'php'
murgatroid99132ce6a2015-03-04 17:29:14 -0800641
Craig Tillerc7449162015-01-16 14:42:10 -0800642
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700643class Php7Language(object):
644
ncteisen888093c2017-12-11 18:00:40 -0800645 def configure(self, config, args):
646 self.config = config
647 self.args = args
648 _check_compiler(self.args.compiler, ['default'])
649 self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true']
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700650
ncteisen888093c2017-12-11 18:00:40 -0800651 def test_specs(self):
652 return [
653 self.config.job_spec(
654 ['src/php/bin/run_tests.sh'],
655 environ=_FORCE_ENVIRON_FOR_WRAPPERS)
656 ]
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700657
ncteisen888093c2017-12-11 18:00:40 -0800658 def pre_build_steps(self):
659 return []
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700660
ncteisen888093c2017-12-11 18:00:40 -0800661 def make_targets(self):
662 return ['static_c', 'shared_c']
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700663
ncteisen888093c2017-12-11 18:00:40 -0800664 def make_options(self):
665 return self._make_options
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700666
ncteisen888093c2017-12-11 18:00:40 -0800667 def build_steps(self):
668 return [['tools/run_tests/helper_scripts/build_php.sh']]
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700669
ncteisen888093c2017-12-11 18:00:40 -0800670 def post_tests_steps(self):
671 return [['tools/run_tests/helper_scripts/post_tests_php.sh']]
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700672
ncteisen888093c2017-12-11 18:00:40 -0800673 def makefile_name(self):
674 return 'Makefile'
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700675
ncteisen888093c2017-12-11 18:00:40 -0800676 def dockerfile_dir(self):
677 return 'tools/dockerfile/test/php7_jessie_%s' % _docker_arch_suffix(
678 self.args.arch)
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700679
ncteisen888093c2017-12-11 18:00:40 -0800680 def __str__(self):
681 return 'php7'
Stanley Cheung2e2cdff2016-07-23 19:07:36 -0700682
683
ncteisen888093c2017-12-11 18:00:40 -0800684class PythonConfig(
685 collections.namedtuple('PythonConfig', ['name', 'build', 'run'])):
686 """Tuple of commands (named s.t. 'what it says on the tin' applies)"""
687
Masood Malekghassemi3b5b2062016-06-02 20:27:20 -0700688
Nathaniel Manista840615e2015-01-22 20:31:47 +0000689class PythonLanguage(object):
690
ncteisen888093c2017-12-11 18:00:40 -0800691 def configure(self, config, args):
692 self.config = config
693 self.args = args
694 self.pythons = self._get_pythons(self.args)
Jan Tattermusch77db4322016-02-20 20:19:35 -0800695
ncteisen888093c2017-12-11 18:00:40 -0800696 def test_specs(self):
697 # load list of known test suites
698 with open(
699 'src/python/grpcio_tests/tests/tests.json') as tests_json_file:
700 tests_json = json.load(tests_json_file)
701 environment = dict(_FORCE_ENVIRON_FOR_WRAPPERS)
702 return [
703 self.config.job_spec(
704 config.run,
705 timeout_seconds=5 * 60,
706 environ=dict(
707 list(environment.items()) + [(
708 'GRPC_PYTHON_TESTRUNNER_FILTER', str(suite_name))]),
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800709 shortname='%s.test.%s' % (config.name, suite_name),
710 ) for suite_name in tests_json for config in self.pythons
ncteisen888093c2017-12-11 18:00:40 -0800711 ]
Nathaniel Manista840615e2015-01-22 20:31:47 +0000712
ncteisen888093c2017-12-11 18:00:40 -0800713 def pre_build_steps(self):
714 return []
murgatroid99256d3df2015-09-21 16:58:02 -0700715
ncteisen888093c2017-12-11 18:00:40 -0800716 def make_targets(self):
717 return []
Nathaniel Manista840615e2015-01-22 20:31:47 +0000718
ncteisen888093c2017-12-11 18:00:40 -0800719 def make_options(self):
720 return []
Jan Tattermuschc895fe02016-01-20 09:13:09 -0800721
ncteisen888093c2017-12-11 18:00:40 -0800722 def build_steps(self):
723 return [config.build for config in self.pythons]
Nathaniel Manista840615e2015-01-22 20:31:47 +0000724
ncteisen888093c2017-12-11 18:00:40 -0800725 def post_tests_steps(self):
726 if self.config.build_config != 'gcov':
727 return []
728 else:
729 return [['tools/run_tests/helper_scripts/post_tests_python.sh']]
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +0200730
ncteisen888093c2017-12-11 18:00:40 -0800731 def makefile_name(self):
732 return 'Makefile'
murgatroid99a3e244f2015-09-22 11:25:53 -0700733
ncteisen888093c2017-12-11 18:00:40 -0800734 def dockerfile_dir(self):
735 return 'tools/dockerfile/test/python_%s_%s' % (
736 self.python_manager_name(), _docker_arch_suffix(self.args.arch))
siddharthshuklac4782142016-06-28 18:48:47 +0200737
ncteisen888093c2017-12-11 18:00:40 -0800738 def python_manager_name(self):
739 if self.args.compiler in ['python3.5', 'python3.6']:
740 return 'pyenv'
741 elif self.args.compiler == 'python_alpine':
742 return 'alpine'
743 else:
744 return 'jessie'
Jan Tattermusch788ee232016-01-26 12:19:44 -0800745
ncteisen888093c2017-12-11 18:00:40 -0800746 def _get_pythons(self, args):
747 if args.arch == 'x86':
748 bits = '32'
749 else:
750 bits = '64'
siddharthshukla2135a1b2016-08-04 02:11:53 +0200751
ncteisen888093c2017-12-11 18:00:40 -0800752 if os.name == 'nt':
753 shell = ['bash']
754 builder = [
755 os.path.abspath(
756 'tools/run_tests/helper_scripts/build_python_msys2.sh')
757 ]
758 builder_prefix_arguments = ['MINGW{}'.format(bits)]
759 venv_relative_python = ['Scripts/python.exe']
760 toolchain = ['mingw32']
761 else:
762 shell = []
763 builder = [
764 os.path.abspath(
765 'tools/run_tests/helper_scripts/build_python.sh')
766 ]
767 builder_prefix_arguments = []
768 venv_relative_python = ['bin/python']
769 toolchain = ['unix']
siddharthshukla2135a1b2016-08-04 02:11:53 +0200770
ncteisen888093c2017-12-11 18:00:40 -0800771 runner = [
772 os.path.abspath('tools/run_tests/helper_scripts/run_python.sh')
773 ]
774 config_vars = _PythonConfigVars(shell, builder,
775 builder_prefix_arguments,
776 venv_relative_python, toolchain, runner)
777 python27_config = _python_config_generator(
778 name='py27',
779 major='2',
780 minor='7',
781 bits=bits,
782 config_vars=config_vars)
783 python34_config = _python_config_generator(
784 name='py34',
785 major='3',
786 minor='4',
787 bits=bits,
788 config_vars=config_vars)
789 python35_config = _python_config_generator(
790 name='py35',
791 major='3',
792 minor='5',
793 bits=bits,
794 config_vars=config_vars)
795 python36_config = _python_config_generator(
796 name='py36',
797 major='3',
798 minor='6',
799 bits=bits,
800 config_vars=config_vars)
801 pypy27_config = _pypy_config_generator(
802 name='pypy', major='2', config_vars=config_vars)
803 pypy32_config = _pypy_config_generator(
804 name='pypy3', major='3', config_vars=config_vars)
siddharthshukla2135a1b2016-08-04 02:11:53 +0200805
ncteisen888093c2017-12-11 18:00:40 -0800806 if args.compiler == 'default':
807 if os.name == 'nt':
808 return (python35_config,)
809 else:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800810 return (
811 python27_config,
812 python34_config,
813 )
ncteisen888093c2017-12-11 18:00:40 -0800814 elif args.compiler == 'python2.7':
815 return (python27_config,)
816 elif args.compiler == 'python3.4':
817 return (python34_config,)
818 elif args.compiler == 'python3.5':
819 return (python35_config,)
820 elif args.compiler == 'python3.6':
821 return (python36_config,)
822 elif args.compiler == 'pypy':
823 return (pypy27_config,)
824 elif args.compiler == 'pypy3':
825 return (pypy32_config,)
826 elif args.compiler == 'python_alpine':
827 return (python27_config,)
828 elif args.compiler == 'all_the_cpythons':
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800829 return (
830 python27_config,
831 python34_config,
832 python35_config,
833 python36_config,
834 )
ncteisen888093c2017-12-11 18:00:40 -0800835 else:
836 raise Exception('Compiler %s not supported.' % args.compiler)
Jan Tattermusch825471c2016-04-25 16:52:25 -0700837
ncteisen888093c2017-12-11 18:00:40 -0800838 def __str__(self):
839 return 'python'
murgatroid99132ce6a2015-03-04 17:29:14 -0800840
Craig Tillerd625d812015-04-08 15:52:35 -0700841
murgatroid996a4c4fa2015-02-27 12:08:57 -0800842class RubyLanguage(object):
843
ncteisen888093c2017-12-11 18:00:40 -0800844 def configure(self, config, args):
845 self.config = config
846 self.args = args
847 _check_compiler(self.args.compiler, ['default'])
Jan Tattermusch77db4322016-02-20 20:19:35 -0800848
ncteisen888093c2017-12-11 18:00:40 -0800849 def test_specs(self):
850 tests = [
851 self.config.job_spec(
852 ['tools/run_tests/helper_scripts/run_ruby.sh'],
853 timeout_seconds=10 * 60,
854 environ=_FORCE_ENVIRON_FOR_WRAPPERS)
855 ]
856 tests.append(
857 self.config.job_spec(
858 ['tools/run_tests/helper_scripts/run_ruby_end2end_tests.sh'],
859 timeout_seconds=10 * 60,
860 environ=_FORCE_ENVIRON_FOR_WRAPPERS))
861 return tests
murgatroid996a4c4fa2015-02-27 12:08:57 -0800862
ncteisen888093c2017-12-11 18:00:40 -0800863 def pre_build_steps(self):
864 return [['tools/run_tests/helper_scripts/pre_build_ruby.sh']]
murgatroid99256d3df2015-09-21 16:58:02 -0700865
ncteisen888093c2017-12-11 18:00:40 -0800866 def make_targets(self):
867 return []
murgatroid996a4c4fa2015-02-27 12:08:57 -0800868
ncteisen888093c2017-12-11 18:00:40 -0800869 def make_options(self):
870 return []
Jan Tattermuschc895fe02016-01-20 09:13:09 -0800871
ncteisen888093c2017-12-11 18:00:40 -0800872 def build_steps(self):
873 return [['tools/run_tests/helper_scripts/build_ruby.sh']]
murgatroid996a4c4fa2015-02-27 12:08:57 -0800874
ncteisen888093c2017-12-11 18:00:40 -0800875 def post_tests_steps(self):
876 return [['tools/run_tests/helper_scripts/post_tests_ruby.sh']]
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +0200877
ncteisen888093c2017-12-11 18:00:40 -0800878 def makefile_name(self):
879 return 'Makefile'
murgatroid99a3e244f2015-09-22 11:25:53 -0700880
ncteisen888093c2017-12-11 18:00:40 -0800881 def dockerfile_dir(self):
882 return 'tools/dockerfile/test/ruby_jessie_%s' % _docker_arch_suffix(
883 self.args.arch)
Jan Tattermusch788ee232016-01-26 12:19:44 -0800884
ncteisen888093c2017-12-11 18:00:40 -0800885 def __str__(self):
886 return 'ruby'
murgatroid99132ce6a2015-03-04 17:29:14 -0800887
Craig Tillerd625d812015-04-08 15:52:35 -0700888
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800889class CSharpLanguage(object):
Jan Tattermusch77db4322016-02-20 20:19:35 -0800890
ncteisen888093c2017-12-11 18:00:40 -0800891 def __init__(self):
892 self.platform = platform_string()
Jan Tattermuschb00aa672015-06-01 15:48:03 -0700893
ncteisen888093c2017-12-11 18:00:40 -0800894 def configure(self, config, args):
895 self.config = config
896 self.args = args
897 if self.platform == 'windows':
898 _check_compiler(self.args.compiler, ['coreclr', 'default'])
899 _check_arch(self.args.arch, ['default'])
900 self._cmake_arch_option = 'x64'
901 self._make_options = []
902 else:
903 _check_compiler(self.args.compiler, ['default', 'coreclr'])
904 self._docker_distro = 'jessie'
Jan Tattermusch76511a52016-06-17 14:00:57 -0700905
ncteisen888093c2017-12-11 18:00:40 -0800906 if self.platform == 'mac':
907 # TODO(jtattermusch): EMBED_ZLIB=true currently breaks the mac build
908 self._make_options = ['EMBED_OPENSSL=true']
909 if self.args.compiler != 'coreclr':
910 # On Mac, official distribution of mono is 32bit.
911 self._make_options += ['ARCH_FLAGS=-m32', 'LDFLAGS=-m32']
912 else:
913 self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true']
Jan Tattermusch77db4322016-02-20 20:19:35 -0800914
ncteisen888093c2017-12-11 18:00:40 -0800915 def test_specs(self):
916 with open('src/csharp/tests.json') as f:
917 tests_by_assembly = json.load(f)
Jan Tattermusch03c01062015-12-11 14:28:56 -0800918
ncteisen888093c2017-12-11 18:00:40 -0800919 msbuild_config = _MSBUILD_CONFIG[self.config.build_config]
920 nunit_args = ['--labels=All', '--noresult', '--workers=1']
921 assembly_subdir = 'bin/%s' % msbuild_config
922 assembly_extension = '.exe'
Jan Tattermusch76511a52016-06-17 14:00:57 -0700923
ncteisen888093c2017-12-11 18:00:40 -0800924 if self.args.compiler == 'coreclr':
925 assembly_subdir += '/netcoreapp1.0'
926 runtime_cmd = ['dotnet', 'exec']
927 assembly_extension = '.dll'
928 else:
929 assembly_subdir += '/net45'
930 if self.platform == 'windows':
931 runtime_cmd = []
932 else:
933 runtime_cmd = ['mono']
Jan Tattermuschbf3b1532015-10-26 10:24:42 -0700934
ncteisen888093c2017-12-11 18:00:40 -0800935 specs = []
936 for assembly in six.iterkeys(tests_by_assembly):
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800937 assembly_file = 'src/csharp/%s/%s/%s%s' % (assembly,
938 assembly_subdir,
939 assembly,
940 assembly_extension)
ncteisen888093c2017-12-11 18:00:40 -0800941 if self.config.build_config != 'gcov' or self.platform != 'windows':
942 # normally, run each test as a separate process
943 for test in tests_by_assembly[assembly]:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800944 cmdline = runtime_cmd + [assembly_file,
945 '--test=%s' % test] + nunit_args
ncteisen888093c2017-12-11 18:00:40 -0800946 specs.append(
947 self.config.job_spec(
948 cmdline,
949 shortname='csharp.%s' % test,
950 environ=_FORCE_ENVIRON_FOR_WRAPPERS))
951 else:
952 # For C# test coverage, run all tests from the same assembly at once
953 # using OpenCover.Console (only works on Windows).
954 cmdline = [
955 'src\\csharp\\packages\\OpenCover.4.6.519\\tools\\OpenCover.Console.exe',
956 '-target:%s' % assembly_file, '-targetdir:src\\csharp',
957 '-targetargs:%s' % ' '.join(nunit_args),
958 '-filter:+[Grpc.Core]*', '-register:user',
959 '-output:src\\csharp\\coverage_csharp_%s.xml' % assembly
960 ]
Jan Tattermusch38ed2cf2016-04-09 16:24:16 -0700961
ncteisen888093c2017-12-11 18:00:40 -0800962 # set really high cpu_cost to make sure instances of OpenCover.Console run exclusively
963 # to prevent problems with registering the profiler.
964 run_exclusive = 1000000
965 specs.append(
966 self.config.job_spec(
967 cmdline,
968 shortname='csharp.coverage.%s' % assembly,
969 cpu_cost=run_exclusive,
970 environ=_FORCE_ENVIRON_FOR_WRAPPERS))
971 return specs
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800972
ncteisen888093c2017-12-11 18:00:40 -0800973 def pre_build_steps(self):
974 if self.platform == 'windows':
975 return [[
976 'tools\\run_tests\\helper_scripts\\pre_build_csharp.bat',
977 self._cmake_arch_option
978 ]]
979 else:
980 return [['tools/run_tests/helper_scripts/pre_build_csharp.sh']]
murgatroid99256d3df2015-09-21 16:58:02 -0700981
ncteisen888093c2017-12-11 18:00:40 -0800982 def make_targets(self):
983 return ['grpc_csharp_ext']
Jan Tattermusch1970a5b2015-03-03 15:17:25 -0800984
ncteisen888093c2017-12-11 18:00:40 -0800985 def make_options(self):
986 return self._make_options
Jan Tattermuschc895fe02016-01-20 09:13:09 -0800987
ncteisen888093c2017-12-11 18:00:40 -0800988 def build_steps(self):
989 if self.platform == 'windows':
990 return [['tools\\run_tests\\helper_scripts\\build_csharp.bat']]
991 else:
992 return [['tools/run_tests/helper_scripts/build_csharp.sh']]
Nathaniel Manista840615e2015-01-22 20:31:47 +0000993
ncteisen888093c2017-12-11 18:00:40 -0800994 def post_tests_steps(self):
995 if self.platform == 'windows':
996 return [['tools\\run_tests\\helper_scripts\\post_tests_csharp.bat']]
997 else:
998 return [['tools/run_tests/helper_scripts/post_tests_csharp.sh']]
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +0200999
ncteisen888093c2017-12-11 18:00:40 -08001000 def makefile_name(self):
1001 if self.platform == 'windows':
1002 return 'cmake/build/%s/Makefile' % self._cmake_arch_option
1003 else:
1004 return 'Makefile'
murgatroid99a3e244f2015-09-22 11:25:53 -07001005
ncteisen888093c2017-12-11 18:00:40 -08001006 def dockerfile_dir(self):
1007 return 'tools/dockerfile/test/csharp_%s_%s' % (
1008 self._docker_distro, _docker_arch_suffix(self.args.arch))
Jan Tattermusch788ee232016-01-26 12:19:44 -08001009
ncteisen888093c2017-12-11 18:00:40 -08001010 def __str__(self):
1011 return 'csharp'
murgatroid99132ce6a2015-03-04 17:29:14 -08001012
Craig Tillerd625d812015-04-08 15:52:35 -07001013
Jorge Canizalesa0b3bfa2015-07-30 19:25:52 -07001014class ObjCLanguage(object):
1015
ncteisen888093c2017-12-11 18:00:40 -08001016 def configure(self, config, args):
1017 self.config = config
1018 self.args = args
1019 _check_compiler(self.args.compiler, ['default'])
Jan Tattermusch77db4322016-02-20 20:19:35 -08001020
ncteisen888093c2017-12-11 18:00:40 -08001021 def test_specs(self):
1022 return [
1023 self.config.job_spec(
1024 ['src/objective-c/tests/run_tests.sh'],
1025 timeout_seconds=60 * 60,
1026 shortname='objc-tests',
1027 cpu_cost=1e6,
1028 environ=_FORCE_ENVIRON_FOR_WRAPPERS),
1029 self.config.job_spec(
1030 ['src/objective-c/tests/run_plugin_tests.sh'],
1031 timeout_seconds=60 * 60,
1032 shortname='objc-plugin-tests',
1033 cpu_cost=1e6,
1034 environ=_FORCE_ENVIRON_FOR_WRAPPERS),
1035 self.config.job_spec(
1036 ['src/objective-c/tests/build_one_example.sh'],
1037 timeout_seconds=10 * 60,
1038 shortname='objc-build-example-helloworld',
1039 cpu_cost=1e6,
1040 environ={
1041 'SCHEME': 'HelloWorld',
1042 'EXAMPLE_PATH': 'examples/objective-c/helloworld'
1043 }),
1044 self.config.job_spec(
1045 ['src/objective-c/tests/build_one_example.sh'],
1046 timeout_seconds=10 * 60,
1047 shortname='objc-build-example-routeguide',
1048 cpu_cost=1e6,
1049 environ={
1050 'SCHEME': 'RouteGuideClient',
1051 'EXAMPLE_PATH': 'examples/objective-c/route_guide'
1052 }),
1053 self.config.job_spec(
1054 ['src/objective-c/tests/build_one_example.sh'],
1055 timeout_seconds=10 * 60,
1056 shortname='objc-build-example-authsample',
1057 cpu_cost=1e6,
1058 environ={
1059 'SCHEME': 'AuthSample',
1060 'EXAMPLE_PATH': 'examples/objective-c/auth_sample'
1061 }),
1062 self.config.job_spec(
1063 ['src/objective-c/tests/build_one_example.sh'],
1064 timeout_seconds=10 * 60,
1065 shortname='objc-build-example-sample',
1066 cpu_cost=1e6,
1067 environ={
1068 'SCHEME': 'Sample',
1069 'EXAMPLE_PATH': 'src/objective-c/examples/Sample'
1070 }),
1071 self.config.job_spec(
1072 ['src/objective-c/tests/build_one_example.sh'],
1073 timeout_seconds=10 * 60,
1074 shortname='objc-build-example-sample-frameworks',
1075 cpu_cost=1e6,
1076 environ={
1077 'SCHEME': 'Sample',
1078 'EXAMPLE_PATH': 'src/objective-c/examples/Sample',
1079 'FRAMEWORKS': 'YES'
1080 }),
1081 self.config.job_spec(
1082 ['src/objective-c/tests/build_one_example.sh'],
1083 timeout_seconds=10 * 60,
1084 shortname='objc-build-example-switftsample',
1085 cpu_cost=1e6,
1086 environ={
1087 'SCHEME': 'SwiftSample',
1088 'EXAMPLE_PATH': 'src/objective-c/examples/SwiftSample'
1089 }),
1090 ]
Jorge Canizalesa0b3bfa2015-07-30 19:25:52 -07001091
ncteisen888093c2017-12-11 18:00:40 -08001092 def pre_build_steps(self):
1093 return []
murgatroid99256d3df2015-09-21 16:58:02 -07001094
ncteisen888093c2017-12-11 18:00:40 -08001095 def make_targets(self):
1096 return ['interop_server']
Jorge Canizalesa0b3bfa2015-07-30 19:25:52 -07001097
ncteisen888093c2017-12-11 18:00:40 -08001098 def make_options(self):
1099 return []
Jan Tattermuschc895fe02016-01-20 09:13:09 -08001100
ncteisen888093c2017-12-11 18:00:40 -08001101 def build_steps(self):
1102 return [['src/objective-c/tests/build_tests.sh']]
Jorge Canizalesa0b3bfa2015-07-30 19:25:52 -07001103
ncteisen888093c2017-12-11 18:00:40 -08001104 def post_tests_steps(self):
1105 return []
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +02001106
ncteisen888093c2017-12-11 18:00:40 -08001107 def makefile_name(self):
1108 return 'Makefile'
murgatroid99a3e244f2015-09-22 11:25:53 -07001109
ncteisen888093c2017-12-11 18:00:40 -08001110 def dockerfile_dir(self):
1111 return None
Jan Tattermusch788ee232016-01-26 12:19:44 -08001112
ncteisen888093c2017-12-11 18:00:40 -08001113 def __str__(self):
1114 return 'objc'
Jorge Canizalesa0b3bfa2015-07-30 19:25:52 -07001115
1116
Nicolas "Pixel" Noble9f728642015-03-24 18:50:30 +01001117class Sanity(object):
1118
ncteisen888093c2017-12-11 18:00:40 -08001119 def configure(self, config, args):
1120 self.config = config
1121 self.args = args
1122 _check_compiler(self.args.compiler, ['default'])
Jan Tattermusch77db4322016-02-20 20:19:35 -08001123
ncteisen888093c2017-12-11 18:00:40 -08001124 def test_specs(self):
1125 import yaml
1126 with open('tools/run_tests/sanity/sanity_tests.yaml', 'r') as f:
1127 environ = {'TEST': 'true'}
1128 if _is_use_docker_child():
1129 environ['CLANG_FORMAT_SKIP_DOCKER'] = 'true'
Noah Eisene737ae92018-01-16 18:02:04 -08001130 environ['CLANG_TIDY_SKIP_DOCKER'] = 'true'
ncteisen888093c2017-12-11 18:00:40 -08001131 return [
1132 self.config.job_spec(
1133 cmd['script'].split(),
1134 timeout_seconds=30 * 60,
1135 environ=environ,
1136 cpu_cost=cmd.get('cpu_cost', 1)) for cmd in yaml.load(f)
1137 ]
Nicolas "Pixel" Noble9f728642015-03-24 18:50:30 +01001138
ncteisen888093c2017-12-11 18:00:40 -08001139 def pre_build_steps(self):
1140 return []
murgatroid99256d3df2015-09-21 16:58:02 -07001141
ncteisen888093c2017-12-11 18:00:40 -08001142 def make_targets(self):
1143 return ['run_dep_checks']
Nicolas "Pixel" Noble9f728642015-03-24 18:50:30 +01001144
ncteisen888093c2017-12-11 18:00:40 -08001145 def make_options(self):
1146 return []
Jan Tattermuschc895fe02016-01-20 09:13:09 -08001147
ncteisen888093c2017-12-11 18:00:40 -08001148 def build_steps(self):
1149 return []
Nicolas "Pixel" Noble9f728642015-03-24 18:50:30 +01001150
ncteisen888093c2017-12-11 18:00:40 -08001151 def post_tests_steps(self):
1152 return []
Nicolas "Pixel" Noble87879b32015-10-12 23:28:53 +02001153
ncteisen888093c2017-12-11 18:00:40 -08001154 def makefile_name(self):
1155 return 'Makefile'
murgatroid99a3e244f2015-09-22 11:25:53 -07001156
ncteisen888093c2017-12-11 18:00:40 -08001157 def dockerfile_dir(self):
1158 return 'tools/dockerfile/test/sanity'
Jan Tattermusch788ee232016-01-26 12:19:44 -08001159
ncteisen888093c2017-12-11 18:00:40 -08001160 def __str__(self):
1161 return 'sanity'
1162
Nicolas "Pixel" Noble9f728642015-03-24 18:50:30 +01001163
Craig Tiller738c3342015-01-12 14:28:33 -08001164# different configurations we can run under
Jan Tattermusch5c79a312016-12-20 11:02:50 +01001165with open('tools/run_tests/generated/configs.json') as f:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001166 _CONFIGS = dict(
1167 (cfg['config'], Config(**cfg)) for cfg in ast.literal_eval(f.read()))
Craig Tiller738c3342015-01-12 14:28:33 -08001168
Craig Tillerc7449162015-01-16 14:42:10 -08001169_LANGUAGES = {
Craig Tillere9c959d2015-01-18 10:23:26 -08001170 'c++': CLanguage('cxx', 'c++'),
1171 'c': CLanguage('c', 'c'),
Matt Kwonge2e7cf42017-09-15 11:17:04 -07001172 'grpc-node': RemoteNodeLanguage(),
Nathaniel Manista840615e2015-01-22 20:31:47 +00001173 'php': PhpLanguage(),
Stanley Cheung2e2cdff2016-07-23 19:07:36 -07001174 'php7': Php7Language(),
Nathaniel Manista840615e2015-01-22 20:31:47 +00001175 'python': PythonLanguage(),
Jan Tattermusch1970a5b2015-03-03 15:17:25 -08001176 'ruby': RubyLanguage(),
Nicolas "Pixel" Noble9f728642015-03-24 18:50:30 +01001177 'csharp': CSharpLanguage(),
ncteisen888093c2017-12-11 18:00:40 -08001178 'objc': ObjCLanguage(),
Jan Tattermusch70a57e42016-02-20 18:50:27 -08001179 'sanity': Sanity()
ncteisen888093c2017-12-11 18:00:40 -08001180}
Jan Tattermusch77db4322016-02-20 20:19:35 -08001181
Jan Tattermuscha2d964c2016-02-22 17:33:09 -08001182_MSBUILD_CONFIG = {
Craig Tiller7bb3efd2015-09-01 08:04:03 -07001183 'dbg': 'Debug',
1184 'opt': 'Release',
Jan Tattermusche4a69182015-12-15 09:53:01 -08001185 'gcov': 'Debug',
ncteisen888093c2017-12-11 18:00:40 -08001186}
Craig Tiller7bb3efd2015-09-01 08:04:03 -07001187
David Garcia Quintase90cd372015-05-31 18:15:26 -07001188
Jan Tattermusch2dd156e2015-12-04 18:26:17 -08001189def _windows_arch_option(arch):
ncteisen888093c2017-12-11 18:00:40 -08001190 """Returns msbuild cmdline option for selected architecture."""
1191 if arch == 'default' or arch == 'x86':
1192 return '/p:Platform=Win32'
1193 elif arch == 'x64':
1194 return '/p:Platform=x64'
1195 else:
1196 print('Architecture %s not supported.' % arch)
1197 sys.exit(1)
Jan Tattermusch788ee232016-01-26 12:19:44 -08001198
Jan Tattermuschf08018a2016-01-26 08:22:09 -08001199
1200def _check_arch_option(arch):
ncteisen888093c2017-12-11 18:00:40 -08001201 """Checks that architecture option is valid."""
1202 if platform_string() == 'windows':
1203 _windows_arch_option(arch)
1204 elif platform_string() == 'linux':
1205 # On linux, we need to be running under docker with the right architecture.
1206 runtime_arch = platform.architecture()[0]
1207 if arch == 'default':
1208 return
1209 elif runtime_arch == '64bit' and arch == 'x64':
1210 return
1211 elif runtime_arch == '32bit' and arch == 'x86':
1212 return
1213 else:
1214 print('Architecture %s does not match current runtime architecture.'
1215 % arch)
1216 sys.exit(1)
Jan Tattermuschf08018a2016-01-26 08:22:09 -08001217 else:
ncteisen888093c2017-12-11 18:00:40 -08001218 if args.arch != 'default':
1219 print('Architecture %s not supported on current platform.' %
1220 args.arch)
1221 sys.exit(1)
Jan Tattermusch2dd156e2015-12-04 18:26:17 -08001222
Jan Tattermusch4dc9e722016-01-25 17:00:54 -08001223
Jan Tattermusche70b3c52016-02-07 20:21:02 -08001224def _docker_arch_suffix(arch):
ncteisen888093c2017-12-11 18:00:40 -08001225 """Returns suffix to dockerfile dir to use."""
1226 if arch == 'default' or arch == 'x64':
1227 return 'x64'
1228 elif arch == 'x86':
1229 return 'x86'
1230 else:
1231 print('Architecture %s not supported with current settings.' % arch)
1232 sys.exit(1)
Jan Tattermusche70b3c52016-02-07 20:21:02 -08001233
1234
David Garcia Quintase90cd372015-05-31 18:15:26 -07001235def runs_per_test_type(arg_str):
1236 """Auxilary function to parse the "runs_per_test" flag.
1237
1238 Returns:
1239 A positive integer or 0, the latter indicating an infinite number of
1240 runs.
1241
1242 Raises:
1243 argparse.ArgumentTypeError: Upon invalid input.
1244 """
1245 if arg_str == 'inf':
1246 return 0
1247 try:
1248 n = int(arg_str)
1249 if n <= 0: raise ValueError
Craig Tiller50e53e22015-06-01 20:18:21 -07001250 return n
David Garcia Quintase90cd372015-05-31 18:15:26 -07001251 except:
Adele Zhoue4c35612015-10-16 15:34:23 -07001252 msg = '\'{}\' is not a positive integer or \'inf\''.format(arg_str)
David Garcia Quintase90cd372015-05-31 18:15:26 -07001253 raise argparse.ArgumentTypeError(msg)
Jan Tattermuschc95eead2015-09-18 13:03:50 -07001254
siddharthshukla2135a1b2016-08-04 02:11:53 +02001255
David Garcia Quintas95b37b72017-02-15 16:49:49 -08001256def percent_type(arg_str):
ncteisen888093c2017-12-11 18:00:40 -08001257 pct = float(arg_str)
1258 if pct > 100 or pct < 0:
1259 raise argparse.ArgumentTypeError(
1260 "'%f' is not a valid percentage in the [0, 100] range" % pct)
1261 return pct
1262
David Garcia Quintas95b37b72017-02-15 16:49:49 -08001263
1264# This is math.isclose in python >= 3.5
1265def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
ncteisen888093c2017-12-11 18:00:40 -08001266 return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
David Garcia Quintas95b37b72017-02-15 16:49:49 -08001267
1268
Jan Tattermuschc95eead2015-09-18 13:03:50 -07001269# parse command line
1270argp = argparse.ArgumentParser(description='Run grpc tests.')
ncteisen888093c2017-12-11 18:00:40 -08001271argp.add_argument(
1272 '-c', '--config', choices=sorted(_CONFIGS.keys()), default='opt')
1273argp.add_argument(
1274 '-n',
1275 '--runs_per_test',
1276 default=1,
1277 type=runs_per_test_type,
1278 help='A positive integer or "inf". If "inf", all tests will run in an '
1279 'infinite loop. Especially useful in combination with "-f"')
Craig Tillerfe406ec2015-02-24 13:55:12 -08001280argp.add_argument('-r', '--regex', default='.*', type=str)
Vijay Pai488fd0e2016-06-13 12:37:12 -07001281argp.add_argument('--regex_exclude', default='', type=str)
Craig Tiller5f735a62016-01-20 09:31:15 -08001282argp.add_argument('-j', '--jobs', default=multiprocessing.cpu_count(), type=int)
Craig Tiller8451e872015-02-27 09:25:51 -08001283argp.add_argument('-s', '--slowdown', default=1.0, type=float)
ncteisen888093c2017-12-11 18:00:40 -08001284argp.add_argument(
1285 '-p',
1286 '--sample_percent',
1287 default=100.0,
1288 type=percent_type,
1289 help='Run a random sample with that percentage of tests')
1290argp.add_argument(
1291 '-f', '--forever', default=False, action='store_const', const=True)
1292argp.add_argument(
1293 '-t', '--travis', default=False, action='store_const', const=True)
1294argp.add_argument(
1295 '--newline_on_success', default=False, action='store_const', const=True)
1296argp.add_argument(
1297 '-l',
1298 '--language',
1299 choices=['all'] + sorted(_LANGUAGES.keys()),
1300 nargs='+',
1301 default=['all'])
1302argp.add_argument(
1303 '-S', '--stop_on_failure', default=False, action='store_const', const=True)
1304argp.add_argument(
1305 '--use_docker',
1306 default=False,
1307 action='store_const',
1308 const=True,
1309 help='Run all the tests under docker. That provides ' +
1310 'additional isolation and prevents the need to install ' +
1311 'language specific prerequisites. Only available on Linux.')
1312argp.add_argument(
1313 '--allow_flakes',
1314 default=False,
1315 action='store_const',
1316 const=True,
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001317 help=
1318 'Allow flaky tests to show as passing (re-runs failed tests up to five times)'
ncteisen888093c2017-12-11 18:00:40 -08001319)
1320argp.add_argument(
1321 '--arch',
1322 choices=['default', 'x86', 'x64'],
1323 default='default',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001324 help=
1325 'Selects architecture to target. For some platforms "default" is the only supported choice.'
ncteisen888093c2017-12-11 18:00:40 -08001326)
1327argp.add_argument(
1328 '--compiler',
1329 choices=[
1330 'default', 'gcc4.4', 'gcc4.6', 'gcc4.8', 'gcc4.9', 'gcc5.3', 'gcc_musl',
1331 'clang3.4', 'clang3.5', 'clang3.6', 'clang3.7', 'python2.7',
1332 'python3.4', 'python3.5', 'python3.6', 'pypy', 'pypy3', 'python_alpine',
1333 'all_the_cpythons', 'electron1.3', 'electron1.6', 'coreclr', 'cmake',
1334 'cmake_vs2015', 'cmake_vs2017'
1335 ],
1336 default='default',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001337 help=
1338 'Selects compiler to use. Allowed values depend on the platform and language.'
ncteisen888093c2017-12-11 18:00:40 -08001339)
1340argp.add_argument(
1341 '--iomgr_platform',
1342 choices=['native', 'uv'],
1343 default='native',
1344 help='Selects iomgr platform to build on')
1345argp.add_argument(
1346 '--build_only',
1347 default=False,
1348 action='store_const',
1349 const=True,
1350 help='Perform all the build steps but don\'t run any tests.')
1351argp.add_argument(
1352 '--measure_cpu_costs',
1353 default=False,
1354 action='store_const',
1355 const=True,
1356 help='Measure the cpu costs of tests')
1357argp.add_argument(
1358 '--update_submodules',
1359 default=[],
1360 nargs='*',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001361 help=
1362 'Update some submodules before building. If any are updated, also run generate_projects. '
ncteisen888093c2017-12-11 18:00:40 -08001363 +
1364 'Submodules are specified as SUBMODULE_NAME:BRANCH; if BRANCH is omitted, master is assumed.'
1365)
Craig Tiller234b6e72015-05-23 10:12:40 -07001366argp.add_argument('-a', '--antagonists', default=0, type=int)
ncteisen888093c2017-12-11 18:00:40 -08001367argp.add_argument(
1368 '-x',
1369 '--xml_report',
1370 default=None,
1371 type=str,
1372 help='Generates a JUnit-compatible XML report')
1373argp.add_argument(
1374 '--report_suite_name',
1375 default='tests',
1376 type=str,
1377 help='Test suite name to use in generated JUnit XML report')
1378argp.add_argument(
1379 '--quiet_success',
1380 default=False,
1381 action='store_const',
1382 const=True,
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001383 help=
1384 'Don\'t print anything when a test passes. Passing tests also will not be reported in XML report. '
ncteisen888093c2017-12-11 18:00:40 -08001385 + 'Useful when running many iterations of each test (argument -n).')
1386argp.add_argument(
1387 '--force_default_poller',
1388 default=False,
1389 action='store_const',
1390 const=True,
1391 help='Don\'t try to iterate over many polling strategies when they exist')
1392argp.add_argument(
1393 '--force_use_pollers',
1394 default=None,
1395 type=str,
1396 help='Only use the specified comma-delimited list of polling engines. '
1397 'Example: --force_use_pollers epollsig,poll '
1398 ' (This flag has no effect if --force_default_poller flag is also used)')
1399argp.add_argument(
1400 '--max_time', default=-1, type=int, help='Maximum test runtime in seconds')
1401argp.add_argument(
1402 '--bq_result_table',
1403 default='',
1404 type=str,
1405 nargs='?',
1406 help='Upload test results to a specified BQ table.')
1407argp.add_argument(
1408 '--disable_auto_set_flakes',
1409 default=False,
1410 const=True,
1411 action='store_const',
1412 help='Disable rerunning historically flaky tests')
Nicolas Nobleddef2462015-01-06 18:08:25 -08001413args = argp.parse_args()
1414
Craig Tillerd16abf82017-06-07 08:58:55 -07001415flaky_tests = set()
Craig Tiller0b86d032017-09-07 13:47:45 -07001416shortname_to_cpu = {}
Matt Kwongc5fd8902017-08-10 13:39:21 -07001417if not args.disable_auto_set_flakes:
ncteisen888093c2017-12-11 18:00:40 -08001418 try:
1419 for test in get_bqtest_data():
1420 if test.flaky: flaky_tests.add(test.name)
1421 if test.cpu > 0: shortname_to_cpu[test.name] = test.cpu
1422 except:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001423 print(
1424 "Unexpected error getting flaky tests: %s" % traceback.format_exc())
David Garcia Quintasfaafa4d2017-06-06 14:52:17 -07001425
Craig Tiller123f1372016-06-15 15:06:14 -07001426if args.force_default_poller:
ncteisen888093c2017-12-11 18:00:40 -08001427 _POLLING_STRATEGIES = {}
Sree Kuchibhotla15d91642017-08-15 14:00:23 -07001428elif args.force_use_pollers:
ncteisen888093c2017-12-11 18:00:40 -08001429 _POLLING_STRATEGIES[platform_string()] = args.force_use_pollers.split(',')
Craig Tiller123f1372016-06-15 15:06:14 -07001430
Craig Tiller5f735a62016-01-20 09:31:15 -08001431jobset.measure_cpu_costs = args.measure_cpu_costs
1432
Craig Tiller1676f912016-01-05 10:49:44 -08001433# update submodules if necessary
Craig Tillerb361b4e2016-01-06 11:44:17 -08001434need_to_regenerate_projects = False
1435for spec in args.update_submodules:
ncteisen888093c2017-12-11 18:00:40 -08001436 spec = spec.split(':', 1)
1437 if len(spec) == 1:
1438 submodule = spec[0]
1439 branch = 'master'
1440 elif len(spec) == 2:
1441 submodule = spec[0]
1442 branch = spec[1]
1443 cwd = 'third_party/%s' % submodule
Craig Tiller1676f912016-01-05 10:49:44 -08001444
ncteisen888093c2017-12-11 18:00:40 -08001445 def git(cmd, cwd=cwd):
1446 print('in %s: git %s' % (cwd, cmd))
1447 run_shell_command('git %s' % cmd, cwd=cwd)
1448
1449 git('fetch')
1450 git('checkout %s' % branch)
1451 git('pull origin %s' % branch)
1452 if os.path.exists('src/%s/gen_build_yaml.py' % submodule):
1453 need_to_regenerate_projects = True
1454if need_to_regenerate_projects:
1455 if jobset.platform_string() == 'linux':
1456 run_shell_command('tools/buildgen/generate_projects.sh')
1457 else:
1458 print(
1459 'WARNING: may need to regenerate projects, but since we are not on')
1460 print(
1461 ' Linux this step is being skipped. Compilation MAY fail.')
Craig Tiller1676f912016-01-05 10:49:44 -08001462
Nicolas Nobleddef2462015-01-06 18:08:25 -08001463# grab config
Jan Tattermusch77db4322016-02-20 20:19:35 -08001464run_config = _CONFIGS[args.config]
1465build_config = run_config.build_config
Craig Tillerf1973b02015-01-16 12:32:13 -08001466
Craig Tiller06805272015-06-11 14:46:47 -07001467if args.travis:
ncteisen888093c2017-12-11 18:00:40 -08001468 _FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'api'}
Craig Tiller06805272015-06-11 14:46:47 -07001469
Adele Zhou6b9527c2015-11-20 15:56:35 -08001470if 'all' in args.language:
ncteisen888093c2017-12-11 18:00:40 -08001471 lang_list = _LANGUAGES.keys()
Adele Zhou6b9527c2015-11-20 15:56:35 -08001472else:
ncteisen888093c2017-12-11 18:00:40 -08001473 lang_list = args.language
Craig Tiller16900662016-01-07 19:30:54 -08001474# We don't support code coverage on some languages
1475if 'gcov' in args.config:
ncteisen888093c2017-12-11 18:00:40 -08001476 for bad in ['objc', 'sanity']:
1477 if bad in lang_list:
1478 lang_list.remove(bad)
Adele Zhou6b9527c2015-11-20 15:56:35 -08001479
1480languages = set(_LANGUAGES[l] for l in lang_list)
Jan Tattermusch77db4322016-02-20 20:19:35 -08001481for l in languages:
ncteisen888093c2017-12-11 18:00:40 -08001482 l.configure(run_config, args)
murgatroid99132ce6a2015-03-04 17:29:14 -08001483
ncteisen888093c2017-12-11 18:00:40 -08001484language_make_options = []
Jan Tattermuschc895fe02016-01-20 09:13:09 -08001485if any(language.make_options() for language in languages):
ncteisen888093c2017-12-11 18:00:40 -08001486 if not 'gcov' in args.config and len(languages) != 1:
1487 print(
1488 'languages with custom make options cannot be built simultaneously with other languages'
1489 )
1490 sys.exit(1)
1491 else:
1492 # Combining make options is not clean and just happens to work. It allows C/C++ and C# to build
1493 # together, and is only used under gcov. All other configs should build languages individually.
1494 language_make_options = list(
1495 set([
1496 make_option
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001497 for lang in languages
1498 for make_option in lang.make_options()
ncteisen888093c2017-12-11 18:00:40 -08001499 ]))
Jan Tattermuschc895fe02016-01-20 09:13:09 -08001500
Jan Tattermusch4dc9e722016-01-25 17:00:54 -08001501if args.use_docker:
ncteisen888093c2017-12-11 18:00:40 -08001502 if not args.travis:
1503 print('Seen --use_docker flag, will run tests under docker.')
1504 print('')
1505 print(
1506 'IMPORTANT: The changes you are testing need to be locally committed'
1507 )
1508 print(
1509 'because only the committed changes in the current branch will be')
1510 print('copied to the docker environment.')
1511 time.sleep(5)
Jan Tattermusch4dc9e722016-01-25 17:00:54 -08001512
ncteisen888093c2017-12-11 18:00:40 -08001513 dockerfile_dirs = set([l.dockerfile_dir() for l in languages])
1514 if len(dockerfile_dirs) > 1:
1515 if 'gcov' in args.config:
1516 dockerfile_dir = 'tools/dockerfile/test/multilang_jessie_x64'
1517 print(
1518 'Using multilang_jessie_x64 docker image for code coverage for '
1519 'all languages.')
1520 else:
1521 print(
1522 'Languages to be tested require running under different docker '
1523 'images.')
1524 sys.exit(1)
Adele Zhou9506ef22016-03-02 13:53:34 -08001525 else:
ncteisen888093c2017-12-11 18:00:40 -08001526 dockerfile_dir = next(iter(dockerfile_dirs))
Craig Tillerde7edf82016-03-20 09:12:16 -07001527
ncteisen888093c2017-12-11 18:00:40 -08001528 child_argv = [arg for arg in sys.argv if not arg == '--use_docker']
1529 run_tests_cmd = 'python tools/run_tests/run_tests.py %s' % ' '.join(
1530 child_argv[1:])
Jan Tattermusch4dc9e722016-01-25 17:00:54 -08001531
ncteisen888093c2017-12-11 18:00:40 -08001532 env = os.environ.copy()
1533 env['RUN_TESTS_COMMAND'] = run_tests_cmd
1534 env['DOCKERFILE_DIR'] = dockerfile_dir
1535 env['DOCKER_RUN_SCRIPT'] = 'tools/run_tests/dockerize/docker_run_tests.sh'
1536 if args.xml_report:
1537 env['XML_REPORT'] = args.xml_report
1538 if not args.travis:
1539 env['TTY_FLAG'] = '-t' # enables Ctrl-C when not on Jenkins.
Jan Tattermusch4dc9e722016-01-25 17:00:54 -08001540
ncteisen888093c2017-12-11 18:00:40 -08001541 subprocess.check_call(
1542 'tools/run_tests/dockerize/build_docker_and_run_tests.sh',
1543 shell=True,
1544 env=env)
1545 sys.exit(0)
Jan Tattermusch788ee232016-01-26 12:19:44 -08001546
Jan Tattermuschf08018a2016-01-26 08:22:09 -08001547_check_arch_option(args.arch)
Jan Tattermusch4dc9e722016-01-25 17:00:54 -08001548
ncteisen888093c2017-12-11 18:00:40 -08001549
Jan Tattermuschfba65302016-01-25 18:21:14 -08001550def make_jobspec(cfg, targets, makefile='Makefile'):
ncteisen888093c2017-12-11 18:00:40 -08001551 if platform_string() == 'windows':
1552 return [
1553 jobset.JobSpec(
1554 [
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001555 'cmake', '--build', '.', '--target',
1556 '%s' % target, '--config', _MSBUILD_CONFIG[cfg]
ncteisen888093c2017-12-11 18:00:40 -08001557 ],
1558 cwd=os.path.dirname(makefile),
1559 timeout_seconds=None) for target in targets
1560 ]
murgatroid998ae409f2015-10-26 16:39:00 -07001561 else:
ncteisen888093c2017-12-11 18:00:40 -08001562 if targets and makefile.startswith('cmake/build/'):
1563 # With cmake, we've passed all the build configuration in the pre-build step already
1564 return [
1565 jobset.JobSpec(
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001566 [os.getenv('MAKE', 'make'), '-j',
1567 '%d' % args.jobs] + targets,
ncteisen888093c2017-12-11 18:00:40 -08001568 cwd='cmake/build',
1569 timeout_seconds=None)
1570 ]
1571 if targets:
1572 return [
1573 jobset.JobSpec(
1574 [
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001575 os.getenv('MAKE', 'make'), '-f', makefile, '-j',
1576 '%d' % args.jobs,
ncteisen888093c2017-12-11 18:00:40 -08001577 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' %
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001578 args.slowdown,
1579 'CONFIG=%s' % cfg, 'Q='
ncteisen888093c2017-12-11 18:00:40 -08001580 ] + language_make_options +
1581 ([] if not args.travis else ['JENKINS_BUILD=1']) + targets,
1582 timeout_seconds=None)
1583 ]
1584 else:
1585 return []
1586
Jan Tattermuschfba65302016-01-25 18:21:14 -08001587
murgatroid99a3e244f2015-09-22 11:25:53 -07001588make_targets = {}
1589for l in languages:
ncteisen888093c2017-12-11 18:00:40 -08001590 makefile = l.makefile_name()
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001591 make_targets[makefile] = make_targets.get(makefile, set()).union(
1592 set(l.make_targets()))
ncteisen888093c2017-12-11 18:00:40 -08001593
Craig Tiller5058c692015-04-08 09:42:04 -07001594
Jan Tattermusche4a69182015-12-15 09:53:01 -08001595def build_step_environ(cfg):
ncteisen888093c2017-12-11 18:00:40 -08001596 environ = {'CONFIG': cfg}
1597 msbuild_cfg = _MSBUILD_CONFIG.get(cfg)
1598 if msbuild_cfg:
1599 environ['MSBUILD_CONFIG'] = msbuild_cfg
1600 return environ
Jan Tattermusche4a69182015-12-15 09:53:01 -08001601
ncteisen888093c2017-12-11 18:00:40 -08001602
1603build_steps = list(
1604 set(
1605 jobset.JobSpec(
1606 cmdline, environ=build_step_environ(build_config), flake_retries=2)
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001607 for l in languages
1608 for cmdline in l.pre_build_steps()))
Craig Tillerbd4e3782015-09-01 06:48:55 -07001609if make_targets:
ncteisen888093c2017-12-11 18:00:40 -08001610 make_commands = itertools.chain.from_iterable(
1611 make_jobspec(build_config, list(targets), makefile)
1612 for (makefile, targets) in make_targets.items())
1613 build_steps.extend(set(make_commands))
1614build_steps.extend(
1615 set(
1616 jobset.JobSpec(
1617 cmdline,
1618 environ=build_step_environ(build_config),
1619 timeout_seconds=None)
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001620 for l in languages
1621 for cmdline in l.build_steps()))
Craig Tillerf1973b02015-01-16 12:32:13 -08001622
ncteisen888093c2017-12-11 18:00:40 -08001623post_tests_steps = list(
1624 set(
1625 jobset.JobSpec(cmdline, environ=build_step_environ(build_config))
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001626 for l in languages
1627 for cmdline in l.post_tests_steps()))
Nicolas Nobleddef2462015-01-06 18:08:25 -08001628runs_per_test = args.runs_per_test
ctiller3040cb72015-01-07 12:13:17 -08001629forever = args.forever
Nicolas Nobleddef2462015-01-06 18:08:25 -08001630
Nicolas Nobleddef2462015-01-06 18:08:25 -08001631
Ken Paysonfa51de52016-06-30 23:50:48 -07001632def _shut_down_legacy_server(legacy_server_port):
ncteisen888093c2017-12-11 18:00:40 -08001633 try:
1634 version = int(
1635 urllib.request.urlopen(
1636 'http://localhost:%d/version_number' % legacy_server_port,
1637 timeout=10).read())
1638 except:
1639 pass
1640 else:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001641 urllib.request.urlopen(
1642 'http://localhost:%d/quitquitquit' % legacy_server_port).read()
Ken Paysonfa51de52016-06-30 23:50:48 -07001643
1644
Adele Zhoud5fffa52015-10-23 15:51:42 -07001645def _calculate_num_runs_failures(list_of_results):
ncteisen888093c2017-12-11 18:00:40 -08001646 """Caculate number of runs and failures for a particular test.
Adele Zhoud5fffa52015-10-23 15:51:42 -07001647
1648 Args:
1649 list_of_results: (List) of JobResult object.
1650 Returns:
1651 A tuple of total number of runs and failures.
1652 """
ncteisen888093c2017-12-11 18:00:40 -08001653 num_runs = len(list_of_results) # By default, there is 1 run per JobResult.
1654 num_failures = 0
1655 for jobresult in list_of_results:
1656 if jobresult.retries > 0:
1657 num_runs += jobresult.retries
1658 if jobresult.num_failures > 0:
1659 num_failures += jobresult.num_failures
1660 return num_runs, num_failures
Adele Zhoud5fffa52015-10-23 15:51:42 -07001661
Adele Zhou6b9527c2015-11-20 15:56:35 -08001662
Craig Tillereb9de8b2016-01-08 08:57:41 -08001663# _build_and_run results
1664class BuildAndRunError(object):
1665
ncteisen888093c2017-12-11 18:00:40 -08001666 BUILD = object()
1667 TEST = object()
1668 POST_TEST = object()
Craig Tillereb9de8b2016-01-08 08:57:41 -08001669
1670
Craig Tiller819cd882017-04-25 13:18:22 -07001671def _has_epollexclusive():
ncteisen888093c2017-12-11 18:00:40 -08001672 binary = 'bins/%s/check_epollexclusive' % args.config
1673 if not os.path.exists(binary):
1674 return False
1675 try:
1676 subprocess.check_call(binary)
1677 return True
1678 except subprocess.CalledProcessError, e:
1679 return False
1680 except OSError, e:
1681 # For languages other than C and Windows the binary won't exist
1682 return False
Craig Tiller819cd882017-04-25 13:18:22 -07001683
1684
Craig Tillereb9de8b2016-01-08 08:57:41 -08001685# returns a list of things that failed (or an empty list on success)
ncteisen888093c2017-12-11 18:00:40 -08001686def _build_and_run(check_cancelled,
1687 newline_on_success,
1688 xml_report=None,
1689 build_only=False):
1690 """Do one pass of building & running tests."""
1691 # build latest sequentially
1692 num_failures, resultset = jobset.run(
1693 build_steps,
1694 maxjobs=1,
1695 stop_on_failure=True,
1696 newline_on_success=newline_on_success,
1697 travis=args.travis)
1698 if num_failures:
1699 return [BuildAndRunError.BUILD]
Craig Tillerb361b4e2016-01-06 11:44:17 -08001700
ncteisen888093c2017-12-11 18:00:40 -08001701 if build_only:
1702 if xml_report:
1703 report_utils.render_junit_xml_report(
1704 resultset, xml_report, suite_name=args.report_suite_name)
1705 return []
ctiller3040cb72015-01-07 12:13:17 -08001706
ncteisen888093c2017-12-11 18:00:40 -08001707 if not args.travis and not _has_epollexclusive() and platform_string(
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001708 ) in _POLLING_STRATEGIES and 'epollex' in _POLLING_STRATEGIES[platform_string(
1709 )]:
ncteisen888093c2017-12-11 18:00:40 -08001710 print('\n\nOmitting EPOLLEXCLUSIVE tests\n\n')
1711 _POLLING_STRATEGIES[platform_string()].remove('epollex')
Craig Tiller819cd882017-04-25 13:18:22 -07001712
ncteisen888093c2017-12-11 18:00:40 -08001713 # start antagonists
1714 antagonists = [
1715 subprocess.Popen(['tools/run_tests/python_utils/antagonist.py'])
1716 for _ in range(0, args.antagonists)
1717 ]
1718 start_port_server.start_port_server()
1719 resultset = None
1720 num_test_failures = 0
1721 try:
1722 infinite_runs = runs_per_test == 0
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001723 one_run = set(
1724 spec for language in languages for spec in language.test_specs()
1725 if (re.search(args.regex, spec.shortname) and
1726 (args.regex_exclude == '' or
1727 not re.search(args.regex_exclude, spec.shortname))))
ncteisen888093c2017-12-11 18:00:40 -08001728 # When running on travis, we want out test runs to be as similar as possible
1729 # for reproducibility purposes.
1730 if args.travis and args.max_time <= 0:
1731 massaged_one_run = sorted(one_run, key=lambda x: x.cpu_cost)
1732 else:
1733 # whereas otherwise, we want to shuffle things up to give all tests a
1734 # chance to run.
1735 massaged_one_run = list(
1736 one_run) # random.sample needs an indexable seq.
1737 num_jobs = len(massaged_one_run)
1738 # for a random sample, get as many as indicated by the 'sample_percent'
1739 # argument. By default this arg is 100, resulting in a shuffle of all
1740 # jobs.
1741 sample_size = int(num_jobs * args.sample_percent / 100.0)
1742 massaged_one_run = random.sample(massaged_one_run, sample_size)
1743 if not isclose(args.sample_percent, 100.0):
1744 assert args.runs_per_test == 1, "Can't do sampling (-p) over multiple runs (-n)."
1745 print("Running %d tests out of %d (~%d%%)" %
1746 (sample_size, num_jobs, args.sample_percent))
1747 if infinite_runs:
1748 assert len(massaged_one_run
1749 ) > 0, 'Must have at least one test for a -n inf run'
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001750 runs_sequence = (itertools.repeat(massaged_one_run)
1751 if infinite_runs else itertools.repeat(
1752 massaged_one_run, runs_per_test))
ncteisen888093c2017-12-11 18:00:40 -08001753 all_runs = itertools.chain.from_iterable(runs_sequence)
Nicolas "Pixel" Noble5937b5b2015-06-26 02:04:12 +02001754
ncteisen888093c2017-12-11 18:00:40 -08001755 if args.quiet_success:
Jan Tattermusch68e27bf2016-12-16 14:09:03 +01001756 jobset.message(
ncteisen888093c2017-12-11 18:00:40 -08001757 'START',
1758 'Running tests quietly, only failing tests will be reported',
Jan Tattermusch68e27bf2016-12-16 14:09:03 +01001759 do_newline=True)
ncteisen888093c2017-12-11 18:00:40 -08001760 num_test_failures, resultset = jobset.run(
1761 all_runs,
1762 check_cancelled,
1763 newline_on_success=newline_on_success,
1764 travis=args.travis,
1765 maxjobs=args.jobs,
1766 maxjobs_cpu_agnostic=max_parallel_tests_for_current_platform(),
1767 stop_on_failure=args.stop_on_failure,
1768 quiet_success=args.quiet_success,
1769 max_time=args.max_time)
1770 if resultset:
1771 for k, v in sorted(resultset.items()):
1772 num_runs, num_failures = _calculate_num_runs_failures(v)
1773 if num_failures > 0:
1774 if num_failures == num_runs: # what about infinite_runs???
1775 jobset.message('FAILED', k, do_newline=True)
1776 else:
1777 jobset.message(
1778 'FLAKE',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -08001779 '%s [%d/%d runs flaked]' % (k, num_failures,
1780 num_runs),
ncteisen888093c2017-12-11 18:00:40 -08001781 do_newline=True)
1782 finally:
1783 for antagonist in antagonists:
1784 antagonist.kill()
1785 if args.bq_result_table and resultset:
1786 upload_results_to_bq(resultset, args.bq_result_table, args,
1787 platform_string())
1788 if xml_report and resultset:
1789 report_utils.render_junit_xml_report(
1790 resultset, xml_report, suite_name=args.report_suite_name)
Craig Tillerd86a3942015-01-14 12:48:54 -08001791
ncteisen888093c2017-12-11 18:00:40 -08001792 number_failures, _ = jobset.run(
1793 post_tests_steps,
1794 maxjobs=1,
1795 stop_on_failure=False,
1796 newline_on_success=newline_on_success,
1797 travis=args.travis)
Craig Tillereb9de8b2016-01-08 08:57:41 -08001798
ncteisen888093c2017-12-11 18:00:40 -08001799 out = []
1800 if number_failures:
1801 out.append(BuildAndRunError.POST_TEST)
1802 if num_test_failures:
1803 out.append(BuildAndRunError.TEST)
Nicolas "Pixel" Noble3fcd3bf2015-10-10 02:30:38 +02001804
ncteisen888093c2017-12-11 18:00:40 -08001805 return out
ctiller3040cb72015-01-07 12:13:17 -08001806
1807
1808if forever:
ncteisen888093c2017-12-11 18:00:40 -08001809 success = True
1810 while True:
1811 dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples'])
1812 initial_time = dw.most_recent_change()
1813 have_files_changed = lambda: dw.most_recent_change() != initial_time
1814 previous_success = success
1815 errors = _build_and_run(
1816 check_cancelled=have_files_changed,
1817 newline_on_success=False,
1818 build_only=args.build_only) == 0
1819 if not previous_success and not errors:
1820 jobset.message(
1821 'SUCCESS',
1822 'All tests are now passing properly',
1823 do_newline=True)
1824 jobset.message('IDLE', 'No change detected')
1825 while not have_files_changed():
1826 time.sleep(1)
ctiller3040cb72015-01-07 12:13:17 -08001827else:
ncteisen888093c2017-12-11 18:00:40 -08001828 errors = _build_and_run(
1829 check_cancelled=lambda: False,
1830 newline_on_success=args.newline_on_success,
1831 xml_report=args.xml_report,
1832 build_only=args.build_only)
1833 if not errors:
1834 jobset.message('SUCCESS', 'All tests passed', do_newline=True)
1835 else:
1836 jobset.message('FAILED', 'Some tests failed', do_newline=True)
1837 exit_code = 0
1838 if BuildAndRunError.BUILD in errors:
1839 exit_code |= 1
1840 if BuildAndRunError.TEST in errors:
1841 exit_code |= 2
1842 if BuildAndRunError.POST_TEST in errors:
1843 exit_code |= 4
1844 sys.exit(exit_code)