Strumpack: Changed old test method to new test method (#44874)
* added try except * Resolve style issues --------- Co-authored-by: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>
This commit is contained in:
parent
15a48990b6
commit
00663f29a9
@ -195,30 +195,14 @@ def test_data_dir(self):
|
|||||||
add_sparse = not self.spec.satisfies("@:5.1.1")
|
add_sparse = not self.spec.satisfies("@:5.1.1")
|
||||||
return join_path("examples", "sparse" if add_sparse else "", "data")
|
return join_path("examples", "sparse" if add_sparse else "", "data")
|
||||||
|
|
||||||
# TODO: Replace this method and its 'get' use for cmake path with
|
|
||||||
# join_path(self.spec['cmake'].prefix.bin, 'cmake') once stand-alone
|
|
||||||
# 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:
|
|
||||||
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))
|
|
||||||
else:
|
|
||||||
with open(filepath, "r") as in_file:
|
|
||||||
return in_file.read().strip()
|
|
||||||
|
|
||||||
@run_after("install")
|
@run_after("install")
|
||||||
def cache_test_sources(self):
|
def cache_test_sources(self):
|
||||||
"""Copy the example source files after the package is installed to an
|
"""Copy the example source 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([self.test_data_dir, self.test_src_dir])
|
self.cache_extra_test_sources([self.test_data_dir, self.test_src_dir])
|
||||||
|
|
||||||
# TODO: Remove once self.spec['cmake'] is available here
|
def _test_example(self, test_prog, test_cmd, test_args):
|
||||||
self.cmake_bin(set=True)
|
test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir)
|
||||||
|
|
||||||
def _test_example(self, test_prog, test_dir, test_cmd, test_args):
|
|
||||||
cmake_filename = join_path(test_dir, "CMakeLists.txt")
|
cmake_filename = join_path(test_dir, "CMakeLists.txt")
|
||||||
with open(cmake_filename, "w") as mkfile:
|
with open(cmake_filename, "w") as mkfile:
|
||||||
mkfile.write("cmake_minimum_required(VERSION 3.15)\n")
|
mkfile.write("cmake_minimum_required(VERSION 3.15)\n")
|
||||||
@ -229,50 +213,42 @@ def _test_example(self, test_prog, test_dir, test_cmd, test_args):
|
|||||||
"target_link_libraries({0} ".format(test_prog) + "PRIVATE STRUMPACK::strumpack)\n"
|
"target_link_libraries({0} ".format(test_prog) + "PRIVATE STRUMPACK::strumpack)\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Remove/replace once self.spec['cmake'] is available here
|
with working_dir(test_dir):
|
||||||
cmake_bin = self.cmake_bin(set=False)
|
opts = self.builder.std_cmake_args
|
||||||
|
opts += self.cmake_args()
|
||||||
|
opts += ["."]
|
||||||
|
cmake = self.spec["cmake"].command
|
||||||
|
cmake(*opts)
|
||||||
|
|
||||||
opts = self.std_cmake_args
|
make = which("make")
|
||||||
opts += self.cmake_args()
|
make(test_prog)
|
||||||
opts += ["."]
|
|
||||||
|
|
||||||
self.run_test(
|
with set_env(OMP_NUM_THREADS="1"):
|
||||||
cmake_bin,
|
exe = which(test_cmd)
|
||||||
opts,
|
exe(*test_args)
|
||||||
[],
|
|
||||||
installed=False,
|
|
||||||
purpose="test: generating makefile",
|
|
||||||
work_dir=test_dir,
|
|
||||||
)
|
|
||||||
self.run_test(
|
|
||||||
"make", test_prog, purpose="test: building {0}".format(test_prog), work_dir=test_dir
|
|
||||||
)
|
|
||||||
with set_env(OMP_NUM_THREADS="1"):
|
|
||||||
self.run_test(
|
|
||||||
test_cmd,
|
|
||||||
test_args,
|
|
||||||
installed=False,
|
|
||||||
purpose="test: running {0}".format(test_prog),
|
|
||||||
skip_missing=False,
|
|
||||||
work_dir=test_dir,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test(self):
|
def test_sparse_seq(self):
|
||||||
"""Run the stand-alone tests for the installed software."""
|
"""Run sequential test_sparse"""
|
||||||
test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir)
|
|
||||||
test_exe = "test_sparse_seq"
|
|
||||||
test_exe_mpi = "test_sparse_mpi"
|
|
||||||
exe_arg = [join_path("..", self.test_data_dir, "pde900.mtx")]
|
|
||||||
if "+mpi" in self.spec:
|
if "+mpi" in self.spec:
|
||||||
test_args = ["-n", "1", test_exe_mpi]
|
raise SkipTest("Package must be installed with '~mpi'")
|
||||||
test_args.extend(exe_arg)
|
test_exe = "test_sparse_seq"
|
||||||
mpiexe_list = ["srun", "mpirun", "mpiexec"]
|
exe_arg = [join_path("..", self.test_data_dir, "pde900.mtx")]
|
||||||
for mpiexe in mpiexe_list:
|
self._test_example(test_exe, test_exe, exe_arg)
|
||||||
if which(mpiexe) is not None:
|
|
||||||
self._test_example(test_exe_mpi, test_dir, mpiexe, test_args)
|
def test_sparse_mpi(self):
|
||||||
break
|
"""Run parallel test_sparse"""
|
||||||
else:
|
if "+mpi" not in self.spec:
|
||||||
self._test_example(test_exe, test_dir, test_exe, exe_arg)
|
raise SkipTest("Package must be installed with '+mpi'")
|
||||||
|
test_exe_mpi = "test_sparse_mpi"
|
||||||
|
test_args = ["-n", "1", test_exe_mpi, join_path("..", self.test_data_dir, "pde900.mtx")]
|
||||||
|
mpiexe_list = ["srun", "mpirun", "mpiexec"]
|
||||||
|
for exe in mpiexe_list:
|
||||||
|
try:
|
||||||
|
self._test_example(test_exe_mpi, exe, test_args)
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
assert False, "No MPI executable was found"
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
"""Skip the builtin testsuite, use the stand-alone tests instead."""
|
"""Skip the builtin testsuite, use the stand-alone tests instead."""
|
||||||
|
Loading…
Reference in New Issue
Block a user