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