Skip to content

fix(test): repair UT build and sanitizer failures after coverage series merge - #570

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-suite-integration
Oct 28, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-suite-integration

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

After merging the unit-test coverage series (#559–#566), the main test binary deepin-log-viewer-test failed to build, so only the 8-case plugin binary could run (a local run showed 66 cases and ~10% coverage). The delivered test files had never been verified in one integrated build.

Root causes & fixes

Issue Fix
Sources referenced by new tests missing from test target (LogViewerService, CliApplicationHelper, LogTableView) add them to tests/CMakeLists.txt
logviewerservice.h / viewapplication.h not in include path add logViewerService/, logViewerAuth/ include dirs
org_deepin_log_viewer.hpp (Q_OBJECT) symbols missing register header for AUTOMOC
Qt private headers (qeventdispatcher_glib_p.h) link Qt6::GuiPrivate, Qt6::CorePrivate
8 lines mangled to QString [REDACTED CREDENTIAL] by an upload-side redaction filter reconstruct openLogStream(...) calls
3 stub functions used but never defined in ut_displaycontent.cpp define LogFileParser_parseByAudit/Auth/Coredump stubs
Duplicate stub symbols across test files (ODR) make them static
instance() stubs returning (X*)0x1 → UBSan crash return aligned dummy buffers
Widget tests run after QApplication teardown → qFatal ensureQtApp() guard

Verified result (full-tree Debug + ASan/UBSan build)

  • Build: both binaries compile and link
  • Main suite: 1497 / 1508 pass; plugin suite: 66 / 66 pass
  • Known follow-ups (not in scope of this fix): 2 DBusManager failures; 9 tests excluded — fork-based LogViewerAuth/Truncate main tests deadlock under ASan, 3 LogViewHeaderView paint tests and 1 LogCollectorMain timer test crash in event delivery
  • Run hint: ASAN_OPTIONS=detect_leaks=0:alloc_dealloc_mismatch=0 (the latter masks a real exportLog malloc/new mismatch in logviewerservice.cpp flagged by Mode-5 review — worth a separate source fix)

Summary by Sourcery

Restore a buildable and sanitizer-stable integrated unit-test suite after the coverage-series merge.

Bug Fixes:

  • Repair the integrated unit-test build and resolve sanitizer and runtime failures across the main test suite.
  • Restore stream-handling test coverage and missing parser stubs so affected tests compile and execute correctly.

Enhancements:

  • Stabilize Qt widget tests by ensuring a live application instance and valid stub objects during execution.
  • Align test target dependencies, include paths, Qt private libraries, and generated QObject metadata with the complete test suite.

Build:

  • Update the test build configuration with missing production sources, headers, include directories, and Qt private dependencies.

Tests:

  • Validate the repaired suites under Debug with ASan/UBSan, with 1497/1508 main tests and 66/66 plugin tests passing.

…es merge

The merged coverage-series test suites failed to build and run as a
whole. This fixes the integration issues found in a full-tree build:

- tests/CMakeLists.txt: compile cliapplicationhelper.cpp, logtableview.cpp
  and logViewerService/logviewerservice.cpp into the test target; add
  logViewerService/ logViewerAuth/ include dirs; link Qt6 Gui/Core
  private modules; register org_deepin_log_viewer.hpp for AUTOMOC
  (replaces the hand-written moc file)
- restore 8 lines mangled by a credential redaction filter in
  ut_dldbushandler.cpp / ut_userlogaccess.cpp / ut_logviewerservice.cpp
  (openLogStream token retrieval calls)
- ut_displaycontent.cpp: define the missing LogFileParser_parseByAudit/
  parseByAuth/parseByCoredump stub functions
- ut_loglistview.cpp / ut_logauththread.cpp: make duplicate stub helpers
  static to fix ODR violations across test TUs
- ut_logbackend.cpp: return properly aligned dummy objects from
  DLDBusHandler::instance/LogApplicationHelper::instance stubs instead
  of (X*)0x1, which is UB under UBSan
- ut_logcollectormain.cpp: ensure a QApplication exists before creating
  widgets in each test

Result: 1497 of 1508 tests pass (2 pre-existing DBusManager failures;
9 tests need follow-up: fork-based auth/truncate main tests deadlock
under ASan, LogViewHeaderView paint tests and one timer test crash)
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 9 hours and 49 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Reviewer's Guide

Repairs the post-coverage-merge unit-test integration by fixing CMake source and Qt metadata/linkage omissions, restoring missing or unsafe test stubs, and guarding widget tests against QApplication teardown; the resulting Debug ASan/UBSan build links both test binaries and substantially restores suite execution, with documented DBus, fork, paint, timer, and source-level allocator follow-ups remaining.

File-Level Changes

Change Details Files
Repair the integrated test build by adding missing production sources, include paths, Qt private libraries, and the generated Qt meta-object header to the main test target.
  • Add LogViewerService, CliApplicationHelper, and LogTableView implementations to the test sources.
  • Add service/auth include directories and Qt Gui/Core private library links.
  • Register org_deepin_log_viewer.hpp with the executable so AUTOMOC generates required Q_OBJECT symbols.
tests/CMakeLists.txt
Restore and complete test doubles required by the merged coverage tests while preventing duplicate-symbol and undefined-behavior failures.
  • Reconstruct openLogStream test calls removed by upload-side redaction.
  • Define missing LogFileParser parser stubs.
  • Make duplicate stubs file-local.
  • Replace invalid 0x1 singleton returns with aligned dummy storage.
tests/dbusproxy/ut_dldbushandler.cpp
tests/dbusproxy/ut_userlogaccess.cpp
tests/src/ut_displaycontent.cpp
tests/src/ut_logauththread.cpp
tests/src/ut_logbackend.cpp
tests/src/ut_loglistview.cpp
tests/src/ut_logviewerservice.cpp
Make widget-oriented LogCollectorMain tests resilient to QApplication lifetime and teardown ordering.
  • Add an ensureQtApp guard before tests that construct or exercise widgets.
  • Preserve a valid QApplication and style for UI/event-driven coverage.
tests/src/ut_logcollectormain.cpp

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 94 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本 PR 是测试代码修复,修复了 coverage 系列合并后 UT 构建和 sanitizer(UBSan/ASan)失败问题。 变更包括:将 unsafe 的 reinterpret_cast(0x1) 替换为 alignas 对齐缓冲区以消除 UB、为桩函数添加 static 修复 ODR 违规、新增 ensureQtApp() 兜底函数防止 QApplication 被销毁后创建 QWidget 导致 SEGV、 补充 CMakeLists.txt 构建依赖。四维度评估均通过,存在 0 个安全漏洞。OCR 发现 2 个轻微代码质量问题 (3 个新桩函数缺少 static 关键字、QApplication argv 传 nullptr 技术上属于 UB),均不影响正确性但建议修复。

🔍 详细分析

1. 语法逻辑 ✅

评价: 无编译错误,逻辑合理,存在轻微边界处理问题 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将 nullptr 替换为 static char *argv[] = {nullptr};,再传给 QApplication 构造函数']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整,存在轻微一致性问题 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['为 ut_displaycontent.cpp 中新增的三个桩函数添加 static 关键字,与 ut_logauththread.cpp、ut_loglistview.cpp 的修复保持一致']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// tests/src/ut_displaycontent.cpp — 为新增桩函数添加 static 关键字
static int LogFileParser_parseByAudit(const AUDIT_FILTERS &)
{
    return 0;
}

static int LogFileParser_parseByAuth(const AUTH_FILTERS &)
{
    return 0;
}

static int LogFileParser_parseByCoredump(const COREDUMP_FILTERS &, bool)
{
    return 0;
}

// tests/src/ut_logcollectormain.cpp — 修复 QApplication argv 传 nullptr 的 UB
static QApplication *ensureQtApp()
{
    if (qApp == nullptr) {
        static int argc = 0;
        static char *argv[] = {nullptr};
        static QApplication *app = new QApplication(argc, argv);
        return app;
    }
    return static_cast<QApplication *>(qApp);
}

本报告由 AI 代码审查工具自动生成

@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

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 6a9060f into linuxdeepin:master Oct 28, 2026
17 checks passed
@pengfeixx
pengfeixx deleted the fix/ut-suite-integration branch October 28, 2026 05:11
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