# Test your firmware

Automate firmware assertions with test suites, sweep boards and fault sets with test matrices, and opt in to silicon errata or cycle-approximate timing.

## Write a suite

Full suite schema and assertions in [File formats](https://circuittwin.ai/docs/formats#test-suite).

suite.yaml

```
schemaVersion: ct.test-suite/1
id: firmware-smoke
name: Firmware smoke test
defaults:
  board:
    id: nucleo-f767zi
cases:
  - id: boots
    name: Firmware boots and reports ready
    firmware:
      path: build/app.elf
    assertions:
      - kind: marker
        pass: READY
      - kind: no_fault
    tags: [smoke]
```

## Run a suite

terminal

```
ct test run suite.yaml --junit out/junit.xml --report out/
ct test run suite.yaml --tag smoke --workers 8
```

Select cases with `--filter TEXT` or `--tag TAG`, preview with `--list`, and set concurrency with `--workers`. For hosted CI runs, use `ct cloud suite run` ([Test in CI](https://circuittwin.ai/docs/ci)).

### Gate on regressions

terminal

```
ct test run suite.yaml --report out/ --baseline main-report.json --fail-on-regression
```

Fails if a previously passing case fails or its report digest shifts relative to your main-branch baseline.

## Run a test matrix

A matrix expands firmware, boards, scenarios, fault sets, input variation and seeds into unique cells and groups failures by root cause.

terminal

```
ct test matrix run power.matrix.yaml --list            # the cells; nothing runs
ct test matrix run power.matrix.yaml --out results/    # report.json, junit.xml, report.sarif, summary.md
ct test matrix run power.matrix.yaml --cloud           # on the hosted service
```

- Cached cells skip automatically; pass `--no-cache` to force execution.
- `--recheck` re-executes every cell and flags any mismatch as a determinism bug.
- `--cloud --no-wait` returns the matrix id immediately (poll via `ct test matrix status <ID>` and `ct test matrix report <ID>`). Executed hosted cells count toward your [weekly allowance](https://circuittwin.ai/docs/concepts#credits).

Schema in [File formats](https://circuittwin.ai/docs/formats#test-matrix); unit spread in [Inputs and faults](https://circuittwin.ai/docs/inputs#variation).

## Silicon errata

Errata are off by default. Enable them to verify firmware workarounds against documented silicon bugs.

terminal

```
ct errata list                                   # documents, parts and record counts
ct errata list STM32F767ZI --class modelled      # the records the twin can apply
ct errata show STM32F767ZI st.es0334.2.15.1      # one record, with its workaround
ct run firmware.elf --board nucleo-f767zi --until DONE --errata rev:Z
```

| Setting       | Behavior                                               |
| ------------- | ------------------------------------------------------ |
| off           | Datasheet behavior (default)                           |
| rev:<label>   | All modelled errata for that revision (e.g. rev:Z)     |
| rev:default   | All modelled errata for the latest documented revision |
| ids:<id>,<id> | Specific errata ids (1 to 64)                          |

Works via `--errata` on `ct run`, `errata: rev:Z` in suite cases, or on a matrix `engine` axis:

spi-bsy.matrix.yaml (excerpt)

```
engine:
- name: datasheet
- name: rev-z-errata
  errata: rev:Z
```

`--json` reports each applied erratum with document and page. Extract new errata PDFs via `ct errata extract`.

## Timing modes

- `functional` (default): Fixed cost per instruction class. Fast; best for logic, protocols and fault handling.
- `cycle-approximate`: Models core pipeline, flash wait states, prefetch, caches, TCMs and buses for busy-wait delays, bit-banged protocols and loop-counted timeouts.

terminal

```
ct run firmware.elf --board nucleo-f767zi --until DONE --timing cycle-approximate
ct gdb-server --board nucleo-f767zi --elf firmware.elf --timing cycle-approximate
```

Supported on `ct run` and `ct gdb-server`. Parts without a timing profile exit with the list of available profiles; runs print the active profile name.
