Skip to content

Add Linux hardware unit tests and fix parseDecimalMemorySizeToBinary - #3161

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:linux-hw-tests-2
Apr 15, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:linux-hw-tests-2

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Add unit tests for Linux hardware classes in oshi-common and fix a latent bug in ParseUtil.parseDecimalMemorySizeToBinary.

Bug Fix

ParseUtil.parseDecimalMemorySizeToBinary failed to apply the multiplier for single-character suffixes like "K", "M", "G", "T". The guard mem[1].length() > 1 skipped these, so sysfs cache sizes like "32K" parsed to 32 instead of 32768. Changed to mem[1].length() > 0. Bare "B" correctly falls through to the default switch case with no shift.

New Tests

Four new test files using @TempDir to build synthetic sysfs directory trees, runnable on any platform:

  • LinuxCentralProcessorTest — createMIDR, getSystemLoadAverage, queryMaxFreqFromCpuFreqPath, readTopologyFromSysfs (including cache parsing), readTopologyFromCpuinfo
  • LinuxSoundCardTest — getCardFolders, getSoundCardVersion, getCardCodec, getCardName, getSoundCards integration
  • LinuxNetworkIFTest — queryIfModelFromSysfs, parseIfOperStatus (all 8 cases)
  • LinuxUsbDeviceTest — getDeviceAndChildren (leaf, fallback vid/pid, hub with sorted children, nested hierarchy)

Source Changes

Extracted testable package-private overloads with path parameters (original methods delegate to them):

  • LinuxCentralProcessor: readTopologyFromSysfs(String), readTopologyFromCpuinfo(List<String>), getSystemLoadAverage(int, String); createMIDR narrowed from private to package-private
  • LinuxSoundCard: Removed final; getSoundCards(String), getCardFolders(String), getSoundCardVersion(String), getCardCodec(File), getCardName(File, String) made package-private with path params
  • LinuxNetworkIF: queryIfModelFromSysfs(String, String) overload

ParseUtilTest Additions

Added assertions for single-char suffixes ("32K", "1M", "2G", "1T") and bare "B" suffix ("32B" → 32).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed memory-size parsing to correctly handle single-character unit suffixes (e.g., "32K", "1M").
  • Improvements

    • More robust Linux hardware and load-average parsing with improved path handling and fallback behavior.
    • Enhanced network interface model and sound-card discovery reliability and flexibility.
  • Tests

    • Added extensive Linux unit tests for CPU, networking, sound, USB, parsing, and shared test utilities.
  • Documentation

    • Added changelog entry for Linux-related updates.

@coderabbitai

coderabbitai Bot commented Apr 15, 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: d51514a4-2c2e-4484-9152-d7adf0a6ca8b

📥 Commits

