The SOF project is transitioning from CMocka to Zephyr's native ztest framework for unit testing. This migration aligns SOF's testing infrastructure with the Zephyr RTOS ecosystem and provides better integration with Twister test runner.
The migration from CMocka to ztest is ongoing. Currently, basic unit tests (math functions, library functions) have been migrated, with more complex audio component tests in progress. For the latest migration status, see GitHub issue #10110.
For more information about the ztest framework, refer to Zephyr's ztest documentation.
For legacy CMocka-based unit tests, refer to :doc:`unit_tests`.
This guide assumes that you have a basic SOF development environment set up. If not, follow the instructions at :doc:`../getting_started/build-guide/build-with-zephyr` first.
Ztest unit tests require the following tools and dependencies:
sudo apt-get update
sudo apt-get install -y clang llvm ninja-build device-tree-compiler \
python3-pyelftools gcc-multilib g++-multilibZephyr uses the west meta-tool for project management. Install it using pip:
pip3 install westInstall Zephyr's Python requirements:
cd path/to/zephyrproject/zephyr
pip3 install -r scripts/requirements.txtFirst, initialize your workspace with west if you haven't already:
cd path/to/sof
west init -l
west update --narrow --fetch-opt=--filter=tree:0Ztest unit tests use the LLVM/Clang toolchain:
export ZEPHYR_TOOLCHAIN_VARIANT=llvmTo build and run all unit tests using Twister:
west twister --testsuite-root sof/test/ztest/unit/ --platform native_sim \
--verbose --inline-logsTwister provides detailed test results in the console output. Test results are also saved in twister-out/ directory.
This section is in progress and will be added in a future update.
This section is in progress and will be added in a future update.
This section is in progress and will be added in a future update.