Skip to content

Add Linux hardware tests; fix sensors fan/voltage discovery bug - #3160

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:gpu-tests
Apr 15, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:gpu-tests

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

Adds tests for Linux hardware classes using @TempDir sysfs fixtures, and fixes a latent bug discovered during test development.

New Tests

  • LinuxGpuStatsTest — Comprehensive coverage of amdgpu, i915, xe drivers, NVML paths, session lifecycle, and edge cases using stub subclasses and temp directories. Coverage: 0% → ~99% instruction, ~80% branch.
  • LinuxGraphicsCardTest — Tests for Attrs, constructor/getters, findDrmInfo (PCI slot matching, fallback, no driver), readUeventValue, and readDriverName using temp directories with symlinks.
  • LinuxPowerSourceTest — Removed @EnabledOnOs(OS.LINUX) (buildPowerSource is pure logic). Added copy-constructor test and getPowerSources(path) tests covering uevent parsing, PropByName.MAP, adapter filtering (ADP/AC/USBC), PRESENT=0 skip, and nonexistent/empty directories.
  • LinuxSensorsTest — Tests for hwmon temperature discovery (priority selection, temp1 direct read, temp2-6 averaging), thermal_zone fallback and priority, fan speed reading, voltage reading, isPi path, and no-sensors-found.

Production Code Changes

  • LinuxPowerSource: Extract getPowerSources(String powerSupplyPath) package-private overload; public no-arg method delegates with SysPath.POWER_SUPPLY.
  • LinuxGraphicsCard: Extract findDrmInfo(String pciSlot, String drmPath) package-private overload; make readUeventValue and readDriverName package-private.
  • LinuxSensors: Replace static final path constants and IS_PI with instance fields set via a new package-private constructor accepting hwmonBasePath, thermalZoneBasePath, and isPi. No-arg constructor delegates with real values.

Bug Fix

LinuxSensors fan/voltage discovery was broken. Inside populateSensorsMapFromHwmon(), the fan and voltage scan called getSensorFilesFromPath(path, ...) where path was the resolved directory (e.g. hwmon0). Since getSensorFilesFromPath appends 0, 1, etc. to iterate, it looked for hwmon00, hwmon01 — which never exist. Moved the fan/voltage scan outside the while loop and passed the base hwmonPath instead.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Linux sensor fan and voltage discovery logic to correctly locate sensor files.
  • Improvements

    • Made Linux graphics and power-source discovery more configurable to improve detection across environments.
  • Tests

    • Added extensive tests for Linux graphics, GPU stats, power sources, and sensor discovery to increase reliability.

@coderabbitai

coderabbitai Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 784581fe-1089-4f02-a3a6-35fbe49221e9

📥 Commits

Reviewing files that changed from the base of the PR and between c82614b and fb9109c.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
✅ Files skipped from review due to trivial changes (3)
  • CHANGELOG.md
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java
📜 Recent 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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (9)
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
📚 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-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
📚 Learning: 2026-04-14T23:28:14.505Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3160
File: oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java:34-40
Timestamp: 2026-04-14T23:28:14.505Z
Learning: In oshi/oshi, `vcgencmd` (used in `LinuxSensors.queryCpuTemperatureFromVcGenCmd()` and related methods) is a Raspberry Pi-specific binary. It will never be present on standard x86/amd64 CI runners or developer machines. Tests that pass `isPi=true` to `LinuxSensors` and assert 0/empty returns are deterministic in practice; do not flag them as potentially flaky due to `vcgencmd` availability.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.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-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
📚 Learning: 2026-04-10T22:44:32.055Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:32.055Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
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:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
🔇 Additional comments (18)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java (3)

308-309: Good compatibility-preserving delegation.

This keeps existing behavior intact while enabling the new testable path overload cleanly.


318-342: Path-parameterized DRM discovery is solid.

The matching-first/fallback-second flow is clear and handles missing/empty paths safely via the cards == null guard.


351-351: Helper visibility change looks appropriate for package-level tests.

Making these methods package-private is a pragmatic testability improvement without altering functional behavior.

