sundials: new test API (#45373)

* sundials: new test API

---------

Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
This commit is contained in:
AcriusWinter 2024-08-26 15:34:06 -07:00 committed by GitHub
parent a60d1084b1
commit c7001efeb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,8 +6,6 @@
import os import os
import sys import sys
from llnl.util import tty
from spack.package import * from spack.package import *
@ -348,7 +346,7 @@ def cmake_args(self):
args.extend( args.extend(
[ [
define("SUNDIALS_INDEX_SIZE", intsize), define("SUNDIALS_INDEX_SIZE", intsize),
define("SUNDIALS_INDEX_TYPE", "int{}_t".format(intsize)), define("SUNDIALS_INDEX_TYPE", f"int{intsize}_t"),
] ]
) )
@ -674,7 +672,7 @@ def filter_compilers(self):
f2003_files = [ f2003_files = [
"arkode/F2003_serial/Makefile", "arkode/F2003_serial/Makefile",
"cvode/F2003_serial/Makefile", "cvode/F2003_serial/Makefile",
"cvodes/F2003_serial/Makefike", "cvodes/F2003_serial/Makefile",
"ida/F2003_serial/Makefile", "ida/F2003_serial/Makefile",
"idas/F2003_serial/Makefile", "idas/F2003_serial/Makefile",
"kinsol/F2003_serial/Makefile", "kinsol/F2003_serial/Makefile",
@ -744,119 +742,95 @@ def libs(self):
@run_after("install") @run_after("install")
@on_package_attributes(run_tests=True) @on_package_attributes(run_tests=True)
def test_install(self): def check_test_install(self):
"""Perform make test_install.""" """Perform test_install on the build."""
with working_dir(self.build_directory): with working_dir(self.builder.build_directory):
make("test_install") make("test_install")
@property
def _smoke_tests(self):
# smoke_tests tuple: exe, args, purpose, use cmake (true/false)
smoke_tests = [
("nvector/serial/test_nvector_serial", ["10", "0"], "Test serial N_Vector", False)
]
if "+CVODE" in self.spec:
smoke_tests.append(("cvode/serial/cvAdvDiff_bnd", [], "Test CVODE", True))
if "+cuda" in self.spec:
smoke_tests.append(
("nvector/cuda/test_nvector_cuda", ["10", "0", "0"], "Test CUDA N_Vector", True)
)
if "+CVODE" in self.spec:
smoke_tests.append(
("cvode/cuda/cvAdvDiff_kry_cuda", [], "Test CVODE with CUDA", True)
)
if "+rocm" in self.spec:
smoke_tests.append(
("nvector/hip/test_nvector_hip", ["10", "0", "0"], "Test HIP N_Vector", True)
)
if "+CVODE" in self.spec:
smoke_tests.append(
("cvode/hip/cvAdvDiff_kry_hip", [], "Test CVODE with HIP", True)
)
if "+sycl" in self.spec:
smoke_tests.append(
("nvector/sycl/test_nvector_sycl", ["10", "0", "0"], "Test SYCL N_Vector")
)
if "+CVODE" in self.spec:
smoke_tests.append(
("cvode/sycl/cvAdvDiff_kry_sycl", [], "Test CVODE with SYCL", True)
)
return smoke_tests
@property @property
def _smoke_tests_path(self): def _smoke_tests_path(self):
# examples/smoke-tests are cached for testing # examples/smoke-tests are cached for testing
return self.prefix.examples return self.prefix.examples
# TODO: Replace this method and its 'get' use for cmake path with def run_example(self, exe_path, opts, cmake_bool):
# join_path(self.spec['cmake'].prefix.bin, 'cmake') once stand-alone """Common sundials test method"""
# tests can access build dependencies through self.spec['cmake'].
def cmake_bin(self, set=True):
"""(Hack) Set/get cmake dependency path."""
filepath = join_path(self.install_test_root, "cmake_bin_path.txt")
if set:
if not os.path.exists(self.install_test_root):
mkdirp(self.install_test_root)
with open(filepath, "w") as out_file:
cmake_bin = join_path(self.spec["cmake"].prefix.bin, "cmake")
out_file.write("{0}\n".format(cmake_bin))
elif os.path.isfile(filepath):
with open(filepath, "r") as in_file:
return in_file.read().strip()
@run_after("install")
def setup_smoke_tests(self):
if "+examples-install" in self.spec:
install_tree(self._smoke_tests_path, join_path(self.install_test_root, "testing"))
self.cmake_bin(set=True)
def build_smoke_tests(self):
cmake_bin = self.cmake_bin(set=False)
if not cmake_bin:
tty.msg("Skipping sundials test: cmake_bin_path.txt not found")
return
if "~examples-install" in self.spec: if "~examples-install" in self.spec:
tty.msg("Skipping sundials test: examples were not installed") raise SkipTest("Package must be installed with +examples-install")
return
for smoke_test in self._smoke_tests: (dirname, basename) = os.path.split(exe_path)
work_dir = join_path(self._smoke_tests_path, os.path.dirname(smoke_test[0])) srcpath = join_path(self._smoke_tests_path, dirname)
with working_dir(work_dir): if not os.path.exists(srcpath):
if smoke_test[3]: # use cmake raise SkipTest(f"Example '{basename}' source directory not found in {self.version}")
self.run_test(exe=cmake_bin, options=["."])
self.run_test(exe="make")
def run_smoke_tests(self): # copy the example's directory to the test stage
if "~examples-install" in self.spec: mkdirp(dirname)
return install_tree(srcpath, dirname)
for smoke_test in self._smoke_tests: # build and run the example
self.run_test( with working_dir(dirname):
exe=join_path(self._smoke_tests_path, smoke_test[0]), if cmake_bool:
options=smoke_test[1], deps = "sundials mpi"
status=[0], prefixes = ";".join([self.spec[x].prefix for x in deps.split()])
installed=True, cmake = self.spec["cmake"].command
skip_missing=True, cmake("-DCMAKE_PREFIX_PATH=" + prefixes, ".")
purpose=smoke_test[2],
make = which("make")
make()
exe = which(basename)
exe(*opts)
make("clean")
def test_nvector_serial(self):
"""build and run serial N_Vector"""
self.run_example(join_path("nvector", "serial", "test_nvector_serial"), ["10", "0"], False)
def test_cvadvdiff_serial(self):
"""build and run serial cvAdvDiff_bnd"""
if "+CVODE" not in self.spec:
raise SkipTest("Package must be installed with +CVODE")
self.run_example(join_path("cvode", "serial", "cvAdvDiff_bnd"), [], True)
def test_nvector_cuda(self):
"""build and run CUDA N_Vector"""
if "+cuda" not in self.spec:
raise SkipTest("Package must be installed with +cuda")
self.run_example(join_path("nvector", "cuda", "test_nvector_cuda"), ["10", "0", "0"], True)
def test_cvadvdiff_cuda(self):
"""build and run CUDA cvAdvDiff_kry"""
if "+cuda" not in self.spec or "+CVODE" not in self.spec:
raise SkipTest("Package must be installed with +cuda+CVODE")
self.run_example(join_path("cvode", "cuda", "cvAdvDiff_kry_cuda"), [], True)
def test_nvector_hip(self):
"""build and run ROCM N_Vector"""
if "+rocm" not in self.spec:
raise SkipTest("Package must be installed with +rocm")
self.run_example(join_path("nvector", "hip", "test_nvector_hip"), ["10", "0", "0"], True)
def test_cvadvdiff_hip(self):
"""build and run ROCM cvAdvDiff_kry"""
if "+rocm" not in self.spec or "+CVODE" not in self.spec:
raise SkipTest("Package must be installed with +rocm+CVODE")
self.run_example(join_path("cvode", "hip", "cvAdvDiff_kry_hip"), [], True)
def test_nvector_sycl(self):
"""build and run SYCL N_Vector"""
if "+sycl" not in self.spec:
raise SkipTest("Package must be installed with +sycl")
self.run_example(
join_path("nvector", "sycl", "test_nvector_sycl"), ["10", "0", "0"], False
) )
def clean_smoke_tests(self): def test_sycl_cvode(self):
if "~examples-install" in self.spec: """build and run SYCL cvAdvDiff_kry"""
return if "+sycl" not in self.spec or "+CVODE" not in self.spec:
raise SkipTest("Package must be installed with +sycl and +CVODE")
for smoke_test in self._smoke_tests: self.run_example(join_path("cvode", "sycl", "cvAdvDiff_kry_sycl"), [], True)
work_dir = join_path(self._smoke_tests_path, os.path.dirname(smoke_test[0]))
with working_dir(work_dir):
self.run_test(exe="make", options=["clean"])
def test(self):
self.build_smoke_tests()
self.run_smoke_tests()
self.clean_smoke_tests()
return