Skip to content

Commit

Permalink
Add INSTALL_TARGET argument to rapids_add_test() (#692)
Browse files Browse the repository at this point in the history
If another command, such as `mpiexec`, is used to execute a target, `rapids_add_test()` currently has no way of installing the target dependency. Add an `INSTALL_TARGET` argument to support this use case.

Authors:
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #692
  • Loading branch information
KyleFromNVIDIA authored Sep 20, 2024
1 parent d2a3054 commit caf5dd6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
20 changes: 16 additions & 4 deletions rapids-cmake/test/add.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,7 +70,7 @@ function(rapids_test_add)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.test.add")

set(options)
set(one_value NAME WORKING_DIRECTORY GPUS PERCENT INSTALL_COMPONENT_SET)
set(one_value NAME WORKING_DIRECTORY GPUS PERCENT INSTALL_COMPONENT_SET INSTALL_TARGET)
set(multi_value COMMAND)
cmake_parse_arguments(_RAPIDS_TEST "${options}" "${one_value}" "${multi_value}" ${ARGN})

Expand All @@ -89,6 +89,18 @@ function(rapids_test_add)
if(TARGET ${command_or_target})
set(command "$<TARGET_FILE:${command}>")
endif()
if(DEFINED _RAPIDS_TEST_INSTALL_TARGET)
if(NOT TARGET ${_RAPIDS_TEST_INSTALL_TARGET})
message(FATAL_ERROR "rapids_add_test given INSTALL_TARGET \"${_RAPIDS_TEST_INSTALL_TARGET}\", which does not exist"
)
endif()
set(target_to_install ${_RAPIDS_TEST_INSTALL_TARGET})
else()
if(NOT TARGET ${command_or_target})
message(VERBOSE "rapids_add_test could not infer a target to install")
endif()
set(target_to_install ${command_or_target})
endif()

if(NOT DEFINED _RAPIDS_TEST_WORKING_DIRECTORY)
set(_RAPIDS_TEST_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
Expand Down Expand Up @@ -120,8 +132,8 @@ function(rapids_test_add)

rapids_test_record_test_component(NAME ${_RAPIDS_TEST_NAME} COMPONENT
${_RAPIDS_TEST_INSTALL_COMPONENT_SET})
if(TARGET ${command_or_target})
rapids_test_record_install(TARGET ${command_or_target} COMPONENT
if(TARGET ${target_to_install})
rapids_test_record_install(TARGET ${target_to_install} COMPONENT
${_RAPIDS_TEST_INSTALL_COMPONENT_SET})
endif()
endif()
Expand Down
2 changes: 2 additions & 0 deletions testing/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ add_cmake_config_test(install_relocatable-wrong-component.cmake SHOULD_FAIL "${w

add_cmake_ctest_test(add-impossible-allocation SHOULD_FAIL "Insufficient resources for test")
add_cmake_config_test(add-with-install-component.cmake)
add_cmake_config_test(add-with-install-target.cmake)
add_cmake_config_test(add-with-install-target-missing.cmake SHOULD_FAIL "rapids_add_test given INSTALL_TARGET \"noexist\", which does not exist")
add_cmake_config_test(add-with-no-gpus.cmake)

add_cmake_ctest_test(add-no-cuda-toolkit)
Expand Down
27 changes: 27 additions & 0 deletions testing/test/add-with-install-target-missing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#=============================================================================
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/test/init.cmake)
include(${rapids-cmake-dir}/test/add.cmake)

enable_language(CUDA)

rapids_test_init()

file(WRITE "${CMAKE_BINARY_DIR}/main.cu" "int main(){return 0;}")
add_executable(verify_alloc "${CMAKE_BINARY_DIR}/main.cu")

enable_testing()
rapids_test_add(NAME simple_test COMMAND verify_alloc GPUS 1 INSTALL_COMPONENT_SET testing INSTALL_TARGET noexist)
39 changes: 39 additions & 0 deletions testing/test/add-with-install-target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#=============================================================================
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/test/init.cmake)
include(${rapids-cmake-dir}/test/add.cmake)

enable_language(CUDA)

rapids_test_init()

file(WRITE "${CMAKE_BINARY_DIR}/main.cu" "int main(){return 0;}")
add_executable(verify_alloc "${CMAKE_BINARY_DIR}/main.cu")

enable_testing()
rapids_test_add(NAME simple_test COMMAND ${CMAKE_COMMAND} -E env verify_alloc GPUS 1 INSTALL_COMPONENT_SET testing INSTALL_TARGET verify_alloc)

# Verify that we have recorded `simple_test` as part of the `testing` component
get_target_property(names rapids_test_install_testing TESTS_TO_RUN)
if(NOT "simple_test" IN_LIST names)
message(FATAL_ERROR "Failed to record `simple_test` as part of the testing component")
endif()

# Verify that `verify_alloc` is marked as to be installed
get_target_property(names rapids_test_install_testing TARGETS_TO_INSTALL)
if(NOT "verify_alloc" IN_LIST names)
message(FATAL_ERROR "Failed to record `verify_alloc` as a target to be installed in the testing component")
endif()

0 comments on commit caf5dd6

Please sign in to comment.