Skip to content

test(rmt4): Rmt4PeripheralMock + 22 host unit tests, no threads (#3462) - #3463

Merged
zackees merged 1 commit into
masterfrom
feat/3462-rmt4-peripheral-mock
Jun 30, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3462-rmt4-peripheral-mock

Conversation

@zackees

@zackees zackees commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the host-side test seam the IRMT4Peripheral wrapper from #3458 (PR #3461) was built for. Mirrors Rmt5PeripheralMock exactly — abstract public class + concrete Impl private to .cpp.hpp, singleton matching the real-hardware "one RMT peripheral" constraint, and single-threaded by design (no std::thread, no condition variable, no async callbacks). Tests advance the simulation manually via simulateThresholdInterrupt(ch) / simulateTxDoneInterrupt(ch) which invoke the stored ISR handler synchronously on the test thread. The peer mocks (rmt5, uart, flexio, parlio, i2s_lcd_cam, objectfled, lpuart) all follow the same pattern.

Closes #3462.

Coverage — 22 tests, all pass

[doctest] test cases: 22 | 22 passed | 0 failed
Group Cases
Channel lifecycle recording configure / install+uninstall / threshold-intr / tx-intr / setGpio / multi-channel independence
ISR cookie symmetry install returns unique non-null cookie / free clears registration / free-then-install hands back fresh cookie / nullptr+stale cookies are no-ops / null out_handle returns false
Simulation API (single-threaded) threshold fires handler / tx-done fires handler / simulate without handler is no-op / multiple sims accumulate count
Error injection every fallible call (configure / install / threshold-intr / tx-intr / gpio / installIsr) returns false when the knob is set; state stays untouched
Reset clears per-channel state, ISR registration, error flags, invocation count, sentinels (cookies intentionally stay monotonic across resets)

What's NOT here (issue points 3–9)

The issue listed engine-integration tests that instantiate ChannelEngineRMT4Impl against the mock and exercise the three acquireChannel strategies, channel exhaustion via mPendingChannels, and the BUSY → READY poll cycle. Those are blocked by a separate gap — the engine's IRAM ISR (handleInterrupt) references RMT.int_st.val and RMT.int_clr.val directly, neither of which exists on the host build. Adding host stubs for the RMT register globals is a follow-up of its own; the mock's contract (what the wrapper exists to support) is fully covered here.

Side change — irmt4_peripheral.h platform guard lifted

The interface header had #if defined(FL_IS_ESP32) && ... around its entire body. That blocked host inclusion and would have made the mock unable to see IRMT4Peripheral on a host build. Lifting it matches IRMT5Peripheral, which has the same docblock comment ("This interface is platform-agnostic (no ESP32 guard)") and no guard. The concrete Rmt4PeripheralESP keeps its own guard — that's where the ESP-IDF types come in. No other call sites changed.

Test plan

  • bash test rmt4_peripheral_mock --cpp --clean — 22 / 22 pass on a fresh build.
  • bash test --cpp — full host suite 340 / 340 pass.
  • clang-format --dry-run --Werror clean on all four new + edited files.
  • On-device validation N/A (the mock is host-only; the production Rmt4PeripheralESP is unchanged).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added broader host-side support for simulating peripheral behavior, including interrupt handling and channel state tracking.
    • Expanded platform compatibility so the interface is available in more build environments.
  • Tests

    • Added coverage for simulated interrupts, channel lifecycle events, error handling, and reset behavior.
    • Verified isolation across channels and correct registration behavior for interrupt callbacks.

Adds the host-side test seam the `IRMT4Peripheral` wrapper from #3458
was built for. Mirrors `Rmt5PeripheralMock` exactly:

  - Abstract public class, concrete `Rmt4PeripheralMockImpl` private
    to the .cpp.hpp.
  - Singleton via `fl::Singleton<Impl>` matching the real-hardware
    constraint (one RMT peripheral per chip).
  - Single-threaded by design. No std::thread, no condition variable,
    no async callbacks. Tests advance the simulation manually via
    `simulateThresholdInterrupt(ch)` / `simulateTxDoneInterrupt(ch)`
    which invoke the stored ISR handler synchronously on the test
    thread. The peer mocks (rmt5, uart, flexio, parlio, i2s_lcd_cam,
    objectfled, lpuart) all follow the same constraint — races and
    timing-coupled assertions are avoided.
  - Error-injection knobs for every fallible IRMT4Peripheral entry
    point: configure, install, threshold-intr-enable, tx-intr-enable,
    gpio, install-isr.
  - Read-only state inspection (`getChannelState(ch)`,
    `isIsrRegistered()`, `getRegisteredIsrHandler()`,
    `getRegisteredIsrArg()`, `isrInvocationCount()`,
    `lastSimulatedKind()`, `lastSimulatedChannel()`).
  - `reset()` returns the mock to a clean state between tests
    (intentionally keeps cookies monotonically unique so caller
    aliasing bugs are still detectable across reset boundaries).

## Tests

22 FL_TEST_CASE definitions in
`tests/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.cpp`,
gated on `FASTLED_STUB_IMPL`. All pass:

  [doctest] test cases: 22 | 22 passed | 0 failed

Coverage:

  - configureChannel / installDriver / uninstallDriver /
    setTxThresholdIntrEnable / setTxIntrEnable / setGpio each record
    exact arguments into per-channel `Rmt4ChannelMockState`.
  - Multiple channels record independently.
  - installIsr returns a unique non-null cookie; freeIsr only clears
    when the issued cookie is passed back; freeIsr(nullptr) and
    freeIsr(stale-cookie) are no-ops.
  - simulateThresholdInterrupt + simulateTxDoneInterrupt fire the
    stored handler synchronously with the right arg.
  - simulate*Interrupt without a registered handler is a no-op (does
    not crash, does not bump invocation count).
  - Every error-injection knob makes the corresponding call return
    false and leaves the mock state untouched.
  - reset() clears per-channel state, ISR registration, error flags,
    invocation count, and last-simulation sentinels.

## Out-of-scope notes (in the issue's points 3-9)

The issue listed engine-integration tests that instantiate
`ChannelEngineRMT4Impl` against the mock and exercise the three
acquireChannel strategies + channel exhaustion + the BUSY→READY
poll cycle. Those are blocked by a separate gap: the engine's IRAM
ISR (`handleInterrupt`) references `RMT.int_st.val` and
`RMT.int_clr.val` directly, which don't exist on the host build.
Adding host-side stubs for the RMT register globals is a follow-up
task in its own right and not in scope for this PR. The mock's own
contract — which is what the wrapper exists to support — is fully
covered here.

## Side change: lift the FL_IS_ESP32 guard from irmt4_peripheral.h

The interface header had `#if defined(FL_IS_ESP32) && ...` around
the entire body. That blocked host inclusion and would have made the
mock unable to see `IRMT4Peripheral` on a host build. Lifting it
matches `IRMT5Peripheral`, which has the same docblock comment
("This interface is platform-agnostic (no ESP32 guard)") and no
guard. The concrete `Rmt4PeripheralESP` keeps its platform guard —
that's where the ESP-IDF types come in.

Closes #3462.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1b1ff47d-836e-4a42-8ad0-2b3091e89e62

📥 Commits

Reviewing files that changed from the base of the PR and between ddbadc4 and a76b13c.

📒 Files selected for processing (5)
  • src/platforms/esp/32/drivers/rmt/rmt_4/irmt4_peripheral.h
  • src/platforms/shared/mock/esp/32/drivers/_build.cpp.hpp
  • src/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.cpp.hpp
  • src/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.h
  • tests/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.cpp

📝 Walkthrough

Walkthrough

Removes ESP32-only preprocessor gating from the IRMT4Peripheral header to make it platform-agnostic. Adds a new host-only Rmt4PeripheralMock interface and implementation supporting channel configuration, ISR cookie-based install/free, synchronous interrupt simulation, and error injection, wires it into the unity mock build, and adds a comprehensive unit test suite.

Changes

RMT4 mock and tests

Layer / File(s) Summary
Platform-agnostic header
src/platforms/esp/32/drivers/rmt/rmt_4/irmt4_peripheral.h
Removes ESP32 feature-flag gating includes and the closing #endif so the interface is unconditionally visible for host builds.
Mock interface contract
src/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.h
Defines Rmt4ChannelMockState and the abstract Rmt4PeripheralMock class with lifecycle overrides, simulation, error-injection, inspection, and reset APIs.
Mock implementation and build wiring
src/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.cpp.hpp, src/platforms/shared/mock/esp/32/drivers/_build.cpp.hpp
Implements Rmt4PeripheralMockImpl with per-channel state, ISR cookie issuance/freeing, interrupt simulation, error injection, reset, and a singleton instance(); includes the new implementation in the unity mock build.
Unit tests
tests/platforms/shared/mock/esp/32/drivers/rmt4_peripheral_mock.cpp
Adds tests for channel lifecycle recording, ISR cookie symmetry, synchronous interrupt simulation, error-injection failure paths, and reset() behavior.

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant Rmt4PeripheralMock
  participant InstalledISR

  Test->>Rmt4PeripheralMock: configureChannel(cfg) / installDriver(channel)
  Rmt4PeripheralMock-->>Test: success or injected failure
  Test->>Rmt4PeripheralMock: installIsr(handler, arg, outHandle)
  Rmt4PeripheralMock-->>Test: unique non-null cookie
  Test->>Rmt4PeripheralMock: simulateThresholdInterrupt(channel)
  Rmt4PeripheralMock->>InstalledISR: invokeIsr(handler, arg)
  Rmt4PeripheralMock-->>Test: updates lastSimulatedKind/Channel, isrInvocationCount
  Test->>Rmt4PeripheralMock: freeIsr(cookie)
  Rmt4PeripheralMock-->>Test: clears registration if cookie matches
  Test->>Rmt4PeripheralMock: reset()
  Rmt4PeripheralMock-->>Test: clears channel state, ISR, flags, counters
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit hops through RMT halls,
No threads, no locks, just simple calls. 🐇
Cookies issued, ISRs ring true,
Reset clears the carrots through and through.
Mocked and tested, channels free—
A burrow built for safe RMT4 simulacre. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 the Rmt4PeripheralMock and host unit tests.
Linked Issues check ✅ Passed The changes align with the issue goals by adding a host-only RMT4 mock, single-threaded ISR simulation, and host unit tests.
Out of Scope Changes check ✅ Passed The changes stay within the requested mock, test, and host-build seam work with no obvious unrelated additions.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3462-rmt4-peripheral-mock

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.

@zackees
zackees merged commit 7ba7725 into master Jun 30, 2026
8 of 11 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 30, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 30, 2026
@zackees
zackees deleted the feat/3462-rmt4-peripheral-mock branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add Rmt4PeripheralMock + unit tests (no threads) — follow-up to #3458

1 participant