-
Notifications
You must be signed in to change notification settings - Fork 75
tests: add Google Test and use it to test space-time-stack connector
#237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.