diff options
Diffstat (limited to 'test/RegressTests.py')
-rwxr-xr-x | test/RegressTests.py | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/test/RegressTests.py b/test/RegressTests.py index a32bdb6b..0472ac90 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -5,18 +5,35 @@ import os import re import tempfile +multiproc = False +try: + from multiprocessing import Pool + multiproc = True +except: + pass + from string import join from difflib import unified_diff from LedgerHarness import LedgerHarness -harness = LedgerHarness(sys.argv) -tests = sys.argv[3] +args = sys.argv +jobs = 1 +match = re.match('-j([0-9]+)?', args[1]) +if match: + args = [args[0]] + args[2:] + if match.group(1): + jobs = int(match.group(1)) +if jobs == 1: + multiproc = False + +harness = LedgerHarness(args) +tests = args[3] if not os.path.isdir(tests) and not os.path.isfile(tests): sys.exit(1) -class RegressFile: +class RegressFile(object): def __init__(self, filename): self.filename = filename self.fd = open(self.filename) @@ -137,24 +154,36 @@ class RegressFile: if not use_stdin: os.remove(tempdata[1]) - def run_tests(self): + def run_tests(self, pool): test = self.read_test() while test: - self.run_test(test) + if pool: + pool.apply_async(RegressFile.run_test, (self, test,)) + else: + self.run_test(test) test = self.read_test(test) def close(self): self.fd.close() -if os.path.isdir(tests): - for test_file in os.listdir(tests): - if re.search('\.test$', test_file): - entry = RegressFile(os.path.join(tests, test_file)) - entry.run_tests() - entry.close() -else: - entry = RegressFile(tests) - entry.run_tests() - entry.close() - -harness.exit() +if __name__ == '__main__': + if multiproc: + pool = Pool(jobs*2) + else: + pool = None + + if os.path.isdir(tests): + for test_file in os.listdir(tests): + if re.search('\.test$', test_file): + entry = RegressFile(os.path.join(tests, test_file)) + entry.run_tests(pool) + entry.close() + else: + entry = RegressFile(tests) + entry.run_tests(pool) + entry.close() + + if pool: + pool.close() + pool.join() + harness.exit() |