blob: 344035478b538626a04e645b8668a57a13fe8ab9 [file] [log] [blame]
Siddharth Shukla8e64d902017-03-12 19:50:18 +01001#!/usr/bin/env python
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2015 gRPC authors.
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +02003#
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
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +02007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +02009#
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.
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020015"""Run test matrix."""
16
Siddharth Shuklad194f592017-03-11 19:12:43 +010017from __future__ import print_function
18
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020019import argparse
Jan Tattermuscha1906d52016-09-19 18:37:17 +020020import multiprocessing
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020021import os
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020022import sys
Jan Tattermusch5c79a312016-12-20 11:02:50 +010023
24import python_utils.jobset as jobset
25import python_utils.report_utils as report_utils
26from python_utils.filter_pull_request_tests import filter_tests
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020027
28_ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
29os.chdir(_ROOT)
30
ncteisen888093c2017-12-11 18:00:40 -080031_DEFAULT_RUNTESTS_TIMEOUT = 1 * 60 * 60
Jan Tattermusch29828c52017-09-12 16:42:55 +020032
Jan Tattermusch060eb872016-09-20 16:06:13 +020033# Set the timeout high to allow enough time for sanitizers and pre-building
34# clang docker.
ncteisen888093c2017-12-11 18:00:40 -080035_CPP_RUNTESTS_TIMEOUT = 4 * 60 * 60
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020036
Jan Tattermusch67cd21e2017-09-19 16:21:20 +020037# C++ TSAN takes longer than other sanitizers
ncteisen888093c2017-12-11 18:00:40 -080038_CPP_TSAN_RUNTESTS_TIMEOUT = 8 * 60 * 60
Jan Tattermusch67cd21e2017-09-19 16:21:20 +020039
Jan Tattermuscha1906d52016-09-19 18:37:17 +020040# Number of jobs assigned to each run_tests.py instance
Matt Kwongfef98962016-10-27 10:45:47 -070041_DEFAULT_INNER_JOBS = 2
Jan Tattermuscha1906d52016-09-19 18:37:17 +020042
Jan Tattermusch5a59c432017-03-07 19:57:13 +010043# report suffix is important for reports to get picked up by internal CI
44_REPORT_SUFFIX = 'sponge_log.xml'
45
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020046
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020047def _report_filename(name):
ncteisen888093c2017-12-11 18:00:40 -080048 """Generates report file name"""
49 return 'report_%s_%s' % (name, _REPORT_SUFFIX)
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020050
51
52def _report_filename_internal_ci(name):
ncteisen888093c2017-12-11 18:00:40 -080053 """Generates report file name that leads to better presentation by internal CI"""
54 return '%s/%s' % (name, _REPORT_SUFFIX)
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020055
56
ncteisen888093c2017-12-11 18:00:40 -080057def _docker_jobspec(name,
58 runtests_args=[],
59 runtests_envs={},
Jan Tattermusch29828c52017-09-12 16:42:55 +020060 inner_jobs=_DEFAULT_INNER_JOBS,
61 timeout_seconds=None):
ncteisen888093c2017-12-11 18:00:40 -080062 """Run a single instance of run_tests.py in a docker container"""
63 if not timeout_seconds:
64 timeout_seconds = _DEFAULT_RUNTESTS_TIMEOUT
65 test_job = jobset.JobSpec(
66 cmdline=[
67 'python', 'tools/run_tests/run_tests.py', '--use_docker', '-t',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080068 '-j',
69 str(inner_jobs), '-x',
70 _report_filename(name), '--report_suite_name',
71 '%s' % name
ncteisen888093c2017-12-11 18:00:40 -080072 ] + runtests_args,
73 environ=runtests_envs,
74 shortname='run_tests_%s' % name,
75 timeout_seconds=timeout_seconds)
76 return test_job
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020077
78
ncteisen888093c2017-12-11 18:00:40 -080079def _workspace_jobspec(name,
80 runtests_args=[],
81 workspace_name=None,
82 runtests_envs={},
83 inner_jobs=_DEFAULT_INNER_JOBS,
Jan Tattermusch29828c52017-09-12 16:42:55 +020084 timeout_seconds=None):
ncteisen888093c2017-12-11 18:00:40 -080085 """Run a single instance of run_tests.py in a separate workspace"""
86 if not workspace_name:
87 workspace_name = 'workspace_%s' % name
88 if not timeout_seconds:
89 timeout_seconds = _DEFAULT_RUNTESTS_TIMEOUT
90 env = {'WORKSPACE_NAME': workspace_name}
91 env.update(runtests_envs)
92 test_job = jobset.JobSpec(
93 cmdline=[
94 'bash', 'tools/run_tests/helper_scripts/run_tests_in_workspace.sh',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080095 '-t', '-j',
96 str(inner_jobs), '-x',
97 '../%s' % _report_filename(name), '--report_suite_name',
98 '%s' % name
ncteisen888093c2017-12-11 18:00:40 -080099 ] + runtests_args,
100 environ=env,
101 shortname='run_tests_%s' % name,
102 timeout_seconds=timeout_seconds)
103 return test_job
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200104
105
ncteisen888093c2017-12-11 18:00:40 -0800106def _generate_jobs(languages,
107 configs,
108 platforms,
109 iomgr_platform='native',
110 arch=None,
111 compiler=None,
112 labels=[],
113 extra_args=[],
114 extra_envs={},
115 inner_jobs=_DEFAULT_INNER_JOBS,
116 timeout_seconds=None):
117 result = []
118 for language in languages:
119 for platform in platforms:
120 for config in configs:
121 name = '%s_%s_%s_%s' % (language, platform, config,
122 iomgr_platform)
123 runtests_args = [
124 '-l', language, '-c', config, '--iomgr_platform',
125 iomgr_platform
126 ]
127 if arch or compiler:
128 name += '_%s_%s' % (arch, compiler)
129 runtests_args += ['--arch', arch, '--compiler', compiler]
130 if '--build_only' in extra_args:
131 name += '_buildonly'
132 for extra_env in extra_envs:
133 name += '_%s_%s' % (extra_env, extra_envs[extra_env])
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200134
ncteisen888093c2017-12-11 18:00:40 -0800135 runtests_args += extra_args
136 if platform == 'linux':
137 job = _docker_jobspec(
138 name=name,
139 runtests_args=runtests_args,
140 runtests_envs=extra_envs,
141 inner_jobs=inner_jobs,
142 timeout_seconds=timeout_seconds)
143 else:
144 job = _workspace_jobspec(
145 name=name,
146 runtests_args=runtests_args,
147 runtests_envs=extra_envs,
148 inner_jobs=inner_jobs,
149 timeout_seconds=timeout_seconds)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200150
ncteisen888093c2017-12-11 18:00:40 -0800151 job.labels = [platform, config, language, iomgr_platform
152 ] + labels
153 result.append(job)
154 return result
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200155
156
Matt Kwongfef98962016-10-27 10:45:47 -0700157def _create_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS):
ncteisen888093c2017-12-11 18:00:40 -0800158 test_jobs = []
159 # supported on linux only
160 test_jobs += _generate_jobs(
161 languages=['sanity', 'php7'],
162 configs=['dbg', 'opt'],
163 platforms=['linux'],
164 labels=['basictests', 'multilang'],
165 extra_args=extra_args,
166 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700167
ncteisen888093c2017-12-11 18:00:40 -0800168 # supported on all platforms.
169 test_jobs += _generate_jobs(
170 languages=['c'],
171 configs=['dbg', 'opt'],
172 platforms=['linux', 'macos', 'windows'],
173 labels=['basictests', 'corelang'],
174 extra_args=extra_args,
175 inner_jobs=inner_jobs,
176 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700177
ncteisen888093c2017-12-11 18:00:40 -0800178 test_jobs += _generate_jobs(
179 languages=['csharp', 'python'],
180 configs=['dbg', 'opt'],
181 platforms=['linux', 'macos', 'windows'],
182 labels=['basictests', 'multilang'],
183 extra_args=extra_args,
184 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700185
ncteisen888093c2017-12-11 18:00:40 -0800186 # supported on linux and mac.
187 test_jobs += _generate_jobs(
188 languages=['c++'],
189 configs=['dbg', 'opt'],
190 platforms=['linux', 'macos'],
191 labels=['basictests', 'corelang'],
192 extra_args=extra_args,
193 inner_jobs=inner_jobs,
194 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700195
ncteisen888093c2017-12-11 18:00:40 -0800196 test_jobs += _generate_jobs(
197 languages=['grpc-node', 'ruby', 'php'],
198 configs=['dbg', 'opt'],
199 platforms=['linux', 'macos'],
200 labels=['basictests', 'multilang'],
201 extra_args=extra_args,
202 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700203
ncteisen888093c2017-12-11 18:00:40 -0800204 # supported on mac only.
205 test_jobs += _generate_jobs(
206 languages=['objc'],
207 configs=['dbg', 'opt'],
208 platforms=['macos'],
209 labels=['basictests', 'multilang'],
210 extra_args=extra_args,
211 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700212
ncteisen888093c2017-12-11 18:00:40 -0800213 # sanitizers
214 test_jobs += _generate_jobs(
215 languages=['c'],
216 configs=['msan', 'asan', 'tsan', 'ubsan'],
217 platforms=['linux'],
218 labels=['sanitizers', 'corelang'],
219 extra_args=extra_args,
220 inner_jobs=inner_jobs,
221 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
222 test_jobs += _generate_jobs(
223 languages=['c++'],
224 configs=['asan'],
225 platforms=['linux'],
226 labels=['sanitizers', 'corelang'],
227 extra_args=extra_args,
228 inner_jobs=inner_jobs,
229 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
230 test_jobs += _generate_jobs(
231 languages=['c++'],
232 configs=['tsan'],
233 platforms=['linux'],
234 labels=['sanitizers', 'corelang'],
235 extra_args=extra_args,
236 inner_jobs=inner_jobs,
237 timeout_seconds=_CPP_TSAN_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700238
ncteisen888093c2017-12-11 18:00:40 -0800239 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200240
murgatroid991687cab2016-10-11 11:42:01 -0700241
ncteisen888093c2017-12-11 18:00:40 -0800242def _create_portability_test_jobs(extra_args=[],
243 inner_jobs=_DEFAULT_INNER_JOBS):
244 test_jobs = []
245 # portability C x86
246 test_jobs += _generate_jobs(
247 languages=['c'],
248 configs=['dbg'],
249 platforms=['linux'],
250 arch='x86',
251 compiler='default',
252 labels=['portability', 'corelang'],
253 extra_args=extra_args,
254 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700255
ncteisen888093c2017-12-11 18:00:40 -0800256 # portability C and C++ on x64
257 for compiler in [
258 'gcc4.8', 'gcc5.3', 'gcc_musl', 'clang3.5', 'clang3.6', 'clang3.7'
259 ]:
260 test_jobs += _generate_jobs(
261 languages=['c', 'c++'],
262 configs=['dbg'],
263 platforms=['linux'],
264 arch='x64',
265 compiler=compiler,
266 labels=['portability', 'corelang'],
267 extra_args=extra_args,
268 inner_jobs=inner_jobs,
269 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700270
ncteisen888093c2017-12-11 18:00:40 -0800271 # portability C on Windows 64-bit (x86 is the default)
272 test_jobs += _generate_jobs(
273 languages=['c'],
274 configs=['dbg'],
275 platforms=['windows'],
276 arch='x64',
277 compiler='default',
278 labels=['portability', 'corelang'],
279 extra_args=extra_args,
280 inner_jobs=inner_jobs)
Jan Tattermuschadd32252017-06-26 17:13:14 +0200281
ncteisen888093c2017-12-11 18:00:40 -0800282 # portability C++ on Windows
283 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
284 test_jobs += _generate_jobs(
285 languages=['c++'],
286 configs=['dbg'],
287 platforms=['windows'],
288 arch='default',
289 compiler='default',
290 labels=['portability', 'corelang'],
291 extra_args=extra_args + ['--build_only'],
292 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700293
ncteisen888093c2017-12-11 18:00:40 -0800294 # portability C and C++ on Windows using VS2017 (build only)
295 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
296 test_jobs += _generate_jobs(
297 languages=['c', 'c++'],
298 configs=['dbg'],
299 platforms=['windows'],
300 arch='x64',
301 compiler='cmake_vs2017',
302 labels=['portability', 'corelang'],
303 extra_args=extra_args + ['--build_only'],
304 inner_jobs=inner_jobs)
Jan Tattermuscha8003e82017-08-23 15:43:17 +0200305
ncteisen888093c2017-12-11 18:00:40 -0800306 # C and C++ with the c-ares DNS resolver on Linux
307 test_jobs += _generate_jobs(
308 languages=['c', 'c++'],
309 configs=['dbg'],
310 platforms=['linux'],
311 labels=['portability', 'corelang'],
312 extra_args=extra_args,
313 extra_envs={'GRPC_DNS_RESOLVER': 'ares'},
314 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
Yuchen Zeng87b59102016-11-08 10:50:12 -0800315
Vijay Pai9d2d8432018-01-08 15:11:23 -0800316 # C and C++ with no-exceptions on Linux
317 test_jobs += _generate_jobs(
318 languages=['c', 'c++'],
319 configs=['noexcept'],
320 platforms=['linux'],
321 labels=['portability', 'corelang'],
322 extra_args=extra_args,
323 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
324
ncteisen888093c2017-12-11 18:00:40 -0800325 # TODO(zyc): Turn on this test after adding c-ares support on windows.
326 # C with the c-ares DNS resolver on Windows
327 # test_jobs += _generate_jobs(languages=['c'],
328 # configs=['dbg'], platforms=['windows'],
329 # labels=['portability', 'corelang'],
330 # extra_args=extra_args,
331 # extra_envs={'GRPC_DNS_RESOLVER': 'ares'})
Yuchen Zengfdae4bd2016-11-07 17:46:16 -0800332
ncteisen888093c2017-12-11 18:00:40 -0800333 # C and C++ build with cmake on Linux
334 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
335 # to make sure it's buildable at least.
336 test_jobs += _generate_jobs(
337 languages=['c', 'c++'],
338 configs=['dbg'],
339 platforms=['linux'],
340 arch='default',
341 compiler='cmake',
342 labels=['portability', 'corelang'],
343 extra_args=extra_args + ['--build_only'],
344 inner_jobs=inner_jobs)
Jan Tattermuschdfb03bb2017-01-25 19:27:58 +0100345
ncteisen888093c2017-12-11 18:00:40 -0800346 test_jobs += _generate_jobs(
347 languages=['python'],
348 configs=['dbg'],
349 platforms=['linux'],
350 arch='default',
351 compiler='python_alpine',
352 labels=['portability', 'multilang'],
353 extra_args=extra_args,
354 inner_jobs=inner_jobs)
Ken Payson02909062017-05-04 12:33:58 -0700355
ncteisen888093c2017-12-11 18:00:40 -0800356 test_jobs += _generate_jobs(
357 languages=['csharp'],
358 configs=['dbg'],
359 platforms=['linux'],
360 arch='default',
361 compiler='coreclr',
362 labels=['portability', 'multilang'],
363 extra_args=extra_args,
364 inner_jobs=inner_jobs)
murgatroid99804c9e92016-12-05 12:19:57 -0800365
ncteisen888093c2017-12-11 18:00:40 -0800366 test_jobs += _generate_jobs(
367 languages=['c'],
368 configs=['dbg'],
369 platforms=['linux'],
370 iomgr_platform='uv',
371 labels=['portability', 'corelang'],
372 extra_args=extra_args,
373 inner_jobs=inner_jobs,
374 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991191b722017-02-08 11:56:52 -0800375
ncteisen888093c2017-12-11 18:00:40 -0800376 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200377
378
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200379def _allowed_labels():
ncteisen888093c2017-12-11 18:00:40 -0800380 """Returns a list of existing job labels."""
381 all_labels = set()
382 for job in _create_test_jobs() + _create_portability_test_jobs():
383 for label in job.labels:
384 all_labels.add(label)
385 return sorted(all_labels)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200386
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200387
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100388def _runs_per_test_type(arg_str):
ncteisen888093c2017-12-11 18:00:40 -0800389 """Auxiliary function to parse the "runs_per_test" flag."""
390 try:
391 n = int(arg_str)
392 if n <= 0: raise ValueError
393 return n
394 except:
395 msg = '\'{}\' is not a positive integer'.format(arg_str)
396 raise argparse.ArgumentTypeError(msg)
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100397
398
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700399if __name__ == "__main__":
ncteisen888093c2017-12-11 18:00:40 -0800400 argp = argparse.ArgumentParser(
401 description='Run a matrix of run_tests.py tests.')
402 argp.add_argument(
403 '-j',
404 '--jobs',
405 default=multiprocessing.cpu_count() / _DEFAULT_INNER_JOBS,
406 type=int,
407 help='Number of concurrent run_tests.py instances.')
408 argp.add_argument(
409 '-f',
410 '--filter',
411 choices=_allowed_labels(),
412 nargs='+',
413 default=[],
414 help='Filter targets to run by label with AND semantics.')
415 argp.add_argument(
416 '--exclude',
417 choices=_allowed_labels(),
418 nargs='+',
419 default=[],
420 help='Exclude targets with any of given labels.')
421 argp.add_argument(
422 '--build_only',
423 default=False,
424 action='store_const',
425 const=True,
426 help='Pass --build_only flag to run_tests.py instances.')
427 argp.add_argument(
428 '--force_default_poller',
429 default=False,
430 action='store_const',
431 const=True,
432 help='Pass --force_default_poller to run_tests.py instances.')
433 argp.add_argument(
434 '--dry_run',
435 default=False,
436 action='store_const',
437 const=True,
438 help='Only print what would be run.')
439 argp.add_argument(
440 '--filter_pr_tests',
441 default=False,
442 action='store_const',
443 const=True,
444 help='Filters out tests irrelevant to pull request changes.')
445 argp.add_argument(
446 '--base_branch',
447 default='origin/master',
448 type=str,
449 help='Branch that pull request is requesting to merge into')
450 argp.add_argument(
451 '--inner_jobs',
452 default=_DEFAULT_INNER_JOBS,
453 type=int,
454 help='Number of jobs in each run_tests.py instance')
455 argp.add_argument(
456 '-n',
457 '--runs_per_test',
458 default=1,
459 type=_runs_per_test_type,
460 help='How many times to run each tests. >1 runs implies ' +
461 'omitting passing test from the output & reports.')
462 argp.add_argument(
463 '--max_time',
464 default=-1,
465 type=int,
466 help='Maximum amount of time to run tests for' +
467 '(other tests will be skipped)')
468 argp.add_argument(
469 '--internal_ci',
470 default=False,
471 action='store_const',
472 const=True,
473 help='Put reports into subdirectories to improve presentation of '
474 'results by Internal CI.')
475 argp.add_argument(
476 '--bq_result_table',
477 default='',
478 type=str,
479 nargs='?',
480 help='Upload test results to a specified BQ table.')
481 args = argp.parse_args()
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200482
ncteisen888093c2017-12-11 18:00:40 -0800483 if args.internal_ci:
484 _report_filename = _report_filename_internal_ci # override the function
Jan Tattermuschac9c9f92017-04-28 20:56:05 +0200485
ncteisen888093c2017-12-11 18:00:40 -0800486 extra_args = []
487 if args.build_only:
488 extra_args.append('--build_only')
489 if args.force_default_poller:
490 extra_args.append('--force_default_poller')
491 if args.runs_per_test > 1:
492 extra_args.append('-n')
493 extra_args.append('%s' % args.runs_per_test)
494 extra_args.append('--quiet_success')
495 if args.max_time > 0:
496 extra_args.extend(('--max_time', '%d' % args.max_time))
497 if args.bq_result_table:
498 extra_args.append('--bq_result_table')
499 extra_args.append('%s' % args.bq_result_table)
500 extra_args.append('--measure_cpu_costs')
501 extra_args.append('--disable_auto_set_flakes')
Matt Kwongfef98962016-10-27 10:45:47 -0700502
ncteisen888093c2017-12-11 18:00:40 -0800503 all_jobs = _create_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) + \
504 _create_portability_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200505
ncteisen888093c2017-12-11 18:00:40 -0800506 jobs = []
507 for job in all_jobs:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800508 if not args.filter or all(
509 filter in job.labels for filter in args.filter):
ncteisen888093c2017-12-11 18:00:40 -0800510 if not any(exclude_label in job.labels
511 for exclude_label in args.exclude):
512 jobs.append(job)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200513
ncteisen888093c2017-12-11 18:00:40 -0800514 if not jobs:
515 jobset.message(
516 'FAILED', 'No test suites match given criteria.', do_newline=True)
517 sys.exit(1)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200518
ncteisen888093c2017-12-11 18:00:40 -0800519 print('IMPORTANT: The changes you are testing need to be locally committed')
520 print('because only the committed changes in the current branch will be')
521 print('copied to the docker environment or into subworkspaces.')
murgatroid991687cab2016-10-11 11:42:01 -0700522
ncteisen888093c2017-12-11 18:00:40 -0800523 skipped_jobs = []
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200524
ncteisen888093c2017-12-11 18:00:40 -0800525 if args.filter_pr_tests:
526 print('Looking for irrelevant tests to skip...')
527 relevant_jobs = filter_tests(jobs, args.base_branch)
528 if len(relevant_jobs) == len(jobs):
529 print('No tests will be skipped.')
530 else:
531 print('These tests will be skipped:')
532 skipped_jobs = list(set(jobs) - set(relevant_jobs))
533 # Sort by shortnames to make printing of skipped tests consistent
534 skipped_jobs.sort(key=lambda job: job.shortname)
535 for job in list(skipped_jobs):
536 print(' %s' % job.shortname)
537 jobs = relevant_jobs
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700538
ncteisen888093c2017-12-11 18:00:40 -0800539 print('Will run these tests:')
540 for job in jobs:
541 if args.dry_run:
542 print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))
543 else:
544 print(' %s' % job.shortname)
545 print
546
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700547 if args.dry_run:
ncteisen888093c2017-12-11 18:00:40 -0800548 print('--dry_run was used, exiting')
549 sys.exit(1)
550
551 jobset.message('START', 'Running test matrix.', do_newline=True)
552 num_failures, resultset = jobset.run(
553 jobs, newline_on_success=True, travis=True, maxjobs=args.jobs)
554 # Merge skipped tests into results to show skipped tests on report.xml
555 if skipped_jobs:
556 ignored_num_skipped_failures, skipped_results = jobset.run(
557 skipped_jobs, skip_jobs=True)
558 resultset.update(skipped_results)
559 report_utils.render_junit_xml_report(
560 resultset,
561 _report_filename('aggregate_tests'),
562 suite_name='aggregate_tests')
563
564 if num_failures == 0:
565 jobset.message(
566 'SUCCESS',
567 'All run_tests.py instance finished successfully.',
568 do_newline=True)
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700569 else:
ncteisen888093c2017-12-11 18:00:40 -0800570 jobset.message(
571 'FAILED',
572 'Some run_tests.py instance have failed.',
573 do_newline=True)
574 sys.exit(1)