Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | """Run tests in parallel.""" |
| 3 | |
| 4 | import argparse |
| 5 | import glob |
| 6 | import itertools |
| 7 | import multiprocessing |
| 8 | import sys |
| 9 | |
| 10 | import jobset |
| 11 | |
| 12 | # flags required for make for each configuration |
| 13 | _CONFIGS = ['dbg', 'opt', 'tsan', 'msan', 'asan'] |
| 14 | |
| 15 | # parse command line |
| 16 | argp = argparse.ArgumentParser(description='Run grpc tests.') |
| 17 | argp.add_argument('-c', '--config', |
| 18 | choices=['all'] + _CONFIGS, |
| 19 | nargs='+', |
| 20 | default=['all']) |
| 21 | argp.add_argument('-t', '--test-filter', nargs='*', default=['*']) |
| 22 | argp.add_argument('-n', '--runs_per_test', default=1, type=int) |
| 23 | args = argp.parse_args() |
| 24 | |
| 25 | # grab config |
| 26 | configs = [cfg |
| 27 | for cfg in itertools.chain.from_iterable( |
| 28 | _CONFIGS if x == 'all' else [x] |
| 29 | for x in args.config)] |
| 30 | filters = args.test_filter |
| 31 | runs_per_test = args.runs_per_test |
| 32 | |
| 33 | # build latest, sharing cpu between the various makes |
| 34 | if not jobset.run( |
| 35 | ['make', |
| 36 | '-j', '%d' % max(multiprocessing.cpu_count() / len(configs), 1), |
| 37 | 'buildtests_c', |
| 38 | 'CONFIG=%s' % cfg] |
| 39 | for cfg in configs): |
| 40 | sys.exit(1) |
| 41 | |
| 42 | # run all the tests |
| 43 | jobset.run([x] |
| 44 | for x in itertools.chain.from_iterable( |
| 45 | itertools.chain.from_iterable(itertools.repeat( |
| 46 | glob.glob('bins/%s/%s_test' % (config, filt)), |
| 47 | runs_per_test)) |
| 48 | for config in configs |
| 49 | for filt in filters)) |