blob: e43319beba603ce2da75b2fcf8133de98daa79b8 [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
Muxi Yanb94f3b32018-02-26 13:06:30 -080040# Set timeout high for ObjC for Cocoapods to install pods
41_OBJC_RUNTESTS_TIMEOUT = 90 * 60
42
Jan Tattermuscha1906d52016-09-19 18:37:17 +020043# Number of jobs assigned to each run_tests.py instance
Matt Kwongfef98962016-10-27 10:45:47 -070044_DEFAULT_INNER_JOBS = 2
Jan Tattermuscha1906d52016-09-19 18:37:17 +020045
Jan Tattermusch5a59c432017-03-07 19:57:13 +010046# report suffix is important for reports to get picked up by internal CI
47_REPORT_SUFFIX = 'sponge_log.xml'
48
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020049
Jan Tattermusch41d220e2018-01-22 17:02:44 +010050def _safe_report_name(name):
51 """Reports with '+' in target name won't show correctly in ResultStore"""
52 return name.replace('+', 'p')
53
54
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020055def _report_filename(name):
ncteisen888093c2017-12-11 18:00:40 -080056 """Generates report file name"""
Jan Tattermusch41d220e2018-01-22 17:02:44 +010057 return 'report_%s_%s' % (_safe_report_name(name), _REPORT_SUFFIX)
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020058
59
60def _report_filename_internal_ci(name):
ncteisen888093c2017-12-11 18:00:40 -080061 """Generates report file name that leads to better presentation by internal CI"""
Jan Tattermusch41d220e2018-01-22 17:02:44 +010062 return '%s/%s' % (_safe_report_name(name), _REPORT_SUFFIX)
Jan Tattermuschac9c9f92017-04-28 20:56:05 +020063
64
ncteisen888093c2017-12-11 18:00:40 -080065def _docker_jobspec(name,
66 runtests_args=[],
67 runtests_envs={},
Jan Tattermusch29828c52017-09-12 16:42:55 +020068 inner_jobs=_DEFAULT_INNER_JOBS,
69 timeout_seconds=None):
ncteisen888093c2017-12-11 18:00:40 -080070 """Run a single instance of run_tests.py in a docker container"""
71 if not timeout_seconds:
72 timeout_seconds = _DEFAULT_RUNTESTS_TIMEOUT
73 test_job = jobset.JobSpec(
74 cmdline=[
75 'python', 'tools/run_tests/run_tests.py', '--use_docker', '-t',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080076 '-j',
77 str(inner_jobs), '-x',
78 _report_filename(name), '--report_suite_name',
Jan Tattermusch41d220e2018-01-22 17:02:44 +010079 '%s' % _safe_report_name(name)
ncteisen888093c2017-12-11 18:00:40 -080080 ] + runtests_args,
81 environ=runtests_envs,
82 shortname='run_tests_%s' % name,
83 timeout_seconds=timeout_seconds)
84 return test_job
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +020085
86
ncteisen888093c2017-12-11 18:00:40 -080087def _workspace_jobspec(name,
88 runtests_args=[],
89 workspace_name=None,
90 runtests_envs={},
91 inner_jobs=_DEFAULT_INNER_JOBS,
Jan Tattermusch29828c52017-09-12 16:42:55 +020092 timeout_seconds=None):
ncteisen888093c2017-12-11 18:00:40 -080093 """Run a single instance of run_tests.py in a separate workspace"""
94 if not workspace_name:
95 workspace_name = 'workspace_%s' % name
96 if not timeout_seconds:
97 timeout_seconds = _DEFAULT_RUNTESTS_TIMEOUT
98 env = {'WORKSPACE_NAME': workspace_name}
99 env.update(runtests_envs)
100 test_job = jobset.JobSpec(
101 cmdline=[
102 'bash', 'tools/run_tests/helper_scripts/run_tests_in_workspace.sh',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800103 '-t', '-j',
104 str(inner_jobs), '-x',
105 '../%s' % _report_filename(name), '--report_suite_name',
Jan Tattermusch41d220e2018-01-22 17:02:44 +0100106 '%s' % _safe_report_name(name)
ncteisen888093c2017-12-11 18:00:40 -0800107 ] + runtests_args,
108 environ=env,
109 shortname='run_tests_%s' % name,
110 timeout_seconds=timeout_seconds)
111 return test_job
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200112
113
ncteisen888093c2017-12-11 18:00:40 -0800114def _generate_jobs(languages,
115 configs,
116 platforms,
kpayson641bfff8e2018-03-13 22:05:48 -0700117 iomgr_platforms=['native'],
ncteisen888093c2017-12-11 18:00:40 -0800118 arch=None,
119 compiler=None,
120 labels=[],
121 extra_args=[],
122 extra_envs={},
123 inner_jobs=_DEFAULT_INNER_JOBS,
124 timeout_seconds=None):
125 result = []
126 for language in languages:
127 for platform in platforms:
kpayson641bfff8e2018-03-13 22:05:48 -0700128 for iomgr_platform in iomgr_platforms:
129 for config in configs:
130 name = '%s_%s_%s_%s' % (language, platform, config,
131 iomgr_platform)
132 runtests_args = [
133 '-l', language, '-c', config, '--iomgr_platform',
134 iomgr_platform
135 ]
136 if arch or compiler:
137 name += '_%s_%s' % (arch, compiler)
138 runtests_args += [
139 '--arch', arch, '--compiler', compiler
140 ]
141 if '--build_only' in extra_args:
142 name += '_buildonly'
143 for extra_env in extra_envs:
144 name += '_%s_%s' % (extra_env, extra_envs[extra_env])
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200145
kpayson641bfff8e2018-03-13 22:05:48 -0700146 runtests_args += extra_args
147 if platform == 'linux':
148 job = _docker_jobspec(
149 name=name,
150 runtests_args=runtests_args,
151 runtests_envs=extra_envs,
152 inner_jobs=inner_jobs,
153 timeout_seconds=timeout_seconds)
154 else:
155 job = _workspace_jobspec(
156 name=name,
157 runtests_args=runtests_args,
158 runtests_envs=extra_envs,
159 inner_jobs=inner_jobs,
160 timeout_seconds=timeout_seconds)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200161
kpayson641bfff8e2018-03-13 22:05:48 -0700162 job.labels = [platform, config, language, iomgr_platform
163 ] + labels
164 result.append(job)
ncteisen888093c2017-12-11 18:00:40 -0800165 return result
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200166
167
Matt Kwongfef98962016-10-27 10:45:47 -0700168def _create_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS):
ncteisen888093c2017-12-11 18:00:40 -0800169 test_jobs = []
170 # supported on linux only
171 test_jobs += _generate_jobs(
172 languages=['sanity', 'php7'],
173 configs=['dbg', 'opt'],
174 platforms=['linux'],
175 labels=['basictests', 'multilang'],
176 extra_args=extra_args,
177 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700178
ncteisen888093c2017-12-11 18:00:40 -0800179 # supported on all platforms.
180 test_jobs += _generate_jobs(
181 languages=['c'],
182 configs=['dbg', 'opt'],
183 platforms=['linux', 'macos', 'windows'],
184 labels=['basictests', 'corelang'],
185 extra_args=extra_args,
186 inner_jobs=inner_jobs,
187 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700188
ncteisen888093c2017-12-11 18:00:40 -0800189 test_jobs += _generate_jobs(
kpayson641bfff8e2018-03-13 22:05:48 -0700190 languages=['csharp'],
ncteisen888093c2017-12-11 18:00:40 -0800191 configs=['dbg', 'opt'],
192 platforms=['linux', 'macos', 'windows'],
193 labels=['basictests', 'multilang'],
194 extra_args=extra_args,
195 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700196
kpayson641bfff8e2018-03-13 22:05:48 -0700197 test_jobs += _generate_jobs(
198 languages=['python'],
199 configs=['opt'],
200 platforms=['linux', 'macos', 'windows'],
201 iomgr_platforms=['native', 'gevent'],
202 labels=['basictests', 'multilang'],
203 extra_args=extra_args,
204 inner_jobs=inner_jobs)
205
ncteisen888093c2017-12-11 18:00:40 -0800206 # supported on linux and mac.
207 test_jobs += _generate_jobs(
208 languages=['c++'],
209 configs=['dbg', 'opt'],
210 platforms=['linux', 'macos'],
211 labels=['basictests', 'corelang'],
212 extra_args=extra_args,
213 inner_jobs=inner_jobs,
214 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700215
ncteisen888093c2017-12-11 18:00:40 -0800216 test_jobs += _generate_jobs(
217 languages=['grpc-node', 'ruby', 'php'],
218 configs=['dbg', 'opt'],
219 platforms=['linux', 'macos'],
220 labels=['basictests', 'multilang'],
221 extra_args=extra_args,
222 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700223
ncteisen888093c2017-12-11 18:00:40 -0800224 # supported on mac only.
225 test_jobs += _generate_jobs(
226 languages=['objc'],
227 configs=['dbg', 'opt'],
228 platforms=['macos'],
229 labels=['basictests', 'multilang'],
230 extra_args=extra_args,
Muxi Yanb94f3b32018-02-26 13:06:30 -0800231 inner_jobs=inner_jobs,
232 timeout_seconds=_OBJC_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700233
ncteisen888093c2017-12-11 18:00:40 -0800234 # sanitizers
235 test_jobs += _generate_jobs(
236 languages=['c'],
237 configs=['msan', 'asan', 'tsan', 'ubsan'],
238 platforms=['linux'],
239 labels=['sanitizers', 'corelang'],
240 extra_args=extra_args,
241 inner_jobs=inner_jobs,
242 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
243 test_jobs += _generate_jobs(
244 languages=['c++'],
245 configs=['asan'],
246 platforms=['linux'],
247 labels=['sanitizers', 'corelang'],
248 extra_args=extra_args,
249 inner_jobs=inner_jobs,
250 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
251 test_jobs += _generate_jobs(
252 languages=['c++'],
253 configs=['tsan'],
254 platforms=['linux'],
255 labels=['sanitizers', 'corelang'],
256 extra_args=extra_args,
257 inner_jobs=inner_jobs,
258 timeout_seconds=_CPP_TSAN_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700259
ncteisen888093c2017-12-11 18:00:40 -0800260 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200261
murgatroid991687cab2016-10-11 11:42:01 -0700262
ncteisen888093c2017-12-11 18:00:40 -0800263def _create_portability_test_jobs(extra_args=[],
264 inner_jobs=_DEFAULT_INNER_JOBS):
265 test_jobs = []
266 # portability C x86
267 test_jobs += _generate_jobs(
268 languages=['c'],
269 configs=['dbg'],
270 platforms=['linux'],
271 arch='x86',
272 compiler='default',
273 labels=['portability', 'corelang'],
274 extra_args=extra_args,
275 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700276
ncteisen888093c2017-12-11 18:00:40 -0800277 # portability C and C++ on x64
278 for compiler in [
Jan Tattermusch0614a682018-01-23 11:51:21 +0100279 'gcc4.8', 'gcc5.3', 'gcc7.2', 'gcc_musl', 'clang3.5', 'clang3.6',
280 'clang3.7'
ncteisen888093c2017-12-11 18:00:40 -0800281 ]:
282 test_jobs += _generate_jobs(
283 languages=['c', 'c++'],
284 configs=['dbg'],
285 platforms=['linux'],
286 arch='x64',
287 compiler=compiler,
288 labels=['portability', 'corelang'],
289 extra_args=extra_args,
290 inner_jobs=inner_jobs,
291 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700292
ncteisen888093c2017-12-11 18:00:40 -0800293 # portability C on Windows 64-bit (x86 is the default)
294 test_jobs += _generate_jobs(
295 languages=['c'],
296 configs=['dbg'],
297 platforms=['windows'],
298 arch='x64',
299 compiler='default',
300 labels=['portability', 'corelang'],
301 extra_args=extra_args,
302 inner_jobs=inner_jobs)
Jan Tattermuschadd32252017-06-26 17:13:14 +0200303
ncteisen888093c2017-12-11 18:00:40 -0800304 # portability C++ on Windows
305 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
306 test_jobs += _generate_jobs(
307 languages=['c++'],
308 configs=['dbg'],
309 platforms=['windows'],
310 arch='default',
311 compiler='default',
312 labels=['portability', 'corelang'],
313 extra_args=extra_args + ['--build_only'],
314 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700315
ncteisen888093c2017-12-11 18:00:40 -0800316 # portability C and C++ on Windows using VS2017 (build only)
317 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
318 test_jobs += _generate_jobs(
319 languages=['c', 'c++'],
320 configs=['dbg'],
321 platforms=['windows'],
322 arch='x64',
323 compiler='cmake_vs2017',
324 labels=['portability', 'corelang'],
325 extra_args=extra_args + ['--build_only'],
326 inner_jobs=inner_jobs)
Jan Tattermuscha8003e82017-08-23 15:43:17 +0200327
ncteisen888093c2017-12-11 18:00:40 -0800328 # C and C++ with the c-ares DNS resolver on Linux
329 test_jobs += _generate_jobs(
330 languages=['c', 'c++'],
331 configs=['dbg'],
332 platforms=['linux'],
333 labels=['portability', 'corelang'],
334 extra_args=extra_args,
335 extra_envs={'GRPC_DNS_RESOLVER': 'ares'},
336 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
Yuchen Zeng87b59102016-11-08 10:50:12 -0800337
Vijay Pai9d2d8432018-01-08 15:11:23 -0800338 # C and C++ with no-exceptions on Linux
339 test_jobs += _generate_jobs(
340 languages=['c', 'c++'],
341 configs=['noexcept'],
342 platforms=['linux'],
343 labels=['portability', 'corelang'],
344 extra_args=extra_args,
345 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
346
ncteisen888093c2017-12-11 18:00:40 -0800347 # TODO(zyc): Turn on this test after adding c-ares support on windows.
348 # C with the c-ares DNS resolver on Windows
349 # test_jobs += _generate_jobs(languages=['c'],
350 # configs=['dbg'], platforms=['windows'],
351 # labels=['portability', 'corelang'],
352 # extra_args=extra_args,
353 # extra_envs={'GRPC_DNS_RESOLVER': 'ares'})
Yuchen Zengfdae4bd2016-11-07 17:46:16 -0800354
ncteisen888093c2017-12-11 18:00:40 -0800355 # C and C++ build with cmake on Linux
356 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
357 # to make sure it's buildable at least.
358 test_jobs += _generate_jobs(
359 languages=['c', 'c++'],
360 configs=['dbg'],
361 platforms=['linux'],
362 arch='default',
363 compiler='cmake',
364 labels=['portability', 'corelang'],
365 extra_args=extra_args + ['--build_only'],
366 inner_jobs=inner_jobs)
Jan Tattermuschdfb03bb2017-01-25 19:27:58 +0100367
ncteisen888093c2017-12-11 18:00:40 -0800368 test_jobs += _generate_jobs(
369 languages=['python'],
370 configs=['dbg'],
371 platforms=['linux'],
372 arch='default',
373 compiler='python_alpine',
374 labels=['portability', 'multilang'],
375 extra_args=extra_args,
376 inner_jobs=inner_jobs)
Ken Payson02909062017-05-04 12:33:58 -0700377
ncteisen888093c2017-12-11 18:00:40 -0800378 test_jobs += _generate_jobs(
379 languages=['csharp'],
380 configs=['dbg'],
381 platforms=['linux'],
382 arch='default',
383 compiler='coreclr',
384 labels=['portability', 'multilang'],
385 extra_args=extra_args,
386 inner_jobs=inner_jobs)
murgatroid99804c9e92016-12-05 12:19:57 -0800387
ncteisen888093c2017-12-11 18:00:40 -0800388 test_jobs += _generate_jobs(
389 languages=['c'],
390 configs=['dbg'],
391 platforms=['linux'],
kpayson641bfff8e2018-03-13 22:05:48 -0700392 iomgr_platforms=['uv'],
ncteisen888093c2017-12-11 18:00:40 -0800393 labels=['portability', 'corelang'],
394 extra_args=extra_args,
395 inner_jobs=inner_jobs,
396 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991191b722017-02-08 11:56:52 -0800397
ncteisen888093c2017-12-11 18:00:40 -0800398 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200399
400
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200401def _allowed_labels():
ncteisen888093c2017-12-11 18:00:40 -0800402 """Returns a list of existing job labels."""
403 all_labels = set()
404 for job in _create_test_jobs() + _create_portability_test_jobs():
405 for label in job.labels:
406 all_labels.add(label)
407 return sorted(all_labels)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200408
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200409
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100410def _runs_per_test_type(arg_str):
ncteisen888093c2017-12-11 18:00:40 -0800411 """Auxiliary function to parse the "runs_per_test" flag."""
412 try:
413 n = int(arg_str)
414 if n <= 0: raise ValueError
415 return n
416 except:
417 msg = '\'{}\' is not a positive integer'.format(arg_str)
418 raise argparse.ArgumentTypeError(msg)
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100419
420
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700421if __name__ == "__main__":
ncteisen888093c2017-12-11 18:00:40 -0800422 argp = argparse.ArgumentParser(
423 description='Run a matrix of run_tests.py tests.')
424 argp.add_argument(
425 '-j',
426 '--jobs',
427 default=multiprocessing.cpu_count() / _DEFAULT_INNER_JOBS,
428 type=int,
429 help='Number of concurrent run_tests.py instances.')
430 argp.add_argument(
431 '-f',
432 '--filter',
433 choices=_allowed_labels(),
434 nargs='+',
435 default=[],
436 help='Filter targets to run by label with AND semantics.')
437 argp.add_argument(
438 '--exclude',
439 choices=_allowed_labels(),
440 nargs='+',
441 default=[],
442 help='Exclude targets with any of given labels.')
443 argp.add_argument(
444 '--build_only',
445 default=False,
446 action='store_const',
447 const=True,
448 help='Pass --build_only flag to run_tests.py instances.')
449 argp.add_argument(
450 '--force_default_poller',
451 default=False,
452 action='store_const',
453 const=True,
454 help='Pass --force_default_poller to run_tests.py instances.')
455 argp.add_argument(
456 '--dry_run',
457 default=False,
458 action='store_const',
459 const=True,
460 help='Only print what would be run.')
461 argp.add_argument(
462 '--filter_pr_tests',
463 default=False,
464 action='store_const',
465 const=True,
466 help='Filters out tests irrelevant to pull request changes.')
467 argp.add_argument(
468 '--base_branch',
469 default='origin/master',
470 type=str,
471 help='Branch that pull request is requesting to merge into')
472 argp.add_argument(
473 '--inner_jobs',
474 default=_DEFAULT_INNER_JOBS,
475 type=int,
476 help='Number of jobs in each run_tests.py instance')
477 argp.add_argument(
478 '-n',
479 '--runs_per_test',
480 default=1,
481 type=_runs_per_test_type,
482 help='How many times to run each tests. >1 runs implies ' +
483 'omitting passing test from the output & reports.')
484 argp.add_argument(
485 '--max_time',
486 default=-1,
487 type=int,
488 help='Maximum amount of time to run tests for' +
489 '(other tests will be skipped)')
490 argp.add_argument(
491 '--internal_ci',
492 default=False,
493 action='store_const',
494 const=True,
495 help='Put reports into subdirectories to improve presentation of '
496 'results by Internal CI.')
497 argp.add_argument(
498 '--bq_result_table',
499 default='',
500 type=str,
501 nargs='?',
502 help='Upload test results to a specified BQ table.')
503 args = argp.parse_args()
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200504
ncteisen888093c2017-12-11 18:00:40 -0800505 if args.internal_ci:
506 _report_filename = _report_filename_internal_ci # override the function
Jan Tattermuschac9c9f92017-04-28 20:56:05 +0200507
ncteisen888093c2017-12-11 18:00:40 -0800508 extra_args = []
509 if args.build_only:
510 extra_args.append('--build_only')
511 if args.force_default_poller:
512 extra_args.append('--force_default_poller')
513 if args.runs_per_test > 1:
514 extra_args.append('-n')
515 extra_args.append('%s' % args.runs_per_test)
516 extra_args.append('--quiet_success')
517 if args.max_time > 0:
518 extra_args.extend(('--max_time', '%d' % args.max_time))
519 if args.bq_result_table:
520 extra_args.append('--bq_result_table')
521 extra_args.append('%s' % args.bq_result_table)
522 extra_args.append('--measure_cpu_costs')
523 extra_args.append('--disable_auto_set_flakes')
Matt Kwongfef98962016-10-27 10:45:47 -0700524
ncteisen888093c2017-12-11 18:00:40 -0800525 all_jobs = _create_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) + \
526 _create_portability_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200527
ncteisen888093c2017-12-11 18:00:40 -0800528 jobs = []
529 for job in all_jobs:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800530 if not args.filter or all(
531 filter in job.labels for filter in args.filter):
ncteisen888093c2017-12-11 18:00:40 -0800532 if not any(exclude_label in job.labels
533 for exclude_label in args.exclude):
534 jobs.append(job)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200535
ncteisen888093c2017-12-11 18:00:40 -0800536 if not jobs:
537 jobset.message(
538 'FAILED', 'No test suites match given criteria.', do_newline=True)
539 sys.exit(1)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200540
ncteisen888093c2017-12-11 18:00:40 -0800541 print('IMPORTANT: The changes you are testing need to be locally committed')
542 print('because only the committed changes in the current branch will be')
543 print('copied to the docker environment or into subworkspaces.')
murgatroid991687cab2016-10-11 11:42:01 -0700544
ncteisen888093c2017-12-11 18:00:40 -0800545 skipped_jobs = []
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200546
ncteisen888093c2017-12-11 18:00:40 -0800547 if args.filter_pr_tests:
548 print('Looking for irrelevant tests to skip...')
549 relevant_jobs = filter_tests(jobs, args.base_branch)
550 if len(relevant_jobs) == len(jobs):
551 print('No tests will be skipped.')
552 else:
553 print('These tests will be skipped:')
554 skipped_jobs = list(set(jobs) - set(relevant_jobs))
555 # Sort by shortnames to make printing of skipped tests consistent
556 skipped_jobs.sort(key=lambda job: job.shortname)
557 for job in list(skipped_jobs):
558 print(' %s' % job.shortname)
559 jobs = relevant_jobs
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700560
ncteisen888093c2017-12-11 18:00:40 -0800561 print('Will run these tests:')
562 for job in jobs:
563 if args.dry_run:
564 print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))
565 else:
566 print(' %s' % job.shortname)
567 print
568
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700569 if args.dry_run:
ncteisen888093c2017-12-11 18:00:40 -0800570 print('--dry_run was used, exiting')
571 sys.exit(1)
572
573 jobset.message('START', 'Running test matrix.', do_newline=True)
574 num_failures, resultset = jobset.run(
575 jobs, newline_on_success=True, travis=True, maxjobs=args.jobs)
576 # Merge skipped tests into results to show skipped tests on report.xml
577 if skipped_jobs:
578 ignored_num_skipped_failures, skipped_results = jobset.run(
579 skipped_jobs, skip_jobs=True)
580 resultset.update(skipped_results)
581 report_utils.render_junit_xml_report(
582 resultset,
583 _report_filename('aggregate_tests'),
584 suite_name='aggregate_tests')
585
586 if num_failures == 0:
587 jobset.message(
588 'SUCCESS',
589 'All run_tests.py instance finished successfully.',
590 do_newline=True)
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700591 else:
ncteisen888093c2017-12-11 18:00:40 -0800592 jobset.message(
593 'FAILED',
594 'Some run_tests.py instance have failed.',
595 do_newline=True)
596 sys.exit(1)