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 15option(TBB_VALGRIND_MEMCHECK "Enable scan for memory leaks using Valgrind" OFF) 16 17if (NOT TBB_VALGRIND_MEMCHECK) 18 return() 19endif() 20 21add_custom_target(memcheck-all 22 COMMENT "Run memcheck on all tests") 23 24find_program(VALGRIND_EXE valgrind) 25 26if (NOT VALGRIND_EXE) 27 message(FATAL_ERROR "Valgrind executable is not found, add tool to PATH or turn off TBB_VALGRIND_MEMCHECK") 28else() 29 message(STATUS "Found Valgrind to run memory leak scan") 30endif() 31 32file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/memcheck) 33 34function(_tbb_run_memcheck test_target subdir) 35 set(target_name memcheck-${test_target}) 36 if(${subdir} STREQUAL "tbbmalloc") 37 # Valgring intercepts all allocation symbols with its own by default, 38 # so it disables using tbbmalloc. In case of tbbmalloc tests 39 # intercept allocation symbols only in the default system libraries, 40 # but not in any other shared library or the executable 41 # defining public malloc or operator new related functions. 42 set(option "--soname-synonyms=somalloc=nouserintercepts") 43 endif() 44 add_custom_target(${target_name} 45 COMMAND ${VALGRIND_EXE} ${option} --leak-check=full --show-leak-kinds=all --log-file=${CMAKE_BINARY_DIR}/memcheck/${target_name}.log -v $<TARGET_FILE:${test_target}>) 46 add_dependencies(memcheck-all ${target_name}) 47endfunction() 48 49add_custom_target(memcheck-short 50 COMMENT "Run memcheck scan on specified list") 51 52# List of reasonable and quick enough tests to use in automated memcheck 53add_dependencies(memcheck-short 54 memcheck-test_allocators 55 memcheck-test_arena_constraints 56 memcheck-test_dynamic_link 57 memcheck-test_concurrent_lru_cache 58 memcheck-conformance_concurrent_unordered_map 59 memcheck-conformance_concurrent_unordered_set 60 memcheck-conformance_concurrent_map 61 memcheck-conformance_concurrent_set 62 memcheck-conformance_concurrent_priority_queue 63 memcheck-conformance_concurrent_vector 64 memcheck-conformance_concurrent_queue 65 memcheck-conformance_concurrent_hash_map 66 memcheck-test_parallel_for 67 memcheck-test_parallel_for_each 68 memcheck-test_parallel_reduce 69 memcheck-test_parallel_sort 70 memcheck-test_parallel_invoke 71 memcheck-test_parallel_scan 72 memcheck-test_parallel_pipeline 73 memcheck-test_eh_algorithms 74 memcheck-test_task_group 75 memcheck-test_task_arena 76 memcheck-test_enumerable_thread_specific 77 memcheck-test_resumable_tasks 78 memcheck-conformance_mutex 79 memcheck-test_function_node 80 memcheck-test_multifunction_node 81 memcheck-test_broadcast_node 82 memcheck-test_buffer_node 83 memcheck-test_composite_node 84 memcheck-test_continue_node 85 memcheck-test_eh_flow_graph 86 memcheck-test_flow_graph 87 memcheck-test_flow_graph_priorities 88 memcheck-test_flow_graph_whitebox 89 memcheck-test_indexer_node 90 memcheck-test_join_node 91 memcheck-test_join_node_key_matching 92 memcheck-test_join_node_msg_key_matching 93 memcheck-test_priority_queue_node 94 memcheck-test_sequencer_node 95 memcheck-test_split_node 96 memcheck-test_tagged_msg 97 memcheck-test_overwrite_node 98 memcheck-test_write_once_node 99 memcheck-test_async_node 100 memcheck-test_input_node 101 memcheck-test_profiling 102 memcheck-test_concurrent_queue_whitebox 103 memcheck-test_intrusive_list 104 memcheck-test_semaphore 105 memcheck-test_environment_whitebox 106 memcheck-test_handle_perror 107 memcheck-test_hw_concurrency 108 memcheck-test_eh_thread 109 memcheck-test_global_control 110 memcheck-test_task 111 memcheck-test_concurrent_monitor 112) 113