Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWDEV-359379 - catch2: Standalone single exe per file [EXPERIMENTAL- DO NOT MERGE] #86

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ set(CATCH_BUILD_DIR catch_tests)
file(COPY ./hipTestMain/config DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain)
file(COPY ./external/Catch2/cmake/Catch2/CatchAddTests.cmake
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/script)
file(COPY ./external/Catch2/cmake/Catch2/catch_include.cmake
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/script)
set(ADD_SCRIPT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/script/CatchAddTests.cmake)
set(CATCH_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/script/catch_include.cmake)



if (WIN32)
configure_file(catchProp_in_rc.in ${CMAKE_CURRENT_BINARY_DIR}/catchProp.rc @ONLY)
Expand Down Expand Up @@ -219,14 +224,14 @@ add_custom_target(build_tests)


# Tests folder
add_subdirectory(unit ${CATCH_BUILD_DIR}/unit)
#add_subdirectory(unit ${CATCH_BUILD_DIR}/unit)
add_subdirectory(ABM ${CATCH_BUILD_DIR}/ABM)
add_subdirectory(kernels ${CATCH_BUILD_DIR}/kernels)
add_subdirectory(hipTestMain ${CATCH_BUILD_DIR}/hipTestMain)
add_subdirectory(stress ${CATCH_BUILD_DIR}/stress)
add_subdirectory(TypeQualifiers ${CATCH_BUILD_DIR}/TypeQualifiers)
#add_subdirectory(stress ${CATCH_BUILD_DIR}/stress)
#add_subdirectory(TypeQualifiers ${CATCH_BUILD_DIR}/TypeQualifiers)
if(UNIX)
add_subdirectory(multiproc ${CATCH_BUILD_DIR}/multiproc)
# add_subdirectory(multiproc ${CATCH_BUILD_DIR}/multiproc)
endif()

cmake_policy(POP)
Expand Down
147 changes: 70 additions & 77 deletions catch/external/Catch2/cmake/Catch2/Catch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,65 +119,36 @@ same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
#]=======================================================================]

#------------------------------------------------------------------------------
function(catch_discover_tests TARGET)
function(catch_discover_tests TARGET_LIST TEST_SET)
cmake_parse_arguments(
""
""
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;REPORTER;OUTPUT_DIR;OUTPUT_PREFIX;OUTPUT_SUFFIX"
"TEST_SPEC;EXTRA_ARGS;PROPERTIES"
${ARGN}
)

if(NOT _WORKING_DIRECTORY)
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if(NOT _TEST_LIST)
set(_TEST_LIST ${TARGET}_TESTS)
endif()

## Generate a unique name based on the extra arguments
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS} ${_REPORTER} ${_OUTPUT_DIR} ${_OUTPUT_PREFIX} ${_OUTPUT_SUFFIX}")
string(SUBSTRING ${args_hash} 0 7 args_hash)

# 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")
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SET}_include-${args_hash}.cmake")
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SET}_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
)

set(EXEC_NAME ${TARGET})
if(WIN32)
set(EXEC_NAME ${EXEC_NAME}.exe)
endif()

# 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
set_property(DIRECTORY
APPEND PROPERTY TEST_INCLUDE_FILES "${ctestincludepath}"
)
else()
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
if (NOT ${test_include_file_set})
file(RELATIVE_PATH CATCH_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CATCH_INCLUDE_PATH})
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
file(WRITE ${ctest_include_file} "set(exc_names ${TARGET_LIST})\n")
file(APPEND ${ctest_include_file} "set(TARGET ${TEST_SET})\n")
file(APPEND ${ctest_include_file} "set(ctestfilepath ${ctestfilepath})\n")
file(APPEND ${ctest_include_file} "set(_CATCH_ADD_TEST_SCRIPT ${_CATCH_ADD_TEST_SCRIPT})\n")
file(APPEND ${ctest_include_file} "set(_PROPERTIES ${_PROPERTIES})\n")
file(APPEND ${ctest_include_file} "include(${CATCH_INCLUDE_PATH})\n")
# Add discovered tests to directory TEST_INCLUDE_FILES
set_property(DIRECTORY
PROPERTY TEST_INCLUDE_FILE "${ctestincludepath}"
)
else()
message(FATAL_ERROR
"Cannot set more than one TEST_INCLUDE_FILE"
APPEND PROPERTY TEST_INCLUDE_FILES "${ctestincludepath}"
)
endif()
endif()

