Nicolas Noble | f358573 | 2015-03-15 20:05:24 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 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 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 31 | """Run tests in parallel.""" |
| 32 | |
| 33 | import argparse |
| 34 | import glob |
| 35 | import itertools |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 36 | import json |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 37 | import multiprocessing |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 38 | import os |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 39 | import re |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 40 | import sys |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 41 | import time |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 42 | import platform |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 43 | import subprocess |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 44 | |
| 45 | import jobset |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 46 | import watch_dirs |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 47 | |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 48 | |
Craig Tiller | 2cc2b84 | 2015-02-27 11:38:31 -0800 | [diff] [blame] | 49 | ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 50 | os.chdir(ROOT) |
| 51 | |
| 52 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 53 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
| 54 | class SimpleConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 55 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 56 | def __init__(self, config, environ=None): |
| 57 | if environ is None: |
| 58 | environ = {} |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 59 | self.build_config = config |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 60 | self.allow_hashing = (config != 'gcov') |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 61 | self.environ = environ |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 62 | self.environ['CONFIG'] = config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 63 | |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 64 | def job_spec(self, cmdline, hash_targets, shortname=None, environ={}): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 65 | """Construct a jobset.JobSpec for a test under this config |
| 66 | |
| 67 | Args: |
| 68 | cmdline: a list of strings specifying the command line the test |
| 69 | would like to run |
| 70 | hash_targets: either None (don't do caching of test results), or |
| 71 | a list of strings specifying files to include in a |
| 72 | binary hash to check if a test has changed |
| 73 | -- if used, all artifacts needed to run the test must |
| 74 | be listed |
| 75 | """ |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 76 | actual_environ = self.environ.copy() |
| 77 | for k, v in environ.iteritems(): |
| 78 | actual_environ[k] = v |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 79 | return jobset.JobSpec(cmdline=cmdline, |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 80 | shortname=shortname, |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 81 | environ=actual_environ, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 82 | hash_targets=hash_targets |
| 83 | if self.allow_hashing else None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 84 | |
| 85 | |
| 86 | # ValgrindConfig: compile with some CONFIG=config, but use valgrind to run |
| 87 | class ValgrindConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 88 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 89 | def __init__(self, config, tool, args=None): |
| 90 | if args is None: |
| 91 | args = [] |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 92 | self.build_config = config |
Craig Tiller | 2aa4d64 | 2015-01-14 15:59:44 -0800 | [diff] [blame] | 93 | self.tool = tool |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 94 | self.args = args |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 95 | self.allow_hashing = False |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 96 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 97 | def job_spec(self, cmdline, hash_targets): |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 98 | return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] + |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 99 | self.args + cmdline, |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 100 | shortname='valgrind %s' % binary, |
| 101 | hash_targets=None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 102 | |
| 103 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 104 | class CLanguage(object): |
| 105 | |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 106 | def __init__(self, make_target, test_lang): |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 107 | self.make_target = make_target |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 108 | if platform.system() == 'Windows': |
| 109 | plat = 'windows' |
| 110 | else: |
| 111 | plat = 'posix' |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 112 | self.platform = plat |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 113 | with open('tools/run_tests/tests.json') as f: |
Craig Tiller | 06b4ff2 | 2015-01-18 11:01:25 -0800 | [diff] [blame] | 114 | js = json.load(f) |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 115 | self.binaries = [tgt |
| 116 | for tgt in js |
| 117 | if tgt['language'] == test_lang and |
| 118 | plat in tgt['platforms']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 119 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 120 | def test_specs(self, config, travis): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 121 | out = [] |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 122 | for target in self.binaries: |
| 123 | if travis and target['flaky']: |
| 124 | continue |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 125 | if self.platform == 'windows': |
| 126 | binary = 'vsprojects\\test_bin\\%s.exe' % (target['name']) |
| 127 | else: |
| 128 | binary = 'bins/%s/%s' % (config.build_config, target['name']) |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 129 | out.append(config.job_spec([binary], [binary])) |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 130 | return sorted(out) |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 131 | |
| 132 | def make_targets(self): |
| 133 | return ['buildtests_%s' % self.make_target] |
| 134 | |
| 135 | def build_steps(self): |
| 136 | return [] |
| 137 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 138 | def supports_multi_config(self): |
| 139 | return True |
| 140 | |
| 141 | def __str__(self): |
| 142 | return self.make_target |
| 143 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 144 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 145 | class NodeLanguage(object): |
| 146 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 147 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 148 | return [config.job_spec(['tools/run_tests/run_node.sh'], None, |
| 149 | environ={'GRPC_TRACE': 'surface,batch'})] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 150 | |
| 151 | def make_targets(self): |
murgatroid99 | c279165 | 2015-01-26 11:33:39 -0800 | [diff] [blame] | 152 | return ['static_c'] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 153 | |
| 154 | def build_steps(self): |
| 155 | return [['tools/run_tests/build_node.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 156 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 157 | def supports_multi_config(self): |
| 158 | return False |
| 159 | |
| 160 | def __str__(self): |
| 161 | return 'node' |
| 162 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 163 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 164 | class PhpLanguage(object): |
| 165 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 166 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 167 | return [config.job_spec(['src/php/bin/run_tests.sh'], None, |
| 168 | environ={'GRPC_TRACE': 'surface,batch'})] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 169 | |
| 170 | def make_targets(self): |
murgatroid99 | 564b944 | 2015-01-26 11:07:59 -0800 | [diff] [blame] | 171 | return ['static_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 172 | |
| 173 | def build_steps(self): |
| 174 | return [['tools/run_tests/build_php.sh']] |
| 175 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 176 | def supports_multi_config(self): |
| 177 | return False |
| 178 | |
| 179 | def __str__(self): |
| 180 | return 'php' |
| 181 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 182 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 183 | class PythonLanguage(object): |
| 184 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 185 | def __init__(self): |
| 186 | with open('tools/run_tests/python_tests.json') as f: |
| 187 | self._tests = json.load(f) |
| 188 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 189 | def test_specs(self, config, travis): |
Masood Malekghassemi | b2d4a8d | 2015-03-05 17:04:18 -0800 | [diff] [blame] | 190 | modules = [config.job_spec(['tools/run_tests/run_python.sh', '-m', |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 191 | test['module']], |
| 192 | None, |
| 193 | environ={'GRPC_TRACE': 'surface,batch'}, |
Craig Tiller | 8302025 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 194 | shortname=test['module']) |
Masood Malekghassemi | b2d4a8d | 2015-03-05 17:04:18 -0800 | [diff] [blame] | 195 | for test in self._tests if 'module' in test] |
| 196 | files = [config.job_spec(['tools/run_tests/run_python.sh', |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 197 | test['file']], |
| 198 | None, |
| 199 | environ={'GRPC_TRACE': 'surface,batch'}, |
Craig Tiller | 8302025 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 200 | shortname=test['file']) |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 201 | for test in self._tests if 'file' in test] |
Masood Malekghassemi | b2d4a8d | 2015-03-05 17:04:18 -0800 | [diff] [blame] | 202 | return files + modules |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 203 | |
| 204 | def make_targets(self): |
Masood Malekghassemi | b2d4a8d | 2015-03-05 17:04:18 -0800 | [diff] [blame] | 205 | return ['static_c', 'grpc_python_plugin'] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 206 | |
| 207 | def build_steps(self): |
| 208 | return [['tools/run_tests/build_python.sh']] |
| 209 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 210 | def supports_multi_config(self): |
| 211 | return False |
| 212 | |
| 213 | def __str__(self): |
| 214 | return 'python' |
| 215 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 216 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 217 | class RubyLanguage(object): |
| 218 | |
| 219 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 220 | return [config.job_spec(['tools/run_tests/run_ruby.sh'], None, |
| 221 | environ={'GRPC_TRACE': 'surface,batch'})] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 222 | |
| 223 | def make_targets(self): |
Nicolas "Pixel" Noble | cbd9c8b | 2015-05-14 06:22:26 +0200 | [diff] [blame] | 224 | return ['run_dep_checks'] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 225 | |
| 226 | def build_steps(self): |
| 227 | return [['tools/run_tests/build_ruby.sh']] |
| 228 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 229 | def supports_multi_config(self): |
| 230 | return False |
| 231 | |
| 232 | def __str__(self): |
| 233 | return 'ruby' |
| 234 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 235 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 236 | class CSharpLanguage(object): |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 237 | def test_specs(self, config, travis): |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 238 | assemblies = ['Grpc.Core.Tests', |
| 239 | 'Grpc.Examples.Tests', |
| 240 | 'Grpc.IntegrationTesting'] |
| 241 | return [config.job_spec(['tools/run_tests/run_csharp.sh', assembly], |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 242 | None, shortname=assembly, |
| 243 | environ={'GRPC_TRACE': 'surface,batch'}) |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 244 | for assembly in assemblies ] |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 245 | |
| 246 | def make_targets(self): |
| 247 | return ['grpc_csharp_ext'] |
| 248 | |
| 249 | def build_steps(self): |
| 250 | return [['tools/run_tests/build_csharp.sh']] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 251 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 252 | def supports_multi_config(self): |
| 253 | return False |
| 254 | |
| 255 | def __str__(self): |
| 256 | return 'csharp' |
| 257 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 258 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 259 | class Sanity(object): |
| 260 | |
| 261 | def test_specs(self, config, travis): |
| 262 | return [config.job_spec('tools/run_tests/run_sanity.sh', None)] |
| 263 | |
| 264 | def make_targets(self): |
| 265 | return ['run_dep_checks'] |
| 266 | |
| 267 | def build_steps(self): |
| 268 | return [] |
| 269 | |
| 270 | def supports_multi_config(self): |
| 271 | return False |
| 272 | |
| 273 | def __str__(self): |
| 274 | return 'sanity' |
| 275 | |
Nicolas "Pixel" Noble | e55cd7f | 2015-04-14 17:59:13 +0200 | [diff] [blame] | 276 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 277 | class Build(object): |
| 278 | |
| 279 | def test_specs(self, config, travis): |
| 280 | return [] |
| 281 | |
| 282 | def make_targets(self): |
Nicolas "Pixel" Noble | c23827b | 2015-04-23 06:17:55 +0200 | [diff] [blame] | 283 | return ['static'] |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 284 | |
| 285 | def build_steps(self): |
| 286 | return [] |
| 287 | |
| 288 | def supports_multi_config(self): |
| 289 | return True |
| 290 | |
| 291 | def __str__(self): |
| 292 | return self.make_target |
| 293 | |
| 294 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 295 | # different configurations we can run under |
| 296 | _CONFIGS = { |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 297 | 'dbg': SimpleConfig('dbg'), |
| 298 | 'opt': SimpleConfig('opt'), |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 299 | 'tsan': SimpleConfig('tsan', environ={ |
| 300 | 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 301 | 'msan': SimpleConfig('msan'), |
Craig Tiller | 96bd5f6 | 2015-02-13 09:04:13 -0800 | [diff] [blame] | 302 | 'ubsan': SimpleConfig('ubsan'), |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 303 | 'asan': SimpleConfig('asan', environ={ |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 304 | 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | 810725c | 2015-05-12 09:44:41 -0700 | [diff] [blame] | 305 | 'asan-noleaks': SimpleConfig('asan', environ={ |
| 306 | 'ASAN_OPTIONS': 'detect_leaks=0:color=always:suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 307 | 'gcov': SimpleConfig('gcov'), |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 308 | 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 309 | 'helgrind': ValgrindConfig('dbg', 'helgrind') |
| 310 | } |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 311 | |
| 312 | |
Nicolas "Pixel" Noble | 1fb5e82 | 2015-03-16 06:20:37 +0100 | [diff] [blame] | 313 | _DEFAULT = ['opt'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 314 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 315 | 'c++': CLanguage('cxx', 'c++'), |
| 316 | 'c': CLanguage('c', 'c'), |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 317 | 'node': NodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 318 | 'php': PhpLanguage(), |
| 319 | 'python': PythonLanguage(), |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 320 | 'ruby': RubyLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 321 | 'csharp': CSharpLanguage(), |
| 322 | 'sanity': Sanity(), |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 323 | 'build': Build(), |
Craig Tiller | eb272bc | 2015-01-30 13:13:14 -0800 | [diff] [blame] | 324 | } |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 325 | |
| 326 | # parse command line |
| 327 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 328 | argp.add_argument('-c', '--config', |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 329 | choices=['all'] + sorted(_CONFIGS.keys()), |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 330 | nargs='+', |
Craig Tiller | b29797b | 2015-01-12 13:51:54 -0800 | [diff] [blame] | 331 | default=_DEFAULT) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 332 | argp.add_argument('-n', '--runs_per_test', default=1, type=int) |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 333 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Craig Tiller | 83762ac | 2015-05-22 14:04:06 -0700 | [diff] [blame] | 334 | argp.add_argument('-j', '--jobs', default=2 * multiprocessing.cpu_count(), type=int) |
Craig Tiller | 8451e87 | 2015-02-27 09:25:51 -0800 | [diff] [blame] | 335 | argp.add_argument('-s', '--slowdown', default=1.0, type=float) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 336 | argp.add_argument('-f', '--forever', |
| 337 | default=False, |
| 338 | action='store_const', |
| 339 | const=True) |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 340 | argp.add_argument('-t', '--travis', |
| 341 | default=False, |
| 342 | action='store_const', |
| 343 | const=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 344 | argp.add_argument('--newline_on_success', |
| 345 | default=False, |
| 346 | action='store_const', |
| 347 | const=True) |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 348 | argp.add_argument('-l', '--language', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 349 | choices=['all'] + sorted(_LANGUAGES.keys()), |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 350 | nargs='+', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 351 | default=['all']) |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame^] | 352 | argp.add_argument('-S', '--stop_on_failure', |
| 353 | default=False, |
| 354 | action='store_const', |
| 355 | const=True) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 356 | argp.add_argument('-a', '--antagonists', default=0, type=int) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 357 | args = argp.parse_args() |
| 358 | |
| 359 | # grab config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 360 | run_configs = set(_CONFIGS[cfg] |
| 361 | for cfg in itertools.chain.from_iterable( |
| 362 | _CONFIGS.iterkeys() if x == 'all' else [x] |
| 363 | for x in args.config)) |
| 364 | build_configs = set(cfg.build_config for cfg in run_configs) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 365 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 366 | make_targets = [] |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 367 | languages = set(_LANGUAGES[l] |
| 368 | for l in itertools.chain.from_iterable( |
| 369 | _LANGUAGES.iterkeys() if x == 'all' else [x] |
| 370 | for x in args.language)) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 371 | |
| 372 | if len(build_configs) > 1: |
| 373 | for language in languages: |
| 374 | if not language.supports_multi_config(): |
| 375 | print language, 'does not support multiple build configurations' |
| 376 | sys.exit(1) |
| 377 | |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 378 | if platform.system() == 'Windows': |
| 379 | def make_jobspec(cfg, targets): |
Jan Tattermusch | e824359 | 2015-04-17 14:14:01 -0700 | [diff] [blame] | 380 | return jobset.JobSpec(['make.bat', 'CONFIG=%s' % cfg] + targets, |
| 381 | cwd='vsprojects', shell=True) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 382 | else: |
| 383 | def make_jobspec(cfg, targets): |
| 384 | return jobset.JobSpec(['make', |
| 385 | '-j', '%d' % (multiprocessing.cpu_count() + 1), |
| 386 | 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % |
| 387 | args.slowdown, |
| 388 | 'CONFIG=%s' % cfg] + targets) |
| 389 | |
| 390 | build_steps = [make_jobspec(cfg, |
| 391 | list(set(itertools.chain.from_iterable( |
| 392 | l.make_targets() for l in languages)))) |
| 393 | for cfg in build_configs] |
| 394 | build_steps.extend(set( |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 395 | jobset.JobSpec(cmdline, environ={'CONFIG': cfg}) |
| 396 | for cfg in build_configs |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 397 | for l in languages |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 398 | for cmdline in l.build_steps())) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 399 | one_run = set( |
| 400 | spec |
| 401 | for config in run_configs |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 402 | for language in languages |
| 403 | for spec in language.test_specs(config, args.travis) |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 404 | if re.search(args.regex, spec.shortname)) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 405 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 406 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 407 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 408 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 409 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 410 | class TestCache(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 411 | """Cache for running tests.""" |
| 412 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 413 | def __init__(self, use_cache_results): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 414 | self._last_successful_run = {} |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 415 | self._use_cache_results = use_cache_results |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 416 | |
| 417 | def should_run(self, cmdline, bin_hash): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 418 | if cmdline not in self._last_successful_run: |
| 419 | return True |
| 420 | if self._last_successful_run[cmdline] != bin_hash: |
| 421 | return True |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 422 | if not self._use_cache_results: |
| 423 | return True |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 424 | return False |
| 425 | |
| 426 | def finished(self, cmdline, bin_hash): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 427 | self._last_successful_run[cmdline] = bin_hash |
Craig Tiller | c1f1162 | 2015-02-25 09:09:59 -0800 | [diff] [blame] | 428 | self.save() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 429 | |
| 430 | def dump(self): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 431 | return [{'cmdline': k, 'hash': v} |
| 432 | for k, v in self._last_successful_run.iteritems()] |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 433 | |
| 434 | def parse(self, exdump): |
| 435 | self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump) |
| 436 | |
| 437 | def save(self): |
| 438 | with open('.run_tests_cache', 'w') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 439 | f.write(json.dumps(self.dump())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 440 | |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 441 | def maybe_load(self): |
| 442 | if os.path.exists('.run_tests_cache'): |
| 443 | with open('.run_tests_cache') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 444 | self.parse(json.loads(f.read())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 445 | |
| 446 | |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 447 | def _build_and_run(check_cancelled, newline_on_success, travis, cache): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 448 | """Do one pass of building & running tests.""" |
murgatroid99 | 666450e | 2015-01-26 13:03:31 -0800 | [diff] [blame] | 449 | # build latest sequentially |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 450 | if not jobset.run(build_steps, maxjobs=1, |
| 451 | newline_on_success=newline_on_success, travis=travis): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 452 | return 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 453 | |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 454 | # start antagonists |
| 455 | antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py']) |
| 456 | for _ in range(0, args.antagonists)] |
| 457 | try: |
| 458 | # run all the tests |
| 459 | all_runs = itertools.chain.from_iterable( |
| 460 | itertools.repeat(one_run, runs_per_test)) |
| 461 | if not jobset.run(all_runs, check_cancelled, |
| 462 | newline_on_success=newline_on_success, travis=travis, |
Craig Tiller | da2220a | 2015-05-27 07:50:53 -0700 | [diff] [blame] | 463 | maxjobs=args.jobs, |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame^] | 464 | stop_on_failure=args.stop_on_failure, |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 465 | cache=cache): |
| 466 | return 2 |
| 467 | finally: |
| 468 | for antagonist in antagonists: |
| 469 | antagonist.kill() |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 470 | |
| 471 | return 0 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 472 | |
| 473 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 474 | test_cache = TestCache(runs_per_test == 1) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 475 | test_cache.maybe_load() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 476 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 477 | if forever: |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 478 | success = True |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 479 | while True: |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 480 | dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples']) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 481 | initial_time = dw.most_recent_change() |
| 482 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 483 | previous_success = success |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 484 | success = _build_and_run(check_cancelled=have_files_changed, |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 485 | newline_on_success=False, |
Craig Tiller | 9a5a940 | 2015-04-16 10:39:50 -0700 | [diff] [blame] | 486 | travis=args.travis, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 487 | cache=test_cache) == 0 |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 488 | if not previous_success and success: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 489 | jobset.message('SUCCESS', |
| 490 | 'All tests are now passing properly', |
| 491 | do_newline=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 492 | jobset.message('IDLE', 'No change detected') |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 493 | while not have_files_changed(): |
| 494 | time.sleep(1) |
| 495 | else: |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 496 | result = _build_and_run(check_cancelled=lambda: False, |
| 497 | newline_on_success=args.newline_on_success, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 498 | travis=args.travis, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 499 | cache=test_cache) |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 500 | if result == 0: |
| 501 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 502 | else: |
| 503 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
| 504 | sys.exit(result) |