From 5dc84b64e9a9c5de7c8ac365fe2fc90f58179d97 Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Wed, 5 Jul 2023 01:41:25 -0700 Subject: tests/qthreads: convert to new stand-alone test process (#38600) --- .../repos/builtin/packages/qthreads/package.py | 78 ++++++++++------------ 1 file changed, 35 insertions(+), 43 deletions(-) (limited to 'var') diff --git a/var/spack/repos/builtin/packages/qthreads/package.py b/var/spack/repos/builtin/packages/qthreads/package.py index 4dec1a5d67..048907b8fe 100644 --- a/var/spack/repos/builtin/packages/qthreads/package.py +++ b/var/spack/repos/builtin/packages/qthreads/package.py @@ -3,6 +3,8 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +import os + from spack.package import * @@ -30,8 +32,7 @@ class Qthreads(AutotoolsPackage): homepage = "http://www.cs.sandia.gov/qthreads/" test_requires_compiler = True - test_base_path = "test/basics/" - test_list = ["hello_world_multi", "hello_world"] + test_base_path = join_path("test", "basics") tags = ["e4s"] @@ -110,44 +111,35 @@ class Qthreads(AutotoolsPackage): def setup_build_tests(self): """Copy the build test files after the package is installed to an install test subdirectory for use during `spack test run`.""" - tests = self.test_list - relative_test_dir = self.test_base_path - files_to_cpy = [] - header = "test/argparsing.h" - for test in tests: - test_path = join_path(relative_test_dir, test + ".c") - files_to_cpy.append(test_path) - files_to_cpy.append(header) - self.cache_extra_test_sources(files_to_cpy) - - def build_tests(self): - """Build and run the added smoke (install) test.""" - tests = self.test_list - relative_test_dir = self.test_base_path - - for test in tests: - options = [ - "-I{0}".format(self.prefix.include), - "-I{0}".format(self.install_test_root + "/test"), - join_path(self.install_test_root, relative_test_dir, test + ".c"), - "-o", - test, - "-L{0}".format(self.prefix.lib), - "-lqthread", - "{0}{1}".format(self.compiler.cc_rpath_arg, self.prefix.lib), - ] - reason = "test:{0}: Checking ability to link to the library.".format(test) - self.run_test("cc", options, [], installed=False, purpose=reason) - - def run_tests(self): - tests = self.test_list - # Now run the program - for test in tests: - reason = "test:{0}: Checking ability to execute.".format(test) - self.run_test(test, [], purpose=reason) - - def test(self): - # Build - self.build_tests() - # Run test programs pulled from the build - self.run_tests() + self.cache_extra_test_sources([join_path("test", "argparsing.h"), self.test_base_path]) + + def _build_and_run_test(self, test): + """Build and run the test.""" + test_root = install_test_root(self) + options = [ + f"-I{self.prefix.include}", + f"-I{join_path(test_root, 'test')}", + join_path(test_root, self.test_base_path, f"{test}.c"), + "-o", + test, + f"-L{self.prefix.lib}", + "-lqthread", + f"{self.compiler.cc_rpath_arg}{self.prefix.lib}", + ] + cc = which(os.environ["CC"]) + cc(*options) + + exe = which(join_path(".", test)) + exe() + + def test_hello_world(self): + """build and run hello_world""" + self._build_and_run_test("hello_world") + + def test_hello_world_multi(self): + """build and run hello_world_multi""" + self._build_and_run_test("hello_world_multi") + + def test_qthread_id(self): + """build and run qthread_id""" + self._build_and_run_test("qthread_id") -- cgit v1.2.3-60-g2f50