diff --git a/tests/common/cov_report.sh b/tests/common/cov_report.sh index 393bf0dd..826edd56 100755 --- a/tests/common/cov_report.sh +++ b/tests/common/cov_report.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash +# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: GPL-3.0-or-later # B2 批次 lcov 函数覆盖率统计(按测试目标隔离对象目录) # 用法: cov_report.sh [source_file_filter] # source_file_filter: 可选,按源文件名过滤(如 utils.cpp / settings.cpp / urlinfo.h) @@ -7,8 +10,18 @@ TARGET="$1" FILTER="${2:-}" BD=/home/uos/work/ut/deepin-editor/build OBJDIR="$BD/tests/common/CMakeFiles/${TARGET}.dir" -lcov --capture --directory "$OBJDIR" -o "/tmp/b2_${TARGET}.info" -q 2>/dev/null -lcov --extract "/tmp/b2_${TARGET}.info" '*/src/common/*' -o "/tmp/b2_${TARGET}_f.info" -q 2>/dev/null +# CI 镜像 lcov 为 2.x:对 gcov 计数器与源码不一致(inconsistent/mismatch) +# 直接报错中断,任一阶段失败都会导致覆盖率无法产出。 +# 因此每一步 lcov/genhtml 都需要带上 --ignore-errors +# (lcov 1.x 不支持 --ignore-errors,保持原行为)。 +LCOV_MAJOR=$(lcov --version 2>/dev/null | grep -oE '[0-9]+(\.[0-9]+)+' | head -1 | cut -d. -f1) +LCOV_IGN="" +if [ "${LCOV_MAJOR:-0}" -ge 2 ]; then + LCOV_IGN="--ignore-errors inconsistent,mismatch" +fi + +lcov $LCOV_IGN --capture --directory "$OBJDIR" -o "/tmp/b2_${TARGET}.info" -q 2>/dev/null +lcov $LCOV_IGN --extract "/tmp/b2_${TARGET}.info" '*/src/common/*' -o "/tmp/b2_${TARGET}_f.info" -q 2>/dev/null python3 - "/tmp/b2_${TARGET}_f.info" "$FILTER" <<'PYEOF' import re, sys info = open(sys.argv[1]).read() diff --git a/tests/test-prj-running.sh b/tests/test-prj-running.sh index e0386724..fc4b11a4 100755 --- a/tests/test-prj-running.sh +++ b/tests/test-prj-running.sh @@ -76,13 +76,23 @@ workdir=$(pwd) mkdir -p report #统计代码覆盖率并生成html报告 -lcov -d $workdir -c -o ./coverage.info || echo "WARNING: lcov capture failed" +# CI 镜像 lcov 为 2.x:对 gcov 计数器与源码不一致(inconsistent/mismatch) +# 直接报错中断,任一阶段失败都会导致覆盖率无法产出。 +# 因此每一步 lcov/genhtml 都需要带上 --ignore-errors +# (lcov 1.x 不支持 --ignore-errors,保持原行为)。 +LCOV_MAJOR=$(lcov --version 2>/dev/null | grep -oE '[0-9]+(\.[0-9]+)+' | head -1 | cut -d. -f1) +LCOV_IGN="" +if [ "${LCOV_MAJOR:-0}" -ge 2 ]; then + LCOV_IGN="--ignore-errors inconsistent,mismatch" +fi + +lcov $LCOV_IGN -d $workdir -c -o ./coverage.info || echo "WARNING: lcov capture failed" -lcov --extract ./coverage.info '*/src/*' -o ./coverage.info || true +lcov $LCOV_IGN --extract ./coverage.info '*/src/*' -o ./coverage.info || true -lcov --remove ./coverage.info '*/tests/*' -o ./coverage.info || true +lcov $LCOV_IGN --remove ./coverage.info '*/tests/*' -o ./coverage.info || true -genhtml -o ./html ./coverage.info || true +genhtml $LCOV_IGN -o ./html ./coverage.info || true [ -f ./html/index.html ] && mv ./html/index.html ./html/cov_deepin-editor.html #对asan、ut、代码覆盖率结果收集至指定文件夹 cp -r html ../$reportdir/ 2>/dev/null || true