Also applies to: 362-371

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java (2)

85-87: Good delegation to a single source of truth.

Routing the no-arg method through the path overload keeps production behavior intact while making the logic testable.


95-105: Path-parameterized discovery is implemented cleanly.

Using the injected powerSupplyPath for directory scanning and uevent reads is a solid, low-risk refactor for test coverage expansion.

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java (4)

9-25: Test scaffolding imports look appropriate.

The added @TempDir/filesystem/assertion imports match the new fixture-driven test coverage.


217-238: Nice copy-constructor coverage.

This validates that the LinuxPowerSource copy path preserves core battery identity/state fields.


240-292: Great edge-case coverage for getPowerSources(String).

The new tests comprehensively exercise empty/missing paths, adapter filtering, uevent parsing behavior, malformed/unknown keys, and PRESENT=0 skipping.


295-311: Round-trip test is a good regression guard.

The parse-and-copy check helps protect the expected LinuxPowerSource object flow used by this code path.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java (4)

33-33: Good refactoring for testability.

Converting from static constants to instance fields while keeping them final maintains thread safety and enables path injection for testing.

Also applies to: 65-72


82-104: Constructor design enables clean testability.

The delegation pattern keeps the default constructor simple while the explicit-path constructor allows test fixtures. Gating sensor map population on !isPi is correct since Raspberry Pi uses vcgencmd instead of sysfs paths.


145-157: Bug fix correctly addresses the path concatenation issue.

Moving fan/voltage scanning outside the temperature selection loop and using hwmonPath (base path) instead of the resolved path (e.g., hwmon0) fixes the issue where getSensorFilesFromPath would search for non-existent directories like hwmon00/hwmon01 instead of hwmon0/hwmon1.


218-220: Instance field usage is consistent throughout.

All query methods correctly branch on the instance isPi field, maintaining the existing behavior while enabling testability.

Also applies to: 274-274, 302-304

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java (5)

19-31: Good baseline test for empty sensor directories.

Tests graceful handling when neither hwmon nor thermal_zone directories exist, verifying the expected 0/empty defaults.


33-40: Pi fallback path correctly tested.

This test verifies the isPi=true code path returns defaults when vcgencmd is unavailable. Based on learnings, this is deterministic on non-Pi systems.


42-91: Comprehensive hwmon temperature coverage.

Tests thoroughly exercise the temperature selection logic:

  • Direct temp1_input read path
  • Averaging fallback when temp1_input is 0
  • Priority-based sensor selection between multiple hwmon devices
  • Unknown sensor names correctly filtered out

93-140: Thermal zone fallback and priority well tested.

Tests correctly validate:

  • hwmon takes precedence when both sources exist
  • thermal_zone fallback when hwmon has no recognized temperature sensor
  • Priority ordering based on THERMAL_ZONE_TYPE_PRIORITY

142-192: Fan and voltage tests validate the bug fix.

Using nct6775 (not in temperature priority list) correctly isolates fan/voltage testing from temperature selection. These tests effectively validate that the bug fix works—fan and voltage sensors are now correctly discovered from hwmon directories.

The helper methods are clean and follow good test utility patterns.


📝 Walkthrough

Walkthrough

