started new python script to run all tests with all compile options

This commit is contained in:
Bryan Herman 2014-02-25 09:31:52 -05:00
parent 6f0ce383be
commit 7dc74d067b

View file

@ -3,156 +3,104 @@
from __future__ import print_function
import os
import sys
import nose
import glob
import shutil
from subprocess import call
from subprocess import call
from collections import OrderedDict
from nose_mpi import NoseMPI
# Compiler paths
FC_DEFAULT='gfortran'
MPI_DIR='/opt/mpich/3.0.4-gnu'
HDF5_DIR='/opt/hdf5/1.8.12-gnu'
PHDF5_DIR='/opt/phdf5/1.8.12-gnu'
PETSC_DIR='/opt/petsc/3.4.3-gnu'
# Define test data structure
tests = OrderedDict()
def run_compile():
print('-'*17)
print('Compilation tests')
print('-'*17)
class Test(object):
def __init__(self, debug=False, optimize=False, mpi=False, openmp=False,
hdf5=False, petsc=False):
self.debug = debug
self.optimize = optimize
self.mpi = mpi
self.openmp = openmp
self.hdf5 = hdf5
self.petsc = petsc
self.success = True
self.setup_cmake()
# clean up all previous executables
openmc_exe = glob.glob(pwd + '/../src/openmc*')
for exe in openmc_exe:
os.remove(exe)
def setup_cmake(self):
# Default cmake
self.cmake = ['cmake','-H.','-Bbuild']
# run compile test
result = nose.run(argv=['nosetests', 'test_compile'] + flags)
if not result:
print('Did not pass compile tests.')
results.append(('compile', result))
def run_suite(name=None, mpi=False):
print('-'*(len(name) + 6))
print(name + ' tests')
print('-'*(len(name) + 6))
# Set arguments list. Note that the first argument is a dummy argument (the
# script name). It's not actually recursively calling run_tests.py
argv = ['nosetests', '--exclude', 'test_compile'] + flags
# Add MPI plugin if set
if mpi:
plugins = [NoseMPI()]
argv += ['--mpi-np', '3', '--mpi-exec', mpiexec]
else:
plugins = None
try:
os.chdir(pwd)
shutil.copyfile(pwd + '/../src/openmc-' + name, pwd + '/../src/openmc')
result = nose.run(argv=argv, addplugins=plugins)
except OSError:
result = False
print('No OpenMC executable found for ' + name + ' tests')
if not result:
print('Did not pass ' + name + ' tests')
results.append((name, result))
# set mpiexec path
if 'COMPILER' in os.environ:
compiler = os.environ['COMPILER']
else:
compiler = 'gnu'
mpiexec = '/opt/mpich/3.0.4-{0}/bin/mpiexec'.format(compiler)
# get current working directory
pwd = os.getcwd()
sys.path.append(pwd)
# Set list of tests, either default or from command line
flags = []
tests = ['compile', 'normal', 'debug', 'optimize',
'omp', 'omp-debug', 'omp-optimize',
'hdf5', 'hdf5-debug', 'hdf5-optimize',
'omp-hdf5', 'omp-hdf5-debug', 'omp-hdf5-optimize',
'mpi', 'mpi-debug', 'mpi-optimize',
'mpi-omp', 'mpi-omp-debug', 'mpi-omp-optimize',
'phdf5', 'phdf5-debug', 'phdf5-optimize',
'phdf5-omp', 'phdf5-omp-debug', 'phdf5-omp-optimize',
'petsc', 'petsc-debug', 'petsc-optimize',
'phdf5-petsc', 'phdf5-petsc-debug', 'phdf5-petsc-optimize',
'omp-phdf5-petsc', 'omp-phdf5-petsc-debug',
'omp-phdf5-petsc-optimize']
if len(sys.argv) > 1:
flags = [i for i in sys.argv[1:] if i.startswith('-')]
tests_ = [i for i in sys.argv[1:] if not i.startswith('-')]
# Check for special subsets of tests
tests__ = []
for i in tests_:
# All tests will run all the tests except for compile unless
# it is also specified on the command line. Note that specifying
# compile all-tests is the same as not specifying any args
if i == 'all-tests':
tests__ = tests
try:
idx = tests_.index('compile') # check for compile test
except ValueError:
del tests__[0]
finally:
break # don't need to check for anything else
# This checks for any subsets of tests. The string after
# all-XXXX will be used to search through all tests.
# Specifying XXXX=normal will run tests that don't contain
# debug or optimize substring.
if i.startswith('all-'):
suffix = i.split('all-')[1]
if suffix == 'normal':
for j in tests:
if j.rfind('debug') == -1 and \
j.rfind('optimize') == -1:
tests__.append(j)
else:
for j in tests:
if j.rfind(suffix) != -1:
if suffix == 'omp' and j == 'compile':
continue
tests__.append(j)
# Check for MPI/HDF5
if self.mpi and not self.hdf5:
self.fc = MPI_DIR+'/bin/mpif90'
elif not self.mpi and self.hdf5:
self.fc = HDF5_DIR+'/bin/h5fc'
elif self.mpi and self.hdf5:
self.fc = PHDF5_DIR+'/bin/h5pfc'
else:
tests__.append(i) # append specific test (e.g., mpi-debug)
tests = tests__ if tests__ else tests
self.fc = FC_DEFAULT
# Run tests
results = []
for name in tests:
if name == 'compile':
run_compile()
elif name in ['normal', 'debug', 'optimize',
'hdf5', 'hdf5-debug', 'hdf5-optimize',
'omp', 'omp-debug', 'omp-optimize',
'omp-hdf5', 'omp-hdf5-debug', 'omp-hdf5-optimize']:
run_suite(name=name)
elif name in ['mpi', 'mpi-debug', 'mpi-optimize',
'mpi-omp', 'mpi-omp-debug', 'mpi-omp-optimize',
'phdf5', 'phdf5-debug', 'phdf5-optimize',
'phdf5-omp', 'phdf5-omp-debug', 'phdf5-omp-optimize',
'petsc', 'petsc-debug', 'petsc-optimize',
'phdf5-petsc', 'phdf5-petsc-debug', 'phdf5-petsc-optimize',
'omp-phdf5-petsc', 'omp-phdf5-petsc-debug',
'omp-phdf5-petsc-optimize']:
run_suite(name=name, mpi=True)
# Set rest of options
if self.debug:
self.cmake.append('-Ddebug=on')
if self.optimize:
self.cmake.append('-Doptimize=on')
if self.openmp:
self.cmake.append('-Dopenmp=on')
if self.petsc:
self.cmake.append('-Dpetsc=on')
os.environ['PETSC_DIR'] = PETSC_DIR
# print out summary of results
print('\n' + '='*54)
print('Summary of Compilation Option Testing:\n')
def run_cmake(self):
os.environ['FC'] = self.fc
rc = call(self.cmake)
if rc != 0:
self.sucess = False
OK = '\033[92m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
for name, result in results:
print(name + '.'*(50 - len(name)), end='')
if result:
print(BOLD + OK + '[OK]' + ENDC)
else:
print(BOLD + FAIL + '[FAILED]' + ENDC)
def add_test(name, debug=False, optimize=False, mpi=False, openmp=False,\
hdf5=False, petsc=False):
tests.update({name:Test(debug, optimize, mpi, openmp, hdf5, petsc)})
# List of tests
add_test('normal')
add_test('debug', debug=True)
add_test('optimize', optimize=True)
add_test('omp-normal', openmp=True)
add_test('omp-debug', openmp=True, debug=True)
add_test('omp-optimize', openmp=True, optimize=True)
add_test('hdf5-normal', hdf5=True)
add_test('hdf5-debug', hdf5=True, debug=True)
add_test('hdf5-optimize', hdf5=True, optimize=True)
add_test('omp-hdf5-normal', openmp=True, hdf5=True)
add_test('omp-hdf5-debug', openmp=True, hdf5=True, debug=True)
add_test('omp-hdf5-optimize', openmp=True, hdf5=True, optimize=True)
add_test('mpi-normal', mpi=True)
add_test('mpi-debug', mpi=True, debug=True)
add_test('mpi-optimize', mpi=True, optimize=True)
add_test('mpi-omp-normal', mpi=True, openmp=True)
add_test('mpi-omp-debug', mpi=True, openmp=True, debug=True)
add_test('mpi-omp-optimize', mpi=True, openmp=True, optimize=True)
add_test('phdf5-normal', mpi=True, hdf5=True)
add_test('phdf5-debug', mpi=True, hdf5=True, debug=True)
add_test('phdf5-optimize', mpi=True, hdf5=True, optimize=True)
add_test('phdf5-omp-normal', mpi=True, hdf5=True, openmp=True)
add_test('phdf5-omp-debug', mpi=True, hdf5=True, openmp=True, debug=True)
add_test('phdf5-omp-optimize', mpi=True, hdf5=True, openmp=True, optimize=True)
add_test('petsc-normal', petsc=True, mpi=True)
add_test('petsc-debug', petsc=True, mpi=True, debug=True)
add_test('petsc-optimize', petsc=True, mpi=True, optimize=True)
add_test('phdf5-petsc-normal', mpi=True, hdf5=True, petsc=True)
add_test('phdf5-petsc-debug', mpi=True, hdf5=True, petsc=True, debug=True)
add_test('phdf5-petsc-optimize', mpi=True, hdf5=True, petsc=True, optimize=True)
add_test('omp-phdf5-petsc-normal', openmp=True, mpi=True, hdf5=True, petsc=True)
add_test('omp-phdf5-petsc-debug', openmp=True, mpi=True, hdf5=True, petsc=True, debug=True)
add_test('omp-phdf5-petsc-optimize', openmp=True, mpi=True, hdf5=True, petsc=True, optimize=True)
# Call tests
os.chdir('../src')
call(['make','distclean'])
for test in iter(tests):
tests[test].run_cmake()
call(['make','distclean'])