1# Copyright (c) 2020-2023 Intel Corporation 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15include(ProcessorCount) 16 17# General function for test target generation 18function(tbb_add_test) 19 set(oneValueArgs SUBDIR NAME SUFFIX) 20 set(multiValueArgs DEPENDENCIES) 21 cmake_parse_arguments(_tbb_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 22 23 set(_tbb_test_TARGET_NAME ${_tbb_test_NAME}) 24 if (_tbb_test_SUFFIX) 25 set(_tbb_test_TARGET_NAME ${_tbb_test_NAME}_${_tbb_test_SUFFIX}) 26 endif() 27 28 # Define the target for test 29 add_executable(${_tbb_test_TARGET_NAME} ${_tbb_test_SUBDIR}/${_tbb_test_NAME}.cpp) 30 target_include_directories(${_tbb_test_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}) 31 32 # cmake>=3.4 no longer adds flags to export symbols from executables (CMP0065) 33 set_property(TARGET ${_tbb_test_TARGET_NAME} PROPERTY ENABLE_EXPORTS TRUE) 34 35 target_compile_options(${_tbb_test_TARGET_NAME} 36 PRIVATE 37 ${TBB_CXX_STD_FLAG} 38 ${TBB_WARNING_LEVEL} 39 # Warning suppression C4324: structure was padded due to alignment specifier 40 $<$<STREQUAL:${MSVC_CXX_ARCHITECTURE_ID},ARM64>:/wd4324> 41 ${TBB_TEST_WARNING_FLAGS} 42 ${TBB_TEST_COMPILE_FLAGS} 43 ${TBB_COMMON_COMPILE_FLAGS} 44 ) 45 46 if (ANDROID_PLATFORM) 47 # Expand the linker rpath by the CMAKE_LIBRARY_OUTPUT_DIRECTORY path since clang compiler from Android SDK 48 # doesn't respect the -L flag. 49 target_link_libraries(${_tbb_test_TARGET_NAME} PRIVATE "-Wl,--rpath-link,${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") 50 add_test(NAME ${_tbb_test_TARGET_NAME} 51 COMMAND ${CMAKE_COMMAND} 52 -DBINARIES_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} 53 -DTEST_NAME=${_tbb_test_TARGET_NAME} 54 -P ${PROJECT_SOURCE_DIR}/cmake/android/test_launcher.cmake) 55 else() 56 add_test(NAME ${_tbb_test_TARGET_NAME} COMMAND ${_tbb_test_TARGET_NAME} --force-colors=1 WORKING_DIRECTORY ${TBB_TEST_WORKING_DIRECTORY}) 57 # Additional testing scenarios if Intel(R) Software Development Emulator is found 58 if (UNIX AND ";test_mutex;conformance_mutex;" MATCHES ";${_tbb_test_TARGET_NAME};" AND SDE_EXE) 59 add_test(NAME ${_tbb_test_TARGET_NAME}_SDE COMMAND ${SDE_EXE} -nhm -rtm_mode disabled -- ./${_tbb_test_TARGET_NAME} --force-colors=1 WORKING_DIRECTORY ${TBB_TEST_WORKING_DIRECTORY}) 60 set_property(TEST ${_tbb_test_TARGET_NAME}_SDE PROPERTY ENVIRONMENT ${TBB_TESTS_ENVIRONMENT} APPEND) 61 endif() 62 endif() 63 64 set_property(TEST ${_tbb_test_TARGET_NAME} PROPERTY ENVIRONMENT ${TBB_TESTS_ENVIRONMENT} APPEND) 65 66 # Prefer using target_link_options instead of target_link_libraries to specify link options because 67 # target_link_libraries may incorrectly handle some options (on Windows, for example). 68 if (COMMAND target_link_options) 69 target_link_options(${_tbb_test_TARGET_NAME} PRIVATE ${TBB_COMMON_LINK_FLAGS} ${TBB_TEST_LINK_FLAGS}) 70 else() 71 target_link_libraries(${_tbb_test_TARGET_NAME} PRIVATE ${TBB_COMMON_LINK_FLAGS} ${TBB_TEST_LINK_FLAGS}) 72 endif() 73 74 target_compile_definitions(${_tbb_test_TARGET_NAME} PRIVATE 75 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 76 $<$<BOOL:${TBB_CPF}>:__TBB_CPF_BUILD=1> 77 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_DYNAMIC_LOAD_ENABLED=0> 78 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_SOURCE_DIRECTLY_INCLUDED=1>) 79 80 target_link_libraries(${_tbb_test_TARGET_NAME} PRIVATE ${_tbb_test_DEPENDENCIES} Threads::Threads ${TBB_COMMON_LINK_LIBS}) 81 82 if (COMMAND _tbb_run_memcheck) 83 _tbb_run_memcheck(${_tbb_test_NAME} ${_tbb_test_SUBDIR}) 84 endif() 85endfunction() 86 87# Function for C test target generation 88function(tbb_add_c_test) 89 set(oneValueArgs SUBDIR NAME) 90 set(multiValueArgs DEPENDENCIES) 91 cmake_parse_arguments(_tbb_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 92 93 # Define the target for test 94 95 add_executable(${_tbb_test_NAME} ${_tbb_test_SUBDIR}/${_tbb_test_NAME}.c) 96 target_include_directories(${_tbb_test_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}) 97 98 if (ANDROID_PLATFORM) 99 add_test(NAME ${_tbb_test_NAME} 100 COMMAND ${CMAKE_COMMAND} 101 -DBINARIES_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} 102 -DTEST_NAME=${_tbb_test_NAME} 103 -P ${PROJECT_SOURCE_DIR}/cmake/android/test_launcher.cmake) 104 else() 105 add_test(NAME ${_tbb_test_NAME} COMMAND ${_tbb_test_NAME} --force-colors=1 WORKING_DIRECTORY ${TBB_TEST_WORKING_DIRECTORY}) 106 endif() 107 108 set_property(TEST ${_tbb_test_NAME} PROPERTY ENVIRONMENT ${TBB_TESTS_ENVIRONMENT} APPEND) 109 110 target_compile_definitions(${_tbb_test_NAME} PRIVATE 111 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 112 $<$<BOOL:${TBB_CPF}>:__TBB_CPF_BUILD=1>) 113 114 target_link_libraries(${_tbb_test_NAME} PRIVATE ${_tbb_test_DEPENDENCIES} Threads::Threads) 115endfunction() 116 117# Function for lib test target generation 118function(tbb_add_lib_test) 119 set(oneValueArgs SUBDIR NAME) 120 set(multiValueArgs DEPENDENCIES) 121 cmake_parse_arguments(_tbb_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 122 123 add_library(_${_tbb_test_NAME} ${_tbb_test_SUBDIR}/${_tbb_test_NAME}.cpp) 124 125 target_include_directories(_${_tbb_test_NAME} 126 PUBLIC 127 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> 128 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 129 PRIVATE 130 ${CMAKE_CURRENT_SOURCE_DIR}/.. 131 ${CMAKE_CURRENT_SOURCE_DIR}) 132 133 # TODO: fix warnings 134 if (MSVC) 135 # signed unsigned mismatch, declaration hides class member 136 set(TBB_WARNING_SUPPRESS ${TBB_WARNING_SUPPRESS} /wd4267 /wd4244 /wd4245 /wd4018 /wd4458) 137 endif() 138 139 set(TEST_LIB_COMPILE_FLAGS -D_USRDLL) 140 # TODO: add ${TBB_WARNING_LEVEL} and fix problems 141 target_compile_options(_${_tbb_test_NAME} 142 PRIVATE 143 ${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC. 144 ${TBB_MMD_FLAG} 145 ${TBB_DSE_FLAG} 146 ${TBB_LIB_COMPILE_FLAGS} 147 ${TBBMALLOC_LIB_COMPILE_FLAGS} 148 ${TBB_COMMON_COMPILE_FLAGS} 149 ${TEST_LIB_COMPILE_FLAGS} 150 ) 151 152 target_compile_definitions(_${_tbb_test_NAME} PRIVATE 153 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 154 $<$<BOOL:${TBB_CPF}>:__TBB_CPF_BUILD=1> 155 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_DYNAMIC_LOAD_ENABLED=0> 156 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_SOURCE_DIRECTLY_INCLUDED=1>) 157 158 159 # Prefer using target_link_options instead of target_link_libraries to specify link options because 160 # target_link_libraries may incorrectly handle some options (on Windows, for example). 161 if (COMMAND target_link_options) 162 target_link_options(_${_tbb_test_NAME} 163 PRIVATE 164 ${TBB_LIB_LINK_FLAGS} 165 ${TBB_COMMON_LINK_FLAGS} 166 ) 167 else() 168 target_link_libraries(_${_tbb_test_NAME} 169 PRIVATE 170 ${TBB_LIB_LINK_FLAGS} 171 ${TBB_COMMON_LINK_FLAGS} 172 ) 173 endif() 174 175 target_link_libraries(_${_tbb_test_NAME} 176 PRIVATE 177 Threads::Threads 178 ${_tbb_test_DEPENDENCIES} 179 ${TBB_LIB_LINK_LIBS} 180 ${TBB_COMMON_LINK_LIBS} 181 ) 182endfunction() 183 184function(_tbb_get_hwloc_runtime_vars) 185 set(oneValueArgs ENV_EXTENSION_VARIABLE) 186 set(multiValueArgs HWLOC_VERSION_LIST) 187 cmake_parse_arguments(_runtime_vars "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 188 189 foreach(HWLOC_VERSION ${_runtime_vars_HWLOC_VERSION_LIST}) 190 get_target_property(HWLOC_LOCATION HWLOC::${HWLOC_VERSION} IMPORTED_LOCATION) 191 get_filename_component(HWLOC_LOCATION_PATH ${HWLOC_LOCATION} DIRECTORY) 192 list(APPEND LIBRARIES_PATH ${HWLOC_LOCATION_PATH}) 193 endforeach() 194 195 if (WIN32) 196 string(REPLACE ";" "\;" LIBRARIES_PATH "${LIBRARIES_PATH}\;$ENV{PATH}") 197 string(REPLACE "/" "\\" LIBRARIES_PATH "${LIBRARIES_PATH}") 198 set(${_runtime_vars_ENV_EXTENSION_VARIABLE} "PATH=${LIBRARIES_PATH}" PARENT_SCOPE) 199 else() 200 string(REPLACE ";" ":" LIBRARIES_PATH "${LIBRARIES_PATH}:$ENV{LD_LIBRARY_PATH}") 201 set(${_runtime_vars_ENV_EXTENSION_VARIABLE} "LD_LIBRARY_PATH=${LIBRARIES_PATH}" PARENT_SCOPE) 202 endif() 203endfunction() 204 205function(tbb_configure_hwloc_dependent_test) 206 set(oneValueArgs SUBDIR NAME SUFFIX TBBBIND_VERSION) 207 set(multiValueArgs HWLOC_REQUIRED_VERSION_LIST) 208 cmake_parse_arguments(_hwloc_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 209 210 set(HWLOC_REQUIREMENTS_SATISFIED TRUE) 211 foreach(HWLOC_TARGET ${_hwloc_test_HWLOC_REQUIRED_VERSION_LIST}) 212 if (NOT TARGET HWLOC::${HWLOC_TARGET}) 213 set(HWLOC_REQUIREMENTS_SATISFIED FALSE) 214 endif() 215 endforeach() 216 if (NOT HWLOC_REQUIREMENTS_SATISFIED) 217 return() 218 endif() 219 220 list(GET _hwloc_test_HWLOC_REQUIRED_VERSION_LIST 0 TEST_HWLOC_VERSION) 221 tbb_add_test( 222 SUBDIR ${_hwloc_test_SUBDIR} 223 NAME ${_hwloc_test_NAME} 224 SUFFIX ${_hwloc_test_SUFFIX} 225 DEPENDENCIES TBB::tbb HWLOC::${TEST_HWLOC_VERSION} 226 ) 227 228 _tbb_get_hwloc_runtime_vars( 229 ENV_EXTENSION_VARIABLE HWLOC_RUNTIME_VARS 230 HWLOC_VERSION_LIST ${_hwloc_test_HWLOC_REQUIRED_VERSION_LIST} 231 ) 232 233 set_property(TEST ${_hwloc_test_NAME}_${_hwloc_test_SUFFIX} PROPERTY ENVIRONMENT "${HWLOC_RUNTIME_VARS}" TBB_VERSION=1 APPEND) 234 set_tests_properties(${_hwloc_test_NAME}_${_hwloc_test_SUFFIX} PROPERTIES 235 PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*${_hwloc_test_TBBBIND_VERSION}" 236 FAIL_REGULAR_EXPRESSION "Status:.*FAILURE" 237 ) 238 239 # The tbbbind isn't loading on 32-bit Windows systems with more then 32 available hardware threads 240 if (WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND SYSTEM_CONCURRENCY GREATER 32) 241 set_tests_properties(${_hwloc_test_NAME}_${_hwloc_test_SUFFIX} PROPERTIES 242 PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*UNAVAILABLE" 243 FAIL_REGULAR_EXPRESSION "Status:.*FAILURE" 244 ) 245 else() 246 target_compile_definitions(${_hwloc_test_NAME}_${_hwloc_test_SUFFIX} PRIVATE __TBB_HWLOC_VALID_ENVIRONMENT) 247 endif() 248 249 add_dependencies(test_suite_arena_constraints ${_hwloc_test_NAME}_${_hwloc_test_SUFFIX}) 250endfunction() 251 252function(tbb_add_tbbbind_test) 253 set(oneValueArgs SUBDIR NAME) 254 cmake_parse_arguments(_tbbbind_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 255 256 tbb_add_test(SUBDIR ${_tbbbind_test_SUBDIR} NAME ${_tbbbind_test_NAME} DEPENDENCIES TBB::tbb) 257 add_dependencies(test_suite_arena_constraints ${_tbbbind_test_NAME}) 258 259 set_property(TEST ${_tbbbind_test_NAME} PROPERTY ENVIRONMENT TBB_VERSION=1 APPEND) 260 261 # Handle the case when HWLOC was found using pkg-config 262 if (NOT DEFINED HWLOC_TARGET_EXPLICITLY_DEFINED AND TARGET PkgConfig::HWLOC) 263 set_tests_properties(${_tbbbind_test_NAME} PROPERTIES 264 PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*${TBBBIND_LIBRARY_NAME}" 265 FAIL_REGULAR_EXPRESSION "Status: FAILURE!" 266 ) 267 target_link_libraries(${_tbbbind_test_NAME} PRIVATE PkgConfig::HWLOC) 268 target_compile_definitions(${_tbbbind_test_NAME} PRIVATE __TBB_HWLOC_VALID_ENVIRONMENT) 269 return() 270 endif() 271 272 # Disable all HWLOC dependent tests in case of unsupported environment. 273 if (TBB_WINDOWS_DRIVER OR ANDROID_PLATFORM OR APPLE OR NOT BUILD_SHARED_LIBS) 274 return() 275 endif() 276 ProcessorCount(SYSTEM_CONCURRENCY) 277 278 set_tests_properties(${_tbbbind_test_NAME} PROPERTIES 279 PASS_REGULAR_EXPRESSION "oneTBB: TBBBIND.*UNAVAILABLE" 280 FAIL_REGULAR_EXPRESSION "Status:.*FAILURE" 281 ) 282 283 if (TARGET HWLOC::hwloc_2_5 AND NOT HWLOC_2_5_TESTS_STATUS_SHOWN) 284 message(STATUS "HWLOC 2.5 dependent tests were enabled.") 285 set(HWLOC_2_5_TESTS_STATUS_SHOWN TRUE PARENT_SCOPE) 286 endif() 287 288 if (TARGET HWLOC::hwloc_2 AND NOT HWLOC_2_TESTS_STATUS_SHOWN) 289 message(STATUS "HWLOC 2 dependent tests were enabled.") 290 set(HWLOC_2_TESTS_STATUS_SHOWN TRUE PARENT_SCOPE) 291 endif() 292 293 if (TARGET HWLOC::hwloc_1_11 AND NOT HWLOC_1_11_TESTS_STATUS_SHOWN) 294 message(STATUS "HWLOC 1.11 dependent tests were enabled.") 295 set(HWLOC_1_11_TESTS_STATUS_SHOWN TRUE PARENT_SCOPE) 296 endif() 297 298 list(APPEND HWLOC_TEST_CASES 299 hwloc_2_5 300 hwloc_2 301 hwloc_1_11 302 hwloc_2_5_hwloc_2 303 hwloc_2_5_hwloc_1_11 304 hwloc_2_hwloc_1_11 305 hwloc_2_5_hwloc_2_hwloc_1_11 306 incompatible_hwlocs_1_11_vs_2_5 307 incompatible_hwlocs_1_11_vs_2 308 ) 309 310 list(APPEND HWLOC_TEST_CASE_0_VARS tbbbind_2_5 "hwloc_2_5") 311 list(APPEND HWLOC_TEST_CASE_1_VARS tbbbind_2 "hwloc_2") 312 list(APPEND HWLOC_TEST_CASE_2_VARS tbbbind "hwloc_1_11") 313 list(APPEND HWLOC_TEST_CASE_3_VARS tbbbind_2_5 "hwloc_2_5,hwloc_2") 314 list(APPEND HWLOC_TEST_CASE_4_VARS tbbbind_2_5 "hwloc_2_5,hwloc_1_11") 315 list(APPEND HWLOC_TEST_CASE_5_VARS tbbbind_2 "hwloc_2,hwloc_1_11") 316 list(APPEND HWLOC_TEST_CASE_6_VARS tbbbind_2_5 "hwloc_2_5,hwloc_2,hwloc_1_11") 317 list(APPEND HWLOC_TEST_CASE_7_VARS tbbbind_2_5 "hwloc_1_11,hwloc_2_5") 318 list(APPEND HWLOC_TEST_CASE_8_VARS tbbbind_2 "hwloc_1_11,hwloc_2") 319 320 foreach(TEST_CASE ${HWLOC_TEST_CASES}) 321 list(FIND HWLOC_TEST_CASES ${TEST_CASE} TEST_CASE_INDEX) 322 list(GET HWLOC_TEST_CASE_${TEST_CASE_INDEX}_VARS 0 TEST_CASE_TBBBIND_EXPECTED_VERSION) 323 list(GET HWLOC_TEST_CASE_${TEST_CASE_INDEX}_VARS 1 TEST_CASE_TBBBIND_HWLOC_REQUIRED_VERSIONS) 324 string(REPLACE "," ";" TEST_CASE_TBBBIND_HWLOC_REQUIRED_VERSIONS "${TEST_CASE_TBBBIND_HWLOC_REQUIRED_VERSIONS}") 325 326 tbb_configure_hwloc_dependent_test( 327 SUBDIR ${_tbbbind_test_SUBDIR} 328 NAME ${_tbbbind_test_NAME} 329 SUFFIX ${TEST_CASE} 330 TBBBIND_VERSION ${TEST_CASE_TBBBIND_EXPECTED_VERSION} 331 HWLOC_REQUIRED_VERSION_LIST ${TEST_CASE_TBBBIND_HWLOC_REQUIRED_VERSIONS} 332 ) 333 endforeach() 334endfunction() 335 336# Copy libraries to test folder to make it visible during tests execution if external TBB is tested. 337# TODO: check and update for multi-config generators. 338if (TBB_FOUND) 339 list(APPEND _tbb_test_components tbb tbbmalloc tbbmalloc_proxy tbbbind tbbbind_2_0 tbbbind_2_5) 340 foreach(_component ${_tbb_test_components}) 341 if (TARGET TBB::${_component}) 342 get_property(${_component}_lib_file_location TARGET TBB::${_component} PROPERTY LOCATION) 343 file(COPY ${${_component}_lib_file_location} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 344 unset(${_component}_lib_file_location CACHE) 345 endif() 346 endforeach() 347 unset(_tbb_test_components) 348endif() 349 350# Find Intel(R) Software Development Emulator to run test_mutex and conformance_mutex for coverage 351set(_sde_find_name sde) 352 353if (UNIX AND TBB_ARCH EQUAL 64) 354 set(_sde_find_name sde64) 355endif() 356 357find_program(SDE_EXE 358 NAMES ${_sde_find_name} 359 PATHS ENV PATH 360 PATH_SUFFIXES bin) 361 362unset(_sde_find_name) 363 364# Common target for the tbbbind related tests 365add_custom_target(test_suite_arena_constraints) 366 367# Check support for --no-as-needed linker option 368if (MINGW OR NOT WIN32) 369 include(CheckCXXSourceCompiles) 370 set(CMAKE_REQUIRED_LIBRARIES "-Wl,--no-as-needed") 371 check_cxx_source_compiles("int main(int, char*[]) { return 0; }" LINKER_HAS_NO_AS_NEEDED) 372 unset(CMAKE_REQUIRED_LIBRARIES) 373endif() 374 375if (TARGET TBB::tbb) 376 # Define the tests 377 tbb_add_test(SUBDIR tbb NAME test_tick_count DEPENDENCIES TBB::tbb) 378 tbb_add_test(SUBDIR tbb NAME test_allocators DEPENDENCIES TBB::tbb) 379 tbb_add_test(SUBDIR tbb NAME test_arena_priorities DEPENDENCIES TBB::tbb) 380 tbb_add_test(SUBDIR tbb NAME test_dynamic_link DEPENDENCIES TBB::tbb) 381 if (LINKER_HAS_NO_AS_NEEDED) 382 # The linker may not detect a dependency on pthread in static variable constructors. 383 target_link_libraries(test_dynamic_link PRIVATE "-Wl,--no-as-needed") 384 endif() 385 if (APPLE OR ANDROID_PLATFORM) 386 target_link_libraries(test_dynamic_link PRIVATE -rdynamic) 387 endif() 388 if (WIN32) 389 tbb_add_test(SUBDIR tbb NAME test_numa_dist DEPENDENCIES TBB::tbb) 390 endif() 391 tbb_add_test(SUBDIR tbb NAME test_collaborative_call_once DEPENDENCIES TBB::tbb) 392 tbb_add_test(SUBDIR tbb NAME test_concurrent_lru_cache DEPENDENCIES TBB::tbb) 393 tbb_add_test(SUBDIR tbb NAME test_concurrent_unordered_map DEPENDENCIES TBB::tbb) 394 tbb_add_test(SUBDIR tbb NAME test_concurrent_unordered_set DEPENDENCIES TBB::tbb) 395 tbb_add_test(SUBDIR tbb NAME test_concurrent_map DEPENDENCIES TBB::tbb) 396 tbb_add_test(SUBDIR tbb NAME test_concurrent_set DEPENDENCIES TBB::tbb) 397 tbb_add_test(SUBDIR tbb NAME test_concurrent_priority_queue DEPENDENCIES TBB::tbb) 398 tbb_add_test(SUBDIR tbb NAME test_partitioner DEPENDENCIES TBB::tbb) 399 tbb_add_test(SUBDIR tbb NAME test_parallel_for DEPENDENCIES TBB::tbb) 400 tbb_add_test(SUBDIR tbb NAME test_parallel_for_each DEPENDENCIES TBB::tbb) 401 tbb_add_test(SUBDIR tbb NAME test_parallel_reduce DEPENDENCIES TBB::tbb) 402 tbb_add_test(SUBDIR tbb NAME test_parallel_sort DEPENDENCIES TBB::tbb) 403 tbb_add_test(SUBDIR tbb NAME test_parallel_invoke DEPENDENCIES TBB::tbb) 404 tbb_add_test(SUBDIR tbb NAME test_parallel_scan DEPENDENCIES TBB::tbb) 405 tbb_add_test(SUBDIR tbb NAME test_parallel_pipeline DEPENDENCIES TBB::tbb) 406 tbb_add_test(SUBDIR tbb NAME test_eh_algorithms DEPENDENCIES TBB::tbb) 407 tbb_add_test(SUBDIR tbb NAME test_blocked_range DEPENDENCIES TBB::tbb) 408 tbb_add_test(SUBDIR tbb NAME test_concurrent_vector DEPENDENCIES TBB::tbb) 409 tbb_add_test(SUBDIR tbb NAME test_task_group DEPENDENCIES TBB::tbb) 410 tbb_add_test(SUBDIR tbb NAME test_concurrent_hash_map DEPENDENCIES TBB::tbb) 411 tbb_add_test(SUBDIR tbb NAME test_task_arena DEPENDENCIES TBB::tbb) 412 tbb_add_test(SUBDIR tbb NAME test_enumerable_thread_specific DEPENDENCIES TBB::tbb) 413 tbb_add_test(SUBDIR tbb NAME test_concurrent_queue DEPENDENCIES TBB::tbb) 414 tbb_add_test(SUBDIR tbb NAME test_resumable_tasks DEPENDENCIES TBB::tbb) 415 tbb_add_test(SUBDIR tbb NAME test_mutex DEPENDENCIES TBB::tbb) 416 tbb_add_test(SUBDIR tbb NAME test_function_node DEPENDENCIES TBB::tbb) 417 tbb_add_test(SUBDIR tbb NAME test_multifunction_node DEPENDENCIES TBB::tbb) 418 tbb_add_test(SUBDIR tbb NAME test_broadcast_node DEPENDENCIES TBB::tbb) 419 tbb_add_test(SUBDIR tbb NAME test_buffer_node DEPENDENCIES TBB::tbb) 420 tbb_add_test(SUBDIR tbb NAME test_composite_node DEPENDENCIES TBB::tbb) 421 tbb_add_test(SUBDIR tbb NAME test_continue_node DEPENDENCIES TBB::tbb) 422 tbb_add_test(SUBDIR tbb NAME test_eh_flow_graph DEPENDENCIES TBB::tbb) 423 tbb_add_test(SUBDIR tbb NAME test_flow_graph DEPENDENCIES TBB::tbb) 424 tbb_add_test(SUBDIR tbb NAME test_flow_graph_priorities DEPENDENCIES TBB::tbb) 425 tbb_add_test(SUBDIR tbb NAME test_flow_graph_whitebox DEPENDENCIES TBB::tbb) 426 tbb_add_test(SUBDIR tbb NAME test_indexer_node DEPENDENCIES TBB::tbb) 427 tbb_add_test(SUBDIR tbb NAME test_join_node DEPENDENCIES TBB::tbb) 428 tbb_add_test(SUBDIR tbb NAME test_join_node_key_matching DEPENDENCIES TBB::tbb) 429 tbb_add_test(SUBDIR tbb NAME test_join_node_key_matching_n_args DEPENDENCIES TBB::tbb) 430 tbb_add_test(SUBDIR tbb NAME test_join_node_msg_key_matching DEPENDENCIES TBB::tbb) 431 tbb_add_test(SUBDIR tbb NAME test_join_node_msg_key_matching_n_args DEPENDENCIES TBB::tbb) 432 tbb_add_test(SUBDIR tbb NAME test_join_node_preview DEPENDENCIES TBB::tbb) 433 tbb_add_test(SUBDIR tbb NAME test_limiter_node DEPENDENCIES TBB::tbb) 434 tbb_add_test(SUBDIR tbb NAME test_priority_queue_node DEPENDENCIES TBB::tbb) 435 tbb_add_test(SUBDIR tbb NAME test_queue_node DEPENDENCIES TBB::tbb) 436 tbb_add_test(SUBDIR tbb NAME test_sequencer_node DEPENDENCIES TBB::tbb) 437 tbb_add_test(SUBDIR tbb NAME test_split_node DEPENDENCIES TBB::tbb) 438 tbb_add_test(SUBDIR tbb NAME test_tagged_msg DEPENDENCIES TBB::tbb) 439 tbb_add_test(SUBDIR tbb NAME test_overwrite_node DEPENDENCIES TBB::tbb) 440 tbb_add_test(SUBDIR tbb NAME test_write_once_node DEPENDENCIES TBB::tbb) 441 tbb_add_test(SUBDIR tbb NAME test_async_node DEPENDENCIES TBB::tbb) 442 tbb_add_test(SUBDIR tbb NAME test_input_node DEPENDENCIES TBB::tbb) 443 tbb_add_test(SUBDIR tbb NAME test_profiling DEPENDENCIES TBB::tbb) 444 tbb_add_test(SUBDIR tbb NAME test_concurrent_queue_whitebox DEPENDENCIES TBB::tbb) 445 tbb_add_test(SUBDIR tbb NAME test_intrusive_list DEPENDENCIES TBB::tbb) 446 tbb_add_test(SUBDIR tbb NAME test_semaphore DEPENDENCIES TBB::tbb) 447 tbb_add_test(SUBDIR tbb NAME test_environment_whitebox DEPENDENCIES TBB::tbb) 448 tbb_add_test(SUBDIR tbb NAME test_hw_concurrency DEPENDENCIES TBB::tbb) 449 tbb_add_test(SUBDIR tbb NAME test_eh_thread DEPENDENCIES TBB::tbb) 450 tbb_add_test(SUBDIR tbb NAME test_global_control DEPENDENCIES TBB::tbb) 451 tbb_add_test(SUBDIR tbb NAME test_task DEPENDENCIES TBB::tbb) 452 453 if (TBB_FUZZ_TESTING AND NOT WIN32) 454 if (NOT ((CMAKE_CXX_COMPILER_ID STREQUAL Clang) OR (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM))) 455 message(FATAL_ERROR "Fuzzing requires Clang or IntelLLVM compiler.") 456 endif() 457 tbb_add_test(SUBDIR tbb NAME test_fuzzing) 458 add_dependencies(test_fuzzing test_task) 459 target_compile_definitions(test_fuzzing PRIVATE CMD="$<TARGET_FILE:test_task> >/dev/null 2>&1") 460 target_link_options(test_fuzzing PRIVATE -fsanitize=fuzzer) 461 endif() 462 463 tbb_add_test(SUBDIR tbb NAME test_concurrent_monitor DEPENDENCIES TBB::tbb) 464 tbb_add_test(SUBDIR tbb NAME test_scheduler_mix DEPENDENCIES TBB::tbb) 465 466 # test_handle_perror 467 tbb_add_test(SUBDIR tbb NAME test_handle_perror) 468 target_include_directories(test_handle_perror PRIVATE 469 $<TARGET_PROPERTY:TBB::tbb,INTERFACE_INCLUDE_DIRECTORIES> 470 ) 471 472 # HWLOC related test 473 if (NOT TBB_EMSCRIPTEN) 474 tbb_add_tbbbind_test(SUBDIR tbb NAME test_arena_constraints) 475 endif() 476 477 if ((NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips") AND (NOT TBB_EMSCRIPTEN)) 478 # TODO: Fix for MIPS 479 tbb_add_test(SUBDIR tbb NAME test_tbb_fork DEPENDENCIES TBB::tbb) 480 endif() 481 482 tbb_add_test(SUBDIR tbb NAME test_tbb_header DEPENDENCIES TBB::tbb) 483 target_sources(test_tbb_header PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tbb/test_tbb_header_secondary.cpp) 484 if (TBB_OPENMP_FLAG AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "(mips)") 485 tbb_add_test(SUBDIR tbb NAME test_openmp DEPENDENCIES TBB::tbb) 486 487 set_target_properties(test_openmp PROPERTIES COMPILE_FLAGS ${TBB_OPENMP_FLAG}) 488 489 if (NOT TBB_OPENMP_NO_LINK_FLAG) 490 set_target_properties(test_openmp PROPERTIES LINK_FLAGS ${TBB_OPENMP_FLAG}) 491 endif() 492 endif() 493 494 # Define the conformance tests 495 tbb_add_test(SUBDIR conformance NAME conformance_tick_count DEPENDENCIES TBB::tbb) 496 tbb_add_test(SUBDIR conformance NAME conformance_allocators DEPENDENCIES TBB::tbb) 497 tbb_add_test(SUBDIR conformance NAME conformance_mutex DEPENDENCIES TBB::tbb) 498 tbb_add_test(SUBDIR conformance NAME conformance_task_group DEPENDENCIES TBB::tbb) 499 tbb_add_test(SUBDIR conformance NAME conformance_task_group_context DEPENDENCIES TBB::tbb) 500 tbb_add_test(SUBDIR conformance NAME conformance_task_arena DEPENDENCIES TBB::tbb) 501 tbb_add_test(SUBDIR conformance NAME conformance_collaborative_call_once DEPENDENCIES TBB::tbb) 502 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_lru_cache DEPENDENCIES TBB::tbb) 503 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_unordered_map DEPENDENCIES TBB::tbb) 504 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_unordered_set DEPENDENCIES TBB::tbb) 505 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_map DEPENDENCIES TBB::tbb) 506 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_set DEPENDENCIES TBB::tbb) 507 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_priority_queue DEPENDENCIES TBB::tbb) 508 tbb_add_test(SUBDIR conformance NAME conformance_parallel_for DEPENDENCIES TBB::tbb) 509 tbb_add_test(SUBDIR conformance NAME conformance_parallel_for_each DEPENDENCIES TBB::tbb) 510 tbb_add_test(SUBDIR conformance NAME conformance_parallel_reduce DEPENDENCIES TBB::tbb) 511 tbb_add_test(SUBDIR conformance NAME conformance_parallel_scan DEPENDENCIES TBB::tbb) 512 tbb_add_test(SUBDIR conformance NAME conformance_parallel_sort DEPENDENCIES TBB::tbb) 513 tbb_add_test(SUBDIR conformance NAME conformance_parallel_pipeline DEPENDENCIES TBB::tbb) 514 tbb_add_test(SUBDIR conformance NAME conformance_parallel_invoke DEPENDENCIES TBB::tbb) 515 tbb_add_test(SUBDIR conformance NAME conformance_blocked_range DEPENDENCIES TBB::tbb) 516 tbb_add_test(SUBDIR conformance NAME conformance_blocked_range2d DEPENDENCIES TBB::tbb) 517 tbb_add_test(SUBDIR conformance NAME conformance_blocked_range3d DEPENDENCIES TBB::tbb) 518 tbb_add_test(SUBDIR conformance NAME conformance_blocked_rangeNd DEPENDENCIES TBB::tbb) 519 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_vector DEPENDENCIES TBB::tbb) 520 tbb_add_test(SUBDIR conformance NAME conformance_global_control DEPENDENCIES TBB::tbb) 521 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_hash_map DEPENDENCIES TBB::tbb) 522 tbb_add_test(SUBDIR conformance NAME conformance_enumerable_thread_specific DEPENDENCIES TBB::tbb) 523 tbb_add_test(SUBDIR conformance NAME conformance_combinable DEPENDENCIES TBB::tbb) 524 tbb_add_test(SUBDIR conformance NAME conformance_concurrent_queue DEPENDENCIES TBB::tbb) 525 tbb_add_test(SUBDIR conformance NAME conformance_resumable_tasks DEPENDENCIES TBB::tbb) 526 tbb_add_test(SUBDIR conformance NAME conformance_version DEPENDENCIES TBB::tbb) 527 # functional nodes conformance 528 tbb_add_test(SUBDIR conformance NAME conformance_function_node DEPENDENCIES TBB::tbb) 529 tbb_add_test(SUBDIR conformance NAME conformance_multifunction_node DEPENDENCIES TBB::tbb) 530 tbb_add_test(SUBDIR conformance NAME conformance_input_node DEPENDENCIES TBB::tbb) 531 tbb_add_test(SUBDIR conformance NAME conformance_continue_node DEPENDENCIES TBB::tbb) 532 tbb_add_test(SUBDIR conformance NAME conformance_async_node DEPENDENCIES TBB::tbb) 533 # buffering nodes conformance 534 tbb_add_test(SUBDIR conformance NAME conformance_overwrite_node DEPENDENCIES TBB::tbb) 535 tbb_add_test(SUBDIR conformance NAME conformance_write_once_node DEPENDENCIES TBB::tbb) 536 tbb_add_test(SUBDIR conformance NAME conformance_buffer_node DEPENDENCIES TBB::tbb) 537 tbb_add_test(SUBDIR conformance NAME conformance_queue_node DEPENDENCIES TBB::tbb) 538 tbb_add_test(SUBDIR conformance NAME conformance_priority_queue_node DEPENDENCIES TBB::tbb) 539 tbb_add_test(SUBDIR conformance NAME conformance_sequencer_node DEPENDENCIES TBB::tbb) 540 # service nodes conformance 541 tbb_add_test(SUBDIR conformance NAME conformance_limiter_node DEPENDENCIES TBB::tbb) 542 tbb_add_test(SUBDIR conformance NAME conformance_broadcast_node DEPENDENCIES TBB::tbb) 543 tbb_add_test(SUBDIR conformance NAME conformance_composite_node DEPENDENCIES TBB::tbb) 544 tbb_add_test(SUBDIR conformance NAME conformance_indexer_node DEPENDENCIES TBB::tbb) 545 tbb_add_test(SUBDIR conformance NAME conformance_split_node DEPENDENCIES TBB::tbb) 546 tbb_add_test(SUBDIR conformance NAME conformance_join_node DEPENDENCIES TBB::tbb) 547 # flowraph auxiliary conformance 548 # TODO: add conformance tests for graph_node, continue_msg, tagged_msg, copy_body, input_port, output_port, make_edge, remove_edge 549 tbb_add_test(SUBDIR conformance NAME conformance_graph DEPENDENCIES TBB::tbb) 550 551 # HWLOC related conformance 552 if (NOT TBB_EMSCRIPTEN) 553 tbb_add_tbbbind_test(SUBDIR conformance NAME conformance_arena_constraints) 554 endif() 555 556 if (MSVC AND BUILD_SHARED_LIBS AND CMAKE_VERSION VERSION_GREATER 3.13) # LINK_OPTIONS property first appeared in 3.13 557 # version of the CMake 558 tbb_add_test(SUBDIR tbb NAME test_implicit_linkage_on_windows) 559 # TODO: consider setting environment instead of passing additional 560 # compiler and linker options 561 target_include_directories(test_implicit_linkage_on_windows PRIVATE 562 $<TARGET_PROPERTY:TBB::tbb,INTERFACE_INCLUDE_DIRECTORIES>) 563 set_target_properties(test_implicit_linkage_on_windows PROPERTIES 564 LINK_OPTIONS LINKER:/LIBPATH:$<TARGET_LINKER_FILE_DIR:TBB::tbb>) 565 add_dependencies(test_implicit_linkage_on_windows TBB::tbb) 566 endif() 567endif() 568 569if (TARGET TBB::tbbmalloc) 570 # TBB allocator tests 571 if (NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips") 572 if (NOT TBB_EMSCRIPTEN) 573 # Define TBB malloc tests 574 tbb_add_test(SUBDIR tbbmalloc NAME test_scalable_allocator DEPENDENCIES TBB::tbbmalloc) 575 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_pools DEPENDENCIES TBB::tbbmalloc) 576 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_init_shutdown DEPENDENCIES TBB::tbbmalloc) 577 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_regression DEPENDENCIES TBB::tbbmalloc) 578 if (TARGET TBB::tbb) 579 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_shutdown_hang DEPENDENCIES TBB::tbb TBB::tbbmalloc) 580 endif() 581 582 if (NOT (WINDOWS_STORE OR TBB_WINDOWS_DRIVER)) 583 # TODO: Consider adding following tests on WINDOWS_STORE and TBB_WINDOWS_DRIVER platforms 584 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_compliance DEPENDENCIES TBB::tbbmalloc) 585 tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_used_by_lib DEPENDENCIES TBB::tbbmalloc) 586 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_used_by_lib DEPENDENCIES _test_malloc_used_by_lib) 587 tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_lib_unload) 588 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_lib_unload DEPENDENCIES _test_malloc_lib_unload) 589 endif() 590 591 enable_language(C) 592 tbb_add_c_test(SUBDIR tbbmalloc NAME test_malloc_pure_c DEPENDENCIES TBB::tbbmalloc) 593 endif() 594 # ---------------------------------------------------------------------------------------- 595 # Whitebox testing 596 597 add_executable(test_malloc_whitebox tbbmalloc/test_malloc_whitebox.cpp) 598 599 target_include_directories(test_malloc_whitebox 600 PRIVATE 601 ${CMAKE_CURRENT_SOURCE_DIR}/../include 602 ${CMAKE_CURRENT_SOURCE_DIR}/.. 603 ${CMAKE_CURRENT_SOURCE_DIR}) 604 target_compile_definitions(test_malloc_whitebox PRIVATE __TBBMALLOC_BUILD) 605 target_compile_options(test_malloc_whitebox 606 PRIVATE 607 ${TBB_CXX_STD_FLAG} 608 ${TBB_WARNING_SUPPRESS} 609 ${TBB_TEST_COMPILE_FLAGS} 610 ${TBB_COMMON_COMPILE_FLAGS} 611 ${TBBMALLOC_LIB_COMPILE_FLAGS} 612 ) 613 if (ANDROID_PLATFORM) 614 add_test(NAME test_malloc_whitebox 615 COMMAND ${CMAKE_COMMAND} 616 -DBINARIES_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} 617 -DTEST_NAME=test_malloc_whitebox 618 -P ${PROJECT_SOURCE_DIR}/cmake/android/test_launcher.cmake) 619 else() 620 add_test(NAME test_malloc_whitebox COMMAND test_malloc_whitebox --force-colors=1) 621 endif() 622 if (COMMAND target_link_options) 623 target_link_options(test_malloc_whitebox PRIVATE ${TBB_COMMON_LINK_FLAGS}) 624 else() 625 target_link_libraries(test_malloc_whitebox PRIVATE ${TBB_COMMON_LINK_FLAGS}) 626 endif() 627 target_link_libraries(test_malloc_whitebox PRIVATE Threads::Threads ${TBB_COMMON_LINK_LIBS}) 628 629 # ------------------------------------------------------------------------------------------ 630 631 # Define TBB malloc conformance tests 632 # tbbmalloc_add_test(conformance conformance_scalable_allocator) 633 634 if ("${CMAKE_MSVC_RUNTIME_LIBRARY}" STREQUAL MultiThreaded OR "${CMAKE_MSVC_RUNTIME_LIBRARY}" STREQUAL MultiThreadedDebug) 635 if ("${CMAKE_MSVC_RUNTIME_LIBRARY}" STREQUAL MultiThreaded) 636 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) 637 else() 638 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL) 639 endif() 640 endif() 641 642 # Thread Sanitizer overloads memory management routines that conflicts with tbbmalloc_proxy. 643 if (BUILD_SHARED_LIBS AND NOT TBB_SANITIZE MATCHES "thread" AND TBBMALLOC_PROXY_BUILD AND NOT MSVC_CXX_ARCHITECTURE_ID MATCHES "ARM64") 644 # Define TBB malloc proxy tests 645 tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_atexit DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc) 646 if (NOT TBB_EMSCRIPTEN) 647 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_atexit DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc _test_malloc_atexit) 648 endif() 649 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_overload DEPENDENCIES TBB::tbbmalloc_proxy) 650 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_overload_disable DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc) # safer_msize call need to be available 651 tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_new_handler DEPENDENCIES TBB::tbbmalloc_proxy) 652 endif() 653 endif() 654endif() 655 656unset(HWLOC_2_5_TESTS_STATUS_SHOWN) 657unset(HWLOC_2_TESTS_STATUS_SHOWN) 658unset(HWLOC_1_11_TESTS_STATUS_SHOWN) 659