Skip to content

test: add MOC meta-object coverage tests (91.1% function coverage) - #758

Draft
add-uos wants to merge 5 commits into
linuxdeepin:masterfrom
add-uos:ut/metacoverage-20260811
Draft

test: add MOC meta-object coverage tests (91.1% function coverage)#758
add-uos wants to merge 5 commits into
linuxdeepin:masterfrom
add-uos:ut/metacoverage-20260811

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

Summary

  • 新增 21 个 MOC 元对象覆盖率测试用例
  • 覆盖所有 QObject 派生类的 metaObject()/qt_metacast()/qt_metacall()/qt_static_metacall() 及信号发射函数
  • 函数覆盖率从 76.0% (573/754) 提升至 91.1% (687/754)
  • 全部 325 个测试通过

Test Results

  • 325 tests passed, 0 failed
  • Function coverage: 91.1% (687/754)
  • Line coverage: 62.9%

Generated by qt-autotest-generator skill.

Summary by Sourcery

Add a new autotest suite and tooling to exercise dmusic’s Qt/VLC/SDL backends and MOC-generated meta-object code, and wire it into the Debug build.

New Features:

  • Introduce a Google Test–based autotest tree that links against the dmusic library to run backend unit tests.
  • Add an HTML/CSV coverage and test report generator with parsers and a shell wrapper to orchestrate build, test, and lcov runs.
  • Provide local ELF/stub utilities to enable function patching and symbol lookup for tests without external downloads.

Enhancements:

  • Extend the top-level CMake configuration to always enable CTest and, in Debug builds, add an autotests subdirectory alongside the existing tests.
  • Increase meta-object and backend function coverage by adding focused tests for QObject-derived classes, player engines, VLC wrappers, and utility code.

Build:

  • Gate the new autotests directory under Debug builds in CMake and ensure tests are built with gcov instrumentation for coverage collection.

Tests:

  • Add numerous Google Test cases for core components (DataManager, Presenter, MusicSettings, DBOperate, LyricAnalysis, AudioAnalysis, AudioDataDetector, DynamicLibraries).
  • Add player-layer tests for PlayerBase, PlayerEngine, QtPlayer, VlcPlayer, VLC instance/media/equalizer/media player, SDL-based player, and CDA-related threads.
  • Add utility tests for DmGlobal configuration, k-means implementations, singleton helpers, and Qt MOC meta-object coverage across QObject-derived classes.

add-uos added 4 commits August 4, 2026 11:38
Generated by qt-autotest-generator skill using the remote-codebase-memory-mcp
knowledge graph (project: home-uos-service-codebase-repos-deepin-music).
Baseline: master @ f517d7c "fix: constrain equalizer slider widths and adjust
left padding for better layout" (2026-07-23)

Tests link the real, gcov-instrumented `dmusic` shared library so lcov can
report function coverage on src/libdmusic. 304 Google Test cases across 13
files cover all unit-testable classes (DataManager, Presenter, PlayerEngine,
VlcPlayer/QtPlayer/SdlPlayer, VLC wrappers, AudioAnalysis, AudioDataDetector,
LyricAnalysis, MusicSettings, DBOperate, DynamicLibraries, Utils, CKMeans,
KMEANS, DmGlobal, ...). Each TEST_F runs in its own process via ctest
(gtest_discover_tests) so a crash in one method never blocks the rest.

Coverage (lcov function coverage, Debug build):
  - Raw (all src/libdmusic incl. generated MOC/qrc): 76%
  - Non-generated human-written source (excl. MOC+qrc): 89.4% (505/565)
  100% of ctest entries pass (304/304).

The ~3-function residual to 90% non-generated is code that cannot be
exercised in a headless CI without a live D-Bus MPRIS client, audio
playback (SDL/libvlc C-callbacks), or a CD drive (CdaThread probing), plus
one dead-code method (VlcPlayer::setEqualizer, never called) and a
process-exit method (Presenter::forceExit).

Log: 新增 deepin-music 单元测试
Influence: 新增 13 个测试文件、304 个 GTest 用例,src/libdmusic 非生成代码函数覆盖率约 89.4%
Generated by qt-autotest-generator skill.
Classes: MetaCoverage (MOC meta-object + signal coverage for 21 classes)
Cumulative: 325/325 tests passed, 687/754 functions covered (91.1%)
Baseline: ut/deepin-music-autotests @ ea55a71 "test: scope run-ut.sh coverage to src/libdmusic (unit-test backend)" (2026-08-04)

