@@ -1023,6 +1023,43 @@ endif()
10231023
10241024partition_provider_test_srcs(all_tests onnxruntime_provider_test_srcs onnxruntime_test_all_srcs)
10251025
1026+ # Workarounds for onnxruntime test targets.
1027+ function (onnxruntime_apply_test_target_workarounds target )
1028+ if (MSVC )
1029+ # TODO: The test code for OpenVINO, QNN, and WebGPU is getting flagged with a warning from ABSL for unreachable code.
1030+ # Need to figure out how those particular targets/build variants are failing, but regular windows is not.
1031+ target_compile_options (${target} PRIVATE "/wd4702" )
1032+ endif ()
1033+
1034+ # TODO fix shorten-64-to-32 warnings
1035+ # there are some in builds where sizeof(size_t) != sizeof(int64_t), e.g., in 'ONNX Runtime Web CI Pipeline'
1036+ if (HAS_SHORTEN_64_TO_32 AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
1037+ target_compile_options (${target} PRIVATE -Wno-error=shorten-64-to-32)
1038+ endif ()
1039+ endfunction ()
1040+
1041+ function (onnxruntime_apply_emscripten_test_link_settings target )
1042+ if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
1043+ set_target_properties (${target} PROPERTIES LINK_DEPENDS ${TEST_SRC_DIR} /wasm/onnxruntime_test_adapter.js)
1044+ set_target_properties (${target} PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT} /wasm/pre.js)
1045+ set_target_properties (${target} PROPERTIES LINK_FLAGS "-s STACK_SIZE=5242880 -s INITIAL_MEMORY=536870912 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4294967296 -s INCOMING_MODULE_JS_API=[preRun,locateFile,arguments,onExit,wasmMemory,buffer,instantiateWasm] --pre-js \" ${TEST_SRC_DIR} /wasm/onnxruntime_test_adapter.js\" --pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre.js\" -s \" EXPORTED_RUNTIME_METHODS=['FS']\" --preload-file ${CMAKE_CURRENT_BINARY_DIR} /testdata@/testdata -s EXIT_RUNTIME=1" )
1046+ if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
1047+ set_property (TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -s DEFAULT_PTHREAD_STACK_SIZE=131072 -s PROXY_TO_PTHREAD=1" )
1048+ endif ()
1049+ if (onnxruntime_USE_JSEP)
1050+ set_target_properties (${target} PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js)
1051+ set_property (TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " --pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js\" " )
1052+ endif ()
1053+
1054+ ###
1055+ ### if you want to investigate or debug a test failure in ${target}, replace the following line.
1056+ ### those flags slow down the CI test significantly, so we don't use them by default.
1057+ ###
1058+ # set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2")
1059+ set_property (TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=0 -s SAFE_HEAP=0 -s STACK_OVERFLOW_CHECK=1" )
1060+ endif ()
1061+ endfunction ()
1062+
10261063list (APPEND onnxruntime_test_all_srcs ${onnxruntime_unittest_main_src} )
10271064AddTest(
10281065 TARGET onnxruntime_test_all
@@ -1035,6 +1072,8 @@ AddTest(
10351072)
10361073target_include_directories (onnxruntime_test_all PRIVATE ${ONNXRUNTIME_ROOT} /core/flatbuffers/schema) # ort.fbs.h
10371074
1075+ onnxruntime_apply_test_target_workarounds(onnxruntime_test_all)
1076+
10381077if (MSVC )
10391078 # The warning means the type of two integral values around a binary operator is narrow than their result.
10401079 # If we promote the two input values first, it could be more tolerant to integer overflow.
@@ -1044,10 +1083,6 @@ if (MSVC)
10441083 target_compile_options (onnxruntime_test_all PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /wd4244>"
10451084 "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/wd4244>" )
10461085
1047- # TODO: The test code for OpenVINO, QNN, and WebGPU is getting flagged with a warning from ABSL for unreachabel code.
1048- # Need to figure out how those particular targets/build variants are failing, but regular windows is not.
1049- target_compile_options (onnxruntime_test_all PRIVATE "/wd4702" )
1050-
10511086 # Avoid this compile error in graph_transform_test.cc and qdq_transformer_test.cc:
10521087 # fatal error C1128: number of sections exceeded object file format limit: compile with /bigobj
10531088 set_property (SOURCE "${TEST_SRC_DIR} /optimizer/graph_transform_test.cc"
@@ -1057,18 +1092,6 @@ else()
10571092 target_compile_options (onnxruntime_test_all PRIVATE "-Wno-parentheses" )
10581093endif ()
10591094
1060- # TODO fix shorten-64-to-32 warnings
1061- # there are some in builds where sizeof(size_t) != sizeof(int64_t), e.g., in 'ONNX Runtime Web CI Pipeline'
1062- if (HAS_SHORTEN_64_TO_32 AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
1063- target_compile_options (onnxruntime_test_all PRIVATE -Wno-error=shorten-64-to-32)
1064- endif ()
1065-
1066- if (UNIX AND (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV))
1067- # The test_main.cc includes NvInfer.h where it has many deprecated declarations
1068- # simply ignore them for TensorRT EP build
1069- set_property (TARGET onnxruntime_test_all APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations" )
1070- endif ()
1071-
10721095if (MSVC AND onnxruntime_ENABLE_STATIC_ANALYSIS)
10731096# attention_op_test.cc: Function uses '49152' bytes of stack: exceeds /analyze:stacksize '16384'..
10741097target_compile_options (onnxruntime_test_all PRIVATE "/analyze:stacksize 131072" )
@@ -1099,25 +1122,7 @@ endif()
10991122if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
11001123 target_link_libraries (onnxruntime_test_all PRIVATE Python::Python)
11011124endif ()
1102- if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
1103- set_target_properties (onnxruntime_test_all PROPERTIES LINK_DEPENDS ${TEST_SRC_DIR} /wasm/onnxruntime_test_adapter.js)
1104- set_target_properties (onnxruntime_test_all PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT} /wasm/pre.js)
1105- set_target_properties (onnxruntime_test_all PROPERTIES LINK_FLAGS "-s STACK_SIZE=5242880 -s INITIAL_MEMORY=536870912 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4294967296 -s INCOMING_MODULE_JS_API=[preRun,locateFile,arguments,onExit,wasmMemory,buffer,instantiateWasm] --pre-js \" ${TEST_SRC_DIR} /wasm/onnxruntime_test_adapter.js\" --pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre.js\" -s \" EXPORTED_RUNTIME_METHODS=['FS']\" --preload-file ${CMAKE_CURRENT_BINARY_DIR} /testdata@/testdata -s EXIT_RUNTIME=1" )
1106- if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
1107- set_property (TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " -s DEFAULT_PTHREAD_STACK_SIZE=131072 -s PROXY_TO_PTHREAD=1" )
1108- endif ()
1109- if (onnxruntime_USE_JSEP)
1110- set_target_properties (onnxruntime_test_all PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js)
1111- set_property (TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " --pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js\" " )
1112- endif ()
1113-
1114- ###
1115- ### if you want to investigate or debug a test failure in onnxruntime_test_all, replace the following line.
1116- ### those flags slow down the CI test significantly, so we don't use them by default.
1117- ###
1118- # set_property(TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2")
1119- set_property (TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=0 -s SAFE_HEAP=0 -s STACK_OVERFLOW_CHECK=1" )
1120- endif ()
1125+ onnxruntime_apply_emscripten_test_link_settings(onnxruntime_test_all)
11211126
11221127if (onnxruntime_ENABLE_ATEN)
11231128 target_compile_definitions (onnxruntime_test_all PRIVATE ENABLE_ATEN)
@@ -1233,6 +1238,8 @@ block()
12331238 DEPENDS ${onnxruntime_provider_test_deps}
12341239 )
12351240
1241+ onnxruntime_apply_test_target_workarounds(onnxruntime_provider_test)
1242+
12361243 # Expose QNN SDK headers to unit tests via an interface target
12371244 if (onnxruntime_USE_QNN)
12381245 add_library (qnn_sdk_headers_include INTERFACE )
@@ -1242,49 +1249,9 @@ block()
12421249 target_link_libraries (onnxruntime_provider_test PRIVATE qnn_sdk_headers_include)
12431250 endif ()
12441251
1245- if (UNIX AND (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV))
1246- # The test_main.cc includes NvInfer.h where it has many deprecated declarations
1247- # simply ignore them for TensorRT EP build
1248- set_property (TARGET onnxruntime_provider_test APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations" )
1249- endif ()
1250-
12511252 # enable dynamic plugin EP usage
12521253 target_compile_definitions (onnxruntime_provider_test PRIVATE ORT_UNIT_TEST_ENABLE_DYNAMIC_PLUGIN_EP_USAGE)
1253-
1254-
1255- if (MSVC )
1256- # TODO: The test code for OpenVINO, QNN, and WebGPU is getting flagged with a warning from ABSL for unreachabel code.
1257- # Need to figure out how those particular targets/build variants are failing, but regular windows is not.
1258- target_compile_options (onnxruntime_provider_test PRIVATE "/wd4702" )
1259- endif ()
1260-
1261- # TODO fix shorten-64-to-32 warnings
1262- # there are some in builds where sizeof(size_t) != sizeof(int64_t), e.g., in 'ONNX Runtime Web CI Pipeline'
1263- if (HAS_SHORTEN_64_TO_32 AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
1264- target_compile_options (onnxruntime_provider_test PRIVATE -Wno-error=shorten-64-to-32)
1265- endif ()
1266-
1267- # copied from onnxruntime_test_all
1268- # TODO reuse instead of copy?
1269- if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
1270- set_target_properties (onnxruntime_provider_test PROPERTIES LINK_DEPENDS ${TEST_SRC_DIR} /wasm/onnxruntime_test_adapter.js)
1271- set_target_properties (onnxruntime_provider_test PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT} /wasm/pre.js)
1272- set_target_properties (onnxruntime_provider_test PROPERTIES LINK_FLAGS "-s STACK_SIZE=5242880 -s INITIAL_MEMORY=536870912 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4294967296 -s INCOMING_MODULE_JS_API=[preRun,locateFile,arguments,onExit,wasmMemory,buffer,instantiateWasm] --pre-js \" ${TEST_SRC_DIR} /wasm/onnxruntime_test_adapter.js\" --pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre.js\" -s \" EXPORTED_RUNTIME_METHODS=['FS']\" --preload-file ${CMAKE_CURRENT_BINARY_DIR} /testdata@/testdata -s EXIT_RUNTIME=1" )
1273- if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
1274- set_property (TARGET onnxruntime_provider_test APPEND_STRING PROPERTY LINK_FLAGS " -s DEFAULT_PTHREAD_STACK_SIZE=131072 -s PROXY_TO_PTHREAD=1" )
1275- endif ()
1276- if (onnxruntime_USE_JSEP)
1277- set_target_properties (onnxruntime_provider_test PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js)
1278- set_property (TARGET onnxruntime_provider_test APPEND_STRING PROPERTY LINK_FLAGS " --pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js\" " )
1279- endif ()
1280-
1281- ###
1282- ### if you want to investigate or debug a test failure in onnxruntime_provider_test, replace the following line.
1283- ### those flags slow down the CI test significantly, so we don't use them by default.
1284- ###
1285- # set_property(TARGET onnxruntime_provider_test APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2")
1286- set_property (TARGET onnxruntime_provider_test APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=0 -s SAFE_HEAP=0 -s STACK_OVERFLOW_CHECK=1" )
1287- endif ()
1254+ onnxruntime_apply_emscripten_test_link_settings(onnxruntime_provider_test)
12881255
12891256 if (IOS)
12901257 add_custom_command (
@@ -1654,12 +1621,6 @@ endif()
16541621 $<TARGET_FILE_DIR:onnxruntime_shared_lib_test>/testdata)
16551622 endif ()
16561623
1657- if (UNIX AND (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV))
1658- # The test_main.cc includes NvInfer.h where it has many deprecated declarations
1659- # simply ignore them for TensorRT EP build
1660- set_property (TARGET onnxruntime_shared_lib_test APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations" )
1661- endif ()
1662-
16631624 # test inference using global threadpools
16641625 if (NOT CMAKE_SYSTEM_NAME MATCHES "Android|iOS" AND NOT onnxruntime_MINIMAL_BUILD)
16651626 AddTest(DYN
@@ -1950,12 +1911,6 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
19501911 $<TARGET_FILE_DIR:onnxruntime_customopregistration_test>/testdata)
19511912 endif ()
19521913
1953- if (UNIX AND (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV))
1954- # The test_main.cc includes NvInfer.h where it has many deprecated declarations
1955- # simply ignore them for TensorRT EP build
1956- set_property (TARGET onnxruntime_customopregistration_test APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations" )
1957- endif ()
1958-
19591914 endif ()
19601915endif ()
19611916
@@ -2335,11 +2290,6 @@ if (onnxruntime_BUILD_SHARED_LIB AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
23352290 LIBS ${onnxruntime_ep_graph_test_LIBS}
23362291 DEPENDS ${all_dependencies}
23372292 )
2338- if (UNIX AND (onnxruntime_USE_TENSORRT OR onnxruntime_USE_NV))
2339- # The test_main.cc includes NvInfer.h where it has many deprecated declarations
2340- # simply ignore them for TensorRT EP build
2341- set_property (TARGET onnxruntime_ep_graph_test APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations" )
2342- endif ()
23432293endif ()
23442294
23452295include (onnxruntime_fuzz_test.cmake)
0 commit comments