diff options
author | Vegard Sjonfjell <vegard@yahoo-inc.com> | 2016-11-17 16:54:52 +0100 |
---|---|---|
committer | Vegard Sjonfjell <vegard@yahoo-inc.com> | 2016-11-17 16:54:52 +0100 |
commit | 6983525cc348394d152808a95477862daaac3eff (patch) | |
tree | 437fca5db6475b15edee7119422153c0ec464cf7 /cppunit-parallelize.py | |
parent | 849a0fc325aa26af2685b21f6e5f79db222e3936 (diff) | |
parent | 1d35e343945522a87a38fd96fee329025abf817f (diff) |
Merge branch 'master' into vegard/cppunit-parallize-bugfix
Diffstat (limited to 'cppunit-parallelize.py')
-rwxr-xr-x | cppunit-parallelize.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/cppunit-parallelize.py b/cppunit-parallelize.py index 25106568d56..058ab61b2a0 100755 --- a/cppunit-parallelize.py +++ b/cppunit-parallelize.py @@ -7,6 +7,7 @@ import copy import os import subprocess import time +import shlex def parse_arguments(): argparser = argparse.ArgumentParser(description="Run Vespa cppunit tests in parallell") @@ -14,7 +15,7 @@ def parse_arguments(): argparser.add_argument("--chunks", type=int, help="Number of chunks", default=5) args = argparser.parse_args() if args.chunks < 1: - raise RuntimeError, "I require at least one chunk" + raise RuntimeError("Error: Chunk size must be greater than 0") return args @@ -32,6 +33,20 @@ def chunkify(lst, chunks): return result +def error_if_file_not_found(function): + def wrapper(*args, **kwargs): + try: + return function(*args, **kwargs) + except OSError as e: + if e.errno == os.errno.ENOENT: # "No such file or directory" + print >>sys.stderr, "Error: could not find testrunner or valgrind executable" + sys.exit(1) + return wrapper + +@error_if_file_not_found +def get_test_suites(testrunner): + return subprocess.check_output((testrunner, "--list")).strip().split("\n") + class Process: def __init__(self, cmd, group): self.group = group @@ -43,13 +58,14 @@ class Process: stderr=subprocess.STDOUT, preexec_fn=os.setpgrp) +@error_if_file_not_found def build_processes(test_groups): valgrind = os.getenv("VALGRIND") - testrunner = (valgrind, args.testrunner) if valgrind else (args.testrunner,) + testrunner = shlex.split(valgrind) + [args.testrunner] if valgrind else [args.testrunner] processes = [] for group in test_groups: - cmd = testrunner + tuple(group) + cmd = testrunner + group processes.append(Process(cmd, group)) return processes @@ -63,8 +79,8 @@ def cleanup_processes(processes): print >>sys.stderr, e.message args = parse_arguments() -test_suites = subprocess.check_output((args.testrunner, "--list")).strip().split("\n") -test_suite_groups = chunkify(test_suites, min(len(test_suites), args.chunks)) +test_suites = get_test_suites(args.testrunner) +test_suite_groups = chunkify(test_suites, args.chunks) processes = build_processes(test_suite_groups) print "Running %d test suites in %d parallel chunks with ~%d tests each" % (len(test_suites), len(test_suite_groups), len(test_suite_groups[0])) @@ -85,7 +101,7 @@ while True: print "All test suites ran successfully" sys.exit(0) elif return_code is not None: - print "One of '%s' test suites failed:" % ", ".join(proc.group) + print "Error: one of '%s' test suites failed:" % ", ".join(proc.group) print >>sys.stderr, proc.output sys.exit(return_code) |