diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-15 01:41:51 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-15 01:49:18 -0400 |
commit | fa263e729c65e073950a15db11c149ebacba0937 (patch) | |
tree | 8aa9079aa0475cb6c6d0cb2ce1666c13fb3c0d59 /test/RegressTests.py | |
parent | f3bedb88b24ae8b2047ad86e57b161265c2812f5 (diff) | |
download | fork-ledger-fa263e729c65e073950a15db11c149ebacba0937.tar.gz fork-ledger-fa263e729c65e073950a15db11c149ebacba0937.tar.bz2 fork-ledger-fa263e729c65e073950a15db11c149ebacba0937.zip |
Tests run in parallel with using acprep -jX make
This is done using the multiprocessing library in Python 2.6. If that's
unavailable, this feature does nothing.
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() |