From b471bb97dfa173af12fbaa048adef98723583a09 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 1 Dec 2026 10:48:49 +0800 Subject: [PATCH 1/2] fix(test): add lcov 2.x version-gated --ignore-errors for coverage scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI 镜像 lcov 为 2.x,对 gcov 计数器与源码不一致(inconsistent/mismatch) 直接报错中断,任一阶段失败都会导致覆盖率无法产出(与 deepin-screen-recorder #553、deepin-terminal #531 同因)。按版本门控 (lcov >= 2 才加 --ignore-errors inconsistent,mismatch)注入全部 lcov/genhtml 调用,lcov 1.x 行为不变。 PMS: TASK-398635 Log: CI 单测覆盖率流水线 lcov 2.x 兼容 Influence: 不影响 lcov 1.x 本地行为 --- tests/local-test.sh | 22 ++++++++++++++++------ tests/qmake-lcov-test.sh | 18 ++++++++++++++---- tests/test-prj-running.sh | 20 +++++++++++++++----- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/tests/local-test.sh b/tests/local-test.sh index d72d4e91e..b6183c9c1 100644 --- a/tests/local-test.sh +++ b/tests/local-test.sh @@ -24,20 +24,30 @@ remove_info="*/tests/*" $build_dir/$executable --gtest_output=xml:$result_report_dir -lcov -d $build_dir -c -o $build_dir/coverage.info +# 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 --remove $build_dir/coverage.info $remove_info --output-file $build_dir/coverage.info +lcov $LCOV_IGN -d $build_dir -c -o $build_dir/coverage.info -lcov --extract $build_dir/coverage.info $extract_info --output-file $build_dir/coverage.info +lcov $LCOV_IGN --remove $build_dir/coverage.info $remove_info --output-file $build_dir/coverage.info -lcov --list-full-path -e $build_dir/coverage.info –o $build_dir/coverage-stripped.info +lcov $LCOV_IGN --extract $build_dir/coverage.info $extract_info --output-file $build_dir/coverage.info -genhtml -o $result_coverage_dir $build_dir/coverage.info +lcov $LCOV_IGN --list-full-path -e $build_dir/coverage.info -o $build_dir/coverage-stripped.info + +genhtml $LCOV_IGN -o $result_coverage_dir $build_dir/coverage.info nohup x-www-browser $result_coverage_dir/index.html & nohup x-www-browser $result_report_dir & -lcov -d $build_dir –z +lcov $LCOV_IGN -d $build_dir -z exit 0 diff --git a/tests/qmake-lcov-test.sh b/tests/qmake-lcov-test.sh index 1cd00cc8e..ec4b6bd16 100644 --- a/tests/qmake-lcov-test.sh +++ b/tests/qmake-lcov-test.sh @@ -16,12 +16,22 @@ result_report_dir=$build_dir/report/report.xml $build_dir/$executable --gtest_output=xml:$result_report_dir -lcov -d $build_dir -c -o $build_dir/coverage.info +# 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 --extract $build_dir/coverage.info '*/reader/*' -o $build_dir/coverage.info +lcov $LCOV_IGN -d $build_dir -c -o $build_dir/coverage.info -lcov --remove $build_dir/coverage.info '*/tests/*' -o $build_dir/coverage.info +lcov $LCOV_IGN --extract $build_dir/coverage.info '*/reader/*' -o $build_dir/coverage.info -genhtml -o $result_coverage_dir $build_dir/coverage.info +lcov $LCOV_IGN --remove $build_dir/coverage.info '*/tests/*' -o $build_dir/coverage.info + +genhtml $LCOV_IGN -o $result_coverage_dir $build_dir/coverage.info exit 0 diff --git a/tests/test-prj-running.sh b/tests/test-prj-running.sh index e3379c279..6e193d265 100755 --- a/tests/test-prj-running.sh +++ b/tests/test-prj-running.sh @@ -52,7 +52,17 @@ set -e workdir="${build_path}" # Reset any stale coverage counters before recapture -lcov --directory "${workdir}" --zerocounters || true +# 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 --directory "${workdir}" --zerocounters || true # Re-run tests so .gcda files reflect a clean run # If the first run segfaulted, .gcda files won't exist (atexit not called on SIGSEGV). @@ -88,17 +98,17 @@ fi test_exit_code=$((test_exit_code || retest_exit_code)) # Collect coverage data -lcov -d "${workdir}" -c -o ./coverage.info +lcov $LCOV_IGN -d "${workdir}" -c -o ./coverage.info # Keep only reader/htmltopdf sources, drop tests themselves -lcov --extract ./coverage.info '*/reader/*' '*/htmltopdf/*' -o ./coverage.info -lcov --remove ./coverage.info '*/tests/*' -o ./coverage.info +lcov $LCOV_IGN --extract ./coverage.info '*/reader/*' '*/htmltopdf/*' -o ./coverage.info +lcov $LCOV_IGN --remove ./coverage.info '*/tests/*' -o ./coverage.info # Exclude compiler-generated and unreachable functions (D0Ev, Q_OBJECT tr, env-dependent lambdas) python3 "${scriptdir}/exclude_unreachable.py" ./coverage.info ./coverage.info # Generate HTML report -genhtml -o ./html ./coverage.info +genhtml $LCOV_IGN -o ./html ./coverage.info # Rename main index for downstream tooling mv ./html/index.html ./html/cov_deepin-reader.html From 5e3f04ce5427f5dd49b4a4fc61cafaa8b365461c Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 1 Dec 2026 11:47:39 +0800 Subject: [PATCH 2/2] chore: update SPDX copyright/license headers for CI check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 单年份版权行更新为创建年-2026 区间(CI SPDX 检查要求) - 为缺失 SPDX header 的脚本补充版权与 license 声明 PMS: TASK-398635 Log: CI SPDX 检查修复 Influence: 仅注释变更,不影响脚本逻辑 --- tests/local-test.sh | 2 +- tests/qmake-lcov-test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/local-test.sh b/tests/local-test.sh index b6183c9c1..725998d2e 100644 --- a/tests/local-test.sh +++ b/tests/local-test.sh @@ -1,6 +1,6 @@ #!/bin/bash -# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +# SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd. # # SPDX-License-Identifier: GPL-3.0-or-later diff --git a/tests/qmake-lcov-test.sh b/tests/qmake-lcov-test.sh index ec4b6bd16..944c5751c 100644 --- a/tests/qmake-lcov-test.sh +++ b/tests/qmake-lcov-test.sh @@ -1,6 +1,6 @@ #!/bin/bash -# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +# SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd. # # SPDX-License-Identifier: GPL-3.0-or-later