Skip to content

Extract parsing from Who, LinuxOSProcess, LinuxOperatingSystem - #3203

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:3189-extract-linux-proc-who-parsing
Apr 28, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:3189-extract-linux-proc-who-parsing

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 28, 2026 •

Copy link
Copy Markdown
Member

Resolves part of #3189.

Separates command execution from output parsing in 5 methods:

Refactored methods:

  • Who.matchLinux() — made package-private (was private) for direct testing with fixture data
  • Who.matchUnix() — already public, added fixture tests for various who date formats
  • LinuxOSProcess.getAffinityMask() → new parseAffinityMask(String) — taskset -p output
  • LinuxOperatingSystem.readOsRelease() → new readOsRelease(List<String>) — /etc/os-release
  • LinuxOperatingSystem.execLsbRelease() → new execLsbRelease(List<String>) — lsb_release -a

Tests added:

  • Linux WhoTest: standard format, no host, no match
  • Unix WhoTest: standard format, no host, single-digit day, no match
  • LinuxOSProcessTest: hex affinity masks, empty/invalid input
  • LinuxOperatingSystemTest: Ubuntu/CentOS os-release, lsb_release, empty/partial input

No public API changes. No new dependencies.

Summary by CodeRabbit

  • Refactor

    • Improved Linux OS identification and process-affinity parsing internals for more reliable detection and resilience to malformed inputs.
  • Tests

    • Added deterministic unit tests covering OS release parsing, process affinity extraction, and user/session parsing to increase confidence and prevent regressions.

@coderabbitai

coderabbitai Bot commented Apr 28, 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: 95ffa934-ad50-4ae2-92aa-dac88921779e

📥 Commits

Reviewing files that changed from the base of the PR and between d12c063 and 3a37914.

📒 Files selected for processing (8)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/util/driver/linux/Who.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
  • oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-common/src/main/java/oshi/util/driver/linux/Who.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.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: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-10T22:44:36.786Z
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:36.786Z
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/software/common/os/linux/LinuxOSProcess.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/LinuxOSProcess.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java (1)

338-359: Clean extraction and robust fallback logic.

Great change: getAffinityMask() is now focused on command execution, while parseAffinityMask(...) is directly testable and safely returns 0 for empty/invalid output paths.

oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java (4)

26-35: Great deterministic coverage for the standard Linux who format.

Nice addition here—this validates match success, parsed core fields, and host extraction in one focused fixture test.


38-46: Good fallback-path test for missing host values.

Thanks for explicitly asserting Constants.UNKNOWN; this keeps the no-host behavior well protected.


49-54: Solid negative-case assertion.

This is a useful guardrail: no false match and no session mutation for invalid input.


56-67: Nice split between fixture tests and Linux-only live validation.

Moving the live check into a nested @EnabledOnOs(OS.LINUX) block keeps CI behavior predictable while still retaining runtime sanity coverage.


📝 Walkthrough

Walkthrough

Refactors Linux parsing by extracting parsing logic into package-private static helpers: parseAffinityMask(String), readOsRelease(List<String>), and execLsbRelease(List<String>); relaxes Who.matchLinux visibility; and adds unit tests and a test JVM open directive.

Changes

Cohort / File(s) Summary
Affinity & OS parsing helpers
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
Added package-private parsing helpers (parseAffinityMask(String), readOsRelease(List<String>), execLsbRelease(List<String>)) and updated existing methods to delegate I/O to these helpers.
Who driver visibility
oshi-common/src/main/java/oshi/util/driver/linux/Who.java
Changed matchLinux from private static to package-private static to allow direct testing of parsing logic.
Test JVM access
oshi-common/src/test/java/module-info.test
Added an extra --add-opens JVM argument to grant test framework reflective access to the Linux package.
New unit tests: affinity & OS release
oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.java, oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
Added tests covering affinity-mask parsing and /etc/os-release / lsb_release parsing, including edge cases and empty inputs.
Who parsing tests & live gating
oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java, oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java
Refactored tests to include deterministic parsing unit tests for matchLinux/matchUnix and moved live system queries into nested live-only test classes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

✨ Parsing lines to tidy art,

