Skip to content

Commit

Permalink
#349: clean up gtest integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Jan 16, 2025
1 parent 8329d2f commit bf4c83c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 141 deletions.
35 changes: 21 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -143,17 +140,8 @@ 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)
Expand All @@ -162,17 +150,36 @@ 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)
Expand Down
35 changes: 0 additions & 35 deletions ci/deps/gtest.sh

This file was deleted.

1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
169 changes: 77 additions & 92 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit bf4c83c

Please sign in to comment.