Repository navigation
Add Linux hardware unit tests and fix parseDecimalMemorySizeToBinary - #3161
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 (13)
✅ Files skipped from review due to trivial changes (6)
🚧 Files skipped from review as they are similar to previous 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). (10)
🧰 Additional context used🧠 Learnings (11)📓 Common learnings📚 Learning: 2026-04-06T04:45:51.516ZApplied to files:
📚 Learning: 2026-04-11T05:51:49.185ZApplied to files:
📚 Learning: 2026-04-05T15:37:17.867ZApplied to files:
📚 Learning: 2026-04-05T05:40:45.797ZApplied to files:
📚 Learning: 2026-04-05T05:39:21.126ZApplied to files:
📚 Learning: 2026-04-06T21:48:11.921ZApplied to files:
📚 Learning: 2026-04-06T22:30:07.083ZApplied to files:
📚 Learning: 2026-04-10T22:44:32.055ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-12T19:34:56.879ZApplied to files:
🔇 Additional comments (13)
📝 WalkthroughWalkthroughParameterize 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
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
🚥 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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (9)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.javaoshi-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
IfOperStatusmappings 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
asoundlayouts.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.
862b85e to
49da383
Compare
There was a problem hiding this comment.
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 intogetSoundCards(...)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
📒 Files selected for processing (10)
CHANGELOG.mdoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSoundCard.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxNetworkIFTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSoundCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxUsbDeviceTest.javaoshi-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 Report❌ Patch coverage is
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
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:
|
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.
49da383 to
23a71d1
Compare
Summary
Add unit tests for Linux hardware classes in
oshi-commonand fix a latent bug inParseUtil.parseDecimalMemorySizeToBinary.Bug Fix
ParseUtil.parseDecimalMemorySizeToBinaryfailed to apply the multiplier for single-character suffixes like"K","M","G","T". The guardmem[1].length() > 1skipped these, so sysfs cache sizes like"32K"parsed to32instead of32768. Changed tomem[1].length() > 0. Bare"B"correctly falls through to thedefaultswitch case with no shift.New Tests
Four new test files using
@TempDirto build synthetic sysfs directory trees, runnable on any platform:createMIDR,getSystemLoadAverage,queryMaxFreqFromCpuFreqPath,readTopologyFromSysfs(including cache parsing),readTopologyFromCpuinfogetCardFolders,getSoundCardVersion,getCardCodec,getCardName,getSoundCardsintegrationqueryIfModelFromSysfs,parseIfOperStatus(all 8 cases)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):
readTopologyFromSysfs(String),readTopologyFromCpuinfo(List<String>),getSystemLoadAverage(int, String);createMIDRnarrowed fromprivateto package-privatefinal;getSoundCards(String),getCardFolders(String),getSoundCardVersion(String),getCardCodec(File),getCardName(File, String)made package-private with path paramsqueryIfModelFromSysfs(String, String)overloadParseUtilTest Additions
Added assertions for single-char suffixes (
"32K","1M","2G","1T") and bare"B"suffix ("32B"→ 32).Summary by CodeRabbit
Bug Fixes
Improvements
Tests
Documentation