How to contribute to the µTest++ Testing Framework
This page is for the contributors who plan to add new features or fix bugs in the µTest++ Testing Framework project, and describes how to build and test the package.
How the framework works
Besides the build and the tests, described below, this guide explains how µTest++ works internally, with excerpts of the code, for the contributors who plan to change the framework:
- Architecture overview: the design constraints, the files, the namespaces, and the path of a test program from the runner to the exit code;
- Expression templates and comparators: the
objects returned by
eq()and the other comparators, and how they store their operands; - Checks and the check result: how
expect()andrequire()collect the messages and report the checks; - The expression formatter: how the operands and the expressions become the text of the reports;
- Test cases and suites: how the test cases run on the stack, and how the suites are stored and run;
- The runner: the options, the state of the session, the order of the suites, and the exit code;
- The reporters: where each record is written, and how the TAP and the human-readable reports are formatted;
- Comparison with other frameworks, in Getting Started: how the design of µTest++ compares with Boost UT, snitch, GoogleTest, Catch2, doctest, Boost.Test, Unity, and CppUTest, and which of its choices are deliberate, and which are limitations;
- Making changes: where new code goes, the rules every change respects, and how it is documented and tested.
The project is written in modern C++ and, for reproducibility reasons, uses the xPack Framework tools during development.
Prerequisites
@micro-os-plus/micro-test-plus is an xpm package that provides a C++ source code library; development can be conducted on macOS, GNU/Linux, and Windows.
The prerequisites are:
- git
- curl
- node >= 22.12
- npm / xpm
To execute the native tests with the system tools,
a C++ development environment is required.
On macOS, install Command Line Tools; on Ubuntu, install build-essential,
on Arch/Manjaro install base-devel, on Fedora/Red Hat install the
Development Tools group.
For details on installing the prerequisites, please refer to the Prerequisites page.
Install xpm
xpm is also a portable
Node.js command-line application that can be
installed with npm.
On macOS and GNU/Linux, if you followed the Quick instructions in the Prerequisites page, it is already installed. Otherwise, to install it, follow the steps in the xpm install page.
As a shortcut, run the following command:
npm install --location=global xpm@latest
To check the result of the installation, run:
xpm --version
Obtain project sources
The @micro-os-plus/micro-test-plus project is hosted on GitHub:
What Git branches are available?
This project uses multiple branches:
master, not actively usedxpack, containing the latest stable version (default branch)xpack-development, containing the current development versionwebsite, containing the current website content; pushing to this branch automatically triggers publication of the main websitewebpreview, containing the current preview website content; pushing to this branch automatically triggers publication of the preview website
All development is conducted in the xpack-development branch, and
contributions via Pull Requests should be directed to this branch.
When new releases are published, the xpack branch is rebased
onto xpack-development.
- Use Fork
- Use Original
To contribute Pull Requests, fork the project. For this, go to the GitHub project page and click on the Fork button.
To get all the branches of the repository, be sure to disable the Copy the xpack branch only option in the fork dialog.
After creating the fork, the next step is to clone the forked repository. First set your GitHub account name:
USER_ACCOUNT_ID=<your-account>
Then clone the xpack-development branch:
rm -rf ~/Work/micro-os-plus/micro-test-plus-xpack.git && \
mkdir -p ~/Work/micro-os-plus && \
git clone \
--branch xpack-development \
https://github.com/${USER_ACCOUNT_ID}/micro-test-plus-xpack.git \
~/Work/micro-os-plus/micro-test-plus-xpack.git
After making changes, be sure to direct the Pull Requests to the
xpack-development branch, otherwise they may be rejected.
If Pull Requests are not intended, you can directly clone the
xpack branch of the original repository:
rm -rf ~/Work/micro-os-plus/micro-test-plus-xpack.git && \
mkdir -p ~/Work/micro-os-plus && \
git clone \
--branch xpack \
https://github.com/micro-os-plus/micro-test-plus-xpack.git \
~/Work/micro-os-plus/micro-test-plus-xpack.git
To work from the development branch instead, clone xpack-development
from the original repository.
If the repository has already been cloned, update it with:
git -C ~/Work/micro-os-plus/micro-test-plus-xpack.git pull
What are npm/xpm links?
By default, to prevent inadvertent changes, xpm dependencies are installed in read-only folders with filtered content; developer-related files are not installed.
However, during development, it is convenient to maintain a writable instance of the code to enable changes in parallel with the parent project.
Therefore, during development, if this project is used as a dependency of another project, it is convenient to use the full version of the project and make changes directly in the local development folder.
The mechanism xpm uses for this is called linking, and is similar to the npm link mechanism.
The process has two steps:
- Tell the global xpm configuration where the local development folder is located.
- Tell the top project to use the linked development folder instead of the installed read-only dependency.
The first step requires executing the xpm link command in the
local development folder, as shown below:
xpm link -C ~/Work/micro-os-plus/micro-test-plus-xpack.git
The result is the creation of a symbolic link in the global xPacks store pointing to the local development folder.
For example:
% ls -l xPacks/micro-os-plus/micro-test-plus-xpack/.link
lrwxr-xr-x 1 ilg staff 75 Oct 26 21:57 xPacks/micro-os-plus/micro-test-plus-xpack/.link -> /Users/ilg/Work/micro-os-plus/micro-test-plus-xpack.git
For the second step, in the top project, instead of adding the dependency by installing it, run the command to link it:
xpm link @micro-os-plus/micro-test-plus
Similarly, this project, which uses multiple xpm dependencies, can also benefit from linking them during development.
For this, clone each xpm dependency in a local folder and run the
xpm link command in each cloned folder, as described above.
Then, in the tests folder, run xpm link <dependency> for each linked
dependency.
As a shortcut, the configuration provides link-dependencies xpm actions
that link multiple dependencies at once.
How to obtain the writable helper sources?
The project has a dependency on a common helper, which is normally installed
as a read-only dependency; for development purposes, to enable modifications
to the scripts located within the helper, clone the
xpack-development branch and link it to the
global packages location:
rm -rf ~/Work/micro-os-plus/build-helper-xpack.git && \
mkdir -p ~/Work/micro-os-plus && \
git clone \
--branch xpack-development \
https://github.com/micro-os-plus/build-helper-xpack.git \
~/Work/micro-os-plus/build-helper-xpack.git
Alternatively, if the repository has already been cloned:
git -C ~/Work/micro-os-plus/build-helper-xpack.git pull
Tell the global npm configuration where the local development folder is located (link the project):
npm --prefix ~/Work/micro-os-plus/build-helper-xpack.git link
Similarly, for the website helper, clone the
master branch and link it to the
global packages location:
rm -rf ~/Work/xpack/docusaurus-template-liquid.git && \
mkdir -p ~/Work/xpack && \
git clone \
--branch master \
https://github.com/xpack/docusaurus-template-liquid.git \
~/Work/xpack/docusaurus-template-liquid.git
Alternatively, if the repository has already been cloned:
git -C ~/Work/xpack/docusaurus-template-liquid.git pull
Tell the global npm configuration where the local development folder is located (link the project):
npm --prefix ~/Work/xpack/docusaurus-template-liquid.git link
After this, run the npm-link-helpers script to link all the local helper sources.
Satisfy dependencies
Execute the following commands:
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git install
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests install
xpm install -C ~/Work/micro-os-plus/micro-test-plus-xpack.git
The first two commands install the npm dependencies of the project and of the
tests project, and the third one installs the xpm development dependencies of
the project, such as the code formatters. The build tools and the toolchains
required by each build configuration are installed later, by the install
actions of the tests project, as described in Manual tests.
Language standard compliance
The library is written in modern C++ and should be compiled with -std=c++20.
Code formatting
For formatting style, the project employs a
.clang-format
configuration file based on the GNU style, in the maintenance/config folder.
The source files are formatted with the clang-format xpm action,
which runs clang-format with that configuration on the C and C++ files of
the project:
xpm run clang-format -C ~/Work/micro-os-plus/micro-test-plus-xpack.git
Similarly, the cmake-format and jsonc-format actions format the CMake and
the JSONC files.
The clang-format program is installed by xpm install, as a development
dependency of the project, in the xpacks/.bin folder.
Always reformat the modified source files before committing them. Enabling format-on-save in your editor makes this automatic.
Tests
The µOS++ testing strategy involves compiling the sources with as many toolchains as possible and executing them on a wide range of platforms.
Therefore, after making any changes, it is necessary to run the tests.
For simple changes, it may be sufficient to run the tests only on the
host platforms (xpm run test).
For more complex changes it is necessary to run the tests on both the host
and target platforms to ensure correctness (xpm run test-selected or
xpm run test-latest).
Host platforms
The tests may be executed on any of the supported host platforms:
- GNU/Linux (x64 and arm64, GLIBC>=2.28); to execute the native
tests, a C++ development environment is required
(on Ubuntu install
build-essential, on Arch/Manjaro installbase-devel) - macOS (>= 11.0); as C++ development environment use Command Line Tools
- Windows 10, Windows 11
Target platforms
The supported target test platforms are in the tests/platforms folder;
the list is taken from tests/config/tests-templates.json.
The test applications are executed as native processes on macOS and GNU/Linux development machines with:
platforms/synthetic-posix
The tests are executed as fully semihosted applications on QEMU emulated boards, which can be run without any hardware, with:
platforms/qemu-cortex-m0platforms/qemu-cortex-m3platforms/qemu-cortex-m4fplatforms/qemu-cortex-m7fplatforms/qemu-cortex-m33platforms/qemu-aarch32-a15platforms/qemu-aarch64-a72platforms/qemu-riscv-rv32imacplatforms/qemu-riscv-rv64imafdc
The tests are built for physical boards, with the following platforms; to run them, the board must be connected and powered up:
platforms/nucleo-f411replatforms/nucleo-f411re-cubemxplatforms/nucleo-f411re-cubemx-startupplatforms/nucleo-f767ziplatforms/nucleo-f767zi-cubemxplatforms/nucleo-h533replatforms/nucleo-h533re-cubemxplatforms/raspberry-pi-picoplatforms/raspberry-pi-pico-sdkplatforms/raspberry-pi-pico-2-armplatforms/raspberry-pi-pico-2-arm-sdkplatforms/raspberry-pi-pico-2-riscvplatforms/raspberry-pi-pico-2-riscv-sdkplatforms/raspberry-pi-zero-2-w-aarch32platforms/raspberry-pi-zero-2-w-aarch64
Note: The Raspberry Pi Zero 2 W platform is work in progress.
Portable test sources
The test sources are highly portable: they are identical on all platforms and in all build configurations; only the platform-specific code and the build configuration files differ.
Semihosting
On embedded platforms, the applications interact with the host via the semihosting mechanism, defined by Arm and used with the same protocol on RISC-V.
The semihosting implementation must support at least
SYS_GETCMDLINE (to pass the command-line arguments),
SYS_EXIT (to return the exit code),
and the file operations SYS_OPEN, SYS_WRITE, and SYS_CLOSE
(to write the test output).
A complete implementation is provided by the @micro-os-plus/semihosting package.
Toolchains
To enhance source code portability, the builds are repeatedly conducted using various toolchains, including multiple versions of the same toolchain.
The following toolchains are used:
- gcc (native)
- clang (native)
- arm-none-eabi-gcc (Cortex-M, AArch32)
- aarch64-none-elf-gcc (AArch64)
- riscv-none-elf-gcc (RISC-V 32/64)
Test details
The tests are built and run for each platform and toolchain.
The test programs are in the tests/sources folder, one
folder for each program, with the sources in src/. The executables are
named <name>-test, and the same sources are built on all platforms.
Each program is run several times, with different options: the TAP reporter
with the default verbosity, --verbose, --quiet, and --silent, and the
human-readable reporter (--reporter=human) with the same four verbosity
levels. For each run, the tests:
- run the program;
- compare the output file with a reference file in
tests/expected/taportests/expected/txt, ignoring the program line, the compiler line, the timings, the addresses, and the line numbers (tests/scripts/compare-files.sh); - parse each TAP output file with the node-tap parser, in strict mode, to
validate it (
tests/scripts/validate-tap.mjs).
The reference files whose names end in -noexcept are for the builds
without exceptions.
Some checks of the unit tests are intended to fail, to validate the
failure-reporting paths. Their failures are part of the reference outputs,
so the test passes when the output is identical to the reference file, not
when all the checks pass; the totals of the unit programs therefore show
failed checks.
The test programs
| Program | What it tests | Reference outputs |
|---|---|---|
empty | runners and suites with no checks, or with only empty test cases; it uses plain assertions instead of the framework primitives | empty-test |
minimal | the smallest possible test, a single test case with two checks, intended for first experiments | minimal-test |
sample | the main primitives of the framework in a practical test, including strings, arguments passed to suites, explicit namespaces, and, if exceptions are enabled, the checks of exceptions | sample-test |
suite | the test hierarchy: local runners, a static runner, and suites, including a static suite defined in a separate file, and the deeply nested test cases used to measure the stack | suite-test |
unit | all the unit tests in one program, built from the bodies of the four programs below | unit-test |
unit-checks | the expectations and requirements, the comparators, and the operands | unit-checks-test |
unit-combinations | the combinations of operand types | unit-combinations-test |
unit-exceptions | the exceptions, including those that escape test cases and suites, and the stopped test cases | unit-exceptions-test |
unit-miscellaneous | the test hierarchy, the formatters, the reporters, and the custom types | unit-miscellaneous-test |
unit-deprecated | the deprecated operators, literals, and wrappers, built with MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED | unit-deprecated-test |
unit-static-asserts | mostly compile-time checks, with static_assert(); the program must compile, and is also run | none |
The unit-checks, unit-combinations, unit-exceptions, and
unit-miscellaneous bodies are also built as separate programs; their
shared header is in unit-common. The unit and unit-checks programs have,
besides the files for the TAP reporter, others for the console output of the
human-readable reporter (-console and -console-quiet) and for the output
with colours (-colour).
Example: the reference output of the minimal test
The reference file tests/expected/tap/minimal-test.tap is the output file of
the minimal-test program, run as shown on the first line. The output file receives
every check, whatever the verbosity of the console:
# Running: minimal-test --reporter=tap --output-file=minimal-test.tap one two
# Built with clang Apple LLVM 17.0.0 (clang-1700.6.4.2), with exceptions, with MICRO_OS_PLUS_DEBUG_ENABLED, with MICRO_OS_PLUS_DIAG_TRACE_ENABLED
TAP version 14
# Subtest: minimal-test
# Subtest: Check various conditions
ok 1 - answer is 42
ok 2 - condition is true
1..2
ok 1 - Check various conditions # { passed, 2 checks }
1..1
ok 1 - minimal-test # { passed, 2 checks in 1 test case, time: 0.069 ms }
1..1
# { total: 2 checks passed, 0 failed, in 1 test case, 1 test suite, time: 0.147 ms }
Similarly, the reference file tests/expected/txt/minimal-test.txt is the
output file of the minimal-test program, run with the human-readable
reporter, as shown on the first line. The output file receives every check,
whatever the verbosity of the console:
Running: minimal-test --reporter=human --output-file=minimal-test.txt one two
Built with clang Apple LLVM 17.0.0 (clang-1700.6.4.2), with exceptions, with MICRO_OS_PLUS_DEBUG_ENABLED, with MICRO_OS_PLUS_DIAG_TRACE_ENABLED
µTest++ human-readable report
• minimal-test
• Check various conditions
✓ answer is 42
✓ condition is true
✓ Check various conditions - passed (2 checks)
✓ minimal-test - passed (2 checks in 1 test case), time: 0.045 ms
✓ Total: 2 checks passed, 0 failed, in 1 test case, 1 test suite, time: 0.095 ms
Manual tests
There are predefined xpm actions available to manually execute various tests on the local development machine.
Start with a clean-up (not needed after the initial git clone):
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests install
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests run deep-clean
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests install
During the initial execution, the installation step may require a considerable amount of time, as it needs to download the toolchain archives, which can be relatively large, up to several hundred megabytes.
Native system compiler tests
To execute the tests with the system compiler (usually not available on Windows):
xpm run install -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
More native and QEMU tests
To execute a selection of tests with the latest versions of toolchains:
xpm run install-selected -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-selected -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
To execute all tests with the latest versions of toolchains:
xpm run install-latest -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-latest -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
To execute all tests with all toolchain versions:
xpm run install-all -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-all -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
Physical boards tests
To build the physical boards binaries with the latest versions of toolchains:
xpm run install-boards -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run build-boards -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
Running the tests on a physical board requires the board to be connected and powered up. To execute the tests for a specific board configuration with the latest versions of toolchains:
xpm run install-nucleo-f411re-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-f411re-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-nucleo-f411re-cubemx-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-f411re-cubemx-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-nucleo-f411re-cubemx-startup-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-f411re-cubemx-startup-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-nucleo-f767zi-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-f767zi-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-nucleo-f767zi-cubemx-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-f767zi-cubemx-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-nucleo-h533re-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-h533re-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-nucleo-h533re-cubemx-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-nucleo-h533re-cubemx-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-raspberry-pi-pico-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-raspberry-pi-pico-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-raspberry-pi-pico-sdk-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-raspberry-pi-pico-sdk-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-raspberry-pi-pico-2-arm-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-raspberry-pi-pico-2-arm-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-raspberry-pi-pico-2-arm-sdk-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-raspberry-pi-pico-2-arm-sdk-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-raspberry-pi-pico-2-riscv-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-raspberry-pi-pico-2-riscv-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run install-raspberry-pi-pico-2-riscv-sdk-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
xpm run test-raspberry-pi-pico-2-riscv-sdk-cmake-gcc -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
Clean-ups
Executing all tests may require several gigabytes of space.
To clean up the tests folder, use:
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests install
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests run deep-clean
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests install
A considerable amount of space may also be used by the toolchains.
When no longer required, they can be removed with xpm uninstall.
xpm clean-ups
For a complete clean-up, note that xpm uses two folders:
- Windows
- macOS
- GNU/Linux
%APPDATA%\xPacks%LOCALAPPDATA%\Caches\xPacks
${HOME}/Library/xPacks${HOME}/Library/Caches/xPacks
${HOME}/.local/xPacks${HOME}/.cache/xPacks
They can be removed at any time and space reclaimed; xpm will recreate them during new installations.
However, the projects that link to the user's global xPacks store will have broken links.
Continuous integration (CI)
The library is subject to continuous integration (CI) testing with every push using GitHub Actions. The tests run on Ubuntu, macOS, and Windows.
Testing is conducted on both 32-bit and 64-bit bare-metal platforms, including a selection of Arm Cortex-M, Cortex-A, and RISC-V, running under QEMU.
The native tests run with the GCC and LLVM/clang compilers.
A workflow that runs the tests on all the supported platforms and
configurations can be triggered manually in the GitHub Actions interface, the
Run all tests workflow.
In the upstream project repository, the workflow can also be triggered manually with:
xpm run trigger-workflow-test-all -C ~/Work/micro-os-plus/micro-test-plus-xpack.git/tests
(this requires curl and the GITHUB_API_DISPATCH_TOKEN environment
variable to be set.)
The website
The project includes the source files for its website. The main pages are generated with Docusaurus, and the reference pages are generated with Doxygen.
Satisfy Docusaurus dependencies
Execute the following command:
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/website install
Regenerate the Doxygen pages
Execute the generate-website-doxygen npm script:
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/website run generate-website-doxygen
At present, the doxygen program must be installed on the host, as it is not available as an xpm dependency.
With the current configuration, the static HTML pages are generated
within the website/static/doxygen folder and converted to Docusaurus
Markdown in docs/api.
The pages generated from templates, marked DO NOT EDIT!, are regenerated by
the maintainers when the website is published (see the
Maintainer's Guide);
change only the pages of the project, which do not have this mark.
Build the static website locally
Validate the website content by performing a local build using the npm build script:
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/website run build
Resolve any broken links that may be identified during the build process.
Start the local web server
Execute the npm script clear followed by start in the website sub-project, or execute the following within the project folder:
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/website run clear
npm --prefix ~/Work/micro-os-plus/micro-test-plus-xpack.git/website run start
The local copy of the site is then available at http://localhost:3000/micro-test-plus-xpack/, and its pages are updated when the source files change.