Author and run ThrowTheSwitch Unity (the C unit-testing library) for bare-metal and RTOS C code. Distinct from the Unity game-engine Test Framework at docs.unity3d.com: this is the ThrowTheSwitch C testing library at throwtheswitch.org/unity, a single C file plus headers that runs on 8-bit MCUs through 64-bit hosts. Anchored on the Unity assertion API and configuration macros regardless of execution environment: the TEST_ASSERT_EQUAL_* / _FLOAT / _DOUBLE / _STRING / _MEMORY / _BITS assertion families, setUp/tearDown/RUN_TEST/UNITY_BEGIN/UNITY_END semantics and the exit-code contract, the generate_test_runner.rb generator, build-time config defines (UNITY_INCLUDE_DOUBLE, UNITY_OUTPUT_CHAR, UNITY_EXCLUDE_SETJMP), and CI integration via Ceedling JUnit XML; applies to host builds, cross-builds, and QEMU-run targets alike. For QEMU machine flags, semihosting, and exit-code capture, see qemu-system-test-runner. Use when the unit-under-test is pure C and the target ranges from 8-bit AVR to Cortex-M0 to Linux ARM.
74
93%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Generate runners, build + run on host, then cross-build and run under QEMU:
jobs:
unity-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install toolchain
run: sudo apt-get install -y gcc-arm-none-eabi qemu-system-arm ruby
- name: Generate runners
run: |
for t in test/test_*.c; do
ruby ext/Unity/auto/generate_test_runner.rb "$t" "${t%.c}_Runner.c"
done
- name: Build + run on host
run: |
gcc -O0 -g -DUNITY_INCLUDE_DOUBLE \
-I src -I ext/Unity/src \
src/*.c ext/Unity/src/unity.c \
test/test_*.c test/*_Runner.c \
-o build/unity_host
./build/unity_host | tee build/host.log
! grep -q ':FAIL:' build/host.log
- name: Cross-build + QEMU run
run: |
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O0 -g \
--specs=rdimon.specs \
-I src -I ext/Unity/src \
src/*.c ext/Unity/src/unity.c \
test/test_*.c test/*_Runner.c \
-o build/unity_arm.elf -lrdimon
qemu-system-arm -M mps2-an385 -cpu cortex-m4 \
-nographic -semihosting-config enable=on,target=native \
-kernel build/unity_arm.elf | tee build/arm.log
! grep -q ':FAIL:' build/arm.logFor Ceedling-driven projects, use ceedling-build-runner for the canonical ceedling test:all + JUnit XML flow.