2023-01-16 01:02:17 -06:00
|
|
|
# Copyright (C) 2018-2023 Intel Corporation
|
2020-04-13 13:17:23 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
2021-06-24 05:14:04 -05:00
|
|
|
|
2021-03-28 12:05:45 -05:00
|
|
|
set(OV_COVERAGE_GCDA_DATA_DIRECTORY "${CMAKE_BINARY_DIR}")
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
if (NOT TARGET ov_coverage)
|
|
|
|
add_custom_target(ov_coverage)
|
|
|
|
set_target_properties(ov_coverage PROPERTIES FOLDER coverage)
|
2020-04-13 13:17:23 -05:00
|
|
|
endif()
|
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
if(NOT TARGET ov_coverage_clean)
|
|
|
|
add_custom_target(ov_coverage_clean)
|
|
|
|
set_target_properties(ov_coverage_clean PROPERTIES FOLDER coverage)
|
2020-04-13 13:17:23 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
set(OV_COVERAGE_REPORTS "${CMAKE_BINARY_DIR}/coverage")
|
2023-10-09 13:30:32 -05:00
|
|
|
set(OV_COVERAGE_SCRIPT_DIR "${OpenVINODeveloperScripts_DIR}/coverage")
|
2020-04-13 13:17:23 -05:00
|
|
|
|
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
|
|
|
#
|
2022-09-19 02:04:10 -05:00
|
|
|
# ov_coverage_clean(REPOSITORY <repo> DIRECTORY <dir>)
|
2020-04-13 13:17:23 -05:00
|
|
|
#
|
2022-09-19 02:04:10 -05:00
|
|
|
function(ov_coverage_clean)
|
|
|
|
cmake_parse_arguments(OV_COVERAGE "" "REPOSITORY;DIRECTORY" "" ${ARGN})
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
add_custom_target(ov_coverage_zerocounters_${OV_COVERAGE_REPOSITORY}
|
2020-04-27 13:21:29 -05:00
|
|
|
COMMAND lcov --zerocounters --quiet
|
2022-09-19 02:04:10 -05:00
|
|
|
--directory "${OV_COVERAGE_DIRECTORY}"
|
|
|
|
COMMENT "Add zero counters for coverage for ${OV_COVERAGE_REPOSITORY}"
|
2020-04-27 13:21:29 -05:00
|
|
|
VERBATIM)
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
add_custom_target(ov_coverage_clean_${OV_COVERAGE_REPOSITORY}
|
2020-04-13 13:17:23 -05:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
2022-09-19 02:04:10 -05:00
|
|
|
-D "OV_COVERAGE_REPORTS=${OV_COVERAGE_REPORTS}"
|
|
|
|
-D "OV_COVERAGE_DIRECTORY=${OV_COVERAGE_DIRECTORY}"
|
2020-04-13 13:17:23 -05:00
|
|
|
-D "CMAKE_BINARY_DIRECTORY=${CMAKE_BINARY_DIR}"
|
|
|
|
-D "CMAKE_SOURCE_DIRECTORY=${CMAKE_SOURCE_DIR}"
|
2022-09-19 02:04:10 -05:00
|
|
|
-P "${OV_COVERAGE_SCRIPT_DIR}/coverage_clean.cmake"
|
|
|
|
COMMENT "Clean previously created HTML report files for ${OV_COVERAGE_REPOSITORY}"
|
|
|
|
DEPENDS "${OV_COVERAGE_SCRIPT_DIR}/coverage_clean.cmake"
|
2020-04-13 13:17:23 -05:00
|
|
|
VERBATIM)
|
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
set_target_properties(ov_coverage_zerocounters_${OV_COVERAGE_REPOSITORY}
|
|
|
|
ov_coverage_clean_${OV_COVERAGE_REPOSITORY}
|
2020-04-27 13:21:29 -05:00
|
|
|
PROPERTIES FOLDER coverage)
|
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
add_dependencies(ov_coverage_clean ov_coverage_zerocounters_${OV_COVERAGE_REPOSITORY}
|
|
|
|
ov_coverage_clean_${OV_COVERAGE_REPOSITORY})
|
2020-04-13 13:17:23 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
2022-09-19 02:04:10 -05:00
|
|
|
# ov_coverage_capture(INFO_FILE <info_file>
|
2020-04-13 13:17:23 -05:00
|
|
|
# BASE_DIRECTORY <base dir>
|
2022-09-19 02:04:10 -05:00
|
|
|
# DIRECTORY <gcda dir>
|
2022-09-19 09:20:05 -05:00
|
|
|
# EXCLUDE_PATTERNS exclude_patterns,...)
|
2020-04-13 13:17:23 -05:00
|
|
|
#
|
2022-09-19 02:04:10 -05:00
|
|
|
function(ov_coverage_capture)
|
2022-09-19 09:20:05 -05:00
|
|
|
cmake_parse_arguments(OV_COVERAGE "" "INFO_FILE;BASE_DIRECTORY;DIRECTORY" "EXCLUDE_PATTERNS" ${ARGN})
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
set(output_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INFO_FILE}.info")
|
|
|
|
set(output_base_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INFO_FILE}_base.info")
|
|
|
|
set(output_tests_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INFO_FILE}_tests.info")
|
2020-04-13 13:17:23 -05:00
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_base_file}
|
2022-09-19 02:04:10 -05:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${OV_COVERAGE_REPORTS}"
|
2020-04-13 13:17:23 -05:00
|
|
|
COMMAND lcov --no-external --capture --initial --quiet
|
2022-09-19 02:04:10 -05:00
|
|
|
--directory "${OV_COVERAGE_DIRECTORY}"
|
|
|
|
--base-directory "${OV_COVERAGE_BASE_DIRECTORY}"
|
2020-04-13 13:17:23 -05:00
|
|
|
--output-file ${output_base_file}
|
2022-09-19 02:04:10 -05:00
|
|
|
COMMENT "Capture initial coverage data ${OV_COVERAGE_INFO_FILE}"
|
2020-04-13 13:17:23 -05:00
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_tests_file}
|
2022-09-19 02:04:10 -05:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${OV_COVERAGE_REPORTS}"
|
2020-04-13 13:17:23 -05:00
|
|
|
COMMAND lcov --no-external --capture --quiet
|
2022-09-19 02:04:10 -05:00
|
|
|
--directory "${OV_COVERAGE_DIRECTORY}"
|
|
|
|
--base-directory "${OV_COVERAGE_BASE_DIRECTORY}"
|
2020-04-13 13:17:23 -05:00
|
|
|
--output-file ${output_tests_file}
|
2022-09-19 02:04:10 -05:00
|
|
|
COMMENT "Capture test coverage data ${OV_COVERAGE_INFO_FILE}"
|
2020-04-13 13:17:23 -05:00
|
|
|
VERBATIM)
|
|
|
|
|
2022-09-19 09:20:05 -05:00
|
|
|
if (OV_COVERAGE_EXCLUDE_PATTERNS)
|
2022-09-19 02:04:10 -05:00
|
|
|
set(out_suf ".tmp")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_file}${out_suf}
|
2020-04-13 13:17:23 -05:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
2022-09-19 02:04:10 -05:00
|
|
|
-D "OV_COVERAGE_OUTPUT_FILE=${output_file}${out_suf}"
|
|
|
|
-D "OV_COVERAGE_INPUT_FILES=${output_base_file};${output_tests_file}"
|
|
|
|
-P "${OV_COVERAGE_SCRIPT_DIR}/coverage_merge.cmake"
|
|
|
|
COMMENT "Generate total coverage data ${OV_COVERAGE_INFO_FILE}"
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${output_base_file} ${output_tests_file}
|
|
|
|
VERBATIM)
|
|
|
|
|
2022-09-19 09:20:05 -05:00
|
|
|
if (OV_COVERAGE_EXCLUDE_PATTERNS)
|
2022-09-19 02:04:10 -05:00
|
|
|
set(commands lcov --quiet)
|
2022-09-19 09:20:05 -05:00
|
|
|
foreach(pattern IN LISTS OV_COVERAGE_EXCLUDE_PATTERNS)
|
2022-09-19 02:04:10 -05:00
|
|
|
list(APPEND commands --remove ${output_file}${out_suf} ${pattern})
|
|
|
|
endforeach()
|
|
|
|
list(APPEND commands --output-file ${output_file})
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_file}
|
|
|
|
COMMAND ${commands}
|
|
|
|
COMMENT "Exclude patterns from report ${OV_COVERAGE_OUTPUT}"
|
|
|
|
DEPENDS ${output_file}${out_suf}
|
|
|
|
VERBATIM)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(ov_coverage_${OV_COVERAGE_INFO_FILE}_info
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${output_file})
|
2022-09-19 02:04:10 -05:00
|
|
|
set_target_properties(ov_coverage_${OV_COVERAGE_INFO_FILE}_info
|
2020-04-27 13:21:29 -05:00
|
|
|
PROPERTIES FOLDER coverage)
|
2020-04-13 13:17:23 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
2022-09-19 02:04:10 -05:00
|
|
|
# ov_coverage_extract(INPUT <info_file> OUTPUT <output_file> PATTERNS <patterns ...>)
|
2020-04-13 13:17:23 -05:00
|
|
|
#
|
2022-09-19 02:04:10 -05:00
|
|
|
function(ov_coverage_extract)
|
|
|
|
cmake_parse_arguments(OV_COVERAGE "" "INPUT;OUTPUT" "PATTERNS" ${ARGN})
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
set(input_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INPUT}.info")
|
|
|
|
set(output_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_OUTPUT}.info")
|
2020-04-13 13:17:23 -05:00
|
|
|
|
|
|
|
set(commands lcov --quiet)
|
2022-09-19 02:04:10 -05:00
|
|
|
foreach(pattern IN LISTS OV_COVERAGE_PATTERNS)
|
2020-04-13 13:17:23 -05:00
|
|
|
list(APPEND commands --extract ${input_file} ${pattern})
|
|
|
|
endforeach()
|
|
|
|
list(APPEND commands --output-file ${output_file})
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_file}
|
|
|
|
COMMAND ${commands}
|
2022-09-19 02:04:10 -05:00
|
|
|
COMMENT "Generate coverage data ${OV_COVERAGE_OUTPUT}"
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${input_file}
|
|
|
|
VERBATIM)
|
2022-09-19 02:04:10 -05:00
|
|
|
add_custom_target(ov_coverage_${OV_COVERAGE_OUTPUT}_info
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${output_file})
|
2022-09-19 02:04:10 -05:00
|
|
|
set_target_properties(ov_coverage_${OV_COVERAGE_OUTPUT}_info
|
2020-04-27 13:21:29 -05:00
|
|
|
PROPERTIES FOLDER coverage)
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
add_dependencies(ov_coverage_${OV_COVERAGE_OUTPUT}_info ov_coverage_${OV_COVERAGE_INPUT}_info)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
|
|
|
# ov_coverage_genhtml(INFO_FILE <info_file> PREFIX <prefix>)
|
|
|
|
#
|
|
|
|
function(ov_coverage_genhtml)
|
|
|
|
cmake_parse_arguments(OV_COVERAGE "" "INFO_FILE;PREFIX" "" ${ARGN})
|
|
|
|
|
|
|
|
set(input_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INFO_FILE}.info")
|
|
|
|
set(output_directory "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INFO_FILE}")
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT "${output_directory}/index.html"
|
|
|
|
COMMAND [ -s ${input_file} ] && genhtml ${input_file} --title "${OV_COVERAGE_INFO_FILE}" --legend
|
|
|
|
--no-branch-coverage --demangle-cpp
|
|
|
|
--output-directory "${output_directory}"
|
|
|
|
--num-spaces 4 --quiet
|
|
|
|
--prefix "${OV_COVERAGE_PREFIX}" || echo "Skip ${input_file}"
|
|
|
|
DEPENDS ${input_file}
|
|
|
|
COMMENT "Generate HTML report for ${OV_COVERAGE_INFO_FILE}"
|
|
|
|
VERBATIM)
|
|
|
|
add_custom_target(ov_coverage_${OV_COVERAGE_INFO_FILE}_genhtml
|
|
|
|
DEPENDS "${output_directory}/index.html")
|
|
|
|
set_target_properties(ov_coverage_${OV_COVERAGE_INFO_FILE}_genhtml
|
|
|
|
PROPERTIES FOLDER coverage)
|
|
|
|
|
|
|
|
add_dependencies(ov_coverage_${OV_COVERAGE_INFO_FILE}_genhtml ov_coverage_${OV_COVERAGE_INFO_FILE}_info)
|
|
|
|
add_dependencies(ov_coverage ov_coverage_${OV_COVERAGE_INFO_FILE}_genhtml)
|
2020-04-13 13:17:23 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
2023-10-09 13:30:32 -05:00
|
|
|
# ov_coverage_remove(INPUT <info_file> OUTPUT <output_file> PATTERNS <patterns ...>)
|
2020-04-13 13:17:23 -05:00
|
|
|
#
|
2023-10-09 13:30:32 -05:00
|
|
|
function(ov_coverage_remove)
|
2022-09-19 02:04:10 -05:00
|
|
|
cmake_parse_arguments(OV_COVERAGE "" "INPUT;OUTPUT" "PATTERNS" ${ARGN})
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
set(input_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INPUT}.info")
|
|
|
|
set(output_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_OUTPUT}.info")
|
2020-04-13 13:17:23 -05:00
|
|
|
|
|
|
|
set(commands lcov --quiet)
|
2022-09-19 02:04:10 -05:00
|
|
|
foreach(pattern IN LISTS OV_COVERAGE_PATTERNS)
|
2020-04-13 13:17:23 -05:00
|
|
|
list(APPEND commands --remove ${input_file} ${pattern})
|
|
|
|
endforeach()
|
|
|
|
list(APPEND commands --output-file ${output_file})
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_file}
|
|
|
|
COMMAND ${commands}
|
2022-09-19 02:04:10 -05:00
|
|
|
COMMENT "Generate coverage data ${OV_COVERAGE_OUTPUT}"
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${input_file}
|
|
|
|
VERBATIM)
|
2022-09-19 02:04:10 -05:00
|
|
|
add_custom_target(ov_coverage_${OV_COVERAGE_OUTPUT}_info
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${output_file})
|
2022-09-19 02:04:10 -05:00
|
|
|
set_target_properties(ov_coverage_${OV_COVERAGE_OUTPUT}_info
|
2020-04-27 13:21:29 -05:00
|
|
|
PROPERTIES FOLDER coverage)
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
add_dependencies(ov_coverage_${OV_COVERAGE_OUTPUT}_info ov_coverage_${OV_COVERAGE_INPUT}_info)
|
2020-04-13 13:17:23 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
2023-10-09 13:30:32 -05:00
|
|
|
# ov_coverage_merge(OUTPUT <output file> INPUTS <input files ...>)
|
2020-04-13 13:17:23 -05:00
|
|
|
#
|
2023-10-09 13:30:32 -05:00
|
|
|
function(ov_coverage_merge)
|
2022-09-19 02:04:10 -05:00
|
|
|
cmake_parse_arguments(OV_COVERAGE "" "OUTPUT" "INPUTS" ${ARGN})
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
set(output_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_OUTPUT}.info")
|
|
|
|
foreach(input_info_file IN LISTS OV_COVERAGE_INPUTS)
|
|
|
|
set(input_file ${OV_COVERAGE_REPORTS}/${input_info_file}.info)
|
|
|
|
list(APPEND dependencies ov_coverage_${input_info_file}_info)
|
2020-04-13 13:17:23 -05:00
|
|
|
list(APPEND input_files ${input_file})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${output_file}
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
2022-09-19 02:04:10 -05:00
|
|
|
-D "OV_COVERAGE_OUTPUT_FILE=${output_file}"
|
|
|
|
-D "OV_COVERAGE_INPUT_FILES=${input_files}"
|
|
|
|
-P "${OV_COVERAGE_SCRIPT_DIR}/coverage_merge.cmake"
|
|
|
|
COMMENT "Generate coverage data ${OV_COVERAGE_OUTPUT}"
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${input_files}
|
|
|
|
VERBATIM)
|
2022-09-19 02:04:10 -05:00
|
|
|
add_custom_target(ov_coverage_${OV_COVERAGE_OUTPUT}_info
|
2020-04-13 13:17:23 -05:00
|
|
|
DEPENDS ${output_file})
|
2022-09-19 02:04:10 -05:00
|
|
|
set_target_properties(ov_coverage_${OV_COVERAGE_OUTPUT}_info
|
2020-04-27 13:21:29 -05:00
|
|
|
PROPERTIES FOLDER coverage)
|
2020-04-13 13:17:23 -05:00
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
add_dependencies(ov_coverage_${OV_COVERAGE_OUTPUT}_info ${dependencies})
|
2020-04-13 13:17:23 -05:00
|
|
|
endfunction()
|
|
|
|
|
2023-10-09 13:30:32 -05:00
|
|
|
# deprecated
|
|
|
|
|
2022-09-19 02:04:10 -05:00
|
|
|
if(NOT TARGET ie_coverage)
|
|
|
|
add_custom_target(ie_coverage)
|
|
|
|
set_target_properties(ie_coverage PROPERTIES FOLDER coverage)
|
|
|
|
add_dependencies(ie_coverage ov_coverage)
|
|
|
|
endif()
|