Nathaniel Manista | ae4fbcd | 2015-09-23 16:29:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
Craig Tiller | 4083977 | 2016-01-05 12:34:49 -0800 | [diff] [blame] | 2 | # Copyright 2015-2016, Google Inc. |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 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 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 49 | import urllib2 |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 50 | import uuid |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 51 | |
| 52 | import jobset |
Adele Zhou | a30f829 | 2015-11-02 13:15:46 -0800 | [diff] [blame] | 53 | import report_utils |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 54 | import watch_dirs |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 55 | |
Craig Tiller | b361b4e | 2016-01-06 11:44:17 -0800 | [diff] [blame] | 56 | |
Craig Tiller | 2cc2b84 | 2015-02-27 11:38:31 -0800 | [diff] [blame] | 57 | ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 58 | os.chdir(ROOT) |
| 59 | |
| 60 | |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 61 | _FORCE_ENVIRON_FOR_WRAPPERS = {} |
| 62 | |
| 63 | |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 64 | def platform_string(): |
Nicolas "Pixel" Noble | f72d7b5 | 2015-12-03 03:07:43 +0100 | [diff] [blame] | 65 | return jobset.platform_string() |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 66 | |
| 67 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 68 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
| 69 | class SimpleConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 70 | |
Masood Malekghassemi | 26ea9e2 | 2015-10-09 15:19:17 -0700 | [diff] [blame] | 71 | def __init__(self, config, environ=None, timeout_multiplier=1): |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 72 | if environ is None: |
| 73 | environ = {} |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 74 | self.build_config = config |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 75 | self.allow_hashing = (config != 'gcov') |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 76 | self.environ = environ |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 77 | self.environ['CONFIG'] = config |
Masood Malekghassemi | 26ea9e2 | 2015-10-09 15:19:17 -0700 | [diff] [blame] | 78 | self.timeout_multiplier = timeout_multiplier |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 79 | |
Masood Malekghassemi | 26ea9e2 | 2015-10-09 15:19:17 -0700 | [diff] [blame] | 80 | def job_spec(self, cmdline, hash_targets, timeout_seconds=5*60, |
Craig Tiller | 56c6b6a | 2016-01-20 08:27:37 -0800 | [diff] [blame] | 81 | shortname=None, environ={}, cpu_cost=1.0): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 82 | """Construct a jobset.JobSpec for a test under this config |
| 83 | |
| 84 | Args: |
| 85 | cmdline: a list of strings specifying the command line the test |
| 86 | would like to run |
| 87 | hash_targets: either None (don't do caching of test results), or |
| 88 | a list of strings specifying files to include in a |
| 89 | binary hash to check if a test has changed |
| 90 | -- if used, all artifacts needed to run the test must |
| 91 | be listed |
| 92 | """ |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 93 | actual_environ = self.environ.copy() |
| 94 | for k, v in environ.iteritems(): |
| 95 | actual_environ[k] = v |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 96 | return jobset.JobSpec(cmdline=cmdline, |
Jan Tattermusch | 9a7d30c | 2015-04-23 16:12:55 -0700 | [diff] [blame] | 97 | shortname=shortname, |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 98 | environ=actual_environ, |
Craig Tiller | 56c6b6a | 2016-01-20 08:27:37 -0800 | [diff] [blame] | 99 | cpu_cost=cpu_cost, |
Craig Tiller | 94d04a5 | 2016-01-20 10:58:23 -0800 | [diff] [blame] | 100 | timeout_seconds=(self.timeout_multiplier * timeout_seconds if timeout_seconds else None), |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 101 | hash_targets=hash_targets |
Craig Tiller | d4509a1 | 2015-09-28 09:18:40 -0700 | [diff] [blame] | 102 | if self.allow_hashing else None, |
Craig Tiller | 35505de | 2015-10-08 13:31:33 -0700 | [diff] [blame] | 103 | flake_retries=5 if args.allow_flakes else 0, |
| 104 | timeout_retries=3 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 | 56c6b6a | 2016-01-20 08:27:37 -0800 | [diff] [blame] | 118 | def job_spec(self, cmdline, hash_targets, cpu_cost=1.0): |
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 | 56c6b6a | 2016-01-20 08:27:37 -0800 | [diff] [blame] | 123 | cpu_cost=cpu_cost, |
Craig Tiller | 95cc07b | 2015-09-28 13:41:30 -0700 | [diff] [blame] | 124 | flake_retries=5 if args.allow_flakes else 0, |
Craig Tiller | 35505de | 2015-10-08 13:31:33 -0700 | [diff] [blame] | 125 | timeout_retries=3 if args.allow_flakes else 0) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 126 | |
| 127 | |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 128 | def get_c_tests(travis, test_lang) : |
| 129 | out = [] |
| 130 | platforms_str = 'ci_platforms' if travis else 'platforms' |
| 131 | with open('tools/run_tests/tests.json') as f: |
murgatroid99 | 89899b1 | 2015-09-22 09:14:48 -0700 | [diff] [blame] | 132 | js = json.load(f) |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 133 | return [tgt |
| 134 | for tgt in js |
| 135 | if tgt['language'] == test_lang and |
| 136 | platform_string() in tgt[platforms_str] and |
| 137 | not (travis and tgt['flaky'])] |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 138 | |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 139 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 140 | class CLanguage(object): |
| 141 | |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 142 | def __init__(self, make_target, test_lang): |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 143 | self.make_target = make_target |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 144 | self.platform = platform_string() |
Craig Tiller | 711bbe6 | 2015-08-19 12:35:16 -0700 | [diff] [blame] | 145 | self.test_lang = test_lang |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 146 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 147 | def test_specs(self, config, args): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 148 | out = [] |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 149 | binaries = get_c_tests(args.travis, self.test_lang) |
Craig Tiller | 711bbe6 | 2015-08-19 12:35:16 -0700 | [diff] [blame] | 150 | for target in binaries: |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 151 | if config.build_config in target['exclude_configs']: |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 152 | continue |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 153 | if self.platform == 'windows': |
Craig Tiller | f418260 | 2015-09-01 12:23:16 -0700 | [diff] [blame] | 154 | binary = 'vsprojects/%s/%s.exe' % ( |
| 155 | _WINDOWS_CONFIG[config.build_config], target['name']) |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 156 | else: |
| 157 | binary = 'bins/%s/%s' % (config.build_config, target['name']) |
yang-g | 6c1fdc6 | 2015-08-18 11:57:42 -0700 | [diff] [blame] | 158 | if os.path.isfile(binary): |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 159 | cmdline = [binary] + target['args'] |
| 160 | out.append(config.job_spec(cmdline, [binary], |
| 161 | shortname=' '.join(cmdline), |
Craig Tiller | 56c6b6a | 2016-01-20 08:27:37 -0800 | [diff] [blame] | 162 | cpu_cost=target['cpu_cost'], |
Craig Tiller | cc0535d | 2015-12-08 15:14:47 -0800 | [diff] [blame] | 163 | environ={'GRPC_DEFAULT_SSL_ROOTS_FILE_PATH': |
| 164 | os.path.abspath(os.path.dirname( |
Craig Tiller | ed2164d | 2015-12-08 22:03:36 -0800 | [diff] [blame] | 165 | sys.argv[0]) + '/../../src/core/tsi/test_creds/ca.pem')})) |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 166 | elif args.regex == '.*' or platform_string() == 'windows': |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 167 | print '\nWARNING: binary not found, skipping', binary |
Nicolas Noble | e144536 | 2015-05-11 17:40:26 -0700 | [diff] [blame] | 168 | return sorted(out) |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 169 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 170 | def make_targets(self, test_regex): |
| 171 | if platform_string() != 'windows' and test_regex != '.*': |
| 172 | # use the regex to minimize the number of things to build |
| 173 | return [target['name'] |
| 174 | for target in get_c_tests(False, self.test_lang) |
| 175 | if re.search(test_regex, target['name'])] |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 176 | if platform_string() == 'windows': |
| 177 | # don't build tools on windows just yet |
| 178 | return ['buildtests_%s' % self.make_target] |
Craig Tiller | 7552f0f | 2015-06-19 17:46:20 -0700 | [diff] [blame] | 179 | return ['buildtests_%s' % self.make_target, 'tools_%s' % self.make_target] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 180 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 181 | def make_options(self): |
| 182 | return [] |
| 183 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 184 | def pre_build_steps(self): |
Jan Tattermusch | 874aec0 | 2015-10-07 19:26:19 -0700 | [diff] [blame] | 185 | if self.platform == 'windows': |
| 186 | return [['tools\\run_tests\\pre_build_c.bat']] |
| 187 | else: |
| 188 | return [] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 189 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 190 | def build_steps(self): |
| 191 | return [] |
| 192 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 193 | def post_tests_steps(self): |
| 194 | if self.platform == 'windows': |
| 195 | return [] |
| 196 | else: |
| 197 | return [['tools/run_tests/post_tests_c.sh']] |
| 198 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 199 | def makefile_name(self): |
| 200 | return 'Makefile' |
| 201 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 202 | def supports_multi_config(self): |
| 203 | return True |
| 204 | |
| 205 | def __str__(self): |
| 206 | return self.make_target |
| 207 | |
Craig Tiller | cc0535d | 2015-12-08 15:14:47 -0800 | [diff] [blame] | 208 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 209 | class NodeLanguage(object): |
| 210 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 211 | def test_specs(self, config, args): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 212 | return [config.job_spec(['tools/run_tests/run_node.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 213 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 214 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 215 | def pre_build_steps(self): |
murgatroid99 | ae369de | 2015-10-09 15:40:48 -0700 | [diff] [blame] | 216 | # Default to 1 week cache expiration |
murgatroid99 | 9375895 | 2015-10-14 11:51:05 -0700 | [diff] [blame] | 217 | return [['tools/run_tests/pre_build_node.sh']] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 218 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 219 | def make_targets(self, test_regex): |
murgatroid99 | db5b160 | 2015-10-01 13:20:11 -0700 | [diff] [blame] | 220 | return [] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 221 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 222 | def make_options(self): |
| 223 | return [] |
| 224 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 225 | def build_steps(self): |
| 226 | return [['tools/run_tests/build_node.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 227 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 228 | def post_tests_steps(self): |
| 229 | return [] |
| 230 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 231 | def makefile_name(self): |
| 232 | return 'Makefile' |
| 233 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 234 | def supports_multi_config(self): |
| 235 | return False |
| 236 | |
| 237 | def __str__(self): |
| 238 | return 'node' |
| 239 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 240 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 241 | class PhpLanguage(object): |
| 242 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 243 | def test_specs(self, config, args): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 244 | return [config.job_spec(['src/php/bin/run_tests.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 245 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 246 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 247 | def pre_build_steps(self): |
| 248 | return [] |
| 249 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 250 | def make_targets(self, test_regex): |
Craig Tiller | af7cf54 | 2015-05-22 10:07:34 -0700 | [diff] [blame] | 251 | return ['static_c', 'shared_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 252 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 253 | def make_options(self): |
| 254 | return [] |
| 255 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 256 | def build_steps(self): |
| 257 | return [['tools/run_tests/build_php.sh']] |
| 258 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 259 | def post_tests_steps(self): |
Stanley Cheung | a6b9548 | 2016-01-13 16:10:48 -0800 | [diff] [blame] | 260 | return [['tools/run_tests/post_tests_php.sh']] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 261 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 262 | def makefile_name(self): |
| 263 | return 'Makefile' |
| 264 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 265 | def supports_multi_config(self): |
| 266 | return False |
| 267 | |
| 268 | def __str__(self): |
| 269 | return 'php' |
| 270 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 271 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 272 | class PythonLanguage(object): |
| 273 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 274 | def __init__(self): |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 275 | self._build_python_versions = ['2.7'] |
Masood Malekghassemi | e5f7002 | 2015-06-29 09:20:26 -0700 | [diff] [blame] | 276 | self._has_python_versions = [] |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 277 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 278 | def test_specs(self, config, args): |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 279 | environment = dict(_FORCE_ENVIRON_FOR_WRAPPERS) |
| 280 | environment['PYVER'] = '2.7' |
| 281 | return [config.job_spec( |
| 282 | ['tools/run_tests/run_python.sh'], |
| 283 | None, |
| 284 | environ=environment, |
| 285 | shortname='py.test', |
Masood Malekghassemi | 26ea9e2 | 2015-10-09 15:19:17 -0700 | [diff] [blame] | 286 | timeout_seconds=15*60 |
Masood Malekghassemi | 2b84162 | 2015-07-28 17:39:02 -0700 | [diff] [blame] | 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 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 292 | def make_targets(self, test_regex): |
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 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 295 | def make_options(self): |
| 296 | return [] |
| 297 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 298 | def build_steps(self): |
Masood Malekghassemi | e5f7002 | 2015-06-29 09:20:26 -0700 | [diff] [blame] | 299 | commands = [] |
| 300 | for python_version in self._build_python_versions: |
| 301 | try: |
| 302 | with open(os.devnull, 'w') as output: |
| 303 | subprocess.check_call(['which', 'python' + python_version], |
| 304 | stdout=output, stderr=output) |
| 305 | commands.append(['tools/run_tests/build_python.sh', python_version]) |
| 306 | self._has_python_versions.append(python_version) |
| 307 | except: |
| 308 | jobset.message('WARNING', 'Missing Python ' + python_version, |
| 309 | do_newline=True) |
| 310 | return commands |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 311 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 312 | def post_tests_steps(self): |
| 313 | return [] |
| 314 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 315 | def makefile_name(self): |
| 316 | return 'Makefile' |
| 317 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 318 | def supports_multi_config(self): |
| 319 | return False |
| 320 | |
| 321 | def __str__(self): |
| 322 | return 'python' |
| 323 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 324 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 325 | class RubyLanguage(object): |
| 326 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 327 | def test_specs(self, config, args): |
Craig Tiller | 4fc9003 | 2015-05-21 10:39:52 -0700 | [diff] [blame] | 328 | return [config.job_spec(['tools/run_tests/run_ruby.sh'], None, |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 329 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 330 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 331 | def pre_build_steps(self): |
Nicolas "Pixel" Noble | bcf988f | 2015-10-08 03:00:42 +0200 | [diff] [blame] | 332 | return [['tools/run_tests/pre_build_ruby.sh']] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 333 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 334 | def make_targets(self, test_regex): |
murgatroid99 | a43c14f | 2015-07-30 13:31:23 -0700 | [diff] [blame] | 335 | return ['static_c'] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 336 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 337 | def make_options(self): |
| 338 | return [] |
| 339 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 340 | def build_steps(self): |
| 341 | return [['tools/run_tests/build_ruby.sh']] |
| 342 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 343 | def post_tests_steps(self): |
Nicolas "Pixel" Noble | 7ef1e53 | 2015-12-02 00:55:33 +0100 | [diff] [blame] | 344 | return [['tools/run_tests/post_tests_ruby.sh']] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 345 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 346 | def makefile_name(self): |
| 347 | return 'Makefile' |
| 348 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 349 | def supports_multi_config(self): |
| 350 | return False |
| 351 | |
| 352 | def __str__(self): |
| 353 | return 'ruby' |
| 354 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 355 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 356 | class CSharpLanguage(object): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 357 | def __init__(self): |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 358 | self.platform = platform_string() |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 359 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 360 | def test_specs(self, config, args): |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 361 | with open('src/csharp/tests.json') as f: |
| 362 | tests_json = json.load(f) |
| 363 | assemblies = tests_json['assemblies'] |
| 364 | tests = tests_json['tests'] |
| 365 | |
| 366 | msbuild_config = _WINDOWS_CONFIG[config.build_config] |
| 367 | assembly_files = ['%s/bin/%s/%s.dll' % (a, msbuild_config, a) |
| 368 | for a in assemblies] |
| 369 | |
| 370 | extra_args = ['-labels'] + assembly_files |
| 371 | |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 372 | if self.platform == 'windows': |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 373 | script_name = 'tools\\run_tests\\run_csharp.bat' |
| 374 | extra_args += ['-domain=None'] |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 375 | else: |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 376 | script_name = 'tools/run_tests/run_csharp.sh' |
Jan Tattermusch | bf3b153 | 2015-10-26 10:24:42 -0700 | [diff] [blame] | 377 | |
Jan Tattermusch | bdf4b2e | 2015-10-28 08:22:34 -0700 | [diff] [blame] | 378 | if config.build_config == 'gcov': |
| 379 | # On Windows, we only collect C# code coverage. |
| 380 | # On Linux, we only collect coverage for native extension. |
| 381 | # For code coverage all tests need to run as one suite. |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 382 | return [config.job_spec([script_name] + extra_args, None, |
| 383 | shortname='csharp.coverage', |
| 384 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
Jan Tattermusch | 61c3a83 | 2015-10-27 17:54:50 -0700 | [diff] [blame] | 385 | else: |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 386 | specs = [] |
| 387 | for test in tests: |
| 388 | cmdline = [script_name, '-run=%s' % test] + extra_args |
| 389 | if self.platform == 'windows': |
| 390 | # use different output directory for each test to prevent |
| 391 | # TestResult.xml clash between parallel test runs. |
| 392 | cmdline += ['-work=test-result/%s' % uuid.uuid4()] |
| 393 | specs.append(config.job_spec(cmdline, None, |
| 394 | shortname='csharp.%s' % test, |
| 395 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)) |
| 396 | return specs |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 397 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 398 | def pre_build_steps(self): |
Jan Tattermusch | 48423fc | 2015-10-07 18:59:16 -0700 | [diff] [blame] | 399 | if self.platform == 'windows': |
Jan Tattermusch | 874aec0 | 2015-10-07 19:26:19 -0700 | [diff] [blame] | 400 | return [['tools\\run_tests\\pre_build_csharp.bat']] |
Jan Tattermusch | 48423fc | 2015-10-07 18:59:16 -0700 | [diff] [blame] | 401 | else: |
| 402 | return [['tools/run_tests/pre_build_csharp.sh']] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 403 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 404 | def make_targets(self, test_regex): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 405 | # For Windows, this target doesn't really build anything, |
| 406 | # everything is build by buildall script later. |
Craig Tiller | d590482 | 2015-08-31 21:30:58 -0700 | [diff] [blame] | 407 | if self.platform == 'windows': |
| 408 | return [] |
| 409 | else: |
| 410 | return ['grpc_csharp_ext'] |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 411 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 412 | def make_options(self): |
| 413 | if self.platform == 'mac': |
| 414 | # On Mac, official distribution of mono is 32bit. |
| 415 | return ['CFLAGS=-arch i386', 'LDFLAGS=-arch i386'] |
| 416 | else: |
| 417 | return [] |
| 418 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 419 | def build_steps(self): |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 420 | if self.platform == 'windows': |
| 421 | return [['src\\csharp\\buildall.bat']] |
| 422 | else: |
| 423 | return [['tools/run_tests/build_csharp.sh']] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 424 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 425 | def post_tests_steps(self): |
| 426 | return [] |
| 427 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 428 | def makefile_name(self): |
| 429 | return 'Makefile' |
| 430 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 431 | def supports_multi_config(self): |
| 432 | return False |
| 433 | |
| 434 | def __str__(self): |
| 435 | return 'csharp' |
| 436 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 437 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 438 | class ObjCLanguage(object): |
| 439 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 440 | def test_specs(self, config, args): |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 441 | return [config.job_spec(['src/objective-c/tests/run_tests.sh'], None, |
| 442 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)] |
| 443 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 444 | def pre_build_steps(self): |
| 445 | return [] |
| 446 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 447 | def make_targets(self, test_regex): |
Jorge Canizales | d0b32e9 | 2015-07-30 23:08:43 -0700 | [diff] [blame] | 448 | return ['grpc_objective_c_plugin', 'interop_server'] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 449 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 450 | def make_options(self): |
| 451 | return [] |
| 452 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 453 | def build_steps(self): |
Jorge Canizales | d0b32e9 | 2015-07-30 23:08:43 -0700 | [diff] [blame] | 454 | return [['src/objective-c/tests/build_tests.sh']] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 455 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 456 | def post_tests_steps(self): |
| 457 | return [] |
| 458 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 459 | def makefile_name(self): |
| 460 | return 'Makefile' |
| 461 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 462 | def supports_multi_config(self): |
| 463 | return False |
| 464 | |
| 465 | def __str__(self): |
| 466 | return 'objc' |
| 467 | |
| 468 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 469 | class Sanity(object): |
| 470 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 471 | def test_specs(self, config, args): |
Craig Tiller | 94d04a5 | 2016-01-20 10:58:23 -0800 | [diff] [blame] | 472 | import yaml |
| 473 | with open('tools/run_tests/sanity_tests.yaml', 'r') as f: |
Craig Tiller | a7a9e40 | 2016-01-20 11:05:34 -0800 | [diff] [blame] | 474 | return [config.job_spec([cmd['script']], None, timeout_seconds=None, environ={'TEST': 'true'}, cpu_cost=cmd.get('cpu_cost', 1)) |
Craig Tiller | 94d04a5 | 2016-01-20 10:58:23 -0800 | [diff] [blame] | 475 | for cmd in yaml.load(f)] |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 476 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 477 | def pre_build_steps(self): |
| 478 | return [] |
| 479 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 480 | def make_targets(self, test_regex): |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 481 | return ['run_dep_checks'] |
| 482 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 483 | def make_options(self): |
| 484 | return [] |
| 485 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 486 | def build_steps(self): |
| 487 | return [] |
| 488 | |
Nicolas "Pixel" Noble | 87879b3 | 2015-10-12 23:28:53 +0200 | [diff] [blame] | 489 | def post_tests_steps(self): |
| 490 | return [] |
| 491 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 492 | def makefile_name(self): |
| 493 | return 'Makefile' |
| 494 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 495 | def supports_multi_config(self): |
| 496 | return False |
| 497 | |
| 498 | def __str__(self): |
| 499 | return 'sanity' |
| 500 | |
Nicolas "Pixel" Noble | e55cd7f | 2015-04-14 17:59:13 +0200 | [diff] [blame] | 501 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 502 | class Build(object): |
| 503 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 504 | def test_specs(self, config, args): |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 505 | return [] |
| 506 | |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 507 | def pre_build_steps(self): |
| 508 | return [] |
| 509 | |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 510 | def make_targets(self, test_regex): |
Nicolas "Pixel" Noble | c23827b | 2015-04-23 06:17:55 +0200 | [diff] [blame] | 511 | return ['static'] |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 512 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 513 | def make_options(self): |
| 514 | return [] |
| 515 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 516 | def build_steps(self): |
| 517 | return [] |
| 518 | |
Nicolas "Pixel" Noble | fe30045 | 2015-10-27 23:05:10 +0100 | [diff] [blame] | 519 | def post_tests_steps(self): |
| 520 | return [] |
| 521 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 522 | def makefile_name(self): |
| 523 | return 'Makefile' |
| 524 | |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 525 | def supports_multi_config(self): |
| 526 | return True |
| 527 | |
| 528 | def __str__(self): |
| 529 | return self.make_target |
| 530 | |
| 531 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 532 | # different configurations we can run under |
| 533 | _CONFIGS = { |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 534 | 'dbg': SimpleConfig('dbg'), |
| 535 | 'opt': SimpleConfig('opt'), |
Masood Malekghassemi | 26ea9e2 | 2015-10-09 15:19:17 -0700 | [diff] [blame] | 536 | 'tsan': SimpleConfig('tsan', timeout_multiplier=2, environ={ |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 537 | '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] | 538 | 'msan': SimpleConfig('msan', timeout_multiplier=1.5), |
Craig Tiller | 96bd5f6 | 2015-02-13 09:04:13 -0800 | [diff] [blame] | 539 | 'ubsan': SimpleConfig('ubsan'), |
Masood Malekghassemi | 26ea9e2 | 2015-10-09 15:19:17 -0700 | [diff] [blame] | 540 | 'asan': SimpleConfig('asan', timeout_multiplier=1.5, environ={ |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 541 | 'ASAN_OPTIONS': 'suppressions=tools/asan_suppressions.txt:detect_leaks=1:color=always', |
| 542 | 'LSAN_OPTIONS': 'suppressions=tools/asan_suppressions.txt:report_objects=1'}), |
Craig Tiller | 810725c | 2015-05-12 09:44:41 -0700 | [diff] [blame] | 543 | 'asan-noleaks': SimpleConfig('asan', environ={ |
Craig Tiller | 2a2a6ed | 2015-11-18 15:52:46 -0800 | [diff] [blame] | 544 | 'ASAN_OPTIONS': 'detect_leaks=0:color=always'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 545 | 'gcov': SimpleConfig('gcov'), |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 546 | 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 547 | 'helgrind': ValgrindConfig('dbg', 'helgrind') |
| 548 | } |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 549 | |
| 550 | |
Nicolas "Pixel" Noble | 1fb5e82 | 2015-03-16 06:20:37 +0100 | [diff] [blame] | 551 | _DEFAULT = ['opt'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 552 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 553 | 'c++': CLanguage('cxx', 'c++'), |
| 554 | 'c': CLanguage('c', 'c'), |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 555 | 'node': NodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 556 | 'php': PhpLanguage(), |
| 557 | 'python': PythonLanguage(), |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 558 | 'ruby': RubyLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 559 | 'csharp': CSharpLanguage(), |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 560 | 'objc' : ObjCLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 561 | 'sanity': Sanity(), |
Nicolas "Pixel" Noble | fd2b093 | 2015-03-26 00:26:29 +0100 | [diff] [blame] | 562 | 'build': Build(), |
Craig Tiller | eb272bc | 2015-01-30 13:13:14 -0800 | [diff] [blame] | 563 | } |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 564 | |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 565 | _WINDOWS_CONFIG = { |
| 566 | 'dbg': 'Debug', |
| 567 | 'opt': 'Release', |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 568 | 'gcov': 'Debug', |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 569 | } |
| 570 | |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 571 | |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 572 | def _windows_arch_option(arch): |
| 573 | """Returns msbuild cmdline option for selected architecture.""" |
| 574 | if arch == 'default' or arch == 'windows_x86': |
| 575 | return '/p:Platform=Win32' |
| 576 | elif arch == 'windows_x64': |
| 577 | return '/p:Platform=x64' |
| 578 | else: |
| 579 | print 'Architecture %s not supported on current platform.' % arch |
| 580 | sys.exit(1) |
| 581 | |
| 582 | |
| 583 | def _windows_build_bat(compiler): |
| 584 | """Returns name of build.bat for selected compiler.""" |
| 585 | if compiler == 'default' or compiler == 'vs2013': |
| 586 | return 'vsprojects\\build_vs2013.bat' |
| 587 | elif compiler == 'vs2015': |
| 588 | return 'vsprojects\\build_vs2015.bat' |
| 589 | elif compiler == 'vs2010': |
| 590 | return 'vsprojects\\build_vs2010.bat' |
| 591 | else: |
| 592 | print 'Compiler %s not supported.' % compiler |
| 593 | sys.exit(1) |
| 594 | |
| 595 | |
| 596 | def _windows_toolset_option(compiler): |
| 597 | """Returns msbuild PlatformToolset for selected compiler.""" |
| 598 | if compiler == 'default' or compiler == 'vs2013': |
| 599 | return '/p:PlatformToolset=v120' |
| 600 | elif compiler == 'vs2015': |
| 601 | return '/p:PlatformToolset=v140' |
| 602 | elif compiler == 'vs2010': |
| 603 | return '/p:PlatformToolset=v100' |
| 604 | else: |
| 605 | print 'Compiler %s not supported.' % compiler |
| 606 | sys.exit(1) |
| 607 | |
| 608 | |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 609 | def runs_per_test_type(arg_str): |
| 610 | """Auxilary function to parse the "runs_per_test" flag. |
| 611 | |
| 612 | Returns: |
| 613 | A positive integer or 0, the latter indicating an infinite number of |
| 614 | runs. |
| 615 | |
| 616 | Raises: |
| 617 | argparse.ArgumentTypeError: Upon invalid input. |
| 618 | """ |
| 619 | if arg_str == 'inf': |
| 620 | return 0 |
| 621 | try: |
| 622 | n = int(arg_str) |
| 623 | if n <= 0: raise ValueError |
Craig Tiller | 50e53e2 | 2015-06-01 20:18:21 -0700 | [diff] [blame] | 624 | return n |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 625 | except: |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 626 | msg = '\'{}\' is not a positive integer or \'inf\''.format(arg_str) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 627 | raise argparse.ArgumentTypeError(msg) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 628 | |
| 629 | # parse command line |
| 630 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 631 | argp.add_argument('-c', '--config', |
| 632 | choices=['all'] + sorted(_CONFIGS.keys()), |
| 633 | nargs='+', |
| 634 | default=_DEFAULT) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 635 | argp.add_argument('-n', '--runs_per_test', default=1, type=runs_per_test_type, |
| 636 | help='A positive integer or "inf". If "inf", all tests will run in an ' |
| 637 | 'infinite loop. Especially useful in combination with "-f"') |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 638 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Craig Tiller | 5f735a6 | 2016-01-20 09:31:15 -0800 | [diff] [blame] | 639 | argp.add_argument('-j', '--jobs', default=multiprocessing.cpu_count(), type=int) |
Craig Tiller | 8451e87 | 2015-02-27 09:25:51 -0800 | [diff] [blame] | 640 | argp.add_argument('-s', '--slowdown', default=1.0, type=float) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 641 | argp.add_argument('-f', '--forever', |
| 642 | default=False, |
| 643 | action='store_const', |
| 644 | const=True) |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 645 | argp.add_argument('-t', '--travis', |
| 646 | default=False, |
| 647 | action='store_const', |
| 648 | const=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 649 | argp.add_argument('--newline_on_success', |
| 650 | default=False, |
| 651 | action='store_const', |
| 652 | const=True) |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 653 | argp.add_argument('-l', '--language', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 654 | choices=['all'] + sorted(_LANGUAGES.keys()), |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 655 | nargs='+', |
Craig Tiller | 60f15e6 | 2015-05-13 09:05:17 -0700 | [diff] [blame] | 656 | default=['all']) |
Craig Tiller | cd43da8 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 657 | argp.add_argument('-S', '--stop_on_failure', |
| 658 | default=False, |
| 659 | action='store_const', |
| 660 | const=True) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 661 | argp.add_argument('--use_docker', |
| 662 | default=False, |
| 663 | action='store_const', |
| 664 | const=True, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 665 | help='Run all the tests under docker. That provides ' + |
| 666 | 'additional isolation and prevents the need to install ' + |
| 667 | 'language specific prerequisites. Only available on Linux.') |
Craig Tiller | d4509a1 | 2015-09-28 09:18:40 -0700 | [diff] [blame] | 668 | argp.add_argument('--allow_flakes', |
| 669 | default=False, |
| 670 | action='store_const', |
| 671 | const=True, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 672 | help='Allow flaky tests to show as passing (re-runs failed tests up to five times)') |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 673 | argp.add_argument('--arch', |
| 674 | choices=['default', 'windows_x86', 'windows_x64'], |
| 675 | default='default', |
| 676 | help='Selects architecture to target. For some platforms "default" is the only supported choice.') |
| 677 | argp.add_argument('--compiler', |
| 678 | choices=['default', 'vs2010', 'vs2013', 'vs2015'], |
| 679 | default='default', |
| 680 | help='Selects compiler to use. For some platforms "default" is the only supported choice.') |
| 681 | argp.add_argument('--build_only', |
| 682 | default=False, |
| 683 | action='store_const', |
| 684 | const=True, |
| 685 | help='Perform all the build steps but dont run any tests.') |
Craig Tiller | 5f735a6 | 2016-01-20 09:31:15 -0800 | [diff] [blame] | 686 | argp.add_argument('--measure_cpu_costs', default=False, action='store_const', const=True, |
| 687 | help='Measure the cpu costs of tests') |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 688 | argp.add_argument('--update_submodules', default=[], nargs='*', |
| 689 | help='Update some submodules before building. If any are updated, also run generate_projects. ' + |
| 690 | 'Submodules are specified as SUBMODULE_NAME:BRANCH; if BRANCH is omitted, master is assumed.') |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 691 | argp.add_argument('-a', '--antagonists', default=0, type=int) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 692 | argp.add_argument('-x', '--xml_report', default=None, type=str, |
| 693 | help='Generates a JUnit-compatible XML report') |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 694 | args = argp.parse_args() |
| 695 | |
Craig Tiller | 5f735a6 | 2016-01-20 09:31:15 -0800 | [diff] [blame] | 696 | jobset.measure_cpu_costs = args.measure_cpu_costs |
| 697 | |
Jan Tattermusch | c96b9eb | 2015-09-18 16:01:21 -0700 | [diff] [blame] | 698 | if args.use_docker: |
| 699 | if not args.travis: |
| 700 | print 'Seen --use_docker flag, will run tests under docker.' |
| 701 | print |
| 702 | print 'IMPORTANT: The changes you are testing need to be locally committed' |
| 703 | print 'because only the committed changes in the current branch will be' |
| 704 | print 'copied to the docker environment.' |
| 705 | time.sleep(5) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 706 | |
| 707 | 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] | 708 | 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] | 709 | |
| 710 | # TODO(jtattermusch): revisit if we need special handling for arch here |
| 711 | # set arch command prefix in case we are working with different arch. |
| 712 | arch_env = os.getenv('arch') |
| 713 | if arch_env: |
| 714 | run_test_cmd = 'arch %s %s' % (arch_env, run_test_cmd) |
| 715 | |
| 716 | env = os.environ.copy() |
| 717 | env['RUN_TESTS_COMMAND'] = run_tests_cmd |
| 718 | if args.xml_report: |
| 719 | env['XML_REPORT'] = args.xml_report |
Jan Tattermusch | 261b58c | 2015-09-18 17:15:48 -0700 | [diff] [blame] | 720 | if not args.travis: |
| 721 | env['TTY_FLAG'] = '-t' # enables Ctrl-C when not on Jenkins. |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 722 | |
| 723 | subprocess.check_call(['tools/jenkins/build_docker_and_run_tests.sh'], |
| 724 | shell=True, |
| 725 | env=env) |
| 726 | sys.exit(0) |
| 727 | |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 728 | # update submodules if necessary |
Craig Tiller | b361b4e | 2016-01-06 11:44:17 -0800 | [diff] [blame] | 729 | need_to_regenerate_projects = False |
| 730 | for spec in args.update_submodules: |
| 731 | spec = spec.split(':', 1) |
| 732 | if len(spec) == 1: |
| 733 | submodule = spec[0] |
| 734 | branch = 'master' |
| 735 | elif len(spec) == 2: |
| 736 | submodule = spec[0] |
| 737 | branch = spec[1] |
| 738 | cwd = 'third_party/%s' % submodule |
| 739 | def git(cmd, cwd=cwd): |
| 740 | print 'in %s: git %s' % (cwd, cmd) |
| 741 | subprocess.check_call('git %s' % cmd, cwd=cwd, shell=True) |
| 742 | git('fetch') |
| 743 | git('checkout %s' % branch) |
| 744 | git('pull origin %s' % branch) |
| 745 | if os.path.exists('src/%s/gen_build_yaml.py' % submodule): |
| 746 | need_to_regenerate_projects = True |
| 747 | if need_to_regenerate_projects: |
| 748 | if jobset.platform_string() == 'linux': |
| 749 | subprocess.check_call('tools/buildgen/generate_projects.sh', shell=True) |
| 750 | else: |
| 751 | print 'WARNING: may need to regenerate projects, but since we are not on' |
| 752 | print ' Linux this step is being skipped. Compilation MAY fail.' |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 753 | |
| 754 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 755 | # grab config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 756 | run_configs = set(_CONFIGS[cfg] |
| 757 | for cfg in itertools.chain.from_iterable( |
| 758 | _CONFIGS.iterkeys() if x == 'all' else [x] |
| 759 | for x in args.config)) |
| 760 | build_configs = set(cfg.build_config for cfg in run_configs) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 761 | |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 762 | if args.travis: |
murgatroid99 | d3b5b7f | 2015-10-06 17:02:03 -0700 | [diff] [blame] | 763 | _FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'api'} |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 764 | |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 765 | if 'all' in args.language: |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 766 | lang_list = _LANGUAGES.keys() |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 767 | else: |
| 768 | lang_list = args.language |
Craig Tiller | 1690066 | 2016-01-07 19:30:54 -0800 | [diff] [blame] | 769 | # We don't support code coverage on some languages |
| 770 | if 'gcov' in args.config: |
| 771 | for bad in ['objc', 'sanity', 'build']: |
| 772 | if bad in lang_list: |
| 773 | lang_list.remove(bad) |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 774 | |
| 775 | languages = set(_LANGUAGES[l] for l in lang_list) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 776 | |
| 777 | if len(build_configs) > 1: |
| 778 | for language in languages: |
| 779 | if not language.supports_multi_config(): |
| 780 | print language, 'does not support multiple build configurations' |
| 781 | sys.exit(1) |
| 782 | |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 783 | language_make_options=[] |
| 784 | if any(language.make_options() for language in languages): |
| 785 | if len(languages) != 1: |
| 786 | print 'languages with custom make options cannot be built simultaneously with other languages' |
| 787 | sys.exit(1) |
| 788 | else: |
| 789 | language_make_options = next(iter(languages)).make_options() |
| 790 | |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 791 | if platform_string() != 'windows': |
| 792 | if args.arch != 'default': |
| 793 | print 'Architecture %s not supported on current platform.' % args.arch |
| 794 | sys.exit(1) |
| 795 | if args.compiler != 'default': |
| 796 | print 'Compiler %s not supported on current platform.' % args.compiler |
| 797 | sys.exit(1) |
| 798 | |
Nicolas "Pixel" Noble | f72d7b5 | 2015-12-03 03:07:43 +0100 | [diff] [blame] | 799 | if platform_string() == 'windows': |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 800 | def make_jobspec(cfg, targets, makefile='Makefile'): |
Craig Tiller | fc3c0c4 | 2015-09-01 16:47:54 -0700 | [diff] [blame] | 801 | extra_args = [] |
Craig Tiller | b5391e1 | 2015-09-03 14:35:18 -0700 | [diff] [blame] | 802 | # better do parallel compilation |
Jan Tattermusch | 47eeb2b | 2015-10-07 14:09:18 -0700 | [diff] [blame] | 803 | # empirically /m:2 gives the best performance/price and should prevent |
| 804 | # overloading the windows workers. |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 805 | extra_args.extend(['/m:2']) |
Craig Tiller | b5391e1 | 2015-09-03 14:35:18 -0700 | [diff] [blame] | 806 | # 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] | 807 | extra_args.extend(['/p:Jenkins=true']) |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 808 | return [ |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 809 | jobset.JobSpec([_windows_build_bat(args.compiler), |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 810 | 'vsprojects\\%s.sln' % target, |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 811 | '/p:Configuration=%s' % _WINDOWS_CONFIG[cfg], |
| 812 | _windows_toolset_option(args.compiler), |
| 813 | _windows_arch_option(args.arch)] + |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 814 | extra_args + |
| 815 | language_make_options, |
Craig Tiller | 590105a | 2016-01-19 13:03:46 -0800 | [diff] [blame] | 816 | shell=True, timeout_seconds=None) |
Craig Tiller | 6fd2384 | 2015-09-01 07:36:31 -0700 | [diff] [blame] | 817 | for target in targets] |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 818 | else: |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 819 | def make_jobspec(cfg, targets, makefile='Makefile'): |
murgatroid99 | 8ae409f | 2015-10-26 16:39:00 -0700 | [diff] [blame] | 820 | if targets: |
| 821 | return [jobset.JobSpec([os.getenv('MAKE', 'make'), |
| 822 | '-f', makefile, |
Craig Tiller | dd6f7ed | 2016-01-21 12:54:42 -0800 | [diff] [blame^] | 823 | '-j', '%d' % args.jobs, |
Craig Tiller | 71a8604 | 2016-01-15 14:59:58 -0800 | [diff] [blame] | 824 | 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % args.slowdown, |
| 825 | 'CONFIG=%s' % cfg] + |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 826 | language_make_options + |
Craig Tiller | 71a8604 | 2016-01-15 14:59:58 -0800 | [diff] [blame] | 827 | ([] if not args.travis else ['JENKINS_BUILD=1']) + |
| 828 | targets, |
Craig Tiller | 590105a | 2016-01-19 13:03:46 -0800 | [diff] [blame] | 829 | timeout_seconds=None)] |
murgatroid99 | 8ae409f | 2015-10-26 16:39:00 -0700 | [diff] [blame] | 830 | else: |
| 831 | return [] |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 832 | make_targets = {} |
| 833 | for l in languages: |
| 834 | makefile = l.makefile_name() |
| 835 | make_targets[makefile] = make_targets.get(makefile, set()).union( |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 836 | set(l.make_targets(args.regex))) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 837 | |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 838 | def build_step_environ(cfg): |
| 839 | environ = {'CONFIG': cfg} |
Jan Tattermusch | 68016a1 | 2015-12-16 15:31:33 -0800 | [diff] [blame] | 840 | msbuild_cfg = _WINDOWS_CONFIG.get(cfg) |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 841 | if msbuild_cfg: |
| 842 | environ['MSBUILD_CONFIG'] = msbuild_cfg |
| 843 | return environ |
| 844 | |
murgatroid99 | fddac96 | 2015-09-22 09:20:11 -0700 | [diff] [blame] | 845 | build_steps = list(set( |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 846 | jobset.JobSpec(cmdline, environ=build_step_environ(cfg), flake_retries=5) |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 847 | for cfg in build_configs |
| 848 | for l in languages |
| 849 | for cmdline in l.pre_build_steps())) |
Craig Tiller | bd4e378 | 2015-09-01 06:48:55 -0700 | [diff] [blame] | 850 | if make_targets: |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 851 | 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] | 852 | build_steps.extend(set(make_commands)) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 853 | build_steps.extend(set( |
Craig Tiller | 590105a | 2016-01-19 13:03:46 -0800 | [diff] [blame] | 854 | jobset.JobSpec(cmdline, environ=build_step_environ(cfg), timeout_seconds=None) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 855 | for cfg in build_configs |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 856 | for l in languages |
Craig Tiller | 533b1a2 | 2015-05-29 08:41:29 -0700 | [diff] [blame] | 857 | for cmdline in l.build_steps())) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 858 | |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 859 | post_tests_steps = list(set( |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 860 | jobset.JobSpec(cmdline, environ=build_step_environ(cfg)) |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 861 | for cfg in build_configs |
| 862 | for l in languages |
| 863 | for cmdline in l.post_tests_steps())) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 864 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 865 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 866 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 867 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 868 | class TestCache(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 869 | """Cache for running tests.""" |
| 870 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 871 | def __init__(self, use_cache_results): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 872 | self._last_successful_run = {} |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 873 | self._use_cache_results = use_cache_results |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 874 | self._last_save = time.time() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 875 | |
| 876 | def should_run(self, cmdline, bin_hash): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 877 | if cmdline not in self._last_successful_run: |
| 878 | return True |
| 879 | if self._last_successful_run[cmdline] != bin_hash: |
| 880 | return True |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 881 | if not self._use_cache_results: |
| 882 | return True |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 883 | return False |
| 884 | |
| 885 | def finished(self, cmdline, bin_hash): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 886 | self._last_successful_run[cmdline] = bin_hash |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 887 | if time.time() - self._last_save > 1: |
| 888 | self.save() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 889 | |
| 890 | def dump(self): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 891 | return [{'cmdline': k, 'hash': v} |
| 892 | for k, v in self._last_successful_run.iteritems()] |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 893 | |
| 894 | def parse(self, exdump): |
| 895 | self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump) |
| 896 | |
| 897 | def save(self): |
| 898 | with open('.run_tests_cache', 'w') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 899 | f.write(json.dumps(self.dump())) |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 900 | self._last_save = time.time() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 901 | |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 902 | def maybe_load(self): |
| 903 | if os.path.exists('.run_tests_cache'): |
| 904 | with open('.run_tests_cache') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 905 | self.parse(json.loads(f.read())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 906 | |
| 907 | |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 908 | def _start_port_server(port_server_port): |
| 909 | # check if a compatible port server is running |
| 910 | # if incompatible (version mismatch) ==> start a new one |
| 911 | # if not running ==> start a new one |
| 912 | # otherwise, leave it up |
| 913 | try: |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 914 | version = int(urllib2.urlopen( |
| 915 | 'http://localhost:%d/version_number' % port_server_port, |
| 916 | timeout=1).read()) |
| 917 | print 'detected port server running version %d' % version |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 918 | running = True |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 919 | except Exception as e: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 920 | print 'failed to detect port server: %s' % sys.exc_info()[0] |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 921 | print e.strerror |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 922 | running = False |
| 923 | if running: |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 924 | current_version = int(subprocess.check_output( |
Jan Tattermusch | 3bd0827 | 2015-11-04 19:24:37 -0800 | [diff] [blame] | 925 | [sys.executable, os.path.abspath('tools/run_tests/port_server.py'), |
| 926 | 'dump_version'])) |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 927 | print 'my port server is version %d' % current_version |
| 928 | running = (version >= current_version) |
| 929 | if not running: |
| 930 | print 'port_server version mismatch: killing the old one' |
| 931 | urllib2.urlopen('http://localhost:%d/quitquitquit' % port_server_port).read() |
| 932 | time.sleep(1) |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 933 | if not running: |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 934 | fd, logfile = tempfile.mkstemp() |
| 935 | os.close(fd) |
| 936 | print 'starting port_server, with log file %s' % logfile |
Jan Tattermusch | 3bd0827 | 2015-11-04 19:24:37 -0800 | [diff] [blame] | 937 | args = [sys.executable, os.path.abspath('tools/run_tests/port_server.py'), |
| 938 | '-p', '%d' % port_server_port, '-l', logfile] |
Craig Tiller | 367d41d | 2015-10-12 13:00:22 -0700 | [diff] [blame] | 939 | env = dict(os.environ) |
| 940 | env['BUILD_ID'] = 'pleaseDontKillMeJenkins' |
Nicolas "Pixel" Noble | f72d7b5 | 2015-12-03 03:07:43 +0100 | [diff] [blame] | 941 | if platform_string() == 'windows': |
Jan Tattermusch | 3bd0827 | 2015-11-04 19:24:37 -0800 | [diff] [blame] | 942 | # Working directory of port server needs to be outside of Jenkins |
| 943 | # workspace to prevent file lock issues. |
| 944 | tempdir = tempfile.mkdtemp() |
Craig Tiller | d2c3971 | 2015-10-12 11:08:49 -0700 | [diff] [blame] | 945 | port_server = subprocess.Popen( |
Craig Tiller | 367d41d | 2015-10-12 13:00:22 -0700 | [diff] [blame] | 946 | args, |
| 947 | env=env, |
Jan Tattermusch | 3bd0827 | 2015-11-04 19:24:37 -0800 | [diff] [blame] | 948 | cwd=tempdir, |
Craig Tiller | 367d41d | 2015-10-12 13:00:22 -0700 | [diff] [blame] | 949 | creationflags = 0x00000008, # detached process |
| 950 | close_fds=True) |
Craig Tiller | d2c3971 | 2015-10-12 11:08:49 -0700 | [diff] [blame] | 951 | else: |
| 952 | port_server = subprocess.Popen( |
| 953 | args, |
Craig Tiller | 367d41d | 2015-10-12 13:00:22 -0700 | [diff] [blame] | 954 | env=env, |
Craig Tiller | d2c3971 | 2015-10-12 11:08:49 -0700 | [diff] [blame] | 955 | preexec_fn=os.setsid, |
| 956 | close_fds=True) |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 957 | time.sleep(1) |
Craig Tiller | 8b5f4dc | 2015-08-26 08:02:01 -0700 | [diff] [blame] | 958 | # ensure port server is up |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 959 | waits = 0 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 960 | while True: |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 961 | if waits > 10: |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 962 | print 'killing port server due to excessive start up waits' |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 963 | port_server.kill() |
Craig Tiller | a2f38b0 | 2015-09-24 11:19:17 -0700 | [diff] [blame] | 964 | if port_server.poll() is not None: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 965 | print 'port_server failed to start' |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 966 | # try one final time: maybe another build managed to start one |
| 967 | time.sleep(1) |
| 968 | try: |
| 969 | urllib2.urlopen('http://localhost:%d/get' % port_server_port, |
| 970 | timeout=1).read() |
| 971 | print 'last ditch attempt to contact port server succeeded' |
| 972 | break |
| 973 | except: |
| 974 | traceback.print_exc(); |
| 975 | port_log = open(logfile, 'r').read() |
| 976 | print port_log |
| 977 | sys.exit(1) |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 978 | try: |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 979 | urllib2.urlopen('http://localhost:%d/get' % port_server_port, |
| 980 | timeout=1).read() |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 981 | print 'port server is up and ready' |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 982 | break |
Craig Tiller | 31fdaa4 | 2015-09-25 13:09:59 -0700 | [diff] [blame] | 983 | except socket.timeout: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 984 | print 'waiting for port_server: timeout' |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 985 | traceback.print_exc(); |
| 986 | time.sleep(1) |
Craig Tiller | 31fdaa4 | 2015-09-25 13:09:59 -0700 | [diff] [blame] | 987 | waits += 1 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 988 | except urllib2.URLError: |
Craig Tiller | 0d6499e | 2015-10-05 14:00:47 -0700 | [diff] [blame] | 989 | print 'waiting for port_server: urlerror' |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 990 | traceback.print_exc(); |
| 991 | time.sleep(1) |
Craig Tiller | abd37fd | 2015-08-26 07:54:01 -0700 | [diff] [blame] | 992 | waits += 1 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 993 | except: |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 994 | traceback.print_exc(); |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 995 | port_server.kill() |
| 996 | raise |
| 997 | |
| 998 | |
Adele Zhou | d5fffa5 | 2015-10-23 15:51:42 -0700 | [diff] [blame] | 999 | def _calculate_num_runs_failures(list_of_results): |
| 1000 | """Caculate number of runs and failures for a particular test. |
| 1001 | |
| 1002 | Args: |
| 1003 | list_of_results: (List) of JobResult object. |
| 1004 | Returns: |
| 1005 | A tuple of total number of runs and failures. |
| 1006 | """ |
| 1007 | num_runs = len(list_of_results) # By default, there is 1 run per JobResult. |
| 1008 | num_failures = 0 |
| 1009 | for jobresult in list_of_results: |
| 1010 | if jobresult.retries > 0: |
| 1011 | num_runs += jobresult.retries |
| 1012 | if jobresult.num_failures > 0: |
| 1013 | num_failures += jobresult.num_failures |
| 1014 | return num_runs, num_failures |
| 1015 | |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 1016 | |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1017 | # _build_and_run results |
| 1018 | class BuildAndRunError(object): |
| 1019 | |
| 1020 | BUILD = object() |
| 1021 | TEST = object() |
| 1022 | POST_TEST = object() |
| 1023 | |
| 1024 | |
| 1025 | # returns a list of things that failed (or an empty list on success) |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 1026 | def _build_and_run( |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 1027 | check_cancelled, newline_on_success, cache, xml_report=None, build_only=False): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1028 | """Do one pass of building & running tests.""" |
murgatroid99 | 666450e | 2015-01-26 13:03:31 -0800 | [diff] [blame] | 1029 | # build latest sequentially |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 1030 | num_failures, _ = jobset.run( |
| 1031 | build_steps, maxjobs=1, stop_on_failure=True, |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 1032 | newline_on_success=newline_on_success, travis=args.travis) |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 1033 | if num_failures: |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1034 | return [BuildAndRunError.BUILD] |
Craig Tiller | b361b4e | 2016-01-06 11:44:17 -0800 | [diff] [blame] | 1035 | |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 1036 | if build_only: |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1037 | return [] |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1038 | |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 1039 | # start antagonists |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 1040 | antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py']) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 1041 | for _ in range(0, args.antagonists)] |
Craig Tiller | fe4939f | 2015-10-06 12:55:36 -0700 | [diff] [blame] | 1042 | port_server_port = 32767 |
Craig Tiller | f53d9c8 | 2015-08-04 14:19:43 -0700 | [diff] [blame] | 1043 | _start_port_server(port_server_port) |
Adele Zhou | 7cf7211 | 2015-11-04 11:18:43 -0800 | [diff] [blame] | 1044 | resultset = None |
Adele Zhou | 803af15 | 2015-11-30 15:16:16 -0800 | [diff] [blame] | 1045 | num_test_failures = 0 |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 1046 | try: |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 1047 | infinite_runs = runs_per_test == 0 |
yang-g | 6c1fdc6 | 2015-08-18 11:57:42 -0700 | [diff] [blame] | 1048 | one_run = set( |
| 1049 | spec |
| 1050 | for config in run_configs |
| 1051 | for language in languages |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 1052 | for spec in language.test_specs(config, args) |
yang-g | 6c1fdc6 | 2015-08-18 11:57:42 -0700 | [diff] [blame] | 1053 | if re.search(args.regex, spec.shortname)) |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 1054 | # When running on travis, we want out test runs to be as similar as possible |
| 1055 | # for reproducibility purposes. |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 1056 | if args.travis: |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 1057 | massaged_one_run = sorted(one_run, key=lambda x: x.shortname) |
| 1058 | else: |
| 1059 | # whereas otherwise, we want to shuffle things up to give all tests a |
| 1060 | # chance to run. |
| 1061 | massaged_one_run = list(one_run) # random.shuffle needs an indexable seq. |
| 1062 | random.shuffle(massaged_one_run) # which it modifies in-place. |
Craig Tiller | f7b7c89 | 2015-06-22 14:33:25 -0700 | [diff] [blame] | 1063 | if infinite_runs: |
| 1064 | 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] | 1065 | runs_sequence = (itertools.repeat(massaged_one_run) if infinite_runs |
| 1066 | else itertools.repeat(massaged_one_run, runs_per_test)) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 1067 | all_runs = itertools.chain.from_iterable(runs_sequence) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 1068 | |
Adele Zhou | 803af15 | 2015-11-30 15:16:16 -0800 | [diff] [blame] | 1069 | num_test_failures, resultset = jobset.run( |
Adele Zhou | 2271ab5 | 2015-10-28 13:59:14 -0700 | [diff] [blame] | 1070 | all_runs, check_cancelled, newline_on_success=newline_on_success, |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 1071 | travis=args.travis, infinite_runs=infinite_runs, maxjobs=args.jobs, |
murgatroid99 | 8ae409f | 2015-10-26 16:39:00 -0700 | [diff] [blame] | 1072 | stop_on_failure=args.stop_on_failure, |
Adele Zhou | f2ca7bc | 2015-10-23 15:38:00 -0700 | [diff] [blame] | 1073 | cache=cache if not xml_report else None, |
Adele Zhou | f2ca7bc | 2015-10-23 15:38:00 -0700 | [diff] [blame] | 1074 | add_env={'GRPC_TEST_PORT_SERVER': 'localhost:%d' % port_server_port}) |
Adele Zhou | d5fffa5 | 2015-10-23 15:51:42 -0700 | [diff] [blame] | 1075 | if resultset: |
| 1076 | for k, v in resultset.iteritems(): |
| 1077 | num_runs, num_failures = _calculate_num_runs_failures(v) |
| 1078 | if num_failures == num_runs: # what about infinite_runs??? |
| 1079 | jobset.message('FAILED', k, do_newline=True) |
| 1080 | elif num_failures > 0: |
| 1081 | jobset.message( |
| 1082 | 'FLAKE', '%s [%d/%d runs flaked]' % (k, num_failures, num_runs), |
| 1083 | do_newline=True) |
| 1084 | else: |
| 1085 | jobset.message('PASSED', k, do_newline=True) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 1086 | finally: |
| 1087 | for antagonist in antagonists: |
| 1088 | antagonist.kill() |
Adele Zhou | 7cf7211 | 2015-11-04 11:18:43 -0800 | [diff] [blame] | 1089 | if xml_report and resultset: |
Adele Zhou | 3bc7ba4 | 2015-11-05 10:21:58 -0800 | [diff] [blame] | 1090 | report_utils.render_junit_xml_report(resultset, xml_report) |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 1091 | |
Adele Zhou | f2ca7bc | 2015-10-23 15:38:00 -0700 | [diff] [blame] | 1092 | number_failures, _ = jobset.run( |
| 1093 | post_tests_steps, maxjobs=1, stop_on_failure=True, |
Craig Tiller | 883064c | 2015-11-04 10:06:10 -0800 | [diff] [blame] | 1094 | newline_on_success=newline_on_success, travis=args.travis) |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1095 | |
| 1096 | out = [] |
| 1097 | if number_failures: |
| 1098 | out.append(BuildAndRunError.POST_TEST) |
| 1099 | if num_test_failures: |
| 1100 | out.append(BuildAndRunError.TEST) |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 1101 | |
Craig Tiller | 69cd237 | 2015-06-11 09:38:09 -0700 | [diff] [blame] | 1102 | if cache: cache.save() |
| 1103 | |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1104 | return out |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1105 | |
| 1106 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 1107 | test_cache = TestCache(runs_per_test == 1) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 1108 | test_cache.maybe_load() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 1109 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1110 | if forever: |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 1111 | success = True |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1112 | while True: |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 1113 | dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples']) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1114 | initial_time = dw.most_recent_change() |
| 1115 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 1116 | previous_success = success |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1117 | errors = _build_and_run(check_cancelled=have_files_changed, |
| 1118 | newline_on_success=False, |
| 1119 | cache=test_cache, |
| 1120 | build_only=args.build_only) == 0 |
| 1121 | if not previous_success and not errors: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 1122 | jobset.message('SUCCESS', |
| 1123 | 'All tests are now passing properly', |
| 1124 | do_newline=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 1125 | jobset.message('IDLE', 'No change detected') |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1126 | while not have_files_changed(): |
| 1127 | time.sleep(1) |
| 1128 | else: |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1129 | errors = _build_and_run(check_cancelled=lambda: False, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 1130 | newline_on_success=args.newline_on_success, |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 1131 | cache=test_cache, |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 1132 | xml_report=args.xml_report, |
| 1133 | build_only=args.build_only) |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1134 | if not errors: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 1135 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 1136 | else: |
| 1137 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1138 | exit_code = 0 |
| 1139 | if BuildAndRunError.BUILD in errors: |
| 1140 | exit_code |= 1 |
Craig Tiller | 4f2be36 | 2016-01-08 08:59:20 -0800 | [diff] [blame] | 1141 | if BuildAndRunError.TEST in errors and not args.travis: |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1142 | exit_code |= 2 |
Craig Tiller | 4f2be36 | 2016-01-08 08:59:20 -0800 | [diff] [blame] | 1143 | if BuildAndRunError.POST_TEST in errors: |
| 1144 | exit_code |= 4 |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1145 | sys.exit(exit_code) |