Skip to content

NetBSD/OpenBSD: extract testable parse methods from command readers - #3496

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

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:netbsd-openbsd-parse-extractions

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Test plan

Summary by CodeRabbit

  • Bug Fixes
    • Improved BSD hardware detection and parsing for CPU topology/model/caches, firmware, graphics, sound, and USB devices.
    • Enhanced NetBSD and OpenBSD processor, system statistics, and firmware extraction accuracy, including more resilient dmesg parsing.
    • Reduced repeated system-output collection during hardware discovery to improve consistency and efficiency.
  • Tests
    • Added/expanded unit test coverage for BSD, NetBSD, and OpenBSD parsing of CPU, firmware, graphics, sound, USB, and system statistics outputs.

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

Extractions:
- BsdCentralProcessor: parseTopology, parseDmesgModelsAndCaches,
  parseCacheStr (shared by NetBSD + OpenBSD)
- BsdGraphicsCard: parsePciDump (pcidump -v)
- BsdSoundCard: parseDmesg (dmesg audio/pci)
- BsdUsbDevice: parseUsbDevices (usbdevs -v)
- NetBsdCentralProcessor: parseVmStats, parseFamilyModelStepping,
  parseCpTime
- NetBsdFirmware: parseDmesg (bios0 vendor line)
- OpenBsdCentralProcessor: parseVmStats, cpuidToFamilyModelStepping
- OpenBsdFirmware: parseDmesg (bios0 vendor line)
@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: c71e512a-44a3-47b6-8c1c-5639c5de0585

📥 Commits

Reviewing files that changed from the base of the PR and between 520861c and d557300.

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

📝 Walkthrough

Walkthrough

BSD hardware, processor, and firmware implementations now separate command execution from parsing helpers. Processor parsing reuses collected dmesg output, platform helpers expose testable parsing logic, and unit tests cover normal, empty, and edge-case inputs.

Changes

BSD parser refactor

