Tsuyoshi Ozawa | 4e0238d | 2016-09-20 05:56:10 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 2 | # Copyright 2015 gRPC authors. |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 3 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 7 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 9 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 15 | """Run tests in parallel.""" |
| 16 | |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 17 | from __future__ import print_function |
| 18 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 19 | import argparse |
Craig Tiller | 9279ac2 | 2016-01-20 17:05:23 -0800 | [diff] [blame] | 20 | import ast |
Masood Malekghassemi | 3b5b206 | 2016-06-02 20:27:20 -0700 | [diff] [blame] | 21 | import collections |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 22 | import glob |
| 23 | import itertools |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 24 | import json |
David Garcia Quintas | 0727c10 | 2017-02-21 10:48:35 -0800 | [diff] [blame] | 25 | import logging |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 26 | import multiprocessing |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 27 | import os |
Masood Malekghassemi | 3b5b206 | 2016-06-02 20:27:20 -0700 | [diff] [blame] | 28 | import os.path |
Craig Tiller | 38fb8de | 2016-07-13 08:23:32 -0700 | [diff] [blame] | 29 | import pipes |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 30 | import platform |
| 31 | import random |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 32 | import re |
Craig Tiller | 8287523 | 2015-09-25 13:57:34 -0700 | [diff] [blame] | 33 | import socket |
David Garcia Quintas | 79e389f | 2015-06-02 17:49:42 -0700 | [diff] [blame] | 34 | import subprocess |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 35 | import sys |
Craig Tiller | f0a293e | 2015-10-12 10:05:50 -0700 | [diff] [blame] | 36 | import tempfile |
| 37 | import traceback |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 38 | import time |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 39 | from six.moves import urllib |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 40 | import uuid |
Siddharth Shukla | d194f59 | 2017-03-11 19:12:43 +0100 | [diff] [blame] | 41 | import six |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 42 | |
Jan Tattermusch | 5c79a31 | 2016-12-20 11:02:50 +0100 | [diff] [blame] | 43 | import python_utils.jobset as jobset |
| 44 | import python_utils.report_utils as report_utils |
| 45 | import python_utils.watch_dirs as watch_dirs |
Craig Tiller | 7dc4ea6 | 2017-02-02 16:08:05 -0800 | [diff] [blame] | 46 | import python_utils.start_port_server as start_port_server |
Matt Kwong | 52ff986 | 2017-04-17 13:56:51 -0700 | [diff] [blame] | 47 | try: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 48 | from python_utils.upload_test_results import upload_results_to_bq |
Matt Kwong | 52ff986 | 2017-04-17 13:56:51 -0700 | [diff] [blame] | 49 | except (ImportError): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 50 | pass # It's ok to not import because this is only necessary to upload results to BQ. |
Craig Tiller | b361b4e | 2016-01-06 11:44:17 -0800 | [diff] [blame] | 51 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 52 | gcp_utils_dir = os.path.abspath( |
| 53 | os.path.join(os.path.dirname(__file__), '../gcp/utils')) |
David Garcia Quintas | faafa4d | 2017-06-06 14:52:17 -0700 | [diff] [blame] | 54 | sys.path.append(gcp_utils_dir) |
David Garcia Quintas | faafa4d | 2017-06-06 14:52:17 -0700 | [diff] [blame] | 55 | |
Jan Tattermusch | 3b5121b | 2016-02-22 17:41:05 -0800 | [diff] [blame] | 56 | _ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 57 | os.chdir(_ROOT) |
Craig Tiller | 2cc2b84 | 2015-02-27 11:38:31 -0800 | [diff] [blame] | 58 | |
Craig Tiller | 8f18ee6 | 2016-07-18 08:00:33 -0700 | [diff] [blame] | 59 | _FORCE_ENVIRON_FOR_WRAPPERS = { |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 60 | 'GRPC_VERBOSITY': 'DEBUG', |
Craig Tiller | 8f18ee6 | 2016-07-18 08:00:33 -0700 | [diff] [blame] | 61 | } |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 62 | |
Craig Tiller | 123f137 | 2016-06-15 15:06:14 -0700 | [diff] [blame] | 63 | _POLLING_STRATEGIES = { |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 64 | 'linux': ['epollex', 'epollsig', 'epoll1', 'poll', 'poll-cv'], |
| 65 | 'mac': ['poll'], |
Craig Tiller | 123f137 | 2016-06-15 15:06:14 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Craig Tiller | 9992bdb | 2017-09-06 15:00:31 -0700 | [diff] [blame] | 68 | BigQueryTestData = collections.namedtuple('BigQueryTestData', 'name flaky cpu') |
| 69 | |
| 70 | |
| 71 | def get_bqtest_data(limit=None): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 72 | import big_query_utils |
Craig Tiller | d16abf8 | 2017-06-07 08:58:55 -0700 | [diff] [blame] | 73 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 74 | bq = big_query_utils.create_big_query() |
| 75 | query = """ |
David Garcia Quintas | 4862359 | 2017-08-02 18:15:22 -0700 | [diff] [blame] | 76 | SELECT |
| 77 | filtered_test_name, |
Craig Tiller | 120d4fd | 2017-09-07 12:25:25 -0700 | [diff] [blame] | 78 | SUM(result != 'PASSED' AND result != 'SKIPPED') > 0 as flaky, |
Craig Tiller | f7617bb | 2017-09-13 09:47:28 -0700 | [diff] [blame] | 79 | MAX(cpu_measured) + 0.01 as cpu |
David Garcia Quintas | 4862359 | 2017-08-02 18:15:22 -0700 | [diff] [blame] | 80 | FROM ( |
| 81 | SELECT |
| 82 | REGEXP_REPLACE(test_name, r'/\d+', '') AS filtered_test_name, |
Craig Tiller | 9992bdb | 2017-09-06 15:00:31 -0700 | [diff] [blame] | 83 | result, cpu_measured |
David Garcia Quintas | 4862359 | 2017-08-02 18:15:22 -0700 | [diff] [blame] | 84 | FROM |
| 85 | [grpc-testing:jenkins_test_results.aggregate_results] |
| 86 | WHERE |
| 87 | timestamp >= DATE_ADD(CURRENT_DATE(), -1, "WEEK") |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 88 | AND platform = '""" + platform_string() + """' |
David Garcia Quintas | 4862359 | 2017-08-02 18:15:22 -0700 | [diff] [blame] | 89 | AND NOT REGEXP_MATCH(job_name, '.*portability.*') ) |
| 90 | GROUP BY |
Craig Tiller | f7617bb | 2017-09-13 09:47:28 -0700 | [diff] [blame] | 91 | filtered_test_name""" |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 92 | if limit: |
| 93 | query += " limit {}".format(limit) |
| 94 | query_job = big_query_utils.sync_query_job(bq, 'grpc-testing', query) |
| 95 | page = bq.jobs().getQueryResults( |
| 96 | pageToken=None, **query_job['jobReference']).execute(num_retries=3) |
| 97 | test_data = [ |
| 98 | BigQueryTestData(row['f'][0]['v'], row['f'][1]['v'] == 'true', |
| 99 | float(row['f'][2]['v'])) for row in page['rows'] |
| 100 | ] |
| 101 | return test_data |
David Garcia Quintas | faafa4d | 2017-06-06 14:52:17 -0700 | [diff] [blame] | 102 | |
| 103 | |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 104 | def platform_string(): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 105 | return jobset.platform_string() |
Craig Tiller | d50993d | 2015-08-05 08:04:36 -0700 | [diff] [blame] | 106 | |
| 107 | |
Craig Tiller | 38fb8de | 2016-07-13 08:23:32 -0700 | [diff] [blame] | 108 | _DEFAULT_TIMEOUT_SECONDS = 5 * 60 |
| 109 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 110 | |
David Garcia Quintas | 0392025 | 2017-02-15 12:51:21 -0800 | [diff] [blame] | 111 | def run_shell_command(cmd, env=None, cwd=None): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 112 | try: |
| 113 | subprocess.check_output(cmd, shell=True, env=env, cwd=cwd) |
| 114 | except subprocess.CalledProcessError as e: |
| 115 | logging.exception( |
| 116 | "Error while running command '%s'. Exit status %d. Output:\n%s", |
| 117 | e.cmd, e.returncode, e.output) |
| 118 | raise |
| 119 | |
Craig Tiller | 38fb8de | 2016-07-13 08:23:32 -0700 | [diff] [blame] | 120 | |
Alexander Polcyn | dbfcd45 | 2017-10-01 15:34:29 -0700 | [diff] [blame] | 121 | def max_parallel_tests_for_current_platform(): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 122 | # Too much test parallelization has only been seen to be a problem |
| 123 | # so far on windows. |
| 124 | if jobset.platform_string() == 'windows': |
| 125 | return 64 |
| 126 | return 1024 |
| 127 | |
Alexander Polcyn | dbfcd45 | 2017-10-01 15:34:29 -0700 | [diff] [blame] | 128 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 129 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
Craig Tiller | a0f8517 | 2016-01-20 15:56:06 -0800 | [diff] [blame] | 130 | class Config(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 131 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 132 | def __init__(self, |
| 133 | config, |
| 134 | environ=None, |
| 135 | timeout_multiplier=1, |
| 136 | tool_prefix=[], |
| 137 | iomgr_platform='native'): |
| 138 | if environ is None: |
| 139 | environ = {} |
| 140 | self.build_config = config |
| 141 | self.environ = environ |
| 142 | self.environ['CONFIG'] = config |
| 143 | self.tool_prefix = tool_prefix |
| 144 | self.timeout_multiplier = timeout_multiplier |
| 145 | self.iomgr_platform = iomgr_platform |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 146 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 147 | def job_spec(self, |
| 148 | cmdline, |
| 149 | timeout_seconds=_DEFAULT_TIMEOUT_SECONDS, |
| 150 | shortname=None, |
| 151 | environ={}, |
| 152 | cpu_cost=1.0, |
| 153 | flaky=False): |
| 154 | """Construct a jobset.JobSpec for a test under this config |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 155 | |
| 156 | Args: |
| 157 | cmdline: a list of strings specifying the command line the test |
| 158 | would like to run |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 159 | """ |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 160 | actual_environ = self.environ.copy() |
| 161 | for k, v in environ.items(): |
| 162 | actual_environ[k] = v |
| 163 | if not flaky and shortname and shortname in flaky_tests: |
| 164 | flaky = True |
| 165 | if shortname in shortname_to_cpu: |
| 166 | cpu_cost = shortname_to_cpu[shortname] |
| 167 | return jobset.JobSpec( |
| 168 | cmdline=self.tool_prefix + cmdline, |
| 169 | shortname=shortname, |
| 170 | environ=actual_environ, |
| 171 | cpu_cost=cpu_cost, |
| 172 | timeout_seconds=(self.timeout_multiplier * timeout_seconds |
| 173 | if timeout_seconds else None), |
| 174 | flake_retries=4 if flaky or args.allow_flakes else 0, |
| 175 | timeout_retries=1 if flaky or args.allow_flakes else 0) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 176 | |
| 177 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 178 | def get_c_tests(travis, test_lang): |
| 179 | out = [] |
| 180 | platforms_str = 'ci_platforms' if travis else 'platforms' |
| 181 | with open('tools/run_tests/generated/tests.json') as f: |
| 182 | js = json.load(f) |
| 183 | return [ |
| 184 | tgt for tgt in js |
| 185 | if tgt['language'] == test_lang and platform_string() in tgt[ |
| 186 | platforms_str] and not (travis and tgt['flaky']) |
| 187 | ] |
murgatroid99 | cf08daf | 2015-09-21 15:33:16 -0700 | [diff] [blame] | 188 | |
murgatroid99 | fafeeb3 | 2015-09-22 09:13:03 -0700 | [diff] [blame] | 189 | |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 190 | def _check_compiler(compiler, supported_compilers): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 191 | if compiler not in supported_compilers: |
| 192 | raise Exception('Compiler %s not supported (on this platform).' % |
| 193 | compiler) |
Jan Tattermusch | b2531e2 | 2016-03-25 16:14:41 -0700 | [diff] [blame] | 194 | |
| 195 | |
| 196 | def _check_arch(arch, supported_archs): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 197 | if arch not in supported_archs: |
| 198 | raise Exception('Architecture %s not supported.' % arch) |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 199 | |
| 200 | |
Jan Tattermusch | c4cbe39 | 2016-02-22 19:29:38 -0800 | [diff] [blame] | 201 | def _is_use_docker_child(): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 202 | """Returns True if running running as a --use_docker child.""" |
| 203 | return True if os.getenv('RUN_TESTS_COMMAND') else False |
Jan Tattermusch | c4cbe39 | 2016-02-22 19:29:38 -0800 | [diff] [blame] | 204 | |
| 205 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 206 | _PythonConfigVars = collections.namedtuple('_ConfigVars', [ |
| 207 | 'shell', 'builder', 'builder_prefix_arguments', 'venv_relative_python', |
| 208 | 'toolchain', 'runner' |
| 209 | ]) |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 210 | |
| 211 | |
| 212 | def _python_config_generator(name, major, minor, bits, config_vars): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 213 | return PythonConfig( |
| 214 | name, config_vars.shell + config_vars.builder + |
| 215 | config_vars.builder_prefix_arguments + [ |
| 216 | _python_pattern_function(major=major, minor=minor, bits=bits) |
| 217 | ] + [name] + config_vars.venv_relative_python + config_vars.toolchain, |
| 218 | config_vars.shell + config_vars.runner + |
| 219 | [os.path.join(name, config_vars.venv_relative_python[0])]) |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 220 | |
| 221 | |
| 222 | def _pypy_config_generator(name, major, config_vars): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 223 | return PythonConfig( |
| 224 | name, |
| 225 | config_vars.shell + config_vars.builder + |
| 226 | config_vars.builder_prefix_arguments + [ |
| 227 | _pypy_pattern_function(major=major) |
| 228 | ] + [name] + config_vars.venv_relative_python + config_vars.toolchain, |
| 229 | config_vars.shell + config_vars.runner + |
| 230 | [os.path.join(name, config_vars.venv_relative_python[0])]) |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 231 | |
| 232 | |
| 233 | def _python_pattern_function(major, minor, bits): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 234 | # Bit-ness is handled by the test machine's environment |
| 235 | if os.name == "nt": |
| 236 | if bits == "64": |
| 237 | return '/c/Python{major}{minor}/python.exe'.format( |
| 238 | major=major, minor=minor, bits=bits) |
| 239 | else: |
| 240 | return '/c/Python{major}{minor}_{bits}bits/python.exe'.format( |
| 241 | major=major, minor=minor, bits=bits) |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 242 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 243 | return 'python{major}.{minor}'.format(major=major, minor=minor) |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 244 | |
| 245 | |
| 246 | def _pypy_pattern_function(major): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 247 | if major == '2': |
| 248 | return 'pypy' |
| 249 | elif major == '3': |
| 250 | return 'pypy3' |
| 251 | else: |
| 252 | raise ValueError("Unknown PyPy major version") |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 253 | |
| 254 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 255 | class CLanguage(object): |
| 256 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 257 | def __init__(self, make_target, test_lang): |
| 258 | self.make_target = make_target |
| 259 | self.platform = platform_string() |
| 260 | self.test_lang = test_lang |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 261 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 262 | def configure(self, config, args): |
| 263 | self.config = config |
| 264 | self.args = args |
Craig Tiller | b38197e | 2016-02-26 10:14:54 -0800 | [diff] [blame] | 265 | if self.platform == 'windows': |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 266 | _check_compiler(self.args.compiler, [ |
| 267 | 'default', 'cmake', 'cmake_vs2015', 'cmake_vs2017' |
| 268 | ]) |
| 269 | _check_arch(self.args.arch, ['default', 'x64', 'x86']) |
| 270 | self._cmake_generator_option = 'Visual Studio 15 2017' if self.args.compiler == 'cmake_vs2017' else 'Visual Studio 14 2015' |
| 271 | self._cmake_arch_option = 'x64' if self.args.arch == 'x64' else 'Win32' |
| 272 | self._use_cmake = True |
| 273 | self._make_options = [] |
| 274 | elif self.args.compiler == 'cmake': |
| 275 | _check_arch(self.args.arch, ['default']) |
| 276 | self._use_cmake = True |
| 277 | self._docker_distro = 'jessie' |
| 278 | self._make_options = [] |
Craig Tiller | ca62ff0 | 2016-02-24 22:22:57 -0800 | [diff] [blame] | 279 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 280 | self._use_cmake = False |
| 281 | self._docker_distro, self._make_options = self._compiler_options( |
| 282 | self.args.use_docker, self.args.compiler) |
| 283 | if args.iomgr_platform == "uv": |
| 284 | cflags = '-DGRPC_UV -DGRPC_UV_THREAD_CHECK' |
| 285 | try: |
| 286 | cflags += subprocess.check_output( |
| 287 | ['pkg-config', '--cflags', 'libuv']).strip() + ' ' |
| 288 | except (subprocess.CalledProcessError, OSError): |
| 289 | pass |
| 290 | try: |
| 291 | ldflags = subprocess.check_output( |
| 292 | ['pkg-config', '--libs', 'libuv']).strip() + ' ' |
| 293 | except (subprocess.CalledProcessError, OSError): |
| 294 | ldflags = '-luv ' |
| 295 | self._make_options += [ |
| 296 | 'EXTRA_CPPFLAGS={}'.format(cflags), |
| 297 | 'EXTRA_LDLIBS={}'.format(ldflags) |
| 298 | ] |
ncteisen | d439b4e | 2017-09-11 17:57:18 -0700 | [diff] [blame] | 299 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 300 | def test_specs(self): |
| 301 | out = [] |
| 302 | binaries = get_c_tests(self.args.travis, self.test_lang) |
| 303 | for target in binaries: |
| 304 | if self._use_cmake and target.get('boringssl', False): |
| 305 | # cmake doesn't build boringssl tests |
| 306 | continue |
| 307 | auto_timeout_scaling = target.get('auto_timeout_scaling', True) |
| 308 | polling_strategies = ( |
| 309 | _POLLING_STRATEGIES.get(self.platform, ['all']) |
| 310 | if target.get('uses_polling', True) else ['none']) |
| 311 | if self.args.iomgr_platform == 'uv': |
| 312 | polling_strategies = ['all'] |
| 313 | for polling_strategy in polling_strategies: |
| 314 | env = { |
| 315 | 'GRPC_DEFAULT_SSL_ROOTS_FILE_PATH': |
| 316 | _ROOT + '/src/core/tsi/test_creds/ca.pem', |
| 317 | 'GRPC_POLL_STRATEGY': |
| 318 | polling_strategy, |
| 319 | 'GRPC_VERBOSITY': |
| 320 | 'DEBUG' |
| 321 | } |
| 322 | resolver = os.environ.get('GRPC_DNS_RESOLVER', None) |
| 323 | if resolver: |
| 324 | env['GRPC_DNS_RESOLVER'] = resolver |
| 325 | shortname_ext = '' if polling_strategy == 'all' else ' GRPC_POLL_STRATEGY=%s' % polling_strategy |
| 326 | if polling_strategy in target.get('excluded_poll_engines', []): |
| 327 | continue |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 328 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 329 | timeout_scaling = 1 |
| 330 | if auto_timeout_scaling: |
| 331 | config = self.args.config |
| 332 | if ('asan' in config or config == 'msan' or |
| 333 | config == 'tsan' or config == 'ubsan' or |
| 334 | config == 'helgrind' or config == 'memcheck'): |
| 335 | # Scale overall test timeout if running under various sanitizers. |
| 336 | # scaling value is based on historical data analysis |
| 337 | timeout_scaling *= 3 |
| 338 | elif polling_strategy == 'poll-cv': |
| 339 | # scale test timeout if running with poll-cv |
| 340 | # sanitizer and poll-cv scaling is not cumulative to ensure |
| 341 | # reasonable timeout values. |
| 342 | # TODO(jtattermusch): based on historical data and 5min default |
| 343 | # test timeout poll-cv scaling is currently not useful. |
| 344 | # Leaving here so it can be reintroduced if the default test timeout |
| 345 | # is decreased in the future. |
| 346 | timeout_scaling *= 1 |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 347 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 348 | if self.config.build_config in target['exclude_configs']: |
| 349 | continue |
| 350 | if self.args.iomgr_platform in target.get('exclude_iomgrs', []): |
| 351 | continue |
| 352 | if self.platform == 'windows': |
| 353 | binary = 'cmake/build/%s/%s.exe' % ( |
| 354 | _MSBUILD_CONFIG[self.config.build_config], |
| 355 | target['name']) |
| 356 | else: |
| 357 | if self._use_cmake: |
| 358 | binary = 'cmake/build/%s' % target['name'] |
| 359 | else: |
| 360 | binary = 'bins/%s/%s' % (self.config.build_config, |
| 361 | target['name']) |
| 362 | cpu_cost = target['cpu_cost'] |
| 363 | if cpu_cost == 'capacity': |
| 364 | cpu_cost = multiprocessing.cpu_count() |
| 365 | if os.path.isfile(binary): |
| 366 | list_test_command = None |
| 367 | filter_test_command = None |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 368 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 369 | # these are the flag defined by gtest and benchmark framework to list |
| 370 | # and filter test runs. We use them to split each individual test |
| 371 | # into its own JobSpec, and thus into its own process. |
| 372 | if 'benchmark' in target and target['benchmark']: |
| 373 | with open(os.devnull, 'w') as fnull: |
| 374 | tests = subprocess.check_output( |
| 375 | [binary, '--benchmark_list_tests'], |
| 376 | stderr=fnull) |
| 377 | for line in tests.split('\n'): |
| 378 | test = line.strip() |
| 379 | if not test: continue |
| 380 | cmdline = [binary, '--benchmark_filter=%s$' % test |
| 381 | ] + target['args'] |
| 382 | out.append( |
| 383 | self.config.job_spec( |
| 384 | cmdline, |
| 385 | shortname='%s %s' % (' '.join(cmdline), |
| 386 | shortname_ext), |
| 387 | cpu_cost=cpu_cost, |
| 388 | timeout_seconds=_DEFAULT_TIMEOUT_SECONDS * |
| 389 | timeout_scaling, |
| 390 | environ=env)) |
| 391 | elif 'gtest' in target and target['gtest']: |
| 392 | # here we parse the output of --gtest_list_tests to build up a complete |
| 393 | # list of the tests contained in a binary for each test, we then |
| 394 | # add a job to run, filtering for just that test. |
| 395 | with open(os.devnull, 'w') as fnull: |
| 396 | tests = subprocess.check_output( |
| 397 | [binary, '--gtest_list_tests'], stderr=fnull) |
| 398 | base = None |
| 399 | for line in tests.split('\n'): |
| 400 | i = line.find('#') |
| 401 | if i >= 0: line = line[:i] |
| 402 | if not line: continue |
| 403 | if line[0] != ' ': |
| 404 | base = line.strip() |
| 405 | else: |
| 406 | assert base is not None |
| 407 | assert line[1] == ' ' |
| 408 | test = base + line.strip() |
| 409 | cmdline = [binary, '--gtest_filter=%s' % test |
| 410 | ] + target['args'] |
| 411 | out.append( |
| 412 | self.config.job_spec( |
| 413 | cmdline, |
| 414 | shortname='%s %s' % (' '.join(cmdline), |
| 415 | shortname_ext), |
| 416 | cpu_cost=cpu_cost, |
| 417 | timeout_seconds=target.get( |
| 418 | 'timeout_seconds', |
| 419 | _DEFAULT_TIMEOUT_SECONDS) * |
| 420 | timeout_scaling, |
| 421 | environ=env)) |
| 422 | else: |
| 423 | cmdline = [binary] + target['args'] |
| 424 | shortname = target.get('shortname', ' '.join( |
| 425 | pipes.quote(arg) for arg in cmdline)) |
| 426 | shortname += shortname_ext |
| 427 | out.append( |
| 428 | self.config.job_spec( |
| 429 | cmdline, |
| 430 | shortname=shortname, |
| 431 | cpu_cost=cpu_cost, |
| 432 | flaky=target.get('flaky', False), |
| 433 | timeout_seconds=target.get( |
| 434 | 'timeout_seconds', _DEFAULT_TIMEOUT_SECONDS) |
| 435 | * timeout_scaling, |
| 436 | environ=env)) |
| 437 | elif self.args.regex == '.*' or self.platform == 'windows': |
| 438 | print('\nWARNING: binary not found, skipping', binary) |
| 439 | return sorted(out) |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 440 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 441 | def make_targets(self): |
| 442 | if self.platform == 'windows': |
| 443 | # don't build tools on windows just yet |
| 444 | return ['buildtests_%s' % self.make_target] |
| 445 | return [ |
| 446 | 'buildtests_%s' % self.make_target, 'tools_%s' % self.make_target, |
| 447 | 'check_epollexclusive' |
| 448 | ] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 449 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 450 | def make_options(self): |
| 451 | return self._make_options |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 452 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 453 | def pre_build_steps(self): |
| 454 | if self.platform == 'windows': |
| 455 | return [[ |
| 456 | 'tools\\run_tests\\helper_scripts\\pre_build_cmake.bat', |
| 457 | self._cmake_generator_option, self._cmake_arch_option |
| 458 | ]] |
| 459 | elif self._use_cmake: |
| 460 | return [['tools/run_tests/helper_scripts/pre_build_cmake.sh']] |
| 461 | else: |
| 462 | return [] |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 463 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 464 | def build_steps(self): |
| 465 | return [] |
Jan Tattermusch | d4726c1 | 2016-02-23 16:57:36 -0800 | [diff] [blame] | 466 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 467 | def post_tests_steps(self): |
| 468 | if self.platform == 'windows': |
| 469 | return [] |
| 470 | else: |
| 471 | return [['tools/run_tests/helper_scripts/post_tests_c.sh']] |
Jan Tattermusch | 9bb7062 | 2016-03-18 10:28:54 -0700 | [diff] [blame] | 472 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 473 | def makefile_name(self): |
| 474 | if self._use_cmake: |
| 475 | return 'cmake/build/Makefile' |
| 476 | else: |
| 477 | return 'Makefile' |
Jan Tattermusch | c4cbe39 | 2016-02-22 19:29:38 -0800 | [diff] [blame] | 478 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 479 | def _clang_make_options(self, version_suffix=''): |
| 480 | return [ |
| 481 | 'CC=clang%s' % version_suffix, 'CXX=clang++%s' % version_suffix, |
| 482 | 'LD=clang%s' % version_suffix, 'LDXX=clang++%s' % version_suffix |
| 483 | ] |
Jan Tattermusch | c4cbe39 | 2016-02-22 19:29:38 -0800 | [diff] [blame] | 484 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 485 | def _gcc_make_options(self, version_suffix): |
| 486 | return [ |
| 487 | 'CC=gcc%s' % version_suffix, 'CXX=g++%s' % version_suffix, |
| 488 | 'LD=gcc%s' % version_suffix, 'LDXX=g++%s' % version_suffix |
| 489 | ] |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 490 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 491 | def _compiler_options(self, use_docker, compiler): |
| 492 | """Returns docker distro and make options to use for given compiler.""" |
| 493 | if not use_docker and not _is_use_docker_child(): |
| 494 | _check_compiler(compiler, ['default']) |
| 495 | |
| 496 | if compiler == 'gcc4.9' or compiler == 'default': |
| 497 | return ('jessie', []) |
| 498 | elif compiler == 'gcc4.8': |
| 499 | return ('jessie', self._gcc_make_options(version_suffix='-4.8')) |
| 500 | elif compiler == 'gcc5.3': |
| 501 | return ('ubuntu1604', []) |
| 502 | elif compiler == 'gcc_musl': |
| 503 | return ('alpine', []) |
| 504 | elif compiler == 'clang3.4': |
| 505 | # on ubuntu1404, clang-3.4 alias doesn't exist, just use 'clang' |
| 506 | return ('ubuntu1404', self._clang_make_options()) |
| 507 | elif compiler == 'clang3.5': |
| 508 | return ('jessie', self._clang_make_options(version_suffix='-3.5')) |
| 509 | elif compiler == 'clang3.6': |
| 510 | return ('ubuntu1604', |
| 511 | self._clang_make_options(version_suffix='-3.6')) |
| 512 | elif compiler == 'clang3.7': |
| 513 | return ('ubuntu1604', |
| 514 | self._clang_make_options(version_suffix='-3.7')) |
| 515 | else: |
| 516 | raise Exception('Compiler %s not supported.' % compiler) |
| 517 | |
| 518 | def dockerfile_dir(self): |
| 519 | return 'tools/dockerfile/test/cxx_%s_%s' % ( |
| 520 | self._docker_distro, _docker_arch_suffix(self.args.arch)) |
| 521 | |
| 522 | def __str__(self): |
| 523 | return self.make_target |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 524 | |
Craig Tiller | cc0535d | 2015-12-08 15:14:47 -0800 | [diff] [blame] | 525 | |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 526 | # This tests Node on grpc/grpc-node and will become the standard for Node testing |
| 527 | class RemoteNodeLanguage(object): |
| 528 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 529 | def __init__(self): |
| 530 | self.platform = platform_string() |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 531 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 532 | def configure(self, config, args): |
| 533 | self.config = config |
| 534 | self.args = args |
| 535 | # Note: electron ABI only depends on major and minor version, so that's all |
| 536 | # we should specify in the compiler argument |
| 537 | _check_compiler(self.args.compiler, [ |
| 538 | 'default', 'node0.12', 'node4', 'node5', 'node6', 'node7', 'node8', |
| 539 | 'electron1.3', 'electron1.6' |
| 540 | ]) |
| 541 | if self.args.compiler == 'default': |
| 542 | self.runtime = 'node' |
| 543 | self.node_version = '8' |
| 544 | else: |
| 545 | if self.args.compiler.startswith('electron'): |
| 546 | self.runtime = 'electron' |
| 547 | self.node_version = self.args.compiler[8:] |
| 548 | else: |
| 549 | self.runtime = 'node' |
| 550 | # Take off the word "node" |
| 551 | self.node_version = self.args.compiler[4:] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 552 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 553 | # TODO: update with Windows/electron scripts when available for grpc/grpc-node |
| 554 | def test_specs(self): |
| 555 | if self.platform == 'windows': |
| 556 | return [ |
| 557 | self.config.job_spec( |
| 558 | ['tools\\run_tests\\helper_scripts\\run_node.bat']) |
| 559 | ] |
| 560 | else: |
| 561 | return [ |
| 562 | self.config.job_spec( |
| 563 | ['tools/run_tests/helper_scripts/run_grpc-node.sh'], |
| 564 | None, |
| 565 | environ=_FORCE_ENVIRON_FOR_WRAPPERS) |
| 566 | ] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 567 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 568 | def pre_build_steps(self): |
| 569 | return [] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 570 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 571 | def make_targets(self): |
| 572 | return [] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 573 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 574 | def make_options(self): |
| 575 | return [] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 576 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 577 | def build_steps(self): |
| 578 | return [] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 579 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 580 | def post_tests_steps(self): |
| 581 | return [] |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 582 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 583 | def makefile_name(self): |
| 584 | return 'Makefile' |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 585 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 586 | def dockerfile_dir(self): |
| 587 | return 'tools/dockerfile/test/node_jessie_%s' % _docker_arch_suffix( |
| 588 | self.args.arch) |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 589 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 590 | def __str__(self): |
| 591 | return 'grpc-node' |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 592 | |
| 593 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 594 | class PhpLanguage(object): |
| 595 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 596 | def configure(self, config, args): |
| 597 | self.config = config |
| 598 | self.args = args |
| 599 | _check_compiler(self.args.compiler, ['default']) |
| 600 | self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true'] |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 601 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 602 | def test_specs(self): |
| 603 | return [ |
| 604 | self.config.job_spec( |
| 605 | ['src/php/bin/run_tests.sh'], |
| 606 | environ=_FORCE_ENVIRON_FOR_WRAPPERS) |
| 607 | ] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 608 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 609 | def pre_build_steps(self): |
| 610 | return [] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 611 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 612 | def make_targets(self): |
| 613 | return ['static_c', 'shared_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 614 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 615 | def make_options(self): |
| 616 | return self._make_options |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 617 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 618 | def build_steps(self): |
| 619 | return [['tools/run_tests/helper_scripts/build_php.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 620 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 621 | def post_tests_steps(self): |
| 622 | return [['tools/run_tests/helper_scripts/post_tests_php.sh']] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 623 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 624 | def makefile_name(self): |
| 625 | return 'Makefile' |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 626 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 627 | def dockerfile_dir(self): |
| 628 | return 'tools/dockerfile/test/php_jessie_%s' % _docker_arch_suffix( |
| 629 | self.args.arch) |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 630 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 631 | def __str__(self): |
| 632 | return 'php' |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 633 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 634 | |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 635 | class Php7Language(object): |
| 636 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 637 | def configure(self, config, args): |
| 638 | self.config = config |
| 639 | self.args = args |
| 640 | _check_compiler(self.args.compiler, ['default']) |
| 641 | self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true'] |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 642 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 643 | def test_specs(self): |
| 644 | return [ |
| 645 | self.config.job_spec( |
| 646 | ['src/php/bin/run_tests.sh'], |
| 647 | environ=_FORCE_ENVIRON_FOR_WRAPPERS) |
| 648 | ] |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 649 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 650 | def pre_build_steps(self): |
| 651 | return [] |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 652 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 653 | def make_targets(self): |
| 654 | return ['static_c', 'shared_c'] |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 655 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 656 | def make_options(self): |
| 657 | return self._make_options |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 658 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 659 | def build_steps(self): |
| 660 | return [['tools/run_tests/helper_scripts/build_php.sh']] |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 661 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 662 | def post_tests_steps(self): |
| 663 | return [['tools/run_tests/helper_scripts/post_tests_php.sh']] |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 664 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 665 | def makefile_name(self): |
| 666 | return 'Makefile' |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 667 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 668 | def dockerfile_dir(self): |
| 669 | return 'tools/dockerfile/test/php7_jessie_%s' % _docker_arch_suffix( |
| 670 | self.args.arch) |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 671 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 672 | def __str__(self): |
| 673 | return 'php7' |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 674 | |
| 675 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 676 | class PythonConfig( |
| 677 | collections.namedtuple('PythonConfig', ['name', 'build', 'run'])): |
| 678 | """Tuple of commands (named s.t. 'what it says on the tin' applies)""" |
| 679 | |
Masood Malekghassemi | 3b5b206 | 2016-06-02 20:27:20 -0700 | [diff] [blame] | 680 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 681 | class PythonLanguage(object): |
| 682 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 683 | def configure(self, config, args): |
| 684 | self.config = config |
| 685 | self.args = args |
| 686 | self.pythons = self._get_pythons(self.args) |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 687 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 688 | def test_specs(self): |
| 689 | # load list of known test suites |
| 690 | with open( |
| 691 | 'src/python/grpcio_tests/tests/tests.json') as tests_json_file: |
| 692 | tests_json = json.load(tests_json_file) |
| 693 | environment = dict(_FORCE_ENVIRON_FOR_WRAPPERS) |
| 694 | return [ |
| 695 | self.config.job_spec( |
| 696 | config.run, |
| 697 | timeout_seconds=5 * 60, |
| 698 | environ=dict( |
| 699 | list(environment.items()) + [( |
| 700 | 'GRPC_PYTHON_TESTRUNNER_FILTER', str(suite_name))]), |
| 701 | shortname='%s.test.%s' % (config.name, suite_name),) |
| 702 | for suite_name in tests_json for config in self.pythons |
| 703 | ] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 704 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 705 | def pre_build_steps(self): |
| 706 | return [] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 707 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 708 | def make_targets(self): |
| 709 | return [] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 710 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 711 | def make_options(self): |
| 712 | return [] |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 713 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 714 | def build_steps(self): |
| 715 | return [config.build for config in self.pythons] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 716 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 717 | def post_tests_steps(self): |
| 718 | if self.config.build_config != 'gcov': |
| 719 | return [] |
| 720 | else: |
| 721 | return [['tools/run_tests/helper_scripts/post_tests_python.sh']] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 722 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 723 | def makefile_name(self): |
| 724 | return 'Makefile' |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 725 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 726 | def dockerfile_dir(self): |
| 727 | return 'tools/dockerfile/test/python_%s_%s' % ( |
| 728 | self.python_manager_name(), _docker_arch_suffix(self.args.arch)) |
siddharthshukla | c478214 | 2016-06-28 18:48:47 +0200 | [diff] [blame] | 729 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 730 | def python_manager_name(self): |
| 731 | if self.args.compiler in ['python3.5', 'python3.6']: |
| 732 | return 'pyenv' |
| 733 | elif self.args.compiler == 'python_alpine': |
| 734 | return 'alpine' |
| 735 | else: |
| 736 | return 'jessie' |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 737 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 738 | def _get_pythons(self, args): |
| 739 | if args.arch == 'x86': |
| 740 | bits = '32' |
| 741 | else: |
| 742 | bits = '64' |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 743 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 744 | if os.name == 'nt': |
| 745 | shell = ['bash'] |
| 746 | builder = [ |
| 747 | os.path.abspath( |
| 748 | 'tools/run_tests/helper_scripts/build_python_msys2.sh') |
| 749 | ] |
| 750 | builder_prefix_arguments = ['MINGW{}'.format(bits)] |
| 751 | venv_relative_python = ['Scripts/python.exe'] |
| 752 | toolchain = ['mingw32'] |
| 753 | else: |
| 754 | shell = [] |
| 755 | builder = [ |
| 756 | os.path.abspath( |
| 757 | 'tools/run_tests/helper_scripts/build_python.sh') |
| 758 | ] |
| 759 | builder_prefix_arguments = [] |
| 760 | venv_relative_python = ['bin/python'] |
| 761 | toolchain = ['unix'] |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 762 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 763 | runner = [ |
| 764 | os.path.abspath('tools/run_tests/helper_scripts/run_python.sh') |
| 765 | ] |
| 766 | config_vars = _PythonConfigVars(shell, builder, |
| 767 | builder_prefix_arguments, |
| 768 | venv_relative_python, toolchain, runner) |
| 769 | python27_config = _python_config_generator( |
| 770 | name='py27', |
| 771 | major='2', |
| 772 | minor='7', |
| 773 | bits=bits, |
| 774 | config_vars=config_vars) |
| 775 | python34_config = _python_config_generator( |
| 776 | name='py34', |
| 777 | major='3', |
| 778 | minor='4', |
| 779 | bits=bits, |
| 780 | config_vars=config_vars) |
| 781 | python35_config = _python_config_generator( |
| 782 | name='py35', |
| 783 | major='3', |
| 784 | minor='5', |
| 785 | bits=bits, |
| 786 | config_vars=config_vars) |
| 787 | python36_config = _python_config_generator( |
| 788 | name='py36', |
| 789 | major='3', |
| 790 | minor='6', |
| 791 | bits=bits, |
| 792 | config_vars=config_vars) |
| 793 | pypy27_config = _pypy_config_generator( |
| 794 | name='pypy', major='2', config_vars=config_vars) |
| 795 | pypy32_config = _pypy_config_generator( |
| 796 | name='pypy3', major='3', config_vars=config_vars) |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 797 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 798 | if args.compiler == 'default': |
| 799 | if os.name == 'nt': |
| 800 | return (python35_config,) |
| 801 | else: |
| 802 | return (python27_config, python34_config,) |
| 803 | elif args.compiler == 'python2.7': |
| 804 | return (python27_config,) |
| 805 | elif args.compiler == 'python3.4': |
| 806 | return (python34_config,) |
| 807 | elif args.compiler == 'python3.5': |
| 808 | return (python35_config,) |
| 809 | elif args.compiler == 'python3.6': |
| 810 | return (python36_config,) |
| 811 | elif args.compiler == 'pypy': |
| 812 | return (pypy27_config,) |
| 813 | elif args.compiler == 'pypy3': |
| 814 | return (pypy32_config,) |
| 815 | elif args.compiler == 'python_alpine': |
| 816 | return (python27_config,) |
| 817 | elif args.compiler == 'all_the_cpythons': |
| 818 | return (python27_config, python34_config, python35_config, |
| 819 | python36_config,) |
| 820 | else: |
| 821 | raise Exception('Compiler %s not supported.' % args.compiler) |
Jan Tattermusch | 825471c | 2016-04-25 16:52:25 -0700 | [diff] [blame] | 822 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 823 | def __str__(self): |
| 824 | return 'python' |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 825 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 826 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 827 | class RubyLanguage(object): |
| 828 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 829 | def configure(self, config, args): |
| 830 | self.config = config |
| 831 | self.args = args |
| 832 | _check_compiler(self.args.compiler, ['default']) |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 833 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 834 | def test_specs(self): |
| 835 | tests = [ |
| 836 | self.config.job_spec( |
| 837 | ['tools/run_tests/helper_scripts/run_ruby.sh'], |
| 838 | timeout_seconds=10 * 60, |
| 839 | environ=_FORCE_ENVIRON_FOR_WRAPPERS) |
| 840 | ] |
| 841 | tests.append( |
| 842 | self.config.job_spec( |
| 843 | ['tools/run_tests/helper_scripts/run_ruby_end2end_tests.sh'], |
| 844 | timeout_seconds=10 * 60, |
| 845 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)) |
| 846 | return tests |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 847 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 848 | def pre_build_steps(self): |
| 849 | return [['tools/run_tests/helper_scripts/pre_build_ruby.sh']] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 850 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 851 | def make_targets(self): |
| 852 | return [] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 853 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 854 | def make_options(self): |
| 855 | return [] |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 856 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 857 | def build_steps(self): |
| 858 | return [['tools/run_tests/helper_scripts/build_ruby.sh']] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 859 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 860 | def post_tests_steps(self): |
| 861 | return [['tools/run_tests/helper_scripts/post_tests_ruby.sh']] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 862 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 863 | def makefile_name(self): |
| 864 | return 'Makefile' |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 865 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 866 | def dockerfile_dir(self): |
| 867 | return 'tools/dockerfile/test/ruby_jessie_%s' % _docker_arch_suffix( |
| 868 | self.args.arch) |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 869 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 870 | def __str__(self): |
| 871 | return 'ruby' |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 872 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 873 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 874 | class CSharpLanguage(object): |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 875 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 876 | def __init__(self): |
| 877 | self.platform = platform_string() |
Jan Tattermusch | b00aa67 | 2015-06-01 15:48:03 -0700 | [diff] [blame] | 878 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 879 | def configure(self, config, args): |
| 880 | self.config = config |
| 881 | self.args = args |
| 882 | if self.platform == 'windows': |
| 883 | _check_compiler(self.args.compiler, ['coreclr', 'default']) |
| 884 | _check_arch(self.args.arch, ['default']) |
| 885 | self._cmake_arch_option = 'x64' |
| 886 | self._make_options = [] |
| 887 | else: |
| 888 | _check_compiler(self.args.compiler, ['default', 'coreclr']) |
| 889 | self._docker_distro = 'jessie' |
Jan Tattermusch | 76511a5 | 2016-06-17 14:00:57 -0700 | [diff] [blame] | 890 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 891 | if self.platform == 'mac': |
| 892 | # TODO(jtattermusch): EMBED_ZLIB=true currently breaks the mac build |
| 893 | self._make_options = ['EMBED_OPENSSL=true'] |
| 894 | if self.args.compiler != 'coreclr': |
| 895 | # On Mac, official distribution of mono is 32bit. |
| 896 | self._make_options += ['ARCH_FLAGS=-m32', 'LDFLAGS=-m32'] |
| 897 | else: |
| 898 | self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true'] |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 899 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 900 | def test_specs(self): |
| 901 | with open('src/csharp/tests.json') as f: |
| 902 | tests_by_assembly = json.load(f) |
Jan Tattermusch | 03c0106 | 2015-12-11 14:28:56 -0800 | [diff] [blame] | 903 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 904 | msbuild_config = _MSBUILD_CONFIG[self.config.build_config] |
| 905 | nunit_args = ['--labels=All', '--noresult', '--workers=1'] |
| 906 | assembly_subdir = 'bin/%s' % msbuild_config |
| 907 | assembly_extension = '.exe' |
Jan Tattermusch | 76511a5 | 2016-06-17 14:00:57 -0700 | [diff] [blame] | 908 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 909 | if self.args.compiler == 'coreclr': |
| 910 | assembly_subdir += '/netcoreapp1.0' |
| 911 | runtime_cmd = ['dotnet', 'exec'] |
| 912 | assembly_extension = '.dll' |
| 913 | else: |
| 914 | assembly_subdir += '/net45' |
| 915 | if self.platform == 'windows': |
| 916 | runtime_cmd = [] |
| 917 | else: |
| 918 | runtime_cmd = ['mono'] |
Jan Tattermusch | bf3b153 | 2015-10-26 10:24:42 -0700 | [diff] [blame] | 919 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 920 | specs = [] |
| 921 | for assembly in six.iterkeys(tests_by_assembly): |
| 922 | assembly_file = 'src/csharp/%s/%s/%s%s' % ( |
| 923 | assembly, assembly_subdir, assembly, assembly_extension) |
| 924 | if self.config.build_config != 'gcov' or self.platform != 'windows': |
| 925 | # normally, run each test as a separate process |
| 926 | for test in tests_by_assembly[assembly]: |
| 927 | cmdline = runtime_cmd + [assembly_file, '--test=%s' % test |
| 928 | ] + nunit_args |
| 929 | specs.append( |
| 930 | self.config.job_spec( |
| 931 | cmdline, |
| 932 | shortname='csharp.%s' % test, |
| 933 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)) |
| 934 | else: |
| 935 | # For C# test coverage, run all tests from the same assembly at once |
| 936 | # using OpenCover.Console (only works on Windows). |
| 937 | cmdline = [ |
| 938 | 'src\\csharp\\packages\\OpenCover.4.6.519\\tools\\OpenCover.Console.exe', |
| 939 | '-target:%s' % assembly_file, '-targetdir:src\\csharp', |
| 940 | '-targetargs:%s' % ' '.join(nunit_args), |
| 941 | '-filter:+[Grpc.Core]*', '-register:user', |
| 942 | '-output:src\\csharp\\coverage_csharp_%s.xml' % assembly |
| 943 | ] |
Jan Tattermusch | 38ed2cf | 2016-04-09 16:24:16 -0700 | [diff] [blame] | 944 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 945 | # set really high cpu_cost to make sure instances of OpenCover.Console run exclusively |
| 946 | # to prevent problems with registering the profiler. |
| 947 | run_exclusive = 1000000 |
| 948 | specs.append( |
| 949 | self.config.job_spec( |
| 950 | cmdline, |
| 951 | shortname='csharp.coverage.%s' % assembly, |
| 952 | cpu_cost=run_exclusive, |
| 953 | environ=_FORCE_ENVIRON_FOR_WRAPPERS)) |
| 954 | return specs |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 955 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 956 | def pre_build_steps(self): |
| 957 | if self.platform == 'windows': |
| 958 | return [[ |
| 959 | 'tools\\run_tests\\helper_scripts\\pre_build_csharp.bat', |
| 960 | self._cmake_arch_option |
| 961 | ]] |
| 962 | else: |
| 963 | return [['tools/run_tests/helper_scripts/pre_build_csharp.sh']] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 964 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 965 | def make_targets(self): |
| 966 | return ['grpc_csharp_ext'] |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 967 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 968 | def make_options(self): |
| 969 | return self._make_options |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 970 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 971 | def build_steps(self): |
| 972 | if self.platform == 'windows': |
| 973 | return [['tools\\run_tests\\helper_scripts\\build_csharp.bat']] |
| 974 | else: |
| 975 | return [['tools/run_tests/helper_scripts/build_csharp.sh']] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 976 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 977 | def post_tests_steps(self): |
| 978 | if self.platform == 'windows': |
| 979 | return [['tools\\run_tests\\helper_scripts\\post_tests_csharp.bat']] |
| 980 | else: |
| 981 | return [['tools/run_tests/helper_scripts/post_tests_csharp.sh']] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 982 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 983 | def makefile_name(self): |
| 984 | if self.platform == 'windows': |
| 985 | return 'cmake/build/%s/Makefile' % self._cmake_arch_option |
| 986 | else: |
| 987 | return 'Makefile' |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 988 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 989 | def dockerfile_dir(self): |
| 990 | return 'tools/dockerfile/test/csharp_%s_%s' % ( |
| 991 | self._docker_distro, _docker_arch_suffix(self.args.arch)) |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 992 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 993 | def __str__(self): |
| 994 | return 'csharp' |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 995 | |
Craig Tiller | d625d81 | 2015-04-08 15:52:35 -0700 | [diff] [blame] | 996 | |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 997 | class ObjCLanguage(object): |
| 998 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 999 | def configure(self, config, args): |
| 1000 | self.config = config |
| 1001 | self.args = args |
| 1002 | _check_compiler(self.args.compiler, ['default']) |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 1003 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1004 | def test_specs(self): |
| 1005 | return [ |
| 1006 | self.config.job_spec( |
| 1007 | ['src/objective-c/tests/run_tests.sh'], |
| 1008 | timeout_seconds=60 * 60, |
| 1009 | shortname='objc-tests', |
| 1010 | cpu_cost=1e6, |
| 1011 | environ=_FORCE_ENVIRON_FOR_WRAPPERS), |
| 1012 | self.config.job_spec( |
| 1013 | ['src/objective-c/tests/run_plugin_tests.sh'], |
| 1014 | timeout_seconds=60 * 60, |
| 1015 | shortname='objc-plugin-tests', |
| 1016 | cpu_cost=1e6, |
| 1017 | environ=_FORCE_ENVIRON_FOR_WRAPPERS), |
| 1018 | self.config.job_spec( |
| 1019 | ['src/objective-c/tests/build_one_example.sh'], |
| 1020 | timeout_seconds=10 * 60, |
| 1021 | shortname='objc-build-example-helloworld', |
| 1022 | cpu_cost=1e6, |
| 1023 | environ={ |
| 1024 | 'SCHEME': 'HelloWorld', |
| 1025 | 'EXAMPLE_PATH': 'examples/objective-c/helloworld' |
| 1026 | }), |
| 1027 | self.config.job_spec( |
| 1028 | ['src/objective-c/tests/build_one_example.sh'], |
| 1029 | timeout_seconds=10 * 60, |
| 1030 | shortname='objc-build-example-routeguide', |
| 1031 | cpu_cost=1e6, |
| 1032 | environ={ |
| 1033 | 'SCHEME': 'RouteGuideClient', |
| 1034 | 'EXAMPLE_PATH': 'examples/objective-c/route_guide' |
| 1035 | }), |
| 1036 | self.config.job_spec( |
| 1037 | ['src/objective-c/tests/build_one_example.sh'], |
| 1038 | timeout_seconds=10 * 60, |
| 1039 | shortname='objc-build-example-authsample', |
| 1040 | cpu_cost=1e6, |
| 1041 | environ={ |
| 1042 | 'SCHEME': 'AuthSample', |
| 1043 | 'EXAMPLE_PATH': 'examples/objective-c/auth_sample' |
| 1044 | }), |
| 1045 | self.config.job_spec( |
| 1046 | ['src/objective-c/tests/build_one_example.sh'], |
| 1047 | timeout_seconds=10 * 60, |
| 1048 | shortname='objc-build-example-sample', |
| 1049 | cpu_cost=1e6, |
| 1050 | environ={ |
| 1051 | 'SCHEME': 'Sample', |
| 1052 | 'EXAMPLE_PATH': 'src/objective-c/examples/Sample' |
| 1053 | }), |
| 1054 | self.config.job_spec( |
| 1055 | ['src/objective-c/tests/build_one_example.sh'], |
| 1056 | timeout_seconds=10 * 60, |
| 1057 | shortname='objc-build-example-sample-frameworks', |
| 1058 | cpu_cost=1e6, |
| 1059 | environ={ |
| 1060 | 'SCHEME': 'Sample', |
| 1061 | 'EXAMPLE_PATH': 'src/objective-c/examples/Sample', |
| 1062 | 'FRAMEWORKS': 'YES' |
| 1063 | }), |
| 1064 | self.config.job_spec( |
| 1065 | ['src/objective-c/tests/build_one_example.sh'], |
| 1066 | timeout_seconds=10 * 60, |
| 1067 | shortname='objc-build-example-switftsample', |
| 1068 | cpu_cost=1e6, |
| 1069 | environ={ |
| 1070 | 'SCHEME': 'SwiftSample', |
| 1071 | 'EXAMPLE_PATH': 'src/objective-c/examples/SwiftSample' |
| 1072 | }), |
| 1073 | ] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 1074 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1075 | def pre_build_steps(self): |
| 1076 | return [] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 1077 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1078 | def make_targets(self): |
| 1079 | return ['interop_server'] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 1080 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1081 | def make_options(self): |
| 1082 | return [] |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 1083 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1084 | def build_steps(self): |
| 1085 | return [['src/objective-c/tests/build_tests.sh']] |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 1086 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1087 | def post_tests_steps(self): |
| 1088 | return [] |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 1089 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1090 | def makefile_name(self): |
| 1091 | return 'Makefile' |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 1092 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1093 | def dockerfile_dir(self): |
| 1094 | return None |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 1095 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1096 | def __str__(self): |
| 1097 | return 'objc' |
Jorge Canizales | a0b3bfa | 2015-07-30 19:25:52 -0700 | [diff] [blame] | 1098 | |
| 1099 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 1100 | class Sanity(object): |
| 1101 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1102 | def configure(self, config, args): |
| 1103 | self.config = config |
| 1104 | self.args = args |
| 1105 | _check_compiler(self.args.compiler, ['default']) |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 1106 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1107 | def test_specs(self): |
| 1108 | import yaml |
| 1109 | with open('tools/run_tests/sanity/sanity_tests.yaml', 'r') as f: |
| 1110 | environ = {'TEST': 'true'} |
| 1111 | if _is_use_docker_child(): |
| 1112 | environ['CLANG_FORMAT_SKIP_DOCKER'] = 'true' |
| 1113 | return [ |
| 1114 | self.config.job_spec( |
| 1115 | cmd['script'].split(), |
| 1116 | timeout_seconds=30 * 60, |
| 1117 | environ=environ, |
| 1118 | cpu_cost=cmd.get('cpu_cost', 1)) for cmd in yaml.load(f) |
| 1119 | ] |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 1120 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1121 | def pre_build_steps(self): |
| 1122 | return [] |
murgatroid99 | 256d3df | 2015-09-21 16:58:02 -0700 | [diff] [blame] | 1123 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1124 | def make_targets(self): |
| 1125 | return ['run_dep_checks'] |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 1126 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1127 | def make_options(self): |
| 1128 | return [] |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 1129 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1130 | def build_steps(self): |
| 1131 | return [] |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 1132 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1133 | def post_tests_steps(self): |
| 1134 | return [] |
Nicolas "Pixel" Noble | 87879b3 | 2015-10-12 23:28:53 +0200 | [diff] [blame] | 1135 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1136 | def makefile_name(self): |
| 1137 | return 'Makefile' |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 1138 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1139 | def dockerfile_dir(self): |
| 1140 | return 'tools/dockerfile/test/sanity' |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 1141 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1142 | def __str__(self): |
| 1143 | return 'sanity' |
| 1144 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 1145 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 1146 | # different configurations we can run under |
Jan Tattermusch | 5c79a31 | 2016-12-20 11:02:50 +0100 | [diff] [blame] | 1147 | with open('tools/run_tests/generated/configs.json') as f: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1148 | _CONFIGS = dict((cfg['config'], Config(**cfg)) |
| 1149 | for cfg in ast.literal_eval(f.read())) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 1150 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 1151 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 1152 | 'c++': CLanguage('cxx', 'c++'), |
| 1153 | 'c': CLanguage('c', 'c'), |
Matt Kwong | e2e7cf4 | 2017-09-15 11:17:04 -0700 | [diff] [blame] | 1154 | 'grpc-node': RemoteNodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 1155 | 'php': PhpLanguage(), |
Stanley Cheung | 2e2cdff | 2016-07-23 19:07:36 -0700 | [diff] [blame] | 1156 | 'php7': Php7Language(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 1157 | 'python': PythonLanguage(), |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 1158 | 'ruby': RubyLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame] | 1159 | 'csharp': CSharpLanguage(), |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1160 | 'objc': ObjCLanguage(), |
Jan Tattermusch | 70a57e4 | 2016-02-20 18:50:27 -0800 | [diff] [blame] | 1161 | 'sanity': Sanity() |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1162 | } |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 1163 | |
Jan Tattermusch | a2d964c | 2016-02-22 17:33:09 -0800 | [diff] [blame] | 1164 | _MSBUILD_CONFIG = { |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 1165 | 'dbg': 'Debug', |
| 1166 | 'opt': 'Release', |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 1167 | 'gcov': 'Debug', |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1168 | } |
Craig Tiller | 7bb3efd | 2015-09-01 08:04:03 -0700 | [diff] [blame] | 1169 | |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 1170 | |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 1171 | def _windows_arch_option(arch): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1172 | """Returns msbuild cmdline option for selected architecture.""" |
| 1173 | if arch == 'default' or arch == 'x86': |
| 1174 | return '/p:Platform=Win32' |
| 1175 | elif arch == 'x64': |
| 1176 | return '/p:Platform=x64' |
| 1177 | else: |
| 1178 | print('Architecture %s not supported.' % arch) |
| 1179 | sys.exit(1) |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 1180 | |
Jan Tattermusch | f08018a | 2016-01-26 08:22:09 -0800 | [diff] [blame] | 1181 | |
| 1182 | def _check_arch_option(arch): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1183 | """Checks that architecture option is valid.""" |
| 1184 | if platform_string() == 'windows': |
| 1185 | _windows_arch_option(arch) |
| 1186 | elif platform_string() == 'linux': |
| 1187 | # On linux, we need to be running under docker with the right architecture. |
| 1188 | runtime_arch = platform.architecture()[0] |
| 1189 | if arch == 'default': |
| 1190 | return |
| 1191 | elif runtime_arch == '64bit' and arch == 'x64': |
| 1192 | return |
| 1193 | elif runtime_arch == '32bit' and arch == 'x86': |
| 1194 | return |
| 1195 | else: |
| 1196 | print('Architecture %s does not match current runtime architecture.' |
| 1197 | % arch) |
| 1198 | sys.exit(1) |
Jan Tattermusch | f08018a | 2016-01-26 08:22:09 -0800 | [diff] [blame] | 1199 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1200 | if args.arch != 'default': |
| 1201 | print('Architecture %s not supported on current platform.' % |
| 1202 | args.arch) |
| 1203 | sys.exit(1) |
Jan Tattermusch | 2dd156e | 2015-12-04 18:26:17 -0800 | [diff] [blame] | 1204 | |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 1205 | |
Jan Tattermusch | e70b3c5 | 2016-02-07 20:21:02 -0800 | [diff] [blame] | 1206 | def _docker_arch_suffix(arch): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1207 | """Returns suffix to dockerfile dir to use.""" |
| 1208 | if arch == 'default' or arch == 'x64': |
| 1209 | return 'x64' |
| 1210 | elif arch == 'x86': |
| 1211 | return 'x86' |
| 1212 | else: |
| 1213 | print('Architecture %s not supported with current settings.' % arch) |
| 1214 | sys.exit(1) |
Jan Tattermusch | e70b3c5 | 2016-02-07 20:21:02 -0800 | [diff] [blame] | 1215 | |
| 1216 | |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 1217 | def runs_per_test_type(arg_str): |
| 1218 | """Auxilary function to parse the "runs_per_test" flag. |
| 1219 | |
| 1220 | Returns: |
| 1221 | A positive integer or 0, the latter indicating an infinite number of |
| 1222 | runs. |
| 1223 | |
| 1224 | Raises: |
| 1225 | argparse.ArgumentTypeError: Upon invalid input. |
| 1226 | """ |
| 1227 | if arg_str == 'inf': |
| 1228 | return 0 |
| 1229 | try: |
| 1230 | n = int(arg_str) |
| 1231 | if n <= 0: raise ValueError |
Craig Tiller | 50e53e2 | 2015-06-01 20:18:21 -0700 | [diff] [blame] | 1232 | return n |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 1233 | except: |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 1234 | msg = '\'{}\' is not a positive integer or \'inf\''.format(arg_str) |
David Garcia Quintas | e90cd37 | 2015-05-31 18:15:26 -0700 | [diff] [blame] | 1235 | raise argparse.ArgumentTypeError(msg) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 1236 | |
siddharthshukla | 2135a1b | 2016-08-04 02:11:53 +0200 | [diff] [blame] | 1237 | |
David Garcia Quintas | 95b37b7 | 2017-02-15 16:49:49 -0800 | [diff] [blame] | 1238 | def percent_type(arg_str): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1239 | pct = float(arg_str) |
| 1240 | if pct > 100 or pct < 0: |
| 1241 | raise argparse.ArgumentTypeError( |
| 1242 | "'%f' is not a valid percentage in the [0, 100] range" % pct) |
| 1243 | return pct |
| 1244 | |
David Garcia Quintas | 95b37b7 | 2017-02-15 16:49:49 -0800 | [diff] [blame] | 1245 | |
| 1246 | # This is math.isclose in python >= 3.5 |
| 1247 | def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1248 | return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) |
David Garcia Quintas | 95b37b7 | 2017-02-15 16:49:49 -0800 | [diff] [blame] | 1249 | |
| 1250 | |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 1251 | # parse command line |
| 1252 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1253 | argp.add_argument( |
| 1254 | '-c', '--config', choices=sorted(_CONFIGS.keys()), default='opt') |
| 1255 | argp.add_argument( |
| 1256 | '-n', |
| 1257 | '--runs_per_test', |
| 1258 | default=1, |
| 1259 | type=runs_per_test_type, |
| 1260 | help='A positive integer or "inf". If "inf", all tests will run in an ' |
| 1261 | 'infinite loop. Especially useful in combination with "-f"') |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 1262 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Vijay Pai | 488fd0e | 2016-06-13 12:37:12 -0700 | [diff] [blame] | 1263 | argp.add_argument('--regex_exclude', default='', type=str) |
Craig Tiller | 5f735a6 | 2016-01-20 09:31:15 -0800 | [diff] [blame] | 1264 | argp.add_argument('-j', '--jobs', default=multiprocessing.cpu_count(), type=int) |
Craig Tiller | 8451e87 | 2015-02-27 09:25:51 -0800 | [diff] [blame] | 1265 | argp.add_argument('-s', '--slowdown', default=1.0, type=float) |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1266 | argp.add_argument( |
| 1267 | '-p', |
| 1268 | '--sample_percent', |
| 1269 | default=100.0, |
| 1270 | type=percent_type, |
| 1271 | help='Run a random sample with that percentage of tests') |
| 1272 | argp.add_argument( |
| 1273 | '-f', '--forever', default=False, action='store_const', const=True) |
| 1274 | argp.add_argument( |
| 1275 | '-t', '--travis', default=False, action='store_const', const=True) |
| 1276 | argp.add_argument( |
| 1277 | '--newline_on_success', default=False, action='store_const', const=True) |
| 1278 | argp.add_argument( |
| 1279 | '-l', |
| 1280 | '--language', |
| 1281 | choices=['all'] + sorted(_LANGUAGES.keys()), |
| 1282 | nargs='+', |
| 1283 | default=['all']) |
| 1284 | argp.add_argument( |
| 1285 | '-S', '--stop_on_failure', default=False, action='store_const', const=True) |
| 1286 | argp.add_argument( |
| 1287 | '--use_docker', |
| 1288 | default=False, |
| 1289 | action='store_const', |
| 1290 | const=True, |
| 1291 | help='Run all the tests under docker. That provides ' + |
| 1292 | 'additional isolation and prevents the need to install ' + |
| 1293 | 'language specific prerequisites. Only available on Linux.') |
| 1294 | argp.add_argument( |
| 1295 | '--allow_flakes', |
| 1296 | default=False, |
| 1297 | action='store_const', |
| 1298 | const=True, |
| 1299 | help='Allow flaky tests to show as passing (re-runs failed tests up to five times)' |
| 1300 | ) |
| 1301 | argp.add_argument( |
| 1302 | '--arch', |
| 1303 | choices=['default', 'x86', 'x64'], |
| 1304 | default='default', |
| 1305 | help='Selects architecture to target. For some platforms "default" is the only supported choice.' |
| 1306 | ) |
| 1307 | argp.add_argument( |
| 1308 | '--compiler', |
| 1309 | choices=[ |
| 1310 | 'default', 'gcc4.4', 'gcc4.6', 'gcc4.8', 'gcc4.9', 'gcc5.3', 'gcc_musl', |
| 1311 | 'clang3.4', 'clang3.5', 'clang3.6', 'clang3.7', 'python2.7', |
| 1312 | 'python3.4', 'python3.5', 'python3.6', 'pypy', 'pypy3', 'python_alpine', |
| 1313 | 'all_the_cpythons', 'electron1.3', 'electron1.6', 'coreclr', 'cmake', |
| 1314 | 'cmake_vs2015', 'cmake_vs2017' |
| 1315 | ], |
| 1316 | default='default', |
| 1317 | help='Selects compiler to use. Allowed values depend on the platform and language.' |
| 1318 | ) |
| 1319 | argp.add_argument( |
| 1320 | '--iomgr_platform', |
| 1321 | choices=['native', 'uv'], |
| 1322 | default='native', |
| 1323 | help='Selects iomgr platform to build on') |
| 1324 | argp.add_argument( |
| 1325 | '--build_only', |
| 1326 | default=False, |
| 1327 | action='store_const', |
| 1328 | const=True, |
| 1329 | help='Perform all the build steps but don\'t run any tests.') |
| 1330 | argp.add_argument( |
| 1331 | '--measure_cpu_costs', |
| 1332 | default=False, |
| 1333 | action='store_const', |
| 1334 | const=True, |
| 1335 | help='Measure the cpu costs of tests') |
| 1336 | argp.add_argument( |
| 1337 | '--update_submodules', |
| 1338 | default=[], |
| 1339 | nargs='*', |
| 1340 | help='Update some submodules before building. If any are updated, also run generate_projects. ' |
| 1341 | + |
| 1342 | 'Submodules are specified as SUBMODULE_NAME:BRANCH; if BRANCH is omitted, master is assumed.' |
| 1343 | ) |
Craig Tiller | 234b6e7 | 2015-05-23 10:12:40 -0700 | [diff] [blame] | 1344 | argp.add_argument('-a', '--antagonists', default=0, type=int) |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1345 | argp.add_argument( |
| 1346 | '-x', |
| 1347 | '--xml_report', |
| 1348 | default=None, |
| 1349 | type=str, |
| 1350 | help='Generates a JUnit-compatible XML report') |
| 1351 | argp.add_argument( |
| 1352 | '--report_suite_name', |
| 1353 | default='tests', |
| 1354 | type=str, |
| 1355 | help='Test suite name to use in generated JUnit XML report') |
| 1356 | argp.add_argument( |
| 1357 | '--quiet_success', |
| 1358 | default=False, |
| 1359 | action='store_const', |
| 1360 | const=True, |
| 1361 | help='Don\'t print anything when a test passes. Passing tests also will not be reported in XML report. ' |
| 1362 | + 'Useful when running many iterations of each test (argument -n).') |
| 1363 | argp.add_argument( |
| 1364 | '--force_default_poller', |
| 1365 | default=False, |
| 1366 | action='store_const', |
| 1367 | const=True, |
| 1368 | help='Don\'t try to iterate over many polling strategies when they exist') |
| 1369 | argp.add_argument( |
| 1370 | '--force_use_pollers', |
| 1371 | default=None, |
| 1372 | type=str, |
| 1373 | help='Only use the specified comma-delimited list of polling engines. ' |
| 1374 | 'Example: --force_use_pollers epollsig,poll ' |
| 1375 | ' (This flag has no effect if --force_default_poller flag is also used)') |
| 1376 | argp.add_argument( |
| 1377 | '--max_time', default=-1, type=int, help='Maximum test runtime in seconds') |
| 1378 | argp.add_argument( |
| 1379 | '--bq_result_table', |
| 1380 | default='', |
| 1381 | type=str, |
| 1382 | nargs='?', |
| 1383 | help='Upload test results to a specified BQ table.') |
| 1384 | argp.add_argument( |
| 1385 | '--disable_auto_set_flakes', |
| 1386 | default=False, |
| 1387 | const=True, |
| 1388 | action='store_const', |
| 1389 | help='Disable rerunning historically flaky tests') |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 1390 | args = argp.parse_args() |
| 1391 | |
Craig Tiller | d16abf8 | 2017-06-07 08:58:55 -0700 | [diff] [blame] | 1392 | flaky_tests = set() |
Craig Tiller | 0b86d03 | 2017-09-07 13:47:45 -0700 | [diff] [blame] | 1393 | shortname_to_cpu = {} |
Matt Kwong | c5fd890 | 2017-08-10 13:39:21 -0700 | [diff] [blame] | 1394 | if not args.disable_auto_set_flakes: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1395 | try: |
| 1396 | for test in get_bqtest_data(): |
| 1397 | if test.flaky: flaky_tests.add(test.name) |
| 1398 | if test.cpu > 0: shortname_to_cpu[test.name] = test.cpu |
| 1399 | except: |
| 1400 | print("Unexpected error getting flaky tests: %s" % |
| 1401 | traceback.format_exc()) |
David Garcia Quintas | faafa4d | 2017-06-06 14:52:17 -0700 | [diff] [blame] | 1402 | |
Craig Tiller | 123f137 | 2016-06-15 15:06:14 -0700 | [diff] [blame] | 1403 | if args.force_default_poller: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1404 | _POLLING_STRATEGIES = {} |
Sree Kuchibhotla | 15d9164 | 2017-08-15 14:00:23 -0700 | [diff] [blame] | 1405 | elif args.force_use_pollers: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1406 | _POLLING_STRATEGIES[platform_string()] = args.force_use_pollers.split(',') |
Craig Tiller | 123f137 | 2016-06-15 15:06:14 -0700 | [diff] [blame] | 1407 | |
Craig Tiller | 5f735a6 | 2016-01-20 09:31:15 -0800 | [diff] [blame] | 1408 | jobset.measure_cpu_costs = args.measure_cpu_costs |
| 1409 | |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 1410 | # update submodules if necessary |
Craig Tiller | b361b4e | 2016-01-06 11:44:17 -0800 | [diff] [blame] | 1411 | need_to_regenerate_projects = False |
| 1412 | for spec in args.update_submodules: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1413 | spec = spec.split(':', 1) |
| 1414 | if len(spec) == 1: |
| 1415 | submodule = spec[0] |
| 1416 | branch = 'master' |
| 1417 | elif len(spec) == 2: |
| 1418 | submodule = spec[0] |
| 1419 | branch = spec[1] |
| 1420 | cwd = 'third_party/%s' % submodule |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 1421 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1422 | def git(cmd, cwd=cwd): |
| 1423 | print('in %s: git %s' % (cwd, cmd)) |
| 1424 | run_shell_command('git %s' % cmd, cwd=cwd) |
| 1425 | |
| 1426 | git('fetch') |
| 1427 | git('checkout %s' % branch) |
| 1428 | git('pull origin %s' % branch) |
| 1429 | if os.path.exists('src/%s/gen_build_yaml.py' % submodule): |
| 1430 | need_to_regenerate_projects = True |
| 1431 | if need_to_regenerate_projects: |
| 1432 | if jobset.platform_string() == 'linux': |
| 1433 | run_shell_command('tools/buildgen/generate_projects.sh') |
| 1434 | else: |
| 1435 | print( |
| 1436 | 'WARNING: may need to regenerate projects, but since we are not on') |
| 1437 | print( |
| 1438 | ' Linux this step is being skipped. Compilation MAY fail.') |
Craig Tiller | 1676f91 | 2016-01-05 10:49:44 -0800 | [diff] [blame] | 1439 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 1440 | # grab config |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 1441 | run_config = _CONFIGS[args.config] |
| 1442 | build_config = run_config.build_config |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 1443 | |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 1444 | if args.travis: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1445 | _FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'api'} |
Craig Tiller | 0680527 | 2015-06-11 14:46:47 -0700 | [diff] [blame] | 1446 | |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 1447 | if 'all' in args.language: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1448 | lang_list = _LANGUAGES.keys() |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 1449 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1450 | lang_list = args.language |
Craig Tiller | 1690066 | 2016-01-07 19:30:54 -0800 | [diff] [blame] | 1451 | # We don't support code coverage on some languages |
| 1452 | if 'gcov' in args.config: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1453 | for bad in ['objc', 'sanity']: |
| 1454 | if bad in lang_list: |
| 1455 | lang_list.remove(bad) |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 1456 | |
| 1457 | languages = set(_LANGUAGES[l] for l in lang_list) |
Jan Tattermusch | 77db432 | 2016-02-20 20:19:35 -0800 | [diff] [blame] | 1458 | for l in languages: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1459 | l.configure(run_config, args) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 1460 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1461 | language_make_options = [] |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 1462 | if any(language.make_options() for language in languages): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1463 | if not 'gcov' in args.config and len(languages) != 1: |
| 1464 | print( |
| 1465 | 'languages with custom make options cannot be built simultaneously with other languages' |
| 1466 | ) |
| 1467 | sys.exit(1) |
| 1468 | else: |
| 1469 | # Combining make options is not clean and just happens to work. It allows C/C++ and C# to build |
| 1470 | # together, and is only used under gcov. All other configs should build languages individually. |
| 1471 | language_make_options = list( |
| 1472 | set([ |
| 1473 | make_option |
| 1474 | for lang in languages for make_option in lang.make_options() |
| 1475 | ])) |
Jan Tattermusch | c895fe0 | 2016-01-20 09:13:09 -0800 | [diff] [blame] | 1476 | |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 1477 | if args.use_docker: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1478 | if not args.travis: |
| 1479 | print('Seen --use_docker flag, will run tests under docker.') |
| 1480 | print('') |
| 1481 | print( |
| 1482 | 'IMPORTANT: The changes you are testing need to be locally committed' |
| 1483 | ) |
| 1484 | print( |
| 1485 | 'because only the committed changes in the current branch will be') |
| 1486 | print('copied to the docker environment.') |
| 1487 | time.sleep(5) |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 1488 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1489 | dockerfile_dirs = set([l.dockerfile_dir() for l in languages]) |
| 1490 | if len(dockerfile_dirs) > 1: |
| 1491 | if 'gcov' in args.config: |
| 1492 | dockerfile_dir = 'tools/dockerfile/test/multilang_jessie_x64' |
| 1493 | print( |
| 1494 | 'Using multilang_jessie_x64 docker image for code coverage for ' |
| 1495 | 'all languages.') |
| 1496 | else: |
| 1497 | print( |
| 1498 | 'Languages to be tested require running under different docker ' |
| 1499 | 'images.') |
| 1500 | sys.exit(1) |
Adele Zhou | 9506ef2 | 2016-03-02 13:53:34 -0800 | [diff] [blame] | 1501 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1502 | dockerfile_dir = next(iter(dockerfile_dirs)) |
Craig Tiller | de7edf8 | 2016-03-20 09:12:16 -0700 | [diff] [blame] | 1503 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1504 | child_argv = [arg for arg in sys.argv if not arg == '--use_docker'] |
| 1505 | run_tests_cmd = 'python tools/run_tests/run_tests.py %s' % ' '.join( |
| 1506 | child_argv[1:]) |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 1507 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1508 | env = os.environ.copy() |
| 1509 | env['RUN_TESTS_COMMAND'] = run_tests_cmd |
| 1510 | env['DOCKERFILE_DIR'] = dockerfile_dir |
| 1511 | env['DOCKER_RUN_SCRIPT'] = 'tools/run_tests/dockerize/docker_run_tests.sh' |
| 1512 | if args.xml_report: |
| 1513 | env['XML_REPORT'] = args.xml_report |
| 1514 | if not args.travis: |
| 1515 | env['TTY_FLAG'] = '-t' # enables Ctrl-C when not on Jenkins. |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 1516 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1517 | subprocess.check_call( |
| 1518 | 'tools/run_tests/dockerize/build_docker_and_run_tests.sh', |
| 1519 | shell=True, |
| 1520 | env=env) |
| 1521 | sys.exit(0) |
Jan Tattermusch | 788ee23 | 2016-01-26 12:19:44 -0800 | [diff] [blame] | 1522 | |
Jan Tattermusch | f08018a | 2016-01-26 08:22:09 -0800 | [diff] [blame] | 1523 | _check_arch_option(args.arch) |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 1524 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1525 | |
Jan Tattermusch | fba6530 | 2016-01-25 18:21:14 -0800 | [diff] [blame] | 1526 | def make_jobspec(cfg, targets, makefile='Makefile'): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1527 | if platform_string() == 'windows': |
| 1528 | return [ |
| 1529 | jobset.JobSpec( |
| 1530 | [ |
| 1531 | 'cmake', '--build', '.', '--target', '%s' % target, |
| 1532 | '--config', _MSBUILD_CONFIG[cfg] |
| 1533 | ], |
| 1534 | cwd=os.path.dirname(makefile), |
| 1535 | timeout_seconds=None) for target in targets |
| 1536 | ] |
murgatroid99 | 8ae409f | 2015-10-26 16:39:00 -0700 | [diff] [blame] | 1537 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1538 | if targets and makefile.startswith('cmake/build/'): |
| 1539 | # With cmake, we've passed all the build configuration in the pre-build step already |
| 1540 | return [ |
| 1541 | jobset.JobSpec( |
| 1542 | [os.getenv('MAKE', 'make'), '-j', '%d' % args.jobs] + |
| 1543 | targets, |
| 1544 | cwd='cmake/build', |
| 1545 | timeout_seconds=None) |
| 1546 | ] |
| 1547 | if targets: |
| 1548 | return [ |
| 1549 | jobset.JobSpec( |
| 1550 | [ |
| 1551 | os.getenv('MAKE', 'make'), '-f', makefile, '-j', '%d' % |
| 1552 | args.jobs, |
| 1553 | 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % |
| 1554 | args.slowdown, 'CONFIG=%s' % cfg, 'Q=' |
| 1555 | ] + language_make_options + |
| 1556 | ([] if not args.travis else ['JENKINS_BUILD=1']) + targets, |
| 1557 | timeout_seconds=None) |
| 1558 | ] |
| 1559 | else: |
| 1560 | return [] |
| 1561 | |
Jan Tattermusch | fba6530 | 2016-01-25 18:21:14 -0800 | [diff] [blame] | 1562 | |
murgatroid99 | a3e244f | 2015-09-22 11:25:53 -0700 | [diff] [blame] | 1563 | make_targets = {} |
| 1564 | for l in languages: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1565 | makefile = l.makefile_name() |
| 1566 | make_targets[makefile] = make_targets.get( |
| 1567 | makefile, set()).union(set(l.make_targets())) |
| 1568 | |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 1569 | |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 1570 | def build_step_environ(cfg): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1571 | environ = {'CONFIG': cfg} |
| 1572 | msbuild_cfg = _MSBUILD_CONFIG.get(cfg) |
| 1573 | if msbuild_cfg: |
| 1574 | environ['MSBUILD_CONFIG'] = msbuild_cfg |
| 1575 | return environ |
Jan Tattermusch | e4a6918 | 2015-12-15 09:53:01 -0800 | [diff] [blame] | 1576 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1577 | |
| 1578 | build_steps = list( |
| 1579 | set( |
| 1580 | jobset.JobSpec( |
| 1581 | cmdline, environ=build_step_environ(build_config), flake_retries=2) |
| 1582 | for l in languages for cmdline in l.pre_build_steps())) |
Craig Tiller | bd4e378 | 2015-09-01 06:48:55 -0700 | [diff] [blame] | 1583 | if make_targets: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1584 | make_commands = itertools.chain.from_iterable( |
| 1585 | make_jobspec(build_config, list(targets), makefile) |
| 1586 | for (makefile, targets) in make_targets.items()) |
| 1587 | build_steps.extend(set(make_commands)) |
| 1588 | build_steps.extend( |
| 1589 | set( |
| 1590 | jobset.JobSpec( |
| 1591 | cmdline, |
| 1592 | environ=build_step_environ(build_config), |
| 1593 | timeout_seconds=None) |
| 1594 | for l in languages for cmdline in l.build_steps())) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 1595 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1596 | post_tests_steps = list( |
| 1597 | set( |
| 1598 | jobset.JobSpec(cmdline, environ=build_step_environ(build_config)) |
| 1599 | for l in languages for cmdline in l.post_tests_steps())) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 1600 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1601 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 1602 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 1603 | |
Ken Payson | fa51de5 | 2016-06-30 23:50:48 -0700 | [diff] [blame] | 1604 | def _shut_down_legacy_server(legacy_server_port): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1605 | try: |
| 1606 | version = int( |
| 1607 | urllib.request.urlopen( |
| 1608 | 'http://localhost:%d/version_number' % legacy_server_port, |
| 1609 | timeout=10).read()) |
| 1610 | except: |
| 1611 | pass |
| 1612 | else: |
| 1613 | urllib.request.urlopen('http://localhost:%d/quitquitquit' % |
| 1614 | legacy_server_port).read() |
Ken Payson | fa51de5 | 2016-06-30 23:50:48 -0700 | [diff] [blame] | 1615 | |
| 1616 | |
Adele Zhou | d5fffa5 | 2015-10-23 15:51:42 -0700 | [diff] [blame] | 1617 | def _calculate_num_runs_failures(list_of_results): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1618 | """Caculate number of runs and failures for a particular test. |
Adele Zhou | d5fffa5 | 2015-10-23 15:51:42 -0700 | [diff] [blame] | 1619 | |
| 1620 | Args: |
| 1621 | list_of_results: (List) of JobResult object. |
| 1622 | Returns: |
| 1623 | A tuple of total number of runs and failures. |
| 1624 | """ |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1625 | num_runs = len(list_of_results) # By default, there is 1 run per JobResult. |
| 1626 | num_failures = 0 |
| 1627 | for jobresult in list_of_results: |
| 1628 | if jobresult.retries > 0: |
| 1629 | num_runs += jobresult.retries |
| 1630 | if jobresult.num_failures > 0: |
| 1631 | num_failures += jobresult.num_failures |
| 1632 | return num_runs, num_failures |
Adele Zhou | d5fffa5 | 2015-10-23 15:51:42 -0700 | [diff] [blame] | 1633 | |
Adele Zhou | 6b9527c | 2015-11-20 15:56:35 -0800 | [diff] [blame] | 1634 | |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1635 | # _build_and_run results |
| 1636 | class BuildAndRunError(object): |
| 1637 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1638 | BUILD = object() |
| 1639 | TEST = object() |
| 1640 | POST_TEST = object() |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1641 | |
| 1642 | |
Craig Tiller | 819cd88 | 2017-04-25 13:18:22 -0700 | [diff] [blame] | 1643 | def _has_epollexclusive(): |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1644 | binary = 'bins/%s/check_epollexclusive' % args.config |
| 1645 | if not os.path.exists(binary): |
| 1646 | return False |
| 1647 | try: |
| 1648 | subprocess.check_call(binary) |
| 1649 | return True |
| 1650 | except subprocess.CalledProcessError, e: |
| 1651 | return False |
| 1652 | except OSError, e: |
| 1653 | # For languages other than C and Windows the binary won't exist |
| 1654 | return False |
Craig Tiller | 819cd88 | 2017-04-25 13:18:22 -0700 | [diff] [blame] | 1655 | |
| 1656 | |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1657 | # returns a list of things that failed (or an empty list on success) |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1658 | def _build_and_run(check_cancelled, |
| 1659 | newline_on_success, |
| 1660 | xml_report=None, |
| 1661 | build_only=False): |
| 1662 | """Do one pass of building & running tests.""" |
| 1663 | # build latest sequentially |
| 1664 | num_failures, resultset = jobset.run( |
| 1665 | build_steps, |
| 1666 | maxjobs=1, |
| 1667 | stop_on_failure=True, |
| 1668 | newline_on_success=newline_on_success, |
| 1669 | travis=args.travis) |
| 1670 | if num_failures: |
| 1671 | return [BuildAndRunError.BUILD] |
Craig Tiller | b361b4e | 2016-01-06 11:44:17 -0800 | [diff] [blame] | 1672 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1673 | if build_only: |
| 1674 | if xml_report: |
| 1675 | report_utils.render_junit_xml_report( |
| 1676 | resultset, xml_report, suite_name=args.report_suite_name) |
| 1677 | return [] |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1678 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1679 | if not args.travis and not _has_epollexclusive() and platform_string( |
| 1680 | ) in _POLLING_STRATEGIES and 'epollex' in _POLLING_STRATEGIES[ |
| 1681 | platform_string()]: |
| 1682 | print('\n\nOmitting EPOLLEXCLUSIVE tests\n\n') |
| 1683 | _POLLING_STRATEGIES[platform_string()].remove('epollex') |
Craig Tiller | 819cd88 | 2017-04-25 13:18:22 -0700 | [diff] [blame] | 1684 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1685 | # start antagonists |
| 1686 | antagonists = [ |
| 1687 | subprocess.Popen(['tools/run_tests/python_utils/antagonist.py']) |
| 1688 | for _ in range(0, args.antagonists) |
| 1689 | ] |
| 1690 | start_port_server.start_port_server() |
| 1691 | resultset = None |
| 1692 | num_test_failures = 0 |
| 1693 | try: |
| 1694 | infinite_runs = runs_per_test == 0 |
| 1695 | one_run = set(spec |
| 1696 | for language in languages |
| 1697 | for spec in language.test_specs() |
| 1698 | if (re.search(args.regex, spec.shortname) and ( |
| 1699 | args.regex_exclude == '' or not re.search( |
| 1700 | args.regex_exclude, spec.shortname)))) |
| 1701 | # When running on travis, we want out test runs to be as similar as possible |
| 1702 | # for reproducibility purposes. |
| 1703 | if args.travis and args.max_time <= 0: |
| 1704 | massaged_one_run = sorted(one_run, key=lambda x: x.cpu_cost) |
| 1705 | else: |
| 1706 | # whereas otherwise, we want to shuffle things up to give all tests a |
| 1707 | # chance to run. |
| 1708 | massaged_one_run = list( |
| 1709 | one_run) # random.sample needs an indexable seq. |
| 1710 | num_jobs = len(massaged_one_run) |
| 1711 | # for a random sample, get as many as indicated by the 'sample_percent' |
| 1712 | # argument. By default this arg is 100, resulting in a shuffle of all |
| 1713 | # jobs. |
| 1714 | sample_size = int(num_jobs * args.sample_percent / 100.0) |
| 1715 | massaged_one_run = random.sample(massaged_one_run, sample_size) |
| 1716 | if not isclose(args.sample_percent, 100.0): |
| 1717 | assert args.runs_per_test == 1, "Can't do sampling (-p) over multiple runs (-n)." |
| 1718 | print("Running %d tests out of %d (~%d%%)" % |
| 1719 | (sample_size, num_jobs, args.sample_percent)) |
| 1720 | if infinite_runs: |
| 1721 | assert len(massaged_one_run |
| 1722 | ) > 0, 'Must have at least one test for a -n inf run' |
| 1723 | runs_sequence = (itertools.repeat(massaged_one_run) if infinite_runs |
| 1724 | else itertools.repeat(massaged_one_run, runs_per_test)) |
| 1725 | all_runs = itertools.chain.from_iterable(runs_sequence) |
Nicolas "Pixel" Noble | 5937b5b | 2015-06-26 02:04:12 +0200 | [diff] [blame] | 1726 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1727 | if args.quiet_success: |
Jan Tattermusch | 68e27bf | 2016-12-16 14:09:03 +0100 | [diff] [blame] | 1728 | jobset.message( |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1729 | 'START', |
| 1730 | 'Running tests quietly, only failing tests will be reported', |
Jan Tattermusch | 68e27bf | 2016-12-16 14:09:03 +0100 | [diff] [blame] | 1731 | do_newline=True) |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1732 | num_test_failures, resultset = jobset.run( |
| 1733 | all_runs, |
| 1734 | check_cancelled, |
| 1735 | newline_on_success=newline_on_success, |
| 1736 | travis=args.travis, |
| 1737 | maxjobs=args.jobs, |
| 1738 | maxjobs_cpu_agnostic=max_parallel_tests_for_current_platform(), |
| 1739 | stop_on_failure=args.stop_on_failure, |
| 1740 | quiet_success=args.quiet_success, |
| 1741 | max_time=args.max_time) |
| 1742 | if resultset: |
| 1743 | for k, v in sorted(resultset.items()): |
| 1744 | num_runs, num_failures = _calculate_num_runs_failures(v) |
| 1745 | if num_failures > 0: |
| 1746 | if num_failures == num_runs: # what about infinite_runs??? |
| 1747 | jobset.message('FAILED', k, do_newline=True) |
| 1748 | else: |
| 1749 | jobset.message( |
| 1750 | 'FLAKE', |
| 1751 | '%s [%d/%d runs flaked]' % |
| 1752 | (k, num_failures, num_runs), |
| 1753 | do_newline=True) |
| 1754 | finally: |
| 1755 | for antagonist in antagonists: |
| 1756 | antagonist.kill() |
| 1757 | if args.bq_result_table and resultset: |
| 1758 | upload_results_to_bq(resultset, args.bq_result_table, args, |
| 1759 | platform_string()) |
| 1760 | if xml_report and resultset: |
| 1761 | report_utils.render_junit_xml_report( |
| 1762 | resultset, xml_report, suite_name=args.report_suite_name) |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 1763 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1764 | number_failures, _ = jobset.run( |
| 1765 | post_tests_steps, |
| 1766 | maxjobs=1, |
| 1767 | stop_on_failure=False, |
| 1768 | newline_on_success=newline_on_success, |
| 1769 | travis=args.travis) |
Craig Tiller | eb9de8b | 2016-01-08 08:57:41 -0800 | [diff] [blame] | 1770 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1771 | out = [] |
| 1772 | if number_failures: |
| 1773 | out.append(BuildAndRunError.POST_TEST) |
| 1774 | if num_test_failures: |
| 1775 | out.append(BuildAndRunError.TEST) |
Nicolas "Pixel" Noble | 3fcd3bf | 2015-10-10 02:30:38 +0200 | [diff] [blame] | 1776 | |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1777 | return out |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1778 | |
| 1779 | |
| 1780 | if forever: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1781 | success = True |
| 1782 | while True: |
| 1783 | dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples']) |
| 1784 | initial_time = dw.most_recent_change() |
| 1785 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
| 1786 | previous_success = success |
| 1787 | errors = _build_and_run( |
| 1788 | check_cancelled=have_files_changed, |
| 1789 | newline_on_success=False, |
| 1790 | build_only=args.build_only) == 0 |
| 1791 | if not previous_success and not errors: |
| 1792 | jobset.message( |
| 1793 | 'SUCCESS', |
| 1794 | 'All tests are now passing properly', |
| 1795 | do_newline=True) |
| 1796 | jobset.message('IDLE', 'No change detected') |
| 1797 | while not have_files_changed(): |
| 1798 | time.sleep(1) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 1799 | else: |
ncteisen | 888093c | 2017-12-11 18:00:40 -0800 | [diff] [blame] | 1800 | errors = _build_and_run( |
| 1801 | check_cancelled=lambda: False, |
| 1802 | newline_on_success=args.newline_on_success, |
| 1803 | xml_report=args.xml_report, |
| 1804 | build_only=args.build_only) |
| 1805 | if not errors: |
| 1806 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 1807 | else: |
| 1808 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
| 1809 | exit_code = 0 |
| 1810 | if BuildAndRunError.BUILD in errors: |
| 1811 | exit_code |= 1 |
| 1812 | if BuildAndRunError.TEST in errors: |
| 1813 | exit_code |= 2 |
| 1814 | if BuildAndRunError.POST_TEST in errors: |
| 1815 | exit_code |= 4 |
| 1816 | sys.exit(exit_code) |