Skip to content

ut: 覆盖率缺口补全单元测试(批次1) - #729

Draft
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:ut/covgap-batch1-20260811
Draft

ut: 覆盖率缺口补全单元测试(批次1)#729
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:ut/covgap-batch1-20260811

Conversation

@add-uos

@add-uos add-uos commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

概述

deepin-devicemanager 单元测试补全 —— 批次1(覆盖率缺口补全)。

本 PR 仅新增独立测试文件,不修改已有测试与源码;新增文件接入既有 deepin-devicemanager/tests/src/ 目录,由 CMake 递归 glob 自动收录,无需改动共享 CMakeLists。

本批次覆盖的类与方法

类 / 文件 新增覆盖方法 说明
EDIDParser hexToBin 十六进制转二进制,含合法与边界输入
DriverInfo (MacroDefinition.h) backupFileName / modelName / driverName / vendorName 内联 getter 回写取值
CommonTools 构造函数、静态 feedback() 无会话总线走 false 分支
PageInfo packageHasInstalled dpkg -s 包查询
DeviceAudio/Bluetooth/Cdrom/Computer/Gpu/Image/Input/Memory/Monitor/OtherPCI/Others/Power/Print vendor() 默认构造调用 getter
DeviceBios tomlname
DevicePrint makeAndeModel
DeviceNetwork vendor / isWireless / hwAddress / canDisable 含可判定默认逻辑
DeviceStorage getManfName / getOemName 厂商 ID 查表

新增文件

  • tests/src/GenerateDevice/ut_edidparser_hextobin.cpp
  • tests/src/ut_driverinfo_getters.cpp
  • tests/src/Tool/ut_commontools_feedback.cpp
  • tests/src/Page/ut_pageinfo_packagehasinstalled.cpp
  • tests/src/DeviceManager/ut_device_getters_covgap.cpp

验证

  • 本地编译:Qt6 + Debug + 覆盖率(CMAKE_COVERAGE_ARG=ON,关闭 ASan),客户端测试目标编译链接通过。
  • 本地运行:QT_QPA_PLATFORM=offscreen,整体 1137 用例,通过 1131,失败 6。
    • 6 项失败均为仓库既有用例,均与键盘/hwinfo/hciconfig 硬件信息相关,非本批次引入。
    • 本批次新增 37 用例全部通过。
  • 函数覆盖率(lcov,仅统计 src/,排除 tests/3rdparty):87.3%(1324/1517) → 89.2%(1354/1517),+30 函数。
  • 本批次使 8 个文件达到 100% 函数覆盖:EDIDParser.cpp / commontools.cpp / PageInfo.cpp / MacroDefinition.h / DeviceBios.cpp / DeviceNetwork.cpp / DevicePrint.cpp / DeviceStorage.cpp。

基线

  • baseline_commit: 89825dcd
  • baseline_title: fix(gpu): fix GPU VRAM size parsing failure on multi-line gpu-info
  • baseline_date: 2026-08-06

后续

本批次为多批次覆盖率补全的第一批。剩余约 163 个未覆盖函数(多为硬件相关 getter、虚析构、GUI 事件槽、lambdas 等)将按类/模块在后续批次与 PR 中继续补全。CI 运行中,详见检查状态。

Summary by Sourcery

Add a first batch of unit tests to close coverage gaps in deepin-devicemanager without modifying production code.

New Features:

  • Add EDIDParser::hexToBin unit tests covering normal and boundary hexadecimal inputs.
  • Add unit tests for DriverInfo inline getters to verify default and assigned values.
  • Add CommonTools constructor and static feedback() tests to exercise non-DBus and no-session-bus paths.
  • Add PageInfo::packageHasInstalled tests via PageMultiInfo to validate dpkg-based installation detection.
  • Add Device* and related getter tests (including DeviceNetwork and DeviceStorage) to cover default semantics and vendor/ID mapping logic.

Tests:

  • Introduce multiple new test files under tests/src to raise overall function coverage and bring several core files to 100% coverage.

补全以下类此前函数覆盖率为 0 或存在缺口的 getter/纯逻辑方法用例:

