Skip to content

Commit

Permalink
cxx: new test API (spack#45462)
Browse files Browse the repository at this point in the history
* cxx: new test API
* gcc: provide cxx
* default providers:  cxx provided by gcc
* cxx: cleanup stand-alone test
  - test_c -> test_cxx
  - simplify compilation and execution
  - corrected output checks

---------

Co-authored-by: Tamara Dahlgren <[email protected]>
  • Loading branch information
AcriusWinter and tldahlgren authored Aug 9, 2024
1 parent 7bec524 commit 899ac78
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions etc/spack/defaults/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ packages:
awk: [gawk]
armci: [armcimpi]
blas: [openblas, amdblis]
cxx: [gcc]
D: [ldc]
daal: [intel-oneapi-daal]
elf: [elfutils]
Expand Down
45 changes: 22 additions & 23 deletions var/spack/repos/builtin/packages/cxx/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ class Cxx(Package):
homepage = "https://isocpp.org/std/the-standard"
virtual = True

def test(self):
test_source = self.test_suite.current_test_data_dir
def test_cxx(self):
"""Compile and run 'Hello World'"""
cxx = which(os.environ["CXX"])
expected = ["Hello world", "YES!"]

test_source = self.test_suite.current_test_data_dir
for test in os.listdir(test_source):
filepath = os.path.join(test_source, test)
exe_name = "%s.exe" % test

cxx_exe = os.environ["CXX"]

# standard options
# Hack to get compiler attributes
# TODO: remove this when compilers are dependencies
c_name = clang if self.spec.satisfies("llvm+clang") else self.name
c_spec = spack.spec.CompilerSpec(c_name, self.spec.version)
c_cls = spack.compilers.class_for_compiler_name(c_name)
compiler = c_cls(c_spec, None, None, ["fakecc", "fakecxx"])

cxx_opts = [compiler.cxx11_flag] if "c++11" in test else []

cxx_opts += ["-o", exe_name, filepath]
compiled = self.run_test(cxx_exe, options=cxx_opts, installed=True)

if compiled:
expected = ["Hello world", "YES!"]
self.run_test(exe_name, expected=expected)
exe_name = f"{test}.exe"
filepath = test_source.join(test)
with test_part(self, f"test_cxx_{test}", f"build and run {exe_name}"):
# standard options
# Hack to get compiler attributes
# TODO: remove this when compilers are dependencies
c_name = clang if self.spec.satisfies("llvm+clang") else self.name
c_spec = spack.spec.CompilerSpec(c_name, self.spec.version)
c_cls = spack.compilers.class_for_compiler_name(c_name)
compiler = c_cls(c_spec, None, None, ["fakecc", "fakecxx"])
cxx_opts = [compiler.cxx11_flag] if "c++11" in test else []
cxx_opts += ["-o", exe_name, filepath]

cxx(*cxx_opts)
exe = which(exe_name)
out = exe(output=str.split, error=str.split)
check_outputs(expected, out)
2 changes: 2 additions & 0 deletions var/spack/repos/builtin/packages/gcc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage, CompilerPackage):

license("GPL-2.0-or-later AND LGPL-2.1-or-later")

provides("cxx")

version("master", branch="master")

version("14.2.0", sha256="a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9")
Expand Down

0 comments on commit 899ac78

Please sign in to comment.