Layer / File(s) Summary
Shared BSD processor parsing
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdCentralProcessorTest.java
CPU topology, models, caches, and feature flags are parsed from one collected dmesg result through dedicated helpers and tested across Intel, ARM, empty, and cache-format inputs.
Shared BSD device parser inputs
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdGraphicsCard.java, BsdSoundCard.java, BsdUsbDevice.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/*Test.java
Graphics, sound, and USB methods pass command output into parsers, with coverage for multiple devices, missing fields, empty input, and final-entry handling.
NetBSD processor and firmware parsing
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/{NetBsdCentralProcessor,NetBsdFirmware}.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/*Test.java
NetBSD VM statistics, CPU family/model/stepping, CPU time, and BIOS fields use extracted parsing helpers with tests for matches and empty or missing inputs.
OpenBSD processor and firmware parsing
oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/{OpenBsdCentralProcessor,OpenBsdFirmware}.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/*Test.java
OpenBSD VM statistics, CPUID mapping, and BIOS dmesg parsing are delegated to helpers and covered by focused unit tests.

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

Possibly related PRs

  • oshi/oshi#3381: Introduced the shared BSD hardware classes refactored here.
  • oshi/oshi#3387: Also changed shared BSD processor topology and cache parsing.
  • oshi/oshi#3447: Also changed the BSD USB enumeration entry point and parser flow.

Poem

A rabbit parsed the dmesg stream,
With caches tucked inside a dream.
“One command!” the bunny cried,
While tests hopped happily beside.
BSD’s helpers now run light—
Clean little parsers, working right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% 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 summarizes the main change: extracting testable parser methods from NetBSD/OpenBSD 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 88.88889% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.88%. Comparing base (8b1ac06) to head (d557300).

Files with missing lines Patch % Lines
.../common/platform/unix/openbsd/OpenBsdFirmware.java 63.63% 0 Missing and 4 partials ⚠️
...ware/common/platform/unix/BsdCentralProcessor.java 96.55% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3496      +/-   ##
============================================
+ Coverage     75.77%   75.88%   +0.10%     
  Complexity       76       76              
============================================
  Files           591      591              
  Lines         21651    21675      +24     
  Branches       3613     3614       +1     
============================================
+ Hits          16406    16447      +41     
+ Misses         3279     3265      -14     
+ Partials       1966     1963       -3     
Flag Coverage Δ
freebsd 29.99% <71.11%> (+0.73%) ⬆️
linux 34.13% <68.88%> (+0.73%) ⬆️
macos 35.28% <68.88%> (+0.74%) ⬆️
openbsd 28.96% <88.88%> (+0.24%) ⬆️
solaris 31.86% <71.11%> (+0.75%) ⬆️
windows 43.18% <68.88%> (+0.74%) ⬆️

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.

🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java (1)

42-77: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Vendor extraction truncates multi-word BIOS vendor names.

afterVendor.split("\\s+")[0] only keeps the first token after vendor, so multi-word vendors (e.g. "American Megatrends Inc.") would be truncated to just "American". Existing test fixtures only cover single-word vendors (LENOVO), masking this.

See the consolidated comment (anchored on OpenBsdFirmware.java) for a proposed shared fix covering both files.

🤖 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/hardware/common/platform/unix/netbsd/NetBsdFirmware.java`
around lines 42 - 77, Update parseDmesg in NetBsdFirmware so vendor extraction
preserves the complete multi-word BIOS vendor name instead of taking only the
first whitespace-delimited token. Reuse the shared extraction approach proposed
for OpenBsdFirmware, while keeping version and release-date parsing unchanged.
🤖 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.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java`:
- Around line 42-77: Update parseDmesg in NetBsdFirmware so vendor extraction
preserves the complete multi-word BIOS vendor name instead of taking only the
first whitespace-delimited token. Reuse the shared extraction approach proposed
for OpenBsdFirmware, while keeping version and release-date parsing unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dff280c1-9cbb-4f72-a608-7276a9756a67

📥 Commits

Reviewing files that changed from the base of the PR and between 8b1ac06 and 520861c.

📒 Files selected for processing (16)
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdSoundCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdSoundCardTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdUsbDeviceTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmwareTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmwareTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ 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/BsdSoundCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.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/BsdSoundCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.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/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
🔇 Additional comments (15)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdGraphicsCard.java (1)

39-48: LGTM!

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

1-107: LGTM!

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

42-52: LGTM!

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

1-73: LGTM!

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

34-44: LGTM!

Also applies to: 55-55

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

1-61: LGTM!

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

56-166: LGTM!

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

1-151: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java (1)

37-65: LGTM!

Also applies to: 79-123, 175-175

oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessorTest.java (1)

1-111: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmwareTest.java (1)

1-54: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java (1)

90-98: LGTM!

Also applies to: 108-130

oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessorTest.java (1)

11-19: LGTM!

Also applies to: 96-145

oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmwareTest.java (1)

22-33: LGTM! (assertion on line 30 will need updating once the vendor-parsing bug flagged on OpenBsdFirmware.java is fixed)

oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java (1)

42-73: 🎯 Functional Correctness

Add tests to pin the expected vendor parsing behavior.
OpenBsdFirmware.java#L42-L73 keeps the full vendor ... version ... date ... tail, while NetBsdFirmware.java#L42-L77 truncates multi-word vendors to the first token. Lock down the intended dmesg format before changing the shared parsing logic.

Both NetBsd and OpenBsd parsers now extract the vendor substring between
the "vendor" keyword and the " version " delimiter, correctly handling
multi-word vendors like "American Megatrends Inc." or "Phoenix
Technologies LTD". Falls back to first-token extraction if no " version "
delimiter is present.
@dbwiddis
dbwiddis merged commit 7f2898f into oshi:master Jul 20, 2026
30 of 32 checks passed
@dbwiddis
dbwiddis deleted the netbsd-openbsd-parse-extractions branch July 20, 2026 20:20
dbwiddis added a commit that referenced this pull request Jul 20, 2026
* Solaris: extract testable parse methods from command readers

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

* Use split("=", 2) in netstat parsers for mixed-prefix lines

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.
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