David Klempner | f94838b | 2015-02-02 16:56:46 -0800 | [diff] [blame] | 1 | #!/usr/bin/python2.7 |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 2 | # Copyright 2015, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 31 | """Run tests in parallel.""" |
| 32 | |
| 33 | import argparse |
| 34 | import glob |
| 35 | import itertools |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 36 | import json |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 37 | import multiprocessing |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 38 | import os |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 39 | import re |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 40 | import sys |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 41 | import time |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 42 | |
| 43 | import jobset |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 44 | import watch_dirs |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 45 | |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 46 | |
Craig Tiller | 2cc2b84 | 2015-02-27 11:38:31 -0800 | [diff] [blame] | 47 | ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 48 | os.chdir(ROOT) |
| 49 | |
| 50 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 51 | # SimpleConfig: just compile with CONFIG=config, and run the binary to test |
| 52 | class SimpleConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 53 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 54 | def __init__(self, config, environ=None): |
| 55 | if environ is None: |
| 56 | environ = {} |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 57 | self.build_config = config |
Craig Tiller | e68de0e | 2015-01-26 08:44:00 -0800 | [diff] [blame] | 58 | self.maxjobs = 2 * multiprocessing.cpu_count() |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 59 | self.allow_hashing = (config != 'gcov') |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 60 | self.environ = environ |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 61 | self.environ['CONFIG'] = config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 62 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 63 | def job_spec(self, cmdline, hash_targets): |
| 64 | """Construct a jobset.JobSpec for a test under this config |
| 65 | |
| 66 | Args: |
| 67 | cmdline: a list of strings specifying the command line the test |
| 68 | would like to run |
| 69 | hash_targets: either None (don't do caching of test results), or |
| 70 | a list of strings specifying files to include in a |
| 71 | binary hash to check if a test has changed |
| 72 | -- if used, all artifacts needed to run the test must |
| 73 | be listed |
| 74 | """ |
| 75 | return jobset.JobSpec(cmdline=cmdline, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 76 | environ=self.environ, |
| 77 | hash_targets=hash_targets |
| 78 | if self.allow_hashing else None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 79 | |
| 80 | |
| 81 | # ValgrindConfig: compile with some CONFIG=config, but use valgrind to run |
| 82 | class ValgrindConfig(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 83 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 84 | def __init__(self, config, tool, args=None): |
| 85 | if args is None: |
| 86 | args = [] |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 87 | self.build_config = config |
Craig Tiller | 2aa4d64 | 2015-01-14 15:59:44 -0800 | [diff] [blame] | 88 | self.tool = tool |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 89 | self.args = args |
Craig Tiller | e68de0e | 2015-01-26 08:44:00 -0800 | [diff] [blame] | 90 | self.maxjobs = 2 * multiprocessing.cpu_count() |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 91 | self.allow_hashing = False |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 92 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 93 | def job_spec(self, cmdline, hash_targets): |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 94 | return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] + |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 95 | self.args + cmdline, |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 96 | shortname='valgrind %s' % binary, |
| 97 | hash_targets=None) |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 98 | |
| 99 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 100 | class CLanguage(object): |
| 101 | |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 102 | def __init__(self, make_target, test_lang): |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 103 | self.make_target = make_target |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 104 | with open('tools/run_tests/tests.json') as f: |
Craig Tiller | 06b4ff2 | 2015-01-18 11:01:25 -0800 | [diff] [blame] | 105 | js = json.load(f) |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 106 | self.binaries = [tgt for tgt in js if tgt['language'] == test_lang] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 107 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 108 | def test_specs(self, config, travis): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 109 | out = [] |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 110 | for target in self.binaries: |
| 111 | if travis and target['flaky']: |
| 112 | continue |
| 113 | binary = 'bins/%s/%s' % (config.build_config, target['name']) |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 114 | out.append(config.job_spec([binary], [binary])) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 115 | return out |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 116 | |
| 117 | def make_targets(self): |
| 118 | return ['buildtests_%s' % self.make_target] |
| 119 | |
| 120 | def build_steps(self): |
| 121 | return [] |
| 122 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 123 | def supports_multi_config(self): |
| 124 | return True |
| 125 | |
| 126 | def __str__(self): |
| 127 | return self.make_target |
| 128 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 129 | |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 130 | class NodeLanguage(object): |
| 131 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 132 | def test_specs(self, config, travis): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 133 | return [config.job_spec(['tools/run_tests/run_node.sh'], None)] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 134 | |
| 135 | def make_targets(self): |
murgatroid99 | c279165 | 2015-01-26 11:33:39 -0800 | [diff] [blame] | 136 | return ['static_c'] |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 137 | |
| 138 | def build_steps(self): |
| 139 | return [['tools/run_tests/build_node.sh']] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 140 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 141 | def supports_multi_config(self): |
| 142 | return False |
| 143 | |
| 144 | def __str__(self): |
| 145 | return 'node' |
| 146 | |
Craig Tiller | 9977582 | 2015-01-30 13:07:16 -0800 | [diff] [blame] | 147 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 148 | class PhpLanguage(object): |
| 149 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 150 | def test_specs(self, config, travis): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 151 | return [config.job_spec(['src/php/bin/run_tests.sh'], None)] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 152 | |
| 153 | def make_targets(self): |
murgatroid99 | 564b944 | 2015-01-26 11:07:59 -0800 | [diff] [blame] | 154 | return ['static_c'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 155 | |
| 156 | def build_steps(self): |
| 157 | return [['tools/run_tests/build_php.sh']] |
| 158 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 159 | def supports_multi_config(self): |
| 160 | return False |
| 161 | |
| 162 | def __str__(self): |
| 163 | return 'php' |
| 164 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 165 | |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 166 | class PythonLanguage(object): |
| 167 | |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 168 | def __init__(self): |
| 169 | with open('tools/run_tests/python_tests.json') as f: |
| 170 | self._tests = json.load(f) |
| 171 | |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 172 | def test_specs(self, config, travis): |
Masood Malekghassemi | b2d4a8d | 2015-03-05 17:04:18 -0800 | [diff] [blame] | 173 | modules = [config.job_spec(['tools/run_tests/run_python.sh', '-m', |
| 174 | test['module']], None) |
| 175 | for test in self._tests if 'module' in test] |
| 176 | files = [config.job_spec(['tools/run_tests/run_python.sh', |
| 177 | test['file']], None) |
| 178 | for test in self._tests if 'file' in test] |
| 179 | return files + modules |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 180 | |
| 181 | def make_targets(self): |
Masood Malekghassemi | b2d4a8d | 2015-03-05 17:04:18 -0800 | [diff] [blame] | 182 | return ['static_c', 'grpc_python_plugin'] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 183 | |
| 184 | def build_steps(self): |
| 185 | return [['tools/run_tests/build_python.sh']] |
| 186 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 187 | def supports_multi_config(self): |
| 188 | return False |
| 189 | |
| 190 | def __str__(self): |
| 191 | return 'python' |
| 192 | |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 193 | class RubyLanguage(object): |
| 194 | |
| 195 | def test_specs(self, config, travis): |
Craig Tiller | 49f6132 | 2015-03-03 13:02:11 -0800 | [diff] [blame] | 196 | return [config.job_spec(['tools/run_tests/run_ruby.sh'], None)] |
murgatroid99 | 6a4c4fa | 2015-02-27 12:08:57 -0800 | [diff] [blame] | 197 | |
| 198 | def make_targets(self): |
| 199 | return ['static_c'] |
| 200 | |
| 201 | def build_steps(self): |
| 202 | return [['tools/run_tests/build_ruby.sh']] |
| 203 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 204 | def supports_multi_config(self): |
| 205 | return False |
| 206 | |
| 207 | def __str__(self): |
| 208 | return 'ruby' |
| 209 | |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 210 | class CSharpLanguage(object): |
| 211 | |
| 212 | def test_specs(self, config, travis): |
| 213 | return [config.job_spec('tools/run_tests/run_csharp.sh', None)] |
| 214 | |
| 215 | def make_targets(self): |
| 216 | return ['grpc_csharp_ext'] |
| 217 | |
| 218 | def build_steps(self): |
| 219 | return [['tools/run_tests/build_csharp.sh']] |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 220 | |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 221 | def supports_multi_config(self): |
| 222 | return False |
| 223 | |
| 224 | def __str__(self): |
| 225 | return 'csharp' |
| 226 | |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame^] | 227 | class Sanity(object): |
| 228 | |
| 229 | def test_specs(self, config, travis): |
| 230 | return [config.job_spec('tools/run_tests/run_sanity.sh', None)] |
| 231 | |
| 232 | def make_targets(self): |
| 233 | return ['run_dep_checks'] |
| 234 | |
| 235 | def build_steps(self): |
| 236 | return [] |
| 237 | |
| 238 | def supports_multi_config(self): |
| 239 | return False |
| 240 | |
| 241 | def __str__(self): |
| 242 | return 'sanity' |
| 243 | |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 244 | # different configurations we can run under |
| 245 | _CONFIGS = { |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 246 | 'dbg': SimpleConfig('dbg'), |
| 247 | 'opt': SimpleConfig('opt'), |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 248 | 'tsan': SimpleConfig('tsan', environ={ |
| 249 | 'TSAN_OPTIONS': 'suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 250 | 'msan': SimpleConfig('msan'), |
Craig Tiller | 96bd5f6 | 2015-02-13 09:04:13 -0800 | [diff] [blame] | 251 | 'ubsan': SimpleConfig('ubsan'), |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 252 | 'asan': SimpleConfig('asan', environ={ |
David Klempner | 1d0302d | 2015-02-04 16:08:01 -0800 | [diff] [blame] | 253 | 'ASAN_OPTIONS': 'detect_leaks=1:color=always:suppressions=tools/tsan_suppressions.txt'}), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 254 | 'gcov': SimpleConfig('gcov'), |
Craig Tiller | 1a305b1 | 2015-02-18 13:37:06 -0800 | [diff] [blame] | 255 | 'memcheck': ValgrindConfig('valgrind', 'memcheck', ['--leak-check=full']), |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 256 | 'helgrind': ValgrindConfig('dbg', 'helgrind') |
| 257 | } |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 258 | |
| 259 | |
Nicolas "Pixel" Noble | 1fb5e82 | 2015-03-16 06:20:37 +0100 | [diff] [blame] | 260 | _DEFAULT = ['opt'] |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 261 | _LANGUAGES = { |
Craig Tiller | e9c959d | 2015-01-18 10:23:26 -0800 | [diff] [blame] | 262 | 'c++': CLanguage('cxx', 'c++'), |
| 263 | 'c': CLanguage('c', 'c'), |
murgatroid99 | 2c8d516 | 2015-01-26 10:41:21 -0800 | [diff] [blame] | 264 | 'node': NodeLanguage(), |
Nathaniel Manista | 840615e | 2015-01-22 20:31:47 +0000 | [diff] [blame] | 265 | 'php': PhpLanguage(), |
| 266 | 'python': PythonLanguage(), |
Jan Tattermusch | 1970a5b | 2015-03-03 15:17:25 -0800 | [diff] [blame] | 267 | 'ruby': RubyLanguage(), |
Nicolas "Pixel" Noble | 9f72864 | 2015-03-24 18:50:30 +0100 | [diff] [blame^] | 268 | 'csharp': CSharpLanguage(), |
| 269 | 'sanity': Sanity(), |
Craig Tiller | eb272bc | 2015-01-30 13:13:14 -0800 | [diff] [blame] | 270 | } |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 271 | |
| 272 | # parse command line |
| 273 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 274 | argp.add_argument('-c', '--config', |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 275 | choices=['all'] + sorted(_CONFIGS.keys()), |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 276 | nargs='+', |
Craig Tiller | b29797b | 2015-01-12 13:51:54 -0800 | [diff] [blame] | 277 | default=_DEFAULT) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 278 | argp.add_argument('-n', '--runs_per_test', default=1, type=int) |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 279 | argp.add_argument('-r', '--regex', default='.*', type=str) |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 280 | argp.add_argument('-j', '--jobs', default=1000, type=int) |
Craig Tiller | 8451e87 | 2015-02-27 09:25:51 -0800 | [diff] [blame] | 281 | argp.add_argument('-s', '--slowdown', default=1.0, type=float) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 282 | argp.add_argument('-f', '--forever', |
| 283 | default=False, |
| 284 | action='store_const', |
| 285 | const=True) |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 286 | argp.add_argument('-t', '--travis', |
| 287 | default=False, |
| 288 | action='store_const', |
| 289 | const=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 290 | argp.add_argument('--newline_on_success', |
| 291 | default=False, |
| 292 | action='store_const', |
| 293 | const=True) |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 294 | argp.add_argument('-l', '--language', |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 295 | choices=sorted(_LANGUAGES.keys()), |
Craig Tiller | 686fb26 | 2015-01-15 07:39:09 -0800 | [diff] [blame] | 296 | nargs='+', |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 297 | default=sorted(_LANGUAGES.keys())) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 298 | args = argp.parse_args() |
| 299 | |
| 300 | # grab config |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 301 | run_configs = set(_CONFIGS[cfg] |
| 302 | for cfg in itertools.chain.from_iterable( |
| 303 | _CONFIGS.iterkeys() if x == 'all' else [x] |
| 304 | for x in args.config)) |
| 305 | build_configs = set(cfg.build_config for cfg in run_configs) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 306 | |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 307 | make_targets = [] |
| 308 | languages = set(_LANGUAGES[l] for l in args.language) |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 309 | |
| 310 | if len(build_configs) > 1: |
| 311 | for language in languages: |
| 312 | if not language.supports_multi_config(): |
| 313 | print language, 'does not support multiple build configurations' |
| 314 | sys.exit(1) |
| 315 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 316 | build_steps = [jobset.JobSpec(['make', |
| 317 | '-j', '%d' % (multiprocessing.cpu_count() + 1), |
Craig Tiller | 86fa1c5 | 2015-02-27 09:57:58 -0800 | [diff] [blame] | 318 | 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % args.slowdown, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 319 | 'CONFIG=%s' % cfg] + list(set( |
| 320 | itertools.chain.from_iterable( |
| 321 | l.make_targets() for l in languages)))) |
| 322 | for cfg in build_configs] + list(set( |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 323 | jobset.JobSpec(cmdline, environ={'CONFIG': cfg}) |
| 324 | for cfg in build_configs |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 325 | for l in languages |
| 326 | for cmdline in l.build_steps())) |
| 327 | one_run = set( |
| 328 | spec |
| 329 | for config in run_configs |
| 330 | for language in args.language |
Nicolas "Pixel" Noble | 9db7c3b | 2015-02-27 06:03:00 +0100 | [diff] [blame] | 331 | for spec in _LANGUAGES[language].test_specs(config, args.travis) |
Craig Tiller | fe406ec | 2015-02-24 13:55:12 -0800 | [diff] [blame] | 332 | if re.search(args.regex, spec.shortname)) |
Craig Tiller | f1973b0 | 2015-01-16 12:32:13 -0800 | [diff] [blame] | 333 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 334 | runs_per_test = args.runs_per_test |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 335 | forever = args.forever |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 336 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 337 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 338 | class TestCache(object): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 339 | """Cache for running tests.""" |
| 340 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 341 | def __init__(self, use_cache_results): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 342 | self._last_successful_run = {} |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 343 | self._use_cache_results = use_cache_results |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 344 | |
| 345 | def should_run(self, cmdline, bin_hash): |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 346 | if cmdline not in self._last_successful_run: |
| 347 | return True |
| 348 | if self._last_successful_run[cmdline] != bin_hash: |
| 349 | return True |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 350 | if not self._use_cache_results: |
| 351 | return True |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 352 | return False |
| 353 | |
| 354 | def finished(self, cmdline, bin_hash): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 355 | self._last_successful_run[cmdline] = bin_hash |
Craig Tiller | c1f1162 | 2015-02-25 09:09:59 -0800 | [diff] [blame] | 356 | self.save() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 357 | |
| 358 | def dump(self): |
Craig Tiller | b50d166 | 2015-01-15 17:28:21 -0800 | [diff] [blame] | 359 | return [{'cmdline': k, 'hash': v} |
| 360 | for k, v in self._last_successful_run.iteritems()] |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 361 | |
| 362 | def parse(self, exdump): |
| 363 | self._last_successful_run = dict((o['cmdline'], o['hash']) for o in exdump) |
| 364 | |
| 365 | def save(self): |
| 366 | with open('.run_tests_cache', 'w') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 367 | f.write(json.dumps(self.dump())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 368 | |
Craig Tiller | 1cc11db | 2015-01-15 22:50:50 -0800 | [diff] [blame] | 369 | def maybe_load(self): |
| 370 | if os.path.exists('.run_tests_cache'): |
| 371 | with open('.run_tests_cache') as f: |
Craig Tiller | 261dd98 | 2015-01-16 16:41:45 -0800 | [diff] [blame] | 372 | self.parse(json.loads(f.read())) |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 373 | |
| 374 | |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 375 | def _build_and_run(check_cancelled, newline_on_success, travis, cache): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 376 | """Do one pass of building & running tests.""" |
murgatroid99 | 666450e | 2015-01-26 13:03:31 -0800 | [diff] [blame] | 377 | # build latest sequentially |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 378 | if not jobset.run(build_steps, maxjobs=1, |
| 379 | newline_on_success=newline_on_success, travis=travis): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 380 | return 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 381 | |
| 382 | # run all the tests |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 383 | all_runs = itertools.chain.from_iterable( |
| 384 | itertools.repeat(one_run, runs_per_test)) |
| 385 | if not jobset.run(all_runs, check_cancelled, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 386 | newline_on_success=newline_on_success, travis=travis, |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 387 | maxjobs=min(args.jobs, min(c.maxjobs for c in run_configs)), |
Craig Tiller | c744916 | 2015-01-16 14:42:10 -0800 | [diff] [blame] | 388 | cache=cache): |
Craig Tiller | d86a394 | 2015-01-14 12:48:54 -0800 | [diff] [blame] | 389 | return 2 |
| 390 | |
| 391 | return 0 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 392 | |
| 393 | |
David Klempner | 2573958 | 2015-02-11 15:57:32 -0800 | [diff] [blame] | 394 | test_cache = TestCache(runs_per_test == 1) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 395 | test_cache.maybe_load() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 396 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 397 | if forever: |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 398 | success = True |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 399 | while True: |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 400 | dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples']) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 401 | initial_time = dw.most_recent_change() |
| 402 | have_files_changed = lambda: dw.most_recent_change() != initial_time |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 403 | previous_success = success |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 404 | success = _build_and_run(check_cancelled=have_files_changed, |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 405 | newline_on_success=False, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 406 | cache=test_cache) == 0 |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 407 | if not previous_success and success: |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 408 | jobset.message('SUCCESS', |
| 409 | 'All tests are now passing properly', |
| 410 | do_newline=True) |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 411 | jobset.message('IDLE', 'No change detected') |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 412 | while not have_files_changed(): |
| 413 | time.sleep(1) |
| 414 | else: |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 415 | result = _build_and_run(check_cancelled=lambda: False, |
| 416 | newline_on_success=args.newline_on_success, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 417 | travis=args.travis, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 418 | cache=test_cache) |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 419 | if result == 0: |
| 420 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
| 421 | else: |
| 422 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
| 423 | sys.exit(result) |