blob: 85f91b04463a488e50958f0e619b9b3623017c6a [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 = []
Jan Tattermuschba5c7a52018-03-28 11:21:03 +0200170 # sanity tests
171 test_jobs += _generate_jobs(
172 languages=['sanity'],
173 configs=['dbg', 'opt'],
174 platforms=['linux'],
175 labels=['basictests'],
176 extra_args=extra_args,
177 inner_jobs=inner_jobs)
178
ncteisen888093c2017-12-11 18:00:40 -0800179 # supported on linux only
180 test_jobs += _generate_jobs(
Jan Tattermuschba5c7a52018-03-28 11:21:03 +0200181 languages=['php7'],
ncteisen888093c2017-12-11 18:00:40 -0800182 configs=['dbg', 'opt'],
183 platforms=['linux'],
184 labels=['basictests', 'multilang'],
185 extra_args=extra_args,
186 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700187
ncteisen888093c2017-12-11 18:00:40 -0800188 # supported on all platforms.
189 test_jobs += _generate_jobs(
190 languages=['c'],
191 configs=['dbg', 'opt'],
192 platforms=['linux', 'macos', 'windows'],
193 labels=['basictests', 'corelang'],
194 extra_args=extra_args,
195 inner_jobs=inner_jobs,
196 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700197
ncteisen888093c2017-12-11 18:00:40 -0800198 test_jobs += _generate_jobs(
kpayson641bfff8e2018-03-13 22:05:48 -0700199 languages=['csharp'],
ncteisen888093c2017-12-11 18:00:40 -0800200 configs=['dbg', 'opt'],
201 platforms=['linux', 'macos', 'windows'],
202 labels=['basictests', 'multilang'],
203 extra_args=extra_args,
204 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700205
kpayson641bfff8e2018-03-13 22:05:48 -0700206 test_jobs += _generate_jobs(
207 languages=['python'],
208 configs=['opt'],
209 platforms=['linux', 'macos', 'windows'],
210 iomgr_platforms=['native', 'gevent'],
211 labels=['basictests', 'multilang'],
212 extra_args=extra_args,
213 inner_jobs=inner_jobs)
214
ncteisen888093c2017-12-11 18:00:40 -0800215 # supported on linux and mac.
216 test_jobs += _generate_jobs(
217 languages=['c++'],
218 configs=['dbg', 'opt'],
219 platforms=['linux', 'macos'],
220 labels=['basictests', 'corelang'],
221 extra_args=extra_args,
222 inner_jobs=inner_jobs,
223 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid9938007752017-10-18 11:24:17 -0700224
ncteisen888093c2017-12-11 18:00:40 -0800225 test_jobs += _generate_jobs(
226 languages=['grpc-node', 'ruby', 'php'],
227 configs=['dbg', 'opt'],
228 platforms=['linux', 'macos'],
229 labels=['basictests', 'multilang'],
230 extra_args=extra_args,
231 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700232
ncteisen888093c2017-12-11 18:00:40 -0800233 # supported on mac only.
234 test_jobs += _generate_jobs(
235 languages=['objc'],
236 configs=['dbg', 'opt'],
237 platforms=['macos'],
238 labels=['basictests', 'multilang'],
239 extra_args=extra_args,
Muxi Yanb94f3b32018-02-26 13:06:30 -0800240 inner_jobs=inner_jobs,
241 timeout_seconds=_OBJC_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700242
ncteisen888093c2017-12-11 18:00:40 -0800243 # sanitizers
244 test_jobs += _generate_jobs(
245 languages=['c'],
246 configs=['msan', 'asan', 'tsan', 'ubsan'],
247 platforms=['linux'],
248 labels=['sanitizers', 'corelang'],
249 extra_args=extra_args,
250 inner_jobs=inner_jobs,
251 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
252 test_jobs += _generate_jobs(
253 languages=['c++'],
254 configs=['asan'],
255 platforms=['linux'],
256 labels=['sanitizers', 'corelang'],
257 extra_args=extra_args,
258 inner_jobs=inner_jobs,
259 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
260 test_jobs += _generate_jobs(
261 languages=['c++'],
262 configs=['tsan'],
263 platforms=['linux'],
264 labels=['sanitizers', 'corelang'],
265 extra_args=extra_args,
266 inner_jobs=inner_jobs,
267 timeout_seconds=_CPP_TSAN_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700268
ncteisen888093c2017-12-11 18:00:40 -0800269 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200270
murgatroid991687cab2016-10-11 11:42:01 -0700271
ncteisen888093c2017-12-11 18:00:40 -0800272def _create_portability_test_jobs(extra_args=[],
273 inner_jobs=_DEFAULT_INNER_JOBS):
274 test_jobs = []
275 # portability C x86
276 test_jobs += _generate_jobs(
277 languages=['c'],
278 configs=['dbg'],
279 platforms=['linux'],
280 arch='x86',
281 compiler='default',
282 labels=['portability', 'corelang'],
283 extra_args=extra_args,
284 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700285
ncteisen888093c2017-12-11 18:00:40 -0800286 # portability C and C++ on x64
287 for compiler in [
Jan Tattermusch0614a682018-01-23 11:51:21 +0100288 'gcc4.8', 'gcc5.3', 'gcc7.2', 'gcc_musl', 'clang3.5', 'clang3.6',
289 'clang3.7'
ncteisen888093c2017-12-11 18:00:40 -0800290 ]:
291 test_jobs += _generate_jobs(
292 languages=['c', 'c++'],
293 configs=['dbg'],
294 platforms=['linux'],
295 arch='x64',
296 compiler=compiler,
297 labels=['portability', 'corelang'],
298 extra_args=extra_args,
299 inner_jobs=inner_jobs,
300 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991687cab2016-10-11 11:42:01 -0700301
ncteisen888093c2017-12-11 18:00:40 -0800302 # portability C on Windows 64-bit (x86 is the default)
303 test_jobs += _generate_jobs(
304 languages=['c'],
305 configs=['dbg'],
306 platforms=['windows'],
307 arch='x64',
308 compiler='default',
309 labels=['portability', 'corelang'],
310 extra_args=extra_args,
311 inner_jobs=inner_jobs)
Jan Tattermuschadd32252017-06-26 17:13:14 +0200312
ncteisen888093c2017-12-11 18:00:40 -0800313 # portability C++ on Windows
314 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
315 test_jobs += _generate_jobs(
316 languages=['c++'],
317 configs=['dbg'],
318 platforms=['windows'],
319 arch='default',
320 compiler='default',
321 labels=['portability', 'corelang'],
322 extra_args=extra_args + ['--build_only'],
323 inner_jobs=inner_jobs)
murgatroid991687cab2016-10-11 11:42:01 -0700324
ncteisen888093c2017-12-11 18:00:40 -0800325 # portability C and C++ on Windows using VS2017 (build only)
326 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
327 test_jobs += _generate_jobs(
328 languages=['c', 'c++'],
329 configs=['dbg'],
330 platforms=['windows'],
331 arch='x64',
332 compiler='cmake_vs2017',
333 labels=['portability', 'corelang'],
334 extra_args=extra_args + ['--build_only'],
335 inner_jobs=inner_jobs)
Jan Tattermuscha8003e82017-08-23 15:43:17 +0200336
ncteisen888093c2017-12-11 18:00:40 -0800337 # C and C++ with the c-ares DNS resolver on Linux
338 test_jobs += _generate_jobs(
339 languages=['c', 'c++'],
340 configs=['dbg'],
341 platforms=['linux'],
342 labels=['portability', 'corelang'],
343 extra_args=extra_args,
344 extra_envs={'GRPC_DNS_RESOLVER': 'ares'},
345 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
Yuchen Zeng87b59102016-11-08 10:50:12 -0800346
Vijay Pai9d2d8432018-01-08 15:11:23 -0800347 # C and C++ with no-exceptions on Linux
348 test_jobs += _generate_jobs(
349 languages=['c', 'c++'],
350 configs=['noexcept'],
351 platforms=['linux'],
352 labels=['portability', 'corelang'],
353 extra_args=extra_args,
354 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
355
ncteisen888093c2017-12-11 18:00:40 -0800356 # TODO(zyc): Turn on this test after adding c-ares support on windows.
357 # C with the c-ares DNS resolver on Windows
358 # test_jobs += _generate_jobs(languages=['c'],
359 # configs=['dbg'], platforms=['windows'],
360 # labels=['portability', 'corelang'],
361 # extra_args=extra_args,
362 # extra_envs={'GRPC_DNS_RESOLVER': 'ares'})
Yuchen Zengfdae4bd2016-11-07 17:46:16 -0800363
ncteisen888093c2017-12-11 18:00:40 -0800364 # C and C++ build with cmake on Linux
365 # TODO(jtattermusch): some of the tests are failing, so we force --build_only
366 # to make sure it's buildable at least.
367 test_jobs += _generate_jobs(
368 languages=['c', 'c++'],
369 configs=['dbg'],
370 platforms=['linux'],
371 arch='default',
372 compiler='cmake',
373 labels=['portability', 'corelang'],
374 extra_args=extra_args + ['--build_only'],
375 inner_jobs=inner_jobs)
Jan Tattermuschdfb03bb2017-01-25 19:27:58 +0100376
ncteisen888093c2017-12-11 18:00:40 -0800377 test_jobs += _generate_jobs(
378 languages=['python'],
379 configs=['dbg'],
380 platforms=['linux'],
381 arch='default',
382 compiler='python_alpine',
383 labels=['portability', 'multilang'],
384 extra_args=extra_args,
385 inner_jobs=inner_jobs)
Ken Payson02909062017-05-04 12:33:58 -0700386
ncteisen888093c2017-12-11 18:00:40 -0800387 test_jobs += _generate_jobs(
388 languages=['csharp'],
389 configs=['dbg'],
390 platforms=['linux'],
391 arch='default',
392 compiler='coreclr',
393 labels=['portability', 'multilang'],
394 extra_args=extra_args,
395 inner_jobs=inner_jobs)
murgatroid99804c9e92016-12-05 12:19:57 -0800396
ncteisen888093c2017-12-11 18:00:40 -0800397 test_jobs += _generate_jobs(
398 languages=['c'],
399 configs=['dbg'],
400 platforms=['linux'],
kpayson641bfff8e2018-03-13 22:05:48 -0700401 iomgr_platforms=['uv'],
ncteisen888093c2017-12-11 18:00:40 -0800402 labels=['portability', 'corelang'],
403 extra_args=extra_args,
404 inner_jobs=inner_jobs,
405 timeout_seconds=_CPP_RUNTESTS_TIMEOUT)
murgatroid991191b722017-02-08 11:56:52 -0800406
ncteisen888093c2017-12-11 18:00:40 -0800407 return test_jobs
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200408
409
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200410def _allowed_labels():
ncteisen888093c2017-12-11 18:00:40 -0800411 """Returns a list of existing job labels."""
412 all_labels = set()
413 for job in _create_test_jobs() + _create_portability_test_jobs():
414 for label in job.labels:
415 all_labels.add(label)
416 return sorted(all_labels)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200417
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200418
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100419def _runs_per_test_type(arg_str):
ncteisen888093c2017-12-11 18:00:40 -0800420 """Auxiliary function to parse the "runs_per_test" flag."""
421 try:
422 n = int(arg_str)
423 if n <= 0: raise ValueError
424 return n
425 except:
426 msg = '\'{}\' is not a positive integer'.format(arg_str)
427 raise argparse.ArgumentTypeError(msg)
Jan Tattermusch68e27bf2016-12-16 14:09:03 +0100428
429
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700430if __name__ == "__main__":
ncteisen888093c2017-12-11 18:00:40 -0800431 argp = argparse.ArgumentParser(
432 description='Run a matrix of run_tests.py tests.')
433 argp.add_argument(
434 '-j',
435 '--jobs',
436 default=multiprocessing.cpu_count() / _DEFAULT_INNER_JOBS,
437 type=int,
438 help='Number of concurrent run_tests.py instances.')
439 argp.add_argument(
440 '-f',
441 '--filter',
442 choices=_allowed_labels(),
443 nargs='+',
444 default=[],
445 help='Filter targets to run by label with AND semantics.')
446 argp.add_argument(
447 '--exclude',
448 choices=_allowed_labels(),
449 nargs='+',
450 default=[],
451 help='Exclude targets with any of given labels.')
452 argp.add_argument(
453 '--build_only',
454 default=False,
455 action='store_const',
456 const=True,
457 help='Pass --build_only flag to run_tests.py instances.')
458 argp.add_argument(
459 '--force_default_poller',
460 default=False,
461 action='store_const',
462 const=True,
463 help='Pass --force_default_poller to run_tests.py instances.')
464 argp.add_argument(
465 '--dry_run',
466 default=False,
467 action='store_const',
468 const=True,
469 help='Only print what would be run.')
470 argp.add_argument(
471 '--filter_pr_tests',
472 default=False,
473 action='store_const',
474 const=True,
475 help='Filters out tests irrelevant to pull request changes.')
476 argp.add_argument(
477 '--base_branch',
478 default='origin/master',
479 type=str,
480 help='Branch that pull request is requesting to merge into')
481 argp.add_argument(
482 '--inner_jobs',
483 default=_DEFAULT_INNER_JOBS,
484 type=int,
485 help='Number of jobs in each run_tests.py instance')
486 argp.add_argument(
487 '-n',
488 '--runs_per_test',
489 default=1,
490 type=_runs_per_test_type,
491 help='How many times to run each tests. >1 runs implies ' +
492 'omitting passing test from the output & reports.')
493 argp.add_argument(
494 '--max_time',
495 default=-1,
496 type=int,
497 help='Maximum amount of time to run tests for' +
498 '(other tests will be skipped)')
499 argp.add_argument(
500 '--internal_ci',
501 default=False,
502 action='store_const',
503 const=True,
504 help='Put reports into subdirectories to improve presentation of '
505 'results by Internal CI.')
506 argp.add_argument(
507 '--bq_result_table',
508 default='',
509 type=str,
510 nargs='?',
511 help='Upload test results to a specified BQ table.')
512 args = argp.parse_args()
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200513
ncteisen888093c2017-12-11 18:00:40 -0800514 if args.internal_ci:
515 _report_filename = _report_filename_internal_ci # override the function
Jan Tattermuschac9c9f92017-04-28 20:56:05 +0200516
ncteisen888093c2017-12-11 18:00:40 -0800517 extra_args = []
518 if args.build_only:
519 extra_args.append('--build_only')
520 if args.force_default_poller:
521 extra_args.append('--force_default_poller')
522 if args.runs_per_test > 1:
523 extra_args.append('-n')
524 extra_args.append('%s' % args.runs_per_test)
525 extra_args.append('--quiet_success')
526 if args.max_time > 0:
527 extra_args.extend(('--max_time', '%d' % args.max_time))
528 if args.bq_result_table:
529 extra_args.append('--bq_result_table')
530 extra_args.append('%s' % args.bq_result_table)
531 extra_args.append('--measure_cpu_costs')
532 extra_args.append('--disable_auto_set_flakes')
Matt Kwongfef98962016-10-27 10:45:47 -0700533
ncteisen888093c2017-12-11 18:00:40 -0800534 all_jobs = _create_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) + \
535 _create_portability_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200536
ncteisen888093c2017-12-11 18:00:40 -0800537 jobs = []
538 for job in all_jobs:
Mehrdad Afshari87cd9942018-01-02 14:40:00 -0800539 if not args.filter or all(
540 filter in job.labels for filter in args.filter):
ncteisen888093c2017-12-11 18:00:40 -0800541 if not any(exclude_label in job.labels
542 for exclude_label in args.exclude):
543 jobs.append(job)
Jan Tattermusch6d7c6ef2016-09-22 13:40:48 +0200544
ncteisen888093c2017-12-11 18:00:40 -0800545 if not jobs:
546 jobset.message(
547 'FAILED', 'No test suites match given criteria.', do_newline=True)
548 sys.exit(1)
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200549
ncteisen888093c2017-12-11 18:00:40 -0800550 print('IMPORTANT: The changes you are testing need to be locally committed')
551 print('because only the committed changes in the current branch will be')
552 print('copied to the docker environment or into subworkspaces.')
murgatroid991687cab2016-10-11 11:42:01 -0700553
ncteisen888093c2017-12-11 18:00:40 -0800554 skipped_jobs = []
Jan Tattermusch9c79e8d2016-09-19 14:33:18 +0200555
ncteisen888093c2017-12-11 18:00:40 -0800556 if args.filter_pr_tests:
557 print('Looking for irrelevant tests to skip...')
558 relevant_jobs = filter_tests(jobs, args.base_branch)
559 if len(relevant_jobs) == len(jobs):
560 print('No tests will be skipped.')
561 else:
562 print('These tests will be skipped:')
563 skipped_jobs = list(set(jobs) - set(relevant_jobs))
564 # Sort by shortnames to make printing of skipped tests consistent
565 skipped_jobs.sort(key=lambda job: job.shortname)
566 for job in list(skipped_jobs):
567 print(' %s' % job.shortname)
568 jobs = relevant_jobs
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700569
ncteisen888093c2017-12-11 18:00:40 -0800570 print('Will run these tests:')
571 for job in jobs:
572 if args.dry_run:
573 print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))
574 else:
575 print(' %s' % job.shortname)
576 print
577
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700578 if args.dry_run:
ncteisen888093c2017-12-11 18:00:40 -0800579 print('--dry_run was used, exiting')
580 sys.exit(1)
581
582 jobset.message('START', 'Running test matrix.', do_newline=True)
583 num_failures, resultset = jobset.run(
584 jobs, newline_on_success=True, travis=True, maxjobs=args.jobs)
585 # Merge skipped tests into results to show skipped tests on report.xml
586 if skipped_jobs:
587 ignored_num_skipped_failures, skipped_results = jobset.run(
588 skipped_jobs, skip_jobs=True)
589 resultset.update(skipped_results)
590 report_utils.render_junit_xml_report(
591 resultset,
592 _report_filename('aggregate_tests'),
593 suite_name='aggregate_tests')
594
595 if num_failures == 0:
596 jobset.message(
597 'SUCCESS',
598 'All run_tests.py instance finished successfully.',
599 do_newline=True)
Matt Kwong7e9bd6c2016-10-24 17:30:25 -0700600 else:
ncteisen888093c2017-12-11 18:00:40 -0800601 jobset.message(
602 'FAILED',
603 'Some run_tests.py instance have failed.',
604 do_newline=True)
605 sys.exit(1)