Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/common/cov_report.sh
Original file line number Diff line number Diff line change
@@ -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 <target_name> [source_file_filter]
# source_file_filter: 可选,按源文件名过滤(如 utils.cpp / settings.cpp / urlinfo.h)
Expand All @@ -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()
Expand Down
18 changes: 14 additions & 4 deletions tests/test-prj-running.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading