blob: d29de5c49125781514f4576d5102a036a62a988d [file] [log] [blame]
onqtamad89a132016-05-21 00:25:35 +03001#!/usr/bin/python
2
3import sys
4import math
5import multiprocessing
6import subprocess
7
8if len(sys.argv) != 2:
9 print("supply the path to the doctest executable as the first argument!")
10 sys.exit(0)
11
12# get the number of tests in the doctest executable
13result = subprocess.Popen([sys.argv[1], "-count"], stdout = subprocess.PIPE).communicate()[0]
14num_tests = int(result.rsplit(' ', 1)[-1])
15
16# calculate the ranges
17cores = multiprocessing.cpu_count()
18l = range(num_tests + 1)
19n = int(math.ceil(float(len( l )) / cores))
20data = [l[i : i + n] for i in range(1, len( l ), n)]
21data = tuple([[x[0], x[-1]] for x in data])
22
23# for 8 cores and 100 tests the ranges will look like this
24# ([1, 13], [14, 26], [27, 39], [40, 52], [53, 65], [66, 78], [79, 91], [92, 100])
25
26# the worker callback that runs the executable for the given range of tests
27def worker((first, last)):
28 subprocess.Popen([sys.argv[1], "-first=%s -last=%s" % (first, last)])
29
30# run the tasks on a pool
31if __name__ == '__main__':
32 p = multiprocessing.Pool(cores)
33 p.map(worker, data)