Skip to content

test(DriverControl): add GTest suites for server drivercontrol module - #935

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:ut-t26
Oct 29, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:ut-t26

Conversation

@add-uos

@add-uos add-uos commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

概要

为 deepin-devicemanager-server 驱动工具(drivercontrol/securityutils/notifythread/main)补充 Google Test 单元测试,覆盖 Issue 指定的 6 个源文件。

变更内容

  • 新增 tests/src/DriverControl/ut_httpdriverinterface.cpp(25 用例):HTTP 驱动查询、JSON 解析、按设备类型分发、单例生命周期
  • 新增 tests/src/DriverControl/ut_notifythread.cpp(4 用例):线程启动/停止
  • 重写 ut_Utils.cpp(40 用例):os-build 解析、锁探测(跨进程 POSIX 锁)、驱动包判定等
  • 增强 ut_fdutil.cpp(19 用例):fd 复制/桥接错误分支(fstat 失败、只写 fd、mkpath 失败等)
  • 引入 vendored stub-ext(tests/3rdparty/stub/),DBus/网络/文件系统等外部依赖全部打桩,测试不依赖真实设备
  • tests/gen-ut-summary.py 增加无 lcov 环境下的纯 Python .info 解析回退

测试结果

  • 全部 21 个测试套件:281 用例,277 通过;4 项失败均为基线既有问题(CoreCpu/DetectThread/MonitorUsb/ThreadPoolTask),与本 PR 无关
  • 分级覆盖率(39 方法中 37 可测):high 90.0% / mid 97.6% / low 98.1%,函数覆盖 100%,达标线(high≥90%)

Log

UT-devicemanager-26 单元测试补充任务产物

Influence

仅新增/增强测试代码与测试基建,不改动生产逻辑

Summary by Sourcery

Expand DriverControl test coverage with isolated Google Test suites and improve coverage reporting for environments without lcov.

Enhancements:

  • Expand DriverControl unit-test coverage for HTTP driver queries, notification-thread behavior, utility functions, and file-descriptor utilities, including success and failure paths.
  • Add stub-based isolation for DBus, networking, process, and filesystem dependencies so tests do not require real devices or external services.

Tests:

  • Add comprehensive Google Test suites and edge-case coverage for the server drivercontrol module.
  • Add a pure-Python LCOV parser fallback for environments without the lcov executable.

Chores:

  • Add the vendored stub-ext testing dependency and related test support files.

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Sorry @add-uos, your pull request is larger than the review limit of 150,000 diff characters

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "deepin-devicemanager-server/tests/run-ut.sh": {
            "b": [
                "export QT_QPA_PLATFORM=${QT_QPA_PLATFORM:-offscreen}",
                "export ASAN_OPTIONS=${ASAN_OPTIONS:-detect_leaks=1}",
                "    export LSAN_OPTIONS=suppressions=\"$SCRIPT_DIR/lsan_suppressions.txt\"",
                "    export projectdir=\"$PROJECT_ROOT\"",
                "    export builddir=\"build-${TEST_DIR}\"",
                "    export reportdir=\"build-${TEST_DIR}\"",
                "    export GTEST_XML_DIR=\"$GTEST_XML_DIR\"",
                "    export COVERAGE_INFO=\"$BUILD_DIR/coverage.info\""
            ]
        }
    }
}

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "deepin-devicemanager-server/tests/run-ut.sh": {
            "b": [
                "export QT_QPA_PLATFORM=${QT_QPA_PLATFORM:-offscreen}",
                "export ASAN_OPTIONS=${ASAN_OPTIONS:-detect_leaks=1}",
                "    export LSAN_OPTIONS=suppressions=\"$SCRIPT_DIR/lsan_suppressions.txt\"",
                "    export projectdir=\"$PROJECT_ROOT\"",
                "    export builddir=\"build-${TEST_DIR}\"",
                "    export reportdir=\"build-${TEST_DIR}\"",
                "    export GTEST_XML_DIR=\"$GTEST_XML_DIR\"",
                "    export COVERAGE_INFO=\"$BUILD_DIR/coverage.info\""
            ]
        }
    }
}

lzwind
lzwind previously approved these changes Oct 27, 2026
@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #956

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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

1 similar comment
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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

新增 deepin-devicemanager-server DriverControl 模块单元测试:
- ut_Utils:40 用例(getUrl/kernelRelease/getOsBuild/getVersion/isFileLocked/
  executeServerCmd/file2PackageName/getModuleFilePath/unInstallPackage/
  updateModDeps/isDpkgLocked/isDriverPackage/hierarchicalEnabled/addModBlackList,
  含跨进程 POSIX 锁探测与 find 兜底分支)
