From 29549a502ffb6c647e12b12d8d671d4533d0d10f Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 12 Aug 2024 11:02:26 +0200 Subject: [PATCH 1/3] add gtests --- CMakeLists.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f08fa4c..1e5d9d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,12 @@ option(INSTALL_WITH_RPATH "RPATH the build dependencies for e.g dlb into the sha # Other options option(WITH_MPI "Compile with MPI" OFF) + +option(WITH_TESTS "Add Tests" ON) option(WITH_MPI_TESTS "Add MPI Tests. Requires mpirun to be working" ON) + if(BUILD_C_FORTRAN) enable_language(Fortran) set(CMAKE_Fortran_FORMAT FREE) @@ -89,7 +92,6 @@ endif() include(FetchContent) - # Define the PathTOJson variable with an empty default value set(NLOHMAN_JSON_PATH "" CACHE STRING "Path to the local nlohmann json release file") @@ -116,9 +118,18 @@ target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json) add_subdirectory(src) -enable_testing() -add_subdirectory(tests) +if(WITH_TESTS) + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + ) + FetchContent_MakeAvailable(googletest) + + enable_testing() + add_subdirectory(tests) +endif() # # Install Targets for nesmik -- GitLab From d0f2e89a8808d33e8baf3acc639ace85eacce5b2 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 12 Aug 2024 11:02:36 +0200 Subject: [PATCH 2/3] make it const & --- src/backends/wrappers/extrae/paraver_config.cpp | 2 +- src/backends/wrappers/extrae/paraver_config.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/wrappers/extrae/paraver_config.cpp b/src/backends/wrappers/extrae/paraver_config.cpp index a04799e..693ab15 100644 --- a/src/backends/wrappers/extrae/paraver_config.cpp +++ b/src/backends/wrappers/extrae/paraver_config.cpp @@ -62,7 +62,7 @@ ParaverConfig::ParaverConfig(const std::string &description) { config_ << head_with_description << "\n"; } -void ParaverConfig::addTimeline(ParaverTimelineWindow window_config) { +void ParaverConfig::addTimeline(const ParaverTimelineWindow &window_config) { assert(window_config.types.size() == window_config.semantic_maximums.size() && window_config.types.size() == window_config.window_names.size()); diff --git a/src/backends/wrappers/extrae/paraver_config.hpp b/src/backends/wrappers/extrae/paraver_config.hpp index 91d609f..23d0fee 100644 --- a/src/backends/wrappers/extrae/paraver_config.hpp +++ b/src/backends/wrappers/extrae/paraver_config.hpp @@ -24,6 +24,6 @@ class ParaverConfig { public: ParaverConfig(const std::string &description); - void addTimeline(ParaverTimelineWindow window_config); + void addTimeline(const ParaverTimelineWindow &window_config); std::string getString(); }; -- GitLab From 0a46ffe130b4adfad28329c84cf8e260d64c5694 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 12 Aug 2024 11:03:23 +0200 Subject: [PATCH 3/3] add test for paraver config --- tests/CMakeLists.txt | 5 ++ tests/backends/wrappers/CMakeLists.txt | 12 ++++ .../backends/wrappers/test_paraver_config.cpp | 66 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 tests/backends/wrappers/CMakeLists.txt create mode 100644 tests/backends/wrappers/test_paraver_config.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3840534..5c1c4be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,8 @@ + + +add_subdirectory(backends/wrappers) + + add_executable(TestCppLink cpp/TestCppLink.cpp) target_link_libraries(TestCppLink nesmik::nesmik) target_include_directories(TestCppLink diff --git a/tests/backends/wrappers/CMakeLists.txt b/tests/backends/wrappers/CMakeLists.txt new file mode 100644 index 0000000..1e41b48 --- /dev/null +++ b/tests/backends/wrappers/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable( + test_paraver_config + test_paraver_config.cpp +) +target_link_libraries( + test_paraver_config + GTest::gtest_main + nesmik::nesmik +) + +include(GoogleTest) +gtest_discover_tests(test_paraver_config) diff --git a/tests/backends/wrappers/test_paraver_config.cpp b/tests/backends/wrappers/test_paraver_config.cpp new file mode 100644 index 0000000..fe86635 --- /dev/null +++ b/tests/backends/wrappers/test_paraver_config.cpp @@ -0,0 +1,66 @@ +#include +#include + +#include + +using ::testing::HasSubstr; +class ParaverConfigTest : public testing::Test { + protected: + ParaverConfigTest() + : config_empty_description_{""}, + config_{"Paraver Configuration description"} {} + ParaverConfig config_empty_description_; + ParaverConfig config_; +}; + +TEST_F(ParaverConfigTest, HandlesEmptyTimelineWindow) { + ParaverTimelineWindow empty_window_not_stacked{ + .window_names = {}, + .types = {}, + .semantic_maximums = {}, + .stacked_window_name = std::nullopt}; + config_.addTimeline(empty_window_not_stacked); + EXPECT_THAT(config_.getString(), + HasSubstr("Paraver Configuration description")); + std::cout << config_.getString(); +} + +TEST_F(ParaverConfigTest, HandlesOneEvent) { + ParaverTimelineWindow window{.window_names = {"TestWindowName"}, + .types = {709888}, + .semantic_maximums = {19}, + .stacked_window_name = std::nullopt}; + config_.addTimeline(window); + EXPECT_THAT(config_.getString(), HasSubstr("TestWindowName")); + EXPECT_THAT(config_.getString(), HasSubstr("709888")); + EXPECT_THAT(config_.getString(), HasSubstr("19")); +} + +TEST_F(ParaverConfigTest, HandlesMultipleEvents) { + ParaverTimelineWindow window{ + .window_names = {"TestWindowName", "TestWindow2"}, + .types = {709888, 828377}, + .semantic_maximums = {19, 90}, + .stacked_window_name = std::nullopt}; + config_.addTimeline(window); + EXPECT_THAT(config_.getString(), HasSubstr("TestWindowName")); + EXPECT_THAT(config_.getString(), HasSubstr("TestWindow2")); + EXPECT_THAT(config_.getString(), HasSubstr("709888")); + EXPECT_THAT(config_.getString(), HasSubstr("828377")); + EXPECT_THAT(config_.getString(), HasSubstr("90")); +} + +TEST_F(ParaverConfigTest, HandlesMultipleEventsWithStackedWindow) { + ParaverTimelineWindow window{ + .window_names = {"TestWindowName", "TestWindow2"}, + .types = {709888, 828377}, + .semantic_maximums = {19, 90}, + .stacked_window_name = {"Stacked Window Name"}}; + config_.addTimeline(window); + EXPECT_THAT(config_.getString(), HasSubstr("TestWindowName")); + EXPECT_THAT(config_.getString(), HasSubstr("TestWindow2")); + EXPECT_THAT(config_.getString(), HasSubstr("709888")); + EXPECT_THAT(config_.getString(), HasSubstr("828377")); + EXPECT_THAT(config_.getString(), HasSubstr("90")); + EXPECT_THAT(config_.getString(), HasSubstr("Stacked Window Name")); +} -- GitLab