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