Skip to content

Expand JaCoCo coverage scope and extract DxgiUtilJNA - #3159

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:improve-coverage
Apr 14, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:improve-coverage

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

JaCoCo exclude changes

Remove excludes that were hiding tested code from coverage reports:

  • **/common/** - oshi-common classes now have direct tests
  • **/driver/** - driver classes are exercised by platform tests
  • **/Abstract* - abstract base classes are tested via subclasses

Add new exclude:

  • **/benchmark/** - benchmark harness code, not production logic

Replace blanket **/unix/** exclude with granular excludes for platforms with limited CI coverage:

  • **/unix/aix/**, **/unix/freebsd/**, **/unix/openbsd/**, **/unix/solaris/**
  • **/unix/*Aix*, **/unix/*Bsd*, **/unix/*FreeBsd*, **/unix/*OpenBsd*, **/unix/*Solaris*
  • **/unix/UnixBaseboard*

This preserves coverage for shared unix classes used on macOS (e.g. UnixPrinter, Cups).

DxgiUtilJNA extraction

Extract four static helper methods from the JNA mapping class Dxgi (formerly WindowsDxgi) to new DxgiUtilJNA in oshi.util.gpu so they are visible to JaCoCo (**/jna/** is excluded):

  • queryAdapters() (delegates to Dxgi)
  • findMatch()
  • registryValueToVram()
  • normalizeName()

Rename AdlUtil to AdlUtilJNA for consistency with NvmlUtilJNA and DxgiUtilJNA.

Summary by CodeRabbit

  • Refactor

    • Reorganized GPU utility code with improved separation of concerns for AMD and NVIDIA GPU metric backends.
    • Consolidated adapter query and utility operations into dedicated utility classes.
  • Tests

    • Relocated and updated GPU-related tests to align with utility code organization.

Remove JaCoCo excludes for common, driver, and Abstract classes
so they appear in coverage reports. Add benchmark exclude. Replace
blanket unix exclude with granular excludes for untested platforms
(aix, freebsd, openbsd, solaris).

Extract static helper methods from Dxgi (JNA mapping) to new
DxgiUtilJNA in oshi.util.gpu so they are visible to coverage.
Rename AdlUtil to AdlUtilJNA for consistency.
@coderabbitai

coderabbitai Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refactors Windows GPU utility classes by extracting utility methods from JNA platform classes into dedicated utility classes, renaming ADL utility from AdlUtil to AdlUtilJNA, and consolidating DXGI-related helpers into a new DxgiUtilJNA utility class. All callers are updated to use the new utility locations.

Changes

Cohort / File(s) Summary
GPU Utility Classes
oshi/util/gpu/AdlUtilJNA.java, oshi/util/gpu/DxgiUtilJNA.java
Renamed AdlUtil → AdlUtilJNA with updated logger reference. New DxgiUtilJNA class consolidates DXGI-related utility methods: queryAdapters(), findMatch(), registryValueToVram(), and normalizeName().
Windows DXGI Classes
oshi/jna/platform/windows/Dxgi.java, oshi/jna/platform/windows/DxgiAdapterInfo.java
Renamed WindowsDxgi → Dxgi and removed three public methods now located in DxgiUtilJNA (findMatch, registryValueToVram, normalizeName). Updated Javadoc reference in DxgiAdapterInfo.
Windows GPU Stats/Graphics
oshi/hardware/platform/windows/WindowsGpuStats.java, oshi/hardware/platform/windows/WindowsGraphicsCard.java
Updated imports and method calls to use AdlUtilJNA (from AdlUtil) and DxgiUtilJNA (from WindowsDxgi) respectively. No control-flow changes.
Tests and Configuration
oshi/util/gpu/DxgiUtilTest.java, pom.xml
Moved and renamed test from WindowsDxgiTest to DxgiUtilTest, updated to test DxgiUtilJNA instead of WindowsDxgi. Updated JaCoCo exclusion patterns to be more specific for Unix platforms and add benchmark exclusions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • mprins

Poem

🐰 Hopping through utilities with care,
Methods find their homes so fair,
WindowsDxgi now just Dxgi shines,
AdlUtil becomes JNA's design,
Refactored paths make logic cleaner! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.63% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: JaCoCo coverage expansion and extraction of DxgiUtilJNA utility class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pom.xml`:
- Around line 811-814: The coverage exclude pattern **/unix/*Bsd* is too broad
and unintentionally excludes shared helper BsdNetworkIF.java; remove that
specific pattern from the excludes list and keep the existing platform-specific
excludes (**/unix/freebsd/**, **/unix/openbsd/** and the file-level patterns
**/unix/*FreeBsd*, **/unix/*OpenBsd*) so only actual FreeBSD/OpenBSD
implementations remain excluded and BsdNetworkIF stays covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e1e02a05-b9f7-407c-b43c-cb5028d575e1

📥 Commits

Reviewing files that changed from the base of the PR and between 8fa7005 and 74de680.

📒 Files selected for processing (8)
  • oshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
  • oshi-core/src/main/java/oshi/jna/platform/windows/Dxgi.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/test/java/oshi/util/gpu/DxgiUtilTest.java
  • pom.xml
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, ubuntu-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.

Applied to files:

  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
📚 Learning: 2026-04-11T05:51:49.185Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:49.185Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
  • oshi-core/src/test/java/oshi/util/gpu/DxgiUtilTest.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
🔇 Additional comments (8)
pom.xml (1)

803-810: Coverage-scope update looks aligned with the stated intent.

Adding benchmark and platform-targeted Unix excludes while keeping shared areas in scope is a good direction for more meaningful JaCoCo reporting.

Also applies to: 815-815

oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java (1)

44-46: Rename is consistent and safe.

Type name, logger binding, and private constructor were updated coherently with no behavioral drift.

Also applies to: 89-89

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java (1)

205-206: ADL backend migration is clean and behavior-preserving.

Delegation to AdlUtilJNA keeps the same availability checks, cached index lookup, and sentinel-based fallback flow.

Also applies to: 225-226, 249-250, 270-271, 291-292, 353-357

oshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.java (1)

13-14: Javadoc reference update is correct.

The link now points to the current DXGI binding entry point.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (1)

140-140: DXGI utility extraction is wired consistently across paths.

All key operations (enumeration, matching, normalization, VRAM conversion) now route through DxgiUtilJNA in both main and fallback flows.

Also applies to: 191-191, 218-219, 264-264, 311-311, 326-327, 365-365

oshi-core/src/test/java/oshi/util/gpu/DxgiUtilTest.java (1)

5-5: Test migration looks complete for the extracted utility API.

The suite now validates DxgiUtilJNA matching, normalization, VRAM conversion, and adapter enumeration behavior.

Also applies to: 23-23, 37-37, 51-51, 64-64, 75-75, 81-81, 92-92, 102-103, 107-108, 112-113, 122-123, 128-129, 135-136, 140-141, 150-150

oshi-core/src/main/java/oshi/jna/platform/windows/Dxgi.java (1)

49-52: Class rename updates are internally consistent.

Dxgi type, logger binding, and constructor naming align cleanly.

Also applies to: 60-60

oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java (1)

18-31: New utility extraction is cohesive and correctly scoped.

The helper methods are cleanly centralized and match how callers/tests now consume DXGI-related logic.

Also applies to: 53-73, 82-97, 105-110

Comment thread pom.xml Resolved
@codecov

codecov Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.11628% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.06%. Comparing base (8fa7005) to head (74de680).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...shi/hardware/platform/windows/WindowsGpuStats.java 0.00% 6 Missing and 1 partial ⚠️
...hardware/platform/windows/WindowsGraphicsCard.java 28.57% 4 Missing and 1 partial ⚠️
...-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java 89.28% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3159      +/-   ##
============================================
- Coverage     56.31%   56.06%   -0.26%     
============================================
  Files           212      362     +150     
  Lines         13491    20222    +6731     
  Branches       2195     3307    +1112     
============================================
+ Hits           7598    11337    +3739     
- Misses         4739     7287    +2548     
- Partials       1154     1598     +444     
Flag Coverage Δ
linux ?
macos ?
macos-latest 27.10% <55.81%> (?)
ubuntu-latest 22.13% <55.81%> (?)
windows ?
windows-latest 26.58% <65.11%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit 6ae3e38 into oshi:master Apr 14, 2026
15 of 17 checks passed
@dbwiddis
dbwiddis deleted the improve-coverage branch April 17, 2026 17:28
@coderabbitai coderabbitai Bot mentioned this pull request Jun 2, 2026
4 tasks done
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.

1 participant