Skip to content

[MED] Fault-emit validation test — intentionally OOM / stack-blow to assert the device emits proper error #3302

Closed

Description

@zackees

Motivation

The on-device crash detection traps being added across FastLED/fbuild/Arduino-core (FastLED/framework-arduino-lpc8xx#30 HardFault override; #3301 OOM-allocator emit; #3300 Step F watchdog wiring) are diagnostic safety nets -- when they fire, the user sees a useful error instead of silent infinite-loop. But there's no way to validate that the safety nets actually work without intentionally triggering them.

This issue adds a small bring-up sketch (or AutoResearch RPC method) that deliberately causes a fault and asserts the device emits the expected diagnostic. Two trigger paths:

  1. Intentional OOM: new char[16 * 1024 * 1024] -- allocate 16 MB. On any embedded target with <= 1 MB RAM this is guaranteed to fail.
  2. Stack blow: infinite recursive function. On a 4 KB stack (LPC845 default), this hits the stack-limit within microseconds and triggers a HardFault.

Either trigger should produce the expected emit:

If neither emits, the safety nets are broken; the test fails and that's a real bug.

Why this is bring-up-critical

When the user (or a future agent) runs bash autoresearch lpc845brk and sees an empty RX: b'' response, the immediate question is: "did the firmware crash, or is something else wrong?". If the crash-detection traps work, we get an immediate FAULT: ... line and can decode the cause in seconds. If they DON'T work (e.g. a future change accidentally regresses the HardFault override back to weak alias), the user is back to "silent failure = ambiguous root cause" and may waste hours debugging the wrong layer.

The test catches regressions in the safety nets. Without it, the safety nets are write-only code -- we trust them until they silently break.

Proposed design

Test as an autoresearch RPC method

Add two new methods to examples/AutoResearch/AutoResearchLowMemory.h -- only registered when FASTLED_AUTORESEARCH_FAULT_TEST=1:

#if defined(FASTLED_AUTORESEARCH_FAULT_TEST)
    remote.bind("trigger_oom", [](void) -> bool {
        // 16 MB -- guaranteed to fail on any embedded target. Use `new char[]`
        // rather than the fl-allocator chokepoint so the test exercises the
        // platform allocator path too (catches breakage in Arduino-core OOM
        // trap separately from FastLED's allocator wrapper).
        volatile char* p = new char[16 * 1024 * 1024];
        // If this returns, the trap is broken -- p will be nullptr.
        // The expected behavior: emit_oom fires before this lambda returns,
        // followed by AIRCR.SYSRESETREQ. The caller never sees the return.
        return p != nullptr;
    });

    remote.bind("trigger_stackblow", [](void) -> bool {
        return recurse_forever(0);  // see helper
    });
    static bool recurse_forever(int depth) FL_NO_INLINE {
        volatile uint8_t pad[64];  // 64 B per frame to burn stack quickly
        pad[0] = static_cast<uint8_t>(depth);
        return recurse_forever(depth + 1) && pad[0] != 0;
    }
#endif

The FL_NO_INLINE is load-bearing -- without it the compiler elides the recursion and the test does nothing.

Host-side assertion

bash autoresearch lpc845brk --fault-emit-test (or a new top-level harness flag) does:

  1. Build with -DFASTLED_AUTORESEARCH_FAULT_TEST=1.
  2. Flash, reset, wait for ready.
  3. Send {"method":"trigger_oom","id":1}.
  4. Wait up to 5 s for serial output.
  5. Assert the output contains a line matching ^FAULT: (OOM size=0x[0-9A-F]+|HardFault PC=0x[0-9A-F]+).
  6. Re-flash + reset (fresh firmware).
  7. Send {"method":"trigger_stackblow","id":2}.
  8. Assert similar emit line.

If both pass, the safety nets work. If either fails, the harness emits a P0 alert -- crash detection is broken, future bring-up debugging will be back to "silent hang = no information".

Optional: also test fault-during-fault recursion

Stretch goal -- not required for the initial test. If we want to validate the fault-during-emit fallback (chip should lock-up reset rather than infinite-loop), add a trigger_double_fault that causes a fault inside the fault handler's emit path. Assertion: the chip reboots within ~50 ms (lock-up reset behavior) and the next boot's Watchdog::lastResetCause() reports SOFTWARE.

Acceptance criteria

  • FASTLED_AUTORESEARCH_FAULT_TEST build flag adds the two trigger methods to AutoResearch's RPC table.
  • Autoresearch harness has a --fault-emit-test mode that flashes the test build, triggers each fault, and asserts the expected emit pattern.
  • Test passes on LPC845-BRK (the immediate validation target). Test passes on at least one other low-memory platform once [LOW] In-FastLED OOM allocator wrapper — diagnostic emit at allocation site (complement to LPC8xx#30) #3301 ships for it (proves the FastLED-side emit hook works cross-platform).
  • Test runs in CI on the LPC845 canary (or whatever CI surface exists for it -- if none today, file a follow-on for that).
  • Documentation in agents/docs/hardware-autoresearch.md explains the fault-emit test and what to do if it fails (the safety nets are broken; consult the linked issues to figure out which layer regressed).

Priority

Medium. Not blocking #3102 / #3300, but should land soon after the safety nets do -- there's a 2-week window between "trap shipped" and "trap silently regressed" where this test catches the regression cheaply. Without the test, regression is caught only when the next bring-up gets a silent hang and the user has to re-investigate from scratch.

Out of scope

  • Fault types beyond OOM and stack blow (e.g. unaligned access, divide-by-zero on M4/M7, MPU violation). The two chosen triggers exercise the two highest-leverage emit paths (OOM trap + HardFault override). Other fault types share the HardFault path and don't add new coverage.
  • Testing the watchdog-fired emit (Step F.2 in [BLOCKER] LPC845-BRK AutoResearch bring-up echo returns empty RX (suspected HardFault) — blocks #3102 #3300). That requires staging a known infinite-loop and waiting 3 s for WWDT to fire -- doable but a separate harness shape; file as a follow-up.
  • Crash-log persistence verification (not yet implemented on LPC; will be its own issue if we add retention-RAM-backed crash dumps).

Refs

Filed alongside #3301 during /clud-fix burn-down on #3208.

Activity

  1. zackees commented on Jun 23, 2026

    @zackees
    MemberAuthor

    Tracking this under the new LPC845-BRK / LPC8xx AutoResearch coordination meta: #3348.

    Keeping this issue open for now as optional LPC8xx validation safety-net work. If fault-emit validation is deferred, close this separately with rationale from #3348 rather than folding it silently into the meta.

  2. zackees commented on Jul 6, 2026

    @zackees
    MemberAuthor

    Rolled up under the active LPC845-BRK meta #3348 and attached there as a GitHub sub-issue.

    Next agent: implement or verify this locally on the attached LPC845-BRK. Capture the exact command, serial port, and observed FAULT: diagnostic/recovery output before closing this issue.

  3. moved this from Triage to Done in FastLED Trackeron Jul 6, 2026
  4. zackees commented on Jul 6, 2026

    @zackees
    MemberAuthor

    Completed via #3615 and verified again after merge on master (298830fed2).

    Post-merge local validation on attached LPC845-BRK / COM10:

    fbuild port scan
    bash autoresearch lpc845 --fault-emit-test --upload-port COM10 --timeout 120s --skip-lint

    Evidence: build/deploy succeeded, the harness re-flashed between triggers, and both intentional fault RPCs emitted diagnostics:

    • trigger_oom: FAULT: HardFault PC=0x10001E70 LR=0xFFFFFFF9 xPSR=0x10000020
    • trigger_stackblow: FAULT: HardFault PC=0x10002FC0 LR=0xFFFFFFF9 xPSR=0x00000000

    Harness verdict: PASS - #3302 fault emit validation confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions