From f68938d5737517cb62759f28f3c63aeb167ad5f5 Mon Sep 17 00:00:00 2001 From: Christopher Erb Date: Fri, 15 Dec 2023 17:51:49 +0000 Subject: [PATCH] add flag for discrete gtest --- test/gtest/CMakeLists.txt | 78 ++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index e946b114c8..3e4d91b15a 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -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 $) + if(NOT MIOPEN_EMBED_DB STREQUAL "") + target_link_libraries(${TEST_NAME} $) + 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 $:-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}) @@ -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 $) -if(NOT MIOPEN_EMBED_DB STREQUAL "") - target_link_libraries(miopen_gtest $) -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 $:-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()