From afd8cc425c8c78cc0702893c6ca475c730f9832c Mon Sep 17 00:00:00 2001 From: YUNSHEN XIE <1084314248@qq.com> Date: Wed, 22 Feb 2023 11:26:39 +0800 Subject: [PATCH] fix coverage combine bug (#50544) * fix coverage combine bug * update --- tools/coverage/paddle_coverage_new.sh | 49 ++++++++++++++------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/tools/coverage/paddle_coverage_new.sh b/tools/coverage/paddle_coverage_new.sh index 98de591fd15..a1bd228e133 100644 --- a/tools/coverage/paddle_coverage_new.sh +++ b/tools/coverage/paddle_coverage_new.sh @@ -29,12 +29,13 @@ function lcov_init(){ tar -xf /home/lcov-1.14.tar.gz -C / cd /lcov-1.14 make install + cd - } function gen_cpp_covinfo(){ # run paddle coverage cd /paddle/build - python3.7 ${PADDLE_ROOT}/tools/coverage/gcda_clean.py ${GIT_PR_ID} || exit 101 + python ${PADDLE_ROOT}/tools/coverage/gcda_clean.py ${GIT_PR_ID} || exit 101 lcov --capture -d ./ -o coverage.info --rc lcov_branch_coverage=0 } @@ -126,9 +127,9 @@ function gen_full_html_report_npu() { function gen_diff_html_report() { if [ "${GIT_PR_ID}" != "" ]; then - COVERAGE_DIFF_PATTERN="`python3.7 ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`" + COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`" - python3.7 ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > git-diff.out + python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > git-diff.out fi lcov --extract coverage-full.info \ @@ -136,7 +137,7 @@ function gen_diff_html_report() { -o coverage-diff.info \ --rc lcov_branch_coverage=0 - python3.7 ${PADDLE_ROOT}/tools/coverage/coverage_diff.py coverage-diff.info git-diff.out > coverage-diff.tmp + python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py coverage-diff.info git-diff.out > coverage-diff.tmp mv -f coverage-diff.tmp coverage-diff.info @@ -149,10 +150,10 @@ function gen_py_covinfo(){ # python coverage export COVERAGE_FILE=/paddle/build/python-coverage.data - coverage combine `$(ls python-coverage.data.*)` || NO_PYTHON_COVERAGE_DATA=1 - `$(coverage xml -i -o python-coverage.xml)` || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]] + coverage combine $(ls python-coverage.data.*) || NO_PYTHON_COVERAGE_DATA=1 + $(coverage xml -i -o python-coverage.xml) || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]] sed -i 's/mnt\/paddle/paddle/g' python-coverage.xml - `$(python ${PADDLE_ROOT}/tools/coverage/python_coverage.py > python-coverage.info)` || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]] + $(python ${PADDLE_ROOT}/tools/coverage/python_coverage.py > python-coverage.info) || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]] } @@ -180,9 +181,9 @@ function gen_python_full_html_report() { function gen_python_diff_html_report() { if [ "${GIT_PR_ID}" != "" ]; then - COVERAGE_DIFF_PATTERN="`python3.7 ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`" + COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`" - python3.7 ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > python-git-diff.out + python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > python-git-diff.out fi lcov --extract python-coverage-full.info \ @@ -190,7 +191,7 @@ function gen_python_diff_html_report() { -o python-coverage-diff.info \ --rc lcov_branch_coverage=0 - python3.7 ${PADDLE_ROOT}/tools/coverage/coverage_diff.py python-coverage-diff.info python-git-diff.out > python-coverage-diff.tmp + python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py python-coverage-diff.info python-git-diff.out > python-coverage-diff.tmp mv -f python-coverage-diff.tmp python-coverage-diff.info @@ -207,34 +208,36 @@ function gen_python_diff_html_report() { # assert coverage lines function covinfo_combine_full(){ - if [ -f "other-coverage.info" ];then - if [ -f "infer-coverage.info" ];then + if [ -f "other-coverage.info" ] && [ -s "other-coverage.info" ];then + if [ -f "infer-coverage.info" ] && [ -s "infer-coverage.info" ];then lcov -a other-coverage.info -a infer-coverage.info -o coverage.info else mv other-coverage.info coverage.info fi - elif [ -f "infer-coverage.info" ];then + elif [ -f "infer-coverage.info" ] && [ -s "infer-coverage.info" ];then mv infer-coverage.info coverage.info else echo "Cannot found coverage.info" fi - if [ -f "other-python-coverage-full.info" ];then - if [ -f "infer-python-coverage-full.info" ];then - lcov -a other-python-coverage-full.info -a infer-python-coverage-full.info -o python-coverage-full.info + if [ -f "other-python-coverage.info" ] && [ -s "other-python-coverage.info" ];then + if [ -f "infer-python-coverage.info" ] && [ -s "other-python-coverage.info" ];then + lcov -a other-python-coverage.info -a infer-python-coverage.info -o python-coverage.info else - mv other-python-coverage-full.info python-coverage-full.info + mv other-python-coverage.info python-coverage.info fi - elif [ -f "infer-coverage.info" ];then - mv infer-python-coverage-full.info python-coverage-full.info + elif [ -f "infer-python-coverage.info" ] && [ -s "infer-python-coverage.info" ];then + mv infer-python-coverage.info python-coverage.info else echo "Cannot found python coverage.info" fi + gen_python_full_html_report || true + gen_full_html_report || true } function cov_rate_judge(){ echo "Assert CPP Diff Coverage" - python3.7 ${PADDLE_ROOT}/tools/coverage/coverage_lines.py coverage-diff.info 0.9 || COVERAGE_LINES_ASSERT=1 + python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py coverage-diff.info 0.9 || COVERAGE_LINES_ASSERT=1 echo "Assert Python Diff Coverage" @@ -244,7 +247,7 @@ function cov_rate_judge(){ echo "NPU has no python coverage!" else if [[ python-coverage-diff.info ]];then - python3.7 ${PADDLE_ROOT}/tools/coverage/coverage_lines.py python-coverage-diff.info 0.9 || PYTHON_COVERAGE_LINES_ASSERT=1 + python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py python-coverage-diff.info 0.9 || PYTHON_COVERAGE_LINES_ASSERT=1 fi fi if [ "$COVERAGE_LINES_ASSERT" = "1" ] || [ "$PYTHON_COVERAGE_LINES_ASSERT" = "1" ]; then @@ -273,8 +276,8 @@ function main () { ;; combine_cov_info) covinfo_combine_full - gen_diff_html_report - gen_python_diff_html_report + gen_diff_html_report || true + gen_python_diff_html_report || true cov_rate_judge ;; *) -- GitLab