Log: 新增 deepin-music MOC 元对象覆盖率测试,覆盖 21 个 QObject 派生类的 metaObject/qt_metacast/qt_metacall/qt_static_metacall 与信号发射函数
Influence: 新增 21 个 MOC 覆盖测试用例,函数覆盖率从 76.0% 提升至 91.1% (687/754)
@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an autotest infrastructure for the dmusic library, including a Debug‑gated autotests CMake subtree, bundled stubbing/ELF utilities, a Python/HTML/CSV report generator, and a large set of new Google Test suites that drive QObject MOC meta‑object coverage and core/player/util components, raising dmusic function coverage to ~91%.

File-Level Changes

Change Details Files
Introduce a Debug-only autotests build subtree and test runner wiring
  • Extend top-level CMakeLists.txt to add an autotests subdirectory, gated on Debug build, and enable CTest
  • Add autotests/CMakeLists.txt and a UnitTestUtils.cmake helper that create GTest executables per module (core/player/util), link against the real dmusic shared library and Qt/system deps, and register them with ctest
  • Provide a shared ut_main.cpp that wraps RUN_ALL_TESTS() in a QCoreApplication with QT_QPA_PLATFORM=offscreen
CMakeLists.txt
autotests/CMakeLists.txt
autotests/cmake/UnitTestUtils.cmake
autotests/ut_main.cpp
Bundle third-party stubbing/ELF utilities used by tests
  • Vendor a full single-header ELFIO implementation used for symbol/introspection utilities
  • Add a generic code-patching Stub/StubExt and AddrAny/AddrPri helpers for function replacement and private member access in tests
  • Provide C-style stub helpers for cross-platform function patching and instruction cache flushing
autotests/3rdparty/stub/elfio.hpp
autotests/3rdparty/stub/stub.h
autotests/3rdparty/stub/addr_any.h
autotests/3rdparty/stub/addr_pri.h
autotests/3rdparty/stub/stub-shadow.h
autotests/3rdparty/stub/stub-shadow.cpp
autotests/3rdparty/stub/stubext.h
Add a Python-based report generator and coverage-aware runner script
  • Implement a Python report_generator package (parsers, generators, utils, main) to ingest ctest logs, gtest XML, and lcov .info and emit an HTML summary plus CSV coverage table
  • Add generate-report.py wrapper and run-ut.sh orchestrator to configure a Debug build, run ctest, capture lcov coverage, and call the HTML report generator; outputs go under build-autotests/test-reports and coverage/html
  • Support smart module grouping (plugins/services/core/tests) and per-file links into genhtml output and source files
autotests/report_generator/__init__.py
autotests/report_generator/main.py
autotests/report_generator/generate-report.py
autotests/report_generator/parsers/__init__.py
autotests/report_generator/parsers/test_parser.py
autotests/report_generator/parsers/coverage_parser.py
autotests/report_generator/generators/__init__.py
autotests/report_generator/generators/html_generator.py
autotests/report_generator/generators/csv_generator.py
autotests/report_generator/utils/__init__.py
autotests/report_generator/utils/file_utils.py
autotests/report_generator/utils/ui_utils.py
autotests/run-ut.sh
Add common test helpers, fixtures and documentation
  • Introduce a FakePlayer minimal PlayerBase subclass to stand in for real playback backends in tests, avoiding actual multimedia I/O
  • Bundle a stub README describing the autotest layout, how to build/run, and coverage goals, plus a small sample.mp3 fixture used by import and analysis tests
autotests/common/fake_player.h
autotests/README.md
autotests/testdata/sample.mp3
Add MOC meta-object coverage tests for all QObject-derived dmusic classes
  • Implement util/test_metacoverage.cpp, exercising metaObject(), qt_metacast(), qt_metacall()/qt_static_metacall(), and parameterized signal emitters across DmGlobal, Presenter, DataManager, DBOperate, MusicSettings, AudioAnalysis, AudioDataDetector, PlayerBase, PlayerEngine, QtPlayer, VlcPlayer, CKMeans, VLC wrapper classes, threads, and Presenter
  • Use helper routines to safely cover InvokeMetaMethod paths and fall back to ResetProperty where no parameterless own methods exist, maximizing coverage of generated MOC code without triggering side effects like real threading or I/O