endfunction()
Expand All @@ -194,56 +165,78 @@ set(_CATCH_DISCOVER_TESTS_SCRIPT
function(hip_add_exe_to_target)
set(options)
set(args NAME TEST_TARGET_NAME PLATFORM COMPILE_OPTIONS)
set(list_args TEST_SRC LINKER_LIBS PROPERTY)
set(list_args TEST_SRC LINKER_LIBS COMMON_SHARED_SRC PROPERTY)
cmake_parse_arguments(
PARSE_ARGV 0
"" # variable prefix
"${options}"
"${args}"
"${list_args}"
)
# Create shared lib of all tests
if(NOT RTC_TESTING)
add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $<TARGET_OBJECTS:Main_Object> $<TARGET_OBJECTS:KERNELS>)
else ()
add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $<TARGET_OBJECTS:Main_Object>)
if(HIP_PLATFORM STREQUAL "amd")
target_link_libraries(${_NAME} hiprtc)
foreach(SRC_NAME ${TEST_SRC})

if(NOT STANDALONE_TESTS EQUAL "1")
set(_EXE_NAME ${_NAME})
set(SRC_NAME ${TEST_SRC})
else()
target_link_libraries(${_NAME} nvrtc)
# strip extension of src and use exe name as src name
get_filename_component(_EXE_NAME ${SRC_NAME} NAME_WLE)
endif()
endif()
catch_discover_tests(${_NAME} PROPERTIES SKIP_REGULAR_EXPRESSION "HIP_SKIP_THIS_TEST")
if(UNIX)
set(_LINKER_LIBS ${_LINKER_LIBS} stdc++fs)
set(_LINKER_LIBS ${_LINKER_LIBS} -ldl)
else()
# res files are built resource files using rc files.
# use llvm-rc exe to build the res files
# Thes are used to populate the properties of the built executables
if(EXISTS "${PROP_RC}/catchProp.res")
set(_LINKER_LIBS ${_LINKER_LIBS} "${PROP_RC}/catchProp.res")
if(WIN32)
set(_EXE_NAME ${_EXE_NAME}.exe)
endif()
endif()

if(DEFINED _LINKER_LIBS)
target_link_libraries(${_NAME} ${_LINKER_LIBS})
endif()
# Create shared lib of all tests
if(NOT RTC_TESTING)
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object> $<TARGET_OBJECTS:KERNELS>)
else ()
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object>)
if(HIP_PLATFORM STREQUAL "amd")
target_link_libraries(${_EXE_NAME} hiprtc)
else()
target_link_libraries(${_EXE_NAME} nvrtc)
endif()
endif()
if (DEFINED _PROPERTY)
set_property(TARGET ${_EXE_NAME} PROPERTY ${_PROPERTY})
endif()
if(UNIX)
set(_LINKER_LIBS ${_LINKER_LIBS} stdc++fs)
set(_LINKER_LIBS ${_LINKER_LIBS} -ldl)
else()
# res files are built resource files using rc files.
# use llvm-rc exe to build the res files
# Thes are used to populate the properties of the built executables
if(EXISTS "${PROP_RC}/catchProp.res")
set(_LINKER_LIBS ${_LINKER_LIBS} "${PROP_RC}/catchProp.res")
endif()
endif()

# Add dependency on build_tests to build it on this custom target
add_dependencies(${_TEST_TARGET_NAME} ${_NAME})
if(DEFINED _LINKER_LIBS)
target_link_libraries(${_EXE_NAME} ${_LINKER_LIBS})
endif()

if (DEFINED _PROPERTY)
set_property(TARGET ${_NAME} PROPERTY ${_PROPERTY})
endif()
# Add dependency on build_tests to build it on this custom target
add_dependencies(${_TEST_TARGET_NAME} ${_EXE_NAME})

if (DEFINED _COMPILE_OPTIONS)
target_compile_options(${_NAME} PUBLIC ${_COMPILE_OPTIONS})
endif()
if (DEFINED _COMPILE_OPTIONS)
target_compile_options(${_EXE_NAME} PUBLIC ${_COMPILE_OPTIONS})
endif()

foreach(arg IN LISTS _UNPARSED_ARGUMENTS)
message(WARNING "Unparsed arguments: ${arg}")
endforeach()
get_property(crosscompiling_emulator
TARGET ${_EXE_NAME}
PROPERTY CROSSCOMPILING_EMULATOR
)
set(_EXE_NAME_LIST ${_EXE_NAME_LIST} ${_EXE_NAME})
if(NOT STANDALONE_TESTS EQUAL "1")
break()
endif()

foreach(arg IN LISTS _UNPARSED_ARGUMENTS)
message(WARNING "Unparsed arguments: ${arg}")
endforeach()
endfunction()

catch_discover_tests("${_EXE_NAME_LIST}" "${_NAME}" PROPERTIES SKIP_REGULAR_EXPRESSION "HIP_SKIP_THIS_TEST")
endfunction()

2 changes: 1 addition & 1 deletion catch/external/Catch2/cmake/Catch2/CatchAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ endforeach()
add_command(set ${TEST_LIST} ${tests})

