Repository navigation
test(rmt4): Rmt4PeripheralMock + 22 host unit tests, no threads (#3462) - #3463
Conversation
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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughRemoves 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. ChangesRMT4 mock and tests
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Summary
Adds the host-side test seam the
IRMT4Peripheralwrapper from #3458 (PR #3461) was built for. MirrorsRmt5PeripheralMockexactly — abstract public class + concreteImplprivate to.cpp.hpp, singleton matching the real-hardware "one RMT peripheral" constraint, and single-threaded by design (nostd::thread, no condition variable, no async callbacks). Tests advance the simulation manually viasimulateThresholdInterrupt(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
What's NOT here (issue points 3–9)
The issue listed engine-integration tests that instantiate
ChannelEngineRMT4Implagainst the mock and exercise the threeacquireChannelstrategies, channel exhaustion viamPendingChannels, and theBUSY → READYpoll cycle. Those are blocked by a separate gap — the engine's IRAM ISR (handleInterrupt) referencesRMT.int_st.valandRMT.int_clr.valdirectly, 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.hplatform guard liftedThe interface header had
#if defined(FL_IS_ESP32) && ...around its entire body. That blocked host inclusion and would have made the mock unable to seeIRMT4Peripheralon a host build. Lifting it matchesIRMT5Peripheral, which has the same docblock comment ("This interface is platform-agnostic (no ESP32 guard)") and no guard. The concreteRmt4PeripheralESPkeeps 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 --Werrorclean on all four new + edited files.Rmt4PeripheralESPis unchanged).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests