Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | # Copyright 2015, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | """Run test matrix.""" |
| 32 | |
| 33 | import argparse |
| 34 | import jobset |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 35 | import multiprocessing |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 36 | import os |
| 37 | import report_utils |
| 38 | import sys |
Matt Kwong | e9163f0 | 2016-10-05 11:42:55 -0700 | [diff] [blame] | 39 | from filter_pull_request_tests import filter_tests |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 40 | |
| 41 | _ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 42 | os.chdir(_ROOT) |
| 43 | |
Jan Tattermusch | 060eb87 | 2016-09-20 16:06:13 +0200 | [diff] [blame] | 44 | # Set the timeout high to allow enough time for sanitizers and pre-building |
| 45 | # clang docker. |
Ken Payson | 97e6920 | 2016-10-17 09:11:49 -0700 | [diff] [blame] | 46 | _RUNTESTS_TIMEOUT = 4*60*60 |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 47 | |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 48 | # Number of jobs assigned to each run_tests.py instance |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 49 | _DEFAULT_INNER_JOBS = 2 |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 50 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 51 | |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 52 | def _docker_jobspec(name, runtests_args=[], runtests_envs={}, |
| 53 | inner_jobs=_DEFAULT_INNER_JOBS): |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 54 | """Run a single instance of run_tests.py in a docker container""" |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 55 | test_job = jobset.JobSpec( |
| 56 | cmdline=['python', 'tools/run_tests/run_tests.py', |
| 57 | '--use_docker', |
| 58 | '-t', |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 59 | '-j', str(inner_jobs), |
Jan Tattermusch | cfcc075 | 2016-10-09 17:02:34 +0200 | [diff] [blame] | 60 | '-x', 'report_%s.xml' % name, |
| 61 | '--report_suite_name', '%s' % name] + runtests_args, |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 62 | environ=runtests_envs, |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 63 | shortname='run_tests_%s' % name, |
| 64 | timeout_seconds=_RUNTESTS_TIMEOUT) |
| 65 | return test_job |
| 66 | |
| 67 | |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 68 | def _workspace_jobspec(name, runtests_args=[], workspace_name=None, |
| 69 | runtests_envs={}, inner_jobs=_DEFAULT_INNER_JOBS): |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 70 | """Run a single instance of run_tests.py in a separate workspace""" |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 71 | if not workspace_name: |
| 72 | workspace_name = 'workspace_%s' % name |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 73 | env = {'WORKSPACE_NAME': workspace_name} |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 74 | env.update(runtests_envs) |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 75 | test_job = jobset.JobSpec( |
| 76 | cmdline=['tools/run_tests/run_tests_in_workspace.sh', |
| 77 | '-t', |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 78 | '-j', str(inner_jobs), |
Jan Tattermusch | cfcc075 | 2016-10-09 17:02:34 +0200 | [diff] [blame] | 79 | '-x', '../report_%s.xml' % name, |
| 80 | '--report_suite_name', '%s' % name] + runtests_args, |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 81 | environ=env, |
| 82 | shortname='run_tests_%s' % name, |
| 83 | timeout_seconds=_RUNTESTS_TIMEOUT) |
| 84 | return test_job |
| 85 | |
| 86 | |
| 87 | def _generate_jobs(languages, configs, platforms, |
| 88 | arch=None, compiler=None, |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 89 | labels=[], extra_args=[], extra_envs={}, |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 90 | inner_jobs=_DEFAULT_INNER_JOBS): |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 91 | result = [] |
| 92 | for language in languages: |
| 93 | for platform in platforms: |
| 94 | for config in configs: |
| 95 | name = '%s_%s_%s' % (language, platform, config) |
| 96 | runtests_args = ['-l', language, |
| 97 | '-c', config] |
| 98 | if arch or compiler: |
| 99 | name += '_%s_%s' % (arch, compiler) |
| 100 | runtests_args += ['--arch', arch, |
| 101 | '--compiler', compiler] |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 102 | for extra_env in extra_envs: |
Yuchen Zeng | 87b5910 | 2016-11-08 10:50:12 -0800 | [diff] [blame^] | 103 | name += '_%s_%s' % (extra_env, extra_envs[extra_env]) |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 104 | |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 105 | runtests_args += extra_args |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 106 | if platform == 'linux': |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 107 | job = _docker_jobspec(name=name, runtests_args=runtests_args, |
| 108 | runtests_envs=extra_envs, inner_jobs=inner_jobs) |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 109 | else: |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 110 | job = _workspace_jobspec(name=name, runtests_args=runtests_args, |
| 111 | runtests_envs=extra_envs, inner_jobs=inner_jobs) |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 112 | |
| 113 | job.labels = [platform, config, language] + labels |
| 114 | result.append(job) |
| 115 | return result |
| 116 | |
| 117 | |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 118 | def _create_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS): |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 119 | test_jobs = [] |
| 120 | # supported on linux only |
| 121 | test_jobs += _generate_jobs(languages=['sanity', 'php7'], |
| 122 | configs=['dbg', 'opt'], |
| 123 | platforms=['linux'], |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 124 | labels=['basictests'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 125 | extra_args=extra_args, |
| 126 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 127 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 128 | # supported on all platforms. |
| 129 | test_jobs += _generate_jobs(languages=['c', 'csharp', 'node', 'python'], |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 130 | configs=['dbg', 'opt'], |
| 131 | platforms=['linux', 'macos', 'windows'], |
| 132 | labels=['basictests'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 133 | extra_args=extra_args, |
| 134 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 135 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 136 | # supported on linux and mac. |
| 137 | test_jobs += _generate_jobs(languages=['c++', 'ruby', 'php'], |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 138 | configs=['dbg', 'opt'], |
| 139 | platforms=['linux', 'macos'], |
| 140 | labels=['basictests'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 141 | extra_args=extra_args, |
| 142 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 143 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 144 | # supported on mac only. |
| 145 | test_jobs += _generate_jobs(languages=['objc'], |
| 146 | configs=['dbg', 'opt'], |
| 147 | platforms=['macos'], |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 148 | labels=['basictests'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 149 | extra_args=extra_args, |
| 150 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 151 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 152 | # sanitizers |
| 153 | test_jobs += _generate_jobs(languages=['c'], |
| 154 | configs=['msan', 'asan', 'tsan'], |
| 155 | platforms=['linux'], |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 156 | labels=['sanitizers'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 157 | extra_args=extra_args, |
| 158 | inner_jobs=inner_jobs) |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 159 | test_jobs += _generate_jobs(languages=['c++'], |
| 160 | configs=['asan', 'tsan'], |
| 161 | platforms=['linux'], |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 162 | labels=['sanitizers'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 163 | extra_args=extra_args, |
| 164 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 165 | |
| 166 | # libuv tests |
| 167 | test_jobs += _generate_jobs(languages=['c'], |
| 168 | configs=['dbg', 'opt'], |
| 169 | platforms=['linux'], |
| 170 | labels=['libuv'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 171 | extra_args=extra_args + ['--iomgr_platform=uv'], |
| 172 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 173 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 174 | return test_jobs |
| 175 | |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 176 | |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 177 | def _create_portability_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS): |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 178 | test_jobs = [] |
| 179 | # portability C x86 |
| 180 | test_jobs += _generate_jobs(languages=['c'], |
| 181 | configs=['dbg'], |
| 182 | platforms=['linux'], |
| 183 | arch='x86', |
| 184 | compiler='default', |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 185 | labels=['portability'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 186 | extra_args=extra_args, |
| 187 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 188 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 189 | # portability C and C++ on x64 |
| 190 | for compiler in ['gcc4.4', 'gcc4.6', 'gcc5.3', |
| 191 | 'clang3.5', 'clang3.6', 'clang3.7']: |
Matt Kwong | e3beac9 | 2016-11-01 12:53:04 -0700 | [diff] [blame] | 192 | test_jobs += _generate_jobs(languages=['c'], |
| 193 | configs=['dbg'], |
| 194 | platforms=['linux'], |
| 195 | arch='x64', |
| 196 | compiler=compiler, |
| 197 | labels=['portability'], |
| 198 | extra_args=extra_args, |
| 199 | inner_jobs=inner_jobs) |
| 200 | for compiler in ['gcc4.8', 'gcc5.3', |
| 201 | 'clang3.5', 'clang3.6', 'clang3.7']: |
| 202 | test_jobs += _generate_jobs(languages=['c++'], |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 203 | configs=['dbg'], |
| 204 | platforms=['linux'], |
| 205 | arch='x64', |
| 206 | compiler=compiler, |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 207 | labels=['portability'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 208 | extra_args=extra_args, |
| 209 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 210 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 211 | # portability C on Windows |
| 212 | for arch in ['x86', 'x64']: |
| 213 | for compiler in ['vs2013', 'vs2015']: |
| 214 | test_jobs += _generate_jobs(languages=['c'], |
| 215 | configs=['dbg'], |
| 216 | platforms=['windows'], |
| 217 | arch=arch, |
| 218 | compiler=compiler, |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 219 | labels=['portability'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 220 | extra_args=extra_args, |
| 221 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 222 | |
Yuchen Zeng | 87b5910 | 2016-11-08 10:50:12 -0800 | [diff] [blame^] | 223 | # C and C++ with the native DNS resolver on Linux |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 224 | test_jobs += _generate_jobs(languages=['c', 'c++'], |
Yuchen Zeng | 87b5910 | 2016-11-08 10:50:12 -0800 | [diff] [blame^] | 225 | configs=['dbg'], platforms=['linux'], |
| 226 | labels=['portability'], |
| 227 | extra_args=extra_args, |
| 228 | extra_envs={'GRPC_DNS_RESOLVER': 'native'}) |
| 229 | |
| 230 | # C with the native DNS resolver on Windonws |
| 231 | test_jobs += _generate_jobs(languages=['c'], |
| 232 | configs=['dbg'], platforms=['windows'], |
Yuchen Zeng | fdae4bd | 2016-11-07 17:46:16 -0800 | [diff] [blame] | 233 | labels=['portability'], |
| 234 | extra_args=extra_args, |
| 235 | extra_envs={'GRPC_DNS_RESOLVER': 'native'}) |
| 236 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 237 | test_jobs += _generate_jobs(languages=['python'], |
| 238 | configs=['dbg'], |
| 239 | platforms=['linux'], |
| 240 | arch='default', |
| 241 | compiler='python3.4', |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 242 | labels=['portability'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 243 | extra_args=extra_args, |
| 244 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 245 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 246 | test_jobs += _generate_jobs(languages=['csharp'], |
| 247 | configs=['dbg'], |
| 248 | platforms=['linux'], |
| 249 | arch='default', |
| 250 | compiler='coreclr', |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 251 | labels=['portability'], |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 252 | extra_args=extra_args, |
| 253 | inner_jobs=inner_jobs) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 254 | return test_jobs |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 255 | |
| 256 | |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 257 | def _allowed_labels(): |
| 258 | """Returns a list of existing job labels.""" |
| 259 | all_labels = set() |
| 260 | for job in _create_test_jobs() + _create_portability_test_jobs(): |
| 261 | for label in job.labels: |
| 262 | all_labels.add(label) |
| 263 | return sorted(all_labels) |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 264 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 265 | |
| 266 | argp = argparse.ArgumentParser(description='Run a matrix of run_tests.py tests.') |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 267 | argp.add_argument('-j', '--jobs', |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 268 | default=multiprocessing.cpu_count()/_DEFAULT_INNER_JOBS, |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 269 | type=int, |
| 270 | help='Number of concurrent run_tests.py instances.') |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 271 | argp.add_argument('-f', '--filter', |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 272 | choices=_allowed_labels(), |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 273 | nargs='+', |
| 274 | default=[], |
| 275 | help='Filter targets to run by label with AND semantics.') |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 276 | argp.add_argument('--build_only', |
| 277 | default=False, |
| 278 | action='store_const', |
| 279 | const=True, |
| 280 | help='Pass --build_only flag to run_tests.py instances.') |
| 281 | argp.add_argument('--force_default_poller', default=False, action='store_const', const=True, |
| 282 | help='Pass --force_default_poller to run_tests.py instances.') |
Jan Tattermusch | c1e4490 | 2016-09-22 14:31:10 +0200 | [diff] [blame] | 283 | argp.add_argument('--dry_run', |
| 284 | default=False, |
| 285 | action='store_const', |
| 286 | const=True, |
| 287 | help='Only print what would be run.') |
Matt Kwong | e9163f0 | 2016-10-05 11:42:55 -0700 | [diff] [blame] | 288 | argp.add_argument('--filter_pr_tests', |
| 289 | default=False, |
| 290 | action='store_const', |
| 291 | const=True, |
| 292 | help='Filters out tests irrelavant to pull request changes.') |
Matt Kwong | f3f2872 | 2016-10-07 15:25:56 -0700 | [diff] [blame] | 293 | argp.add_argument('--base_branch', |
| 294 | default='origin/master', |
| 295 | type=str, |
| 296 | help='Branch that pull request is requesting to merge into') |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 297 | argp.add_argument('--inner_jobs', |
| 298 | default=_DEFAULT_INNER_JOBS, |
| 299 | type=int, |
| 300 | help='Number of jobs in each run_tests.py instance') |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 301 | args = argp.parse_args() |
| 302 | |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 303 | |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 304 | extra_args = [] |
| 305 | if args.build_only: |
| 306 | extra_args.append('--build_only') |
| 307 | if args.force_default_poller: |
| 308 | extra_args.append('--force_default_poller') |
| 309 | |
Matt Kwong | fef9896 | 2016-10-27 10:45:47 -0700 | [diff] [blame] | 310 | all_jobs = _create_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) + \ |
| 311 | _create_portability_test_jobs(extra_args=extra_args, inner_jobs=args.inner_jobs) |
Jan Tattermusch | 6d7c6ef | 2016-09-22 13:40:48 +0200 | [diff] [blame] | 312 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 313 | jobs = [] |
| 314 | for job in all_jobs: |
| 315 | if not args.filter or all(filter in job.labels for filter in args.filter): |
| 316 | jobs.append(job) |
| 317 | |
| 318 | if not jobs: |
| 319 | jobset.message('FAILED', 'No test suites match given criteria.', |
| 320 | do_newline=True) |
| 321 | sys.exit(1) |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 322 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 323 | print('IMPORTANT: The changes you are testing need to be locally committed') |
| 324 | print('because only the committed changes in the current branch will be') |
| 325 | print('copied to the docker environment or into subworkspaces.') |
| 326 | |
murgatroid99 | 1687cab | 2016-10-11 11:42:01 -0700 | [diff] [blame] | 327 | print |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 328 | print 'Will run these tests:' |
| 329 | for job in jobs: |
Jan Tattermusch | 7b9c21a | 2016-09-22 14:44:27 +0200 | [diff] [blame] | 330 | if args.dry_run: |
| 331 | print ' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)) |
| 332 | else: |
| 333 | print ' %s' % job.shortname |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 334 | print |
| 335 | |
Matt Kwong | e9163f0 | 2016-10-05 11:42:55 -0700 | [diff] [blame] | 336 | if args.filter_pr_tests: |
| 337 | print 'IMPORTANT: Test filtering is not active; this is only for testing.' |
Matt Kwong | f3f2872 | 2016-10-07 15:25:56 -0700 | [diff] [blame] | 338 | relevant_jobs = filter_tests(jobs, args.base_branch) |
Matt Kwong | f01122c | 2016-10-12 18:24:53 -0700 | [diff] [blame] | 339 | # todo(mattkwong): add skipped tests to report.xml |
Matt Kwong | e9163f0 | 2016-10-05 11:42:55 -0700 | [diff] [blame] | 340 | print |
| 341 | if len(relevant_jobs) == len(jobs): |
Matt Kwong | f3f2872 | 2016-10-07 15:25:56 -0700 | [diff] [blame] | 342 | print '(TESTING) No tests will be skipped.' |
Matt Kwong | e9163f0 | 2016-10-05 11:42:55 -0700 | [diff] [blame] | 343 | else: |
Matt Kwong | f3f2872 | 2016-10-07 15:25:56 -0700 | [diff] [blame] | 344 | print '(TESTING) These tests will be skipped:' |
Matt Kwong | e9163f0 | 2016-10-05 11:42:55 -0700 | [diff] [blame] | 345 | for job in list(set(jobs) - set(relevant_jobs)): |
| 346 | print ' %s' % job.shortname |
| 347 | print |
| 348 | |
Jan Tattermusch | c1e4490 | 2016-09-22 14:31:10 +0200 | [diff] [blame] | 349 | if args.dry_run: |
| 350 | print '--dry_run was used, exiting' |
| 351 | sys.exit(1) |
| 352 | |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 353 | jobset.message('START', 'Running test matrix.', do_newline=True) |
| 354 | num_failures, resultset = jobset.run(jobs, |
| 355 | newline_on_success=True, |
| 356 | travis=True, |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 357 | maxjobs=args.jobs) |
Jan Tattermusch | cfcc075 | 2016-10-09 17:02:34 +0200 | [diff] [blame] | 358 | report_utils.render_junit_xml_report(resultset, 'report.xml', |
| 359 | suite_name='aggregate_tests') |
Jan Tattermusch | 9c79e8d | 2016-09-19 14:33:18 +0200 | [diff] [blame] | 360 | |
| 361 | if num_failures == 0: |
| 362 | jobset.message('SUCCESS', 'All run_tests.py instance finished successfully.', |
| 363 | do_newline=True) |
| 364 | else: |
| 365 | jobset.message('FAILED', 'Some run_tests.py instance have failed.', |
| 366 | do_newline=True) |
| 367 | sys.exit(1) |