Repository navigation
test: convert CMocka tests to ztest, part 3: pipeline, and remove CMocka - #11558
Merged
lgirdwood merged 7 commits intoNov 29, 2026
Merged
Conversation
This was referenced Nov 28, 2026
Add a ztest application for the pipeline graph code with one suite per CMocka test, twelve cases in total: the pipeline_new() creation case from pipeline_new.c, the nine pipeline_complete() cases from pipeline_connect_upstream.c and the two pipeline_free() cases from pipeline_free.c. The shared test objects from pipeline_connection_mocks.c are ported along with them. The CMocka builds link nineteen SOF sources plus the common and notifier mocks each. Only six are needed here: pipeline-graph.c under test, pipeline-schedule.c for pipeline_comp_ll_task_free(), the IPC3 helper, ipc-common.c and ipc-common-kernel.c for the stream position message, and component.c for sys_comp_init(), which the common sof_context.c calls. The SOF heap comes from zephyr/lib/alloc.c routed to the host malloc(), so ASan and LSan see it. Like the CMocka unit_test_defconfig build, the suite uses IPC3, where pipeline_new() allocates the stream position message and pipeline_free() only frees the pipeline task. Adapted from the CMocka tests: - CMocka set the connection objects up once per test group, so the cases shared them. ztest runs the cases in alphabetical order, so every case now gets new objects from before/after hooks. - connect_upstream_full expected the upstream component to be bound to the pipeline. pipeline_complete() only walks downstream, and the check only passed in CMocka because the previous case had left the component bound to its own pipeline copy at the same stack address: clearing the pointer before the case makes the CMocka check fail. The ztest case checks that the component is left unbound. - pipeline_free.c replaced sof_heap_free() with a no-op for the whole test. The ztest suite wraps sof_heap_free() and only skips the frees while its cases run, so the test objects can be freed afterwards. - pipeline_new_creation also checks that the position message was allocated before freeing it, and frees the alloc context, which the CMocka test leaked. The test objects helper now also frees the mock scheduler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
This patch removes the pipeline_new, pipeline_connect_upstream and pipeline_free tests that have been successfully converted to the new framework (from cmock to ztest), together with their CMake entries and the pipeline_connection_mocks.c, pipeline_connection_mocks.h and pipeline_mocks.h helpers, which no other CMocka test uses. Code coverage testing did not reveal any regression. CMock stats for pipeline-graph.c, pipeline-schedule.c (host gcc, unit_test_defconfig) - lines: 30.8 % (120/389) - branches: 13.4 % (36/269) Ztest stats for pipeline-graph.c, pipeline-schedule.c (native_sim, host LLVM) - lines: 28.6 % (126/441) - branches: 13.5 % (28/207) The ztest suite covers every line of pipeline-schedule.c the CMocka tests covered, and every such line of pipeline-graph.c but one: the vregion_set_interim() call in pipeline_complete(). Neither build enables CONFIG_SOF_VREGIONS and the pipeline alloc context has no vregion in either test, so the call is not made and the stub it would reach is an empty inline function. gcc still reports the line as executed, LLVM does not. The totals differ because gcc and LLVM count lines and branches differently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add a ztest suite for comp_set_state() with the same table of 67 state transitions as the CMocka test: 13 transitions that must succeed, 34 that must fail with -EINVAL and 20 that must leave the component in a given state. CMocka registered one test per table entry. The suite has one case per kind of check, which runs every entry of its kind and names the failing entry in the assertion message. The CMocka build links twenty SOF sources and the notifier mocks. Only component.c, which implements comp_set_state(), is needed here. Like the CMocka unit_test_defconfig build, the suite uses IPC3, where comp_set_state() returns COMP_STATUS_STATE_ALREADY_SET instead of 0 when the component is already in the requested state. The test component is now zero initialised; CMocka only set its state and left the rest of the stack object uninitialised. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
This patch removes the comp_set_state test that has been successfully converted to the new framework (from cmock to ztest), together with its CMake entry and the now empty test/cmocka/src/audio/component directory. Code coverage testing did not reveal any regression. CMock stats for component.c (host gcc, unit_test_defconfig) - lines: 21.1 % (41/194) - branches: 22.1 % (40/181) Ztest stats for component.c (native_sim, host LLVM) - lines: 21.6 % (44/204) - branches: 32.0 % (31/97) The ztest suite covers every line of component.c the CMocka test covered. The eight case labels of the comp_set_state() switch count as lines for gcc but not for LLVM. The totals differ because gcc and LLVM count lines and branches differently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The ztest suites still use some files from test/cmocka: - the two channel chirp test signal and the logarithm and power tables in test/cmocka/include; - the notifier mocks, linked by the FFT suites; - the Octave helpers in test/cmocka/m, which the reference data generator scripts use to write C headers. Move them with git mv, so that the CMocka tree can be removed: - the headers to test/ztest/unit/include; - the notifier mocks to test/ztest/unit/common; - the Octave helpers to test/ztest/m. The auditory, DCT, FFT multi and A-law/mu-law generator scripts already look for the Octave helpers in test/ztest/m, so they work again. The DFT3 and PCAN generator scripts and the EQ FIR and IIR reference data scripts in src/audio/eq_iir/tune are updated for the new paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
All CMocka unit tests have been converted to ztest or removed, so the CMocka job has nothing left to run. Remove the unit-tests workflow and its job in the daily tests. The ztest suites run in the Zephyr unit tests workflow (zephyr-unit-tests.yml). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
All CMocka unit tests have been converted to ztest suites in test/ztest/unit, which run on native_sim with ASan and LSan, or removed. Remove what is left of the CMocka framework: - test/cmocka: the CMocka build, its toolchain file, the common mocks, the memory mock linker script, the per-platform unit test defconfigs and the empty test source tree; - test/test-all-defconfigs.sh and scripts/run-mocks.sh, which built and ran the CMocka tests; - the BUILD_UNIT_TESTS and BUILD_UNIT_TESTS_HOST CMake options: the top level project now only builds the host library, for the testbench; - the unit test defconfig directory in the Kconfig search list, the CODEOWNERS placeholder for the CMocka CMake file, and the remaining mentions of CMocka in comments. The README describes how to run the ztest suites, as CI does. The CI jobs that run the CMocka tests are removed in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
lgirdwood
force-pushed
the
kernel-user/ztest-port-c
branch
from
November 28, 2026 19:33
6a0ec95 to
0e0708e
Compare
lgirdwood
marked this pull request as ready for review
November 28, 2026 19:42
lgirdwood
requested review from
dbaluta,
kv2019i,
lbetlej,
mmaka1,
plbossart and
singalsu
as code owners
November 28, 2026 19:42
PR 11558: test resultsRun date: 2026-11-28 20:00 UTC Tested commit: 0e0708e6495a54c22eb64bc7a100dcd697b1a2ad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #11306: convert the last CMocka unit tests to ztest and remove the CMocka framework. After this, the testbench is the only user of the host library (
CONFIG_LIBRARY,posix/include).Follows #11556 and #11557, both merged.
Patches
Convert to ztest
audio/pipelineaudio/componentEach removal commit has the coverage of both frameworks (CMocka with host gcc, ztest with native_sim and host LLVM as in CI). Every line that the CMocka tests cover is covered by the ztest suites, with one exception: a line in
pipeline_complete()that gcc counts as executed and LLVM does not. It is never executed in either build.Remove the framework
Shared files:
test/ztest/unit/include;test/ztest/unit/common;test/ztest/m. Four generator scripts already looked for them there, so they work again.CI: the CMocka workflow and its daily job are removed. The ztest suites run in
zephyr-unit-tests.yml.The rest of the framework:
test/cmocka,test/test-all-defconfigs.shandscripts/run-mocks.sh;BUILD_UNIT_TESTSandBUILD_UNIT_TESTS_HOSTCMake options;The README now shows how to run the ztest suites.
What the ports found
connect_upstream_fulltest only passed because the previous case left a component bound to a stack copy of its pipeline.pipeline_complete()only walks downstream, and the ztest case checks that.Out of tree
The unit testing page of sof-docs still describes CMocka and needs an update.
Testing
yamllint, run as in the codestyle workflow, passes.All of the above was run on 64b7446 with #11556 and #11557 below it, and again after rebasing onto 7429eff (current main): ZTest, yamllint, the host library, the testbench and the tools.
Changes since the last push
test/is unchanged.🤖 Generated with Claude Code