Repository navigation
Add Linux hardware tests; fix sensors fan/voltage discovery bug - #3160
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (3)
📜 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)
🧰 Additional context used🧠 Learnings (9)📚 Learning: 2026-04-08T00:58:10.736ZApplied to files:
📚 Learning: 2026-04-06T04:45:51.516ZApplied to files:
📚 Learning: 2026-04-05T05:40:45.797ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-14T23:28:14.505ZApplied to files:
📚 Learning: 2026-04-11T05:51:49.185ZApplied to files:
📚 Learning: 2026-04-10T22:44:32.055ZApplied to files:
📚 Learning: 2026-04-06T22:30:07.083ZApplied to files:
📚 Learning: 2026-04-05T05:39:21.126ZApplied to files:
🔇 Additional comments (18)
📝 WalkthroughWalkthroughRefactors 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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify 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. Comment |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.
testQueryPowerSourcesdoes not callqueryPowerSources()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
📒 Files selected for processing (8)
CHANGELOG.mdoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxPowerSourceTest.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxPowerSource.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.javaoshi-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.linuxis implementation detail, so this visibility/testability refactor is acceptable.
351-360:readUeventValuevisibility change is well-contained and behavior remains safe.Returning
""when keys/files are absent is consistent and keeps callers resilient.
362-370:readDriverNameremains 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
StubGraphicsCardandAttrsassertions validate the new fields and accessors thoroughly.
60-124:findDrmInfotest 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-basedreadDriverNamebehavior is validated well.Good direct coverage of expected driver-name extraction from the symlink target.
166-176: Fixture helper is concise and readable.
createCardWithDriverkeeps 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 thehwmon00/hwmon01path 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 thegt0path.This mirrors the real
card0/device -> ../gt/gt0layout, 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.
Adds tests for Linux hardware classes using
@TempDirsysfs fixtures, and fixes a latent bug discovered during test development.New Tests
Attrs, constructor/getters,findDrmInfo(PCI slot matching, fallback, no driver),readUeventValue, andreadDriverNameusing temp directories with symlinks.@EnabledOnOs(OS.LINUX)(buildPowerSourceis pure logic). Added copy-constructor test andgetPowerSources(path)tests covering uevent parsing,PropByName.MAP, adapter filtering (ADP/AC/USBC),PRESENT=0skip, and nonexistent/empty directories.Production Code Changes
getPowerSources(String powerSupplyPath)package-private overload; public no-arg method delegates withSysPath.POWER_SUPPLY.findDrmInfo(String pciSlot, String drmPath)package-private overload; makereadUeventValueandreadDriverNamepackage-private.IS_PIwith instance fields set via a new package-private constructor acceptinghwmonBasePath,thermalZoneBasePath, andisPi. No-arg constructor delegates with real values.Bug Fix
LinuxSensors fan/voltage discovery was broken. Inside
populateSensorsMapFromHwmon(), the fan and voltage scan calledgetSensorFilesFromPath(path, ...)wherepathwas the resolved directory (e.g.hwmon0). SincegetSensorFilesFromPathappends0,1, etc. to iterate, it looked forhwmon00,hwmon01— which never exist. Moved the fan/voltage scan outside the while loop and passed the basehwmonPathinstead.Summary by CodeRabbit
Bug Fixes
Improvements
Tests