diff options
author | Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> | 2023-06-20 16:46:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-20 16:46:11 -0700 |
commit | 1b6e1fc8522772426e51319c3d9607b140bcba63 (patch) | |
tree | 18105bfd12c3afeb3b06a8c3aeca34f273d384ad /var | |
parent | 1376ec488799403d10880edb57473e47b99305e2 (diff) | |
download | spack-1b6e1fc8522772426e51319c3d9607b140bcba63.tar.gz spack-1b6e1fc8522772426e51319c3d9607b140bcba63.tar.bz2 spack-1b6e1fc8522772426e51319c3d9607b140bcba63.tar.xz spack-1b6e1fc8522772426e51319c3d9607b140bcba63.zip |
tests/superlu: convert to new stand-alone test process (#38404)
* superlu: convert to new stand-alone test process
* Bugfix/superlu: add BaseBuilder and move post-install work to it
Diffstat (limited to 'var')
-rw-r--r-- | var/spack/repos/builtin/packages/superlu/package.py | 164 |
1 files changed, 67 insertions, 97 deletions
diff --git a/var/spack/repos/builtin/packages/superlu/package.py b/var/spack/repos/builtin/packages/superlu/package.py index ec6d590d52..382e6eb411 100644 --- a/var/spack/repos/builtin/packages/superlu/package.py +++ b/var/spack/repos/builtin/packages/superlu/package.py @@ -4,8 +4,6 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) import os -from llnl.util import tty - import spack.build_systems.cmake import spack.build_systems.generic from spack.package import * @@ -21,6 +19,8 @@ class Superlu(CMakePackage, Package): tags = ["e4s"] + test_requires_compiler = True + version("6.0.0", sha256="5c199eac2dc57092c337cfea7e422053e8f8229f24e029825b0950edd1d17e8e") version( "5.3.0", @@ -43,7 +43,7 @@ class Superlu(CMakePackage, Package): ) build_system( - conditional("cmake", when="@5:"), conditional("autotools", when="@:4"), default="cmake" + conditional("cmake", when="@5:"), conditional("generic", when="@:4"), default="cmake" ) variant("pic", default=True, description="Build with position independent code") @@ -55,115 +55,85 @@ class Superlu(CMakePackage, Package): msg="Older SuperLU is incompatible with newer compilers", ) - test_requires_compiler = True - - # Pre-cmake installation method examples_src_dir = "EXAMPLE" - make_hdr_file = "make.inc" + def test_example(self): + """build and run test example""" + test_dir = join_path(self.test_suite.current_test_cache_dir, self.examples_src_dir) + test_exe = "superlu" + test_src = f"{test_exe}.c" + + if not os.path.isfile(join_path(test_dir, test_src)): + raise SkipTest(f"Cached {test_src} is missing") + + with working_dir(test_dir): + args = [] + if self.version < Version("5.2.2"): + args.append("HEADER=" + self.prefix.include) + args.append(test_exe) + + make = which("make") + make(*args) + + superlu = which(test_exe) + superlu() + + +class BaseBuilder(metaclass=spack.builder.PhaseCallbacksMeta): @run_after("install") - def cache_test_sources(self): - """Copy the example source files after the package is installed to an - install test subdirectory for use during `spack test run`.""" + def setup_standalone_tests(self): + """Set up and copy example source files after the package is installed + to an install test subdirectory for use during `spack test run`.""" + makefile = join_path(self.pkg.examples_src_dir, "Makefile") + if self.spec.satisfies("@5.2.2:"): # Include dir was hardcoded in 5.2.2 filter_file( - r"INCLUDEDIR = -I\.\./SRC", - "INCLUDEDIR = -I" + self.prefix.include, - join_path(self.examples_src_dir, "Makefile"), + r"INCLUDEDIR = -I\.\./SRC", "INCLUDEDIR = -I" + self.prefix.include, makefile ) - self.cache_extra_test_sources(self.examples_src_dir) - - def _generate_make_hdr_for_test(self): - config_args = [] - - # Define make.inc file - config_args.extend( - [ - "SuperLUroot = {0}".format(self.prefix), - "SUPERLULIB = {0}/libsuperlu.a".format(self.prefix.lib), - "BLASLIB = {0}".format(self.spec["blas"].libs.ld_flags), - "TMGLIB = libtmglib.a", - "LIBS = $(SUPERLULIB) $(BLASLIB)", - "ARCH = ar", - "ARCHFLAGS = cr", - "RANLIB = {0}".format("ranlib" if which("ranlib") else "echo"), - "CC = {0}".format(env["CC"]), - "FORTRAN = {0}".format(env["FC"]), - "LOADER = {0}".format(env["CC"]), - "CFLAGS = -O3 -DNDEBUG -DUSE_VENDOR_BLAS -DPRNTlevel=0 -DAdd_", - "NOOPTS = -O0", - ] - ) - - return config_args - - # Pre-cmake configuration - @when("@:4") - def _generate_make_hdr_for_test(self): + # Create the example makefile's include file and ensure the new file + # is the one use. + filename = "make.inc" config_args = [] + if self.spec.satisfies("@5:"): + lib = "libsuperlu.a" + else: + config_args.append("PLAT = _x86_64") + lib = f"libsuperlu_{self.spec.version}.a" + config_args.extend(self._make_hdr_for_test(lib)) - # Define make.inc file - config_args.extend( - [ - "PLAT = _x86_64", - "SuperLUroot = {0}".format(self.prefix), - "SUPERLULIB = {0}/libsuperlu_{1}.a".format(self.prefix.lib, self.spec.version), - "BLASLIB = {0}".format(self.spec["blas"].libs.ld_flags), - "TMGLIB = libtmglib.a", - "LIBS = $(SUPERLULIB) $(BLASLIB)", - "ARCH = ar", - "ARCHFLAGS = cr", - "RANLIB = {0}".format("ranlib" if which("ranlib") else "echo"), - "CC = {0}".format(env["CC"]), - "FORTRAN = {0}".format(env["FC"]), - "LOADER = {0}".format(env["CC"]), - "CFLAGS = -O3 -DNDEBUG -DUSE_VENDOR_BLAS -DPRNTlevel=0 -DAdd_", - "NOOPTS = -O0", - ] - ) - - return config_args - - def run_superlu_test(self, test_dir, exe, args): - if not self.run_test( - "make", - options=args, - purpose="test: compile {0} example".format(exe), - work_dir=test_dir, - ): - tty.warn("Skipping test: failed to compile example") - return - - if not self.run_test(exe, purpose="test: run {0} example".format(exe), work_dir=test_dir): - tty.warn("Skipping test: failed to run example") - - def test(self): - config_args = self._generate_make_hdr_for_test() - - # Write configuration options to make.inc file - make_file_inc = join_path(self.test_suite.current_test_cache_dir, self.make_hdr_file) - with open(make_file_inc, "w") as inc: + with open(join_path(self.pkg.examples_src_dir, filename), "w") as inc: for option in config_args: - inc.write("{0}\n".format(option)) + inc.write(f"{option}\n") - args = [] - if self.version < Version("5.2.2"): - args.append("HEADER=" + self.prefix.include) - args.append("superlu") + # change the path in the example's Makefile to the file written above + filter_file(r"include \.\./" + filename, "include ./" + filename, makefile) - test_dir = join_path(self.test_suite.current_test_cache_dir, self.examples_src_dir) - exe = "superlu" + # Cache the examples directory for use by stand-alone tests + self.pkg.cache_extra_test_sources(self.pkg.examples_src_dir) - if not os.path.isfile(join_path(test_dir, "{0}.c".format(exe))): - tty.warn("Skipping superlu test:" "missing file {0}.c".format(exe)) - return - - self.run_superlu_test(test_dir, exe, args) + def _make_hdr_for_test(self, lib): + """Standard configure arguments for make.inc""" + ranlib = "ranlib" if which("ranlib") else "echo" + return [ + f"SuperLUroot = {self.prefix}", + f"SUPERLULIB = {self.prefix.lib}/{lib}", + f"BLASLIB = {self.spec['blas'].libs.ld_flags}", + "TMGLIB = libtmglib.a", + "LIBS = $(SUPERLULIB) $(BLASLIB)", + "ARCH = ar", + "ARCHFLAGS = cr", + f"RANLIB = {ranlib}", + f"CC = {env['CC']}", + f"FORTRAN = {env['FC']}", + f"LOADER = {env['CC']}", + "CFLAGS = -O3 -DNDEBUG -DUSE_VENDOR_BLAS -DPRNTlevel=0 -DAdd_", + "NOOPTS = -O0", + ] -class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder): +class CMakeBuilder(BaseBuilder, spack.build_systems.cmake.CMakeBuilder): def cmake_args(self): if self.pkg.version > Version("5.2.1"): _blaslib_key = "enable_internal_blaslib" @@ -178,7 +148,7 @@ class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder): return args -class GenericBuilder(spack.build_systems.generic.GenericBuilder): +class GenericBuilder(BaseBuilder, spack.build_systems.generic.GenericBuilder): def install(self, pkg, spec, prefix): """Use autotools before version 5""" # Define make.inc file |