Repository navigation
FreeBSD: quiet dmesg.boot read and extract testable command parsers - #3495
Conversation
A missing dmesg.boot is tolerated (falls back to sysctl); warning on every CentralProcessor construction spammed callers that recreate SystemInfo.
Split data acquisition from parsing in the FreeBSD HAL so the parsing logic can be unit-tested with synthetic fixtures instead of only on a live FreeBSD host. Each public method becomes a thin wrapper around runNative/readFile, and a package-private parse method takes the already-read List<String>: - FreeBsdCentralProcessor: parseProcessorIdFromDmesg (+ DmesgProcessorId holder), parseProcModelsAndFlags, parseCachesFromLscpu - FreeBsdUsbDevice: parseUsbDevices (lshal device tree) - FreeBsdSoundCard: parseSoundCards (lshal pcm nodes) - FreeBsdComputerSystem: parseDmiDecode (dmidecode -t system) - FreeBsdFirmware: parseDmiDecode (dmidecode -t bios) Fixtures are grounded in real dmesg.boot, lshal, lscpu, and dmidecode output. The new tests run on every platform and cover each parse method's lines fully.
testProcstatLive asserted getCwd(pid) was nonempty, but procstat resolves a process cwd on a best-effort basis: on some filesystems (nullfs / memory-backed CI build dirs) the cwd vnode maps to no path and procstat returns it empty, which failed the assertion on the vmactions FreeBSD runner. Accept an empty result, and require an absolute path only when one is actually returned. The parse logic itself remains fully covered by testParseCwdReturnsFirstCwdPath.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (14)
🔇 Additional comments (1)
📝 WalkthroughWalkthroughFreeBSD hardware discovery separates command or file acquisition from parsing helpers. CPU, DMI, sound-card, and USB parsers accept supplied output lines, with unit tests covering parsed fields and edge cases. The procstat CWD test now permits empty results. ChangesFreeBSD CPU and cache parsing
FreeBSD DMI parsing
FreeBSD sound and USB parsing
Procstat CWD test contract
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3495 +/- ##
============================================
- Coverage 75.16% 69.53% -5.64%
Complexity 76 76
============================================
Files 591 591
Lines 21617 21651 +34
Branches 3613 3613
============================================
- Hits 16248 15054 -1194
- Misses 3412 4829 +1417
+ Partials 1957 1768 -189
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.java (1)
47-94: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlign the DMI parser fallback contract between
FreeBsdFirmwareandFreeBsdComputerSystem. Both classes extracted aparseDmiDecodehelper in this PR, but they disagree on where theConstants.UNKNOWN/null fallback is applied — one root cause spanning two files.
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.java#L47-L94: move theConstants.UNKNOWNternaries out ofparseDmiDecode's return statement and intoreadDmiDecode(), so the parser returns raw/nullvalues like its sibling; updateFreeBsdFirmwareTest.testParseDmiDecodeEmptyaccordingly.oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystem.java#L90-L124: no change needed — this file already follows the caller-boundary-fallback pattern described in the PR objective; keep as the reference implementation.🤖 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/freebsd/FreeBsdFirmware.java` around lines 47 - 94, Align FreeBsdFirmware.readDmiDecode and parseDmiDecode with the caller-boundary fallback pattern: have parseDmiDecode return raw or null manufacturer, version, and release-date values, and apply Constants.UNKNOWN fallbacks in readDmiDecode instead. Update FreeBsdFirmwareTest.testParseDmiDecodeEmpty for the parser’s raw/null results. FreeBsdComputerSystem.java lines 90-124 requires no direct change and remains the reference implementation.
🤖 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/freebsd/FreeBsdFirmware.java`:
- Around line 47-94: Align FreeBsdFirmware.readDmiDecode and parseDmiDecode with
the caller-boundary fallback pattern: have parseDmiDecode return raw or null
manufacturer, version, and release-date values, and apply Constants.UNKNOWN
fallbacks in readDmiDecode instead. Update
FreeBsdFirmwareTest.testParseDmiDecodeEmpty for the parser’s raw/null results.
FreeBsdComputerSystem.java lines 90-124 requires no direct change and remains
the reference implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b83a019c-e4fe-4df2-bda3-6e214a334860
📒 Files selected for processing (11)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdSoundCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystemTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmwareTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdSoundCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDeviceTest.javaoshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (13)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
🧰 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/freebsd/FreeBsdSoundCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.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/freebsd/FreeBsdSoundCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.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/freebsd/FreeBsdCentralProcessor.java
🔇 Additional comments (11)
oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java (1)
12-13: LGTM!Also applies to: 78-85
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java (1)
23-23: LGTM!Also applies to: 155-343
oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.java (1)
1-98: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystem.java (1)
9-9: LGTM!Also applies to: 69-88
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.java (1)
9-9: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystemTest.java (1)
1-53: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmwareTest.java (1)
1-47: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdSoundCard.java (1)
45-82: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java (1)
38-120: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdSoundCardTest.java (1)
1-56: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDeviceTest.java (1)
1-104: LGTM!
…rmware Mirror FreeBsdComputerSystem: parseDmiDecode returns raw values (null manufacturer/version, empty release date) and readDmiDecode applies the Constants.UNKNOWN fallbacks, so the two dmidecode parsers follow the same caller-boundary pattern. Update testParseDmiDecodeEmpty for the raw results.
…3496) * NetBSD/OpenBSD: extract testable parse methods from command readers 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) * Fix firmware vendor extraction to preserve multi-word BIOS vendor names 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.
* 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.
Summary
Improves FreeBSD testability/coverage and quiets a log-noise source, in three focused commits.
Read
/var/run/dmesg.bootquietly — the file is often unreadable to non-root users; read it withreportError=falseso a routine permission miss no longer logs an error.Extract testable parse methods from FreeBSD command readers — separate acquisition (
runNative/readFile) from parsing across the FreeBSD HAL, so the parsing logic is unit-testable with synthetic fixtures rather than only on a live FreeBSD host:FreeBsdCentralProcessor:parseProcessorIdFromDmesg(+DmesgProcessorIdholder),parseProcModelsAndFlags,parseCachesFromLscpuFreeBsdUsbDevice:parseUsbDevices(lshal device tree)FreeBsdSoundCard:parseSoundCards(lshal pcm nodes)FreeBsdComputerSystem:parseDmiDecode(dmidecode -t system)FreeBsdFirmware:parseDmiDecode(dmidecode -t bios)New fixtures are grounded in real
dmesg.boot/lshal/lscpu/dmidecodeoutput; the tests run on every platform and cover each parse method's lines fully.Tolerate an unresolvable procstat cwd in the live FreeBSD test —
procstatresolves a process cwd on a best-effort basis; on some CI filesystems it returns empty. Accept that, and require an absolute path only when one is actually returned.Testing
oshi-commonfull gate green: spotless, checkstyle, install + forbiddenapis, javadoc.clean testpasses; new parse methods measured at ~100% line coverage locally via JaCoCo.No CHANGELOG entry — test/coverage work plus a minor log-noise reduction.
Summary by CodeRabbit
dmidecodeparsing for system and BIOS details with centralized fallbacks for missing fields.lshaloutput.