Repository navigation
test: add unit tests for GenerateDevice pool and generators (102 cases) - #914
Conversation
按 W-R-B 闭环对 GenerateDevice 模块重写单元测试: - HWGenerator: 计算机/磁盘/蓝牙/网络/音频/内存/显示器/电源/CPU/键盘/摄像头 46用例, 覆盖空数据/全量字段/正则归一化/wifi文件解析/toml分支 - HWGeneratorGpu: gpuinfo 退出码127/126/有效输出/全角冒号 7用例 - GenerateDevicePool: 16类型任务分发/槽计数/真实工厂MIPS分支 12用例 - LoadInfoThread: 构造状态/服务运行判定/装载闭环/析构安全 7用例 - GetInfoPool: 命令表装载/框架转发/finishedCmd计数边界 10用例 - MipsGenerator: 首页URL/DMI覆盖/OS版本gcc归一化/空数据 9用例 关键桩策略: - Qt虚函数(QFile::open/QIODevice::close)经 dlsym 原始地址打桩 - QDateTime 单调递增桩使全部忙等循环立即超时 - 工厂桩每次返回新实例(GenerateTask::run 尾部 delete 所得生成器) - boardVendorType 置空避免 dmidecode 子进程 - Common::getArch 桩驱动真实工厂分支 编译验证: deepin-devicemanager-test 全量构建通过 运行验证: 89/89 通过(offscreen, 24.5s, 无崩溃)
依据 Mode 6 复审机械性违规清单逐项修补: - 测试名 TOO_FEW_SEGMENTS: 14 处重命名为 方法_场景_结果 三段式 - 断言空洞: 23 处补第二断言(重名/空值/数量), 消除 SOLE_BOOL_ASSERT/LOW_ASSERT - AAA 段: 47+ 处补 Arrange/Act/Assert 注释, Act 段保证含实质动作 - BELOW_MIN 用例数: 新增 13 个真实用例(ctor 幂等/rerun 语义/边界值), 高于下限的方法以 actual 增量修复, 未凑数改声明表 - 声明表: 用例计数按 FEAT 前缀聚合更新, actual 与 TEST_F 计数一致 - 已知保留项: UT_HEAD 继承结构检查误报(项目框架约定, 每文件 1 处) 验证: self-check 6 文件 0 error(除结构误报) 0 warning; 102 用例(47/7/14/10/14/10) 全部通过, offscreen 25s; test-review: 0 FAIL / 6 WARN(仅结构误报) / 0 critical
Replace the legacy 'Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.' line inherited from the rewritten test files with 'Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd'.
Reviewer's GuideThis PR rewrites and substantially expands six GenerateDevice test files to 102 deterministic Google Test cases, using stubs for DBus, commands, processes, time, filesystem, and hardware data to exercise normal, boundary, error, asynchronous, and routing paths headlessly; the tests also document four observed production defects without modifying production code. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning
详情 {
"dmidecode": {
"deepin-devicemanager/tests/src/GenerateDevice/ut_generatedevicepool.cpp": [
"// \u7a7avendor -> \u751f\u6210\u5668\u6784\u9020\u8d70\u8f7b\u91cf\u8def\u5f84, \u4e0d\u89e6\u53d1 dmidecode \u5b50\u8fdb\u7a0b(\u771f\u5b9e\u5de5\u5382\u7528\u4f8b\u9664\u5916)"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_getinfopool.cpp": [
" EXPECT_EQ(m_readFilePool->m_CmdList[6][0], \"dmidecode4\");"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_hwgenerator.cpp": [
"// B3 dmidecode1 \u975e\u7a7a\u4e14[0]\u542b\"Product Name\"\u4e14\u975e\u7a7a -> setName(dmi[0][\"Product Name\"]);",
"/// B1-B5: \u5168\u91cf\u6709\u6548\u6570\u636e -> \u8bbe\u5907\u5b57\u6bb5\u6b63\u786e(dmidecode \u8986\u76d6 name, gcc \u6bb5\u5f52\u4e00\u5316)",
" seedCmdInfo(\"dmidecode1\", {QMap<QString, QString> {{\"Product Name\", \"ThinkCentre M910\"}}});",
" EXPECT_EQ(computer->name(), \"ThinkCentre M910\"); // B3 dmidecode \u8986\u76d6",
" seedCmdInfo(\"dmidecode1\", {QMap<QString, QString> {{\"Product Name\", \"Pavilion 14\"}}});",
" EXPECT_EQ(computer->name(), \"Pavilion 14\"); // B3 dmidecode Product Name \u4ecd\u7136\u751f\u6548",
"/// B6(\u4e0d\u6ee1\u8db3): dmidecode1 \u65e0 Product Name \u952e -> \u540d\u79f0\u53d6 lshw product",
" seedCmdInfo(\"dmidecode1\", {QMap<QString, QString> {{\"Manufacturer\", \"Dell\"}}});"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_loadinfothread.cpp": [
"// B3 \u91cd\u8bd5\u5faa\u73af: dmidecode4 \u4e3a\u7a7a\u4e14 finishedReadFilePool \u672a\u7f6e\u4f4d -> 4s \u8d85\u65f6 -> readNum>3 \u9000\u51fa;",
"// \u7a7avendor -> \u751f\u6210\u5668\u6784\u9020\u4e0d\u89e6\u53d1 dmidecode \u5b50\u8fdb\u7a0b",
" // \u751f\u6210\u5668\u6784\u9020\u8d70\u8f7b\u91cf\u8def\u5f84, \u4e0d\u89e6\u53d1 dmidecode \u5b50\u8fdb\u7a0b(generateDevice \u4f1a\u771f\u5b9e\u5efa\u751f\u6210\u5668)"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_mipsgenerator.cpp": [
"// B3 dmidecode1 size>1(\u4e25\u683c\u5927\u4e8e) -> setName(dmiInfo[1][\"Product Name\"]);",
"/// B3: dmidecode1 \u53d6\u7b2c\u4e8c\u6761\u76ee(index 1)\u7684 Product Name",
" data[\"dmidecode1\"] = QList<QMap<QString, QString>>()",
" EXPECT_EQ(computer->vendor(), \"Loongson\"); // \u7b2c\u4e8c\u6761 dmidecode \u53ea\u8986\u76d6 name",
"/// B3(\u8fb9\u754c): dmidecode1 \u4ec5\u4e00\u6761(size==1) -> name \u4e0d\u88ab\u8986\u76d6, \u4fdd\u6301 lshw product",
" data[\"dmidecode1\"] = QList<QMap<QString, QString>>()",
" EXPECT_EQ(computer->vendor(), \"Loongson\"); // \u5355\u6761 dmidecode \u4e0d\u8986\u76d6 name, vendor \u4ecd\u6765\u81ea lshw"
]
},
"lshw": {
"deepin-devicemanager/tests/src/GenerateDevice/ut_getinfopool.cpp": [
"// Stub: CmdTool::loadCmdInfo \u6253\u6869\u4e3a\u7a7a\u64cd\u4f5c \u2014\u2014 \u6d4b\u8bd5\u4e0d\u6267\u884c\u771f\u5b9e\u547d\u4ee4(lshw/hwinfo \u7b49),",
" // \u9996\u6761\u547d\u4ee4\u4e3a lshw",
" EXPECT_EQ(m_readFilePool->m_CmdList[0][0], \"lshw\");",
" EXPECT_EQ(m_readFilePool->m_CmdList[0][1], \"lshw.txt\");",
" EXPECT_EQ(m_readFilePool->m_CmdList[29][0], \"lshw\"); // \u8ffd\u52a0\u6bb5\u4ece lshw \u91cd\u65b0\u5f00\u59cb",
" EXPECT_EQ(second->m_CmdList[0][0], \"lshw\");",
" data[\"lshw\"] = QList<QMap<QString, QString>>() << QMap<QString, QString> {{\"vendor\", \"Lenovo\"}};",
" EXPECT_FALSE(DeviceManager::instance()->cmdInfo(\"lshw\").isEmpty());"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_hwgenerator.cpp": [
"// B2 lshw_system size>0 -> setType(description)+setName(product);",
"// generatorBluetoothDevice(146-186): hciconfig/hwinfo_usb/lshw_usb \u4e09\u6e90 +",
" seedCmdInfo(\"lshw_system\", {QMap<QString, QString> {{\"description\", \"Desktop Computer\"},",
" seedCmdInfo(\"lshw_system\", {QMap<QString, QString> {{\"description\", \"Notebook\"}, {\"vendor\", \"HP\"}, {\"product\", \"Pavilion\"}}});",
"/// B6(\u4e0d\u6ee1\u8db3): dmidecode1 \u65e0 Product Name \u952e -> \u540d\u79f0\u53d6 lshw product",
" seedCmdInfo(\"lshw_system\", {QMap<QString, QString> {{\"description\", \"Desktop\"}, {\"vendor\", \"Dell\"}, {\"product\", \"OptiPlex 7080\"}}});",
" EXPECT_EQ(computer->name(), \"OptiPlex 7080\"); // B6 \u540d\u79f0\u4fdd\u6301 lshw product",
" seedCmdInfo(\"lshw_usb\", {e1, e2});",
" seedCmdInfo(\"lshw_memory\", {QMap<QString, QString> {{\"size\", \"8 GB\"}, {\"slot\", \"DIMM0\"}}});",
" seedCmdInfo(\"lshw_memory\", {mem});",
" seedCmdInfo(\"lshw_memory\", {mem});"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_mipsgenerator.cpp": [
"// B2 lshw_system \u975e\u7a7a -> setType(description)/setVendor(vendor)/setName(product);",
"/// B2: lshw_system -> type/vendor/name",
" data[\"lshw_system\"] = QList<QMap<QString, QString>>()",
" data[\"lshw_system\"] = QList<QMap<QString, QString>>()",
"/// B3(\u8fb9\u754c): dmidecode1 \u4ec5\u4e00\u6761(size==1) -> name \u4e0d\u88ab\u8986\u76d6, \u4fdd\u6301 lshw product",
" data[\"lshw_system\"] = QList<QMap<QString, QString>>()",
" EXPECT_EQ(computer->vendor(), \"Loongson\"); // \u5355\u6761 dmidecode \u4e0d\u8986\u76d6 name, vendor \u4ecd\u6765\u81ea lshw",
" EXPECT_EQ(computer->vendor(), QString()); // \u65e0 lshw_system -> vendor \u4fdd\u6301\u7a7a"
]
}
} |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ❌评价: 存在逻辑缺陷 ❌ 不通过 潜在问题: 建议: ['为 s_cmdKey/s_cmdFile 加 QMutex 保护,或在多线程路径中不触碰这两个捕获变量(改用 std::atomic 计数器验证调用次数)', '在调用 m_stub.set(qtFileOpenSym(), ...) 前增加空指针判断,符号未找到时跳过该桩或记录 GTEST_SKIP', '将 busIdCount 的捕获移到 slotFinished 调用之前,断言调用前后 size 不变'] 2. 代码质量 ❌评价: 存在重复代码 ❌ 不通过 潜在问题: 建议: ['删除各文件中重复的第二个最小清单注释块', '移除 ut_hwgenerator_gpu.cpp 中 ASSERT_EQ 后冗余的 EXPECT_EQ 同参断言', '局部裸指针改用 std::unique_ptr,或在 ASSERT 前完成断言、delete 放到 ASSERT 之后;s_factoryNext 在 SetUp 中先 delete 再置空', '合并 ut_dmSetBtLshw 与 ut_dmSetBtLshwEmpty,或让 Empty 变体有不同行为', 'SlotFinishedReadFilePool_FreshInstance 移除对 emit 计数的断言,或显式记录顺序依赖', '修正 DT_Others 用例注释,改为走显式 case DT_Others 分支'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['ut_generatedevicepool.cpp:138-145 — ut_qdatetime_now 中静态变量 t 跨用例不重置,建议在 SetUp 中重置以消除隐式顺序依赖(不影响性能)'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 修复1: ut_getinfopool.cpp — 加锁保护多线程写
#include <QMutex>
static QMutex s_stubMutex;
static QString s_cmdKey;
static QString s_cmdFile;
static void ut_ct_loadCmdInfo(void *obj, const QString &cmd, const QString &file)
{
Q_UNUSED(obj);
QMutexLocker locker(&s_stubMutex);
s_cmdKey = cmd;
s_cmdFile = file;
}
// 修复2: ut_hwgenerator.cpp — dlsym 空指针保护
#define STUB_SET_OR_SKIP(stub, addr, fn) do { \
if (addr) { stub.set(addr, fn); } \
else { GTEST_SKIP() << "symbol not found, skip stub"; } \
} while(0)
// 使用: STUB_SET_OR_SKIP(m_stub, qtFileOpenSym(), (void *)&ut_qfile_open_bootdevice);
// 修复3: ut_generatedevicepool.cpp — 恒真断言改为前后对比
const int busIdBefore = DeviceManager::instance()->m_BusIdList.size();
pool.slotFinished(QStringList());
EXPECT_EQ(DeviceManager::instance()->m_BusIdList.size(), busIdBefore);
// 修复4: 局部裸指针改 unique_ptr
std::unique_ptr<DeviceStorage> storage(new DeviceStorage);
s_convertList.append(storage.get());
// ... 断言 ...
// storage 自动释放,ASSERT 失败亦不泄漏本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
Summary
Rewrite and extend the Google Test suites for the GenerateDevice module (5 source files, 6 test files), 102 cases all passing:
ut_hwgenerator.cpput_generatedevicepool.cpput_loadinfothread.cpput_getinfopool.cpput_mipsgenerator.cppQT_QPA_PLATFORM=offscreenand never touch real device environments.Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd.master(845a8b6), verified build + 102/102 pass after rebase.4 source-code defects reported (not fixed in this PR, reported to bug-fix squad)
src/GenerateDevice/GenerateDevicePool.h:86—m_FinishedGeneratorhas no initializer; first clear only happens ingenerateDevice().src/DeviceManager.cpp:57—clear()does not resetm_BusIdListwhileaddBusId()only appends.src/GenerateDevice/GetInfoPool.cpp—initCmd()appends without clearing, duplicated commands accumulate on re-run.src/GenerateDevice/LoadInfoThread.cpp:23— file-levelstatic bool firstLoadFlagis shared across instances (needs manual review).Test plan
cmake --buildofdeepin-devicemanager-testtarget, 0 warnings from new test filesQT_QPA_PLATFORM=offscreen ./deepin-devicemanager-test --gtest_filter='UT_HWGenerator.*:...'→ 102/102 PASSEDSummary by Sourcery
Strengthen GenerateDevice test coverage with 102 isolated unit tests and report the implementation defects uncovered during validation.
Enhancements:
Tests:
Chores: