Skip to content

Differentially test the pre-Windows-10 physical-memory fallback path - #3454

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:test-windows-memory-legacy-path
Jul 12, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:test-windows-memory-legacy-path

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

Summary

The pre-Windows-10 branch of WindowsGlobalMemory.getPhysicalMemory() (the Win32_PhysicalMemory query with the pre-10 MemoryType field, resolved via memoryType() instead of smBiosMemoryType()) has never executed on CI — the runners are all Windows 10+, so that else branch is dead on CI and its legacy query/field-mapping has drifted through several refactors untested since it was written on a Win7 VM years ago.

The recent memory dedup (#3453) incidentally made this testable: the version check is now an overridable protected isWindows10OrGreater() hook rather than an inlined static VersionHelpers read, so the legacy path can be forced against the real system without mocking a static native call.

Changes

  • WindowsGlobalMemoryJNA: dropped final (one word + a javadoc note) so a test can subclass it and override only the version gate, inheriting the genuine query hooks.
  • WindowsGlobalMemoryLegacyTest (new, @EnabledOnOs(WINDOWS)): builds the real class twice with isWindows10OrGreater() forced false and true, runs the real WMI query both ways, and asserts the legacy and modern results agree bank-for-bank on every schema-independent field — bank label, capacity, clock speed, manufacturer, part number, serial number. memoryType is intentionally excluded (the two schemas legitimately resolve it differently). Lists are sorted before comparison so WMI row order can't flake it; a runner reporting no banks still exercises the legacy branch.

Why differential (not fabricated tables)

The goal isn't coverage for its own sake — it's to exercise the real legacy query/parse on real hardware and catch a rotted path. Feeding canned WmiResult tables would only test the parser. Forcing the gate and diffing legacy-vs-modern on the same machine catches a broken legacy query (wrong field, wrong parse) as a concrete divergence.

A red result on the Windows runner is the intended signal that the legacy path diverged and needs a fix (either the path itself, or narrowing the comparison if some field legitimately differs pre-10).

Testing

  • Compiles clean; correctly skipped on non-Windows ([S] Disabled)
  • spotless / checkstyle / forbiddenapis / javadoc: clean; clean full-reactor build, 0 tests failed
  • The legacy path itself is validated by the Windows CI runners here

Pattern

Establishes a reusable approach for the consistency arc: seam the version/capability gate, then differential-test the legacy path against real data — to reapply on the Windows CPU counter-set selection (Processor vs ProcessorInformation) and the 32-bit uptime wrap when those subsystems are touched.

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility validation for Windows systems by verifying that legacy and modern memory detection paths report consistent physical memory details.
  • Tests

    • Added Windows-specific coverage for comparing memory bank information across supported operating system versions.

The pre-Windows-10 branch of WindowsGlobalMemory.getPhysicalMemory() has never
run on CI (runners are Windows 10+), so its legacy Win32_PhysicalMemory query
and field mapping have gone untested through several refactors. The recent
dedup made the version gate an overridable isWindows10OrGreater() hook, so the
legacy path can now be forced against the real system without mocking.

Drop `final` from WindowsGlobalMemoryJNA so a test can subclass it and override
only the version gate, inheriting the genuine query hooks. Add a Windows-only
differential test that runs the real WMI query with the gate forced both ways
and asserts the legacy and modern results agree bank-for-bank on every
schema-independent field (bank label, capacity, speed, manufacturer, part
number, serial number); memoryType is excluded because the two schemas resolve
it differently. Results are sorted before comparison so WMI row order can't
flake it, and empty-bank runners still exercise the legacy branch.

A red result on the Windows runner means the legacy path diverged from the
modern one -- exactly the class of bug this is meant to surface.
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

WindowsGlobalMemoryJNA can now be subclassed for version-gated tests. A Windows-only test compares physical-memory results from legacy and modern query paths while excluding memory type from equality checks.

Changes

Windows memory parity

Layer / File(s) Summary
Enable version-path substitution
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
Allows test subclasses of WindowsGlobalMemoryJNA and documents the intended version-gating use.
Compare legacy and modern memory queries
oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java
Forces legacy and modern paths, sorts physical-memory entries deterministically, and compares matching bank fields except memory type.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hops through Windows’ gate,
With memory banks aligned in state.
Legacy and modern paths agree,
Sorted neatly as carrots in a tree.
Type may differ—so let it be!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding differential tests for the pre-Windows-10 physical-memory fallback path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

Actionable comments posted: 1

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

Inline comments:
In
`@oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java`:
- Around line 30-31: Update the BY_BANK comparator to use null-safe ordering for
both PhysicalMemory::getBankLabel and PhysicalMemory::getSerialNumber, wrapping
each natural-order key comparator with nullsFirst. Preserve the existing
capacity comparison and comparator ordering.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2e3b1ceb-30e4-4fec-9693-3539f470cf8c

📥 Commits

Reviewing files that changed from the base of the PR and between 6aa6bb8 and ac59f59.

📒 Files selected for processing (2)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (16)
  • GitHub Check: CodeRabbit
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-06T04:45:47.644Z
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:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.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-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
🔇 Additional comments (2)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java (1)

26-31: LGTM!

oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java (1)

53-71: LGTM!

@codecov

codecov Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.62%. Comparing base (6aa6bb8) to head (ac59f59).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3454   +/-   ##
=========================================
  Coverage     74.61%   74.62%           
  Complexity       76       76           
=========================================
  Files           584      584           
  Lines         21923    21923           
  Branches       3679     3679           
=========================================
+ Hits          16357    16359    +2     
+ Misses         3529     3518   -11     
- Partials       2037     2046    +9     
Flag Coverage Δ
freebsd 26.85% <0.00%> (+<0.01%) ⬆️
linux 31.51% <0.00%> (-0.04%) ⬇️
macos 31.99% <0.00%> (-0.05%) ⬇️
openbsd 26.32% <0.00%> (+<0.01%) ⬆️
solaris 28.38% <0.00%> (+<0.01%) ⬆️
windows 39.78% <100.00%> (+0.06%) ⬆️

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.

@dbwiddis
dbwiddis merged commit f13e966 into oshi:master Jul 12, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the test-windows-memory-legacy-path branch July 12, 2026 22:05
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