diff --git a/tests/local-test.sh b/tests/local-test.sh index d72d4e91..725998d2 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 @@ -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 1cd00cc8..944c5751 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 @@ -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 e3379c27..6e193d26 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