-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from uliegecsm/add-google-test
tests: add Google Test and use it to test `space-time-stack` connector
- Loading branch information
Showing
7 changed files
with
124 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Look for Google Test and enable it as a target. | ||
# | ||
# The main targets that will be available are: | ||
# * GTest::gtest | ||
# * GTest::gmock | ||
# | ||
# References: | ||
# * https://github.com/google/googletest | ||
# * https://matgomes.com/integrate-google-test-into-cmake/ | ||
# * https://google.github.io/googletest/quickstart-cmake.html | ||
# * https://jeremimucha.com/2021/04/cmake-fetchcontent/ | ||
|
||
include(FetchContent) | ||
|
||
# Declare the Google Test dependency | ||
FetchContent_Declare( | ||
googletest | ||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG v1.14.0 | ||
) | ||
|
||
# If not yet populated, add Google Test to the build with the following options: | ||
# * disable installation of Google Test | ||
# * enable GMock | ||
# Note that we could have used FetchContent_MakeAvailable instead, but it would then | ||
# use the default configuration that would install Google Test. | ||
FetchContent_GetProperties(googletest) | ||
if (NOT googletest_POPULATED) | ||
FetchContent_Populate(googletest) | ||
|
||
set(BUILD_GMOCK ON) | ||
set(INSTALL_GTEST OFF) | ||
|
||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,61 @@ | ||
# Add an executable and its related test. | ||
# | ||
# The executable is always linked to 'kokkostools' and 'test_common'. | ||
# | ||
# Arguments: | ||
# TARGET_NAME : name of the test (required) | ||
# SOURCE_FILE : source file, defaults to <TARGET_NAME>.cpp (optional) | ||
# KOKKOS_TOOLS_LIBS : the test environment will received the variable 'KOKKOS_TOOLS_LIBS' that is set as the path | ||
# to the target file of this argument (optional) | ||
function(kp_add_executable_and_test) | ||
|
||
cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS" "" ${ARGN}) | ||
|
||
if(NOT DEFINED kaeat_args_TARGET_NAME) | ||
message(FATAL_ERROR "'TARGET_NAME' is a required argument.") | ||
endif() | ||
|
||
if(NOT DEFINED kaeat_args_SOURCE_FILE) | ||
set(kaeat_args_SOURCE_FILE "${kaeat_args_TARGET_NAME}.cpp") | ||
endif() | ||
|
||
add_executable(${kaeat_args_TARGET_NAME}) | ||
|
||
target_sources( | ||
${kaeat_args_TARGET_NAME} | ||
PRIVATE | ||
${kaeat_args_SOURCE_FILE} | ||
) | ||
target_link_libraries( | ||
${kaeat_args_TARGET_NAME} | ||
PRIVATE | ||
kokkostools test_common | ||
) | ||
|
||
add_test( | ||
NAME ${kaeat_args_TARGET_NAME} | ||
COMMAND $<TARGET_FILE:${kaeat_args_TARGET_NAME}> | ||
) | ||
|
||
if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS) | ||
set_property( | ||
TEST ${kaeat_args_TARGET_NAME} | ||
APPEND | ||
PROPERTY | ||
ENVIRONMENT "KOKKOS_TOOLS_LIBS=$<TARGET_FILE:${kaeat_args_KOKKOS_TOOLS_LIBS}>" | ||
) | ||
endif() | ||
|
||
endfunction(kp_add_executable_and_test) | ||
|
||
# Create a test library that contains the required Kokkos and Google Test | ||
# initialization sequence. | ||
add_library(test_common OBJECT) | ||
target_sources( | ||
test_common | ||
PRIVATE | ||
UnitTestMain.cpp | ||
) | ||
target_link_libraries(test_common PUBLIC GTest::gtest GTest::gmock Kokkos::kokkos) | ||
|
||
add_subdirectory(space-time-stack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "Kokkos_Core.hpp" | ||
|
||
//! Main entry point for tests. | ||
int main(int argc, char* argv[]) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
||
auto success = RUN_ALL_TESTS(); | ||
|
||
return success; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,5 @@ | ||
# A function to add such "simple" tests in 'tests/CMakeLists.txt' might be a good option. | ||
add_executable(test_space_time_stack_demangling) | ||
target_sources( | ||
test_space_time_stack_demangling | ||
PRIVATE | ||
test_demangling.cpp | ||
) | ||
target_link_libraries( | ||
test_space_time_stack_demangling | ||
PRIVATE | ||
Kokkos::kokkos kokkostools | ||
) | ||
add_test( | ||
NAME test_space_time_stack_demangling | ||
COMMAND $<TARGET_FILE:test_space_time_stack_demangling> | ||
--kokkos-tools-libs=$<TARGET_FILE:kp_space_time_stack> | ||
--kokkos-tools-args=1e-9 | ||
kp_add_executable_and_test( | ||
TARGET_NAME test_space_time_stack_demangling | ||
SOURCE_FILE test_demangling.cpp | ||
KOKKOS_TOOLS_LIBS kp_space_time_stack | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters