From cba7e9bc87e1757d228aba9e29b271f8808d0f6c Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Tue, 15 Oct 2019 22:00:07 +0100 Subject: [PATCH] Added regression tests for dlopen source --- .../source_dlopen/inputs_true.dat | 23 ++++++ .../source_dlopen/results_true.dat | 0 .../source_dlopen}/source_sampling.cpp | 0 tests/regression_tests/source_dlopen/test.py | 70 +++++++++++++++++++ .../dlopen_source/test_dlopen_source.py | 57 --------------- 5 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 tests/regression_tests/source_dlopen/inputs_true.dat create mode 100644 tests/regression_tests/source_dlopen/results_true.dat rename tests/{unit_tests/dlopen_source => regression_tests/source_dlopen}/source_sampling.cpp (100%) create mode 100644 tests/regression_tests/source_dlopen/test.py delete mode 100644 tests/unit_tests/dlopen_source/test_dlopen_source.py diff --git a/tests/regression_tests/source_dlopen/inputs_true.dat b/tests/regression_tests/source_dlopen/inputs_true.dat new file mode 100644 index 0000000000..23f3d84384 --- /dev/null +++ b/tests/regression_tests/source_dlopen/inputs_true.dat @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + fixed source + 1000 + 10 + 0 + + diff --git a/tests/regression_tests/source_dlopen/results_true.dat b/tests/regression_tests/source_dlopen/results_true.dat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit_tests/dlopen_source/source_sampling.cpp b/tests/regression_tests/source_dlopen/source_sampling.cpp similarity index 100% rename from tests/unit_tests/dlopen_source/source_sampling.cpp rename to tests/regression_tests/source_dlopen/source_sampling.cpp diff --git a/tests/regression_tests/source_dlopen/test.py b/tests/regression_tests/source_dlopen/test.py new file mode 100644 index 0000000000..ac63ca8045 --- /dev/null +++ b/tests/regression_tests/source_dlopen/test.py @@ -0,0 +1,70 @@ +import openmc +import pytest +import os +import glob + +from tests.testing_harness import PyAPITestHarness + +# compile the external source +def compile_source(): + # first one should be CMakelists in share/ + files = glob.glob('../../../*/CMakeLists.txt') + assert len(files) != 0 + + # copy the cmakefile + status = os.system('rm -rf build') + assert os.WEXITSTATUS(status) == 0 + status = os.system('mkdir build ; cd build ; cp ../'+files[0]+' .') + assert os.WEXITSTATUS(status) == 0 + status = os.system('cd build ; cmake -DSOURCE_FILES=../source_sampling.cpp ; make') + assert os.WEXITSTATUS(status) == 0 + status = os.system('cp build/libsource.so .') + assert os.WEXITSTATUS(status) == 0 + status = os.system('rm -rf build') + assert os.WEXITSTATUS(status) == 0 + + return 0 + +class SourceTestHarness(PyAPITestHarness): + # build the test geometry + def _build_inputs(self): + mats = openmc.Materials() + + natural_lead = openmc.Material(1, "natural_lead") + natural_lead.add_element('Pb', 1,'ao') + natural_lead.set_density('g/cm3', 11.34) + mats.append(natural_lead) + + # surfaces + surface_sph1 = openmc.Sphere(r=100,boundary_type='vacuum') + volume_sph1 = -surface_sph1 + + # cell + cell_1 = openmc.Cell(region=volume_sph1) + cell_1.fill = natural_lead #assigning a material to a cell + universe = openmc.Universe(cells=[cell_1]) #hint, this list will need to include the new cell + geom = openmc.Geometry(universe) + + # settings + sett = openmc.Settings() + batches = 10 + sett.batches = batches + sett.inactive = 0 + sett.particles = 1000 + sett.particle = "neutron" + sett.run_mode = 'fixed source' + + #source + source = openmc.Source() + source.library = './libsource.so' + sett.source = source + + # run + model = openmc.model.Model(geom,mats,sett) + model.export_to_xml() + return + +def test_dlopen_source(): + compile_source() + harness = SourceTestHarness('statepoint.10.h5') + harness.main() diff --git a/tests/unit_tests/dlopen_source/test_dlopen_source.py b/tests/unit_tests/dlopen_source/test_dlopen_source.py deleted file mode 100644 index 917f3fd4fe..0000000000 --- a/tests/unit_tests/dlopen_source/test_dlopen_source.py +++ /dev/null @@ -1,57 +0,0 @@ -import openmc -import pytest -import os - -# compile the external source -def compile_source(): - # needs a more robust way to know where the - # Makefile is - status = os.system('cp /usr/local/share/Makefile .') - assert os.WEXITSTATUS(status) == 0 - status = os.system('make') - assert os.WEXITSTATUS(status) == 0 - - return - -# build the test geometry -def make_geometry(): - mats = openmc.Materials() - - natural_lead = openmc.Material(1, "natural_lead") - natural_lead.add_element('Pb', 1,'ao') - natural_lead.set_density('g/cm3', 11.34) - mats.append(natural_lead) - - # surfaces - surface_sph1 = openmc.Sphere(r=100) - volume_sph1 = -surface_sph1 - - # cell - cell_1 = openmc.Cell(region=volume_sph1) - cell_1.fill = natural_lead #assigning a material to a cell - universe = openmc.Universe(cells=[cell_1]) #hint, this list will need to include the new cell - geom = openmc.Geometry(universe) - - # settings - sett = openmc.Settings() - batches = 10 - sett.batches = batches - sett.inactive = 0 - sett.particles = 1000 - sett.particle = "neutron" - sett.run_mode = 'fixed source' - - #source - source = openmc.Source() - source.library = PATH+'source_sampling.so' - sett.source = source - - # run - model = openmc.model.Model(geom,mats,sett) - return model - -def test_dlopen_source(): - compile_source() - model = make_geometry() - model.run() -