Repository navigation
test: convert CMocka tests to ztest, part 1: math and already ported tests - #11556
Merged
lgirdwood merged 11 commits intoNov 28, 2026
Merged
Conversation
The dft3 test has been converted to ztest (test/ztest/unit/math/dft3). Remove the CMocka version, the last test in test/cmocka/src/math, and move its reference vectors (ref_dft3_32.h) and their generator script (ref_dft3.m) with git mv into the ztest suite's directory, which included them from the CMocka tree. The script now finds the export helpers in test/cmocka/m from its new directory. Code coverage testing did not reveal any regression. Every line of fft_multi_generic.c that the CMocka test covers is covered by the ztest suite. CMock stats for fft_multi_generic.c (host gcc, unit_test_defconfig) - lines: 32.3 % (20/62) - branches: 22.9 % (11/48) Ztest stats for fft_multi_generic.c (native_sim, host LLVM) - lines: 27.3 % (18/66) - branches: 8.3 % (2/24) 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 DC blocking filter math test has been converted to ztest (test/ztest/unit/math/dcblock). Remove the CMocka version. The dcblock_process test in the same directory is not converted yet and stays. Code coverage testing did not reveal any regression. Every line of dcblock_generic.c that the CMocka test covers is covered by the ztest suite. The ztest build also compiles the float path, which neither test exercises. CMock stats for dcblock_generic.c (host gcc, unit_test_defconfig) - lines: 100.0 % (78/78) - branches: 70.7 % (41/58) Ztest stats for dcblock_generic.c (native_sim, host LLVM) - lines: 74.0 % (74/100) - branches: 60.0 % (24/40) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The fast-get tests have been converted to ztest (test/ztest/unit/fast-get). Remove the CMocka version. Code coverage testing did not reveal any regression. Every line of zephyr/lib/fast-get.c that the CMocka test covers is covered by the ztest suite, except the "Put called to unknown address" error path of fast_put(). The CMocka size mismatch test reached it by accident: it passed the address of its pointer array to fast_put(), which the ztest version corrects to the allocation it got. CMock stats for fast-get.c (host gcc, unit_test_defconfig) - lines: 96.2 % (77/80) - branches: 60.5 % (23/38) Ztest stats for fast-get.c (native_sim, host LLVM) - lines: 80.2 % (81/101) - branches: 51.9 % (27/52) 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 four component buffer tests (buffer_copy, buffer_new, buffer_wrap and buffer_write) have been converted to one ztest suite of nine cases (test/ztest/unit/audio/buffer). Remove the CMocka versions. Code coverage testing did not reveal any regression. Every line of comp_buffer.c, audio_buffer.c and audio_stream.c that the CMocka tests cover is covered by the ztest suite. CMock stats for comp_buffer.c, audio_buffer.c, audio_stream.c (host gcc, unit_test_defconfig) - lines: 26.2 % (87/332) - branches: 8.3 % (19/230) Ztest stats for comp_buffer.c, audio_buffer.c, audio_stream.c (native_sim, host LLVM) - lines: 23.6 % (87/368) - branches: 10.3 % (15/146) 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 alloc, rstrcmp and rstrlen tests check the host library's allocator (src/lib/alloc.c) and string functions (src/lib/lib.c). Both files are only built with CONFIG_LIBRARY, for the testbench and these unit tests. The firmware uses the Zephyr allocator in zephyr/lib/alloc.c and the inline rstrlen() and rstrcmp() wrappers in zephyr/include/rtos/string.h, which these tests do not cover. So they are removed rather than converted to ztest. The alloc test also added the cAVS platform include directories to sof_options for all CMocka tests. The remaining tests build and pass without them, for every CMocka defconfig. 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 the mux and demux components, porting the three CMocka tests in test/cmocka/src/audio/mux/ as three ztest suites in one application: - mux_copy: 27 cases, one per frame format (S16_LE, S24_4LE, S32_LE) and routing mask set (9 sets). Each case creates a mux through the IPC3 comp_new() path with four sources and one sink, copies one frame and checks the output against the routing masks. - demux_copy: 27 cases, the same formats and mask sets for a demux with one source and four sinks. - mux_get_processing_function: 5 cases, the invalid format, S16_LE, S24_4LE and S32_LE cases, and the FLOAT case. The FLOAT case is guarded by CONFIG_FORMAT_FLOAT as in CMocka; it is built on native_sim, which enables CONFIG_FORMAT_FLOAT, while the CMocka build did not run it. The cases use the same input vectors, mask sets and checks as the CMocka tests and keep their names, for example test_mux_copy_s16le_mask_0. The suite links the same SOF sources as the CMocka audio_mux library: mux.c, mux_ipc3.c and mux_generic.c, the module adapter with its IPC3 part, the component buffer, source and sink API, component.c and data_blob.c, the IPC3 helper for comp_new(), ipc-helper.c, objpool.c and numbers.c. The notifier mocks are not needed. The SOF heap is the real zephyr/lib/alloc.c, routed to the host malloc() of native_sim with CONFIG_SOF_NATIVE_SIM_HOST_HEAP so that ASan and LSan cover it, and sof_get() comes from test/ztest/unit/common/sof_context.c. Adapted: - The buffer helpers of test/cmocka/src/util.h and the component IPC setup, which each CMocka file had its own copy of, are shared in mux_test_util.c. - Teardown is done in the ztest after hooks, so that the component and its buffers are also freed when a case fails. - The dummy pipeline that bypasses comp_check_eos() is zero-initialised with calloc() instead of left uninitialised. - mux_test_util.c defines an idc_send_msg() that fails the test if it is called. comp_prepare() is an inline function with a branch that sends an IDC message for shared components on another core. The test components are never shared, but builds without optimization, such as the coverage build, still reference idc_send_msg(). 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 mux_copy, demux_copy and mux_get_processing_function tests that have been successfully converted to the new framework (from cmock to ztest), together with their CMakeLists.txt, the now empty test/cmocka/src/audio/mux directory and its add_subdirectory() entry. Code coverage testing did not reveal any regression. CMock stats for mux.c, mux_generic.c, mux_ipc3.c (host gcc, unit_test_defconfig) - lines: 86.8 % (515/593) - branches: 59.7 % (191/320) Ztest stats for mux.c, mux_generic.c, mux_ipc3.c (native_sim, host LLVM) - lines: 83.7 % (507/606) - branches: 69.2 % (180/260) Every line of the three files that the CMocka tests execute is also executed by the ztest suite. 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 the DRC fixed-point 1/x function drc_inv_fixed(), covering the same three cases as the CMocka drc_math_test: Q12 to Q30, Q22 to Q26 and Q31 to Q20, each over 500 or 501 inputs from 1 to INT32_MAX, checked against a double precision reference with the same absolute and relative error limits. The suite lives in test/ztest/unit/math/drc, as it tests math functions only; test/ztest/unit/audio/drc tests the DRC component processing. The same sources as the CMocka target are linked: drc_math_generic.c, drc_math_hifi3.c, numbers.c, exp_fcn.c and exp_fcn_hifi.c. The HiFi3 variants compile to nothing on native_sim. CONFIG_COMP_DRC=y is set, because the DRC SIMD level choice depends on it; on native_sim it selects DRC_HIFI_NONE, i.e. the generic implementation, as the CMocka unit_test_defconfig does. The values printed in the error messages are computed with ((int64_t)1 << q) instead of (1 << q), which overflowed for q = 31. They are not used by the checks. 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 drc_math_test test that has been successfully converted to the new framework (from cmock to ztest) in test/ztest/unit/math/drc. It was the only test in test/cmocka/src/audio/drc, so the directory and its add_subdirectory() entry are removed too. Code coverage testing did not reveal any regression. CMock stats for drc_math_generic.c, drc_math_hifi3.c, numbers.c, exp_fcn.c, exp_fcn_hifi.c (host gcc, unit_test_defconfig) - lines: 18.6 % (44/236) - branches: 22.2 % (16/72) Ztest stats for drc_math_generic.c, drc_math_hifi3.c, numbers.c, exp_fcn.c, exp_fcn_hifi.c (native_sim, host LLVM) - lines: 21.2 % (44/208) - branches: 22.2 % (16/72) Every line covered by the CMocka test is also covered by the ztest suite. Both exercise only drc_inv_fixed(), its rexp_fixed() helper and norm_int32() from numbers.c; the HiFi3 sources have no code on the host. 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 the generic float PCM conversions, covering the same nine cases as the CMocka pcm_float_generic test: S16_LE, S24_4LE (with and without sign extension) and S32_LE to float, and float to S16_LE, S24_4LE and S32_LE, including saturation of large and infinite values. Each case converts the same sample vectors from one component buffer to another with pcm_get_conversion_function() and checks every sample, and that the byte after the last sample is left untouched. The CMocka build links twenty two SOF sources and the notifier mocks. Only fourteen are needed here: the two PCM converter sources, component.c for the cir_buf_copy() used by pcm_converter.c, numbers.c, and the heap and buffer sources the buffer suite links. The pipeline, IPC3 helper, IPC common and data blob code and the notifier mocks are dropped. As in the CMocka build, PCM_CONVERTER_GENERIC is defined, because pcm_converter.h does not select an implementation under UNIT_TEST. CONFIG_FPU is not set on native_sim, so the conversions use the integer-only float code, as they did in the CMocka build. Adapted from the CMocka version: - The buffers come from buffer_new() directly. The dummy source and sink components that test/cmocka/src/util.h attached to them are not used by the conversion functions and are not allocated. - assert_float_equal() is replaced by a helper with the same rule: the values are equal if they differ by at most epsilon, or by at most FLT_EPSILON relative to the larger of them. The integer results of the two big value cases are compared as floats, as before. - The arrays that are scaled or masked in place are automatic instead of static, so a case gives the same result if it runs again. - Int constants that do not fit a float exactly are cast to float explicitly, as clang rejects the implicit conversion with -Werror,-Wimplicit-const-int-float-conversion. The values are the same. - The number of conversion functions is printed from the suite setup instead of main(). 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 pcm_float_generic test that has been successfully converted to the new framework (from cmock to ztest) in test/ztest/unit/audio/pcm_converter. It was the only test in test/cmocka/src/audio/pcm_converter, so the directory and its add_subdirectory() entry are removed too. The test is built only with CONFIG_FORMAT_FLOAT, which since commit 856cf13 ("kconfig: audio: gate CONFIG_FORMAT_FLOAT on hardware floating-point support") depends on SOF_HAS_FLOAT_HW. Neither CPU_HAS_FPU nor XTENSA exists in the CMocka Kconfig, so no CMocka defconfig has built or run this test since then. The ztest suite runs it again on native_sim, where CPU_HAS_FPU is set. Code coverage testing did not reveal any regression. The CMocka numbers were measured with SOF_HAS_FLOAT_HW forced on in a local, uncommitted Kconfig change. CMock stats for pcm_converter.c, pcm_converter_generic.c (host gcc, unit_test_defconfig) - lines: 34.9 % (101/289) - branches: 33.0 % (35/106) Ztest stats for pcm_converter.c, pcm_converter_generic.c (native_sim, host LLVM) - lines: 32.9 % (96/292) - branches: 30.0 % (30/100) Every line covered by the CMocka test is also covered by the ztest suite; the lines the ztest build does not report are variable declarations that LLVM attributes no code to. 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>
This was referenced Nov 28, 2026
lgirdwood
marked this pull request as ready for review
November 28, 2026 17:08
lgirdwood
requested review from
dbaluta,
kv2019i,
lbetlej,
mmaka1 and
plbossart
as code owners
November 28, 2026 17:08
PR 11556: test resultsRun date: 2026-11-28 17:45 UTC Tested commit: 5e9d77c75714b4e9e48092d6ce6009c6a1976170 |
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: retire the CMocka unit tests, so that the testbench is the only user of the host library (
CONFIG_LIBRARY,posix/include). First of three PRs. This one, the processing module ports (#11557) and the pipeline ports with the framework removal (#11558) follow the pattern of the earlier conversions by @tmleman: one commit adds the ztest suite, the next removes the CMocka test and records the coverage of both.Patches
Remove the CMocka tests that already have ztest versions
git mvinto the ztest suite, which included them from the CMocka tree.Remove the host library allocator and string tests
alloc,rstrcmpandrstrlentestsrc/lib/alloc.candsrc/lib/lib.c, which only the host library builds. The firmware useszephyr/lib/alloc.cand the inline wrappers inzephyr/include/rtos/string.h, which these tests do not cover. So they are removed rather than converted.Convert to ztest
audio/muxmath/drcaudio/pcm_converterCoverage
Each removal commit has the coverage of the code under test with both frameworks:
unit_test_defconfig;Every line that a CMocka test covers is covered by its ztest suite, with one exception: fast-get's "unknown address" path. The CMocka test only reached it by passing the address of its pointer array to
fast_put(), which the ztest version corrects. The totals differ because gcc and LLVM count lines and branches differently.What the ports found
CONFIG_FORMAT_FLOATon hardware float support, which no CMocka defconfig has. native_sim enables it, so the ztest suite runs the test again.mux_get_processing_functionwas never run, for the same reason.Testing
All of the above was run on 64b7446 (main).
🤖 Generated with Claude Code