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 14add_custom_target(bytecode_optimizer_coverage DEPENDS bytecodeopt_unit_tests) 15 16add_custom_command(TARGET bytecode_optimizer_coverage POST_BUILD 17 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 18 COMMAND bash ${PANDA_ROOT}/bytecode_optimizer/tools/optimizer_coverage.sh --binary-dir=${PANDA_BINARY_ROOT} --root-dir=${PANDA_ROOT} 19) 20 21option(ENABLE_BYTECODE_OPTIMIZER_COVERAGE "Enable coverage calculation for the bytecode optimizer" false) 22 23find_program( 24 LCOV 25 NAMES "lcov" 26 DOC "Path to lcov executable") 27if(NOT LCOV) 28 set(ENABLE_BYTECODE_OPTIMIZER_COVERAGE false) 29endif() 30 31find_program( 32 GENHTML 33 NAMES "genhtml" 34 DOC "Path to genhtml executable") 35if(NOT GENHTML) 36 set(ENABLE_BYTECODE_OPTIMIZER_COVERAGE false) 37endif() 38 39if(ENABLE_BYTECODE_OPTIMIZER_COVERAGE) 40 # Set coverage options 41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") 42 add_custom_target(bo_coverage DEPENDS bytecodeopt_unit_tests) # Execute tests 43 set(ADD_COV_FLAGS --quiet --rc lcov_branch_coverage=1) 44 add_custom_command(TARGET bo_coverage POST_BUILD 45 WORKING_DIRECTORY ${PANDA_BINARY_ROOT} 46 # Update current coverage info 47 COMMAND lcov --no-external -b ${PANDA_ROOT}/bytecode_optimizer -d ${CMAKE_CURRENT_BINARY_DIR} -c -o bo_coverage.info ${ADD_COV_FLAGS} 48 # Generating an html report 49 COMMAND genhtml -o bo_coverage_report bo_coverage.info --ignore-errors source ${ADD_COV_FLAGS} 50 COMMAND echo "Coverage report: ${PANDA_BINARY_ROOT}/bo_coverage_report" 51 # Delete temporary files to collect statistics 52 COMMAND rm bo_coverage.info 53 COMMAND find ${PANDA_BINARY_ROOT}/* -iname "*.gcda" -delete 54 ) 55else() 56 message(STATUS "Coverage will not be calculated (may be enabled by -DENABLE_BYTECODE_OPTIMIZER_COVERAGE=true ).") 57endif(ENABLE_BYTECODE_OPTIMIZER_COVERAGE) 58