{"slug": "it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules", "title": "\"It compiles\" is not \"it works\": how we test AI-generated firmware against the rules you wrote", "summary": "MCUcraft detailed a verification pipeline that turns a user's plain-language device description into identified rules, has the firmware generator declare which file and function implement each rule, and then runs the compiled firmware on a PC bench against scenarios generated from the rules rather than the code. In a diesel tank example, 10 of 10 scenarios passed while one geometry-related rule was flagged as unproven by any scenario; a workshop air quality monitor example failed. The team noted that static checks only read the code's text, so green means \"not broken\" rather than \"does what you asked.", "body_md": "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\n\nThis post explains how MCUcraft checks that, what the check catches, and what it does not.\n\nYou 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\ncustom PCB.\"*\n\nBefore any code exists, those sentences become **rules with an identifier**, each one tied to the words you used: the CO2\n\nlimit at 1500 ppm, the buzzer, what happens when the sensor stops answering. Where you did not say something\n\n(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.\n\nThe firmware generator does not just write code. For every rule it **declares where it implemented it**: which file, which\n\nfunction. Then a deterministic check verifies the claim: the function exists, in that file. A rule that has no place in the\n\ncode is not silently dropped: it is reported.\n\nOn top of that, a set of checks reads the code itself: limits compared in the right direction, the state machine the\n\nproject declared, outputs that actually move, the power budget. They are useful, but they share a weakness we measured\n\nearly: **they read the text of the code**. Green means \"not broken\". It does not mean \"does what you asked\".\n\nSo the last check does not read the code: it **runs it**.\n\nThis is the stub the bench generates for the air quality monitor:\n\n```\n// src/parts.cpp as compiled on the PC (generated; helper names translated)\n#include \"parts.h\"\nfloat bench_value(const char* name);             // the scenario's value right now\nvoid  bench_command(const char* name, float v);  // logged with the simulated time\n\nvoid  parts_begin() {}\nfloat read_co2()            { return bench_value(\"co2\"); }\nfloat read_temperature()    { return bench_value(\"temperature\"); }\nvoid  drive_buzzer(bool on) { bench_command(\"buzzer\", on ? 1.0f : 0.0f); }\n```\n\nThe scenarios are written **from your rules, not from the code**: a model reads the project's sentences and the list of\n\nthings that can be measured and driven, and writes scripts like this one, from the diesel tank example:\n\n```\n{\n  \"name\": \"V-01.over\",\n  \"rules\": [\"A#0\", \"R-b8a7\", \"V-01\"],\n  \"assumptions\": [\"fuel_level below 20 %: just beyond -> alarm\"],\n  \"steps\": [\n    { \"t_ms\": 0,      \"set\": { \"fuel_level\": 20.0 } },\n    { \"t_ms\": 903000, \"set\": { \"fuel_level\": 19.8 } }\n  ],\n  \"expect\": [\n    { \"what\": \"alert\", \"sent\": true, \"from_ms\": 903000, \"to_ms\": 1806000, \"about\": \"fuel_level\" }\n  ]\n}\n```\n\nA quarter of an hour in, the level drops just below 20 %, and the alert must go out within the next 15 minutes. The model\n\nnever sees the firmware, so it cannot copy its mistakes. Each scenario also states the assumptions it made, because those\n\nare what you might want to correct.\n\nThe timing margin is set by the judge, not by the scenario: right after a value changes, the device gets the time it needs\n\nto read the sensor and react before anything counts as a failure.\n\nBesides the scenarios built from your rules, the same run checks a few things every device should do: outputs in a safe\n\nstate at power-on, values kept inside their limits, no surprises under random sequences of inputs.\n\n**Pass.** The diesel tank levels example (three tanks, one level sensor each, data every 15 minutes): the firmware compiles,\n\nand **10 of 10 scenarios pass** on the PC. One rule is listed as *not proven by any scenario*: it describes the tanks'\n\ngeometry and the router distance, which no behaviour test can check. The verdict says so instead of hiding it.\n\n**Fail.** The workshop air quality monitor. The scenario was:\n\nat 0 s CO2 = 1500 ppm · at 3 s CO2 = 1515 ppm · at 6 s CO2 = 1350 ppm\n\nexpected: buzzer **off** from 6 s to 9 s\n\nThe 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\n\nbuzzer **stayed on**. The project page shows exactly this, with the verdict *\"Firmware builds, some tests fail\"*. We did not\n\nre-run the generation until the verdict turned green and then show only that one: the example is public as it came out.\n\nEvery project shows one of four verdicts, with the reason:\n\n| verdict | what it means | \n|---|---|\n| Firmware passes its tests on the PC | it compiles and every scenario that ran passes; rules no scenario can prove are listed | \n| Firmware builds, some tests fail | it compiles, and at least one scenario fails: which one, with the script | \n| Firmware builds, not tested yet | it compiles, but some rules were not exercised by any scenario that ran | \n| Firmware does not build | the compiler's errors | \n\nWe measured it before turning it on. On a training glove we had checked by hand, the scenarios written by the model gave\n\nthe same verdict as ours in **12 of 12** cases, and the run showed that the exercise phase never started, although every\n\ncode-reading check was green. Then on four projects from earlier runs it found a real defect in **all four**, for example a\n\ngas valve that did not close from the phone, a compressor monitor that never counted its starts, and an oven that missed a\n\nshort button press.\n\nAnd one lesson that changed how we fix things. A firmware once had six `write_heater(false)` and no `true`: the heater never\n\nturned 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 \n\nThe firmware as a PlatformIO project (ZIP), the parts list as an Excel file or a KiCad-style CSV, and the KiCad files of the\n\nschematic and, when the project has one, of the board. You can open, build and change all of it without MCUcraft.\n\nThe firmware uses the Arduino framework, built with PlatformIO (the ESP32 Arduino core, STM32duino on STM32). Native ESP-IDF\n\nprojects or hand-written FreeRTOS tasks are not generated today.\n\nThe examples are public and open without an account: each one shows its parts list, board, firmware and verdict, green or\n\nnot. If you think a scenario is wrong, that is useful too: the scenario's assumptions are written next to it, and you can\n\ncorrect them in the chat.", "url": "https://wpnews.pro/news/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules", "canonical_source": "https://dev.to/mcucraft/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules-you-wrote-420i", "published_at": "2026-11-23 19:00:35+00:00", "updated_at": "2026-11-23 19:12:52.830098+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-safety", "developer-tools", "large-language-models"], "entities": ["MCUcraft", "STM32"], "also_reported_by": [], "takeaway": "Generate behavior test scenarios from the user's stated rules rather than from the generated code, so the test model never sees the firmware and cannot copy its mistakes, and report any rule no scenario proves.", "recommendation": {"advice": "Derive test scenarios from the spec's rules, not the implementation, and explicitly flag rules that no scenario can prove.", "playbook": "evals-testing", "playbook_url": "https://wpnews.pro/playbooks/evals-testing"}, "alternates": {"html": "https://wpnews.pro/news/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules", "markdown": "https://wpnews.pro/news/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules.md", "text": "https://wpnews.pro/news/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules.txt", "jsonld": "https://wpnews.pro/news/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules.jsonld"}}