Reviewing files that changed from the base of the PR and between 49da383 and 23a71d1.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGpuStatsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/TestFileUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
✅ Files skipped from review due to trivial changes (6)
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/TestFileUtil.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.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). (10)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
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.
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.
📚 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/LinuxGpuStatsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.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
📚 Learning: 2026-04-05T15:37:17.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:17.867Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.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/LinuxUsbDeviceTest.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/LinuxUsbDeviceTest.java
📚 Learning: 2026-04-06T21:48:11.921Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:85-111
Timestamp: 2026-04-06T21:48:11.921Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` (and `MacUsbDeviceFFM.java`), the `id = 0L` sentinel is intentional when `device.getParentEntry(IOSERVICE)` returns null. It acts as a catch-all controller group for devices whose controller cannot be identified (an edge case that "should never happen" given the IORegistry format). Do not flag this as a bug or suggest skipping such devices; the design intentionally avoids both silently dropping orphaned devices and placing them at the top level without a controller context.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.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/LinuxUsbDeviceTest.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/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.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/LinuxCentralProcessor.java
📚 Learning: 2026-04-12T19:34:56.879Z
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:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
🔇 Additional comments (13)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java (1)

10-10: Shared fixture-writer import is a clean improvement.

Switching to TestFileUtil.writeFile removes duplicate test utility logic while preserving test intent.

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

11-11: Good consolidation to shared test file utility.

Using TestFileUtil.writeFile here improves maintainability and keeps fixtures consistent across Linux hardware tests.

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

28-52: Strong leaf-device coverage and assertions.

This test validates all key leaf fields (name, vendor, IDs, serial, unique ID) and confirms empty child topology for non-hub devices.


58-71: Fallback VID/PID behavior is well-tested.

Good targeted coverage for inherited parent IDs and default/fallback string fields when maps are missing entries.


77-105: Great deterministic ordering check for hub children.

Asserting sorted child names here is valuable and prevents nondeterministic traversal regressions.


111-137: Nested hierarchy recursion is validated clearly.

This test gives solid confidence in multi-level topology construction and child chaining.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java (7)

207-212: Good delegation split for sysfs topology parsing.

The zero-arg method delegating to a path-injectable overload is clean and improves testability without altering runtime behavior.


218-232: Path-parameterized sysfs scan and logging look correct.

Using cpuPath in both traversal and warning output makes failures easier to diagnose in tests and production.


248-259: Nice path construction hardening with Paths.get(...).

The node/cache/index prefix construction is clearer and avoids manual separator handling.


282-287: Cpuinfo parsing overload is well-structured for unit tests.

Delegating from file-backed input to a List<String> parser keeps behavior centralized and easy to test.


494-505: policy prefix normalization via Paths.get is a good update.

This keeps prefix matching aligned with the provided base path format.


513-523: Load-average overload extraction is clean and test-friendly.

Injecting raw loadavg content while preserving the public method behavior is a solid improvement.


612-612: createMIDR package-private visibility is appropriate here.

This is a pragmatic testability change in a platform-specific implementation class.

Based on learnings: In the oshi/oshi project, platform-specific subpackages are implementation details and not public API surface.


📝 Walkthrough

Walkthrough

Parameterize sysfs/proc paths and expose package-private helpers across several Linux platform classes, relax LinuxSoundCard finality, adjust ParseUtil single-character unit parsing, change createMIDR visibility, update path joins, and add comprehensive JUnit 5 tests for CPU, network, sound, USB, and parsing utilities.

Changes

Cohort / File(s) Summary
Linux CPU / Topology / Load
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
Added overloads readTopologyFromSysfs(String) and readTopologyFromCpuinfo(List<String>); getSystemLoadAverage now has getSystemLoadAverage(int, String) overload; createMIDR visibility relaxed to package-private; sysfs path concatenation updated to use Paths.get.
Linux Network Interface
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
Added queryIfModelFromSysfs(String name, String netPath) and made existing method delegate to it, enabling custom netPath for uevent reading.
Linux Sound Card
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java
Removed final modifier; helpers parameterized to accept asoundPath; helper visibility widened to package-private; added getSoundCards(String asoundPath) overload and made public method delegate to it.
Parsing Utility
oshi-common/src/main/java/oshi/util/ParseUtil.java
parseDecimalMemorySizeToBinary adjusted to accept single-character unit tokens (guard now allows length > 0).
Tests — LinuxCentralProcessor
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
New tests for MIDR formatting, load-average parsing, cpufreq detection, sysfs topology parsing, and cpuinfo parsing using temporary sysfs-like fixtures.
Tests — LinuxNetworkIF
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.java
New tests for queryIfModelFromSysfs with uevent fixtures and for IfOperStatus parsing.
Tests — LinuxSoundCard
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java
New tests validating card folder discovery, version/codec/name parsing, and integration-style sound card discovery using temp asound trees.
Tests — LinuxUsbDevice
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.java
New tests for getDeviceAndChildren covering leaf devices, VID/PID inheritance, hub children ordering, and nested hub hierarchies.
Tests — ParseUtil
oshi-common/src/test/java/oshi/util/ParseUtilTest.java
Added assertions for single-character suffix parsing (K/M/G/T) and bare B suffix behavior.
Test Utilities
oshi-common/src/test/java/oshi/hardware/common/platform/linux/TestFileUtil.java
Added shared writeFile(Path,String) helper; tests updated to use it.
Docs
CHANGELOG.md
Added entry under 6.12.0 noting Linux hardware tests and parsing/path handling updates.

Sequence Diagram(s)

(Skipped — changes are refactors, helpers, and tests; no new multi-component runtime control flow requiring a sequence diagram.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through /sys and /proc tonight,
Paths now flexible, tests gleam bright,
MIDR in caps, units parse with care,
Sound, net, USB—each revealed there,
Tiny rabbit cheers — hop, test, delight! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.53% 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 summarizes the two main changes: adding Linux hardware unit tests and fixing a bug in parseDecimalMemorySizeToBinary, which are 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.

@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

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

191-194: Consider centralizing the repeated file-fixture helper.

writeFile(Path, String) is effectively duplicated across multiple new Linux test classes; extracting a shared test utility would reduce repetition.

🤖 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/LinuxSoundCardTest.java`
around lines 191 - 194, The test helper method writeFile(Path, String) is
duplicated across Linux test classes—extract it into a shared test utility
(e.g., a new TestFileHelpers class with a public static writeFile(Path, String)
or writeFile(Path, String, Charset)) and replace the per-class implementations
with calls to that shared method; ensure you preserve behavior (create parent
directories and write UTF-8) and update imports/usages in classes that currently
define writeFile(Path, String).
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java (1)

