blob: 1c14ba7deaa6a3dadbdb0c4a2fa23d14474069e2 [file] [log] [blame]
onqtamad89a132016-05-21 00:25:35 +03001#!/usr/bin/python
2
3import sys
4import math
5import multiprocessing
6import subprocess
7
onqtame4c75fc2016-05-21 01:24:48 +03008if len(sys.argv) < 2:
onqtamad89a132016-05-21 00:25:35 +03009 print("supply the path to the doctest executable as the first argument!")
onqtame4c75fc2016-05-21 01:24:48 +030010 sys.exit(1)
onqtamad89a132016-05-21 00:25:35 +030011
12# get the number of tests in the doctest executable
onqtame4c75fc2016-05-21 01:24:48 +030013num_tests = 0
14
onqtam1586ea22016-05-21 18:02:26 +030015program_with_args = [sys.argv[1], "--dt-count=1"]
onqtame4c75fc2016-05-21 01:24:48 +030016for i in range(2, len(sys.argv)):
17 program_with_args.append(sys.argv[i])
18
19result = subprocess.Popen(program_with_args, stdout = subprocess.PIPE).communicate()[0]
20result = result.splitlines(True)
21for line in result:
onqtam6c7369e2017-05-05 11:51:10 +030022 if line.startswith("[doctest] unskipped test cases passing the current filters:"):
onqtame4c75fc2016-05-21 01:24:48 +030023 num_tests = int(line.rsplit(' ', 1)[-1])
onqtamad89a132016-05-21 00:25:35 +030024
25# calculate the ranges
26cores = multiprocessing.cpu_count()
27l = range(num_tests + 1)
28n = int(math.ceil(float(len( l )) / cores))
29data = [l[i : i + n] for i in range(1, len( l ), n)]
30data = tuple([[x[0], x[-1]] for x in data])
31
32# for 8 cores and 100 tests the ranges will look like this
33# ([1, 13], [14, 26], [27, 39], [40, 52], [53, 65], [66, 78], [79, 91], [92, 100])
34
35# the worker callback that runs the executable for the given range of tests
36def worker((first, last)):
onqtam1586ea22016-05-21 18:02:26 +030037 program_with_args = [sys.argv[1], "--dt-first=" + str(first), "--dt-last=" + str(last)]
onqtame4c75fc2016-05-21 01:24:48 +030038 subprocess.Popen(program_with_args)
onqtamad89a132016-05-21 00:25:35 +030039
40# run the tasks on a pool
41if __name__ == '__main__':
42 p = multiprocessing.Pool(cores)
43 p.map(worker, data)