Skip to content

fix: 关闭泄漏检测避免UT被误判失败 - #551

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-disable-leaksan
Oct 24, 2026
Merged

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-disable-leaksan

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

问题现象

UT 集群上执行 tests/test-prj-running.sh,690 个测试用例(682 + 8)全部 PASSED、覆盖率报告也正常生成,但任务最终以 exit_code=1 被判失败,日志中找不到任何 [ FAILED ] 或 AddressSanitizer 报错。

原因分析

  • UT 编译开启了 -fsanitize=undefined,address(CMAKE_SAFETYTEST_ARG_ON),进程退出时 LeakSanitizer 检测到内存泄漏后以退出码 1 结束进程;
  • 泄漏主要来自 Qt 框架自身一次性初始化(QColormap::initialize、QApplicationPrivate::initialize 等)以及第三方库 libxlsxwriter/DocxFactory,属于无法避免的框架级"良性"泄漏;
  • tests/src/ut_main.cpp 中 __sanitizer_set_report_path("asan.log") 会把 sanitizer 报告重定向到 asan.log.<pid> 文件,导致控制台日志完全看不到泄漏报告,表现为"全部通过却失败";
  • 脚本最后 exit $test_exit_code(两个测试进程退出码取或),整体任务被判失败。

已在本地完整复现:两个测试进程均为"全部 PASSED + 退出码 1",asan.log.* 中内容为 LeakSanitizer: detected memory leaks(170892 字节 / 1483 处,绝大部分来自 Qt 与第三方库)。

修改内容

在 tests/test-prj-running.sh 运行测试前导出 ASAN_OPTIONS=detect_leaks=0,关闭退出时的泄漏检测,使进程退出码真实反映 gtest 结果。已验证:关闭后两个测试进程退出码均为 0,用例全部通过。

自测说明

  • 本地以相同参数(CMAKE_SAFETYTEST_ARG_ON)构建并运行 deepin-log-viewer-test(682 个)与 deepin-log-viewer-plugin-test(8 个),全部通过,退出码 0
  • bash -n 语法检查通过

Summary by Sourcery

Bug Fixes:

  • Disable AddressSanitizer leak detection during unit-test execution so framework-level leaks do not produce a false failure exit code when all tests pass.

1. Qt/QApplication one-shot allocations are never freed at exit
2. LeakSanitizer then kills the test process with exit code 1 even
   though all gtest cases passed
3. The ASan report is redirected to asan.log.* by
   __sanitizer_set_report_path, so nothing shows in the UT console
4. Export ASAN_OPTIONS=detect_leaks=0 in test-prj-running.sh so the
   exit code reflects real test results

Log: No user-facing changes

Influence:
1. Run tests/test-prj-running.sh on the UT cluster and check the job
   exits with code 0 while all cases pass
2. Run deepin-log-viewer-test and deepin-log-viewer-plugin-test
   manually and verify the PASSED counts match ut-summary.json
3. Confirm no asan.log.* files are generated and the coverage report
   is still produced normally

fix: 关闭泄漏检测避免UT被误判失败

1. Qt/QApplication退出时的一次性分配不会被释放
2. LeakSanitizer会以退出码1结束测试进程,即使全部用例已通过
3. ASan报告被__sanitizer_set_report_path重定向到asan.log.*,
   控制台日志中完全不可见
4. 在test-prj-running.sh中导出ASAN_OPTIONS=detect_leaks=0,
   使退出码真实反映测试结果

Log: 无用户可见变化

Influence:
1. 在UT集群执行tests/test-prj-running.sh,确认任务退出码为0
   且全部用例通过
2. 手动执行deepin-log-viewer-test与deepin-log-viewer-plugin-test,
   核对PASSED数量与ut-summary.json一致
3. 确认不再生成asan.log.*文件,且覆盖率报告仍正常产出
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "tests/test-prj-running.sh": {
            "b": [
                "export ASAN_OPTIONS=detect_leaks=0"
            ]
        }
    }
}

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The test runner now disables LeakSanitizer leak detection before running the two unit-test binaries, ensuring the final exit code reflects gtest failures rather than unavoidable Qt/third-party framework leaks hidden in redirected sanitizer logs.

File-Level Changes

Change Details Files
Disable LeakSanitizer leak detection during unit-test execution so sanitizer-detected framework leaks do not override the test result.
  • Export ASAN_OPTIONS=detect_leaks=0 after building and before launching the test processes.
  • Document that Qt and third-party one-time allocations, combined with redirected sanitizer reports, caused passing tests to exit with code 1.
tests/test-prj-running.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx
pengfeixx merged commit 48c53e0 into linuxdeepin:master Oct 24, 2026
15 of 17 checks passed
@pengfeixx
pengfeixx deleted the fix/ut-disable-leaksan branch October 24, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants