@@ -139,6 +139,9 @@ function(AddTest)
139139 endif ()
140140endfunction (AddTest)
141141
142+ # general program entrypoint for C++ unit tests
143+ set (onnxruntime_unittest_main_src "${TEST_SRC_DIR} /unittest_main/test_main.cc" )
144+
142145#Do not add '${TEST_SRC_DIR}/util/include' to your include directories directly
143146#Use onnxruntime_add_include_to_target or target_link_libraries, so that compile definitions
144147#can propagate correctly.
@@ -571,65 +574,58 @@ endif()
571574
572575set (all_dependencies ${onnxruntime_test_providers_dependencies} )
573576
574- if (onnxruntime_ENABLE_TRAINING)
575- list (APPEND all_tests ${onnxruntime_test_training_src} )
576- endif ()
577+ if (onnxruntime_ENABLE_TRAINING)
578+ list (APPEND all_tests ${onnxruntime_test_training_src} )
579+ endif ()
577580
578- if (onnxruntime_USE_TVM)
579- list (APPEND all_tests ${onnxruntime_test_tvm_src} )
580- endif ()
581- if (onnxruntime_USE_OPENVINO)
582- list (APPEND all_tests ${onnxruntime_test_openvino_src} )
583- endif ()
584- # we can only have one 'main', so remove them all and add back the providers test_main as it sets
585- # up everything we need for all tests
586- file (GLOB_RECURSE test_mains CONFIGURE_DEPENDS
587- "${TEST_SRC_DIR} /*/test_main.cc"
588- )
589- list (REMOVE_ITEM all_tests ${test_mains} )
590- list (APPEND all_tests "${TEST_SRC_DIR} /providers/test_main.cc" )
581+ if (onnxruntime_USE_TVM)
582+ list (APPEND all_tests ${onnxruntime_test_tvm_src} )
583+ endif ()
584+ if (onnxruntime_USE_OPENVINO)
585+ list (APPEND all_tests ${onnxruntime_test_openvino_src} )
586+ endif ()
591587
592- # this is only added to onnxruntime_test_framework_libs above, but we use onnxruntime_test_providers_libs for the onnxruntime_test_all target.
593- # for now, add it here. better is probably to have onnxruntime_test_providers_libs use the full onnxruntime_test_framework_libs
594- # list given it's built on top of that library and needs all the same dependencies.
595- if (WIN32 )
596- list (APPEND onnxruntime_test_providers_libs Advapi32)
597- endif ()
588+ # this is only added to onnxruntime_test_framework_libs above, but we use onnxruntime_test_providers_libs for the onnxruntime_test_all target.
589+ # for now, add it here. better is probably to have onnxruntime_test_providers_libs use the full onnxruntime_test_framework_libs
590+ # list given it's built on top of that library and needs all the same dependencies.
591+ if (WIN32 )
592+ list (APPEND onnxruntime_test_providers_libs Advapi32)
593+ endif ()
598594
599- AddTest(
600- TARGET onnxruntime_test_all
601- SOURCES ${all_tests}
602- LIBS onnx_test_runner_common ${onnxruntime_test_providers_libs} ${onnxruntime_test_common_libs} re2::re2 onnx_test_data_proto
603- DEPENDS ${all_dependencies}
604- )
595+ AddTest(
596+ TARGET onnxruntime_test_all
597+ SOURCES ${all_tests} ${onnxruntime_unittest_main_src }
598+ LIBS onnx_test_runner_common ${onnxruntime_test_providers_libs} ${onnxruntime_test_common_libs} re2::re2 onnx_test_data_proto
599+ DEPENDS ${all_dependencies}
600+ )
605601
606- # the default logger tests conflict with the need to have an overall default logger
607- # so skip in this type of
608- target_compile_definitions (onnxruntime_test_all PUBLIC -DSKIP_DEFAULT_LOGGER_TESTS)
609- if (CMAKE_SYSTEM_NAME STREQUAL "iOS" )
610- target_compile_definitions (onnxruntime_test_all_xc PUBLIC -DSKIP_DEFAULT_LOGGER_TESTS)
611- endif ()
612- if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
613- target_compile_options (onnxruntime_test_all PUBLIC "-Wno-unused-const-variable" )
614- endif ()
615- if (onnxruntime_RUN_MODELTEST_IN_DEBUG_MODE)
616- target_compile_definitions (onnxruntime_test_all PUBLIC -DRUN_MODELTEST_IN_DEBUG_MODE)
617- endif ()
618- if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS)
619- target_compile_definitions (onnxruntime_test_all PRIVATE DEBUG_NODE_INPUTS_OUTPUTS)
620- endif ()
621- if (onnxruntime_USE_FEATURIZERS)
622- target_include_directories (onnxruntime_test_all PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /external/FeaturizersLibrary/src)
623- endif ()
624- if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS)
625- target_link_libraries (onnxruntime_test_all PRIVATE onnxruntime_language_interop onnxruntime_pyop)
626- endif ()
602+ # the default logger tests conflict with the need to have an overall default logger
603+ # so skip in this type of
604+ target_compile_definitions (onnxruntime_test_all PUBLIC -DSKIP_DEFAULT_LOGGER_TESTS)
605+ if (CMAKE_SYSTEM_NAME STREQUAL "iOS" )
606+ target_compile_definitions (onnxruntime_test_all_xc PUBLIC -DSKIP_DEFAULT_LOGGER_TESTS)
607+ endif ()
608+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
609+ target_compile_options (onnxruntime_test_all PUBLIC "-Wno-unused-const-variable" )
610+ endif ()
611+ if (onnxruntime_RUN_MODELTEST_IN_DEBUG_MODE)
612+ target_compile_definitions (onnxruntime_test_all PUBLIC -DRUN_MODELTEST_IN_DEBUG_MODE)
613+ endif ()
614+ if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS)
615+ target_compile_definitions (onnxruntime_test_all PRIVATE DEBUG_NODE_INPUTS_OUTPUTS)
616+ endif ()
617+ if (onnxruntime_USE_FEATURIZERS)
618+ target_include_directories (onnxruntime_test_all PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /external/FeaturizersLibrary/src)
619+ endif ()
620+ if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS)
621+ target_link_libraries (onnxruntime_test_all PRIVATE onnxruntime_language_interop onnxruntime_pyop)
622+ endif ()
627623
628- if (onnxruntime_USE_ROCM)
629- target_include_directories (onnxruntime_test_all PRIVATE ${onnxruntime_ROCM_HOME} /include /hiprand ${onnxruntime_ROCM_HOME} /include /rocrand)
630- endif ()
624+ if (onnxruntime_USE_ROCM)
625+ target_include_directories (onnxruntime_test_all PRIVATE ${onnxruntime_ROCM_HOME} /include /hiprand ${onnxruntime_ROCM_HOME} /include /rocrand)
626+ endif ()
631627
632- set (test_data_target onnxruntime_test_all)
628+ set (test_data_target onnxruntime_test_all)
633629
634630
635631#
@@ -872,7 +868,7 @@ if (onnxruntime_BUILD_SHARED_LIB)
872868 endif ()
873869 AddTest(DYN
874870 TARGET onnxruntime_shared_lib_test
875- SOURCES ${onnxruntime_shared_lib_test_SRC} ${TEST_SRC_DIR} /providers/test_main.cc
871+ SOURCES ${onnxruntime_shared_lib_test_SRC} ${onnxruntime_unittest_main_src}
876872 LIBS ${onnxruntime_shared_lib_test_LIBS}
877873 DEPENDS ${all_dependencies}
878874 )
@@ -905,6 +901,24 @@ if (onnxruntime_BUILD_SHARED_LIB)
905901 endif ()
906902endif ()
907903
904+ # the debug node IO functionality uses static variables, so it is best tested
905+ # in its own process
906+ if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS)
907+ AddTest(
908+ TARGET onnxruntime_test_debug_node_inputs_outputs
909+ SOURCES
910+ "${TEST_SRC_DIR} /debug_node_inputs_outputs/debug_node_inputs_outputs_utils_test.cc"
911+ "${TEST_SRC_DIR} /framework/TestAllocatorManager.cc"
912+ "${TEST_SRC_DIR} /providers/provider_test_utils.cc"
913+ ${onnxruntime_unittest_main_src}
914+ LIBS ${onnxruntime_test_providers_libs} ${onnxruntime_test_common_libs}
915+ DEPENDS ${all_dependencies}
916+ )
917+
918+ target_compile_definitions (onnxruntime_test_debug_node_inputs_outputs
919+ PRIVATE DEBUG_NODE_INPUTS_OUTPUTS)
920+ endif (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS)
921+
908922#some ETW tools
909923if (WIN32 AND onnxruntime_ENABLE_INSTRUMENT)
910924 add_executable (generate_perf_report_from_etl ${ONNXRUNTIME_ROOT} /tool/etw/main.cc
0 commit comments