Helpers born to play their part,
Tests arrive with fixtures bright,
Visibility opens light,
Cheers to clearer code tonight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: extracting parsing logic from three core classes (Who, LinuxOSProcess, LinuxOperatingSystem) to improve testability.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.86%. Comparing base (80078df) to head (3a37914).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../oshi/software/common/os/linux/LinuxOSProcess.java 50.00% 1 Missing and 1 partial ⚠️
...software/common/os/linux/LinuxOperatingSystem.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3203      +/-   ##
==========================================
+ Coverage   58.56%   58.86%   +0.29%     
==========================================
  Files         421      421              
  Lines       20355    20358       +3     
  Branches     3576     3577       +1     
==========================================
+ Hits        11921    11983      +62     
+ Misses       6688     6624      -64     
- Partials     1746     1751       +5     
Flag Coverage Δ
linux 24.83% <57.14%> (+0.26%) ⬆️
macos 27.99% <14.28%> (+0.15%) ⬆️
windows 37.12% <14.28%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java (1)

38-52: Strengthen the no-host and single-digit-day tests with field-level assertions.

Both tests currently prove a match happened, but not that the parsed values are correct. Adding a couple of field assertions will make regressions much easier to catch.

Suggested test assertion additions
 `@Test`
 void testMatchUnixNoHost() {
     List<OSSession> sessions = new ArrayList<>();
     boolean matched = Who.matchUnix(sessions, "root     console  Jan 15 08:30");
     assertThat(matched, is(true));
     assertThat(sessions.size(), is(1));
     assertThat(sessions.get(0).getUserName(), is("root"));
+    assertThat(sessions.get(0).getTerminalDevice(), is("console"));
 }

 `@Test`
 void testMatchUnixSingleDigitDay() {
     List<OSSession> sessions = new ArrayList<>();
     boolean matched = Who.matchUnix(sessions, "user1 pts/0 Dec  3 14:22 (10.0.0.1)");
     assertThat(matched, is(true));
     assertThat(sessions.size(), is(1));
+    assertThat(sessions.get(0).getUserName(), is("user1"));
+    assertThat(sessions.get(0).getTerminalDevice(), is("pts/0"));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java` around lines 38
- 52, Update the two tests that call Who.matchUnix to assert parsed fields on
the created OSSession(s): in testMatchUnixNoHost, after the existing assertions
also assert sessions.get(0).getTerminal() equals "console" and
sessions.get(0).getHost() is null (or empty) and that the parsed month/day/time
fields (e.g., getLoginMonth/getLoginDay/getLoginTime or equivalent getters)
match Jan/15/"08:30"; in testMatchUnixSingleDigitDay, after the size assertion
assert sessions.get(0).getUserName() equals "user1",
sessions.get(0).getTerminal() equals "pts/0" and sessions.get(0).getHost()
equals "10.0.0.1" (and check the parsed day is 3 and time is "14:22"). Use the
existing OSSession getters to locate those fields and add these assertions to
make the tests validate field-level parsing from Who.matchUnix.
oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java (1)

36-42: Consider asserting the no-host fallback value explicitly.

Line 38 exercises a no-host input, but the test doesn’t currently validate the host fallback (Constants.UNKNOWN). Adding that assertion would pin parser behavior.

✅ Suggested test enhancement
 import oshi.software.os.OSSession;
+import oshi.util.Constants;
@@
     void testMatchLinuxNoHost() {
         List<OSSession> sessions = new ArrayList<>();
         boolean matched = Who.matchLinux(sessions, "root     tty1         2023-01-15 08:30");
         assertThat(matched, is(true));
         assertThat(sessions.size(), is(1));
         assertThat(sessions.get(0).getUserName(), is("root"));
+        assertThat(sessions.get(0).getHost(), is(Constants.UNKNOWN));
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java` around lines
36 - 42, The test testMatchLinuxNoHost should explicitly assert the parsed host
fallback; update the test in WhoTest to check that Who.matchLinux produced a
session whose getHost() equals Constants.UNKNOWN (e.g.,
assertThat(sessions.get(0).getHost(), is(Constants.UNKNOWN))). Locate the
assertion block in testMatchLinuxNoHost and add this assertion referencing
Who.matchLinux, OSSession.getHost, and Constants.UNKNOWN so the parser's no-host
behavior is pinned.
🤖 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/software/common/os/linux/LinuxOSProcess.java`:
- Around line 351-354: The code in LinuxOSProcess that splits tasksetOutput
using ParseUtil.whitespaces may produce an empty array for whitespace-only input
and then throw ArrayIndexOutOfBounds when accessing split[split.length - 1];
update the logic in the method (around the use of
ParseUtil.whitespaces.split(tasksetOutput), the BigInteger(..., 16).longValue()
conversion, and the existing NumberFormatException catch) to first check if the
split array is empty or has no non-empty entries and return 0 immediately; only
attempt to parse the last element into a BigInteger if the array contains at
least one element, otherwise return 0 to satisfy the “return 0 if unparseable”
contract.

---

Nitpick comments:
In `@oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java`:
- Around line 36-42: The test testMatchLinuxNoHost should explicitly assert the
parsed host fallback; update the test in WhoTest to check that Who.matchLinux
produced a session whose getHost() equals Constants.UNKNOWN (e.g.,
assertThat(sessions.get(0).getHost(), is(Constants.UNKNOWN))). Locate the
assertion block in testMatchLinuxNoHost and add this assertion referencing
Who.matchLinux, OSSession.getHost, and Constants.UNKNOWN so the parser's no-host
behavior is pinned.

In `@oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java`:
- Around line 38-52: Update the two tests that call Who.matchUnix to assert
parsed fields on the created OSSession(s): in testMatchUnixNoHost, after the
existing assertions also assert sessions.get(0).getTerminal() equals "console"
and sessions.get(0).getHost() is null (or empty) and that the parsed
month/day/time fields (e.g., getLoginMonth/getLoginDay/getLoginTime or
equivalent getters) match Jan/15/"08:30"; in testMatchUnixSingleDigitDay, after
the size assertion assert sessions.get(0).getUserName() equals "user1",
sessions.get(0).getTerminal() equals "pts/0" and sessions.get(0).getHost()
equals "10.0.0.1" (and check the parsed day is 3 and time is "14:22"). Use the
existing OSSession getters to locate those fields and add these assertions to
make the tests validate field-level parsing from Who.matchUnix.
🪄 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: 83c3082b-1421-4ebe-9a25-425438079cfd

📥 Commits

Reviewing files that changed from the base of the PR and between 80078df and d12c063.

📒 Files selected for processing (8)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/util/driver/linux/Who.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
  • oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.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). (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (6)
📚 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/module-info.test
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.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/module-info.test
  • oshi-common/src/main/java/oshi/util/driver/linux/Who.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.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/driver/linux/Who.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
📚 Learning: 2026-04-10T22:44:36.786Z
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:36.786Z
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/software/common/os/linux/LinuxOSProcess.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java
🔇 Additional comments (8)
oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java (3)

27-35: Great deterministic coverage for the primary Unix who parse path.

Nice job validating match result, list mutation, and key parsed fields in one focused fixture test.


55-60: No-match behavior is validated cleanly.

Checking both false and zero appended sessions is exactly what this negative case should assert.


62-73: Good separation of fixture tests from live/system-dependent checks.

Moving runtime-dependent assertions into LiveTests keeps parser tests deterministic while still preserving runtime validation.

oshi-common/src/test/java/module-info.test (1)

21-22: Good addition for test reflection access.

This --add-opens entry cleanly supports the new Linux package tests without widening production visibility.

oshi-common/src/main/java/oshi/util/driver/linux/Who.java (1)

60-60: Visibility change is a solid testability improvement.

Line 60 keeps parser behavior intact while enabling deterministic fixture tests.

oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.java (1)

14-37: Nice focused coverage for the extracted affinity parser.

These cases validate both happy paths and invalid/empty fallbacks well.

oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java (1)

270-327: Clean extraction of parsing from command/file I/O.

The new overloads keep behavior stable while making the parser paths directly unit-testable.

oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java (1)

35-81: Great fixture coverage for the extracted Linux OS parsers.

The test matrix is pragmatic and directly validates the key parsing branches and null-return conditions.

Separate command execution from output parsing for testability:

- Who.matchLinux(): made package-private for direct testing
- Who.matchUnix(): already public, added fixture tests
- LinuxOSProcess.parseAffinityMask(): extracted from getAffinityMask()
- LinuxOperatingSystem.readOsRelease(List): extracted from readOsRelease()
- LinuxOperatingSystem.execLsbRelease(List): extracted from execLsbRelease()

Added fixture-based tests for Linux/Unix who date formats, taskset
affinity mask parsing, /etc/os-release and lsb_release -a parsing.
No public API changes.
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