Skip to content

test(basekit): add threads, system and filesystem coverage tests - #769

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/basekit-coverage
Jul 15, 2026
Merged

test(basekit): add threads, system and filesystem coverage tests#769
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/basekit-coverage

Conversation

@pengfeixx

Copy link
Copy Markdown
Contributor

Add unit tests for FileLock, NamedCriticalSection, NamedSemaphore, Thread priority, sync primitives, UUID, StackTrace, console, DLL, pipe, process, symlink, path and file buffer operations.

新增basekit线程/系统/文件系统模块的单元测试,覆盖文件锁、
命名临界区、信号量、线程优先级、同步原语、UUID、堆栈跟踪、
控制台、动态库、管道、进程、符号链接和文件操作。

Log: 添加basekit基础设施覆盖率测试
Influence: 仅新增测试文件,不影响现有功能,提升basekit模块测试覆盖率。

Add unit tests for FileLock, NamedCriticalSection, NamedSemaphore,
Thread priority, sync primitives, UUID, StackTrace, console, DLL,
pipe, process, symlink, path and file buffer operations.

新增basekit线程/系统/文件系统模块的单元测试,覆盖文件锁、
命名临界区、信号量、线程优先级、同步原语、UUID、堆栈跟踪、
控制台、动态库、管道、进程、符号链接和文件操作。

Log: 添加basekit基础设施覆盖率测试
Influence: 仅新增测试文件,不影响现有功能,提升basekit模块测试覆盖率。

@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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了对UOS基础设施模块的全面单元测试覆盖,逻辑清晰且规避了被测代码的已知缺陷。
评分理由为代码整体质量良好,但因存在少量代码重复及未检查系统调用返回值扣5分。

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

symlink_test.cpp 中的 MakeTempFile 函数调用 write(fd, content.data(), content.size()) 后未检查返回值,可能导致数据写入不完整。测试代码整体逻辑正确,能够正确处理被测代码中的已知缺陷,如 sync_extra_test.cpp 中对 TryWaitFor 缺陷的规避。
潜在问题:write 调用失败时未进行错误处理
建议:检查 write 返回值,失败时抛出异常或进行重试

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

FreshPath 函数在 file_buffer_test.cppfile_readall_test.cpp 等多个测试文件中重复定义。dll_extra_test.cpp 中硬编码了 /usr/lib/x86_64-linux-gnu/libz.so 路径,降低了代码的可移植性。测试注释详尽,特别是对被测代码缺陷的说明非常清晰。
潜在问题:辅助函数重复定义;硬编码库路径可能在不同架构上失效
建议:将公共辅助函数提取到独立的测试头文件中;使用动态查找或环境变量获取库路径

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

测试代码中使用了 std::this_thread::sleep_for 进行线程同步,这在单元测试中是常见做法,不会对系统性能产生负面影响。临时文件和资源的清理及时,无资源泄漏。
建议:保持现有资源管理策略

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
测试代码使用 mkstemp 安全地创建临时文件,Process::Execute 使用参数数组避免了命令注入。未发现安全漏洞。
建议:保持现有安全编码规范

■ 【改进建议代码示例】

std::string MakeTempFile(const std::string& content = "data")
{
    char t[] = "/tmp/bk_symf_XXXXXX";
    int fd = mkstemp(t);
    if (fd < 0) throw std::runtime_error("mkstemp");
    
    ssize_t written = write(fd, content.data(), content.size());
    close(fd);
    
    if (written < 0 || static_cast<size_t>(written) != content.size()) {
        std::remove(t);
        throw std::runtime_error("write failed");
    }
    return t;
}

@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

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 9548b7d into linuxdeepin:master Jul 15, 2026
17 of 19 checks passed
@pengfeixx
pengfeixx deleted the test/basekit-coverage branch July 15, 2026 01:20
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