Nathaniel Manista | ae4fbcd | 2015-09-23 16:29:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
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 |
| 41 | import random |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 42 | import re |
Craig Tiller | 8287523 | 2015-09-25 13:57:34 -0700 | [diff] [blame] | 43 | import socket |
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 | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 60 | def platform_string(): |
| 61 | if platform.system() == 'Windows': |
| 62 | return 'windows' |
| 63 | elif platform.system() == 'Darwin': |
| 64 | return 'mac' |
| 65 | elif platform.system() == 'Linux': |
| 66 | return 'linux' |
| 67 | else: |
| 68 | return 'posix' |
| 69 | |
| 70 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 71 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
| 72 | class SimpleConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 73 | |
Craig Tiller | b2ea0b9 | 2015-08-26 13:06:53 -0700 | [diff] [blame] | 74 | def __init__(self, config, environ=None, timeout_seconds=5*60): |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 75 | if environ is None: |
| 76 | environ = {} |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 77 | self.build_config = config |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 78 | self.allow_hashing = (config != 'gcov') |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 79 | self.environ = environ |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 80 | self.environ['CONFIG'] = config |
Craig Tiller | b2ea0b9 | 2015-08-26 13:06:53 -0700 | [diff] [blame] | 81 | self.timeout_seconds = timeout_seconds |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 82 | |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 83 | def job_spec(self, cmdline, hash_targets, shortname=None, environ={}): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 84 | """Construct a jobset.JobSpec for a test under this config |
| 85 | |
| 86 | Args: |
| 87 | cmdline: a list of strings specifying the command line the test |
| 88 | would like to run |
| 89 | hash_targets: either None (don't do caching of test results), or |
| 90 | a list of strings specifying files to include in a |
| 91 | binary hash to check if a test has changed |
| 92 | -- if used, all artifacts needed to run the test must |
| 93 | be listed |
| 94 | """ |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 95 | actual_environ = self.environ.copy() |
| 96 | for k, v in environ.iteritems(): |
| 97 | actual_environ[k] = v |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 98 | return jobset.JobSpec(cmdline=cmdline, |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 99 | shortname=shortname, |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 100 | environ=actual_environ, |
Craig Tiller | b2ea0b9 | 2015-08-26 13:06:53 -0700 | [diff] [blame] | 101 | timeout_seconds=self.timeout_seconds, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 102 | hash_targets=hash_targets |
Craig Tiller | d4509a1 | 2015-09-28 09:18:40 -0700 | [diff] [blame] | 103 | if self.allow_hashing else None, |
| 104 | flake_retries=5 if args.allow_flakes else 0) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 105 | |
| 106 | |
| 107 | # ValgrindConfig: compile with some CONFIG=config, but use valgrind to run |
| 108 | class ValgrindConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 109 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 110 | def __init__(self, config, tool, args=None): |
| 111 | if args is None: |
| 112 | args = [] |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 113 | self.build_config = config |
Craig Tiller | 2aa4d64 | 2015-01-14 15:59:44 -0800 | [diff] [blame] | 114 | self.tool = tool |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 115 | self.args = args |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 116 | self.allow_hashing = False |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 117 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 118 | def job_spec(self, cmdline, hash_targets): |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 119 | return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] + |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 120 | self.args + cmdline, |
Craig Tiller | 71ec6cb | 2015-06-03 00:51:11 -0700 | [diff] [blame] | 121 | shortname='valgrind %s' % cmdline[0], |
Craig Tiller | d4509a1 | 2015-09-28 09:18:40 -0700 | [diff] [blame] | 122 | hash_targets=None, |
Craig Tiller | 95cc07b | 2015-09-28 13:41:30 -0700 | [diff] [blame] | 123 | flake_retries=5 if args.allow_flakes else 0, |
| 124 | timeout_retries=2 if args.allow_flakes else 0) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 125 | |
| 126 | |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 127 | def get_c_tests(travis, test_lang) : |
| 128 | out = [] |
| 129 | platforms_str = 'ci_platforms' if travis else 'platforms' |
| 130 | with open('tools/run_tests/tests.json') as f: |
murgatroid99 | 89899b1 | 2015-09-22 09:14:48 -0700 | [diff] [blame] | 131 | js = json.load(f) |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 132 | return [tgt |
| 133 | for tgt in js |
| 134 | if tgt['language'] == test_lang and |
| 135 | platform_string() in tgt[platforms_str] and |
| 136 | not (travis and tgt['flaky'])] |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 137 | |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 138 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 139 | class CLanguage(object): |
| 140 | |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 141 | def __init__(self, make_target, test_lang): |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 142 | self.make_target = make_target |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 143 | self.platform = platform_string() |
Craig Tiller | 711bbe6 | 2015-08-19 12:35:16 -0700 | [diff] [blame] | 144 | self.test_lang = test_lang |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 145 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 146 | def test_specs(self, config, travis): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 147 | out = [] |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 148 | binaries = get_c_tests(travis, self.test_lang) |
Craig Tiller | 711bbe6 | 2015-08-19 12:35:16 -0700 | [diff] [blame] | 149 | for target in binaries: |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 150 | if config.build_config in target['exclude_configs']: |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 151 | continue |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 152 | if self.platform == 'windows': |
Craig Tiller | f418260 | 2015-09-01 12:23:16 -0700 | [diff] [blame] | 153 | binary = 'vsprojects/%s/%s.exe' % ( |
| 154 | _WINDOWS_CONFIG[config.build_config], target['name']) |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 155 | else: |
| 156 | binary = 'bins/%s/%s' % (config.build_config, target['name']) |
yang-g | 6c1fdc6 | 2015-08-18 11:57:42 -0700 | [diff] [blame] | 157 | if os.path.isfile(binary): |
| 158 | out.append(config.job_spec([binary], [binary])) |
| 159 | else: |
| 160 | print "\nWARNING: binary not found, skipping", binary |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 161 | return sorted(out) |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 162 | |
| 163 | def make_targets(self): |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 164 | if platform_string() == 'windows': |
| 165 | # don't build tools on windows just yet |
| 166 | return ['buildtests_%s' % self.make_target] |
Craig Tiller | 7552f0f | 2015-06-19 17:46:20 -0700 | [diff] [blame] | 167 | return ['buildtests_%s' % self.make_target, 'tools_%s' % self.make_target] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 168 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 169 | def pre_build_steps(self): |
| 170 | return [] |
| 171 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 172 | def build_steps(self): |
| 173 | return [] |
| 174 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 175 | def makefile_name(self): |
| 176 | return 'Makefile' |
| 177 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 178 | def supports_multi_config(self): |
| 179 | return True |
| 180 | |
| 181 | def __str__(self): |
| 182 | return self.make_target |
| 183 | |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 184 | |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 185 | def gyp_test_paths(travis, config=None): |
| 186 | binaries = get_c_tests(travis, 'c') |
| 187 | out = [] |
| 188 | for target in binaries: |
murgatroid99 | fddac96 | 2015-09-22 09:20:11 -0700 | [diff] [blame] | 189 | if config is not None and config.build_config in target['exclude_configs']: |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 190 | continue |
| 191 | binary = 'out/Debug/%s' % target['name'] |
| 192 | out.append(binary) |
| 193 | return sorted(out) |
| 194 | |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 195 | |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 196 | class GYPCLanguage(object): |
| 197 | |
| 198 | def test_specs(self, config, travis): |
| 199 | return [config.job_spec([binary], [binary]) |
| 200 | for binary in gyp_test_paths(travis, config)] |
| 201 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 202 | def pre_build_steps(self): |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 203 | return [['gyp', '--depth=.', '--suffix=-gyp', 'grpc.gyp']] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 204 | |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 205 | def make_targets(self): |
Craig Tiller | c1385d6 | 2015-09-24 08:52:00 -0700 | [diff] [blame] | 206 | # HACK(ctiller): force fling_client and fling_server to be built, as fling_test |
| 207 | # needs these |
| 208 | return gyp_test_paths(False) + ['fling_client', 'fling_server'] |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 209 | |
| 210 | def build_steps(self): |
| 211 | return [] |
| 212 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 213 | def makefile_name(self): |
| 214 | return 'Makefile-gyp' |
| 215 | |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 216 | def supports_multi_config(self): |
| 217 | return False |
| 218 | |
| 219 | def __str__(self): |
| 220 | return 'gyp' |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 221 | |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 222 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 223 | class NodeLanguage(object): |
| 224 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 225 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 226 | return [config.job_spec(['tools/run_tests/run_node.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 227 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 228 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 229 | def pre_build_steps(self): |
| 230 | return [] |
| 231 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 232 | def make_targets(self): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 233 | return ['static_c', 'shared_c'] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 234 | |
| 235 | def build_steps(self): |
| 236 | return [['tools/run_tests/build_node.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 237 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 238 | def makefile_name(self): |
| 239 | return 'Makefile' |
| 240 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 241 | def supports_multi_config(self): |
| 242 | return False |
| 243 | |
| 244 | def __str__(self): |
| 245 | return 'node' |
| 246 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 247 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 248 | class PhpLanguage(object): |
| 249 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 250 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 251 | return [config.job_spec(['src/php/bin/run_tests.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 252 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 253 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 254 | def pre_build_steps(self): |
| 255 | return [] |
| 256 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 257 | def make_targets(self): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 258 | return ['static_c', 'shared_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 259 | |
| 260 | def build_steps(self): |
| 261 | return [['tools/run_tests/build_php.sh']] |
| 262 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 263 | def makefile_name(self): |
| 264 | return 'Makefile' |
| 265 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 266 | def supports_multi_config(self): |
| 267 | return False |
| 268 | |
| 269 | def __str__(self): |
| 270 | return 'php' |
| 271 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 272 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 273 | class PythonLanguage(object): |
| 274 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 275 | def __init__(self): |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 276 | self._build_python_versions = ['2.7'] |
Masood Malekghassemi | e5f7002 | 2015-06-29 09:20:26 -0700 | [diff] [blame] | 277 | self._has_python_versions = [] |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 278 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 279 | def test_specs(self, config, travis): |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 280 | environment = dict(_FORCE_ENVIRON_FOR_WRAPPERS) |
| 281 | environment['PYVER'] = '2.7' |
| 282 | return [config.job_spec( |
| 283 | ['tools/run_tests/run_python.sh'], |
| 284 | None, |
| 285 | environ=environment, |
| 286 | shortname='py.test', |
| 287 | )] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 288 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 289 | def pre_build_steps(self): |
| 290 | return [] |
| 291 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 292 | def make_targets(self): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 293 | return ['static_c', 'grpc_python_plugin', 'shared_c'] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 294 | |
| 295 | def build_steps(self): |
Masood Malekghassemi | e5f7002 | 2015-06-29 09:20:26 -0700 | [diff] [blame] | 296 | commands = [] |
| 297 | for python_version in self._build_python_versions: |
| 298 | try: |
| 299 | with open(os.devnull, 'w') as output: |
| 300 | subprocess.check_call(['which', 'python' + python_version], |
| 301 | stdout=output, stderr=output) |
| 302 | commands.append(['tools/run_tests/build_python.sh', python_version]) |
| 303 | self._has_python_versions.append(python_version) |
| 304 | except: |
| 305 | jobset.message('WARNING', 'Missing Python ' + python_version, |
| 306 | do_newline=True) |
| 307 | return commands |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 308 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 309 | def makefile_name(self): |
| 310 | return 'Makefile' |
| 311 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 312 | def supports_multi_config(self): |
| 313 | return False |
| 314 | |
| 315 | def __str__(self): |
| 316 | return 'python' |
| 317 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 318 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 319 | class RubyLanguage(object): |
| 320 | |
| 321 | def test_specs(self, config, travis): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 322 | return [config.job_spec(['tools/run_tests/run_ruby.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 323 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 324 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 325 | def pre_build_steps(self): |
| 326 | return [] |
| 327 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 328 | def make_targets(self): |
murgatroid99 | a43c14f | 2015-07-30 13:31:23 -0700 | [diff] [blame] | 329 | return ['static_c'] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 330 | |
| 331 | def build_steps(self): |
| 332 | return [['tools/run_tests/build_ruby.sh']] |
| 333 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 334 | def makefile_name(self): |
| 335 | return 'Makefile' |
| 336 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 337 | def supports_multi_config(self): |
| 338 | return False |
| 339 | |
| 340 | def __str__(self): |
| 341 | return 'ruby' |
| 342 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 343 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 344 | class CSharpLanguage(object): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 345 | def __init__(self): |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 346 | self.platform = platform_string() |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 347 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 348 | def test_specs(self, config, travis): |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 349 | assemblies = ['Grpc.Core.Tests', |
| 350 | 'Grpc.Examples.Tests', |
Jan Tattermusch | 9d67d8d | 2015-08-01 20:39:16 -0700 | [diff] [blame] | 351 | 'Grpc.HealthCheck.Tests', |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 352 | 'Grpc.IntegrationTesting'] |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 353 | if self.platform == 'windows': |
| 354 | cmd = 'tools\\run_tests\\run_csharp.bat' |
| 355 | else: |
| 356 | cmd = 'tools/run_tests/run_csharp.sh' |
| 357 | return [config.job_spec([cmd, assembly], |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 358 | None, shortname=assembly, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 359 | environ=_FORCE_ENVIRON_FOR_WRAPPERS) |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 360 | for assembly in assemblies] |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 361 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 362 | def pre_build_steps(self): |
| 363 | return [] |
| 364 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 365 | def make_targets(self): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 366 | # For Windows, this target doesn't really build anything, |
| 367 | # everything is build by buildall script later. |
Craig Tiller | d590482 | 2015-08-31 21:30:58 -0700 | [diff] [blame] | 368 | if self.platform == 'windows': |
| 369 | return [] |
| 370 | else: |
| 371 | return ['grpc_csharp_ext'] |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 372 | |
| 373 | def build_steps(self): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 374 | if self.platform == 'windows': |
| 375 | return [['src\\csharp\\buildall.bat']] |
| 376 | else: |
| 377 | return [['tools/run_tests/build_csharp.sh']] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 378 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 379 | def makefile_name(self): |
| 380 | return 'Makefile' |
| 381 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 382 | def supports_multi_config(self): |
| 383 | return False |
| 384 | |
| 385 | def __str__(self): |
| 386 | return 'csharp' |
| 387 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 388 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 389 | class ObjCLanguage(object): |
| 390 | |
| 391 | def test_specs(self, config, travis): |
| 392 | return [config.job_spec(['src/objective-c/tests/run_tests.sh'], None, |
| 393 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
| 394 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 395 | def pre_build_steps(self): |
| 396 | return [] |
| 397 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 398 | def make_targets(self): |
Jorge Canizales | d0b32e9 | 2015-07-30 23:08:43 -0700 | [diff] [blame] | 399 | return ['grpc_objective_c_plugin', 'interop_server'] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 400 | |
| 401 | def build_steps(self): |
Jorge Canizales | d0b32e9 | 2015-07-30 23:08:43 -0700 | [diff] [blame] | 402 | return [['src/objective-c/tests/build_tests.sh']] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 403 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 404 | def makefile_name(self): |
| 405 | return 'Makefile' |
| 406 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 407 | def supports_multi_config(self): |
| 408 | return False |
| 409 | |
| 410 | def __str__(self): |
| 411 | return 'objc' |
| 412 | |
| 413 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 414 | class Sanity(object): |
| 415 | |
| 416 | def test_specs(self, config, travis): |
Craig Tiller | f75fc12 | 2015-06-25 06:58:00 -0700 | [diff] [blame] | 417 | return [config.job_spec('tools/run_tests/run_sanity.sh', None), |
| 418 | 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] | 419 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 420 | def pre_build_steps(self): |
| 421 | return [] |
| 422 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 423 | def make_targets(self): |
| 424 | return ['run_dep_checks'] |
| 425 | |
| 426 | def build_steps(self): |
| 427 | return [] |
| 428 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 429 | def makefile_name(self): |
| 430 | return 'Makefile' |
| 431 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 432 | def supports_multi_config(self): |
| 433 | return False |
| 434 | |
| 435 | def __str__(self): |
| 436 | return 'sanity' |
| 437 | |
Nicolas "Pixel" Noble | e55cd7f | 2015-04-14 17:59:13 +0200 | [diff] [blame] | 438 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 439 | class Build(object): |
| 440 | |
| 441 | def test_specs(self, config, travis): |
| 442 | return [] |
| 443 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 444 | def pre_build_steps(self): |
| 445 | return [] |
| 446 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 447 | def make_targets(self): |
Nicolas "Pixel" Noble | c23827b | 2015-04-23 06:17:55 +0200 | [diff] [blame] | 448 | return ['static'] |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 449 | |
| 450 | def build_steps(self): |
| 451 | return [] |
| 452 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 453 | def makefile_name(self): |
| 454 | return 'Makefile' |
| 455 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 456 | def supports_multi_config(self): |
| 457 | return True |
| 458 | |
| 459 | def __str__(self): |
| 460 | return self.make_target |
| 461 | |
| 462 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 463 | # different configurations we can run under |
| 464 | _CONFIGS = { |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 465 | 'dbg': SimpleConfig('dbg'), |
| 466 | 'opt': SimpleConfig('opt'), |
Craig Tiller | b2ea0b9 | 2015-08-26 13:06:53 -0700 | [diff] [blame] | 467 | 'tsan': SimpleConfig('tsan', timeout_seconds=10*60, environ={ |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 468 | 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1'}), |
Craig Tiller | 4a71ce2 | 2015-08-26 15:47:55 -0700 | [diff] [blame] | 469 | 'msan': SimpleConfig('msan', timeout_seconds=7*60), |
Craig Tiller | 96bd5f6 | 2015-02-13 09:04:13 -0800 | [diff] [blame] | 470 | 'ubsan': SimpleConfig('ubsan'), |
Craig Tiller | b2ea0b9 | 2015-08-26 13:06:53 -0700 | [diff] [blame] | 471 | 'asan': SimpleConfig('asan', timeout_seconds=7*60, environ={ |
Craig Tiller | d4b1362 | 2015-05-29 09:10:10 -0700 | [diff] [blame] | 472 | 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt', |
| 473 | 'LSAN_OPTIONS': 'report_objects=1'}), |
Craig Tiller | 810725c | 2015-05-12 09:44:41 -0700 | [diff] [blame] | 474 | 'asan-noleaks': SimpleConfig('asan', environ={ |
| 475 | 'ASAN_OPTIONS': 'detect_leaks=0:color=always:suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 476 | 'gcov': SimpleConfig('gcov'), |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 477 | 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 478 | 'helgrind': ValgrindConfig('dbg', 'helgrind') |
| 479 | } |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 480 | |
| 481 | |
Nicolas "Pixel" Noble | 1fb5e82 | 2015-03-16 06:20:37 +0100 | [diff] [blame] | 482 | _DEFAULT = ['opt'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 483 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 484 | 'c++': CLanguage('cxx', 'c++'), |
| 485 | 'c': CLanguage('c', 'c'), |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 486 | 'gyp': GYPCLanguage(), |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 487 | 'node': NodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 488 | 'php': PhpLanguage(), |
| 489 | 'python': PythonLanguage(), |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 490 | 'ruby': RubyLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 491 | 'csharp': CSharpLanguage(), |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 492 | 'objc' : ObjCLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 493 | 'sanity': Sanity(), |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 494 | 'build': Build(), |
Craig Tiller | eb272bc | 2015-01-30 13:13:14 -0800 | [diff] [blame] | 495 | } |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 496 | |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 497 | _WINDOWS_CONFIG = { |
| 498 | 'dbg': 'Debug', |
| 499 | 'opt': 'Release', |
| 500 | } |
| 501 | |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 502 | |
| 503 | def runs_per_test_type(arg_str): |
| 504 | """Auxilary function to parse the "runs_per_test" flag. |
| 505 | |
| 506 | Returns: |
| 507 | A positive integer or 0, the latter indicating an infinite number of |
| 508 | runs. |
| 509 | |
| 510 | Raises: |
| 511 | argparse.ArgumentTypeError: Upon invalid input. |
| 512 | """ |
| 513 | if arg_str == 'inf': |
| 514 | return 0 |
| 515 | try: |
| 516 | n = int(arg_str) |
| 517 | if n <= 0: raise ValueError |
Craig Tiller | 50e53e2 | 2015-06-01 20:18:21 -0700 | [diff] [blame] | 518 | return n |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 519 | except: |
| 520 | msg = "'{}' isn't a positive integer or 'inf'".format(arg_str) |
| 521 | raise argparse.ArgumentTypeError(msg) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 522 | |
| 523 | # parse command line |
| 524 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 525 | argp.add_argument('-c', '--config', |
| 526 | choices=['all'] + sorted(_CONFIGS.keys()), |
| 527 | nargs='+', |
| 528 | default=_DEFAULT) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 529 | argp.add_argument('-n', '--runs_per_test', default=1, type=runs_per_test_type, |
| 530 | help='A positive integer or "inf". If "inf", all tests will run in an ' |
| 531 | 'infinite loop. Especially useful in combination with "-f"') |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 532 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Craig Tiller | 83762ac | 2015-05-22 14:04:06 -0700 | [diff] [blame] | 533 | argp.add_argument('-j', '--jobs', default=2 * multiprocessing.cpu_count(), type=int) |
Craig Tiller | 8451e87 | 2015-02-27 09:25:51 -0800 | [diff] [blame] | 534 | argp.add_argument('-s', '--slowdown', default=1.0, type=float) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 535 | argp.add_argument('-f', '--forever', |
| 536 | default=False, |
| 537 | action='store_const', |
| 538 | const=True) |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 539 | argp.add_argument('-t', '--travis', |
| 540 | default=False, |
| 541 | action='store_const', |
| 542 | const=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 543 | argp.add_argument('--newline_on_success', |
| 544 | default=False, |
| 545 | action='store_const', |
| 546 | const=True) |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 547 | argp.add_argument('-l', '--language', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 548 | choices=['all'] + sorted(_LANGUAGES.keys()), |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 549 | nargs='+', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 550 | default=['all']) |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 551 | argp.add_argument('-S', '--stop_on_failure', |
| 552 | default=False, |
| 553 | action='store_const', |
| 554 | const=True) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 555 | argp.add_argument('--use_docker', |
| 556 | default=False, |
| 557 | action='store_const', |
| 558 | const=True, |
| 559 | help="Run all the tests under docker. That provides " + |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 560 | "additional isolation and prevents the need to install " + |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 561 | "language specific prerequisites. Only available on Linux.") |
Craig Tiller | d4509a1 | 2015-09-28 09:18:40 -0700 | [diff] [blame] | 562 | argp.add_argument('--allow_flakes', |
| 563 | default=False, |
| 564 | action='store_const', |
| 565 | const=True, |
| 566 | help="Allow flaky tests to show as passing (re-runs failed tests up to five times)") |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 567 | argp.add_argument('-a', '--antagonists', default=0, type=int) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 568 | argp.add_argument('-x', '--xml_report', default=None, type=str, |
| 569 | help='Generates a JUnit-compatible XML report') |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 570 | args = argp.parse_args() |
| 571 | |
Jan Tattermusch | c96b9eb | 2015-09-18 16:01:21 -0700 | [diff] [blame] | 572 | if args.use_docker: |
| 573 | if not args.travis: |
| 574 | print 'Seen --use_docker flag, will run tests under docker.' |
| 575 | print |
| 576 | print 'IMPORTANT: The changes you are testing need to be locally committed' |
| 577 | print 'because only the committed changes in the current branch will be' |
| 578 | print 'copied to the docker environment.' |
| 579 | time.sleep(5) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 580 | |
| 581 | child_argv = [ arg for arg in sys.argv if not arg == '--use_docker' ] |
| 582 | run_tests_cmd = 'tools/run_tests/run_tests.py %s' % " ".join(child_argv[1:]) |
| 583 | |
| 584 | # TODO(jtattermusch): revisit if we need special handling for arch here |
| 585 | # set arch command prefix in case we are working with different arch. |
| 586 | arch_env = os.getenv('arch') |
| 587 | if arch_env: |
| 588 | run_test_cmd = 'arch %s %s' % (arch_env, run_test_cmd) |
| 589 | |
| 590 | env = os.environ.copy() |
| 591 | env['RUN_TESTS_COMMAND'] = run_tests_cmd |
| 592 | if args.xml_report: |
| 593 | env['XML_REPORT'] = args.xml_report |
Jan Tattermusch | 261b58c | 2015-09-18 17:15:48 -0700 | [diff] [blame] | 594 | if not args.travis: |
| 595 | env['TTY_FLAG'] = '-t' # enables Ctrl-C when not on Jenkins. |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 596 | |
| 597 | subprocess.check_call(['tools/jenkins/build_docker_and_run_tests.sh'], |
| 598 | shell=True, |
| 599 | env=env) |
| 600 | sys.exit(0) |
| 601 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 602 | # grab config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 603 | run_configs = set(_CONFIGS[cfg] |
| 604 | for cfg in itertools.chain.from_iterable( |
| 605 | _CONFIGS.iterkeys() if x == 'all' else [x] |
| 606 | for x in args.config)) |
| 607 | build_configs = set(cfg.build_config for cfg in run_configs) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 608 | |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 609 | if args.travis: |
| 610 | _FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'surface,batch'} |
| 611 | |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 612 | languages = set(_LANGUAGES[l] |
| 613 | for l in itertools.chain.from_iterable( |
| 614 | _LANGUAGES.iterkeys() if x == 'all' else [x] |
| 615 | for x in args.language)) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 616 | |
| 617 | if len(build_configs) > 1: |
| 618 | for language in languages: |
| 619 | if not language.supports_multi_config(): |
| 620 | print language, 'does not support multiple build configurations' |
| 621 | sys.exit(1) |
| 622 | |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 623 | if platform.system() == 'Windows': |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 624 | def make_jobspec(cfg, targets, makefile='Makefile'): |
Craig Tiller | fc3c0c4 | 2015-09-01 16:47:54 -0700 | [diff] [blame] | 625 | extra_args = [] |
Craig Tiller | b5391e1 | 2015-09-03 14:35:18 -0700 | [diff] [blame] | 626 | # better do parallel compilation |
Jan Tattermusch | 47eeb2b | 2015-10-07 14:09:18 -0700 | [diff] [blame^] | 627 | # empirically /m:2 gives the best performance/price and should prevent |
| 628 | # overloading the windows workers. |
| 629 | extra_args.extend(["/m:2"]) |
Craig Tiller | b5391e1 | 2015-09-03 14:35:18 -0700 | [diff] [blame] | 630 | # disable PDB generation: it's broken, and we don't need it during CI |
Craig Tiller | 3ef8c08 | 2015-09-04 15:17:12 -0700 | [diff] [blame] | 631 | extra_args.extend(["/p:Jenkins=true"]) |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 632 | return [ |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 633 | jobset.JobSpec(['vsprojects\\build.bat', |
| 634 | 'vsprojects\\%s.sln' % target, |
Craig Tiller | fc3c0c4 | 2015-09-01 16:47:54 -0700 | [diff] [blame] | 635 | '/p:Configuration=%s' % _WINDOWS_CONFIG[cfg]] + |
| 636 | extra_args, |
Craig Tiller | dfc3eee | 2015-09-01 16:32:16 -0700 | [diff] [blame] | 637 | shell=True, timeout_seconds=90*60) |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 638 | for target in targets] |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 639 | else: |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 640 | def make_jobspec(cfg, targets, makefile='Makefile'): |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 641 | return [jobset.JobSpec([os.getenv('MAKE', 'make'), |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 642 | '-f', makefile, |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 643 | '-j', '%d' % (multiprocessing.cpu_count() + 1), |
| 644 | 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % |
| 645 | args.slowdown, |
| 646 | 'CONFIG=%s' % cfg] + targets, |
| 647 | timeout_seconds=30*60)] |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 648 | make_targets = {} |
| 649 | for l in languages: |
| 650 | makefile = l.makefile_name() |
| 651 | make_targets[makefile] = make_targets.get(makefile, set()).union( |
| 652 | set(l.make_targets())) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 653 | |
murgatroid99 | fddac96 | 2015-09-22 09:20:11 -0700 | [diff] [blame] | 654 | build_steps = list(set( |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 655 | jobset.JobSpec(cmdline, environ={'CONFIG': cfg}) |
| 656 | for cfg in build_configs |
| 657 | for l in languages |
| 658 | for cmdline in l.pre_build_steps())) |
Craig Tiller | bd4e378 | 2015-09-01 06:48:55 -0700 | [diff] [blame] | 659 | if make_targets: |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 660 | make_commands = itertools.chain.from_iterable(make_jobspec(cfg, list(targets), makefile) for cfg in build_configs for (makefile, targets) in make_targets.iteritems()) |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 661 | build_steps.extend(set(make_commands)) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 662 | build_steps.extend(set( |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 663 | jobset.JobSpec(cmdline, environ={'CONFIG': cfg}) |
| 664 | for cfg in build_configs |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 665 | for l in languages |
Craig Tiller | 533b1a2 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 666 | for cmdline in l.build_steps())) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 667 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 668 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 669 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 670 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 671 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 672 | class TestCache(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 673 | """Cache for running tests.""" |
| 674 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 675 | def __init__(self, use_cache_results): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 676 | self._last_successful_run = {} |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 677 | self._use_cache_results = use_cache_results |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 678 | self._last_save = time.time() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 679 | |
| 680 | def should_run(self, cmdline, bin_hash): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 681 | if cmdline not in self._last_successful_run: |
| 682 | return True |
| 683 | if self._last_successful_run[cmdline] != bin_hash: |
| 684 | return True |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 685 | if not self._use_cache_results: |
| 686 | return True |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 687 | return False |
| 688 | |
| 689 | def finished(self, cmdline, bin_hash): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 690 | self._last_successful_run[cmdline] = bin_hash |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 691 | if time.time() - self._last_save > 1: |
| 692 | self.save() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 693 | |
| 694 | def dump(self): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 695 | return [{'cmdline': k, 'hash': v} |
| 696 | for k, v in self._last_successful_run.iteritems()] |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 697 | |
| 698 | def parse(self, exdump): |
| 699 | self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump) |
| 700 | |
| 701 | def save(self): |
| 702 | with open('.run_tests_cache', 'w') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 703 | f.write(json.dumps(self.dump())) |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 704 | self._last_save = time.time() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 705 | |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 706 | def maybe_load(self): |
| 707 | if os.path.exists('.run_tests_cache'): |
| 708 | with open('.run_tests_cache') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 709 | self.parse(json.loads(f.read())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 710 | |
| 711 | |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 712 | def _start_port_server(port_server_port): |
| 713 | # check if a compatible port server is running |
| 714 | # if incompatible (version mismatch) ==> start a new one |
| 715 | # if not running ==> start a new one |
| 716 | # otherwise, leave it up |
| 717 | try: |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 718 | version = int(urllib2.urlopen( |
| 719 | 'http://localhost:%d/version_number' % port_server_port, |
| 720 | timeout=1).read()) |
| 721 | print 'detected port server running version %d' % version |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 722 | running = True |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 723 | except Exception as e: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 724 | print 'failed to detect port server: %s' % sys.exc_info()[0] |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 725 | print e.strerror |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 726 | running = False |
| 727 | if running: |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 728 | current_version = int(subprocess.check_output( |
| 729 | [sys.executable, 'tools/run_tests/port_server.py', 'dump_version'])) |
| 730 | print 'my port server is version %d' % current_version |
| 731 | running = (version >= current_version) |
| 732 | if not running: |
| 733 | print 'port_server version mismatch: killing the old one' |
| 734 | urllib2.urlopen('http://localhost:%d/quitquitquit' % port_server_port).read() |
| 735 | time.sleep(1) |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 736 | if not running: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 737 | print 'starting port_server' |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 738 | port_log = open('portlog.txt', 'w') |
| 739 | port_server = subprocess.Popen( |
Craig Tiller | 1447ece | 2015-10-05 14:44:32 -0700 | [diff] [blame] | 740 | [sys.executable, 'tools/run_tests/port_server.py', '-p', '%d' % port_server_port], |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 741 | stderr=subprocess.STDOUT, |
| 742 | stdout=port_log) |
Craig Tiller | 8b5f4dc | 2015-08-26 08:02:01 -0700 | [diff] [blame] | 743 | # ensure port server is up |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 744 | waits = 0 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 745 | while True: |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 746 | if waits > 10: |
| 747 | port_server.kill() |
Craig Tiller | a2f38b0 | 2015-09-24 11:19:17 -0700 | [diff] [blame] | 748 | if port_server.poll() is not None: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 749 | print 'port_server failed to start' |
Craig Tiller | a2f38b0 | 2015-09-24 11:19:17 -0700 | [diff] [blame] | 750 | port_log = open('portlog.txt', 'r').read() |
| 751 | print port_log |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 752 | sys.exit(1) |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 753 | try: |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 754 | urllib2.urlopen('http://localhost:%d/get' % port_server_port, |
| 755 | timeout=1).read() |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 756 | break |
Craig Tiller | 31fdaa4 | 2015-09-25 13:09:59 -0700 | [diff] [blame] | 757 | except socket.timeout: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 758 | print 'waiting for port_server: timeout' |
Craig Tiller | 31fdaa4 | 2015-09-25 13:09:59 -0700 | [diff] [blame] | 759 | time.sleep(0.5) |
| 760 | waits += 1 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 761 | except urllib2.URLError: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 762 | print 'waiting for port_server: urlerror' |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 763 | time.sleep(0.5) |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 764 | waits += 1 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 765 | except: |
| 766 | port_server.kill() |
| 767 | raise |
| 768 | |
| 769 | |
| 770 | def _build_and_run( |
| 771 | check_cancelled, newline_on_success, travis, cache, xml_report=None): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 772 | """Do one pass of building & running tests.""" |
murgatroid99 | 666450e | 2015-01-26 13:03:31 -0800 | [diff] [blame] | 773 | # build latest sequentially |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 774 | if not jobset.run(build_steps, maxjobs=1, |
| 775 | newline_on_success=newline_on_success, travis=travis): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 776 | return 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 777 | |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 778 | # start antagonists |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 779 | antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py']) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 780 | for _ in range(0, args.antagonists)] |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 781 | port_server_port = 32767 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 782 | _start_port_server(port_server_port) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 783 | try: |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 784 | infinite_runs = runs_per_test == 0 |
yang-g | 6c1fdc6 | 2015-08-18 11:57:42 -0700 | [diff] [blame] | 785 | one_run = set( |
| 786 | spec |
| 787 | for config in run_configs |
| 788 | for language in languages |
| 789 | for spec in language.test_specs(config, args.travis) |
| 790 | if re.search(args.regex, spec.shortname)) |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 791 | # When running on travis, we want out test runs to be as similar as possible |
| 792 | # for reproducibility purposes. |
| 793 | if travis: |
| 794 | massaged_one_run = sorted(one_run, key=lambda x: x.shortname) |
| 795 | else: |
| 796 | # whereas otherwise, we want to shuffle things up to give all tests a |
| 797 | # chance to run. |
| 798 | massaged_one_run = list(one_run) # random.shuffle needs an indexable seq. |
| 799 | random.shuffle(massaged_one_run) # which it modifies in-place. |
Craig Tiller | f7b7c89 | 2015-06-22 14:33:25 -0700 | [diff] [blame] | 800 | if infinite_runs: |
| 801 | 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] | 802 | runs_sequence = (itertools.repeat(massaged_one_run) if infinite_runs |
| 803 | else itertools.repeat(massaged_one_run, runs_per_test)) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 804 | all_runs = itertools.chain.from_iterable(runs_sequence) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 805 | |
| 806 | root = ET.Element('testsuites') if xml_report else None |
| 807 | testsuite = ET.SubElement(root, 'testsuite', id='1', package='grpc', name='tests') if xml_report else None |
| 808 | |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 809 | if not jobset.run(all_runs, check_cancelled, |
| 810 | newline_on_success=newline_on_success, travis=travis, |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 811 | infinite_runs=infinite_runs, |
Craig Tiller | da2220a | 2015-05-27 07:50:53 -0700 | [diff] [blame] | 812 | maxjobs=args.jobs, |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 813 | stop_on_failure=args.stop_on_failure, |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 814 | cache=cache if not xml_report else None, |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 815 | xml_report=testsuite, |
| 816 | add_env={'GRPC_TEST_PORT_SERVER': 'localhost:%d' % port_server_port}): |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 817 | return 2 |
| 818 | finally: |
| 819 | for antagonist in antagonists: |
| 820 | antagonist.kill() |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 821 | if xml_report: |
| 822 | tree = ET.ElementTree(root) |
| 823 | tree.write(xml_report, encoding='UTF-8') |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 824 | |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 825 | if cache: cache.save() |
| 826 | |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 827 | return 0 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 828 | |
| 829 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 830 | test_cache = TestCache(runs_per_test == 1) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 831 | test_cache.maybe_load() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 832 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 833 | if forever: |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 834 | success = True |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 835 | while True: |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 836 | dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples']) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 837 | initial_time = dw.most_recent_change() |
| 838 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 839 | previous_success = success |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 840 | success = _build_and_run(check_cancelled=have_files_changed, |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 841 | newline_on_success=False, |
Craig Tiller | 9a5a940 | 2015-04-16 10:39:50 -0700 | [diff] [blame] | 842 | travis=args.travis, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 843 | cache=test_cache) == 0 |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 844 | if not previous_success and success: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 845 | jobset.message('SUCCESS', |
| 846 | 'All tests are now passing properly', |
| 847 | do_newline=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 848 | jobset.message('IDLE', 'No change detected') |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 849 | while not have_files_changed(): |
| 850 | time.sleep(1) |
| 851 | else: |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 852 | result = _build_and_run(check_cancelled=lambda: False, |
| 853 | newline_on_success=args.newline_on_success, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 854 | travis=args.travis, |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 855 | cache=test_cache, |
| 856 | xml_report=args.xml_report) |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 857 | if result == 0: |
| 858 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 859 | else: |
| 860 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
| 861 | sys.exit(result) |