Repository navigation
FreeBSD Port: FFM libc bindings + sysctl util + WhoFFM driver - #3319
Conversation
Lowest-level FFM bindings for the FreeBSD port: sysctlbyname and
getloadavg in FreeBsdLibcFunctions, and a BsdSysctlUtilFFM that mirrors
the JNA BsdSysctlUtil API one-for-one so per-class FFM concretes can be
dropped in without changing call sites.
Bottom-up ordering: bind libc and the sysctl util first, then build up
FFM concretes against them (Phase 4), defer SystemInfo factory wiring
to Phase 6 so we never expose a half-built "available" state.
Module-info exports the new oshi.ffm.util.platform.unix.freebsd package
to match the established oshi.ffm.util.platform.{mac,windows} pattern.
Parity test (oshi-benchmark BsdSysctlComparisonTest, @EnabledOnOs FREEBSD)
runs each BsdSysctlUtil method (int, long, String, struct, raw buffer,
unknown-MIB) through both implementations and asserts equality. Skipped
on Mac/Linux/Windows; exercised on the FreeBSD CI workflow.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Continues bottom-up Phase 3 work without leaving testable surface on
the floor:
* Extends FreeBsdLibcFunctions with the utmpx surface — setutxent /
getutxent / endutxent MethodHandles plus UTMPX_LAYOUT matching
FreeBSD's struct utmpx (276 bytes: short ut_type + Timeval{tv_sec,
tv_usec} + ut_id[8] + ut_pid + ut_user[32] + ut_line[16] +
ut_host[128] + __ut_spare[64]) and primitive/string accessors that
mirror the Linux pattern.
* Adds oshi.driver.unix.freebsd.WhoFFM mirroring the JNA Who driver
one-for-one — walks getutxent, filters USER_PROCESS / LOGIN_PROCESS,
returns List<OSSession>. Falls back to the oshi.util.driver.unix.Who
command-line implementation on invalid sessions or FFM errors, same
as the mac/linux WhoFFM siblings.
* Adds two new FreeBSD-only parity tests:
- WhoComparisonTest — asserts JNA Who.queryUtxent() and FFM
WhoFFM.queryUtxent() return identical session sets (user, device,
host, loginTime) on FreeBSD.
- FreeBsdLibcComparisonTest.getloadavg — closes out the gap where
Phase 3 commit 1 bound getloadavg but never tested it.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
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 (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📜 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). (14)
📝 WalkthroughWalkthroughThis PR adds FreeBSD FFM bindings (sysctlbyname, getloadavg, utmpx API), a BsdSysctlUtilFFM sysctl wrapper, an FFM-backed utmpx-based session query (WhoFFM), module export and test wiring, and FreeBSD-gated tests verifying default-fallback behavior. ChangesFreeBSD FFM System Integration
Sequence DiagramsequenceDiagram
participant Caller
participant BsdSysctlUtilFFM
participant FreeBsdLibcFunctions
participant libc
Caller->>BsdSysctlUtilFFM: sysctl(name, default)
BsdSysctlUtilFFM->>FreeBsdLibcFunctions: sysctlbyname(callState, name, oldp, oldlenp, ...)
FreeBsdLibcFunctions->>libc: sysctlbyname
libc-->>FreeBsdLibcFunctions: return code + errno
FreeBsdLibcFunctions-->>BsdSysctlUtilFFM: boolean success
alt success
BsdSysctlUtilFFM-->>Caller: parsed value
else failure
BsdSysctlUtilFFM-->>Caller: provided default
end
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 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🧪 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 #3319 +/- ##
============================================
- Coverage 76.13% 76.04% -0.10%
Complexity 76 76
============================================
Files 448 449 +1
Lines 17235 17255 +20
Branches 2820 2824 +4
============================================
- Hits 13122 13121 -1
- Misses 2523 2543 +20
- Partials 1590 1591 +1
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:
|
Replaces the over-eager comparison tests added in commits 1 and 2 with the testing pattern OSHI already uses for the same code shape on macOS. * Removes three oshi-benchmark comparison tests (BsdSysctlComparisonTest, WhoComparisonTest, FreeBsdLibcComparisonTest). These exercised internals that Phase 6's NativeComparisonTest will cover transitively through the HAL/OS public API once SystemInfo wires FreeBSD in. WhoFFM is also covered indirectly today by the pre-existing oshi.driver.unix.freebsd.WhoTest (JNA smoke pattern). * Adds BsdSysctlUtilTest in oshi-core mirroring oshi.util.platform.mac.SysctlUtilTest — closes a pre-existing JNA-side coverage gap where the FreeBSD sysctl util had no dedicated test even though the Mac mirror did. Smoke-tests the default-on-failure paths for int/long/String variants. * Adds BsdSysctlUtilFFMTest in oshi-core-ffm following the same shape for the FFM util, and add-opens oshi.ffm.util.platform.unix.freebsd for JUnit reflection. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Follow-up to the five FreeBSD FFM port PRs (#3316, #3319, #3322, #3328, #3330) covering loose ends that don't fit any individual port commit. JaCoCo agent excludes: * Remove `**/unix/BsdNetworkIF*` and `**/unix/UnixBaseboard*`. Both classes were hoisted to oshi-common during the port (#3316 and #3328 respectively) and are now exercised on the permanent FreeBSD CI job through `NativeComparisonTest.networkInterfaces()` and `ComputerSystem.getBaseboard()`; the excludes were silently dropping that coverage from the `freebsd` codecov flag. * Add `**/FreeBsdPowerSource*` alongside the existing `**/{Mac,Windows,Linux}PowerSource*` entries. No battery on the FreeBSD CI VM, same hardware-conditional pattern. Documentation: * Update the supported-platforms statement in README.md, FAQ.md, PERFORMANCE.md, src/site/markdown/index.md, oshi-core-ffm module-info Javadoc, oshi-core SystemInfo Javadoc, and oshi-core package-info Javadoc from "Windows, macOS, and Linux" to "Windows, macOS, Linux, and FreeBSD". CHANGELOG.md gains a New Features bullet linking all five FreeBSD FFM port PRs. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Phase 3 of the FreeBSD FFM port (tracking #3315). Bottom-up layer:
introduce the lowest FFM bindings (
sysctlbyname,getloadavg,utmpxfamily) and the first sysctl utility and session driverbuilt on them. Lays the foundation Phase 4+ concretes need without
exposing any half-built
SystemInfosurface — FFMSystemInfostillreports FreeBSD as unsupported until Phase 6 wires the HAL/OS in.
Per-commit walk
oshi.ffm.unix.freebsd.FreeBsdLibcFunctionswith errno-captured
sysctlbyname+getloadavg. Newoshi.ffm.util.platform.unix.freebsd.BsdSysctlUtilFFMmirrorsoshi.util.platform.unix.freebsd.BsdSysctlUtil1:1(int/long/String/struct/raw-buffer variants), so per-class FFM
concretes can be dropped in without changing call sites.
module-infoexports the new util package alongsideoshi.ffm.util.platform.{mac,windows}.utmpxsurface toFreeBsdLibcFunctions:setutxent/getutxent/endutxent,a 276-byte
UTMPX_LAYOUTmatching FreeBSD'sstruct utmpx(
short ut_type+Timeval ut_tv+ut_id[8]+ut_pid+ut_user[32]+ut_line[16]+ut_host[128]+__ut_spare[64]),plus primitive/string accessors. New
oshi.driver.unix.freebsd.WhoFFMmirrors the JNAWhodriverone-for-one — walks
getutxent, filtersUSER_PROCESS/LOGIN_PROCESS, falls back tooshi.util.driver.unix.Who.queryWho()on errors, same as theoshi.driver.{mac,linux}.WhoFFMsiblings.pattern. Adds
BsdSysctlUtilTestin oshi-core mirroringoshi.util.platform.mac.SysctlUtilTest(smoke-testsdefault-on-failure paths for int/long/String) — this closes a
pre-existing JNA-side coverage gap where the Mac mirror had a test
but the FreeBSD util didn't. Adds
BsdSysctlUtilFFMTestinoshi-core-ffm following the same shape;
add-opensthe new testpackage in
module-info.test.Intentionally deferred
SystemInfofactory wiring — kept for Phase 6 soisAvailable()doesn't return true on FreeBSD while concretes arestill being built.
NativeComparisonTeststays gated to{LINUX, MAC, WINDOWS}.sysctlint-MIB form,getpid,getrlimit,thr_self) — wait for their first FFM consumerin Phase 5 rather than landing untested-on-FreeBSD.
WhoFFMandgetloadavgdedicated tests — both will becovered transitively in Phase 6 via
NativeComparisonTest.sessions()and
.processorLoadAverage()once HAL/OS wiring lands. Nocomparison-test scaffolding committed.
Test plan
./mvnw clean test -Paggregate-coveragelocally (Mac, JDK 25)./mvnw spotless:check checkstyle:checkcleanBsdSysctlUtilTest(oshi-core, 3 tests) andBsdSysctlUtilFFMTest(oshi-core-ffm, 3 tests) both run andpass on the FreeBSD VM
testfreebsdjob inpr.yamlwill exercisethe new tests under
flags: freebsdTracks #3315.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests