# "It compiles" is not "it works": how we test AI-generated firmware against the rules you wrote

> Source: <https://dev.to/mcucraft/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules-you-wrote-420i>
> Published: 2026-11-23 19:00:35+00:00

**Recommendation:** Derive test scenarios from the spec's rules, not the implementation, and explicitly flag rules that no scenario can prove.
More in the playbook "Evals and testing for LLM apps": <https://wpnews.pro/playbooks/evals-testing>

When an AI writes firmware for your device, the first question is not "is the code pretty?". It is: **does the device do what I asked?** A firmware that compiles, passes a linter and reads well can still leave the heater off forever, never close

This post explains how MCUcraft checks that, what the check catches, and what it does not.

You describe the device in a chat: *"Air quality monitor for my workshop, on an STM32. It measures CO2, temperature and humidity, shows them on a small OLED display, and sounds a buzzer when CO2 goes above 1500 ppm. Powered from USB-C. I want a
custom PCB."*

Before any code exists, those sentences become **rules with an identifier**, each one tied to the words you used: the CO2

limit at 1500 ppm, the buzzer, what happens when the sensor stops answering. Where you did not say something

(how far below 1500 ppm the alarm should clear, for example), the generator picks a value and **writes it down as an assumption**, in the code and in the project, so you can correct it.

The firmware generator does not just write code. For every rule it **declares where it implemented it**: which file, which

function. Then a deterministic check verifies the claim: the function exists, in that file. A rule that has no place in the

code is not silently dropped: it is reported.

On top of that, a set of checks reads the code itself: limits compared in the right direction, the state machine the

project declared, outputs that actually move, the power budget. They are useful, but they share a weakness we measured

early: **they read the text of the code**. Green means "not broken". It does not mean "does what you asked".

So the last check does not read the code: it **runs it**.

This is the stub the bench generates for the air quality monitor:

```
// src/parts.cpp as compiled on the PC (generated; helper names translated)
#include "parts.h"
float bench_value(const char* name);             // the scenario's value right now
void  bench_command(const char* name, float v);  // logged with the simulated time

void  parts_begin() {}
float read_co2()            { return bench_value("co2"); }
float read_temperature()    { return bench_value("temperature"); }
void  drive_buzzer(bool on) { bench_command("buzzer", on ? 1.0f : 0.0f); }
```

The scenarios are written **from your rules, not from the code**: a model reads the project's sentences and the list of

things that can be measured and driven, and writes scripts like this one, from the diesel tank example:

```
{
  "name": "V-01.over",
  "rules": ["A#0", "R-b8a7", "V-01"],
  "assumptions": ["fuel_level below 20 %: just beyond -> alarm"],
  "steps": [
    { "t_ms": 0,      "set": { "fuel_level": 20.0 } },
    { "t_ms": 903000, "set": { "fuel_level": 19.8 } }
  ],
  "expect": [
    { "what": "alert", "sent": true, "from_ms": 903000, "to_ms": 1806000, "about": "fuel_level" }
  ]
}
```

A quarter of an hour in, the level drops just below 20 %, and the alert must go out within the next 15 minutes. The model

never sees the firmware, so it cannot copy its mistakes. Each scenario also states the assumptions it made, because those

are what you might want to correct.

The timing margin is set by the judge, not by the scenario: right after a value changes, the device gets the time it needs

to read the sensor and react before anything counts as a failure.

Besides the scenarios built from your rules, the same run checks a few things every device should do: outputs in a safe

state at power-on, values kept inside their limits, no surprises under random sequences of inputs.

**Pass.** The diesel tank levels example (three tanks, one level sensor each, data every 15 minutes): the firmware compiles,

and **10 of 10 scenarios pass** on the PC. One rule is listed as *not proven by any scenario*: it describes the tanks'

geometry and the router distance, which no behaviour test can check. The verdict says so instead of hiding it.

**Fail.** The workshop air quality monitor. The scenario was:

at 0 s CO2 = 1500 ppm · at 3 s CO2 = 1515 ppm · at 6 s CO2 = 1350 ppm

expected: buzzer **off** from 6 s to 9 s

The firmware's own assumption is that the alarm clears at or below 1450 ppm, and 1350 ppm is well below it. On the PC the

buzzer **stayed on**. The project page shows exactly this, with the verdict *"Firmware builds, some tests fail"*. We did not

re-run the generation until the verdict turned green and then show only that one: the example is public as it came out.

Every project shows one of four verdicts, with the reason:

| verdict | what it means | 
|---|---|
| Firmware passes its tests on the PC | it compiles and every scenario that ran passes; rules no scenario can prove are listed | 
| Firmware builds, some tests fail | it compiles, and at least one scenario fails: which one, with the script | 
| Firmware builds, not tested yet | it compiles, but some rules were not exercised by any scenario that ran | 
| Firmware does not build | the compiler's errors | 

We measured it before turning it on. On a training glove we had checked by hand, the scenarios written by the model gave

the same verdict as ours in **12 of 12** cases, and the run showed that the exercise phase never started, although every

code-reading check was green. Then on four projects from earlier runs it found a real defect in **all four**, for example a

gas valve that did not close from the phone, a compressor monitor that never counted its starts, and an oven that missed a

short button press.

And one lesson that changed how we fix things. A firmware once had six `write_heater(false)` and no `true`: the heater never

turned on. The model had not made a mistake: the contract told it *"when temperature leaves its declared limits, turn the heater off"*, and on a temperature 

The firmware as a PlatformIO project (ZIP), the parts list as an Excel file or a KiCad-style CSV, and the KiCad files of the

schematic and, when the project has one, of the board. You can open, build and change all of it without MCUcraft.

The firmware uses the Arduino framework, built with PlatformIO (the ESP32 Arduino core, STM32duino on STM32). Native ESP-IDF

projects or hand-written FreeRTOS tasks are not generated today.

The examples are public and open without an account: each one shows its parts list, board, firmware and verdict, green or

not. If you think a scenario is wrong, that is useful too: the scenario's assumptions are written next to it, and you can

correct them in the chat.
