Skip to content

Commit

Permalink
add flag for discrete gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
cderb committed Dec 15, 2023
1 parent 8ac0916 commit f68938d
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,35 @@ if(MIOPEN_BACKEND_OPENCL)
set(SKIP_TESTS dumpTensorTest.cpp)
endif()

function(add_gtest TEST_NAME TEST_CPP)
#message("Adding Test: " ${TEST_NAME} " : " ${TEST_CPP})
add_executable(${TEST_NAME} ${TEST_CPP} ${SOURCES})
if(WIN32)
target_compile_definitions(${TEST_NAME} PRIVATE NOMINMAX)
endif()
add_dependencies(tests ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
target_compile_options(${TEST_NAME} PRIVATE -Wno-global-constructors -Wno-undef)
target_include_directories(${TEST_NAME} PRIVATE ../ ../../src/kernels)
if(MIOPEN_ENABLE_AI_KERNEL_TUNING)
target_link_libraries(${TEST_NAME} frugally-deep::fdeep Eigen3::Eigen)
endif()
target_link_libraries(${TEST_NAME} GTest::gtest GTest::gtest_main MIOpen ${Boost_LIBRARIES} hip::host $<BUILD_INTERFACE:roc::rocblas>)
if(NOT MIOPEN_EMBED_DB STREQUAL "")
target_link_libraries(${TEST_NAME} $<BUILD_INTERFACE:miopen_data>)
endif()
if(NOT WIN32) # TODO: cannot run on Windows due to missing DLL dependencies
# Enable CMake to discover the test binary
gtest_discover_tests(${TEST_NAME} PROPERTIES ENVIRONMENT "MIOPEN_USER_DB_PATH=${CMAKE_CURRENT_BINARY_DIR};MIOPEN_TEST_FLOAT_ARG=${MIOPEN_TEST_FLOAT_ARG};MIOPEN_TEST_ALL=${MIOPEN_TEST_ALL};MIOPEN_TEST_MLIR=${MIOPEN_TEST_MLIR};MIOPEN_TEST_COMPOSABLEKERNEL=${MIOPEN_TEST_COMPOSABLEKERNEL}")
endif()

if(WIN32)
# Refer to https://en.cppreference.com/w/cpp/language/types for details.
target_compile_options(${TEST_NAME} PRIVATE $<BUILD_INTERFACE:$<$<CXX_COMPILER_ID:Clang>:-U__LP64__>>)
endif()
endfunction()

file(GLOB TESTS *.cpp)
file(GLOB HEADERS *.hpp)
# Remove files that do not contain tests
foreach(SOURCE ${SOURCES})
list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE})
Expand All @@ -21,42 +48,25 @@ foreach(SOURCE ${SKIP_TESTS})
list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE})
endforeach()

message("Test files: " ${TESTS})
foreach(TEST ${TESTS})
get_filename_component(BASE_NAME ${TEST} NAME)
list(APPEND TESTS_CPP ${BASE_NAME})
endforeach()
if( DISCRETE_GTEST )
foreach(TEST ${TESTS})
get_filename_component(BASE_NAME ${TEST} NAME_WE)
add_gtest(test_${BASE_NAME} ${BASE_NAME}.cpp)
endforeach()

else()
foreach(TEST ${TESTS})
get_filename_component(BASE_NAME ${TEST} NAME)
list(APPEND TESTS_CPP ${BASE_NAME})
endforeach()

message("Adding miopen_gtest: " ${TESTS_CPP})
add_executable(miopen_gtest ${TESTS_CPP} ${SOURCES})
if(WIN32)
target_compile_definitions(miopen_gtest PRIVATE NOMINMAX)
endif()
add_dependencies(tests miopen_gtest)
add_dependencies(check miopen_gtest)
target_compile_options(miopen_gtest PRIVATE -Wno-global-constructors -Wno-undef)
target_include_directories(miopen_gtest PRIVATE ../ ../../src/kernels)
if(MIOPEN_ENABLE_AI_KERNEL_TUNING)
target_link_libraries(miopen_gtest frugally-deep::fdeep Eigen3::Eigen)
endif()
target_link_libraries(miopen_gtest GTest::gtest GTest::gtest_main MIOpen ${Boost_LIBRARIES} hip::host $<BUILD_INTERFACE:roc::rocblas>)
if(NOT MIOPEN_EMBED_DB STREQUAL "")
target_link_libraries(miopen_gtest $<BUILD_INTERFACE:miopen_data>)
endif()
add_gtest(miopen_gtest "${TESTS_CPP}")

if(NOT WIN32) # TODO: cannot run on Windows due to missing DLL dependencies
# Enable CMake to discover the test binary
gtest_discover_tests(miopen_gtest PROPERTIES ENVIRONMENT "MIOPEN_USER_DB_PATH=${CMAKE_CURRENT_BINARY_DIR};MIOPEN_TEST_FLOAT_ARG=${MIOPEN_TEST_FLOAT_ARG};MIOPEN_TEST_ALL=${MIOPEN_TEST_ALL};MIOPEN_TEST_MLIR=${MIOPEN_TEST_MLIR};MIOPEN_TEST_COMPOSABLEKERNEL=${MIOPEN_TEST_COMPOSABLEKERNEL}")
if( NOT ENABLE_ASAN_PACKAGING )
install(TARGETS miopen_gtest
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()

if(WIN32)
# Refer to https://en.cppreference.com/w/cpp/language/types for details.
target_compile_options(miopen_gtest PRIVATE $<BUILD_INTERFACE:$<$<CXX_COMPILER_ID:Clang>:-U__LP64__>>)
endif()

if( NOT ENABLE_ASAN_PACKAGING )
install(TARGETS miopen_gtest
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

0 comments on commit f68938d

Please sign in to comment.