- EDIDParser: hexToBin(十六进制转二进制,含合法输入与边界)
- DriverInfo(MacroDefinition.h): backupFileName/modelName/driverName/vendorName 四个 getter
- CommonTools: 构造函数与静态 feedback()
- PageInfo: packageHasInstalled(dpkg -s 包查询)
- Device* 系列 vendor() 等 getter:DeviceAudio/DeviceBluetooth/DeviceCdrom/
  DeviceComputer/DeviceGpu/DeviceImage/DeviceInput/DeviceMemory/DeviceMonitor/
  DeviceOtherPCI/DeviceOthers/DevicePower/DevicePrint
- DeviceBios: tomlname
- DevicePrint: makeAndeModel
- DeviceNetwork: vendor/isWireless/hwAddress/canDisable
- DeviceStorage: getManfName/getOemName

所有新增用例均接入既有 tests/src 目录(CMake 递归 glob 自动收录),
仅新增独立测试文件,不修改已有测试与源码。

批次统计:
- 新增测试文件:5
- 新增用例:37(全部通过,0 失败 0 跳过)
- 整体用例数:1137,通过 1131,失败 6
  (6 项失败为既有用例,均与键盘/hwinfo/hciconfig 硬件相关,非本批次引入)
- 函数覆盖率:87.3%(1324/1517) → 89.2%(1354/1517),+30 函数
- 本批次使 8 个文件达到 100% 函数覆盖:
  EDIDParser.cpp / commontools.cpp / PageInfo.cpp / MacroDefinition.h /
  DeviceBios.cpp / DeviceNetwork.cpp / DevicePrint.cpp / DeviceStorage.cpp

基线 commit:
- baseline_commit: 89825dc
- baseline_title: fix(gpu): fix GPU VRAM size parsing failure on multi-line gpu-info
- baseline_date: 2026-08-06
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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

@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a first batch of standalone GoogleTest unit tests to close function coverage gaps in deepin-devicemanager, targeting EDIDParser::hexToBin, DriverInfo inline getters, CommonTools construction and feedback(), PageInfo::packageHasInstalled, and several Device* getter methods including DeviceNetwork and DeviceStorage logic, without modifying any production or existing test code.

File-Level Changes

Change Details Files
Add focused tests for Device* getter methods to cover default-construction semantics and simple logic branches
  • Instantiate various Device* subclasses with default constructors and call vendor() to ensure they are callable without crashes
  • Verify DeviceBios::tomlname and DevicePrint::makeAndeModel return empty strings on default construction
  • Assert DeviceNetwork default instance returns empty vendor()/hwAddress(), false isWireless(), and false canDisable() when sys path is empty
  • Validate DeviceStorage::getManfName maps known IDs via MANFID_TABLE and returns raw input when unmapped, and getOemName returns raw input for unknown IDs
tests/src/DeviceManager/ut_device_getters_covgap.cpp
Cover DriverInfo inline getters in MacroDefinition.h with direct value and default semantics tests
  • Construct DriverInfo, assign backing members, and assert backupFileName/modelName/driverName/vendorName getters return the assigned strings
  • Check that a default-constructed DriverInfo returns empty strings for all four getters
tests/src/ut_driverinfo_getters.cpp
Exercise EDIDParser::hexToBin across normal and boundary hexadecimal inputs
  • Test hexToBin with multi-digit input "FF" expecting eight 1 bits
  • Verify single-digit inputs like "0","1","A" are converted with correct 4-bit padding and values
  • Confirm empty-string input is treated as zero and returns "0000"
tests/src/GenerateDevice/ut_edidparser_hextobin.cpp
Add tests for CommonTools construction and static feedback() behavior in environments without a DBus session bus
  • Instantiate CommonTools with and without a QObject parent to cover constructors and parent association
  • Call CommonTools::feedback() and assert it completes without fatal failures when the QDBusInterface is invalid (no session bus)
tests/src/Tool/ut_commontools_feedback.cpp
Introduce tests for PageInfo::packageHasInstalled using PageMultiInfo to cover dpkg-based package detection
  • Create a PageMultiInfo instance, upcast to PageInfo, and assert packageHasInstalled("dpkg") returns true for an installed package
  • Assert packageHasInstalled returns false for a clearly non-existent package name, relying on dpkg -s behavior with stderr-only output
tests/src/Page/ut_pageinfo_packagehasinstalled.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-bot

deepin-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.70
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #724

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.

2 participants