Skip to content

Solaris: extract testable parse methods from command readers - #3497

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:solaris-parse-extractions
Jul 20, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:solaris-parse-extractions

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Test plan

Summary by CodeRabbit

  • Bug Fixes
    • Improved Solaris parsing reliability for CPU/feature extraction, kstat rollups (context switches and interrupts), NUMA node mapping, SMBIOS/serial fallback, graphics and sound device discovery, and swap/virtual memory calculations.
    • Enhanced TCP/UDP netstat stats parsing consistency by separating command execution from parsing and tightening stat splitting.
  • Tests
    • Added new Solaris-focused JUnit coverage for CPU, NUMA, SMBIOS/serial, graphics, sound, virtual memory, and TCP/UDP netstat parsing, including empty and edge-case outputs.

Extract inline command-output parsing into package-private static
methods that accept List<String> (or String), mirroring the pattern
from #3494 (Linux), #3495 (FreeBSD), and #3496 (NetBSD/OpenBSD).
This allows fixture-based tests to exercise the parse logic on every
CI platform without requiring Solaris/OpenIndiana.

Extractions:
- SolarisCentralProcessor: parseDmesgCpuInfo (dmesg), parseNumaNodes
  (lgrpinfo -c leaves), parseIsainfoFlags (isainfo -v), sumKstatLong
  (kstat -p cpu_stat)
- SolarisComputerSystem: parseSmbios (smbios), parseSerialFromPrtconf
  (prtconf -pv chassis-sn)
- SolarisGraphicsCard: parsePrtconf (prtconf -pv display class)
- SolarisSoundCard: parseLshal (lshal audio810 driver)
- SolarisVirtualMemory: parseSwapInfo (swap -lk), sumKstatLong
  (kstat -p cpu_stat:::pgswapin/pgswapout)
- SolarisInternetProtocolStats: parseTcpStats and parseUdpStats
  (netstat -s -P tcp/udp/ip), splitOnPrefix made package-private
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2b3575d2-a0ba-4129-80b5-e4b6dd51121c

📥 Commits

Reviewing files that changed from the base of the PR and between 53cb2dd and d883a77.

📒 Files selected for processing (2)
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java
  • oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (14)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

Solaris hardware, virtual-memory, and network collectors now separate native command execution from output parsing through reusable helpers. New Solaris-focused tests cover processor, SMBIOS, device, memory, and protocol parsing, including empty and boundary inputs.

Changes

Solaris parser refactor

