blob: 433137a9bc02a1515a3470156c1ff5b45aa6b304 [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 [
Jan Tattermusch0614a682018-01-23 11:51:21 +0100263 'gcc4.8', 'gcc5.3', 'gcc7.2', 'gcc_musl', 'clang3.5', 'clang3.6',
264 'clang3.7'
ncteisen888093c2017-12-11 18:00:40 -0800265 ]:
266 test_jobs += _generate_jobs(
267 languages=['c', 'c++'],
268 configs=['dbg'],
269 platforms=['linux'],
270 arch='x64',
271 compiler=compiler,
272 labels=['portability', 'corelang'],
273 extra_args=extra_args,
274 inner_jobs=inner_jobs,
275 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700276
ncteisen888093c2017-12-11 18:00:40 -0800277 # portability C on Windows 64-bit (x86 is the default)
278 test_jobs += _generate_jobs(
279 languages=['c'],
280 configs=['dbg'],
281 platforms=['windows'],
282 arch='x64',
283 compiler='default',
284 labels=['portability', 'corelang'],
285 extra_args=extra_args,
286 inner_jobs=inner_jobs)
Jan Tattermuschadd32252017-06-26 17:13:14 +0200287
ncteisen888093c2017-12-11 18:00:40 -0800288 # portability C++ on Windows
289 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
290 test_jobs += _generate_jobs(
291 languages=['c++'],
292 configs=['dbg'],
293 platforms=['windows'],
294 arch='default',
295 compiler='default',
296 labels=['portability', 'corelang'],
297 extra_args=extra_args + ['--build_only'],
298 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700299
ncteisen888093c2017-12-11 18:00:40 -0800300 # portability C and C++ on Windows using VS2017 (build only)
301 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
302 test_jobs += _generate_jobs(
303 languages=['c', 'c++'],
304 configs=['dbg'],
305 platforms=['windows'],
306 arch='x64',
307 compiler='cmake_vs2017',
308 labels=['portability', 'corelang'],
309 extra_args=extra_args + ['--build_only'],
310 inner_jobs=inner_jobs)
Jan Tattermuscha8003e82017-08-23 15:43:17 +0200311
ncteisen888093c2017-12-11 18:00:40 -0800312 # C and C++ with the c-ares DNS resolver on Linux
313 test_jobs += _generate_jobs(
314 languages=['c', 'c++'],
315 configs=['dbg'],
316 platforms=['linux'],
317 labels=['portability', 'corelang'],
318 extra_args=extra_args,
319 extra_envs={'GRPC_DNS_RESOLVER': 'ares'},
320 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
Yuchen Zeng87b59102016-11-08 10:50:12 -0800321
Vijay Pai9d2d8432018-01-08 15:11:23 -0800322 # C and C++ with no-exceptions on Linux
323 test_jobs += _generate_jobs(
324 languages=['c', 'c++'],
325 configs=['noexcept'],
326 platforms=['linux'],
327 labels=['portability', 'corelang'],
328 extra_args=extra_args,
329 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
330
ncteisen888093c2017-12-11 18:00:40 -0800331 # TODO(zyc): Turn on this test after adding c-ares support on windows.
332 # C with the c-ares DNS resolver on Windows
333 # test_jobs += _generate_jobs(languages=['c'],
334 # configs=['dbg'], platforms=['windows'],
335 # labels=['portability', 'corelang'],
336 # extra_args=extra_args,
337 # extra_envs={'GRPC_DNS_RESOLVER': 'ares'})
Yuchen Zengfdae4bd2016-11-07 17:46:16 -0800338
ncteisen888093c2017-12-11 18:00:40 -0800339 # C and C++ build with cmake on Linux
340 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
341 # to make sure it's buildable at least.
342 test_jobs += _generate_jobs(
343 languages=['c', 'c++'],
344 configs=['dbg'],
345 platforms=['linux'],
346 arch='default',
347 compiler='cmake',
348 labels=['portability', 'corelang'],
349 extra_args=extra_args + ['--build_only'],
350 inner_jobs=inner_jobs)
Jan Tattermuschdfb03bb2017-01-25 19:27:58 +0100351
ncteisen888093c2017-12-11 18:00:40 -0800352 test_jobs += _generate_jobs(
353 languages=['python'],
354 configs=['dbg'],
355 platforms=['linux'],
356 arch='default',
357 compiler='python_alpine',
358 labels=['portability', 'multilang'],
359 extra_args=extra_args,
360 inner_jobs=inner_jobs)
Ken Payson02909062017-05-04 12:33:58 -0700361
ncteisen888093c2017-12-11 18:00:40 -0800362 test_jobs += _generate_jobs(
363 languages=['csharp'],
364 configs=['dbg'],
365 platforms=['linux'],
366 arch='default',
367 compiler='coreclr',
368 labels=['portability', 'multilang'],
369 extra_args=extra_args,
370 inner_jobs=inner_jobs)
murgatroid99804c9e92016-12-05 12:19:57 -0800371
ncteisen888093c2017-12-11 18:00:40 -0800372 test_jobs += _generate_jobs(
373 languages=['c'],
374 configs=['dbg'],
375 platforms=['linux'],
376 iomgr_platform='uv',
377 labels=['portability', 'corelang'],
378 extra_args=extra_args,
379 inner_jobs=inner_jobs,
380 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991191b722017-02-08 11:56:52 -0800381
ncteisen888093c2017-12-11 18:00:40 -0800382 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200383
384
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200385def _allowed_labels():
ncteisen888093c2017-12-11 18:00:40 -0800386 """Returns a list of existing job labels."""
387 all_labels = set()
388 for job in _create_test_jobs() + _create_portability_test_jobs():
389 for label in job.labels:
390 all_labels.add(label)
391 return sorted(all_labels)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200392
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200393
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100394def _runs_per_test_type(arg_str):
ncteisen888093c2017-12-11 18:00:40 -0800395 """Auxiliary function to parse the "runs_per_test" flag."""
396 try:
397 n = int(arg_str)
398 if n <= 0: raise ValueError
399 return n
400 except:
401 msg = '\'{}\' is not a positive integer'.format(arg_str)
402 raise argparse.ArgumentTypeError(msg)
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100403
404
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700405if __name__ == "__main__":
ncteisen888093c2017-12-11 18:00:40 -0800406 argp = argparse.ArgumentParser(
407 description='Run a matrix of run_tests.py tests.')
408 argp.add_argument(
409 '-j',
410 '--jobs',
411 default=multiprocessing.cpu_count() / _DEFAULT_INNER_JOBS,
412 type=int,
413 help='Number of concurrent run_tests.py instances.')
414 argp.add_argument(
415 '-f',
416 '--filter',
417 choices=_allowed_labels(),
418 nargs='+',
419 default=[],
420 help='Filter targets to run by label with AND semantics.')
421 argp.add_argument(
422 '--exclude',
423 choices=_allowed_labels(),
424 nargs='+',
425 default=[],
426 help='Exclude targets with any of given labels.')
427 argp.add_argument(
428 '--build_only',
429 default=False,
430 action='store_const',
431 const=True,
432 help='Pass --build_only flag to run_tests.py instances.')
433 argp.add_argument(
434 '--force_default_poller',
435 default=False,
436 action='store_const',
437 const=True,
438 help='Pass --force_default_poller to run_tests.py instances.')
439 argp.add_argument(
440 '--dry_run',
441 default=False,
442 action='store_const',
443 const=True,
444 help='Only print what would be run.')
445 argp.add_argument(
446 '--filter_pr_tests',
447 default=False,
448 action='store_const',
449 const=True,
450 help='Filters out tests irrelevant to pull request changes.')
451 argp.add_argument(
452 '--base_branch',
453 default='origin/master',
454 type=str,
455 help='Branch that pull request is requesting to merge into')
456 argp.add_argument(
457 '--inner_jobs',
458 default=_DEFAULT_INNER_JOBS,
459 type=int,
460 help='Number of jobs in each run_tests.py instance')
461 argp.add_argument(
462 '-n',
463 '--runs_per_test',
464 default=1,
465 type=_runs_per_test_type,
466 help='How many times to run each tests. >1 runs implies ' +
467 'omitting passing test from the output & reports.')
468 argp.add_argument(
469 '--max_time',
470 default=-1,
471 type=int,
472 help='Maximum amount of time to run tests for' +
473 '(other tests will be skipped)')
474 argp.add_argument(
475 '--internal_ci',
476 default=False,
477 action='store_const',
478 const=True,
479 help='Put reports into subdirectories to improve presentation of '
480 'results by Internal CI.')
481 argp.add_argument(
482 '--bq_result_table',
483 default='',
484 type=str,
485 nargs='?',
486 help='Upload test results to a specified BQ table.')
487 args = argp.parse_args()
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200488
ncteisen888093c2017-12-11 18:00:40 -0800489 if args.internal_ci:
490 _report_filename = _report_filename_internal_ci # override the function
Jan Tattermuschac9c9f92017-04-28 20:56:05 +0200491
ncteisen888093c2017-12-11 18:00:40 -0800492 extra_args = []
493 if args.build_only:
494 extra_args.append('--build_only')
495 if args.force_default_poller:
496 extra_args.append('--force_default_poller')
497 if args.runs_per_test > 1:
498 extra_args.append('-n')
499 extra_args.append('%s' % args.runs_per_test)
500 extra_args.append('--quiet_success')
501 if args.max_time > 0:
502 extra_args.extend(('--max_time', '%d' % args.max_time))
503 if args.bq_result_table:
504 extra_args.append('--bq_result_table')
505 extra_args.append('%s' % args.bq_result_table)
506 extra_args.append('--measure_cpu_costs')
507 extra_args.append('--disable_auto_set_flakes')
Matt Kwongfef98962016-10-27 10:45:47 -0700508
ncteisen888093c2017-12-11 18:00:40 -0800509 all_jobs = _create_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) + \
510 _create_portability_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200511
ncteisen888093c2017-12-11 18:00:40 -0800512 jobs = []
513 for job in all_jobs:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800514 if not args.filter or all(
515 filter in job.labels for filter in args.filter):
ncteisen888093c2017-12-11 18:00:40 -0800516 if not any(exclude_label in job.labels
517 for exclude_label in args.exclude):
518 jobs.append(job)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200519
ncteisen888093c2017-12-11 18:00:40 -0800520 if not jobs:
521 jobset.message(
522 'FAILED', 'No test suites match given criteria.', do_newline=True)
523 sys.exit(1)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200524
ncteisen888093c2017-12-11 18:00:40 -0800525 print('IMPORTANT: The changes you are testing need to be locally committed')
526 print('because only the committed changes in the current branch will be')
527 print('copied to the docker environment or into subworkspaces.')
murgatroid991687cab2016-10-11 11:42:01 -0700528
ncteisen888093c2017-12-11 18:00:40 -0800529 skipped_jobs = []
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200530
ncteisen888093c2017-12-11 18:00:40 -0800531 if args.filter_pr_tests:
532 print('Looking for irrelevant tests to skip...')
533 relevant_jobs = filter_tests(jobs, args.base_branch)
534 if len(relevant_jobs) == len(jobs):
535 print('No tests will be skipped.')
536 else:
537 print('These tests will be skipped:')
538 skipped_jobs = list(set(jobs) - set(relevant_jobs))
539 # Sort by shortnames to make printing of skipped tests consistent
540 skipped_jobs.sort(key=lambda job: job.shortname)
541 for job in list(skipped_jobs):
542 print(' %s' % job.shortname)
543 jobs = relevant_jobs
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700544
ncteisen888093c2017-12-11 18:00:40 -0800545 print('Will run these tests:')
546 for job in jobs:
547 if args.dry_run:
548 print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))
549 else:
550 print(' %s' % job.shortname)
551 print
552
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700553 if args.dry_run:
ncteisen888093c2017-12-11 18:00:40 -0800554 print('--dry_run was used, exiting')
555 sys.exit(1)
556
557 jobset.message('START', 'Running test matrix.', do_newline=True)
558 num_failures, resultset = jobset.run(
559 jobs, newline_on_success=True, travis=True, maxjobs=args.jobs)
560 # Merge skipped tests into results to show skipped tests on report.xml
561 if skipped_jobs:
562 ignored_num_skipped_failures, skipped_results = jobset.run(
563 skipped_jobs, skip_jobs=True)
564 resultset.update(skipped_results)
565 report_utils.render_junit_xml_report(
566 resultset,
567 _report_filename('aggregate_tests'),
568 suite_name='aggregate_tests')
569
570 if num_failures == 0:
571 jobset.message(
572 'SUCCESS',
573 'All run_tests.py instance finished successfully.',
574 do_newline=True)
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700575 else:
ncteisen888093c2017-12-11 18:00:40 -0800576 jobset.message(
577 'FAILED',
578 'Some run_tests.py instance have failed.',
579 do_newline=True)
580 sys.exit(1)