blob: ae3a28bde538e8fa5fe344c9e205fe0d75c86131 [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 Tattermusch41d220e2018-01-22 17:02:44 +010047def _safe_report_name(name):
48 """Reports with '+' in target name won't show correctly in ResultStore"""
49 return name.replace('+', 'p')
50
51
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020052def _report_filename(name):
ncteisen888093c2017-12-11 18:00:40 -080053 """Generates report file name"""
Jan Tattermusch41d220e2018-01-22 17:02:44 +010054 return 'report_%s_%s' % (_safe_report_name(name), _REPORT_SUFFIX)
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020055
56
57def _report_filename_internal_ci(name):
ncteisen888093c2017-12-11 18:00:40 -080058 """Generates report file name that leads to better presentation by internal CI"""
Jan Tattermusch41d220e2018-01-22 17:02:44 +010059 return '%s/%s' % (_safe_report_name(name), _REPORT_SUFFIX)
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020060
61
ncteisen888093c2017-12-11 18:00:40 -080062def _docker_jobspec(name,
63 runtests_args=[],
64 runtests_envs={},
Jan Tattermusch29828c52017-09-12 16:42:55 +020065 inner_jobs=_DEFAULT_INNER_JOBS,
66 timeout_seconds=None):
ncteisen888093c2017-12-11 18:00:40 -080067 """Run a single instance of run_tests.py in a docker container"""
68 if not timeout_seconds:
69 timeout_seconds = _DEFAULT_RUNTESTS_TIMEOUT
70 test_job = jobset.JobSpec(
71 cmdline=[
72 'python', 'tools/run_tests/run_tests.py', '--use_docker', '-t',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080073 '-j',
74 str(inner_jobs), '-x',
75 _report_filename(name), '--report_suite_name',
Jan Tattermusch41d220e2018-01-22 17:02:44 +010076 '%s' % _safe_report_name(name)
ncteisen888093c2017-12-11 18:00:40 -080077 ] + runtests_args,
78 environ=runtests_envs,
79 shortname='run_tests_%s' % name,
80 timeout_seconds=timeout_seconds)
81 return test_job
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020082
83
ncteisen888093c2017-12-11 18:00:40 -080084def _workspace_jobspec(name,
85 runtests_args=[],
86 workspace_name=None,
87 runtests_envs={},
88 inner_jobs=_DEFAULT_INNER_JOBS,
Jan Tattermusch29828c52017-09-12 16:42:55 +020089 timeout_seconds=None):
ncteisen888093c2017-12-11 18:00:40 -080090 """Run a single instance of run_tests.py in a separate workspace"""
91 if not workspace_name:
92 workspace_name = 'workspace_%s' % name
93 if not timeout_seconds:
94 timeout_seconds = _DEFAULT_RUNTESTS_TIMEOUT
95 env = {'WORKSPACE_NAME': workspace_name}
96 env.update(runtests_envs)
97 test_job = jobset.JobSpec(
98 cmdline=[
99 'bash', 'tools/run_tests/helper_scripts/run_tests_in_workspace.sh',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800100 '-t', '-j',
101 str(inner_jobs), '-x',
102 '../%s' % _report_filename(name), '--report_suite_name',
Jan Tattermusch41d220e2018-01-22 17:02:44 +0100103 '%s' % _safe_report_name(name)
ncteisen888093c2017-12-11 18:00:40 -0800104 ] + runtests_args,
105 environ=env,
106 shortname='run_tests_%s' % name,
107 timeout_seconds=timeout_seconds)
108 return test_job
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200109
110
ncteisen888093c2017-12-11 18:00:40 -0800111def _generate_jobs(languages,
112 configs,
113 platforms,
114 iomgr_platform='native',
115 arch=None,
116 compiler=None,
117 labels=[],
118 extra_args=[],
119 extra_envs={},
120 inner_jobs=_DEFAULT_INNER_JOBS,
121 timeout_seconds=None):
122 result = []
123 for language in languages:
124 for platform in platforms:
125 for config in configs:
126 name = '%s_%s_%s_%s' % (language, platform, config,
127 iomgr_platform)
128 runtests_args = [
129 '-l', language, '-c', config, '--iomgr_platform',
130 iomgr_platform
131 ]
132 if arch or compiler:
133 name += '_%s_%s' % (arch, compiler)
134 runtests_args += ['--arch', arch, '--compiler', compiler]
135 if '--build_only' in extra_args:
136 name += '_buildonly'
137 for extra_env in extra_envs:
138 name += '_%s_%s' % (extra_env, extra_envs[extra_env])
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200139
ncteisen888093c2017-12-11 18:00:40 -0800140 runtests_args += extra_args
141 if platform == 'linux':
142 job = _docker_jobspec(
143 name=name,
144 runtests_args=runtests_args,
145 runtests_envs=extra_envs,
146 inner_jobs=inner_jobs,
147 timeout_seconds=timeout_seconds)
148 else:
149 job = _workspace_jobspec(
150 name=name,
151 runtests_args=runtests_args,
152 runtests_envs=extra_envs,
153 inner_jobs=inner_jobs,
154 timeout_seconds=timeout_seconds)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200155
ncteisen888093c2017-12-11 18:00:40 -0800156 job.labels = [platform, config, language, iomgr_platform
157 ] + labels
158 result.append(job)
159 return result
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200160
161
Matt Kwongfef98962016-10-27 10:45:47 -0700162def _create_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS):
ncteisen888093c2017-12-11 18:00:40 -0800163 test_jobs = []
164 # supported on linux only
165 test_jobs += _generate_jobs(
166 languages=['sanity', 'php7'],
167 configs=['dbg', 'opt'],
168 platforms=['linux'],
169 labels=['basictests', 'multilang'],
170 extra_args=extra_args,
171 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700172
ncteisen888093c2017-12-11 18:00:40 -0800173 # supported on all platforms.
174 test_jobs += _generate_jobs(
175 languages=['c'],
176 configs=['dbg', 'opt'],
177 platforms=['linux', 'macos', 'windows'],
178 labels=['basictests', 'corelang'],
179 extra_args=extra_args,
180 inner_jobs=inner_jobs,
181 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700182
ncteisen888093c2017-12-11 18:00:40 -0800183 test_jobs += _generate_jobs(
184 languages=['csharp', 'python'],
185 configs=['dbg', 'opt'],
186 platforms=['linux', 'macos', 'windows'],
187 labels=['basictests', 'multilang'],
188 extra_args=extra_args,
189 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700190
ncteisen888093c2017-12-11 18:00:40 -0800191 # supported on linux and mac.
192 test_jobs += _generate_jobs(
193 languages=['c++'],
194 configs=['dbg', 'opt'],
195 platforms=['linux', 'macos'],
196 labels=['basictests', 'corelang'],
197 extra_args=extra_args,
198 inner_jobs=inner_jobs,
199 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700200
ncteisen888093c2017-12-11 18:00:40 -0800201 test_jobs += _generate_jobs(
202 languages=['grpc-node', 'ruby', 'php'],
203 configs=['dbg', 'opt'],
204 platforms=['linux', 'macos'],
205 labels=['basictests', 'multilang'],
206 extra_args=extra_args,
207 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700208
ncteisen888093c2017-12-11 18:00:40 -0800209 # supported on mac only.
210 test_jobs += _generate_jobs(
211 languages=['objc'],
212 configs=['dbg', 'opt'],
213 platforms=['macos'],
214 labels=['basictests', 'multilang'],
215 extra_args=extra_args,
216 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700217
ncteisen888093c2017-12-11 18:00:40 -0800218 # sanitizers
219 test_jobs += _generate_jobs(
220 languages=['c'],
221 configs=['msan', 'asan', 'tsan', 'ubsan'],
222 platforms=['linux'],
223 labels=['sanitizers', 'corelang'],
224 extra_args=extra_args,
225 inner_jobs=inner_jobs,
226 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
227 test_jobs += _generate_jobs(
228 languages=['c++'],
229 configs=['asan'],
230 platforms=['linux'],
231 labels=['sanitizers', 'corelang'],
232 extra_args=extra_args,
233 inner_jobs=inner_jobs,
234 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
235 test_jobs += _generate_jobs(
236 languages=['c++'],
237 configs=['tsan'],
238 platforms=['linux'],
239 labels=['sanitizers', 'corelang'],
240 extra_args=extra_args,
241 inner_jobs=inner_jobs,
242 timeout_seconds=_CPP_TSAN_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700243
ncteisen888093c2017-12-11 18:00:40 -0800244 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200245
murgatroid991687cab2016-10-11 11:42:01 -0700246
ncteisen888093c2017-12-11 18:00:40 -0800247def _create_portability_test_jobs(extra_args=[],
248 inner_jobs=_DEFAULT_INNER_JOBS):
249 test_jobs = []
250 # portability C x86
251 test_jobs += _generate_jobs(
252 languages=['c'],
253 configs=['dbg'],
254 platforms=['linux'],
255 arch='x86',
256 compiler='default',
257 labels=['portability', 'corelang'],
258 extra_args=extra_args,
259 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700260
ncteisen888093c2017-12-11 18:00:40 -0800261 # portability C and C++ on x64
262 for compiler in [
263 'gcc4.8', 'gcc5.3', 'gcc_musl', 'clang3.5', 'clang3.6', 'clang3.7'
264 ]:
265 test_jobs += _generate_jobs(
266 languages=['c', 'c++'],
267 configs=['dbg'],
268 platforms=['linux'],
269 arch='x64',
270 compiler=compiler,
271 labels=['portability', 'corelang'],
272 extra_args=extra_args,
273 inner_jobs=inner_jobs,
274 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700275
ncteisen888093c2017-12-11 18:00:40 -0800276 # portability C on Windows 64-bit (x86 is the default)
277 test_jobs += _generate_jobs(
278 languages=['c'],
279 configs=['dbg'],
280 platforms=['windows'],
281 arch='x64',
282 compiler='default',
283 labels=['portability', 'corelang'],
284 extra_args=extra_args,
285 inner_jobs=inner_jobs)
Jan Tattermuschadd32252017-06-26 17:13:14 +0200286
ncteisen888093c2017-12-11 18:00:40 -0800287 # portability C++ on Windows
288 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
289 test_jobs += _generate_jobs(
290 languages=['c++'],
291 configs=['dbg'],
292 platforms=['windows'],
293 arch='default',
294 compiler='default',
295 labels=['portability', 'corelang'],
296 extra_args=extra_args + ['--build_only'],
297 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700298
ncteisen888093c2017-12-11 18:00:40 -0800299 # portability C and C++ on Windows using VS2017 (build only)
300 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
301 test_jobs += _generate_jobs(
302 languages=['c', 'c++'],
303 configs=['dbg'],
304 platforms=['windows'],
305 arch='x64',
306 compiler='cmake_vs2017',
307 labels=['portability', 'corelang'],
308 extra_args=extra_args + ['--build_only'],
309 inner_jobs=inner_jobs)
Jan Tattermuscha8003e82017-08-23 15:43:17 +0200310
ncteisen888093c2017-12-11 18:00:40 -0800311 # C and C++ with the c-ares DNS resolver on Linux
312 test_jobs += _generate_jobs(
313 languages=['c', 'c++'],
314 configs=['dbg'],
315 platforms=['linux'],
316 labels=['portability', 'corelang'],
317 extra_args=extra_args,
318 extra_envs={'GRPC_DNS_RESOLVER': 'ares'},
319 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
Yuchen Zeng87b59102016-11-08 10:50:12 -0800320
Vijay Pai9d2d8432018-01-08 15:11:23 -0800321 # C and C++ with no-exceptions on Linux
322 test_jobs += _generate_jobs(
323 languages=['c', 'c++'],
324 configs=['noexcept'],
325 platforms=['linux'],
326 labels=['portability', 'corelang'],
327 extra_args=extra_args,
328 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
329
ncteisen888093c2017-12-11 18:00:40 -0800330 # TODO(zyc): Turn on this test after adding c-ares support on windows.
331 # C with the c-ares DNS resolver on Windows
332 # test_jobs += _generate_jobs(languages=['c'],
333 # configs=['dbg'], platforms=['windows'],
334 # labels=['portability', 'corelang'],
335 # extra_args=extra_args,
336 # extra_envs={'GRPC_DNS_RESOLVER': 'ares'})
Yuchen Zengfdae4bd2016-11-07 17:46:16 -0800337
ncteisen888093c2017-12-11 18:00:40 -0800338 # C and C++ build with cmake on Linux
339 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
340 # to make sure it's buildable at least.
341 test_jobs += _generate_jobs(
342 languages=['c', 'c++'],
343 configs=['dbg'],
344 platforms=['linux'],
345 arch='default',
346 compiler='cmake',
347 labels=['portability', 'corelang'],
348 extra_args=extra_args + ['--build_only'],
349 inner_jobs=inner_jobs)
Jan Tattermuschdfb03bb2017-01-25 19:27:58 +0100350
ncteisen888093c2017-12-11 18:00:40 -0800351 test_jobs += _generate_jobs(
352 languages=['python'],
353 configs=['dbg'],
354 platforms=['linux'],
355 arch='default',
356 compiler='python_alpine',
357 labels=['portability', 'multilang'],
358 extra_args=extra_args,
359 inner_jobs=inner_jobs)
Ken Payson02909062017-05-04 12:33:58 -0700360
ncteisen888093c2017-12-11 18:00:40 -0800361 test_jobs += _generate_jobs(
362 languages=['csharp'],
363 configs=['dbg'],
364 platforms=['linux'],
365 arch='default',
366 compiler='coreclr',
367 labels=['portability', 'multilang'],
368 extra_args=extra_args,
369 inner_jobs=inner_jobs)
murgatroid99804c9e92016-12-05 12:19:57 -0800370
ncteisen888093c2017-12-11 18:00:40 -0800371 test_jobs += _generate_jobs(
372 languages=['c'],
373 configs=['dbg'],
374 platforms=['linux'],
375 iomgr_platform='uv',
376 labels=['portability', 'corelang'],
377 extra_args=extra_args,
378 inner_jobs=inner_jobs,
379 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991191b722017-02-08 11:56:52 -0800380
ncteisen888093c2017-12-11 18:00:40 -0800381 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200382
383
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200384def _allowed_labels():
ncteisen888093c2017-12-11 18:00:40 -0800385 """Returns a list of existing job labels."""
386 all_labels = set()
387 for job in _create_test_jobs() + _create_portability_test_jobs():
388 for label in job.labels:
389 all_labels.add(label)
390 return sorted(all_labels)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200391
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200392
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100393def _runs_per_test_type(arg_str):
ncteisen888093c2017-12-11 18:00:40 -0800394 """Auxiliary function to parse the "runs_per_test" flag."""
395 try:
396 n = int(arg_str)
397 if n <= 0: raise ValueError
398 return n
399 except:
400 msg = '\'{}\' is not a positive integer'.format(arg_str)
401 raise argparse.ArgumentTypeError(msg)
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100402
403
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700404if __name__ == "__main__":
ncteisen888093c2017-12-11 18:00:40 -0800405 argp = argparse.ArgumentParser(
406 description='Run a matrix of run_tests.py tests.')
407 argp.add_argument(
408 '-j',
409 '--jobs',
410 default=multiprocessing.cpu_count() / _DEFAULT_INNER_JOBS,
411 type=int,
412 help='Number of concurrent run_tests.py instances.')
413 argp.add_argument(
414 '-f',
415 '--filter',
416 choices=_allowed_labels(),
417 nargs='+',
418 default=[],
419 help='Filter targets to run by label with AND semantics.')
420 argp.add_argument(
421 '--exclude',
422 choices=_allowed_labels(),
423 nargs='+',
424 default=[],
425 help='Exclude targets with any of given labels.')
426 argp.add_argument(
427 '--build_only',
428 default=False,
429 action='store_const',
430 const=True,
431 help='Pass --build_only flag to run_tests.py instances.')
432 argp.add_argument(
433 '--force_default_poller',
434 default=False,
435 action='store_const',
436 const=True,
437 help='Pass --force_default_poller to run_tests.py instances.')
438 argp.add_argument(
439 '--dry_run',
440 default=False,
441 action='store_const',
442 const=True,
443 help='Only print what would be run.')
444 argp.add_argument(
445 '--filter_pr_tests',
446 default=False,
447 action='store_const',
448 const=True,
449 help='Filters out tests irrelevant to pull request changes.')
450 argp.add_argument(
451 '--base_branch',
452 default='origin/master',
453 type=str,
454 help='Branch that pull request is requesting to merge into')
455 argp.add_argument(
456 '--inner_jobs',
457 default=_DEFAULT_INNER_JOBS,
458 type=int,
459 help='Number of jobs in each run_tests.py instance')
460 argp.add_argument(
461 '-n',
462 '--runs_per_test',
463 default=1,
464 type=_runs_per_test_type,
465 help='How many times to run each tests. >1 runs implies ' +
466 'omitting passing test from the output & reports.')
467 argp.add_argument(
468 '--max_time',
469 default=-1,
470 type=int,
471 help='Maximum amount of time to run tests for' +
472 '(other tests will be skipped)')
473 argp.add_argument(
474 '--internal_ci',
475 default=False,
476 action='store_const',
477 const=True,
478 help='Put reports into subdirectories to improve presentation of '
479 'results by Internal CI.')
480 argp.add_argument(
481 '--bq_result_table',
482 default='',
483 type=str,
484 nargs='?',
485 help='Upload test results to a specified BQ table.')
486 args = argp.parse_args()
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200487
ncteisen888093c2017-12-11 18:00:40 -0800488 if args.internal_ci:
489 _report_filename = _report_filename_internal_ci # override the function
Jan Tattermuschac9c9f92017-04-28 20:56:05 +0200490
ncteisen888093c2017-12-11 18:00:40 -0800491 extra_args = []
492 if args.build_only:
493 extra_args.append('--build_only')
494 if args.force_default_poller:
495 extra_args.append('--force_default_poller')
496 if args.runs_per_test > 1:
497 extra_args.append('-n')
498 extra_args.append('%s' % args.runs_per_test)
499 extra_args.append('--quiet_success')
500 if args.max_time > 0:
501 extra_args.extend(('--max_time', '%d' % args.max_time))
502 if args.bq_result_table:
503 extra_args.append('--bq_result_table')
504 extra_args.append('%s' % args.bq_result_table)
505 extra_args.append('--measure_cpu_costs')
506 extra_args.append('--disable_auto_set_flakes')
Matt Kwongfef98962016-10-27 10:45:47 -0700507
ncteisen888093c2017-12-11 18:00:40 -0800508 all_jobs = _create_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) + \
509 _create_portability_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200510
ncteisen888093c2017-12-11 18:00:40 -0800511 jobs = []
512 for job in all_jobs:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800513 if not args.filter or all(
514 filter in job.labels for filter in args.filter):
ncteisen888093c2017-12-11 18:00:40 -0800515 if not any(exclude_label in job.labels
516 for exclude_label in args.exclude):
517 jobs.append(job)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200518
ncteisen888093c2017-12-11 18:00:40 -0800519 if not jobs:
520 jobset.message(
521 'FAILED', 'No test suites match given criteria.', do_newline=True)
522 sys.exit(1)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200523
ncteisen888093c2017-12-11 18:00:40 -0800524 print('IMPORTANT: The changes you are testing need to be locally committed')
525 print('because only the committed changes in the current branch will be')
526 print('copied to the docker environment or into subworkspaces.')
murgatroid991687cab2016-10-11 11:42:01 -0700527
ncteisen888093c2017-12-11 18:00:40 -0800528 skipped_jobs = []
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200529
ncteisen888093c2017-12-11 18:00:40 -0800530 if args.filter_pr_tests:
531 print('Looking for irrelevant tests to skip...')
532 relevant_jobs = filter_tests(jobs, args.base_branch)
533 if len(relevant_jobs) == len(jobs):
534 print('No tests will be skipped.')
535 else:
536 print('These tests will be skipped:')
537 skipped_jobs = list(set(jobs) - set(relevant_jobs))
538 # Sort by shortnames to make printing of skipped tests consistent
539 skipped_jobs.sort(key=lambda job: job.shortname)
540 for job in list(skipped_jobs):
541 print(' %s' % job.shortname)
542 jobs = relevant_jobs
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700543
ncteisen888093c2017-12-11 18:00:40 -0800544 print('Will run these tests:')
545 for job in jobs:
546 if args.dry_run:
547 print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))
548 else:
549 print(' %s' % job.shortname)
550 print
551
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700552 if args.dry_run:
ncteisen888093c2017-12-11 18:00:40 -0800553 print('--dry_run was used, exiting')
554 sys.exit(1)
555
556 jobset.message('START', 'Running test matrix.', do_newline=True)
557 num_failures, resultset = jobset.run(
558 jobs, newline_on_success=True, travis=True, maxjobs=args.jobs)
559 # Merge skipped tests into results to show skipped tests on report.xml
560 if skipped_jobs:
561 ignored_num_skipped_failures, skipped_results = jobset.run(
562 skipped_jobs, skip_jobs=True)
563 resultset.update(skipped_results)
564 report_utils.render_junit_xml_report(
565 resultset,
566 _report_filename('aggregate_tests'),
567 suite_name='aggregate_tests')
568
569 if num_failures == 0:
570 jobset.message(
571 'SUCCESS',
572 'All run_tests.py instance finished successfully.',
573 do_newline=True)
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700574 else:
ncteisen888093c2017-12-11 18:00:40 -0800575 jobset.message(
576 'FAILED',
577 'Some run_tests.py instance have failed.',
578 do_newline=True)
579 sys.exit(1)