Skip to content

Commit

Permalink
More fixes to ROCMTest module (#143)
Browse files Browse the repository at this point in the history
* Test for test package is enabled

* Fix installation of tests

* Add test

* Add install-tests target

* Remove other exclude_from_all
  • Loading branch information
pfultz2 authored Sep 7, 2023
1 parent 433d5cb commit 0e5e571
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
24 changes: 12 additions & 12 deletions share/rocm/cmake/ROCMTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${
add_custom_target(tests COMMENT "Build all tests.")
add_dependencies(check tests)

add_custom_target(install-tests COMMAND ${CMAKE_COMMAND} -DCOMPONENT=tests -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
add_dependencies(install-tests tests)

rocm_define_property(TARGET "ROCM_TEST_INSTALLDIR" "Install dir for tests")
function(rocm_enable_test_package NAME)
macro(rocm_enable_test_package NAME)
message(STATUS "Enable test package ${NAME}")
set_target_properties(tests PROPERTIES ROCM_TEST_INSTALLDIR ${CMAKE_INSTALL_PREFIX}/share/test/${NAME})
rocm_package_setup_component(tests DEPENDS COMPONENT runtime)
rocm_defer(rocm_test_install_ctest)
endfunction()
endmacro()

if(POLICY CMP0079)
cmake_policy(SET CMP0079 OLD)
Expand Down Expand Up @@ -189,11 +192,6 @@ endfunction()

function(rocm_mark_as_test)
foreach(TEST_TARGET ${ARGN})
get_target_property(TEST_TARGET_TYPE ${TEST_TARGET} TYPE)
# We can only use EXCLUDE_FROM_ALL on build targets
if(NOT "${TEST_TARGET_TYPE}" STREQUAL "INTERFACE_LIBRARY")
set_target_properties(${TEST_TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
add_dependencies(tests ${TEST_TARGET})
endforeach()
endfunction()
Expand Down Expand Up @@ -221,21 +219,23 @@ function(rocm_install_test)
if(PARSE_TARGETS)
install(
TARGETS ${PARSE_TARGETS}
COMPONENT test
DESTINATION ${INSTALL_PREFIX}/bin)
COMPONENT tests
DESTINATION ${INSTALL_PREFIX}/bin
EXCLUDE_FROM_ALL)
rocm_set_install_dir_property(TARGETS ${PARSE_TARGETS} DESTINATION ${INSTALL_PREFIX}/bin)
get_target_property(INSTALLDIR ${PARSE_TARGETS} ROCM_INSTALL_DIR)
endif()
if(PARSE_FILES)
install(
FILES ${PARSE_FILES}
COMPONENT test
DESTINATION ${INSTALL_PREFIX}/${PARSE_DESTINATION})
COMPONENT tests
DESTINATION ${INSTALL_PREFIX}/${PARSE_DESTINATION}
EXCLUDE_FROM_ALL)
endif()
endfunction()

function(rocm_add_test_executable EXE)
add_executable(${EXE} EXCLUDE_FROM_ALL ${ARGN})
add_executable(${EXE} ${ARGN})
target_link_libraries(${EXE} ${CMAKE_THREAD_LIBS_INIT})
# Cmake does not add flags correctly for gcc
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
Expand Down
11 changes: 11 additions & 0 deletions test/pass/simple-test-package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ######################################################################################################################
# Copyright (C) 2023 Advanced Micro Devices, Inc.
# ######################################################################################################################

configure_dir(${TEST_DIR}/libsimpletest TARGETS package BUILD_DIR_VAR BUILD_DIR)
file(GLOB TEST_PACKAGE ${BUILD_DIR}/*-tests.tar.gz)
list(LENGTH TEST_PACKAGE NTEST_PACKAGE)
test_expect_eq(${NTEST_PACKAGE} 1)
test_exec(COMMAND ${CMAKE_COMMAND} -E tar t ${TEST_PACKAGE})
test_exec(COMMAND ${CMAKE_COMMAND} -E tar x ${TEST_PACKAGE} WORKING_DIRECTORY /)
test_expect_file(${PREFIX}/share/test/simple/CTestTestfile.cmake)
2 changes: 1 addition & 1 deletion test/pass/simple-test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Copyright (C) 2023 Advanced Micro Devices, Inc.
# ######################################################################################################################

install_dir(${TEST_DIR}/libsimpletest TARGETS check package)
install_dir(${TEST_DIR}/libsimpletest TARGETS check install-tests)
test_expect_file(${PREFIX}/share/test/simple/CTestTestfile.cmake)
test_exec(COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure WORKING_DIRECTORY ${PREFIX}/share/test/simple)
8 changes: 6 additions & 2 deletions test/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ endmacro()

function(configure_dir DIR)
set(options)
set(oneValueArgs)
set(oneValueArgs BUILD_DIR_VAR)
set(multiValueArgs CMAKE_ARGS TARGETS)

cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
Expand All @@ -118,7 +118,11 @@ function(configure_dir DIR)
endif()
endforeach()

file(REMOVE_RECURSE ${BUILD_DIR})
if(PARSE_BUILD_DIR_VAR)
set(${PARSE_BUILD_DIR_VAR} ${BUILD_DIR} PARENT_SCOPE)
else()
file(REMOVE_RECURSE ${BUILD_DIR})
endif()
endfunction()

function(install_dir DIR)
Expand Down

0 comments on commit 0e5e571

Please sign in to comment.