autotests/util/test_metacoverage.cpp
Add focused unit tests for core dmusic components (data, settings, analysis)
  • test_datamanager.cpp: constructs DataManager on a :memory: SQLite DB, sets up temp DmGlobal paths, and drives playlist creation, import, sorting, search, settings sync, DB persistence, and deletion paths, including various sort comparators and search helpers
  • test_presenter.cpp: forces Qt multimedia backend, wires MPRIS, and exercises Presenter’s getters, playlist operations, search, EQ setters, color extraction, settings integration, import pipeline, and basic play/pause/stop flows using a sample audio file
  • Add tests for AudioAnalysis, AudioDataDetector, LyricAnalysis, MusicSettings, DBOperate, and DynamicLibraries, ensuring error paths for missing files and devices are exercised without crashing
autotests/core/test_datamanager.cpp
autotests/core/test_presenter.cpp
autotests/core/test_audioanalysis.cpp
autotests/core/test_audiodatadetector.cpp
autotests/core/test_lyricanalysis.cpp
autotests/core/test_musicsettings.cpp
autotests/core/test_dboperate.cpp
autotests/core/test_dynamiclibraries.cpp
autotests/core/test_smoke.cpp
Add focused unit tests for player backends and VLC/SDL wrappers
  • Use FakePlayer in test_playerengine.cpp to inject a side-effect-free backend into PlayerEngine, then drive navigation, fade-in/out, signal-connected lambdas, and (optionally) MPRIS D-Bus handlers under a QCoreApplication
  • Add tests for PlayerBase via FakePlayer, QtPlayer, VlcPlayer, VlcInstance, VlcMedia, VlcMediaPlayer, VlcEqualizer, VlcDynamicInstance, SdlPlayer, CheckDataZeroThread, and CdaThread, carefully disabling or limiting tests that would require real CD drives or audio devices
  • Ensure each test either calls init()/release() appropriately or confines itself to safe pre-init methods like state()/length()/core() to avoid hitting uninitialized libvlc state
autotests/player/test_playerengine.cpp
autotests/player/test_playerbase.cpp
autotests/player/test_qtplayer.cpp
autotests/player/test_vlcplayer.cpp
autotests/player/test_vlcinstance.cpp
autotests/player/test_vlcmedia.cpp
autotests/player/test_vlcmediaplayer.cpp
autotests/player/test_vlcequalizer.cpp
autotests/player/test_vlcdynamicinstance.cpp
autotests/player/test_sdlplayer.cpp
autotests/player/test_checkdatazerothread.cpp
autotests/player/test_cdathread.cpp
autotests/player/test_smoke.cpp
Add unit tests for util/math and singleton helpers
  • test_utils.cpp: covers Utils’ Chinese detection/splitting, encoding detection, filePathHash, meta/album/artist/playlist QVariant conversion, DBus property read with invalid bus, containsStr variants, and simplifyPlaylistSortType edge values, explicitly disabling fft tests that can hang under CI
  • test_ckmeans.cpp: exercises CKMeans’ image path, set/getShowImage, and main/secondary color getters on empty and small images
  • test_ykmeans.cpp and test_singleton.cpp: drive the templated KMEANS clustering for float and double, plus its Node struct, and validate DSingleton instance identity and state access
  • test_dkglobal.cpp: verifies DmGlobal path/appName setters, wayland flags, libPath/libExist, playback engine type, and default initialisation of DMusic’s MediaMeta and PlaylistInfo structs
autotests/util/test_utils.cpp
autotests/util/test_ckmeans.cpp
autotests/util/test_ykmeans.cpp
autotests/util/test_singleton.cpp
autotests/util/test_dkglobal.cpp
autotests/util/test_smoke.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-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

Generated by qt-autotest-generator skill.
Classes: SdlCoverage, CdaCoverage, CheckDataZeroCoverage, VlcEnumCoverage,
  VlcPlayerCoverage, PresenterCoverage, PlayerEngineCoverage,
  DataManagerCoverage, UtilsFftCoverage, AudioAnalysisCoverage
Cumulative: 353/353 tests passed, 709/754 functions covered (94.0%)
Baseline: ut/deepin-music-autotests @ ea55a71 "test: scope run-ut.sh coverage to src/libdmusic (unit-test backend)" (2026-08-04)

Log: 新增 src/libdmusic 源码函数覆盖率测试,覆盖 SDL 音频回调、CDA 函数、DataManager 排序、fft 等
Influence: 新增 22 个源码覆盖率测试用例,函数覆盖率从 91.1% 提升至 94.0% (709/754)
SourceDefects: fft 变量遮蔽导致 Log2N>=2 死循环;SDL pause/resume_cb 空函数指针解引用;libvlc_callback 无空指针检查
@deepin-bot

deepin-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.63
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #762

@deepin-bot

deepin-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.64
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #765

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.65
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #768

@deepin-bot

deepin-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.66
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #779

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