Mixed parallel and non-parallel tests are possible.

pull/15/head
Jussi Pakkanen 12 years ago
parent d6f94cc6ce
commit 26bf87d1dc
  1. 26
      meson_test.py

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys, subprocess, time, datetime, pickle, multiprocessing import sys, os, subprocess, time, datetime, pickle, multiprocessing
import concurrent.futures as conc import concurrent.futures as conc
from optparse import OptionParser from optparse import OptionParser
@ -77,6 +77,11 @@ def print_stats(numlen, tests, name, result, i, logfile):
print(result_str) print(result_str)
write_log(logfile, name, result_str, result.stdo, result.stde) write_log(logfile, name, result_str, result.stdo, result.stde)
def drain_futures(futures):
for i in futures:
(result, numlen, tests, name, result, i, logfile) = i
print_stats(numlen, tests, name, result.result(), i, logfile)
def run_tests(options, datafilename): def run_tests(options, datafilename):
logfile_base = 'meson-logs/testlog' logfile_base = 'meson-logs/testlog'
if options.wrapper is None: if options.wrapper is None:
@ -89,6 +94,13 @@ def run_tests(options, datafilename):
logfile.write('Log of Meson test suite run on %s.\n\n' % datetime.datetime.now().isoformat()) logfile.write('Log of Meson test suite run on %s.\n\n' % datetime.datetime.now().isoformat())
tests = pickle.load(open(datafilename, 'rb')) tests = pickle.load(open(datafilename, 'rb'))
numlen = len('%d' % len(tests)) numlen = len('%d' % len(tests))
varname = 'MESON_TESTTHREADS'
if varname in os.environ:
try:
num_workers = int(os.environ[varname])
except ValueError:
write_log('Invalid value in %s, using 1 thread.' % varname)
else:
num_workers = multiprocessing.cpu_count() num_workers = multiprocessing.cpu_count()
executor = conc.ThreadPoolExecutor(max_workers=num_workers) executor = conc.ThreadPoolExecutor(max_workers=num_workers)
futures = [] futures = []
@ -97,12 +109,16 @@ def run_tests(options, datafilename):
fname = test[1] fname = test[1]
is_cross = test[2] is_cross = test[2]
exe_runner = test[3] exe_runner = test[3]
is_parallel = True is_parallel = False
if not is_parallel:
drain_futures(futures)
futures = []
f = run_single_test(wrap, fname, is_cross, exe_runner)
print_stats(numlen, tests, name, f, i, logfile)
else:
f = executor.submit(run_single_test, wrap, fname, is_cross, exe_runner) f = executor.submit(run_single_test, wrap, fname, is_cross, exe_runner)
futures.append((f, numlen, tests, name, f, i, logfile)) futures.append((f, numlen, tests, name, f, i, logfile))
for i in futures: drain_futures(futures)
(f, numlen, tests, name, result, i, logfile) = i
print_stats(numlen, tests, name, result.result(), i, logfile)
print('\nFull log written to %s.' % logfilename) print('\nFull log written to %s.' % logfilename)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save