# Write CTest script
file(WRITE "${CTEST_FILE}" "${script}")
file(APPEND "${CTEST_FILE}" "${script}")
38 changes: 38 additions & 0 deletions catch/external/Catch2/cmake/Catch2/catch_include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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)

foreach(EXEC_NAME ${exc_names})
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}"
)
else()
message("executable not found : ${EXEC_NAME}" )
endif()
endforeach()

if(EXISTS "${ctestfilepath}")
# include the generated ctest file for execution
include(${ctestfilepath})
endif()
34 changes: 0 additions & 34 deletions catch/external/Catch2/cmake/Catch2/catch_include.cmake.in

This file was deleted.

12 changes: 5 additions & 7 deletions catch/multiproc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Common Tests
set(LINUX_TEST_SRC
set(TEST_SRC
childMalloc.cc
hipDeviceComputeCapabilityMproc.cc
hipDeviceGetPCIBusIdMproc.cc
Expand All @@ -12,25 +12,23 @@ set(LINUX_TEST_SRC
hipMallocConcurrencyMproc.cc
hipMemCoherencyTstMProc.cc
hipIpcEventHandle.cc
hipIpcMemAccessTest.cc
deviceAllocationMproc.cc
hipNoGpuTsts.cc
hipMemGetInfo.cc
hipMemGetInfoMProc.cc
)

add_custom_target(dummy_kernel.code COMMAND ${CMAKE_CXX_COMPILER} --genco ${CMAKE_CURRENT_SOURCE_DIR}/dummy_kernel.cpp -o ${CMAKE_CURRENT_BINARY_DIR}/../multiproc/dummy_kernel.code -I${CMAKE_CURRENT_SOURCE_DIR}/../../../../include/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../include)

# the last argument linker libraries is required for this test but optional to the function
if(HIP_PLATFORM MATCHES "nvidia")
hip_add_exe_to_target(NAME MultiProc
TEST_SRC ${LINUX_TEST_SRC}
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME build_tests
LINKER_LIBS nvrtc)
elseif(HIP_PLATFORM MATCHES "amd")
hip_add_exe_to_target(NAME MultiProc
TEST_SRC ${LINUX_TEST_SRC}
TEST_TARGET_NAME build_tests
LINKER_LIBS ${CMAKE_DL_LIBS})
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME build_tests)
endif()
add_dependencies(build_tests dummy_kernel.code)

2 changes: 1 addition & 1 deletion catch/stress/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(TEST_SRC
hipMemcpyMThreadMSize.cc
hipMallocManagedStress.cc
hipMemPrftchAsyncStressTst.cc
hipHostMalloc.cc
hipHostMallocStress.cc
)

hip_add_exe_to_target(NAME memory
Expand Down
6 changes: 3 additions & 3 deletions catch/unit/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ set_source_files_properties(hipGetDeviceCount.cc PROPERTIES COMPILE_FLAGS -std=c
set_source_files_properties(hipDeviceGetP2PAttribute.cc PROPERTIES COMPILE_FLAGS -std=c++17)

add_executable(getDeviceCount EXCLUDE_FROM_ALL getDeviceCount_exe.cc)
add_executable(hipDeviceGetP2PAttribute EXCLUDE_FROM_ALL hipDeviceGetP2PAttribute_exe.cc)
add_executable(hipDeviceGetP2PAttribute_exe EXCLUDE_FROM_ALL hipDeviceGetP2PAttribute_exe.cc)

hip_add_exe_to_target(NAME DeviceTest
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME build_tests
COMPILE_OPTIONS -std=c++14)

add_dependencies(DeviceTest getDeviceCount)
add_dependencies(DeviceTest hipDeviceGetP2PAttribute)
add_dependencies(build_tests getDeviceCount)
add_dependencies(build_tests hipDeviceGetP2PAttribute_exe)
22 changes: 11 additions & 11 deletions catch/unit/device/hipDeviceGetP2PAttribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,20 @@ TEST_CASE("Unit_hipDeviceGetP2PAttribute_Negative") {

/* https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars */
SECTION("Hidden devices using environment variables") {
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("0") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("1") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("0,1") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("-1,0") == hipErrorNoDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("0,-1") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("0,1,-1") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("0,-1,1") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("1") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,1") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("-1,0") == hipErrorNoDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,-1") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,1,-1") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,-1,1") == hipErrorInvalidDevice);

if (deviceCount > 2) {
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("2,1") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("2") == hipErrorInvalidDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("2,1") == hipSuccess);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("2") == hipErrorInvalidDevice);
} else {
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("2,1") == hipErrorNoDevice);
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("2,1") == hipErrorNoDevice);
}
}
#endif
Expand Down
Loading