Repository navigation
Add cross-platform tests for Windows and Mac utility methods - #3191
Conversation
Test pure lookup/mapping methods that are testable from any platform: - WindowsGlobalMemoryTest: memoryType() and smBiosMemoryType() switch statements covering all WMI and SMBIOS memory type codes - WindowsCentralProcessorTest: parseIdentifier() string parsing for Family/Model/Stepping extraction - ThreadInfoTest: ThreadStats constructor state mapping (all 7 states) and getter coverage Also add module-info.test opens for windows, mac, and mac driver test packages. 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 (1)
✅ Files skipped from review due to trivial changes (1)
📜 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)
📝 WalkthroughWalkthroughAdds unit tests for macOS thread parsing and Windows CPU/memory parsing, and extends the test module configuration to open additional macOS and Windows packages to JUnit for reflective access. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/test/java/oshi/driver/common/mac/ThreadInfoTest.java (1)
8-8: Consider asserting the deterministicupTimevalue.
greaterThan(0L)would still pass if the getter returned almost any positive value. With these constructor inputs, the computed value is deterministic, so this can catch regressions more directly.Proposed tightening
-import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; @@ assertThat(ts.getThreadId(), is(5)); assertThat(ts.getSystemTime(), is(1000L)); assertThat(ts.getUserTime(), is(2000L)); - assertThat(ts.getUpTime(), greaterThan(0L)); + assertThat(ts.getUpTime(), is(11976L)); assertThat(ts.getPriority(), is(20));Also applies to: 28-35
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-common/src/test/java/oshi/driver/common/mac/ThreadInfoTest.java` at line 8, The test currently asserts upTime with greaterThan(0L), which is too loose; compute the deterministic expected upTime from the ThreadInfo constructor inputs used in the test and replace the greaterThan assertion with a strict equality check (e.g., assertEquals(expectedUpTime, threadInfo.getUpTime()) or use equalTo(expectedUpTime) matcher). Update every occurrence (including the other assertions around lines 28-35) that use greaterThan(0L) to assert the exact expected upTime value for the ThreadInfo instances created in this test.oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGlobalMemoryTest.java (1)
15-46: Broaden these lookup tests to cover every switch arm.A few
memoryTypeand SMBIOS branches remain untested, so regressions in those mappings could still slip through. A small table-driven loop keeps this exhaustive without adding native/platform dependencies.Proposed table-driven expansion
`@Test` void testMemoryTypeKnownValues() { - assertThat(WindowsGlobalMemory.memoryType(0), is("Unknown")); - assertThat(WindowsGlobalMemory.memoryType(1), is("Other")); - assertThat(WindowsGlobalMemory.memoryType(2), is("DRAM")); - assertThat(WindowsGlobalMemory.memoryType(17), is("SDRAM")); - assertThat(WindowsGlobalMemory.memoryType(20), is("DDR")); - assertThat(WindowsGlobalMemory.memoryType(21), is("DDR2")); - assertThat(WindowsGlobalMemory.memoryType(22), is("BRAM")); - assertThat(WindowsGlobalMemory.memoryType(23), is("DDR FB-DIMM")); + String[] expected = { "Unknown", "Other", "DRAM", "Synchronous DRAM", "Cache DRAM", "EDO", "EDRAM", + "VRAM", "SRAM", "RAM", "ROM", "Flash", "EEPROM", "FEPROM", "EPROM", "CDRAM", "3DRAM", + "SDRAM", "SGRAM", "RDRAM", "DDR", "DDR2", "BRAM", "DDR FB-DIMM" }; + for (int type = 0; type < expected.length; type++) { + assertThat(WindowsGlobalMemory.memoryType(type), is(expected[type])); + } @@ `@Test` void testSmBiosMemoryTypeKnownValues() { - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x01), is("Other")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x03), is("DRAM")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x12), is("DDR")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x13), is("DDR2")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x14), is("DDR2 FB-DIMM")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x18), is("DDR3")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x1A), is("DDR4")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x1E), is("LPDDR4")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x22), is("DDR5")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x23), is("LPDDR5")); - assertThat(WindowsGlobalMemory.smBiosMemoryType(0x24), is("HBM3")); + Object[][] expected = { { 0x01, "Other" }, { 0x03, "DRAM" }, { 0x04, "EDRAM" }, { 0x05, "VRAM" }, + { 0x06, "SRAM" }, { 0x07, "RAM" }, { 0x08, "ROM" }, { 0x09, "FLASH" }, + { 0x0A, "EEPROM" }, { 0x0B, "FEPROM" }, { 0x0C, "EPROM" }, { 0x0D, "CDRAM" }, + { 0x0E, "3DRAM" }, { 0x0F, "SDRAM" }, { 0x10, "SGRAM" }, { 0x11, "RDRAM" }, + { 0x12, "DDR" }, { 0x13, "DDR2" }, { 0x14, "DDR2 FB-DIMM" }, { 0x18, "DDR3" }, + { 0x19, "FBD2" }, { 0x1A, "DDR4" }, { 0x1B, "LPDDR" }, { 0x1C, "LPDDR2" }, + { 0x1D, "LPDDR3" }, { 0x1E, "LPDDR4" }, { 0x1F, "Logical non-volatile device" }, + { 0x20, "HBM" }, { 0x21, "HBM2" }, { 0x22, "DDR5" }, { 0x23, "LPDDR5" }, + { 0x24, "HBM3" } }; + for (Object[] type : expected) { + assertThat(WindowsGlobalMemory.smBiosMemoryType((int) type[0]), is(type[1])); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGlobalMemoryTest.java` around lines 15 - 46, Extend the tests to cover every branch of the WindowsGlobalMemory.memoryType and WindowsGlobalMemory.smBiosMemoryType switch statements by replacing the scattered assertions in testMemoryTypeKnownValues, testMemoryTypeFallsBackToSmBios, and testSmBiosMemoryTypeKnownValues with table-driven loops: create maps/arrays of (inputValue -> expectedString) that include every mapped constant used in memoryType and smBiosMemoryType (including the values that trigger the SMBIOS fallback like 0x1A and the ones >23), iterate and assert each pair with the same assertThat(...) pattern; keep the existing test method names and use the unique symbols WindowsGlobalMemory.memoryType and WindowsGlobalMemory.smBiosMemoryType to locate the code to expand.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@oshi-common/src/test/java/oshi/driver/common/mac/ThreadInfoTest.java`:
- Line 8: The test currently asserts upTime with greaterThan(0L), which is too
loose; compute the deterministic expected upTime from the ThreadInfo constructor
inputs used in the test and replace the greaterThan assertion with a strict
equality check (e.g., assertEquals(expectedUpTime, threadInfo.getUpTime()) or
use equalTo(expectedUpTime) matcher). Update every occurrence (including the
other assertions around lines 28-35) that use greaterThan(0L) to assert the
exact expected upTime value for the ThreadInfo instances created in this test.
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGlobalMemoryTest.java`:
- Around line 15-46: Extend the tests to cover every branch of the
WindowsGlobalMemory.memoryType and WindowsGlobalMemory.smBiosMemoryType switch
statements by replacing the scattered assertions in testMemoryTypeKnownValues,
testMemoryTypeFallsBackToSmBios, and testSmBiosMemoryTypeKnownValues with
table-driven loops: create maps/arrays of (inputValue -> expectedString) that
include every mapped constant used in memoryType and smBiosMemoryType (including
the values that trigger the SMBIOS fallback like 0x1A and the ones >23), iterate
and assert each pair with the same assertThat(...) pattern; keep the existing
test method names and use the unique symbols WindowsGlobalMemory.memoryType and
WindowsGlobalMemory.smBiosMemoryType to locate the code to expand.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cba14d82-0355-4565-b01e-67218cc35ac1
📒 Files selected for processing (4)
oshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/driver/common/mac/ThreadInfoTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGlobalMemoryTest.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). (10)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, macos-latest
- 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: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
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.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-common/src/test/java/module-info.test
📚 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/module-info.test
📚 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/hardware/common/platform/windows/WindowsCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGlobalMemoryTest.java
📚 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/hardware/common/platform/windows/WindowsGlobalMemoryTest.javaoshi-common/src/test/java/oshi/driver/common/mac/ThreadInfoTest.java
🔇 Additional comments (4)
oshi-common/src/test/java/module-info.test (1)
13-18: Looks good.These test-only
--add-opensentries are narrowly scoped to the new package-level tests and avoid exposing implementation packages in production modules.oshi-common/src/test/java/oshi/driver/common/mac/ThreadInfoTest.java (1)
17-26: Good coverage of the state mapping.This exercises each switch outcome without invoking macOS-specific/native behavior.
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGlobalMemoryTest.java (1)
48-52: Good default-path coverage.This covers both the explicit SMBIOS unknown code and an unmapped value.
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsCentralProcessorTest.java (1)
14-31: Looks good.The tests cover successful extraction, missing keys, and the trailing-key edge case while staying platform-independent.
Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: Dan Widdis <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3191 +/- ##
==========================================
+ Coverage 57.98% 58.17% +0.18%
==========================================
Files 421 421
Lines 20272 20272
Branches 3563 3563
==========================================
+ Hits 11755 11793 +38
+ Misses 6750 6716 -34
+ Partials 1767 1763 -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:
|
Description
Tests pure lookup/mapping methods in Windows and Mac platform classes that are testable from any platform — no native calls or platform-specific APIs involved.
New test classes
WindowsGlobalMemoryTest — Tests
memoryType(int)andsmBiosMemoryType(int)switch statements covering WMI memory type codes (0-23) and SMBIOS type codes (DDR through HBM3, plus unknown/default). This file was at 3.3% coverage — the two methods are 58 lines of pure lookup logic.WindowsCentralProcessorTest — Tests
parseIdentifier(String, String)which extracts Family/Model/Stepping values from Windows processor identifier strings. Covers found, not-found, and key-at-end-of-string edge cases.ThreadInfoTest (Mac) — Tests
ThreadStatsconstructor state mapping for all 7 process states (Sleeping, Idle, Running, Waiting, Zombie, Stopped, Other) and getter methods.Also adds
--add-opensdirectives tomodule-info.testfor theoshi.hardware.common.platform.windows,oshi.hardware.common.platform.mac, andoshi.driver.common.macpackages.Testing
All 455 tests pass locally on Linux (Java 25). Spotless, checkstyle, and forbiddenapis all clean.
Summary by CodeRabbit
Tests
Chores