Layer / File(s) Summary
Processor parsing helpers
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java, oshi-common/src/test/.../SolarisCentralProcessorTest.java
CPU, NUMA, feature-flag, and kstat parsing use shared helpers with representative unit coverage.
Hardware output parser inputs
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.java, SolarisGraphicsCard.java, SolarisSoundCard.java, oshi-common/src/test/.../solaris/*Test.java, oshi-common/src/test/java/module-info.test
SMBIOS, serial, graphics, and sound parsers consume supplied command output, with parsing tests and Solaris module access updates.
Virtual memory parsing helpers
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.java, oshi-common/src/test/.../SolarisVirtualMemoryTest.java
Kstat summation and swap parsing are centralized and tested with populated and empty inputs.
Network statistics parser inputs
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java, oshi-common/src/test/.../SolarisInternetProtocolStatsTest.java
TCP and UDP command output is assembled before parsing, with reusable prefix splitting and protocol-stat tests.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Poem

I’m a rabbit with logs in my burrow,
Parsing each line without hurry or worry.
CPU flags hop, swap totals gleam,
Netstat streams flow like a dream.
Tests guard each helper with care—
Solaris data now travels fair!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% 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 captures the main change: extracting Solaris parsing logic into testable methods from command readers.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.41270% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.95%. Comparing base (7f2898f) to head (d883a77).

Files with missing lines Patch % Lines
...n/platform/unix/solaris/SolarisComputerSystem.java 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3497      +/-   ##
============================================
+ Coverage     75.92%   75.95%   +0.02%     
  Complexity       76       76              
============================================
  Files           591      591              
  Lines         21675    21676       +1     
  Branches       3614     3612       -2     
============================================
+ Hits          16456    16463       +7     
- Misses         3260     3262       +2     
+ Partials       1959     1951       -8     
Flag Coverage Δ
freebsd 30.88% <55.55%> (+0.87%) ⬆️
linux 35.01% <55.55%> (+0.88%) ⬆️
macos 36.14% <55.55%> (+0.83%) ⬆️
openbsd 29.83% <55.55%> (+0.86%) ⬆️
solaris 31.95% <98.41%> (+0.09%) ⬆️
windows 44.06% <55.55%> (+0.85%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java (1)

68-69: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix multi-stat parsing when the second stat lacks the prefix.

stat.split("=") splits the line into as many parts as there are = signs. If a line contains two stats with different prefixes (e.g., "tcpInErrs = 3 udpNoPorts = 0"), splitOnPrefix correctly leaves the string intact because it doesn't find a second matching prefix. However, splitting this combined string by = produces an array of length 3. The if (split.length == 2) condition will then evaluate to false, causing the entire line to be skipped. As noted by the inline comment, this scenario is expected, but the strict length check prevents ParseUtil.getFirstIntValue from ever being reached.

  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java#L68-L69: In parseTcpStats, use stat.split("=", 2) to split only on the first = sign, guaranteeing a length of 2 and allowing the value to be parsed correctly.
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java#L130-L131: Apply the same stat.split("=", 2) fix in parseUdpStats to protect against trailing non-UDP stats.
🐛 Proposed fix

For TCP stats (parseTcpStats):

-                    String[] split = stat.split("=");
-                    if (split.length == 2) {
+                    String[] split = stat.split("=", 2);
+                    if (split.length == 2) {

For UDP stats (parseUdpStats):

-                    String[] split = stat.split("=");
-                    if (split.length == 2) {
+                    String[] split = stat.split("=", 2);
+                    if (split.length == 2) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java`
around lines 68 - 69, Update stat splitting in both parseTcpStats
(SolarisInternetProtocolStats.java lines 68-69) and parseUdpStats
(SolarisInternetProtocolStats.java lines 130-131) to split on only the first
equals sign, preserving the existing length check and allowing values to be
parsed when trailing stats use different prefixes.
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java (1)

24-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use realistic test data to cover mixed-prefix edge cases.

The test currently bypasses a real-world parsing bug because tcpInErr shares a line with tcpOutRsts, allowing splitOnPrefix to separate them cleanly. In real Solaris netstat -s -P ip output, tcpInErrs typically shares a line with udpNoPorts (which doesn't start with tcp).

Once you apply the stat.split("=", 2) fix to the parser, I recommend updating this mock data to properly test the parser's resilience against lines containing mixed prefixes.

💡 Proposed refactor
         List<String> netstat = Arrays.asList(//
                 "tcpCurrEstab =    42   tcpActiveOpens =  1000", //
                 "tcpPassiveOpens = 500   tcpAttemptFails =   10", //
                 "tcpEstabResets =    5   tcpOutSegs    = 50000", //
                 "tcpInSegs     = 60000   tcpRetransSegs =   200", //
-                "tcpInErr      =     3   tcpOutRsts    =    15");
+                "tcpInErr      =     3   udpNoPorts    =    15", //
+                "tcpOutRsts    =    15");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java`
around lines 24 - 30, Update the mock netstat data in
SolarisInternetProtocolStatsTest to reflect realistic mixed-prefix output: use
the correctly named tcpInErrs statistic on a line with udpNoPorts rather than
pairing tcpInErr with tcpOutRsts, while preserving coverage of the
stat.split("=", 2) parsing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java`:
- Around line 68-69: Update stat splitting in both parseTcpStats
(SolarisInternetProtocolStats.java lines 68-69) and parseUdpStats
(SolarisInternetProtocolStats.java lines 130-131) to split on only the first
equals sign, preserving the existing length check and allowing values to be
parsed when trailing stats use different prefixes.

---

Nitpick comments:
In
`@oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java`:
- Around line 24-30: Update the mock netstat data in
SolarisInternetProtocolStatsTest to reflect realistic mixed-prefix output: use
the correctly named tcpInErrs statistic on a line with udpNoPorts rather than
pairing tcpInErr with tcpOutRsts, while preserving coverage of the
stat.split("=", 2) parsing behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 070d1b81-6702-4f39-b986-0d99a83e8c24

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2898f and 53cb2dd.

📒 Files selected for processing (13)
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystemTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemoryTest.java
  • oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (13)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 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/unix/solaris/SolarisVirtualMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.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/unix/solaris/SolarisCentralProcessor.java
🔇 Additional comments (11)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.java (1)

10-10: LGTM!

Also applies to: 79-85, 86-113

oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemoryTest.java (1)

1-51: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java (1)

37-37: LGTM!

Also applies to: 61-68, 83-97, 105-132, 152-181

oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessorTest.java (1)

1-100: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.java (1)

15-15: LGTM!

Also applies to: 83-115, 152-201

oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystemTest.java (1)

1-100: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.java (1)

44-53: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCardTest.java (1)

1-79: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.java (1)

46-60: LGTM!

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

89-92: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCardTest.java (1)

1-78: LGTM!

When tcpInErr is paired with a non-tcp stat on the same line (e.g.
udpNoPorts), splitOnPrefix finds only one "tcp" occurrence, leaving
the full remainder including a second "=" sign. Limiting split to 2
parts ensures the length check passes and getFirstIntValue extracts
the correct value from the leading portion.
@dbwiddis
dbwiddis merged commit 9569fff into oshi:master Jul 20, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the solaris-parse-extractions branch July 20, 2026 21:18
dbwiddis added a commit that referenced this pull request Jul 20, 2026
…#3498)

* Solaris: extract prtpicl, prtconf USB, svcs, and plimit/pbind parsers

Extract remaining Solaris-specific command parsers into testable static
methods, continuing the coverage work from #3497.

Extractions:
- SolarisSensors: parseCpuTemperature, parseFanSpeeds, parseVoltage
  (prtpicl -v -c temperature-sensor/fan/voltage-sensor)
- SolarisUsbDevice: parsePrtconf (prtconf -pv USB device tree)
- SolarisOperatingSystem: parseSvcs (svcs -p service enumeration)
- SolarisOSProcess: parseOpenFileLimit (plimit), parsePbindOutput
  (pbind -q), parsePsrinfo (psrinfo processor enumeration)

* Remove stale comment and use stream conversion in parseFanSpeeds
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