/qa-embedded:qemu-system-test-runnerfrom qa-embedded
Runs cross-compiled embedded test binaries on QEMU system emulation for ARM Cortex-M/A and RISC-V targets. Handles machine/CPU selection, ELF loading, semihosting exit codes, GDB/QMP, and CI integration.
Ships in qa-embedded. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
QEMU system emulation (per
qemu.org system docs)
runs cross-compiled ELF test binaries on virtual MCUs and SoCs.
The embedded-relevant binaries are qemu-system-arm,
qemu-system-aarch64, qemu-system-riscv32, and
qemu-system-riscv64.
In an embedded test pipeline QEMU sits between the host build
(fast, but misses arch-specific behaviour) and the physical
hardware-in-loop rig (slow, expensive). A cross-compiled
GoogleTest or Unity binary runs under QEMU with semihosting; the
test's main() returns the failure count; QEMU exits with that
code; CI gates on it.
Composes with:
googletest-embedded-arm - cross-compiled C++ test binary.unity-test-framework-c - cross-compiled C test binary.ceedling-build-runner - Ceedling project configured for ARM cross-compile.hardware-in-loop-reference - the next rung up the V-cycle (PIL / HIL).QEMU does not emulate analog I/O, sensor wiring, or
real-time timing precisely - for that, escalate to a real HIL
rig per
hardware-in-loop-reference.
Match the machine to the CPU profile: mps2-* boards for
M-profile cores, virt for A-profile and RISC-V. The common
Cortex-M mapping:
| Test target | QEMU command | Typical -cpu |
|---|---|---|
| Cortex-M0 / M0+ | qemu-system-arm -M mps2-an385 | cortex-m0 |
| Cortex-M3 | qemu-system-arm -M mps2-an385 | cortex-m3 (board default) |
| Cortex-M4 | qemu-system-arm -M mps2-an386 | cortex-m4 |
The full machine list, the A-profile / Raspberry Pi / Xilinx
targets, and the max CPU note are in
references/boards.md.
For an embedded test, load the ELF with -kernel and send serial
to the console with -nographic. The full invocation flag table
(-M, -cpu, -smp, -m, -bios, -serial, -monitor,
-qmp), per
invocation.html,
is in references/flags.md.
The critical flag for cross-compiled test binaries:
-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=name][,arg=string]
Per the same invocation page, semihosting "allows direct host
system calls and I/O operations". When the test ELF was linked
with --specs=rdimon.specs, printf and exit() from the
binary go through ARM semihosting calls; with
-semihosting-config enable=on,target=native QEMU services those
calls against the host.
Practically: the test binary's main() returns the failure
count; the C runtime calls _exit(rc); QEMU exits with rc. CI
gates on $?.
The test side is covered in
googletest-embedded-arm
and
unity-test-framework-c;
the canonical Cortex-M4 build:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O0 -g \
--specs=rdimon.specs \
test/test_ringbuffer.c test/test_ringbuffer_Runner.c \
src/ringbuffer.c ext/Unity/src/unity.c \
-o build/test.elf -lrdimon
-lrdimon links the ARM semihosting library
(developer.arm.com GNU Toolchain).
--specs=rdimon.specs pulls in startup code that wires printf
/ _write / _exit to the semihosting interface.
qemu-system-arm -M mps2-an386 -cpu cortex-m4 \
-nographic \
-semihosting-config enable=on,target=native \
-kernel build/test.elf
Output (Unity-style):
test/test_ringbuffer.c:34:test_ringbuffer_initially_empty:PASS
test/test_ringbuffer.c:42:test_ringbuffer_push_increments_size:PASS
-----------------------
2 Tests 0 Failures 0 Ignored
OK
Exit code: 0 (or the failure count for Unity / GoogleTest).
Per the invocation page, -d "activates debug logging for
specified subsystems":
qemu-system-arm -M mps2-an386 -cpu cortex-m4 \
-nographic -semihosting-config enable=on,target=native \
-d int,cpu_reset,unimp \
-kernel build/test.elf 2> qemu-debug.log
-d help lists the available items. int traces interrupts;
cpu_reset traces resets; unimp traces unimplemented
features (board-quirk hunts).
# Terminal 1
qemu-system-arm -M mps2-an386 -cpu cortex-m4 -nographic \
-semihosting-config enable=on,target=native \
-S -gdb tcp::1234 \
-kernel build/test.elf
# Terminal 2
arm-none-eabi-gdb build/test.elf \
-ex "target remote :1234" \
-ex "b main" \
-ex "continue"
-S "freezes the CPU at startup"; -gdb tcp::1234 "opens a GDB
stub on the specified device" (per the invocation page).
Per the same invocation reference, -qmp tcp:host:port[,server, nowait] exposes the QEMU Machine Protocol over TCP as JSON-RPC.
For a CI orchestration that needs to inject faults mid-test:
qemu-system-arm -M mps2-an386 -cpu cortex-m4 -nographic \
-semihosting-config enable=on,target=native \
-qmp tcp:localhost:4444,server,nowait \
-kernel build/test.elf
A test harness then connects to localhost:4444 and issues
{"execute":"query-status"}, {"execute":"stop"},
{"execute":"cont"} - useful for staged fault injection that
mirrors the HIL fault-injection patterns.
Semihosting's _exit(rc) propagates rc through QEMU. A test
binary linked with --specs=rdimon.specs and ending in:
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_x);
return UNITY_END(); /* failure count */
}
…makes qemu-system-arm ... -kernel test.elf; echo $? return
the failure count. CI gates on the exit code directly.
For Unity / GoogleTest, the canonical line format reaches host
stdout via semihosting → QEMU stdio. Grep / tee / pipe-to-JUnit
the same way as a host run - see
unity-test-framework-c
and
googletest-embedded-arm.
QEMU emulation is not real-time. For a test that asserts on
wall-clock latency, the result is wrong - QEMU executes
faster than physical hardware for compute-bound code and slower
for I/O-heavy code. For real-time-sensitive tests, escalate to
hardware-in-loop-reference.
The canonical GitHub Actions pipeline (install toolchain, cross-build, run under two CPU profiles) is in references/ci.md. The "run under multiple CPUs" pattern is the cheap way to catch CPU-feature regressions - float vs no-float, ARMv6-M vs ARMv7-M.
| Anti-pattern | Why it fails | Fix |
|---|---|---|
Forgetting -semihosting-config enable=on,target=native | Test prints nothing; QEMU never exits | Always set both -semihosting-config enable=on and target=native (or auto) |
-kernel pointed at a stripped binary | QEMU loads but symbol info gone for debug | Keep -g debug info; strip only the release binary |
| Asserting on wall-clock timing under QEMU | QEMU is not real-time | Move timing assertions to HIL; QEMU asserts only logical correctness |
Using -M virt for a Cortex-M test | virt is Cortex-A - wrong instruction set | Match machine to CPU profile (mps2-* for M-profile, virt for A-profile) |
| Not pinning the QEMU version | Newer QEMU may emulate differently; CI flakes | Pin qemu-system-arm version in the runner image |
Skipping -cpu and relying on board default | Board defaults shift between QEMU versions | Always specify -cpu explicitly |
Reading -monitor stdio and -nographic together without -serial mon:stdio | Serial and monitor share stdio; output garbles | Use -monitor none -serial stdio for clean output |
| Running QEMU in CI without a sane timeout | A hung test ELF runs forever | Wrap in timeout 60 qemu-system-arm ... |
max CPU diverges from production. The max CPU is per
the cpu-features page "available for comprehensive feature
testing"; passing on max does not mean passing on the
production part.--specs=rdimon.specs; the
semihosting bkpt is a debug-only path.Cited inline. Foundational documents:
max, named CPUs) - www.qemu.org/docs/master/system/arm/cpu-features.html.--specs=rdimon.specs, semihosting) - developer.arm.com Tools and Software / GNU Toolchain.googletest-embedded-arm,
unity-test-framework-c,
ceedling-build-runner,
hardware-in-loop-reference,
embedded-coverage-strategy-reference.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
qemu, embedded-testing, system-emulation, arm, riscv, ci-testing
6 skills in this plugin
/ceedling-build-runnerUse when a C project wants Unity, CMock and CException run by one build command, or CMock mocks need writing or reading: Ceedling project scaffolding, project.yml, test tasks, JUnit XML, gcov coverage, host vs cross builds and CI. The Unity assertion API is unity-test-framework-c./embedded-coverage-strategy-referenceUse when deciding what code coverage level embedded C/C++ needs (statement, branch, MC/DC) and wiring gcov or llvm-cov into the build: host vs QEMU instrumentation, MISRA-C and DO-178C expectations by safety level, and report formats./googletest-embedded-armUse for any task that writes or runs GoogleTest tests for embedded C++ (C++17 or later) on ARM, even one test with a mock, including firmware tests that pass on the host but fail on the target: TEST, TEST_F and parameterized tests, EXPECT vs ASSERT, fixtures, GoogleMock, cross-compiling with arm-none-eabi-g++, running on host or QEMU and XML output for CI. Pure C uses unity-test-framework-c./hardware-in-loop-referenceUse when scoping an embedded hardware-in-the-loop (HIL) rig or reading an automotive, aerospace or industrial HIL report: MIL, SIL, PIL and HIL stages, NI, dSPACE, Vector and Speedgoat stacks, CAN, LIN, FlexRay and Ethernet emulation, fault injection and ISO 26262, DO-178C and IEC 61508 evidence./unity-test-framework-cUse for any question or task about unit tests for pure C code on 8-bit MCUs, Cortex-M or embedded Linux, even tests for one function, including which framework fits a tiny-memory target: ThrowTheSwitch Unity (not the Unity game engine) with TEST_ASSERT families, setUp and tearDown, RUN_TEST, the test runner generator, config defines and CI via Ceedling JUnit XML.npx claudepluginhub testland/qa --plugin qa-embedded2 plugins ship this exact skill · first indexed Nov 12, 2026
Other plugins' skills for the same job