Refactors Linux hardware-detection code for testability: adds parameterized overloads for sysfs base paths, converts LinuxSensors from static to instance-configurable, adjusts helper visibility, and adds comprehensive unit tests for GPUs, graphics cards, power sources, and sensors. CHANGELOG updated with a LinuxSensors fix entry.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added entry under # 6.12.0 (in progress) → ##### Bug fixes / Improvements for PR #3160 documenting a LinuxSensors fan/voltage discovery path fix.
Graphics card platform
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
Added findDrmInfo(String pciSlot, String drmPath) overload and delegated existing method to it; changed readUeventValue and readDriverName from private static to package-visible static.
Power source platform
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
Added package-private overload getPowerSources(String powerSupplyPath) and made getPowerSources() delegate to it (parameterizes Sysfs power-supply base path).
Sensors platform
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
Converted class from final to non-final; replaced static config constants with instance fields (hwmonPath, thermalZonePath, isPi); added constructor LinuxSensors(String, String, boolean); deferred fan/voltage scanning to a separate pass after temperature selection; runtime queries now use instance state.
GPU stats tests
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java
New comprehensive test suite using temp filesystems to validate sysfs parsing, driver-specific parsing (amdgpu/i915/xe), hwmon/dpm fallbacks, NVML fallback and caching, and resource cleanup behavior.
Graphics card tests
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
New tests for DRM discovery, driver symlink resolution, pci-slot matching, and helpers (readUeventValue, readDriverName) using @TempDir fixtures.
Power source tests
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
Removed OS gating; added copy-constructor test and multiple getPowerSources(...) tests covering nonexistent/empty dirs, filtering (ADP/AC/USBC), uevent parsing, and POWER_SUPPLY_PRESENT filtering.
Sensors tests
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
New tests covering hwmon and thermal_zone discovery/parsing, Pi-mode behavior, temperature averaging/priority, fan and voltage extraction, and helper fixtures for hwmon layouts.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰
I hopped through hwmon paths and dots,
swapped static maps for tiny slots,
temp dirs bloomed where tests now play,
fans and volts found their new way,
a little rabbit cheers the day! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.69% 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 describes both the main addition (Linux hardware tests) and the key bug fix (sensors fan/voltage discovery), reflecting the primary objectives of the PR.

✏️ 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.

@codecov

codecov Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.51%. Comparing base (6ae3e38) to head (fb9109c).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...i/hardware/common/platform/linux/LinuxSensors.java 70.00% 2 Missing and 4 partials ⚠️
...dware/common/platform/linux/LinuxGraphicsCard.java 50.00% 1 Missing ⚠️
...rdware/common/platform/linux/LinuxPowerSource.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3160      +/-   ##
==========================================
+ Coverage   56.15%   57.51%   +1.35%     
==========================================
  Files         362      362              
  Lines       20222    20226       +4     
  Branches     3307     3306       -1     
==========================================
+ Hits        11356    11632     +276     
+ Misses       7270     6972     -298     
- Partials     1596     1622      +26     
Flag Coverage Δ
linux ?
macos ?
macos-latest 29.16% <64.00%> (?)
ubuntu-latest 23.50% <68.00%> (?)
windows ?
windows-latest 28.47% <64.00%> (?)

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.

@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: 4

🧹 Nitpick comments (2)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java (1)

61-63: Prefer temp-dir-relative missing paths over hard-coded /nonexistent/....

Using tempDir.resolve("does-not-exist") would make these tests fully environment-independent while preserving intent.

