From 488d7582dff27919b99a6fa1819a14fd2a68b951 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sun, 2 Feb 2014 18:24:28 -0500 Subject: [PATCH] Convert test_compily.py to use cmake. --- tests/test_compile/test_compile.py | 307 ++++++++++++++++++----------- 1 file changed, 192 insertions(+), 115 deletions(-) diff --git a/tests/test_compile/test_compile.py b/tests/test_compile/test_compile.py index 8d411abd9..882a4795c 100644 --- a/tests/test_compile/test_compile.py +++ b/tests/test_compile/test_compile.py @@ -15,10 +15,11 @@ import shutil pwd = os.path.dirname(__file__) -if 'COMPILER' in os.environ: - compiler = 'COMPILER=' + os.environ['COMPILER'] -else: - compiler = 'COMPILER=gnu' +# Set default copmilers +fc = 'gfortran' +h5fc = 'h5fc' +h5pfc = 'h5pfc' +mpifc = 'mpif90' def setup(): @@ -27,257 +28,333 @@ def setup(): def test_normal(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler]) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -H. -Bbuild'.format(fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-normal') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-normal') def test_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Ddebug=on -H. -Bbuild'.format(fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-debug') def test_profile(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'PROFILE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dprofile=on -H. -Bbuild'.format(fc)) assert returncode == 0 + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-profile') def test_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Doptimize=on -H. -Bbuild'.format(fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-optimize') def test_mpi(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -H. -Bbuild'.format(mpifc)) assert returncode == 0 - shutil.move('openmc', 'openmc-mpi') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-mpi') def test_mpi_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Ddebug=on -H. -Bbuild'.format(mpifc)) assert returncode == 0 - shutil.move('openmc', 'openmc-mpi-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-mpi-debug') def test_mpi_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Doptimize=on -H. -Bbuild'.format(mpifc)) assert returncode == 0 - shutil.move('openmc', 'openmc-mpi-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-mpi-optimize') def test_omp(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPENMP=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -H. -Bbuild'.format(fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-omp') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp') def test_omp_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPENMP=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Ddebug=on '.format(fc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-debug') def test_omp_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPENMP=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Doptimize=on '.format(fc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-optimize') def test_hdf5(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'HDF5=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -H. -Bbuild'.format(h5fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-hdf5') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-hdf5') def test_hdf5_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'HDF5=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Ddebug=on -H. -Bbuild'.format(h5fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-hdf5-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-hdf5-debug') def test_hdf5_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'HDF5=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Doptimize=on -H. -Bbuild'.format(h5fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-hdf5-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-hdf5-optimize') def test_omp_hdf5(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPENMP=yes', 'HDF5=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -H. -Bbuild'.format(h5fc)) assert returncode == 0 - shutil.move('openmc', 'openmc-omp-hdf5') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-hdf5') def test_omp_hdf5_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPENMP=yes', 'HDF5=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Ddebug=on '.format(h5fc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-hdf5-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-hdf5-debug') def test_omp_hdf5_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'OPENMP=yes', 'HDF5=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Doptimize=on '.format(h5fc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-hdf5-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-hdf5-optimize') def test_petsc(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'PETSC=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -H. -Bbuild'.format(mpifc)) assert returncode == 0 - shutil.move('openmc', 'openmc-petsc') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-petsc') def test_petsc_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'PETSC=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Ddebug=on '.format(mpifc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-petsc-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-petsc-debug') def test_petsc_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'PETSC=yes', - 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Doptimize=on '.format(mpifc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-petsc-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-petsc-optimize') def test_mpi_omp(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -H. -Bbuild'.format(mpifc)) assert returncode == 0 - shutil.move('openmc', 'openmc-mpi-omp') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-mpi-omp') def test_mpi_omp_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Ddebug=on '.format(mpifc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-mpi-omp-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-mpi-omp-debug') def test_mpi_omp_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Doptimize=on '.format(mpifc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-mpi-omp-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-mpi-omp-optimize') def test_mpi_hdf5(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -H. -Bbuild'.format(h5pfc)) assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5') def test_mpi_hdf5_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Ddebug=on -H. -Bbuild'.format(h5pfc)) assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-debug') def test_mpi_hdf5_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Doptimize=on -H. -Bbuild'.format(h5pfc)) assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-optimize') def test_mpi_omp_hdf5(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes', 'HDF5=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -H. -Bbuild'.format(h5pfc)) assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-omp') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-omp') def test_mpi_omp_hdf5_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes', 'HDF5=yes', - 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Ddebug=on '.format(h5pfc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-omp-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-omp-debug') def test_mpi_omp_hdf5_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes', 'HDF5=yes', - 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dopenmp=on -Doptimize=on '.format(h5pfc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-omp-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-omp-optimize') def test_mpi_hdf5_petsc(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'PETSC=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -H. -Bbuild'.format(h5pfc)) assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-petsc') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-petsc') def test_mpi_hdf5_petsc_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'PETSC=yes', - 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Ddebug=on '.format(h5pfc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-petsc-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-petsc-debug') def test_mpi_hdf5_petsc_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'PETSC=yes', - 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Doptimize=on '.format(h5pfc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-phdf5-petsc-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-phdf5-petsc-optimize') def test_mpi_omp_hdf5_petsc(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OMP=yes', 'HDF5=yes', - 'PETSC=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Dopenmp=on '.format(h5pfc) + + '-H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-phdf5-petsc') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-phdf5-petsc') def test_mpi_omp_hdf5_petsc_debug(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OMP=yes', 'HDF5=yes', - 'PETSC=yes', 'DEBUG=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Dopenmp=on '.format(h5pfc) + + '-Ddebug=on -H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-phdf5-petsc-debug') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-phdf5-petsc-debug') def test_mpi_omp_hdf5_petsc_optimize(): - returncode = run(['make', 'distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'OMP=yes', 'HDF5=yes', - 'PETSC=yes', 'OPTIMIZE=yes']) + shutil.rmtree('build', ignore_errors=True) + returncode = run('FC={0} cmake -Dpetsc=on -Dopenmp=on '.format(h5pfc) + + '-Doptimize=on -H. -Bbuild') assert returncode == 0 - shutil.move('openmc', 'openmc-omp-phdf5-petsc-optimize') + returncode = run('make -s -C build') + assert returncode == 0 + shutil.move('build/bin/openmc', 'openmc-omp-phdf5-petsc-optimize') def run(commands): - proc = Popen(commands, stderr=STDOUT, stdout=PIPE) + proc = Popen(commands, shell=True, stderr=STDOUT, stdout=PIPE) print(proc.communicate()[0]) returncode = proc.returncode return returncode def teardown(commands): - returncode = run(['make', 'distclean']) + shutil.rmtree('build', ignore_errors=True) shutil.copy('openmc-normal', 'openmc')