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