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 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame^] | 35 | import hashlib |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 36 | import itertools |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 37 | import json |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 38 | import multiprocessing |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 39 | import os |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 40 | import platform |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame^] | 41 | import psutil |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 42 | import random |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 43 | import re |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 44 | import subprocess |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 45 | import sys |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 46 | import time |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 47 | import xml.etree.cElementTree as ET |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame^] | 48 | import urllib2 |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 49 | |
| 50 | import jobset |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 51 | import watch_dirs |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 52 | |
Craig Tiller | 2cc2b84 | 2015-02-27 11:38:31 -0800 | [diff] [blame] | 53 | ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 54 | os.chdir(ROOT) |
| 55 | |
| 56 | |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 57 | _FORCE_ENVIRON_FOR_WRAPPERS = {} |
| 58 | |
| 59 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 60 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
| 61 | class SimpleConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 62 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 63 | def __init__(self, config, environ=None): |
| 64 | if environ is None: |
| 65 | environ = {} |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 66 | self.build_config = config |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 67 | self.allow_hashing = (config != 'gcov') |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 68 | self.environ = environ |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 69 | self.environ['CONFIG'] = config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 70 | |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 71 | def job_spec(self, cmdline, hash_targets, shortname=None, environ={}): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 72 | """Construct a jobset.JobSpec for a test under this config |
| 73 | |
| 74 | Args: |
| 75 | cmdline: a list of strings specifying the command line the test |
| 76 | would like to run |
| 77 | hash_targets: either None (don't do caching of test results), or |
| 78 | a list of strings specifying files to include in a |
| 79 | binary hash to check if a test has changed |
| 80 | -- if used, all artifacts needed to run the test must |
| 81 | be listed |
| 82 | """ |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 83 | actual_environ = self.environ.copy() |
| 84 | for k, v in environ.iteritems(): |
| 85 | actual_environ[k] = v |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 86 | return jobset.JobSpec(cmdline=cmdline, |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 87 | shortname=shortname, |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 88 | environ=actual_environ, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 89 | hash_targets=hash_targets |
| 90 | if self.allow_hashing else None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 91 | |
| 92 | |
| 93 | # ValgrindConfig: compile with some CONFIG=config, but use valgrind to run |
| 94 | class ValgrindConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 95 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 96 | def __init__(self, config, tool, args=None): |
| 97 | if args is None: |
| 98 | args = [] |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 99 | self.build_config = config |
Craig Tiller | 2aa4d64 | 2015-01-14 15:59:44 -0800 | [diff] [blame] | 100 | self.tool = tool |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 101 | self.args = args |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 102 | self.allow_hashing = False |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 103 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 104 | def job_spec(self, cmdline, hash_targets): |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 105 | return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] + |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 106 | self.args + cmdline, |
Craig Tiller | 71ec6cb | 2015-06-03 00:51:11 -0700 | [diff] [blame] | 107 | shortname='valgrind %s' % cmdline[0], |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 108 | hash_targets=None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 109 | |
| 110 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 111 | class CLanguage(object): |
| 112 | |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 113 | def __init__(self, make_target, test_lang): |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 114 | self.make_target = make_target |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 115 | if platform.system() == 'Windows': |
| 116 | plat = 'windows' |
| 117 | else: |
| 118 | plat = 'posix' |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 119 | self.platform = plat |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 120 | with open('tools/run_tests/tests.json') as f: |
Craig Tiller | 06b4ff2 | 2015-01-18 11:01:25 -0800 | [diff] [blame] | 121 | js = json.load(f) |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 122 | self.binaries = [tgt |
| 123 | for tgt in js |
| 124 | if tgt['language'] == test_lang and |
| 125 | plat in tgt['platforms']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 126 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 127 | def test_specs(self, config, travis): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 128 | out = [] |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 129 | for target in self.binaries: |
| 130 | if travis and target['flaky']: |
| 131 | continue |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 132 | if self.platform == 'windows': |
Jan Tattermusch | 12e8a04 | 2015-06-15 17:07:14 -0700 | [diff] [blame] | 133 | binary = 'vsprojects/test_bin/%s.exe' % (target['name']) |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 134 | else: |
| 135 | binary = 'bins/%s/%s' % (config.build_config, target['name']) |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 136 | out.append(config.job_spec([binary], [binary])) |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 137 | return sorted(out) |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 138 | |
| 139 | def make_targets(self): |
Craig Tiller | 7552f0f | 2015-06-19 17:46:20 -0700 | [diff] [blame] | 140 | return ['buildtests_%s' % self.make_target, 'tools_%s' % self.make_target] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 141 | |
| 142 | def build_steps(self): |
| 143 | return [] |
| 144 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 145 | def supports_multi_config(self): |
| 146 | return True |
| 147 | |
| 148 | def __str__(self): |
| 149 | return self.make_target |
| 150 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 151 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 152 | class NodeLanguage(object): |
| 153 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 154 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 155 | return [config.job_spec(['tools/run_tests/run_node.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 156 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 157 | |
| 158 | def make_targets(self): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 159 | return ['static_c', 'shared_c'] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 160 | |
| 161 | def build_steps(self): |
| 162 | return [['tools/run_tests/build_node.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 163 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 164 | def supports_multi_config(self): |
| 165 | return False |
| 166 | |
| 167 | def __str__(self): |
| 168 | return 'node' |
| 169 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 170 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 171 | class PhpLanguage(object): |
| 172 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 173 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 174 | return [config.job_spec(['src/php/bin/run_tests.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 175 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 176 | |
| 177 | def make_targets(self): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 178 | return ['static_c', 'shared_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 179 | |
| 180 | def build_steps(self): |
| 181 | return [['tools/run_tests/build_php.sh']] |
| 182 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 183 | def supports_multi_config(self): |
| 184 | return False |
| 185 | |
| 186 | def __str__(self): |
| 187 | return 'php' |
| 188 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 189 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 190 | class PythonLanguage(object): |
| 191 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 192 | def __init__(self): |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 193 | self._build_python_versions = ['2.7'] |
Masood Malekghassemi | e5f7002 | 2015-06-29 09:20:26 -0700 | [diff] [blame] | 194 | self._has_python_versions = [] |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 195 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 196 | def test_specs(self, config, travis): |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 197 | environment = dict(_FORCE_ENVIRON_FOR_WRAPPERS) |
| 198 | environment['PYVER'] = '2.7' |
| 199 | return [config.job_spec( |
| 200 | ['tools/run_tests/run_python.sh'], |
| 201 | None, |
| 202 | environ=environment, |
| 203 | shortname='py.test', |
| 204 | )] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 205 | |
| 206 | def make_targets(self): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 207 | return ['static_c', 'grpc_python_plugin', 'shared_c'] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 208 | |
| 209 | def build_steps(self): |
Masood Malekghassemi | e5f7002 | 2015-06-29 09:20:26 -0700 | [diff] [blame] | 210 | commands = [] |
| 211 | for python_version in self._build_python_versions: |
| 212 | try: |
| 213 | with open(os.devnull, 'w') as output: |
| 214 | subprocess.check_call(['which', 'python' + python_version], |
| 215 | stdout=output, stderr=output) |
| 216 | commands.append(['tools/run_tests/build_python.sh', python_version]) |
| 217 | self._has_python_versions.append(python_version) |
| 218 | except: |
| 219 | jobset.message('WARNING', 'Missing Python ' + python_version, |
| 220 | do_newline=True) |
| 221 | return commands |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 222 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 223 | def supports_multi_config(self): |
| 224 | return False |
| 225 | |
| 226 | def __str__(self): |
| 227 | return 'python' |
| 228 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 229 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 230 | class RubyLanguage(object): |
| 231 | |
| 232 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 233 | return [config.job_spec(['tools/run_tests/run_ruby.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 234 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 235 | |
| 236 | def make_targets(self): |
murgatroid99 | a43c14f | 2015-07-30 13:31:23 -0700 | [diff] [blame] | 237 | return ['static_c'] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 238 | |
| 239 | def build_steps(self): |
| 240 | return [['tools/run_tests/build_ruby.sh']] |
| 241 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 242 | def supports_multi_config(self): |
| 243 | return False |
| 244 | |
| 245 | def __str__(self): |
| 246 | return 'ruby' |
| 247 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 248 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 249 | class CSharpLanguage(object): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 250 | def __init__(self): |
| 251 | if platform.system() == 'Windows': |
| 252 | plat = 'windows' |
| 253 | else: |
| 254 | plat = 'posix' |
| 255 | self.platform = plat |
| 256 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 257 | def test_specs(self, config, travis): |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 258 | assemblies = ['Grpc.Core.Tests', |
| 259 | 'Grpc.Examples.Tests', |
| 260 | 'Grpc.IntegrationTesting'] |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 261 | if self.platform == 'windows': |
| 262 | cmd = 'tools\\run_tests\\run_csharp.bat' |
| 263 | else: |
| 264 | cmd = 'tools/run_tests/run_csharp.sh' |
| 265 | return [config.job_spec([cmd, assembly], |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 266 | None, shortname=assembly, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 267 | environ=_FORCE_ENVIRON_FOR_WRAPPERS) |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 268 | for assembly in assemblies ] |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 269 | |
| 270 | def make_targets(self): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 271 | # For Windows, this target doesn't really build anything, |
| 272 | # everything is build by buildall script later. |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 273 | return ['grpc_csharp_ext'] |
| 274 | |
| 275 | def build_steps(self): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 276 | if self.platform == 'windows': |
| 277 | return [['src\\csharp\\buildall.bat']] |
| 278 | else: |
| 279 | return [['tools/run_tests/build_csharp.sh']] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 280 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 281 | def supports_multi_config(self): |
| 282 | return False |
| 283 | |
| 284 | def __str__(self): |
| 285 | return 'csharp' |
| 286 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 287 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 288 | class ObjCLanguage(object): |
| 289 | |
| 290 | def test_specs(self, config, travis): |
| 291 | return [config.job_spec(['src/objective-c/tests/run_tests.sh'], None, |
| 292 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
| 293 | |
| 294 | def make_targets(self): |
Jorge Canizales | d0b32e9 | 2015-07-30 23:08:43 -0700 | [diff] [blame] | 295 | return ['grpc_objective_c_plugin', 'interop_server'] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 296 | |
| 297 | def build_steps(self): |
Jorge Canizales | d0b32e9 | 2015-07-30 23:08:43 -0700 | [diff] [blame] | 298 | return [['src/objective-c/tests/build_tests.sh']] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 299 | |
| 300 | def supports_multi_config(self): |
| 301 | return False |
| 302 | |
| 303 | def __str__(self): |
| 304 | return 'objc' |
| 305 | |
| 306 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 307 | class Sanity(object): |
| 308 | |
| 309 | def test_specs(self, config, travis): |
Craig Tiller | f75fc12 | 2015-06-25 06:58:00 -0700 | [diff] [blame] | 310 | return [config.job_spec('tools/run_tests/run_sanity.sh', None), |
| 311 | config.job_spec('tools/run_tests/check_sources_and_headers.py', None)] |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 312 | |
| 313 | def make_targets(self): |
| 314 | return ['run_dep_checks'] |
| 315 | |
| 316 | def build_steps(self): |
| 317 | return [] |
| 318 | |
| 319 | def supports_multi_config(self): |
| 320 | return False |
| 321 | |
| 322 | def __str__(self): |
| 323 | return 'sanity' |
| 324 | |
Nicolas "Pixel" Noble | e55cd7f | 2015-04-14 17:59:13 +0200 | [diff] [blame] | 325 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 326 | class Build(object): |
| 327 | |
| 328 | def test_specs(self, config, travis): |
| 329 | return [] |
| 330 | |
| 331 | def make_targets(self): |
Nicolas "Pixel" Noble | c23827b | 2015-04-23 06:17:55 +0200 | [diff] [blame] | 332 | return ['static'] |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 333 | |
| 334 | def build_steps(self): |
| 335 | return [] |
| 336 | |
| 337 | def supports_multi_config(self): |
| 338 | return True |
| 339 | |
| 340 | def __str__(self): |
| 341 | return self.make_target |
| 342 | |
| 343 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 344 | # different configurations we can run under |
| 345 | _CONFIGS = { |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 346 | 'dbg': SimpleConfig('dbg'), |
| 347 | 'opt': SimpleConfig('opt'), |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 348 | 'tsan': SimpleConfig('tsan', environ={ |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 349 | 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 350 | 'msan': SimpleConfig('msan'), |
Craig Tiller | 96bd5f6 | 2015-02-13 09:04:13 -0800 | [diff] [blame] | 351 | 'ubsan': SimpleConfig('ubsan'), |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 352 | 'asan': SimpleConfig('asan', environ={ |
Craig Tiller | d4b1362 | 2015-05-29 09:10:10 -0700 | [diff] [blame] | 353 | 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt', |
| 354 | 'LSAN_OPTIONS': 'report_objects=1'}), |
Craig Tiller | 810725c | 2015-05-12 09:44:41 -0700 | [diff] [blame] | 355 | 'asan-noleaks': SimpleConfig('asan', environ={ |
| 356 | 'ASAN_OPTIONS': 'detect_leaks=0:color=always:suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 357 | 'gcov': SimpleConfig('gcov'), |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 358 | 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 359 | 'helgrind': ValgrindConfig('dbg', 'helgrind') |
| 360 | } |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 361 | |
| 362 | |
Nicolas "Pixel" Noble | 1fb5e82 | 2015-03-16 06:20:37 +0100 | [diff] [blame] | 363 | _DEFAULT = ['opt'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 364 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 365 | 'c++': CLanguage('cxx', 'c++'), |
| 366 | 'c': CLanguage('c', 'c'), |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 367 | 'node': NodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 368 | 'php': PhpLanguage(), |
| 369 | 'python': PythonLanguage(), |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 370 | 'ruby': RubyLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 371 | 'csharp': CSharpLanguage(), |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 372 | 'objc' : ObjCLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 373 | 'sanity': Sanity(), |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 374 | 'build': Build(), |
Craig Tiller | eb272bc | 2015-01-30 13:13:14 -0800 | [diff] [blame] | 375 | } |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 376 | |
| 377 | # parse command line |
| 378 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 379 | argp.add_argument('-c', '--config', |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 380 | choices=['all'] + sorted(_CONFIGS.keys()), |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 381 | nargs='+', |
Craig Tiller | b29797b | 2015-01-12 13:51:54 -0800 | [diff] [blame] | 382 | default=_DEFAULT) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 383 | |
| 384 | def runs_per_test_type(arg_str): |
| 385 | """Auxilary function to parse the "runs_per_test" flag. |
| 386 | |
| 387 | Returns: |
| 388 | A positive integer or 0, the latter indicating an infinite number of |
| 389 | runs. |
| 390 | |
| 391 | Raises: |
| 392 | argparse.ArgumentTypeError: Upon invalid input. |
| 393 | """ |
| 394 | if arg_str == 'inf': |
| 395 | return 0 |
| 396 | try: |
| 397 | n = int(arg_str) |
| 398 | if n <= 0: raise ValueError |
Craig Tiller | 50e53e2 | 2015-06-01 20:18:21 -0700 | [diff] [blame] | 399 | return n |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 400 | except: |
| 401 | msg = "'{}' isn't a positive integer or 'inf'".format(arg_str) |
| 402 | raise argparse.ArgumentTypeError(msg) |
| 403 | argp.add_argument('-n', '--runs_per_test', default=1, type=runs_per_test_type, |
| 404 | help='A positive integer or "inf". If "inf", all tests will run in an ' |
| 405 | 'infinite loop. Especially useful in combination with "-f"') |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 406 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Craig Tiller | 83762ac | 2015-05-22 14:04:06 -0700 | [diff] [blame] | 407 | argp.add_argument('-j', '--jobs', default=2 * multiprocessing.cpu_count(), type=int) |
Craig Tiller | 8451e87 | 2015-02-27 09:25:51 -0800 | [diff] [blame] | 408 | argp.add_argument('-s', '--slowdown', default=1.0, type=float) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 409 | argp.add_argument('-f', '--forever', |
| 410 | default=False, |
| 411 | action='store_const', |
| 412 | const=True) |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 413 | argp.add_argument('-t', '--travis', |
| 414 | default=False, |
| 415 | action='store_const', |
| 416 | const=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 417 | argp.add_argument('--newline_on_success', |
| 418 | default=False, |
| 419 | action='store_const', |
| 420 | const=True) |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 421 | argp.add_argument('-l', '--language', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 422 | choices=['all'] + sorted(_LANGUAGES.keys()), |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 423 | nargs='+', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 424 | default=['all']) |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 425 | argp.add_argument('-S', '--stop_on_failure', |
| 426 | default=False, |
| 427 | action='store_const', |
| 428 | const=True) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 429 | argp.add_argument('-a', '--antagonists', default=0, type=int) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 430 | argp.add_argument('-x', '--xml_report', default=None, type=str, |
| 431 | help='Generates a JUnit-compatible XML report') |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 432 | args = argp.parse_args() |
| 433 | |
| 434 | # grab config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 435 | run_configs = set(_CONFIGS[cfg] |
| 436 | for cfg in itertools.chain.from_iterable( |
| 437 | _CONFIGS.iterkeys() if x == 'all' else [x] |
| 438 | for x in args.config)) |
| 439 | build_configs = set(cfg.build_config for cfg in run_configs) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 440 | |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 441 | if args.travis: |
| 442 | _FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'surface,batch'} |
| 443 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 444 | make_targets = [] |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 445 | languages = set(_LANGUAGES[l] |
| 446 | for l in itertools.chain.from_iterable( |
| 447 | _LANGUAGES.iterkeys() if x == 'all' else [x] |
| 448 | for x in args.language)) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 449 | |
| 450 | if len(build_configs) > 1: |
| 451 | for language in languages: |
| 452 | if not language.supports_multi_config(): |
| 453 | print language, 'does not support multiple build configurations' |
| 454 | sys.exit(1) |
| 455 | |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 456 | if platform.system() == 'Windows': |
| 457 | def make_jobspec(cfg, targets): |
Jan Tattermusch | e824359 | 2015-04-17 14:14:01 -0700 | [diff] [blame] | 458 | return jobset.JobSpec(['make.bat', 'CONFIG=%s' % cfg] + targets, |
| 459 | cwd='vsprojects', shell=True) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 460 | else: |
| 461 | def make_jobspec(cfg, targets): |
Nicolas "Pixel" Noble | 4243ca8 | 2015-07-23 23:47:56 +0200 | [diff] [blame] | 462 | return jobset.JobSpec([os.getenv('MAKE', 'make'), |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 463 | '-j', '%d' % (multiprocessing.cpu_count() + 1), |
Craig Tiller | 533b1a2 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 464 | 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 465 | args.slowdown, |
| 466 | 'CONFIG=%s' % cfg] + targets) |
| 467 | |
Craig Tiller | 533b1a2 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 468 | build_steps = [make_jobspec(cfg, |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 469 | list(set(itertools.chain.from_iterable( |
| 470 | l.make_targets() for l in languages)))) |
| 471 | for cfg in build_configs] |
| 472 | build_steps.extend(set( |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 473 | jobset.JobSpec(cmdline, environ={'CONFIG': cfg}) |
| 474 | for cfg in build_configs |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 475 | for l in languages |
Craig Tiller | 533b1a2 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 476 | for cmdline in l.build_steps())) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 477 | one_run = set( |
| 478 | spec |
| 479 | for config in run_configs |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 480 | for language in languages |
| 481 | for spec in language.test_specs(config, args.travis) |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 482 | if re.search(args.regex, spec.shortname)) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 483 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 484 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 485 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 486 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 487 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 488 | class TestCache(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 489 | """Cache for running tests.""" |
| 490 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 491 | def __init__(self, use_cache_results): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 492 | self._last_successful_run = {} |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 493 | self._use_cache_results = use_cache_results |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 494 | self._last_save = time.time() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 495 | |
| 496 | def should_run(self, cmdline, bin_hash): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 497 | if cmdline not in self._last_successful_run: |
| 498 | return True |
| 499 | if self._last_successful_run[cmdline] != bin_hash: |
| 500 | return True |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 501 | if not self._use_cache_results: |
| 502 | return True |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 503 | return False |
| 504 | |
| 505 | def finished(self, cmdline, bin_hash): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 506 | self._last_successful_run[cmdline] = bin_hash |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 507 | if time.time() - self._last_save > 1: |
| 508 | self.save() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 509 | |
| 510 | def dump(self): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 511 | return [{'cmdline': k, 'hash': v} |
| 512 | for k, v in self._last_successful_run.iteritems()] |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 513 | |
| 514 | def parse(self, exdump): |
| 515 | self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump) |
| 516 | |
| 517 | def save(self): |
| 518 | with open('.run_tests_cache', 'w') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 519 | f.write(json.dumps(self.dump())) |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 520 | self._last_save = time.time() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 521 | |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 522 | def maybe_load(self): |
| 523 | if os.path.exists('.run_tests_cache'): |
| 524 | with open('.run_tests_cache') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 525 | self.parse(json.loads(f.read())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 526 | |
| 527 | |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame^] | 528 | def _start_port_server(port_server_port): |
| 529 | # check if a compatible port server is running |
| 530 | # if incompatible (version mismatch) ==> start a new one |
| 531 | # if not running ==> start a new one |
| 532 | # otherwise, leave it up |
| 533 | try: |
| 534 | version, _, pid = urllib2.urlopen( |
| 535 | 'http://localhost:%d/version_and_pid' % port_server_port).read().partition('+') |
| 536 | running = True |
| 537 | except Exception: |
| 538 | running = False |
| 539 | if running: |
| 540 | with open('tools/run_tests/port_server.py') as f: |
| 541 | current_version = hashlib.sha1(f.read()).hexdigest() |
| 542 | running = (version == current_version) |
| 543 | if not running: |
| 544 | psutil.Process(int(pid)).terminate() |
| 545 | if not running: |
| 546 | port_log = open('portlog.txt', 'w') |
| 547 | port_server = subprocess.Popen( |
| 548 | ['tools/run_tests/port_server.py', '-p', '%d' % port_server_port], |
| 549 | stderr=subprocess.STDOUT, |
| 550 | stdout=port_log) |
| 551 | # ensure port server is up |
| 552 | while True: |
| 553 | try: |
| 554 | urllib2.urlopen('http://localhost:%d/get' % port_server_port).read() |
| 555 | break |
| 556 | except urllib2.URLError: |
| 557 | time.sleep(0.5) |
| 558 | except: |
| 559 | port_server.kill() |
| 560 | raise |
| 561 | |
| 562 | |
| 563 | def _build_and_run( |
| 564 | check_cancelled, newline_on_success, travis, cache, xml_report=None): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 565 | """Do one pass of building & running tests.""" |
murgatroid99 | 666450e | 2015-01-26 13:03:31 -0800 | [diff] [blame] | 566 | # build latest sequentially |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 567 | if not jobset.run(build_steps, maxjobs=1, |
| 568 | newline_on_success=newline_on_success, travis=travis): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 569 | return 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 570 | |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 571 | # start antagonists |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 572 | antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py']) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 573 | for _ in range(0, args.antagonists)] |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame^] | 574 | port_server_port = 9999 |
| 575 | _start_port_server(port_server_port) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 576 | try: |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 577 | infinite_runs = runs_per_test == 0 |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 578 | # When running on travis, we want out test runs to be as similar as possible |
| 579 | # for reproducibility purposes. |
| 580 | if travis: |
| 581 | massaged_one_run = sorted(one_run, key=lambda x: x.shortname) |
| 582 | else: |
| 583 | # whereas otherwise, we want to shuffle things up to give all tests a |
| 584 | # chance to run. |
| 585 | massaged_one_run = list(one_run) # random.shuffle needs an indexable seq. |
| 586 | random.shuffle(massaged_one_run) # which it modifies in-place. |
Craig Tiller | f7b7c89 | 2015-06-22 14:33:25 -0700 | [diff] [blame] | 587 | if infinite_runs: |
| 588 | assert len(massaged_one_run) > 0, 'Must have at least one test for a -n inf run' |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 589 | runs_sequence = (itertools.repeat(massaged_one_run) if infinite_runs |
| 590 | else itertools.repeat(massaged_one_run, runs_per_test)) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 591 | all_runs = itertools.chain.from_iterable(runs_sequence) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 592 | |
| 593 | root = ET.Element('testsuites') if xml_report else None |
| 594 | testsuite = ET.SubElement(root, 'testsuite', id='1', package='grpc', name='tests') if xml_report else None |
| 595 | |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 596 | if not jobset.run(all_runs, check_cancelled, |
| 597 | newline_on_success=newline_on_success, travis=travis, |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 598 | infinite_runs=infinite_runs, |
Craig Tiller | da2220a | 2015-05-27 07:50:53 -0700 | [diff] [blame] | 599 | maxjobs=args.jobs, |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 600 | stop_on_failure=args.stop_on_failure, |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 601 | cache=cache if not xml_report else None, |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame^] | 602 | xml_report=testsuite, |
| 603 | add_env={'GRPC_TEST_PORT_SERVER': 'localhost:%d' % port_server_port}): |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 604 | return 2 |
| 605 | finally: |
| 606 | for antagonist in antagonists: |
| 607 | antagonist.kill() |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 608 | if xml_report: |
| 609 | tree = ET.ElementTree(root) |
| 610 | tree.write(xml_report, encoding='UTF-8') |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 611 | |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 612 | if cache: cache.save() |
| 613 | |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 614 | return 0 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 615 | |
| 616 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 617 | test_cache = TestCache(runs_per_test == 1) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 618 | test_cache.maybe_load() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 619 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 620 | if forever: |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 621 | success = True |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 622 | while True: |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 623 | dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples']) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 624 | initial_time = dw.most_recent_change() |
| 625 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 626 | previous_success = success |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 627 | success = _build_and_run(check_cancelled=have_files_changed, |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 628 | newline_on_success=False, |
Craig Tiller | 9a5a940 | 2015-04-16 10:39:50 -0700 | [diff] [blame] | 629 | travis=args.travis, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 630 | cache=test_cache) == 0 |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 631 | if not previous_success and success: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 632 | jobset.message('SUCCESS', |
| 633 | 'All tests are now passing properly', |
| 634 | do_newline=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 635 | jobset.message('IDLE', 'No change detected') |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 636 | while not have_files_changed(): |
| 637 | time.sleep(1) |
| 638 | else: |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 639 | result = _build_and_run(check_cancelled=lambda: False, |
| 640 | newline_on_success=args.newline_on_success, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 641 | travis=args.travis, |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 642 | cache=test_cache, |
| 643 | xml_report=args.xml_report) |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 644 | if result == 0: |
| 645 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 646 | else: |
| 647 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
| 648 | sys.exit(result) |