Also applies to: 137-139

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java`
around lines 61 - 63, Replace hard-coded missing paths with a temp-dir-relative
path: in the test method testFindDrmInfoNonexistentPath (and the similar test
around lines 137-139), add a JUnit `@TempDir` Path parameter (e.g., Path tempDir)
and call LinuxGraphicsCard.findDrmInfo("01:00.0",
tempDir.resolve("does-not-exist").toString()) instead of using
"/nonexistent/drm" so the tests are environment-independent.
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java (1)

295-311: Test name is slightly misleading for current behavior.

testQueryPowerSources does not call queryPowerSources() directly; consider renaming to reflect what is actually exercised.

Suggested rename
-    void testQueryPowerSources(`@TempDir` Path tempDir) throws IOException {
+    void testGetPowerSourcesAndCopyRoundTrip(`@TempDir` Path tempDir) throws IOException {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java`
around lines 295 - 311, The test method name testQueryPowerSources is misleading
because it does not call queryPowerSources() but instead invokes
LinuxPowerSource.getPowerSources(...) and verifies the copy constructor (new
LinuxPowerSource(ps)); rename the test to something descriptive (e.g.,
testGetPowerSourcesAndCopyConstructorRoundTrip or
testGetPowerSourcesCopyRoundTrip) and update any references/annotations
accordingly so the name accurately reflects that it exercises
LinuxPowerSource.getPowerSources and the copy constructor.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java`:
- Around line 396-404: The test testNvmlUnavailableCachesResult currently cannot
detect whether caching occurred because StubLinuxGpuStats.findNvmlDevice()
always returns the same constant; update the stub so it records invocations
(e.g., add a callCount field on StubLinuxGpuStats and increment it inside the
stubbed resolution used by findNvmlDevice()) or change the stub to return a
different value after the first lookup, then assert the callCount remains 1 (or
the second return equals the first cached value) to prove the cache was hit;
apply the same change to the other affected test (the one around lines 499-505)
so both tests verify the cache behavior rather than just equal returns.
- Around line 509-557: The test testNvmlFallbackToNameLookup() currently passes
an empty pciBusId so findNvmlDevice() never exercises the nvmlFindDevice(...)
branch; change the first ctor argument from "" to a non-empty bus id (e.g.,
"0000:01:00.0") and keep nvmlFindDevice(...) returning null so that
LinuxGpuStats.findNvmlDevice() first calls nvmlFindDevice(deviceBusId) (which
fails) and then falls back to nvmlFindDeviceByName(name) returning
"nvml-by-name"; update only the test instantiation in LinuxGpuStatsTest to use a
non-empty bus id while leaving nvmlFindDeviceByName(...) and assertions
unchanged.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java`:
- Around line 240-244: The test method testGetPowerSourcesNonexistentPath should
not use a hard-coded absolute path; instead, use JUnit's `@TempDir` to create a
guaranteed-missing path and pass that to LinuxPowerSource.getPowerSources.
Modify LinuxPowerSourceTest.testGetPowerSourcesNonexistentPath to accept a Path
tempDir (annotated with `@TempDir`), resolve a child directory/file name that is
not created (e.g., tempDir.resolve("power_supply_missing")), convert to string,
and call LinuxPowerSource.getPowerSources(...) with that path, then assert the
result has size 0.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java`:
- Around line 34-40: The test assumes vcgencmd is missing but can be present on
CI; make it deterministic by ensuring vcgencmd cannot be found before creating
the LinuxSensors instance in testIsPiReturnsDefaults: save the current PATH env,
set PATH to an empty or clearly-invalid value (so executing "vcgencmd" will
fail), construct LinuxSensors("/nonexistent/hwmon", "/nonexistent/thermal_zone",
true), run the assertions, then restore the original PATH; this guarantees
queryCpuTemperature(), queryFanSpeeds(), and queryCpuVoltage() return the
expected defaults regardless of host.

---

Nitpick comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java`:
- Around line 61-63: Replace hard-coded missing paths with a temp-dir-relative
path: in the test method testFindDrmInfoNonexistentPath (and the similar test
around lines 137-139), add a JUnit `@TempDir` Path parameter (e.g., Path tempDir)
and call LinuxGraphicsCard.findDrmInfo("01:00.0",
tempDir.resolve("does-not-exist").toString()) instead of using
"/nonexistent/drm" so the tests are environment-independent.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java`:
- Around line 295-311: The test method name testQueryPowerSources is misleading
because it does not call queryPowerSources() but instead invokes
LinuxPowerSource.getPowerSources(...) and verifies the copy constructor (new
LinuxPowerSource(ps)); rename the test to something descriptive (e.g.,
testGetPowerSourcesAndCopyConstructorRoundTrip or
testGetPowerSourcesCopyRoundTrip) and update any references/annotations
accordingly so the name accurately reflects that it exercises
LinuxPowerSource.getPowerSources and the copy constructor.
🪄 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: 523e1e53-00c6-43e6-a152-f234b59aeda3

📥 Commits

Reviewing files that changed from the base of the PR and between 6ae3e38 and c82614b.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
📜 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). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
📚 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-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.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: For OSHI Linux GPU stats implementations (e.g., LinuxGpuStats and its LinuxGpuStatsJNA/LinuxGpuStatsFFM subclasses), treat NVML "nvml*" methods (such as nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) as having a documented failure sentinel: they are contractually expected to return -1 (long/double) on failure. The base class/implementations should use guards like `if (val >= 0)` before consuming NVML results and should fall back to sysfs/hwmon paths when the value is negative. In review, do not flag subclass pass-through of the -1 sentinel as a missing clamp/contract violation; only flag issues if the -1 sentinel is altered or NVML failure results are used without the expected `>= 0` guard or fallback behavior.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java
🔇 Additional comments (14)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java (3)

307-319: Good refactor: default path behavior is preserved while enabling injectable test paths.

The overload on Line 318 keeps production behavior intact through the delegating call on Line 308 and improves testability cleanly.

Based on learnings: platform-specific code under oshi.hardware.common.platform.linux is implementation detail, so this visibility/testability refactor is acceptable.


351-360: readUeventValue visibility change is well-contained and behavior remains safe.

Returning "" when keys/files are absent is consistent and keeps callers resilient.


362-370: readDriverName remains robust after making it package-visible.

The null/empty symlink-target guard and filename extraction logic are solid.

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java (4)

32-58: Constructor/getter coverage is clear and complete.

The StubGraphicsCard and Attrs assertions validate the new fields and accessors thoroughly.


60-124: findDrmInfo test matrix is excellent.

This set hits the key discovery paths (match, fallback, null-slot, empty/missing cases, and non-card directory filtering).


142-150: Symlink-based readDriverName behavior is validated well.

Good direct coverage of expected driver-name extraction from the symlink target.


166-176: Fixture helper is concise and readable.

createCardWithDriver keeps setup logic centralized and makes the test cases easier to maintain.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.java (1)

85-106: Clean delegation and testability seam without behavior drift.

The no-arg method now cleanly delegates to the path-based overload, and the new overload preserves existing filtering/parsing behavior while enabling filesystem-driven tests.

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.java (2)

217-238: Strong copy-constructor coverage.

This validates a broad field-preservation round trip and materially protects against regressions in LinuxPowerSource(LinuxPowerSource src).


246-292: Good filesystem-path parsing coverage.

These cases cover empty dirs, adapter filtering, uevent parsing robustness, and PRESENT=0 exclusion well.

CHANGELOG.md (1)

29-29: Changelog note is accurate and well-scoped.

This entry clearly documents the LinuxSensors fan/voltage path fix and maps cleanly to the implementation changes.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java (1)

146-157: Fan/voltage discovery fix looks correct.

Scanning from hwmonPath (base prefix) instead of the resolved per-device directory fixes the hwmon00/hwmon01 path construction bug.

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java (1)

42-193: Excellent scenario coverage for sensor selection and parsing paths.

The suite gives strong confidence in hwmon/thermal priority logic and the fan/voltage discovery behavior introduced by this PR.

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java (1)

306-322: Nice production-shaped fixture for the gt0 path.

This mirrors the real card0/device -> ../gt/gt0 layout, so the i915/xe tests exercise the same relative-path construction as production instead of a flattened temp-dir shortcut.

New tests for LinuxGpuStats, LinuxGraphicsCard, LinuxPowerSource, and
LinuxSensors using temp sysfs directories. Tests run on all platforms
without requiring Linux.

Refactor LinuxPowerSource.getPowerSources to accept a path parameter,
LinuxGraphicsCard.findDrmInfo to accept a DRM path parameter, and
LinuxSensors to accept hwmon/thermal paths via constructor injection.

Remove @EnabledOnOs(OS.LINUX) from LinuxPowerSourceTest since
buildPowerSource is pure logic.

Fix bug in LinuxSensors where fan and voltage sensor discovery passed
the resolved hwmon path (e.g. hwmon0) instead of the base path (hwmon)
to getSensorFilesFromPath, causing the iteration to look for hwmon00,
hwmon01, etc. which never exist.
@dbwiddis
dbwiddis merged commit 6d8020b into oshi:master Apr 15, 2026
14 of 16 checks passed
@dbwiddis
dbwiddis deleted the gpu-tests branch April 15, 2026 00:08
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