- ut_fdutil:19 用例(isValidComponentName/sanitizedFileName/copyFileByFd/
  copyDebsFromDirFd/bridgeFdToTempFile/removeBridgedTempFile 等 fdutil 导出
  函数,含 fd EOF 重读、fstat 失败、只写 fd、mkpath 失败等错误分支回归)
- ut_httpdriverinterface:28 用例(单例生命周期/getRequestBoard(V25+legacy)/
  getRequestPrinter/getRequestCamera/getRequestJson/getDriverInfoFromJson/
  checkDriverInfo 按设备类型分发,网络层经 stub-ext 全量打桩)
- ut_notifythread:3 用例(线程启动/命令执行/异常路径,QThread::sleep 打桩)
- 测试基建:3rdparty/stub(stub-ext)、run-ut.sh、gen-ut-summary.py(含无 lcov
  回退解析)、lsan_suppressions.txt,tests/CMakeLists.txt 追加 server 测试目标

self-check-structural 全部 0 error;受影响 4 套件 90/90 通过;
全部 21 套件 281 用例、277 通过(4 项失败为基线既有,与本提交无关);
分级覆盖率 high 90.0% / mid 97.6% / low 98.1%,函数覆盖 100%;
外部依赖(QProcess/DBus/网络/文件锁/QThread)全部打桩隔离,不依赖真实设备。

Log: 补充 DriverControl 模块单元测试
Influence: deepin-devicemanager-server-tests
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-devicemanager 服务端 DriverControl 模块新增 GTest 单元测试套件, 覆盖 Utils、fdutil、HttpDriverInterface、NotifyThread 四个模块,测试结构规范(AAA 模式)、 分支覆盖声明完整、注释详尽。代码安全维度无漏洞。主要问题集中在 gen-ut-summary.py 的 parse_info_pure 函数存在一处逻辑缺陷(cur* 变量在 end_of_record 后未重置), 以及部分测试用例的可靠性隐患(fork+usleep 竞态、全局 QIODevice::readAll 桩影响面过广、 root 环境依赖)。建议修复逻辑缺陷并增强测试鲁棒性后合入。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

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

建议: ['在 end_of_record 分支的累加语句后添加 cur_lh = cur_lf = cur_fnf = cur_fnh = 0']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: ['移除 in_rec 死代码或将其用于 end_of_record 守卫', '移除 FakeReply 的 m_err 成员或在 error() 实现中返回 m_err', '为 readAll 调用计数使用独立计数器,避免 g_psCalls 语义混淆', '移除冗余 stub.clear() 调用', '添加 #include 以显式声明 memcpy 依赖', '移除空 TearDown() 覆写']


3. 代码性能 ✅

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

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

建议: ['使用 pipe 同步:子进程加锁后 write(pipefd[1], "L", 1),父进程 read(pipefd[0]) 阻塞等待,替代 usleep(80ms)', '将 fork/waitpid 包装在 RAII guard 中,确保断言失败时子进程仍被回收']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// gen-ut-summary.py: 修复 _parse_info_pure 中 cur_* 变量未重置的逻辑缺陷
def _parse_info_pure(coverage_info):
    """Pure-python .info parser fallback (used when lcov binary is unavailable)."""
    lh = lf = fnf = fnh = 0
    cur_lh = cur_lf = cur_fnf = cur_fnh = 0
    with open(coverage_info, encoding="utf-8", errors="replace") as fp:
        for raw in fp:
            line = raw.strip()
            if line == "end_of_record":
                lh += cur_lh; lf += cur_lf; fnf += cur_fnf; fnh += cur_fnh
                cur_lh = cur_lf = cur_fnf = cur_fnh = 0  # <-- 修复:重置 cur_* 变量
            elif line.startswith("LH:"):
                cur_lh = int(line[3:])
            elif line.startswith("LF:"):
                cur_lf = int(line[3:])
            elif line.startswith("FNF:"):
                cur_fnf = int(line[4:])
            elif line.startswith("FNH:"):
                cur_fnh = int(line[4:])
    result = {}
    if lf:
        result["line_coverage"] = {"total": lf, "passed": lh, "failed": lf - lh,
                                   "coverage": f"{lh / lf * 100:.2f}%"}
    if fnf:
        result["function_coverage"] = {"total": fnf, "passed": fnh, "failed": fnf - fnh,
                                       "coverage": f"{fnh / fnf * 100:.2f}%"}
    return result

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

@add-uos

add-uos commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 895b9a6 into linuxdeepin:master Oct 29, 2026
29 of 32 checks passed
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