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