diff --git a/tests/nose_mpi.py b/tests/nose_mpi.py new file mode 100644 index 0000000000..70cea8936e --- /dev/null +++ b/tests/nose_mpi.py @@ -0,0 +1,41 @@ +import os +import logging +from nose.plugins import Plugin + +log = logging.getLogger('nose.plugins.nose_mpi') + +class NoseMPI(Plugin): + + mpi_np = "0" + mpi_exec = "/opt/mpich/3.0.4-gnu/bin/mpiexec" + + def options(self, parser, env=os.environ): + """Define the command line options for plugin.""" + super(NoseMPI, self).options(parser, env) + + parser.add_option( + "--mpi-np", dest="mpi_np", default=0, + help="Number of MPI processors to execute OpenMC executable.") + + parser.add_option( + "--mpi-exec", dest="mpi_exec", + default="/opt/mpich/3.0.4-gnu/bin/mpiexec", + help="Absolute path to mpiexec file.") + + def configure(self, options, conf): + """Configure plugin based on command line options""" + super(NoseMPI, self).configure(options, conf) + + try: + mpi_np = int(options.mpi_np) + self.enabled = True + NoseMPI.mpi_np = options.mpi_np + except: + self.enabled = False + return + + if not os.path.exists(options.mpi_exec): + print 'Need to specify valid mpiexec path.' + exit() + + NoseMPI.mpi_exec = options.mpi_exec diff --git a/tests/run_tests.py b/tests/run_tests.py new file mode 100644 index 0000000000..5c2f70ca3f --- /dev/null +++ b/tests/run_tests.py @@ -0,0 +1,94 @@ +#!/bin/sh env python + +# load in packages +import os +import sys +import nose +from subprocess import call + +pwd = os.getcwd() + +# run compile test +result = nose.run(argv=['run_tests.py','-v','test_compile']) +if not result: + sys.exit('Did not pass compile tests.') + +# run gfortran tests +print '\n--------------' +print 'gfortran tests' +print '--------------\n' +os.chdir(pwd) +os.rename(pwd + '/../src/openmc-gfortran', pwd + '/../src/openmc') +result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile','test_basic']) +if not result: + sys.exit('Did not pass gfortran tests') + +# run gfortran-dbg tests +print '\n--------------' +print 'gfortran-dbg tests' +print '--------------\n' +os.rename(pwd + '/../src/openmc-gfortran-dbg', pwd + '/../src/openmc') +result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile','test_basic']) +if not result: + sys.exit('Did not pass gfortran-dbg tests') + +# run gfortran-opt tests +print '\n--------------' +print 'gfortran-opt tests' +print '--------------\n' +os.rename(pwd + '/../src/openmc-gfortran-opt', pwd + '/../src/openmc') +result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile','test_basic']) +if not result: + sys.exit('Did not pass gfortran-opt tests') + +# run gfortran-hdf5 tests +print '\n--------------' +print 'gfortran-hdf5 tests' +print '--------------\n' +#os.rename(pwd + '/../src/openmc-gfortran-hdf5', pwd + '/../src/openmc') +#result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile','test_basic']) +#if not result: +# sys.exit('Did not pass gfortran-hdf5 tests') + +# run gfortran-mpi tests +print '\n--------------' +print 'gfortran-mpi tests' +print '--------------\n' +os.rename(pwd + '/../src/openmc-gfortran-mpi', pwd + '/../src/openmc') +result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile', + '--mpi-np','3','--mpi-exec', + '/opt/mpich/3.0.4-gnu/bin/mpiexec','test_basic']) +if not result: + sys.exit('Did not pass gfortran-mpi tests') + +# run gfortran-phdf5 tests +print '\n--------------' +print 'gfortran-phdf5 tests' +print '--------------\n' +#result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile', +# '--mpi-np','3','--mpi-exec', +# '/opt/mpich/3.0.4-gnu/bin/mpiexec','test_basic']) +#if not result: +# sys.exit('Did not pass gfortran-phdf5 tests') + +# run gfortran-petsc tests +print '\n--------------' +print 'gfortran-petsc tests' +print '--------------\n' +os.rename(pwd + '/../src/openmc-gfortran-petsc', pwd + '/../src/openmc') +result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile', + '--mpi-np','3','--mpi-exec', + '/opt/mpich/3.0.4-gnu/bin/mpiexec','test_basic']) +if not result: + sys.exit('Did not pass gfortran-petsc tests') + +# run gfortran-phdf5-petsc tests +print '\n--------------' +print 'gfortran-phdf5-petsc tests' +print '--------------\n' +os.rename(pwd + '/../src/openmc-gfortran-phdf5-petsc', pwd + '/../src/openmc') +result = nose.run(argv=['run_tests.py','-v','--exclude','test_compile', + '--mpi-np','3','--mpi-exec', + '/opt/mpich/3.0.4-gnu/bin/mpiexec','test_basic']) +if not result: + sys.exit('Did not pass gfortran-phdf5-petsc tests') diff --git a/tests/setup.py b/tests/setup.py new file mode 100644 index 0000000000..4adb1904b8 --- /dev/null +++ b/tests/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup +setup(name="nose-mpi", + entry_points = { + 'nose.plugins':['nose_mpi = nose_mpi:NoseMPI'] + }, + install_requires = ['nose'] +) diff --git a/tests/test_basic/test_basic.py b/tests/test_basic/test_basic.py index 44e8b681c2..4ca7f78045 100644 --- a/tests/test_basic/test_basic.py +++ b/tests/test_basic/test_basic.py @@ -3,6 +3,7 @@ import os from subprocess import Popen, STDOUT, PIPE import filecmp +from nose_mpi import NoseMPI pwd = os.path.dirname(__file__) @@ -11,7 +12,13 @@ def setup(): os.chdir(pwd) def test_run(): - proc = Popen([pwd + '/../../src/openmc'], stderr=STDOUT, stdout=PIPE) + + openmc_path = pwd + '/../../src/openmc' + if int(NoseMPI.mpi_np) > 0: + proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path], + stderr=STDOUT, stdout=PIPE) + else: + proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE) returncode = proc.wait() print(proc.communicate()[0]) assert returncode == 0 diff --git a/tests/test_compile/test_compile.py b/tests/test_compile/test_compile.py index 2f98532b5d..cfe8f31eea 100644 --- a/tests/test_compile/test_compile.py +++ b/tests/test_compile/test_compile.py @@ -29,6 +29,7 @@ def test_gfortran_debug(): returncode = run(['make','distclean']) returncode = run(['make', 'DEBUG=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-dbg') def test_gfortran_profile(): returncode = run(['make','distclean']) @@ -39,31 +40,37 @@ def test_gfortran_optimize(): returncode = run(['make','distclean']) returncode = run(['make', 'OPTIMIZE=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-opt') def test_gfortran_mpi(): returncode = run(['make','distclean']) returncode = run(['make', 'MPI=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-mpi') def test_gfortran_hdf5(): returncode = run(['make','distclean']) returncode = run(['make', 'HDF5=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-hdf5') def test_gfortran_petsc(): returncode = run(['make','distclean']) returncode = run(['make', 'MPI=yes', 'PETSC=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-petsc') def test_gfortran_mpi_hdf5(): returncode = run(['make','distclean']) returncode = run(['make', 'MPI=yes', 'HDF5=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-phdf5') def test_gfortran_mpi_hdf5_petsc(): returncode = run(['make','distclean']) returncode = run(['make', 'MPI=yes', 'HDF5=yes', 'PETSC=yes']) assert returncode == 0 + shutil.move('openmc', 'openmc-gfortran-phdf5-petsc') def test_intel(): returncode = run(['make','distclean'])