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