Skip to content

test: improve unit test coverage to 70% and fix eventlogutils bug#692

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/ut-coverage-70
Jun 22, 2026
Merged

test: improve unit test coverage to 70% and fix eventlogutils bug#692
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/ut-coverage-70

Conversation

@pengfeixx

Copy link
Copy Markdown
Contributor

Add unit tests across low-coverage modules to raise line coverage above 70%.

为多个低覆盖模块新增单元测试,将前端行覆盖率提升至70%以上。

Fix missing-braces bug in eventlogutils::writeLogs that caused early return.

修复eventlogutils的writeLogs缺大括号导致提前返回、日志永不写入的bug。

Log: 提升单元测试覆盖率至70%
Influence: 前端行覆盖率由62.0%提升至70.3%,全部970个测试通过,零失败;顺带修复eventlogutils日志写入bug。

@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.

Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Add unit tests across low-coverage modules to raise line coverage above 70%.

为多个低覆盖模块新增单元测试,将前端行覆盖率提升至70%以上。

Fix missing-braces bug in eventlogutils::writeLogs that caused early return.

修复eventlogutils的writeLogs缺大括号导致提前返回、日志永不写入的bug。

Log: 提升单元测试覆盖率至70%
Influence: 前端行覆盖率由62.0%提升至70.3%,全部970个测试通过,零失败;顺带修复eventlogutils日志写入bug。
@pengfeixx pengfeixx force-pushed the test/ut-coverage-70 branch from 8ae31ee to 9324d0f Compare June 22, 2026 08:14
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了空指针保护分支缺少大括号的隐患并补充了全面的单元测试,质量优秀
逻辑正确且无安全漏洞,符合满分标准

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

eventlogutils.cpp 第47-50行,为 if (writeEventLog == nullptr) 分支补充了大括号,消除了后续维护时因缺少大括号导致的悬空 else 或逻辑绑定错误隐患;同时清理了无用的注释代码
建议:继续保持对单行 if/else 语句强制添加大括号的代码规范

  • 2.代码质量(良好)✓

核心代码修改精简准确;新增的单元测试覆盖了设备解析、导出、工厂模式等核心链路,使用 stub 隔离了文件读写、DBus 调用和命令执行等外部依赖,测试目的注释清晰
建议:部分测试用例仅使用 EXPECT_NO_FATAL_FAILURE 而未对返回值或状态变更进行严格断言,后续可考虑补充更精确的 EXPECT_EQ/EXPECT_TRUE 断言以提升测试有效性

  • 3.代码性能(无性能问题)✓

核心逻辑仅为增加括号,无性能影响;测试代码仅在编译和执行阶段运行,不影响生产环境性能
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
核心代码修改未引入任何安全风险;测试代码中使用的 #define private public 及全局静态变量桩均被限制在测试编译环境中,不会泄露至生产构建

  • 建议:确保测试文件的编译选项与生产环境严格隔离,防止封装破坏宏被意外引入非测试代码

■ 【改进建议代码示例】

// eventlogutils.cpp 已修复完成,无需进一步改动
// 以下为符合规范的测试代码片段示例,展示如何避免全局静态变量污染
class UT_DeviceFactorySafe : public UT_HEAD
{
public:
    void SetUp() override
    {
        // 在每个用例中局部设置桩,避免全局状态污染
        m_stub.set(ADDR(Common, getArch), []() { return "x86_64"; });
    }
    void TearDown() override
    {
        m_stub.reset();
    }
private:
    Stub m_stub;
};

TEST_F(UT_DeviceFactorySafe, getDeviceGenerator_x86_64)
{
    DeviceGenerator *g = DeviceFactory::getDeviceGenerator();
    EXPECT_NE(dynamic_cast<X86Generator *>(g), nullptr);
    delete g;
}

@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 2d24d45 into linuxdeepin:master Jun 22, 2026
22 checks passed
@pengfeixx pengfeixx deleted the test/ut-coverage-70 branch June 22, 2026 08:28
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