Repository navigation
Improve Linux test coverage in oshi-common - #3188
Conversation
- SysfsTest: verify actual return values (non-null, non-empty) for system vendor, product model, BIOS description, and release date - CpuInfoTest: verify queryBoardInfo returns non-null quartet, test queryFeatureFlags returns flags on x86 Linux - LinuxCentralProcessorTest: add topology tests for NUMA node detection and multiple cache types (Instruction + Unified) - DmidecodeTest: verify queryBiosNameRev returns non-null pair - WhoTest: new test for command-line who parser Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: Dan Widdis <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📜 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)
🧰 Additional context used🧠 Learnings (5)📓 Common learnings📚 Learning: 2026-04-19T01:28:43.529ZApplied to files:
📚 Learning: 2026-04-05T05:40:45.797ZApplied to files:
📚 Learning: 2026-04-05T05:39:21.126ZApplied to files:
📚 Learning: 2026-04-18T03:18:03.725ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughAdds Linux-only JUnit tests expanding runtime coverage for processor topology (NUMA and cache types), DMI/sysfs queries, CPU info (board and feature flags), and Who session parsing; several tests are gated with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 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✨ Simplify 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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3188 +/- ##
==========================================
+ Coverage 57.91% 58.06% +0.14%
==========================================
Files 421 421
Lines 20272 20272
Branches 3563 3563
==========================================
+ Hits 11741 11770 +29
+ Misses 6775 6742 -33
- Partials 1756 1760 +4
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:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
oshi-common/src/test/java/oshi/util/driver/linux/proc/CpuInfoTest.java (2)
30-36: Assertion is tautological — consider asserting on the quartet contents instead.Since
queryBoardInfo()always constructs and returns anew Quartet<>(...)(nevernull),assertThat(info, is(notNullValue()))will always pass regardless of parsing behavior. The comment even acknowledges the fields are typicallynullon x86, so this test effectively only verifies that the method doesn't throw — whichtestQueries()already covers.If you want this test to provide additional signal, consider asserting on the arity/shape you actually care about, e.g. that each getter is reachable without NPE, or drop it in favor of the existing
assertDoesNotThrowcoverage.🤖 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/proc/CpuInfoTest.java` around lines 30 - 36, The current test testQueryBoardInfoReturnsQuartet only asserts the Quartet returned by CpuInfo.queryBoardInfo() is non-null (tautological); replace or strengthen it by either removing the test (since testQueries() already ensures no exception) or assert the quartet shape/arity by invoking its accessors (e.g., info.getA(), info.getB(), info.getC(), info.getD()) to ensure getters are reachable without NPE and/or assert expected nullability patterns for your platform; update the test method name and assertions accordingly so it verifies meaningful behavior of CpuInfo.queryBoardInfo() and references Quartet and CpuInfo.queryBoardInfo() explicitly.
38-43: Minor:queryFeatureFlags()returns whole lines, not individual flags.Just a heads-up for future readers —
queryFeatureFlags()returns the deduplicated full/proc/cpuinfolines starting withflags/features(typically one entry on SMP x86), not a list of individual feature tokens. The assertion is still correct on x86 Linux CI, but the comment"/proc/cpuinfo should have a 'flags' line"is accurate while the test name hints at per-flag granularity. Consider renaming to something liketestQueryFeatureFlagsLinePresentor splitting the line to assert on an individual well-known flag (e.g.,fpu) for a stronger check on x86 runners.🤖 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/proc/CpuInfoTest.java` around lines 38 - 43, The test name/test intent is misleading because CpuInfo.queryFeatureFlags() returns deduplicated full "/proc/cpuinfo" lines (lines starting with "flags"/"features") rather than individual tokens; either rename the test method testQueryFeatureFlags to testQueryFeatureFlagsLinePresent (or similar) to reflect that it only verifies presence of a "flags" line, or keep the name and change the assertion to split the returned line(s) on whitespace and assert a known token (e.g., "fpu") is present; update references to the test method name and the assertion logic around CpuInfo.queryFeatureFlags() accordingly.oshi-common/src/test/java/oshi/util/driver/linux/SysfsTest.java (1)
38-70: Assertions are weaker than the PR description suggests.The PR summary states these tests verify "actual return values (non-null, non-empty)", but each new test only asserts non-empty if the value happens to be non-null. On a CI runner where DMI is populated, a regression that starts returning
nullwould silently pass. Since the Linux CI runner does have these sysfs files populated (as the comment on line 23-24 notes), consider asserting non-null directly for the queries that are reliably present on the CI image — or keep the null-tolerant check but also assert, e.g., that at least one of the four returns non-null, so a blanket regression is caught.Not a blocker — happy to defer if the headless-CI variability is broader than I'm assuming.
🤖 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/SysfsTest.java` around lines 38 - 70, The tests use conditional assertions that skip checks when the value is null, so regressions returning null can pass on CI; update the tests for Sysfs.querySystemVendor, Sysfs.queryProductModel, Sysfs.queryBiosDescription, and Sysfs.queryBiosReleaseDate to assert non-null (and non-empty) directly on the CI image, or alternatively keep per-method null-tolerant checks but add a single aggregated assertion that at least one of the four query results is non-null to catch blanket regressions; modify the existing test methods (testQuerySystemVendorReturnsValue, testQueryProductModelReturnsValue, testQueryBiosDescriptionReturnsValue, testQueryBiosReleaseDateFormat) accordingly so they fail if expected sysfs values become null.
🤖 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/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java`:
- Around line 294-308: The test testReadTopologyFromSysfsWithNumaNode is
ineffective because getLogicalProcessorFromSyspath defaults nodeId to 0; change
the created NUMA directory from node0 to a non-zero id (e.g., node3) so
readTopologyFromSysfs actually parses a non-default value, then update the
assertion on result.getA().get(0).getNumaNode() to expect that non-zero id;
reference LinuxCentralProcessor.readTopologyFromSysfs and
getLogicalProcessorFromSyspath to locate the parsing logic and getNumaNode on
the LogicalProcessor to validate the parsed value.
In `@oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java`:
- Around line 23-33: Remove the tautological assertion in testQueryWho: the
assertion assertThat(sessions.size(), is(greaterThanOrEqualTo(0))) is always
true and redundant after asserting sessions is not null. Edit the testQueryWho
method to delete that size check and keep the null check and the loop assertions
over OSSession.getUserName() and OSSession.getTerminalDevice(); leave
Who.queryWho() usage unchanged.
---
Nitpick comments:
In `@oshi-common/src/test/java/oshi/util/driver/linux/proc/CpuInfoTest.java`:
- Around line 30-36: The current test testQueryBoardInfoReturnsQuartet only
asserts the Quartet returned by CpuInfo.queryBoardInfo() is non-null
(tautological); replace or strengthen it by either removing the test (since
testQueries() already ensures no exception) or assert the quartet shape/arity by
invoking its accessors (e.g., info.getA(), info.getB(), info.getC(),
info.getD()) to ensure getters are reachable without NPE and/or assert expected
nullability patterns for your platform; update the test method name and
assertions accordingly so it verifies meaningful behavior of
CpuInfo.queryBoardInfo() and references Quartet and CpuInfo.queryBoardInfo()
explicitly.
- Around line 38-43: The test name/test intent is misleading because
CpuInfo.queryFeatureFlags() returns deduplicated full "/proc/cpuinfo" lines
(lines starting with "flags"/"features") rather than individual tokens; either
rename the test method testQueryFeatureFlags to testQueryFeatureFlagsLinePresent
(or similar) to reflect that it only verifies presence of a "flags" line, or
keep the name and change the assertion to split the returned line(s) on
whitespace and assert a known token (e.g., "fpu") is present; update references
to the test method name and the assertion logic around
CpuInfo.queryFeatureFlags() accordingly.
In `@oshi-common/src/test/java/oshi/util/driver/linux/SysfsTest.java`:
- Around line 38-70: The tests use conditional assertions that skip checks when
the value is null, so regressions returning null can pass on CI; update the
tests for Sysfs.querySystemVendor, Sysfs.queryProductModel,
Sysfs.queryBiosDescription, and Sysfs.queryBiosReleaseDate to assert non-null
(and non-empty) directly on the CI image, or alternatively keep per-method
null-tolerant checks but add a single aggregated assertion that at least one of
the four query results is non-null to catch blanket regressions; modify the
existing test methods (testQuerySystemVendorReturnsValue,
testQueryProductModelReturnsValue, testQueryBiosDescriptionReturnsValue,
testQueryBiosReleaseDateFormat) accordingly so they fail if expected sysfs
values become null.
🪄 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: 38996417-a411-4e32-872b-0d9a3eda0ce9
📒 Files selected for processing (5)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.javaoshi-common/src/test/java/oshi/util/driver/linux/DmidecodeTest.javaoshi-common/src/test/java/oshi/util/driver/linux/SysfsTest.javaoshi-common/src/test/java/oshi/util/driver/linux/WhoTest.javaoshi-common/src/test/java/oshi/util/driver/linux/proc/CpuInfoTest.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). (11)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, ubuntu-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-04-18T03:18:03.725Z
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:03.725Z
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/linux/proc/CpuInfoTest.javaoshi-common/src/test/java/oshi/util/driver/linux/DmidecodeTest.javaoshi-common/src/test/java/oshi/util/driver/linux/SysfsTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java
📚 Learning: 2026-04-14T23:28:18.252Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3160
File: oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxSensorsTest.java:34-40
Timestamp: 2026-04-14T23:28:18.252Z
Learning: In oshi/oshi, `vcgencmd` (used in `LinuxSensors.queryCpuTemperatureFromVcGenCmd()` and related methods) is a Raspberry Pi-specific binary. It will never be present on standard x86/amd64 CI runners or developer machines. Tests that pass `isPi=true` to `LinuxSensors` and assert 0/empty returns are deterministic in practice; do not flag them as potentially flaky due to `vcgencmd` availability.
Applied to files:
oshi-common/src/test/java/oshi/util/driver/linux/proc/CpuInfoTest.java
📚 Learning: 2026-04-19T01:28:43.529Z
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:43.529Z
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/proc/CpuInfoTest.javaoshi-common/src/test/java/oshi/util/driver/linux/DmidecodeTest.javaoshi-common/src/test/java/oshi/util/driver/linux/SysfsTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.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/test/java/oshi/util/driver/linux/proc/CpuInfoTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.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/oshi/util/driver/linux/DmidecodeTest.java
🔇 Additional comments (2)
oshi-common/src/test/java/oshi/util/driver/linux/DmidecodeTest.java (1)
33-39: LGTM.Explicit non-null assertion on the returned
Pairis a nice complement to theassertDoesNotThrowcheck above; matches the documented contract inDmidecode.queryBiosNameRev().oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxCentralProcessorTest.java (1)
310-338: LGTM.Nice coverage for the
Instruction+Unifiedcache types exercisingparseCacheTypeand ensuring distinctProcessorCacheentries are produced.
- Use non-zero NUMA node (node3) to verify parsing, not default - Remove tautological size >= 0 assertion from WhoTest - Strengthen CpuInfoTest: call quartet accessors, rename feature flags test - Replace null-tolerant Sysfs tests with aggregate non-null assertion Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: Dan Widdis <[email protected]>
Description
Improves test coverage for Linux-specific driver and hardware classes in
oshi-common. These tests run on the Linux CI runner and exercise real sysfs/procfs paths where possible, with@TempDir-based synthetic file trees for topology parsing.Changes
SysfsTest — Extended beyond
assertDoesNotThrowto verify actual return values (non-null, non-empty) forquerySystemVendor,queryProductModel,queryBiosDescription, andqueryBiosReleaseDate. On most Linux systems (including CI), these sysfs files are populated.CpuInfoTest — Added tests for
queryBoardInfo(verifies non-null quartet) andqueryFeatureFlags(verifies flags are returned on x86 Linux from/proc/cpuinfo).LinuxCentralProcessorTest — Added topology tests for:
node*directoriescache/index*DmidecodeTest — Added test verifying
queryBiosNameRevreturns a non-nullPair.WhoTest (new) — Tests the
Who.queryWho()command-line parser. May return empty on headless CI but verifies no exceptions and valid session fields when present.Testing
All 449 tests pass locally on Linux (Java 25). Spotless, checkstyle, and forbiddenapis all clean.
Summary by CodeRabbit