1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14option(ENABLE_COMPILER_COVERAGE "Enable coverage-calculation for compiler" false) 15 16find_program( 17 LCOV 18 NAMES "lcov" 19 DOC "Path to lcov executable") 20if(NOT LCOV) 21 set(ENABLE_COMPILER_COVERAGE false) 22endif() 23 24find_program( 25 GENHTML 26 NAMES "genhtml" 27 DOC "Path to genhtml executable") 28if(NOT GENHTML) 29 set(ENABLE_COMPILER_COVERAGE false) 30endif() 31 32if(ENABLE_COMPILER_COVERAGE) 33 # Set coverage options 34 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") 35 add_custom_target(coverage DEPENDS cts-assembly tests benchmarks) # Execute tests 36 set(ADD_COV_FLAGS --quiet --rc lcov_branch_coverage=1) 37 add_custom_command(TARGET coverage POST_BUILD 38 WORKING_DIRECTORY ${PANDA_BINARY_ROOT} 39 # Update current coverage info 40 COMMAND lcov --no-external -b ${PANDA_ROOT}/compiler -d ${CMAKE_CURRENT_BINARY_DIR} -c -o compiler_coverage.info ${ADD_COV_FLAGS} 41 # Generating an html report 42 COMMAND genhtml -o compiler_coverage_report compiler_coverage.info --ignore-errors source ${ADD_COV_FLAGS} 43 COMMAND echo "Coverage report: ${PANDA_BINARY_ROOT}/compiler_coverage_report" 44 # Delete temporary files to collect statistics 45 COMMAND rm compiler_coverage.info 46 COMMAND find ${PANDA_BINARY_ROOT}/* -iname "*.gcda" -delete 47 ) 48else() 49 message(STATUS "Coverage will not be calculated (may be enabled by -DENABLE_COMPILER_COVERAGE=true ).") 50endif(ENABLE_COMPILER_COVERAGE) 51