catch2-selftest
:::warning [UNTESTED] — host-run only
This is a host unit-test example, not a firmware demo: the binary builds and runs on native_sim and exits 0. It has never run on real E1M silicon, and there is no board-specific behaviour to bench-verify — Catch2 is a pure C++ test framework with no hardware surface.
:::
A minimal Catch2 v3 unit-test binary: three TEST_CASEs (6 assertions) over a trivial clamp() helper.
Source: examples/testing/catch2-selftest/.
What it does
Runs the test cases from a custom main() driving Catch::Session (CATCH_AMALGAMATED_CUSTOM_MAIN), and prints [catch2-selftest] done only when zero assertions fail. There is no <alp/*> wrapper — the example uses Catch2's own API directly.
Catch2 ships as the vendored amalgamated catch_amalgamated.{hpp,cpp} pair. libraries: [catch2] emits CONFIG_ALP_SDK_CATCH2_VENDORED=y, which gates the SDK's Zephyr module compiling it.
:::caution Use int main(void), not main(int argc, char *argv[])
The example deliberately declares int main(void). An earlier draft took argc/argv and segfaulted, because Zephyr feeds garbage argument values into Catch::Session::applyCommandLine().
:::
board.yaml
libraries:
- name: catch2
cores: [m55_hp]
som:
sku: E1M-AEN801
preset: e1m-evk
cores:
m55_hp:
app: ./src
peripherals: []
diagnostics:
log_level: info
som.sku and preset are present only because the project generator needs a SoM to derive the baseline SoC config from. This example never touches peripherals: or a chip driver, so there is no hardware config to swap.
Expected output
The seed line varies run to run — Catch2 shuffles test order unless told otherwise. Everything else is fixed:
Randomness seeded to: 1405010408
===============================================================================
All tests passed (6 assertions in 3 test cases)
[catch2-selftest] done
See also
doctest-selftest— the same test suite on a header-only framework- Examples overview