Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 13 additions & 105 deletions cpp/libcudf_streaming/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,12 @@
# ##################################################################################################
enable_testing()

file(WRITE "${CUDF_STREAMING_BINARY_DIR}/CTestTestfile.cmake" "subdirs(\"tests\")\n")
include(rapids-test)
rapids_test_init()

# Create a separate test case for each of these n_ranks.
set(nranks_to_run 1 2 5)

# ##################################################################################################
# Test registration model --------------------------------------------------------------------------
# All tests are registered with plain add_test() using the absolute build-tree path of each test
# executable (${CUDF_STREAMING_BINARY_DIR}/gtests/<target>). The generated build-tree
# CTestTestfile.cmake is re-rooted for the install tree by the install section at the bottom: the
# executables are installed next to the CTestTestfile.cmake, so those absolute build paths are
# rewritten to "./<target>". Matching the full absolute build path keeps that rewrite unambiguous.
# ##################################################################################################

# Register a single-process test for TEST_TARGET.
function(libcudf_streaming_test_add)
set(options) # no options
set(one_value TEST_TARGET)
set(multi_value) # no multi_value args
cmake_parse_arguments(_TEST "${options}" "${one_value}" "${multi_value}" ${ARGN})

if(NOT DEFINED _TEST_TEST_TARGET)
message(FATAL_ERROR "libcudf_streaming_test_add called without a test target")
endif()

add_test(NAME "${_TEST_TEST_TARGET}"
COMMAND "${CUDF_STREAMING_BINARY_DIR}/gtests/${_TEST_TEST_TARGET}"
)
endfunction()

# Register an mpirun-launched test for TEST_TARGET, creating one test case per parallelism in
# nranks_to_run identified by <TEST_TARGET>_<n_ranks>.
function(libcudf_streaming_mpirun_test_add)
Expand All @@ -53,42 +29,16 @@ function(libcudf_streaming_mpirun_test_add)
endif()

message(STATUS "Adding mpirun test: ${_MPIRUN_TEST_TEST_TARGET} nranks: ${nranks_to_run}")
foreach(np IN ITEMS ${nranks_to_run})
add_test(
foreach(np IN LISTS nranks_to_run)
rapids_test_add(
NAME "${_MPIRUN_TEST_TEST_TARGET}_${np}"
COMMAND mpirun --oversubscribe --map-by node --bind-to none -np ${np}
"${CUDF_STREAMING_BINARY_DIR}/gtests/${_MPIRUN_TEST_TEST_TARGET}"
"$<TARGET_FILE:${_MPIRUN_TEST_TEST_TARGET}>"
INSTALL_COMPONENT_SET testing INSTALL_TARGET ${_MPIRUN_TEST_TEST_TARGET}
)
endforeach(np)
endfunction(libcudf_streaming_mpirun_test_add)

# Collect targets in this directory carrying the property KEY:VALUE into OUTPUT.
function(libcudf_streaming_targets_with_property)
set(options)
set(one_value KEY VALUE OUTPUT)
set(multi_value)
cmake_parse_arguments(_PROP "${options}" "${one_value}" "${multi_value}" ${ARGN})

get_property(
all_targets
DIRECTORY
PROPERTY BUILDSYSTEM_TARGETS
)

set(matched_targets "")
foreach(target ${all_targets})
get_target_property(prop_value ${target} ${_PROP_KEY})
if(prop_value STREQUAL ${_PROP_VALUE})
list(APPEND matched_targets ${target})
endif()
endforeach()

set(${_PROP_OUTPUT}
${matched_targets}
PARENT_SCOPE
)
endfunction()

add_library(libcudf_streaming_test_sources OBJECT)
set_target_properties(
libcudf_streaming_test_sources
Expand Down Expand Up @@ -152,7 +102,11 @@ target_link_libraries(
PRIVATE cudf_streaming rapidsmpf::rapidsmpf GTest::gmock GTest::gtest
$<TARGET_NAME_IF_EXISTS:conda_env> libcudf_streaming_test_sources
)
libcudf_streaming_test_add(TEST_TARGET libcudf_streaming_single_tests)
rapids_test_add(
NAME libcudf_streaming_single_tests
COMMAND libcudf_streaming_single_tests
INSTALL_COMPONENT_SET testing
)

# ##################################################################################################
# MPI and UCXX based tests -------------------------------------------------------------------------
Expand Down Expand Up @@ -220,52 +174,6 @@ else()
cudf_streaming_skip_optional_target(libcudf_streaming_mpi_tests "MPI not found")
endif()

# ##################################################################################################
# Install the tests --------------------------------------------------------------------------------
# Discover every test executable via the custom COMPONENT marker property, install them, and write
# the installed CTestTestfile.cmake from the entries accumulated by the test-add helpers. The
# testing component is EXCLUDE_FROM_ALL so it is only installed on demand (e.g. `cmake --install .
# --component testing`).
# ##################################################################################################
libcudf_streaming_targets_with_property(
KEY COMPONENT VALUE testing OUTPUT _cudf_streaming_test_targets
)

if(_cudf_streaming_test_targets)
install(
TARGETS ${_cudf_streaming_test_targets}
DESTINATION bin/gtests/libcudf_streaming
COMPONENT testing
EXCLUDE_FROM_ALL
)

# Re-root the generated build-tree CTestTestfile.cmake for the install tree. Tests reference the
# absolute build path of each executable (${CUDF_STREAMING_BINARY_DIR}/gtests/<target>); in the
# install tree the executables sit next to the CTestTestfile.cmake, so that absolute prefix is
# rewritten to "./. Matching the full absolute build path keeps the rewrite unambiguous. This runs
# at install time because CTestTestfile.cmake is produced during CMake's generate step (it does
# not exist yet while this directory is being configured).
set(_cudf_streaming_relocate_script
"${CMAKE_CURRENT_BINARY_DIR}/relocate_installed_ctestfile.cmake"
)
file(
WRITE "${_cudf_streaming_relocate_script}"
"set(_src_ctestfile \"${CMAKE_CURRENT_BINARY_DIR}/CTestTestfile.cmake\")\n"
"set(_build_gtests_prefix \"${CUDF_STREAMING_BINARY_DIR}/gtests/\")\n"
)
file(
APPEND "${_cudf_streaming_relocate_script}"
[=[
file(READ "${_src_ctestfile}" _ctest_contents)
string(REPLACE "\"${_build_gtests_prefix}" "\"./" _ctest_contents "${_ctest_contents}")
file(WRITE "${CMAKE_INSTALL_PREFIX}/bin/gtests/libcudf_streaming/CTestTestfile.cmake"
"${_ctest_contents}"
rapids_test_install_relocatable(
INSTALL_COMPONENT_SET testing DESTINATION bin/gtests/libcudf_streaming
)
]=]
)
install(
SCRIPT "${_cudf_streaming_relocate_script}"
COMPONENT testing
EXCLUDE_FROM_ALL
)
endif()
Loading