Fault Injection & Debugging

# Catching uninitialized SRAM and nondeterminism with --recheck

Flaky firmware tests hide real silicon bugs. Run --recheck in CI to verify every test trace is bit-for-bit reproducible.

A local variable left uninitialized on the stack or a buffer outside .bss often happens to read zero on one debugger session and crashes in production after a warm reset.

CircuitTwin runs with deterministic virtual clocks and provides --recheck to execute your suite twice and fail immediately if console output or exit state diverges.

## Nondeterminism bugs caught by --recheck

| Bug class              | Why benches hide it              | How --recheck catches it                         |
| ---------------------- | -------------------------------- | ------------------------------------------------ |
| Missing .bss zero loop | Debugger pre-zeroes SRAM on load | Divergent state across clean twin boots          |
| ISR/main shared global | Slow manual stepping masks race  | Exact instruction-level replay exposes race      |
| Unseeded PRNG in test  | Passes 9 of 10 bench runs        | Pinned seed vs --recheck flags drift immediately |

## Local CLI workflow

Shell - run deterministic double-check

```
ct test run --json --recheck --junit results/det.xml tests/app.suite.yaml
```

## Suite & fault configuration

tests/app.suite.yaml

```
version: 1
board: nucleo-f767zi
firmware: build/app.elf
tests:
  - name: deterministic-control-loop
    seed: 1337
    timeout_ms: 2500
    expect:
      console_contains: "LOOP_CHECKSUM_OK"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/determinism-ci.yml

```
name: Determinism Recheck CI
on: [push, pull_request]
jobs:
  recheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: make -j
      - uses: circuittwin/action@v1
        with:
          suite: tests/app.suite.yaml
          args: "--recheck"
```

## Troubleshooting checklist

| Symptom                                   | Fix                                                                                          |
| ----------------------------------------- | -------------------------------------------------------------------------------------------- |
| Firmware reads garbage after soft reset   | Verify Reset\_Handler zeroes the full range from \_sbss to \_ebss before calling main().     |
| ISR counter skips increments occasionally | Use atomic LDREX/STREX or critical-section PRIMASK guards around read-modify-write counters. |

## Frequently asked questions

| Question                            | Answer                                                                                                                                                             |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| What does ct test run --recheck do? | It executes the test suite twice and compares verdicts and deterministic outputs to guarantee your test does not depend on host scheduling or uninitialized state. |

## Related boards & component twins

[Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: stm32f4-discovery](https://circuittwin.ai/boards/stm32f4-discovery) [Board: nrf52840-dk](https://circuittwin.ai/boards/nrf52840-dk) [Twin: BMI088](https://circuittwin.ai/twins/bmi088) [Twin: BME280](https://circuittwin.ai/twins/bme280) [Determinism & --recheck docs](https://circuittwin.ai/docs/testing)

## More in Fault Injection & Debugging

[I2C NACK and stuck-bus fault injection in CI](https://circuittwin.ai/guides/i2c-nack-fault-injection) [SPI bus fault testing and chip-select verification](https://circuittwin.ai/guides/spi-bus-fault-testing) [Debugging UART baud mismatches and framing errors](https://circuittwin.ai/guides/uart-baud-mismatch-debugging) [Cortex-M HardFault triage in CI and reverse GDB](https://circuittwin.ai/guides/cortex-m-hardfault-ci-triage)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
