Skip to content

Test the Windows legacy GetSystemTimes system-CPU-tick path (JNA and FFM) - #3464

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:windows-legacy-counter-test
Jul 17, 2026
Merged

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

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Closes the last coverage gap from the CentralProcessor dedup arc: the Windows USE_LEGACY_SYSTEM_COUNTERS=true path.

What

querySystemCpuLoadTicks() has a legacy branch that reads idle/kernel/user times via GetSystemTimes (Kernel32 for JNA, Kernel32FFM for FFM). The IRQ/DPC half of that path (querySystemCounters) is already compared JNA==FFM, but the GetSystemTimes half — including how each backend interprets the raw FILETIME — had no test.

The flag is a static final capture, and the junit-platform plugin runs tests in-process (<executor>JAVA</executor>, no per-class fork), so a @BeforeAll config flip can't reliably force the path before the class loads. This follows the existing WindowsGlobalMemoryLegacyTest seam pattern instead:

  • Add an overridable useLegacySystemCounters() gate (returns the static flag); both twins call it instead of the raw field.
  • De-final WindowsCentralProcessorJNA/FFM so a test can subclass and force the gate.
  • One @EnabledOnOs(WINDOWS) test per backend forces the legacy path and asserts the ticks are sane (non-negative, non-zero idle and user time) and that the legacy total is within a generous tolerance of the modern per-processor sum — both measure cumulative CPU time since boot. A rotted native GetSystemTimes or FILETIME read surfaces as all-zero ticks or a wildly inconsistent total.

Running both backends closes the JNA==FFM parity transitively (each legacy ≈ its own modern, and the moderns are already compared equal).

Notes

No CHANGELOG — test-only plus an internal overridable seam; no behavior change. The assertions only run on the Windows CI runners; tolerances are kept generous since they can't be smoke-tested off-Windows.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows CPU load tick collection by making the legacy system-counter approach selectable and more reliably exercised.
  • Tests
    • Added Windows-only JUnit coverage for validating legacy CPU tick values, totals, and consistency against modern measurements (including both JNA and FFM paths).
  • Chores
    • Updated test module JVM options to ensure required Windows FFM packages can be accessed during the test run.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d390a659-9c3b-46b2-82f8-6af1fcd37271

📥 Commits

Reviewing files that changed from the base of the PR and between 8488049 and e04e300.

📒 Files selected for processing (6)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
  • oshi-core-ffm/src/test/java/module-info.test
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFMLegacyTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorJNA.java
  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsCentralProcessorLegacyTest.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsCentralProcessorLegacyTest.java
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFMLegacyTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (1)
📚 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-ffm/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
🔇 Additional comments (2)
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java (1)

47-50: LGTM!

Also applies to: 172-172

oshi-core-ffm/src/test/java/module-info.test (1)

23-24: LGTM!


📝 Walkthrough

Walkthrough

Windows CPU processor implementations now use an overridable legacy-counter selection method. JNA and FFM classes support subclassing, and Windows-only tests validate legacy tick values and totals against modern counters.

Changes

Windows counter selection

Layer / File(s) Summary
Overrideable counter-selection contract
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
Adds the protected useLegacySystemCounters() hook backed by the existing configuration flag.
Backend routing and legacy-path validation
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorJNA.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java, oshi-core/src/test/.../WindowsCentralProcessorLegacyTest.java, oshi-core-ffm/src/test/.../WindowsCentralProcessorFFMLegacyTest.java, oshi-core-ffm/src/test/java/module-info.test
Allows backend subclassing, routes both legacy branches through the hook, opens the FFM Windows package for tests, and validates legacy tick arrays and totals against modern counters.

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

Poem

A rabbit hopped through counters bright,
And nudged the legacy path to light.
JNA and FFM followed the trail,
While ticks stayed whole and totals prevailed.
“Good tests,” he thumped, “the old code is hale!”

🚥 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 Windows legacy GetSystemTimes CPU-tick tests for both JNA and FFM backends.
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.

@codecov

codecov Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.25%. Comparing base (bc6e8a7) to head (8488049).

Files with missing lines Patch % Lines
...e/platform/windows/WindowsCentralProcessorFFM.java 0.00% 2 Missing ⚠️
...mmon/platform/windows/WindowsCentralProcessor.java 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (40.00%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@              Coverage Diff              @@
##             master    #3464       +/-   ##
=============================================
- Coverage     74.95%   62.25%   -12.71%     
  Complexity       76       76               
=============================================
  Files           587      587               
  Lines         21603    21604        +1     
  Branches       3611     3611               
=============================================
- Hits          16192    13449     -2743     
- Misses         3432     6524     +3092     
+ Partials       1979     1631      -348     
Flag Coverage Δ
freebsd 27.44% <0.00%> (+0.01%) ⬆️
linux 31.95% <0.00%> (-0.02%) ⬇️
macos 32.44% <0.00%> (-0.05%) ⬇️
openbsd 26.78% <0.00%> (-0.02%) ⬇️
solaris 29.09% <0.00%> (-0.01%) ⬇️
windows 32.68% <66.66%> (-8.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.

…FFM)

The USE_LEGACY_SYSTEM_COUNTERS=true path in querySystemCpuLoadTicks() reads
idle/kernel/user times via GetSystemTimes (Kernel32 for JNA, Kernel32FFM for
FFM) and was not exercised by any test. The IRQ/DPC half (querySystemCounters)
is already compared JNA==FFM; this covers the remaining GetSystemTimes half.

Because the flag is a static-final capture and the junit-platform plugin runs
tests in-process (no per-class fork), a @BeforeAll config flip can't reliably
force the path. Instead, follow the WindowsGlobalMemoryLegacyTest seam pattern:
add an overridable useLegacySystemCounters() gate (returning the static flag),
switch both twins to call it, and de-final the twins so a test can subclass and
force the legacy path against the real system.

Add one @EnabledOnOs(WINDOWS) test per backend that forces the legacy path and
asserts the ticks are sane (non-negative, non-zero idle and user time) and that
the legacy total is within a generous tolerance of the modern per-processor sum
(both measure cumulative CPU time since boot). A rotted native GetSystemTimes or
FILETIME read surfaces as all-zero ticks or a wildly inconsistent total rather
than as a mere coverage number.
@dbwiddis
dbwiddis force-pushed the windows-legacy-counter-test branch from 8488049 to e04e300 Compare July 17, 2026 05:02
@dbwiddis
dbwiddis merged commit 6976275 into oshi:master Jul 17, 2026
17 of 18 checks passed
@dbwiddis
dbwiddis deleted the windows-legacy-counter-test branch July 17, 2026 05:08
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