Skip to content
Snippets Groups Projects
Verified Commit 28c17c0e authored by René Fritze's avatar René Fritze
Browse files

move test distribution script to dune-xt

and pickle files to test dir
parent 449844bc
No related branches found
No related tags found
No related merge requests found
File deleted
#!/usr/bin/env python3
import os
import pickle
import sys
from pprint import pprint
import subprocess
import time
from contextlib import contextmanager
import binpacking
from multiprocessing import Pool, cpu_count
MAXTIME = 8*60
pickle_file = 'totals.pickle'
@contextmanager
def elapsed_timer():
clock = time.time
start = clock()
elapser = lambda: clock() - start
yield lambda: elapser()
end = clock()
elapser = lambda: end-start
def _compile(binary):
with elapsed_timer() as timer:
try:
_ = subprocess.check_output(['ninja', '-j1', binary], universal_newlines=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as cpe:
if 'Timeout' not in cpe.output:
raise cpe
print('Timeout in compile {}'.format(binary))
return timer()
def _run_tests(tpl):
binary, teststrings = tpl
testtimes = 0
for test in teststrings.split(';'):
with elapsed_timer() as timer:
try:
_ = subprocess.check_output(['ctest', '-j1', '-N', '-R', test], universal_newlines=True,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as cpe:
if 'Timeout' not in cpe.output:
raise cpe
# be pessimistic and double the timeout value as time for this run
testtimes += timer()
print('Timeout in {} from {}'.format(test, binary))
testtimes += timer()
return testtimes
def _redo(processes, keys, *args):
try:
with Pool(processes=processes) as pool:
result = pool.map(*args)
return {k: v for k,v in zip(keys, result)}
except subprocess.CalledProcessError as cpe:
print('*'*79)
print(cpe.stdout)
print(cpe.stderr)
print('*' * 79)
raise cpe
def do_timings(builddir, pickledir, binaries, testnames, processes):
os.chdir(builddir)
testlimit = -1
binaries = binaries[:testlimit]
compiles_fn = os.path.join(pickledir, 'compiles_' + pickle_file)
try:
compiles = pickle.load(open(compiles_fn, 'rb'))
if set(compiles.keys()) != set(binaries):
print('redoing compiles due to mismatched binaries')
compiles = _redo(processes, binaries, _compile, binaries)
except FileNotFoundError:
print('redoing compiles due to missing pickle')
compiles = _redo(processes, binaries, _compile, binaries)
pickle.dump(compiles, open(compiles_fn, 'wb'))
testnames = testnames[:testlimit]
testruns_fn = os.path.join(pickledir, 'testruns_' + pickle_file)
try:
loaded_testnames, testruns = pickle.load(open(testruns_fn, 'rb'))
if set(compiles.keys()) != set(binaries) or loaded_testnames != testnames:
print('redoing tests due to mismatched binaries/testnames')
testruns = _redo(processes, binaries, _run_tests, zip(binaries, testnames))
except FileNotFoundError:
print('redoing tests due to missing pickle')
testruns = _redo(processes, binaries, _run_tests, zip(binaries, testnames))
pickle.dump((testnames, testruns), open(testruns_fn, 'wb'))
totals = {n: compiles[n]+testruns[n] for n in binaries}
pickle.dump(totals, open(os.path.join(pickledir, pickle_file), 'wb'))
# print('totals')
# pprint(totals)
return totals
# list comes with a leading empty entry
all_testnames = sys.argv[4].split('/')[1:]
builddir = sys.argv[1]
module_root = sys.argv[2]
pickledir = os.path.join(module_root, 'cmake', 'scripts')
testdir = os.path.join(module_root, 'dune', 'gdt', 'test')
cmake_outfile = os.path.join(testdir, 'builder_definitions.cmake')
binaries = sys.argv[3].split(';')
testname_map = {b: t.split(';') for b,t in zip(binaries, all_testnames)}
processes = cpu_count()
totals = do_timings(builddir, pickledir, binaries, all_testnames, processes)
b = list(totals.keys())
bins = binpacking.to_constant_volume(totals, MAXTIME)
# for idx, bin in enumerate(bins):
# pprint('Bin {} vol: {}'.format(idx, sum(bin.values())))
# pprint(bin)
with open(cmake_outfile, 'wt') as out:
for idx, bin in enumerate(bins):
out.write('add_custom_target(test_binaries_builder_{} DEPENDS {})\n'.format(idx, ' '.join(bin.keys())))
for binary in bin.keys():
for testname in testname_map[binary]:
out.write('set_tests_properties({} PROPERTIES LABELS "builder_{}")\n'.format(testname, idx))
......@@ -12,15 +12,7 @@ BEGIN_TESTCASES()
END_TESTCASES()
set(DXT_TRAVIS_BUILDER 18)
set(current_idx 0)
foreach (target ${dxt_test_binaries})
set(all_sorted_testnames "${all_sorted_testnames}/${dxt_test_names_${target}}")
endforeach (target ${dxt_test_binaries})
add_custom_target(refresh_test_timings python3 ${CMAKE_SOURCE_DIR}/cmake/scripts/distribute_testing.py
"${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}" "${dxt_test_binaries}" "${all_sorted_testnames}" VERBATIM)
# generated from dune-xt-common's distribute_testing.py
include("builder_definitions.cmake")
# link spe10 data file if present
......
File added
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment