Skip to content

Commit

Permalink
rapids_test_install_relocatable tracks tests environment properties (r…
Browse files Browse the repository at this point in the history
…apidsai#390)

Will allow projects to specify env variables on tests and have those recorded on the installed tests

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

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

URL: rapidsai#390
  • Loading branch information
robertmaynard authored Mar 23, 2023
1 parent 9866795 commit 623988d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
18 changes: 9 additions & 9 deletions rapids-cmake/test/install_relocatable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ function(rapids_test_install_relocatable)

foreach(test IN LISTS tests_to_run)
get_test_property(${test} INSTALL_COMMAND command)
get_test_property(${test} RESOURCE_GROUPS resources)
get_test_property(${test} LABELS labels)
string(APPEND content "add_test([=[${test}]=] ${command})\n")
if(resources)
string(APPEND content
"set_tests_properties([=[${test}]=] PROPERTIES RESOURCE_GROUPS ${resources})\n")
endif()
if(labels)
string(APPEND content "set_tests_properties([=[${test}]=] PROPERTIES LABELS ${labels})\n")
endif()

set(properties_to_record ENVIRONMENT ENVIRONMENT_MODIFICATION RESOURCE_GROUPS LABELS)
foreach(prop_name IN LISTS properties_to_record)
get_test_property(${test} ${prop_name} prop_value)
if(prop_value)
string(APPEND content
"set_tests_properties([=[${test}]=] PROPERTIES ${prop_name} ${prop_value})\n")
endif()
endforeach()
endforeach()

set(test_launcher_file
Expand Down
1 change: 1 addition & 0 deletions testing/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_cmake_config_test(init-simple.cmake)

set(wrong_component_message "No install component set [wrong_component] can be found")
add_cmake_build_test(install_relocatable-include-in-all.cmake)
add_cmake_build_test(install_relocatable-env-vars.cmake)
add_cmake_build_test(install_relocatable-labels.cmake)
add_cmake_config_test(install_relocatable-simple.cmake)
add_cmake_config_test(install_relocatable-wrong-component.cmake SHOULD_FAIL "${wrong_component_message}")
Expand Down
43 changes: 43 additions & 0 deletions testing/test/install_relocatable-env-vars.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#=============================================================================
# Copyright (c) 2022-2023, 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)
include(${rapids-cmake-dir}/test/install_relocatable.cmake)

enable_language(CUDA)
rapids_test_init()

rapids_test_add(NAME verify_env COMMAND env GPUS 1 INSTALL_COMPONENT_SET testing)
set_tests_properties(verify_env PROPERTIES ENVIRONMENT "MYVAR=my_value")
set_tests_properties(verify_env PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_append:/fake/path")

rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing
DESTINATION bin/testing)

set(generated_testfile "${CMAKE_CURRENT_BINARY_DIR}/rapids-cmake/testing/CTestTestfile.cmake.to_install")
file(READ "${generated_testfile}" contents)

set(env_match_string [===[PROPERTIES ENVIRONMENT MYVAR=my_value]===])
string(FIND "${contents}" "${env_match_string}" is_found)
if(is_found EQUAL -1)
message(FATAL_ERROR "Failed to record the ENVIRONMENT property")
endif()

set(env_mod_match_string [===[PROPERTIES ENVIRONMENT_MODIFICATION PATH=path_list_append:/fake/path]===])
string(FIND "${contents}" "${env_mod_match_string}" is_found)
if(is_found EQUAL -1)
message(FATAL_ERROR "Failed to record the ENVIRONMENT_MODIFICATION property")
endif()

0 comments on commit 623988d

Please sign in to comment.