From a81d7e7ac7a56226683dde1865ffc77b9280a785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Thu, 16 Jan 2025 18:32:40 +0100 Subject: [PATCH] #349: clean up gtest integration --- CMakeLists.txt | 40 +++++----- ci/deps/gtest.sh | 35 --------- docker-compose.yml | 1 + tests/CMakeLists.txt | 169 ++++++++++++++++++++----------------------- 4 files changed, 98 insertions(+), 147 deletions(-) delete mode 100755 ci/deps/gtest.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 44fb1823..a5a0e86f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,9 +58,6 @@ if(magistrate_mpi_enabled) ) endif() -message (STATUS "Magistrate build tests: ${magistrate_tests_enabled}") -message (STATUS "Magistrate build examples: ${magistrate_examples_enabled}") - include(cmake/load_package.cmake) deprecated_option(checkpoint_doxygen_enabled magistrate_doxygen_enabled "Build doxygen documentation for magistrate" OFF) @@ -140,39 +137,42 @@ else() message(STATUS "Magistrate: building as top-level") endif() -# If magistrate build tests require the GTest package -if (${magistrate_tests_enabled}) - if(NOT hasParent) - find_package(GTest REQUIRED) - set(MAGISTRATE_HAS_GTEST TRUE) - else() - if (NOT DISABLE_TPL_GTEST) - set(MAGISTRATE_HAS_GTEST TRUE) - else() - set(MAGISTRATE_HAS_GTEST FALSE) - endif() - endif() -else() - set(MAGISTRATE_HAS_GTEST FALSE) -endif() - set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(PROJECT_EXAMPLE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples) set(PROJECT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) add_subdirectory(src) +message (STATUS "Magistrate build tests: ${magistrate_tests_enabled}") if (magistrate_tests_enabled AND "${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}") # CTest implies enable_testing() and defines the BUILD_TESTING option. # The default of BUILD_TESTING is ON. - # Testing is only enabled if the actual project being built is VT. + # Testing is only enabled if the actual project being built is magistrate. include(CTest) + find_package(GTest) + if (NOT GTest_FOUND) + include(FetchContent) + FetchContent_Declare( + googletest + DOWNLOAD_EXTRACT_TIMESTAMP FALSE + URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz + ) + FetchContent_MakeAvailable(googletest) + endif() + + message( + STATUS + "Magistrate: GTest package is found, unit tests are enabled " + "GTEST_ROOT=${GTEST_ROOT}" + ) + add_custom_target(magistrate_tests) add_subdirectory(tests) endif() +message (STATUS "Magistrate build examples: ${magistrate_examples_enabled}") if(magistrate_examples_enabled) add_custom_target(magistrate_examples) add_subdirectory(examples) diff --git a/ci/deps/gtest.sh b/ci/deps/gtest.sh deleted file mode 100755 index be586cb7..00000000 --- a/ci/deps/gtest.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -exo pipefail - -if test $# -lt 2 -then - echo "usage: ./$0 " - exit 1 -fi - -gtest_version=$1 -gtest_zip_name=release-${gtest_version}.zip - -build_dir=$2 - -echo "${gtest_version}" -echo "${gtest_zip_name}" - -wget "http://github.com/google/googletest/archive/${gtest_zip_name}" - -unzip "${gtest_zip_name}" - -mkdir -p "${build_dir}" -pushd "${build_dir}" - -export gtest=/googletest-release-${gtest_version} -export gtest_build=${build_dir}/gtest -mkdir -p "$gtest_build" -cd "$gtest_build" -mkdir build -cd build -cmake -G "${CMAKE_GENERATOR:-Ninja}" \ - -DCMAKE_INSTALL_PREFIX="$gtest_build/install" \ - "$gtest" -cmake --build . --target install diff --git a/docker-compose.yml b/docker-compose.yml index 961945c9..9b96f92f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,6 +56,7 @@ volumes: amd64-ubuntu-20.04-gcc-8-cache: amd64-ubuntu-20.04-gcc-9-cache: amd64-ubuntu-20.04-gcc-10-cache: + amd64-ubuntu-22.04-gcc-11-cache: amd64-ubuntu-18.04-icc-18-cache: amd64-ubuntu-18.04-icc-19-cache: amd64-ubuntu-20.04-nvcc-11.2-cache: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 107653ef..25e9e76c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,104 +38,89 @@ macro(magistrate_link_target target has_mpi) endif() endmacro() -if (magistrate_tests_enabled) - if (NOT MAGISTRATE_HAS_GTEST) - message( - STATUS - "Magistrate: Unit test are disabled because GoogleTest is not setup:" - "gtest_DIR=${gtest_DIR}" - ) - else() - message( - STATUS - "Magistrate: GTEST package is found: unit tests are enabled " - "gtest_DIR=${gtest_DIR}, GTEST_ROOT=${GTEST_ROOT}" - ) - set( - TEST_HEADER_FILES - ${PROJECT_TEST_UNIT_DIR}/test_commons.h - ${PROJECT_TEST_UNIT_DIR}/test_harness.h +set( + TEST_HEADER_FILES + ${PROJECT_TEST_UNIT_DIR}/test_commons.h + ${PROJECT_TEST_UNIT_DIR}/test_harness.h +) + +#System's threading library info (eg pthread) +find_package(Threads REQUIRED) + +if(magistrate_mpi_enabled) + set( + TEST_HEADER_FILES ${TEST_HEADER_FILES} + ${PROJECT_TEST_MPI_UNIT_DIR}/mpi-init.h + ${PROJECT_TEST_MPI_UNIT_DIR}/test_commons_mpi.h + ) +endif() + +set( + TEST_SOURCE_FILES + ${PROJECT_TEST_UNIT_DIR}/main.cc +) + +foreach(TEST_FULL ${PROJECT_TEST_LIST}) + GET_FILENAME_COMPONENT( + TEST + ${TEST_FULL} + NAME_WE + ) + + add_executable( + ${TEST} + ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES} + ${PROJECT_TEST_UNIT_DIR}/${TEST}.cc + ) + + add_dependencies(magistrate_tests ${TEST}) + magistrate_link_target(${TEST} 0) + + add_test( + magistrate:${TEST} + ${CMAKE_CURRENT_BINARY_DIR}/${TEST} + ) + + set_tests_properties( + magistrate:${TEST} + PROPERTIES TIMEOUT 60 + FAIL_REGULAR_EXPRESSION "FAILED;should be deleted but never is" + PASS_REGULAR_EXPRESSION "PASSED" + ) +endforeach() + +if(magistrate_mpi_enabled) + foreach(TEST_FULL ${PROJECT_TEST_LIST_MPI}) + GET_FILENAME_COMPONENT( + TEST + ${TEST_FULL} + NAME_WE ) - #System's threading library info (eg pthread) - find_package(Threads REQUIRED) + add_executable( + ${TEST} + ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES} + ${PROJECT_TEST_MPI_UNIT_DIR}/${TEST}.cc + ) - if(magistrate_mpi_enabled) - set( - TEST_HEADER_FILES ${TEST_HEADER_FILES} - ${PROJECT_TEST_MPI_UNIT_DIR}/mpi-init.h - ${PROJECT_TEST_MPI_UNIT_DIR}/test_commons_mpi.h - ) - endif() + magistrate_link_target(${TEST} 1) set( - TEST_SOURCE_FILES - ${PROJECT_TEST_UNIT_DIR}/main.cc + MAGISTRATE_TEST_PARAM_MPI ${MPI_NUMPROC_FLAG} + ${MAGISTRATE_MPI_PROC} "${CMAKE_CURRENT_BINARY_DIR}/${TEST}" + ) + add_test( + NAME magistrate:${TEST} + COMMAND ${MPI_RUN_COMMAND} ${MAGISTRATE_TEST_PARAM_MPI} ) - foreach(TEST_FULL ${PROJECT_TEST_LIST}) - GET_FILENAME_COMPONENT( - TEST - ${TEST_FULL} - NAME_WE - ) - - add_executable( - ${TEST} - ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES} - ${PROJECT_TEST_UNIT_DIR}/${TEST}.cc - ) - - add_dependencies(magistrate_tests ${TEST}) - magistrate_link_target(${TEST} 0) - - add_test( - magistrate:${TEST} - ${CMAKE_CURRENT_BINARY_DIR}/${TEST} - ) - - set_tests_properties( - magistrate:${TEST} - PROPERTIES TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "FAILED;should be deleted but never is" - PASS_REGULAR_EXPRESSION "PASSED" - ) - endforeach() - - if(magistrate_mpi_enabled) - foreach(TEST_FULL ${PROJECT_TEST_LIST_MPI}) - GET_FILENAME_COMPONENT( - TEST - ${TEST_FULL} - NAME_WE - ) - - add_executable( - ${TEST} - ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES} - ${PROJECT_TEST_MPI_UNIT_DIR}/${TEST}.cc - ) - - magistrate_link_target(${TEST} 1) - - set( - MAGISTRATE_TEST_PARAM_MPI ${MPI_NUMPROC_FLAG} - ${MAGISTRATE_MPI_PROC} "${CMAKE_CURRENT_BINARY_DIR}/${TEST}" - ) - add_test( - NAME magistrate:${TEST} - COMMAND ${MPI_RUN_COMMAND} ${MAGISTRATE_TEST_PARAM_MPI} - ) - - set_tests_properties( - magistrate:${TEST} - PROPERTIES TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "FAILED;should be deleted but never is" - PASS_REGULAR_EXPRESSION "PASSED" - ) - - endforeach() - endif() - endif() + set_tests_properties( + magistrate:${TEST} + PROPERTIES TIMEOUT 60 + FAIL_REGULAR_EXPRESSION "FAILED;should be deleted but never is" + PASS_REGULAR_EXPRESSION "PASSED" + ) + + endforeach() endif()