151-155: Hoist driver version lookup out of the card loop.

getSoundCardVersion(asoundPath) is loop-invariant; reading it once reduces redundant file I/O.

Proposed refactor
 static List<SoundCard> getSoundCards(String asoundPath) {
     List<SoundCard> soundCards = new ArrayList<>();
+    String driverVersion = getSoundCardVersion(asoundPath);
     for (File cardFile : getCardFolders(asoundPath)) {
-        soundCards.add(new LinuxSoundCard(getSoundCardVersion(asoundPath), getCardName(cardFile, asoundPath),
+        soundCards.add(new LinuxSoundCard(driverVersion, getCardName(cardFile, asoundPath),
                 getCardCodec(cardFile)));
     }
     return soundCards;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java`
around lines 151 - 155, The loop in getSoundCards currently calls
getSoundCardVersion(asoundPath) on every iteration; hoist this loop-invariant by
calling getSoundCardVersion(asoundPath) once before the for-loop, store the
result in a local variable (e.g., soundCardVersion), and use that variable when
constructing new LinuxSoundCard instances; update getSoundCards to use
soundCardVersion with getCardName(cardFile, asoundPath) and
getCardCodec(cardFile) to avoid redundant file I/O.
🤖 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/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java`:
- Line 75: The code in LinuxSoundCard uses string concatenation to build file
paths (e.g., calling FileUtil.getStringFromFile(asoundPath + "version")), which
fails if asoundPath lacks a trailing separator; update the path construction to
use a filesystem-safe join (for example, Paths.get(asoundPath,
"version").toString() or new File(asoundPath, "version").getPath()) wherever
FileUtil.getStringFromFile is invoked with concatenated paths (e.g., in the
LinuxSoundCard class referencing asoundPath for "version" and the other
occurrence), replacing the string concatenation with the safe join call.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java`:
- Around line 151-155: The loop in getSoundCards currently calls
getSoundCardVersion(asoundPath) on every iteration; hoist this loop-invariant by
calling getSoundCardVersion(asoundPath) once before the for-loop, store the
result in a local variable (e.g., soundCardVersion), and use that variable when
constructing new LinuxSoundCard instances; update getSoundCards to use
soundCardVersion with getCardName(cardFile, asoundPath) and
getCardCodec(cardFile) to avoid redundant file I/O.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java`:
- Around line 191-194: The test helper method writeFile(Path, String) is
duplicated across Linux test classes—extract it into a shared test utility
(e.g., a new TestFileHelpers class with a public static writeFile(Path, String)
or writeFile(Path, String, Charset)) and replace the per-class implementations
with calls to that shared method; ensure you preserve behavior (create parent
directories and write UTF-8) and update imports/usages in classes that currently
define writeFile(Path, String).
🪄 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: 9c6c4f23-f06f-4847-9f3b-c48f3f79eef4

📥 Commits

Reviewing files that changed from the base of the PR and between 6d8020b and 862b85e.

📒 Files selected for processing (9)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.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). (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (9)
📚 Learning: 2026-04-05T15:37:17.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:17.867Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.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/LinuxUsbDeviceTest.java
📚 Learning: 2026-04-06T21:48:11.921Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:85-111
Timestamp: 2026-04-06T21:48:11.921Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` (and `MacUsbDeviceFFM.java`), the `id = 0L` sentinel is intentional when `device.getParentEntry(IOSERVICE)` returns null. It acts as a catch-all controller group for devices whose controller cannot be identified (an edge case that "should never happen" given the IORegistry format). Do not flag this as a bug or suggest skipping such devices; the design intentionally avoids both silently dropping orphaned devices and placing them at the top level without a controller context.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.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/LinuxUsbDeviceTest.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/LinuxUsbDeviceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.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/LinuxUsbDeviceTest.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/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.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/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
📚 Learning: 2026-04-12T19:34:56.879Z
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:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
🔇 Additional comments (9)
oshi-common/src/main/java/oshi/util/ParseUtil.java (1)

998-999: Single-character unit parsing fix looks correct.

This change correctly allows "K", "M", "G", and "T" suffixes to be shifted, while "B" still falls through to no multiplier.

oshi-common/src/test/java/oshi/util/ParseUtilTest.java (1)

523-529: Nice targeted regression coverage.

These assertions directly validate the suffix parsing edge case and protect the "B" fallback behavior.

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

28-137: Strong coverage of USB topology construction paths.

Leaf, fallback inheritance, sorted children, and nested recursion are all exercised with clear assertions.

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

49-64: Good testability refactor with behavior preserved.

Delegating through the new overload keeps runtime behavior intact while enabling path-injected unit tests.

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

26-118: Comprehensive unit coverage for both new and existing branches.

The uevent parsing fallback cases and all IfOperStatus mappings are well exercised.

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

207-214: Well-structured extraction for testability without semantic drift.

The delegating wrappers keep existing entrypoints stable, and the new overloads make topology/loadavg parsing easy to test in isolation.

Also applies to: 282-287, 513-527, 612-613

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

30-183: Great end-to-end coverage of Linux sound-card parsing paths.

The suite validates both low-level parsers and integration behavior against realistic synthetic asound layouts.

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

38-285: Excellent focused coverage for the new CPU test seams.

The cases validate core parsing behavior across MIDR, load averages, cpufreq fallback, sysfs topology, and cpuinfo topology variants.

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

148-149: Good delegation preserves behavior while enabling test seams.

Keeping getSoundCards() as the production entrypoint and delegating to the path-aware overload is a clean testability improvement.

@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

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

168-173: Expand integration assertion to include resolved sound card name.

This integration test is a good place to verify getCardName(...) is correctly wired into getSoundCards(...) end-to-end.

Suggested additional assertion
         SoundCard sc = cards.get(0);
         assertThat(sc.getDriverVersion(), is("ALSA v1.2.6"));
+        assertThat(sc.getName(), is("HDA-Intel - HDA Intel PCH"));
         assertThat(sc.getCodec(), is("ALC892"));
🤖 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/LinuxSoundCardTest.java`
around lines 168 - 173, The test is missing an assertion that verifies
getCardName(...) is wired into LinuxSoundCard.getSoundCards(...) end-to-end;
update the test in LinuxSoundCardTest to assert the resolved card name on the
returned SoundCard (use cards.get(0).getName() or the specific accessor
getCardName/getName available on SoundCard) equals the expected string for the
fixture (the same expected value used for driverVersion/codec), so add a single
assert that checks the card name matches the expected resolved name.

54-56: Strengthen folder-filter assertions beyond count-only checks.

At Line 55, hasSize(2) can still pass if the wrong two directories are returned. Assert the actual folder names to avoid false positives.

Suggested assertion upgrade
         List<File> folders = LinuxSoundCard.getCardFolders(asound.toString());
         assertThat(folders, hasSize(2));
+        assertThat(folders.stream().map(File::getName).toArray(String[]::new),
+                org.hamcrest.Matchers.containsInAnyOrder("card0", "card1"));
🤖 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/LinuxSoundCardTest.java`
around lines 54 - 56, The test in LinuxSoundCardTest currently only asserts the
count returned by LinuxSoundCard.getCardFolders(asound.toString()) which can
hide wrong entries; update the assertion to verify the actual folder names
(e.g., map folders to their names) and assert those names equal the expected set
using a matcher like containsInAnyOrder or an exact list comparison so the test
fails if wrong directories are returned.
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java (1)

159-163: Consider asserting full empty topology tuple on missing sysfs path.

Line [162] currently checks only logical processors. Adding emptiness checks for caches, efficiency map, and modalias map would make this test more regression-resistant.

Suggested enhancement
         assertThat(result.getA(), is(empty()));
+        assertThat(result.getB(), is(empty()));
+        assertThat(result.getC(), is(Collections.emptyMap()));
+        assertThat(result.getD(), is(Collections.emptyMap()));
🤖 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/LinuxCentralProcessorTest.java`
around lines 159 - 163, The test testReadTopologyFromSysfsNonexistentPath
currently asserts only that logical processors are empty; update it to assert
that the entire Quartet returned by LinuxCentralProcessor.readTopologyFromSysfs
(i.e., result.getA(), result.getB(), result.getC(), and result.getD()) are all
empty to ensure caches, the efficiency map and modalias map are also empty when
the sysfs path is missing; locate the call in
testReadTopologyFromSysfsNonexistentPath and add assertions for
result.getB().isEmpty(), result.getC().isEmpty(), and result.getD().isEmpty()
(or equivalent hamcrest/AssertJ empty checks) to make the test fully validate an
empty topology.
🤖 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/LinuxCentralProcessorTest.java`:
- Line 61: The inline comment in testCreateMIDRNoStepping incorrectly shows the
composed MIDR hex as 0x41080030 while the assertion expects 0x4108D030; update
the comment in the testCreateMIDRNoStepping method to reflect the correct
composition (e.g., show how 0x41 << 24 + 8 << 16 + 0xd03 << 4 results in
0x4108D030) so the comment matches the asserted value.

---

Nitpick comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java`:
- Around line 159-163: The test testReadTopologyFromSysfsNonexistentPath
currently asserts only that logical processors are empty; update it to assert
that the entire Quartet returned by LinuxCentralProcessor.readTopologyFromSysfs
(i.e., result.getA(), result.getB(), result.getC(), and result.getD()) are all
empty to ensure caches, the efficiency map and modalias map are also empty when
the sysfs path is missing; locate the call in
testReadTopologyFromSysfsNonexistentPath and add assertions for
result.getB().isEmpty(), result.getC().isEmpty(), and result.getD().isEmpty()
(or equivalent hamcrest/AssertJ empty checks) to make the test fully validate an
empty topology.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java`:
- Around line 168-173: The test is missing an assertion that verifies
getCardName(...) is wired into LinuxSoundCard.getSoundCards(...) end-to-end;
update the test in LinuxSoundCardTest to assert the resolved card name on the
returned SoundCard (use cards.get(0).getName() or the specific accessor
getCardName/getName available on SoundCard) equals the expected string for the
fixture (the same expected value used for driverVersion/codec), so add a single
assert that checks the card name matches the expected resolved name.
- Around line 54-56: The test in LinuxSoundCardTest currently only asserts the
count returned by LinuxSoundCard.getCardFolders(asound.toString()) which can
hide wrong entries; update the assertion to verify the actual folder names
(e.g., map folders to their names) and assert those names equal the expected set
using a matcher like containsInAnyOrder or an exact list comparison so the test
fails if wrong directories are returned.
🪄 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: 96485d5f-02cf-44ae-8a63-c3dbdc04874b

📥 Commits

Reviewing files that changed from the base of the PR and between 862b85e and 49da383.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
✅ Files skipped from review due to trivial changes (4)
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • CHANGELOG.md
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.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 25, windows-latest (+ JNA==FFM)
  • 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, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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.
📚 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/LinuxCentralProcessorTest.java
🔇 Additional comments (3)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.java (1)

82-121: Codec parsing coverage is well-structured and comprehensive.

The file-based codec path, codec-subdirectory path, and empty/no-codec fallbacks are all exercised cleanly.

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

38-55: Good MIDR coverage across normal, missing-stepping, and zero-value inputs.

These cases validate both formatting and bit-field composition paths effectively.

Also applies to: 57-69


75-104: Solid edge-case and fallback-path test design overall.

The suite meaningfully exercises parsing boundaries, sysfs/proc synthetic inputs, and frequency fallback behavior with deterministic temp fixtures.

Also applies to: 110-152, 166-235, 241-285, 294-297

@codecov

codecov Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.33%. Comparing base (6d8020b) to head (23a71d1).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...e/common/platform/linux/LinuxCentralProcessor.java 70.00% 3 Missing ⚠️
...hardware/common/platform/linux/LinuxNetworkIF.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3161      +/-   ##
==========================================
+ Coverage   57.59%   58.33%   +0.73%     
==========================================
  Files         362      362              
  Lines       20226    20231       +5     
  Branches     3306     3306              
==========================================
+ Hits        11650    11801     +151     
+ Misses       6964     6806     -158     
- Partials     1612     1624      +12     
Flag Coverage Δ
linux ?
macos ?
macos-latest 30.02% <76.19%> (?)
ubuntu-latest 24.41% <80.95%> (?)
windows ?
windows-latest 29.36% <76.19%> (?)

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.

Add unit tests for LinuxCentralProcessor, LinuxSoundCard,
LinuxNetworkIF,
and LinuxUsbDevice using @tempdir to create synthetic sysfs trees.

Extract testable overloads with path parameters from
LinuxCentralProcessor
(readTopologyFromSysfs, readTopologyFromCpuinfo, getSystemLoadAverage),
LinuxSoundCard (getSoundCards, getCardFolders, getSoundCardVersion,
getCardCodec, getCardName), and LinuxNetworkIF (queryIfModelFromSysfs).

Fix ParseUtil.parseDecimalMemorySizeToBinary to handle single-char
suffixes like "K", "M", "G", "T" (e.g. sysfs cache size "32K").
The length() > 1 guard skipped these; changed to length() > 0.
@dbwiddis
dbwiddis merged commit 1964f5d into oshi:master Apr 15, 2026
15 of 17 checks passed
@dbwiddis
dbwiddis deleted the linux-hw-tests-2 branch April 15, 2026 02:09
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