diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 11680e00f08cc7aa5ed80d9ed022fd3705bc8078..81d7553d5552133c35147fed3aa28c1fa571e2a1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,6 +45,7 @@ add_executable (unit_tests test_BinaryExpressionProcessor_equality.cpp test_BinaryExpressionProcessor_logic.cpp test_BiCGStab.cpp + test_BuildInfo.cpp test_BuiltinFunctionEmbedder.cpp test_BuiltinFunctionEmbedderTable.cpp test_BuiltinFunctionProcessor.cpp diff --git a/tests/test_BuildInfo.cpp b/tests/test_BuildInfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..36c8c79aac7c150764512dadab9306438b4432db --- /dev/null +++ b/tests/test_BuildInfo.cpp @@ -0,0 +1,70 @@ +#ifndef TEST_BUILD_INFO_HPP +#define TEST_BUILD_INFO_HPP + +#include <catch2/catch.hpp> + +#include <utils/BuildInfo.hpp> +#include <utils/pugs_build_info.hpp> +#include <utils/pugs_config.hpp> + +#include <sstream> + +#ifdef PUGS_HAS_MPI +#include <mpi.h> +#endif // PUGS_HAS_MPI + +#ifdef PUGS_HAS_PETSC +#include <petsc.h> +#endif // PUGS_HAS_PETSC + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("BuildInfo", "[utils]") +{ + SECTION("type") + { + REQUIRE(BuildInfo::type() == PUGS_BUILD_TYPE); + } + + SECTION("compiler") + { + std::stringstream compiler_info; + compiler_info << PUGS_BUILD_COMPILER << " (" << PUGS_BUILD_COMPILER_VERSION << ")" << std::ends; + REQUIRE(BuildInfo::compiler() == compiler_info.str()); + } + + SECTION("kokkos") + { + REQUIRE(BuildInfo::kokkosDevices() == PUGS_BUILD_KOKKOS_DEVICES); + } + + SECTION("mpi") + { +#ifdef PUGS_HAS_MPI + const std::string mpi_library = []() { + int length; + char mpi_version[MPI_MAX_LIBRARY_VERSION_STRING]; + MPI_Get_library_version(mpi_version, &length); + return std::string(mpi_version); + }(); + + REQUIRE(BuildInfo::mpiLibrary() == mpi_library); +#else + REQUIRE(BuildInfo::mpiLibrary() == "none"); +#endif // PUGS_HAS_MPI + } + + SECTION("petsc") + { +#ifdef PUGS_HAS_PETSC + const std::string petsc_library = std::to_string(PETSC_VERSION_MAJOR) + "." + std::to_string(PETSC_VERSION_MINOR) + + "." + std::to_string(PETSC_VERSION_SUBMINOR); + + REQUIRE(BuildInfo::petscLibrary() == petsc_library); +#else + REQUIRE(BuildInfo::petscLibrary() == "none"); +#endif // PUGS_HAS_PETSC + } +} + +#endif // TEST_BUILD_INFO_HPP