diff --git a/CMakeLists.txt b/CMakeLists.txt index f08fa4cc9cb9d596407cb56f0e876f62a35957e6..1e5d9d8c5d2d0edd28737d8c0470cecfff7747ee 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 diff --git a/src/backends/wrappers/extrae/paraver_config.cpp b/src/backends/wrappers/extrae/paraver_config.cpp index a04799e7bc5154aa061f0ab244b00fe9a537c162..693ab15e763ffa53d59902f6704128fd1aa2fd50 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 91d609f97ec36551e7e7b9c51edacac468353283..23d0feea88a6e0f8e325535057d90e942840b282 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(); }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 384053429942e9a7ca5d6aae9b6b43be418d5862..5c1c4be270cb7ae38c8930b93e4b6fa7df754b2e 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 0000000000000000000000000000000000000000..1e41b48b23dc0f825f9dce75b666388c258498f8 --- /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 0000000000000000000000000000000000000000..fe86635c2bde5fa982583c892aa745e75e67c9c5 --- /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")); +}