Repository navigation
test: supplement unit tests for 6 core files (Tool + src root, 92 cases) - #907
Conversation
- rewrite tests/src/ut_debugtimemanager.cpp, cases 0 -> 8 - stub gettimeofday via dlsym so the fake clock is deterministic - capture [GRABPOINT] logs via qInstallMessageHandler for assertions - cover constructor / beginPointLinux / endPointLinux (with and without sub-point, unknown point) / clear on all branches - AAA comments complete, no real clock or device dependencies
- rewrite tests/src/Tool/ut_eventlogutils.cpp, cases 3 -> 4 - stub QLibrary::resolve to return null and inject a recording stub into the private function pointer - cover singleton access, null-pointer guard, writeLogs event recording and round-trip JSON payload - no real eventlog library dependency
- rewrite tests/src/Tool/ut_loadcpuinfothread.cpp, cases 1 -> 9 - stub QProcess member functions via static_cast member pointers to isolate real process invocation - pin DeviceManager::cmdInfo via ADDR stub for setCpuRefreshInfoFromlscpu - cover constructor / runCmd / getMapInfoFromCmd parsing branches / cpuInfo paths - no real lscpu or device dependencies
- extend tests/src/ut_commonfunction.cpp, cases 38 -> 49: add boardVendorType caching, checkBoardVendorFlag four branches, executeClientCmd three branches, safeReadSysFsFile seven branches and isShowScreenSize - clear the sticky boardVendorKey via the NormalCom branch first in checkBoardVendorFlag cases - stub DBusInterface::init/getInfo on the getDeviceInfo fallback path to isolate the real DBus call - patch virtual QFile::open/QIODevice::read via dlsym(RTLD_DEFAULT) real function addresses; member-pointer patching breaks the vtable and causes a segfault - add AAA comments and SPDX header for the new cases
Reviewer's GuideAdds or rewrites unit tests for six core files, increasing the scoped suite to 92 cases with deterministic stubs for Qt, DBus, process, filesystem, timing, and device dependencies; the reported run passes 91 cases with one deliberate skip and achieves 92.7% line and 100% function coverage. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning
详情 {
"dmidecode": {
"deepin-devicemanager/tests/src/ut_commonfunction.cpp": [
"// B2 specialComType == -1 -> dmidecode \u5206\u652f:",
"// checkBoardVendorFlag B2.1: dmidecode \u8f93\u51fa\u542b L540 -> KLVV",
" // Assert: M900(/proc/cpuinfo \u65e0 Hardware)\u4e0e W525(dmidecode \u65e0 String 4)\u5747\u4e3a false, \u952e\u4fdd\u6301\u7a7a"
]
}
} |
- add tests/src/ut_singledevicemanager.cpp, previously untested - a DApplication subclass crashes on exit when constructed twice in one process: run plain scenarios in forked children, dump coverage via __gcov_dump and _exit to keep counters - forked children deadlock on the first DBus-dependent call inside activateWindow (no Qt DBus thread after fork), so use an exec-child harness instead: the parent re-executes the test binary via QProcess with DM_UT_SINGLE_DEVICE_MARKER=1 and checks the exit code - declare __gcov_dump through gcov.h wrapped in extern "C"; a weak C++ declaration gets name-mangled and stays null, silently losing all child coverage data - cover constructor / parseCmdLine four branches / startDeviceManager two branches / activateWindow create-and-reuse branches - stub MainWindow::refreshDataBase, QLibrary::resolve and EventLogUtils; no real device, DBus or eventlog dependencies
|
Warning
详情 {
"dmidecode": {
"deepin-devicemanager/tests/src/ut_commonfunction.cpp": [
"// B2 specialComType == -1 -> dmidecode \u5206\u652f:",
"// checkBoardVendorFlag B2.1: dmidecode \u8f93\u51fa\u542b L540 -> KLVV",
" // Assert: M900(/proc/cpuinfo \u65e0 Hardware)\u4e0e W525(dmidecode \u65e0 String 4)\u5747\u4e3a false, \u952e\u4fdd\u6301\u7a7a"
]
}
} |
|
[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 |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['继续保持 AAA(Arrange/Act/Assert)结构和清晰的用例命名'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['建议将 QProcess 打桩辅助函数提取到公共头文件(如 ut_qprocess_stub.h)复用', '建议在文件头注释中标注静态全局状态的串行执行依赖', 'dlsym 路径建议增加编译期 Qt 版本断言或改用 vtable 偏移方案'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无需优化'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无需安全加固'] 💡 改进建议代码示例// 建议:提取 QProcess 打桩公共头文件 ut_qprocess_stub.h
// 减少 ut_commonfunction.cpp 与 ut_loadcpuinfothread.cpp 之间的重复代码
//
// #pragma once
// #include <QByteArray>
// #include <QProcess>
// #include "stub.h"
//
// namespace ut_stub {
// static QByteArray qprocess_stdout;
//
// static void qprocess_start_noop(QProcess*, const QString&,
// const QStringList&, QIODevice::OpenMode) {}
// static bool qprocess_waitForFinished_true(QProcess*, int) { return true; }
// static QByteArray qprocess_readAll_canned(QProcess*) { return qprocess_stdout; }
//
// inline void install_qprocess_stubs(Stub &stub) {
// auto startFunc = static_cast<void (QProcess::*)(const QString&,
// const QStringList&, QIODevice::OpenMode)>(&QProcess::start);
// auto waitFunc = static_cast<bool (QProcess::*)(int)>(&QProcess::waitForFinished);
// auto readFunc = static_cast<QByteArray (QProcess::*)()>(&QProcess::readAllStandardOutput);
// stub.set(startFunc, qprocess_start_noop);
// stub.set(waitFunc, qprocess_waitForFinished_true);
// stub.set(readFunc, qprocess_readAll_canned);
// }
// }本报告由 AI 代码审查工具自动生成 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
What this PR does
Rewrites or extends Google Test unit tests for 6 core files of
deepin-devicemanager(scope: Tool utilities + src root):UT_DebugTimeManagersrc/DebugTimeManager.cppUT_EventLogUtilssrc/Tool/eventlogutils.cppUT_LoadCpuInfoThreadsrc/Tool/LoadCpuInfoThread.cppUT_Commonsrc/commonfunction.cppUT_SingleDeviceManagersrc/SingleDeviceManager.cppUT_DBusAnythingInterfacesrc/Tool/DBusAnythingInterface.cpp92 cases in scope; test code only, no production changes.
Key points
QFile::open,QIODevice::read) are patched viadlsym(RTLD_DEFAULT, <mangled>)real function addresses; member-pointer patching on virtuals breaks the vtable and segfaults.SingleDeviceManagerinheritsDApplication; constructing a second QApplication in-process crashes on exit, and forked children deadlock on the first DBus call (no Qt DBus thread). Plain scenarios run in forked children (__gcov_dump+_exit, declared viagcov.hwrapped inextern "C"— a weak C++ declaration gets name-mangled and silently loses all child coverage data); window scenarios use an exec-child harness (DM_UT_SINGLE_DEVICE_MARKER=1, exit-code encoded results).ActivateWindow_InternalMarker_ScenarioThenExitis intentionally skipped outside that harness and driven byActivateWindow_ViaChildProcess_ExitCodeZero.Verification
Result: 91 passed, 0 failed, 1 skipped by design (exit code 0), based on latest upstream/master (f4d271c).
During test development 3 suspected source defects were found and reported separately (DBus timeout blocking in
getDeviceInfo, stickyboardVendorKeycache incheckBoardVendorFlag, commented-outshowNormal()instartDeviceManager); no production code is changed in this PR.Summary by Sourcery
Strengthen unit-test coverage for six core files without changing production code.
Enhancements:
Tests: