n2p2: convert from old to new test API (#45141)
* n2p2: convert from old to new test API * n2p2: Enhance stand-alone testing checks to reduce unnecessary processing --------- Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
This commit is contained in:
parent
a965c7c5c8
commit
c624088a7b
@ -2,6 +2,7 @@
|
|||||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
import os
|
||||||
|
|
||||||
from spack.package import *
|
from spack.package import *
|
||||||
from spack.pkg.builtin.boost import Boost
|
from spack.pkg.builtin.boost import Boost
|
||||||
@ -59,16 +60,15 @@ class N2p2(MakefilePackage):
|
|||||||
|
|
||||||
def edit(self, spec, prefix):
|
def edit(self, spec, prefix):
|
||||||
makefile = FileFilter(join_path("src", "makefile"))
|
makefile = FileFilter(join_path("src", "makefile"))
|
||||||
makefile.filter("MODE=.*", "MODE={0}".format("shared" if "+shared" in spec else "static"))
|
makefile.filter("MODE=.*", f"MODE={'shared' if '+shared' in spec else 'static'}")
|
||||||
|
|
||||||
makefile = FileFilter(join_path("src", "makefile.gnu"))
|
makefile = FileFilter(join_path("src", "makefile.gnu"))
|
||||||
blas_libs = self.spec["blas"].libs
|
blas_libs = self.spec["blas"].libs
|
||||||
makefile.filter("PROJECT_CC=.*", "PROJECT_CC={0}".format(spack_cxx))
|
makefile.filter("PROJECT_CC=.*", f"PROJECT_CC={spack_cxx}")
|
||||||
makefile.filter("PROJECT_MPICC=.*", "PROJECT_MPICC={0}".format(self.spec["mpi"].mpicxx))
|
makefile.filter("PROJECT_MPICC=.*", f"PROJECT_MPICC={self.spec['mpi'].mpicxx}")
|
||||||
makefile.filter("PROJECT_CFLAGS=.*", "PROJECT_CFLAGS={0}".format(self.compiler.cxx11_flag))
|
makefile.filter("PROJECT_CFLAGS=.*", f"PROJECT_CFLAGS={self.compiler.cxx11_flag}")
|
||||||
makefile.filter(
|
makefile.filter(
|
||||||
"PROJECT_LDFLAGS_BLAS.*",
|
"PROJECT_LDFLAGS_BLAS.*", f"PROJECT_LDFLAGS_BLAS={blas_libs.ld_flags} -lgsl -lgslcblas"
|
||||||
"PROJECT_LDFLAGS_BLAS={0} -lgsl -lgslcblas".format(blas_libs.ld_flags),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def build(self, spec, prefix):
|
def build(self, spec, prefix):
|
||||||
@ -94,46 +94,62 @@ def install(self, spec, prefix):
|
|||||||
def setup_build_tests(self):
|
def setup_build_tests(self):
|
||||||
"""Copy the build test files after the package is installed to an
|
"""Copy the build test files after the package is installed to an
|
||||||
install test subdirectory for use during `spack test run`."""
|
install test subdirectory for use during `spack test run`."""
|
||||||
self.cache_extra_test_sources(".")
|
cache_extra_test_sources(self, ["."])
|
||||||
|
|
||||||
def test(self):
|
def test_result_check(self):
|
||||||
with working_dir(join_path(self.install_test_root, "test"), create=False):
|
"""Build and run result-check.sh"""
|
||||||
|
# The results cannot be verified with the script without an expected
|
||||||
|
# results file added to the test subdirectory of the package repository.
|
||||||
|
expected_file = join_path(
|
||||||
|
self.test_suite.current_test_data_dir, f"expected-result-{self.version}.txt"
|
||||||
|
)
|
||||||
|
if not os.path.exists(expected_file):
|
||||||
|
raise SkipTest(
|
||||||
|
f"The expected results file is missing from the repository for {self.version}"
|
||||||
|
)
|
||||||
|
|
||||||
|
result_check_script = join_path(self.test_suite.current_test_data_dir, "result-check.sh")
|
||||||
|
if not os.path.exists(result_check_script):
|
||||||
|
raise SkipTest("Required result-check.sh is missing from the repository directory")
|
||||||
|
|
||||||
|
make = which("make")
|
||||||
|
with working_dir(self.test_suite.current_test_cache_dir.test):
|
||||||
make("clean")
|
make("clean")
|
||||||
|
|
||||||
with working_dir(join_path(self.install_test_root, "src"), create=False):
|
with working_dir(self.test_suite.current_test_cache_dir.src):
|
||||||
make("clean")
|
make("clean")
|
||||||
make(
|
make(
|
||||||
"MODE=test",
|
"MODE=test",
|
||||||
"PROJECT_GSL={0}".format(self.spec["gsl"].prefix.include),
|
f"PROJECT_GSL={self.spec['gsl'].prefix.include}",
|
||||||
"PROJECT_EIGEN={0}".format(self.spec["eigen"].prefix.include.eigen3),
|
f"PROJECT_EIGEN={self.spec['eigen'].prefix.include.eigen3}",
|
||||||
)
|
)
|
||||||
make(
|
make(
|
||||||
"MODE=test",
|
"MODE=test",
|
||||||
"lammps-nnp",
|
"lammps-nnp",
|
||||||
"PROJECT_GSL={0}".format(self.spec["gsl"].prefix.include),
|
f"PROJECT_GSL={self.spec['gsl'].prefix.include}",
|
||||||
"PROJECT_EIGEN={0}".format(self.spec["eigen"].prefix.include.eigen3),
|
f"PROJECT_EIGEN={self.spec['eigen'].prefix.include.eigen3}",
|
||||||
)
|
)
|
||||||
make("pynnp", "MODE=test")
|
make("pynnp", "MODE=test")
|
||||||
|
|
||||||
with working_dir(join_path(self.install_test_root, "test"), create=False):
|
with working_dir(self.test_suite.current_test_cache_dir.test):
|
||||||
if self.spec.satisfies("%fj"):
|
if self.spec.satisfies("%fj"):
|
||||||
f = FileFilter(join_path("cpp", "nnp_test.h"))
|
f = FileFilter(join_path("cpp", "nnp_test.h"))
|
||||||
f.filter(
|
mpirun = self.spec["mpi"].prefix.bin.mpirun
|
||||||
"(example.co",
|
f.filter("(example.co", f'("{mpirun} -n 1 " + example.co', string=True)
|
||||||
'("{0} -n 1 " + example.co'.format(self.spec["mpi"].prefix.bin.mpirun),
|
|
||||||
string=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
cpp_output = "output_cpp.txt"
|
||||||
f = FileFilter(join_path("cpp", "makefile"))
|
f = FileFilter(join_path("cpp", "makefile"))
|
||||||
f.filter("log_level=.*", "log_level=$(LOG_LEVEL) 2>&1 | tee -a ../output_cpp.txt")
|
f.filter("log_level=.*", f"log_level=$(LOG_LEVEL) 2>&1 | tee -a ../{cpp_output}")
|
||||||
|
|
||||||
|
python_output = "output_python.txt"
|
||||||
f = FileFilter(join_path("python", "makefile"))
|
f = FileFilter(join_path("python", "makefile"))
|
||||||
f.filter("term\\s-v.*", "term -v | tee -a ../output_python.txt")
|
f.filter("term\\s-v.*", f"term -v | tee -a ../{python_output}")
|
||||||
|
|
||||||
make("cpp", parallel=False)
|
make("cpp", parallel=False)
|
||||||
make("python", parallel=False)
|
assert os.path.isfile(cpp_output), f"{cpp_output} was not produced"
|
||||||
|
|
||||||
test_dir = self.test_suite.current_test_data_dir
|
make("python", parallel=False)
|
||||||
expected_file = join_path(test_dir, "expected-result-{0}.txt".format(self.version))
|
assert os.path.isfile(python_output), f"{python_output} was not produced"
|
||||||
check_n2p2 = Executable(join_path(test_dir, "result-check.sh"))
|
|
||||||
check_n2p2("./output_cpp.txt", "./output_python.txt", expected_file)
|
result_check = which(result_check_script)
|
||||||
|
result_check(cpp_output, python_output, expected_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user