SWDEV-1 - hip tests: Moving ctest file generation to execution phase (#2522)

Earlier ctest file creation was taking place during build time.
Due to cmake framework issue the file creation had issues,
which in turn failed the test build.
This change moves this logic to the execution phase
and gets rid of the unwanted dependency during build time

Change-Id: Ifbf7e325f1b15a8be12e76560a6d339bc76705ee
This commit is contained in:
agunashe
2022-02-28 09:26:33 -08:00
committed by GitHub
parent e108ed9cbf
commit 4872e70674
6 changed files with 62 additions and 34 deletions
+12 -31
View File
@@ -142,43 +142,24 @@ function(catch_discover_tests TARGET)
# Define rule to generate test list for aforementioned test executable
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
file(RELATIVE_PATH ctestincludepath ${CMAKE_CURRENT_BINARY_DIR} ${ctest_include_file})
file(RELATIVE_PATH ctestfilepath ${CMAKE_CURRENT_BINARY_DIR} ${ctest_tests_file})
file(RELATIVE_PATH _workdir ${CMAKE_CURRENT_BINARY_DIR} ${_WORKING_DIRECTORY})
file(RELATIVE_PATH _CATCH_ADD_TEST_SCRIPT ${CMAKE_CURRENT_BINARY_DIR} ${ADD_SCRIPT_PATH})
get_property(crosscompiling_emulator
TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR
)
add_custom_command(
TARGET ${TARGET} POST_BUILD
BYPRODUCTS "${ctest_tests_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TARGET=${TARGET}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
-D "TEST_EXECUTOR=${crosscompiling_emulator}"
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
-D "TEST_SPEC=${_TEST_SPEC}"
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
-D "TEST_PROPERTIES=${_PROPERTIES}"
-D "TEST_PREFIX=${_TEST_PREFIX}"
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
-D "TEST_LIST=${_TEST_LIST}"
-D "TEST_REPORTER=${_REPORTER}"
-D "TEST_OUTPUT_DIR=${_OUTPUT_DIR}"
-D "TEST_OUTPUT_PREFIX=${_OUTPUT_PREFIX}"
-D "TEST_OUTPUT_SUFFIX=${_OUTPUT_SUFFIX}"
-D "CTEST_FILE=${ctest_tests_file}"
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
VERBATIM
)
file(RELATIVE_PATH ctestincludepath ${CMAKE_CURRENT_BINARY_DIR} ${ctest_include_file})
file(RELATIVE_PATH ctestfilepath ${CMAKE_CURRENT_BINARY_DIR} ${ctest_tests_file})
set(EXEC_NAME ${TARGET})
if(WIN32)
set(EXEC_NAME ${EXEC_NAME}.exe)
endif()
file(WRITE "${ctest_include_file}"
"if(EXISTS \"${ctestfilepath}\")\n"
" include(\"${ctestfilepath}\")\n"
"else()\n"
" message(WARNING \"Test ${TARGET} not built yet.\")\n"
"endif()\n"
)
# uses catch_include.cmake.in file to generate the *_include.cmake file
# *_include.cmake is used to generate the *_test.cmake during execution of ctest cmd
configure_file(${CATCH2_INCLUDE} ${TARGET}_include-${args_hash}.cmake @ONLY)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
# Add discovered tests to directory TEST_INCLUDE_FILES
@@ -29,6 +29,8 @@ function(add_command NAME)
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
endfunction()
get_filename_component(TEST_EXECUTABLE ${TEST_EXECUTABLE} ABSOLUTE)
# Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR
@@ -0,0 +1,34 @@
# File @ctestincludepath@ is generated by cmake.
# For changes please modify hip/tests/catch/external/Catch2/cmake/Catch2/catch_include.cmake.in
get_filename_component(_cmake_path cmake ABSOLUTE)
if(EXISTS "@EXEC_NAME@")
execute_process(
COMMAND "${_cmake_path}"
-D "TEST_TARGET=@TARGET@"
-D "TEST_EXECUTABLE=@EXEC_NAME@"
-D "TEST_EXECUTOR=@crosscompiling_emulator@"
-D "TEST_WORKING_DIR=@_workdir@"
-D "TEST_SPEC=@_TEST_SPEC@"
-D "TEST_EXTRA_ARGS=@_EXTRA_ARGS@"
-D "TEST_PROPERTIES=@_PROPERTIES@"
-D "TEST_PREFIX=@_TEST_PREFIX@"
-D "TEST_SUFFIX=@_TEST_SUFFIX@"
-D "TEST_LIST=@_TEST_LIST@"
-D "TEST_REPORTER=@_REPORTER@"
-D "TEST_OUTPUT_DIR=@_OUTPUT_DIR@"
-D "TEST_OUTPUT_PREFIX=@_OUTPUT_PREFIX@"
-D "TEST_OUTPUT_SUFFIX=@_OUTPUT_SUFFIX@"
-D "CTEST_FILE=@ctestfilepath@"
-P "@_CATCH_ADD_TEST_SCRIPT@"
OUTPUT_VARIABLE output
RESULT_VARIABLE result
WORKING_DIRECTORY "@TEST_WORKING_DIR@"
)
# include the generated ctest file for execution
include(@ctestfilepath@)
else()
message(STATUS "executable not built : @EXEC_NAME@" )
endif()