From bb9ae05f764cf3f182f3de01aae1268fc8e0833e Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Mon, 16 Sep 2024 21:39:45 +0200 Subject: [PATCH] ci --- ci/run_ctests.sh | 14 ++++++++++++-- cpp/CMakeLists.txt | 1 - cpp/examples/CMakeLists.txt | 30 ++++++++++++++++++------------ cpp/tests/CMakeLists.txt | 3 ++- cpp/tests/utils.hpp | 13 ++++++++----- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/ci/run_ctests.sh b/ci/run_ctests.sh index 069490facf..02266145c9 100755 --- a/ci/run_ctests.sh +++ b/ci/run_ctests.sh @@ -6,5 +6,15 @@ set -euo pipefail # Support customizing the ctests' install location cd "${INSTALL_PREFIX:-${CONDA_PREFIX:-/usr}}/bin/tests/libkvikio/" -# Run BASIC_IO_TEST -./BASIC_IO_TEST +# Run basic tests +rapids-logger "Run BASIC_IO_EXAMPLE" +./BASIC_IO_EXAMPLE +rapids-logger "Run BASIC_NO_CUDA_EXAMPLE" +./BASIC_NO_CUDA_EXAMPLE + +# Run gtests +rapids-logger "Run gtests" +./cpp_tests +# TODO: how to use ctest instead of executing the test directly? +# The following line fails with a "ctest doesn't exist" in CI. +# ctest --no-tests=error --output-on-failure "$@" diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 37ae89ab2b..780efa4b2e 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -143,7 +143,6 @@ if(KvikIO_BUILD_TESTS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(${rapids-cmake-dir}/cpm/gtest.cmake) rapids_cpm_gtest(BUILD_STATIC) include(CTest) # calls enable_testing() - add_subdirectory(tests) endif() diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt index c12ddb2e52..5124c9ef71 100644 --- a/cpp/examples/CMakeLists.txt +++ b/cpp/examples/CMakeLists.txt @@ -14,19 +14,23 @@ set(TEST_INSTALL_PATH bin/tests/libkvikio) +# Example: basic_io + if(CUDAToolkit_FOUND) - add_executable(BASIC_IO_TEST basic_io.cpp) - set_target_properties(BASIC_IO_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib") - target_include_directories(BASIC_IO_TEST PRIVATE ../include ${cuFile_INCLUDE_DIRS}) - target_link_libraries(BASIC_IO_TEST PRIVATE kvikio CUDA::cudart) + add_executable(BASIC_IO_EXAMPLE basic_io.cpp) + set_target_properties(BASIC_IO_EXAMPLE PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib") + target_include_directories(BASIC_IO_EXAMPLE PRIVATE ../include ${cuFile_INCLUDE_DIRS}) + target_link_libraries(BASIC_IO_EXAMPLE PRIVATE kvikio CUDA::cudart) if(CMAKE_COMPILER_IS_GNUCXX) set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas") - target_compile_options(BASIC_IO_TEST PRIVATE "$<$:${KVIKIO_CXX_FLAGS}>") + target_compile_options( + BASIC_IO_EXAMPLE PRIVATE "$<$:${KVIKIO_CXX_FLAGS}>" + ) endif() install( - TARGETS BASIC_IO_TEST + TARGETS BASIC_IO_EXAMPLE COMPONENT testing DESTINATION ${TEST_INSTALL_PATH} EXCLUDE_FROM_ALL @@ -35,20 +39,22 @@ else() message(STATUS "Cannot build the basic_io example when CUDA is not found") endif() -add_executable(BASIC_NO_CUDA_TEST basic_no_cuda.cpp) -set_target_properties(BASIC_NO_CUDA_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib") -target_include_directories(BASIC_NO_CUDA_TEST PRIVATE ../include) -target_link_libraries(BASIC_NO_CUDA_TEST PRIVATE kvikio) +# Example: basic_no_cuda + +add_executable(BASIC_NO_CUDA_EXAMPLE basic_no_cuda.cpp) +set_target_properties(BASIC_NO_CUDA_EXAMPLE PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib") +target_include_directories(BASIC_NO_CUDA_EXAMPLE PRIVATE ../include) +target_link_libraries(BASIC_NO_CUDA_EXAMPLE PRIVATE kvikio) if(CMAKE_COMPILER_IS_GNUCXX) set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas") target_compile_options( - BASIC_NO_CUDA_TEST PRIVATE "$<$:${KVIKIO_CXX_FLAGS}>" + BASIC_NO_CUDA_EXAMPLE PRIVATE "$<$:${KVIKIO_CXX_FLAGS}>" ) endif() install( - TARGETS BASIC_NO_CUDA_TEST + TARGETS BASIC_NO_CUDA_EXAMPLE COMPONENT testing DESTINATION ${TEST_INSTALL_PATH} EXCLUDE_FROM_ALL diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 1b625e7f52..1c6684e9b7 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -18,7 +18,6 @@ enable_testing() include(rapids-test) -# NB: calling `rapids_test_init()` to have CTest manage GPU resource doesn't work file(GLOB SOURCES "*.cpp") add_executable(cpp_tests ${SOURCES}) @@ -38,3 +37,5 @@ rapids_test_add( COMMAND cpp_tests INSTALL_COMPONENT_SET testing ) + +rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing DESTINATION bin/tests/libkvikio) diff --git a/cpp/tests/utils.hpp b/cpp/tests/utils.hpp index 7132ec72ef..991b2b773b 100644 --- a/cpp/tests/utils.hpp +++ b/cpp/tests/utils.hpp @@ -102,8 +102,15 @@ class TempDir { std::filesystem::path _dir_path{}; }; +/** + * @brief Help class for creating and comparing buffers. + */ class DevBuffer { public: + const std::size_t nelem; + const std::size_t nbytes; + void* ptr{nullptr}; + DevBuffer(std::size_t nelem) : nelem{nelem}, nbytes{nelem * sizeof(std::int64_t)} { KVIKIO_CHECK_CUDA(cudaMalloc(&ptr, nbytes)); @@ -144,13 +151,9 @@ class DevBuffer { } std::cout << ")" << std::endl; } - - const std::size_t nelem; - const std::size_t nbytes; - void* ptr{nullptr}; }; -void expect_equal(const DevBuffer& a, const DevBuffer& b) +inline void expect_equal(const DevBuffer& a, const DevBuffer& b) { EXPECT_EQ(a.nbytes, b.nbytes); auto a_vec = a.to_vector();