Repository navigation
Extract /proc/[pid]/stat parsing and add LinuxFileSystem tests - #3205
Conversation
- LinuxOperatingSystem.getParentPidFromStat(String): extracted from getParentPidFromProcFile(), also fixed to use ProcPath.PID_STAT instead of hardcoded /proc path - LinuxFileSystemTest: Linux-only integration test verifying mount parsing returns root filesystem with expected properties Tests cover stat line parsing (standard, init, empty, comm with spaces) and filesystem mount parsing (root present, local-only filtering). No public API changes.
📝 WalkthroughWalkthroughRefactors parent-PID extraction in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3205 +/- ##
==========================================
+ Coverage 59.02% 59.11% +0.08%
==========================================
Files 421 421
Lines 20358 20358
Branches 3576 3575 -1
==========================================
+ Hits 12017 12035 +18
+ Misses 6583 6571 -12
+ Partials 1758 1752 -6
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@oshi-common/src/test/java/oshi/software/common/os/linux/LinuxFileSystemTest.java`:
- Around line 55-62: Replace the weak size-only check in
testGetFileStoresLocalOnly with assertions that verify the filter actually
selects a subset of mounts: call StubLinuxFileSystem.getFileStoreMatching(null,
Collections.emptyMap(), false) and getFileStoreMatching(..., true) as before,
then assert that every OSFileStore in local is contained in all (e.g., assert
that all containsAll local) to prove locality is a subset, and also assert that
the two lists are not equal when the StubLinuxFileSystem returns at least one
non-local mount (i.e., assertThat(all, is(not(local)))) so the test fails if
localOnly is ignored. Ensure you reference StubLinuxFileSystem and
getFileStoreMatching in the assertions.
🪄 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: e5d71985-5baf-43ad-ad5c-8c4a293c0e16
📒 Files selected for processing (3)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.javaoshi-common/src/test/java/oshi/software/common/os/linux/LinuxFileSystemTest.javaoshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.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 21, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (4)
📚 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/software/common/os/linux/LinuxFileSystemTest.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/software/common/os/linux/LinuxFileSystemTest.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-common/src/test/java/oshi/software/common/os/linux/LinuxFileSystemTest.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/software/common/os/linux/LinuxOperatingSystem.java
🔇 Additional comments (3)
oshi-common/src/test/java/oshi/software/common/os/linux/LinuxFileSystemTest.java (1)
34-53: Good coverage for the root mount path.This test exercises the real Linux mount parsing path and verifies the root store's mount, type, and space metadata without relying on a hardcoded fixture.
oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java (1)
90-117: Good coverage for the new stat parser.These cases hit the important edge conditions here: a normal PPID, PID 1 returning
0, empty input, andcommvalues with spaces/parentheses.oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java (1)
193-198: No null check needed here.FileUtil.getStringFromFile()returns an empty string (not null) on failure, and your empty-string check on line 194 already handles that case. The implementation is safe as-is.> Likely an incorrect or invalid review comment.
| @Test | ||
| void testGetFileStoresLocalOnly() { | ||
| StubLinuxFileSystem fs = new StubLinuxFileSystem(); | ||
| List<OSFileStore> all = fs.getFileStoreMatching(null, Collections.emptyMap(), false); | ||
| List<OSFileStore> local = fs.getFileStoreMatching(null, Collections.emptyMap(), true); | ||
| // Local should be a subset of all | ||
| assertThat(local.size(), is(not(greaterThan(all.size())))); | ||
| } |
There was a problem hiding this comment.
Strengthen the localOnly assertion.
This only compares list sizes, so it still passes if localOnly is ignored or if the environment happens to expose only local mounts. Please assert on the actual returned mounts to prove the filter is doing work.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@oshi-common/src/test/java/oshi/software/common/os/linux/LinuxFileSystemTest.java`
around lines 55 - 62, Replace the weak size-only check in
testGetFileStoresLocalOnly with assertions that verify the filter actually
selects a subset of mounts: call StubLinuxFileSystem.getFileStoreMatching(null,
Collections.emptyMap(), false) and getFileStoreMatching(..., true) as before,
then assert that every OSFileStore in local is contained in all (e.g., assert
that all containsAll local) to prove locality is a subset, and also assert that
the two lists are not equal when the StubLinuxFileSystem returns at least one
non-local mount (i.e., assertThat(all, is(not(local)))) so the test fails if
localOnly is ignored. Ensure you reference StubLinuxFileSystem and
getFileStoreMatching in the assertions.
Resolves the remaining items in #3189.
Refactored methods:
LinuxOperatingSystem.getParentPidFromProcFile()→ newgetParentPidFromStat(String)— parses/proc/[pid]/statcontentProcPath.PID_STATinstead of hardcoded/procpathTests added to LinuxOperatingSystemTest:
New LinuxFileSystemTest (Linux-only):
No public API changes. No new dependencies.
Summary by CodeRabbit
Refactor
Tests