Repository navigation
test: convert CMocka tests to ztest, part 2: processing modules - #11557
Merged
lgirdwood merged 12 commits intoNov 28, 2026
Merged
Conversation
This was referenced Nov 28, 2026
lgirdwood
marked this pull request as ready for review
November 28, 2026 17:16
lgirdwood
requested review from
dbaluta,
kv2019i,
lbetlej,
mmaka1,
plbossart and
singalsu
as code owners
November 28, 2026 17:16
PR 11557: test resultsRun date: 2026-11-28 19:06 UTC Tested commit: e6df678e21317b3163c48e64e8c0ac9a6cdd57ff |
Add a ztest suite for the generic C volume processing functions in volume_generic.c, covering the same nine cases as the CMocka test: the S16_LE, S24_4LE and S32_LE formats, each at the VOL_MAX, VOL_ZERO_DB and -80 dB gains, two channels and 48 frames. The source signal, the double precision reference and the +-1 LSB tolerance are unchanged, and the CMocka parameter table becomes one ztest case per format and gain. Like the CMocka test, the suite builds a processing module and component device by hand and calls the function returned by vol_get_processing_function() directly. The suite is built for IPC3, the native_sim default, as the CMocka test is under unit_test_defconfig, so the gains are Q8.16. The CMocka build links 33 SOF sources. Only volume_generic.c and the eleven sources needed for the test buffers are linked here, as in the buffer suite; volume.c, volume_ipc3.c, the module adapter, the IPC and pipeline code and the notifier mocks are dropped, since the test never calls into them (CMocka line coverage of volume.c and volume_ipc3.c is 0 %). The HiFi sources are inert on the host and are not linked either. The SOF heap is routed to the host malloc() so that ASan and LSan see the buffers. The CMocka setup also allocated cd->vol, which only the HiFi versions use, so it is dropped. The S24 reference multiplies the sample by 256 instead of shifting a negative value left by 8, which gives the same result without undefined behaviour. 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 volume_process test that has been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for volume_generic.c, volume.h (host gcc, unit_test_defconfig) - lines: 60.0 % (87/145) - branches: 43.2 % (38/88) Ztest stats for volume_generic.c, volume.h (native_sim, host LLVM) - lines: 45.9 % (78/170) - branches: 38.9 % (28/72) Every line of volume_generic.c and volume.h that the CMocka test covers is also covered by the ztest suite. The ztest denominator is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in the float processing and passthrough functions, which neither test exercises. 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 C mixing functions in mixer_generic.c, covering the same ten cases as the CMocka test: 1, 2, 3, 4, 6 and 8 S32_LE sources of 2 channels, and 1 and 2 sources of 4 and 8 channels, 48 frames each. Each source is filled with the same sine wave as in the CMocka test and every output sample must equal the saturated sum of the input samples. The CMocka case names are kept as the ztest case names. Like the CMocka test, the suite builds a component device and its buffers by hand and calls the function returned by mixer_get_processing_function() directly. The CMocka build links 30 SOF sources. Only mixer_generic.c and the eleven sources needed for the test buffers are linked here, as in the buffer suite; mixer.c, the module adapter, the IPC and pipeline code and the notifier mocks are dropped, since the test never calls into them (CMocka line coverage of mixer.c is 0 %). mixer_hifi3.c is inert on the host and is not linked either. The SOF heap is routed to the host malloc() so that ASan and LSan see the buffers. M_PI is defined locally as in the dcblock suite. 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 mixer test that has been successfully converted to the new framework (from cmock to ztest). comp_mock.c and comp_mock.h are removed with it; comp_mock.c was not part of the mixer target and neither file had other users. module_adapter_test.c and module_adapter.h are removed too, since the volume_process and mixer tests were their only users. Code coverage testing did not reveal any regression. CMock stats for mixer_generic.c, mixer.h (host gcc, unit_test_defconfig) - lines: 35.0 % (49/140) - branches: 30.9 % (34/110) Ztest stats for mixer_generic.c, mixer.h (native_sim, host LLVM) - lines: 26.2 % (51/195) - branches: 23.9 % (22/92) Every line of mixer_generic.c and mixer.h that the CMocka test covers is also covered by the ztest suite. The CMocka test covers no line of mixer.c. The ztest denominator is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in mix_n_float(), which neither test exercises. 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 the 16 cases of the CMocka selector test to the selector ztest suite, in a new source file and an IPC3 build of the suite. None of the CMocka cases was already covered by the existing suite. The CMocka test is built for IPC3 (all the CMocka defconfigs, including unit_test_defconfig, are IPC3), so it tests the IPC3 channel selection functions sel_s16le_1ch(), sel_s16le_nch(), sel_s32le_1ch() and sel_s32le_nch() through the IPC3 sel_get_processing_function(dev). The existing suite is built for IPC4, where selector_generic.c compiles the IPC4 coefficient matrix functions instead, so none of its twelve cases can reach the IPC3 functions. The IPC4 branch of the CMocka test was never built. selector_ipc3_ztest.c is built by a new sof.unit.audio.selector.ipc3 scenario that uses prj_ipc3.conf, the existing prj.conf with CONFIG_IPC_MAJOR_3=y instead of CONFIG_IPC_MAJOR_4=y. CMakeLists.txt selects the sources by CONFIG_IPC_MAJOR_3; the IPC4 source list of the existing suite is unchanged, only indented. Like the CMocka test, the IPC3 cases build a component device and its buffers by hand and call the processing function directly, so only selector_generic.c and the sources needed for the test buffers are linked, with the suite's common/alloc.c allocator wrappers; selector.c, the IPC, pipeline and component code and the notifier mocks of the CMocka build are dropped. The cases keep the CMocka parameter table: S16_LE and S24_4LE, 2 to 1 channel with channel 0 and 1 selected at 16 and 48 frames, 2 to 2 and 4 to 4 channel passthrough and 4 to 1 channel at 48 frames. The table lists the 2 to 1 channel, channel 0, 48 frame case twice per format; both entries are kept, the second with a _repeat suffix. The identical CMocka 2ch_to_2ch and 4ch_to_4ch verify functions are merged into one nch_to_nch function per format. The S32 2 to 1 and 4 to 1 channel check compared only the low 16 bits of the samples (as uint16_t), which are zero for every sample of the test signal, so it also passed for a wrong sample such as one from another channel. It compares the full 32 bit samples here. 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 selector test that has been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for selector_generic.c (host gcc, unit_test_defconfig) - lines: 93.7 % (119/127) - branches: 62.1 % (41/66) Ztest stats for selector_generic.c (native_sim, host LLVM), IPC3 scenario sof.unit.audio.selector.ipc3 - lines: 89.7 % (113/126) - branches: 62.1 % (41/66) Ztest stats for selector_generic.c (native_sim, host LLVM), both scenarios of the suite merged - lines: 85.8 % (283/330) - branches: 66.1 % (115/174) Every line of selector_generic.c that the CMocka test covers is also covered by the ztest suite. The CMocka test covers no line of selector.c. The lines the IPC3 scenario misses are the error returns of the source and sink buffer requests and the NULL return of sel_get_processing_function(), which neither test exercises; gcc attributes some of them to other lines. The merged totals are larger because the IPC4 scenario compiles the IPC4 processing functions instead of the IPC3 ones. 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 FIR equalizer component, with the same six cases as the CMocka test eq_fir_process: the 9600 sample two channel chirp filtered in S16, S24 and S32 and compared to the reference output with the same tolerances (1, 2 and 4 LSB), the rounding down of an odd frame count, the eleven malformed configuration blobs that must be rejected, and, with IPC3, the rejection of an unknown frame format by set_fir_func(). The processing cases keep the random frame count jitter of the CMocka test; the native_sim build links the host C library, so rand() is the same unseeded generator as in the CMocka build. As in the CMocka test the component is created with comp_new() from an IPC3 description, configured through set_configuration() and prepared and run through module_prepare() and module_process_sink_src(). The suite links the FIR EQ and FIR math sources of the CMocka build, the module adapter, buffer, source/sink, component, data blob, objpool and IPC3 helper code they need, the real SOF allocator zephyr/lib/alloc.c with the host heap back end (CONFIG_SOF_NATIVE_SIM_HOST_HEAP) so that ASan and LSan see the allocations, and the minimal sof_get() from test/ztest/unit/common. The pipeline sources, ipc-common.c, ipc-common-kernel.c and the notifier mocks of the CMocka build are not needed and are dropped. The CMocka setup and teardown become a helper called by each case and a ztest after-hook, so the component and buffers are released also when an assertion fails. The stream parameters handed to module_prepare() are zero initialised; CMocka test_malloc() filled them with 0xba bytes apart from the channel count. The optional DEBUG_FILES output is kept, the files are written to the current directory, which under twister is the build directory of the suite. The reference data headers are included in place from the CMocka tree for now, and cmocka_chirp_2ch.h from test/cmocka/include, which is still shared with other CMocka tests. 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 eq_fir_process test that has been successfully converted to the new framework (from cmock to ztest), together with its audio_for_eq_fir helper library and the eq_fir directory, of which it was the only test. The reference data cmocka_fir_ref.h and cmocka_fir_coef_2ch.h and the debug_files_plot.m script for the optional DEBUG_FILES output are only used by this test and are moved with git mv into the ztest suite directory. The script now loads the files from the current directory, which is where the ztest suite writes them, instead of from the CMocka build directory. The suite drops the include path to the CMocka directory, and the Octave script src/audio/eq_iir/tune/sof_cmocka_data_eq_fir.m, which generates the reference data, now writes the two headers to their new location. Code coverage testing did not reveal any regression. CMock stats for eq_fir.c, eq_fir_ipc3.c, eq_fir_generic.c, fir_generic.c (host gcc, unit_test_defconfig) - lines: 75.4 % (381/505) - branches: 54.2 % (142/262) Ztest stats for eq_fir.c, eq_fir_ipc3.c, eq_fir_generic.c, fir_generic.c (native_sim, host LLVM) - lines: 54.0 % (369/683) - branches: 44.1 % (123/279) Every line covered by the CMocka test in these files is also covered by the ztest suite. The ztest denominators are larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in the float FIR path (eq_fir_setup_float() and eq_fir_float()), which neither test exercises and which the CMocka build does not compile. The totals also 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 IIR equalizer component, with the same six cases as the CMocka test eq_iir_process: the 9600 sample two channel chirp filtered with the S16, S24 and S32 formats and with the S32 to S16 and S32 to S24 conversions, each compared to the reference output with the same tolerances (2, 128 and 32768 LSB), and the iir_delay_size_df1() check for valid and invalid series counts. The processing cases keep the random frame count jitter of the CMocka test; the native_sim build links the host C library, so rand() is the same unseeded generator as in the CMocka build. As in CMocka, the delay size check runs in its own suite without a component. As in the CMocka test the component is created with comp_new() from an IPC3 description, configured through set_configuration() and prepared and run through module_prepare() and module_process_sink_src(). The suite links the IIR EQ and DF1 IIR math sources of the CMocka build, the module adapter, buffer, source/sink, component, data blob, objpool and IPC3 helper code they need, the real SOF allocator zephyr/lib/alloc.c with the host heap back end (CONFIG_SOF_NATIVE_SIM_HOST_HEAP) so that ASan and LSan see the allocations, and the minimal sof_get() from test/ztest/unit/common. The DF2T IIR sources, which the IIR EQ does not use, the pipeline sources, ipc-common.c, ipc-common-kernel.c and the notifier mocks of the CMocka build are not needed and are dropped. The CMocka setup and teardown become a helper called by each case and a ztest after-hook, so the component and buffers are released also when an assertion fails. The helper is named eq_iir_test_setup(), eq_iir_setup() is taken by the component. The stream parameters handed to module_prepare() are zero initialised; CMocka test_malloc() filled them with 0xba bytes apart from the channel count. The reference data headers are included in place from the CMocka tree for now, and cmocka_chirp_2ch.h from test/cmocka/include, which is still shared with other CMocka tests. 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 eq_iir_process test that has been successfully converted to the new framework (from cmock to ztest), together with its audio_for_eq_iir helper library and the eq_iir directory, of which it was the only test. The reference data cmocka_chirp_iir_ref_2ch.h and cmocka_iir_coef_2ch.h are only used by this test and are moved with git mv into the ztest suite directory. The suite drops the include path to the CMocka directory, and the Octave script src/audio/eq_iir/tune/sof_cmocka_data_eq_iir.m, which generates the reference data, now writes the two headers to their new location. Code coverage testing did not reveal any regression. CMock stats for eq_iir.c, eq_iir_ipc3.c, eq_iir_generic.c, iir_df1.c, iir_df1_generic.c (host gcc, unit_test_defconfig) - lines: 75.3 % (476/632) - branches: 48.0 % (164/342) Ztest stats for eq_iir.c, eq_iir_ipc3.c, eq_iir_generic.c, iir_df1.c, iir_df1_generic.c (native_sim, host LLVM) - lines: 61.4 % (428/697) - branches: 47.1 % (129/274) Every line covered by the CMocka test in these files is also covered by the ztest suite. The ztest line count is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in the float IIR path (eq_iir_setup_float(), eq_iir_float_default() and its selection in eq_iir_new_blob()), which neither test exercises and which the CMocka build does not compile. The totals also 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 DC blocking filter component, with the same three cases as the CMocka test dcblock_process: the 9600 sample two channel chirp filtered in S16, S24 and S32 and compared to the same double precision reference filter with the same tolerances (2, 4 and 2048 LSB). The processing cases keep the random frame count jitter of the CMocka test; the native_sim build links the host C library, so rand() is the same unseeded generator as in the CMocka build. As in the CMocka test the component is created with comp_new() from an IPC3 description, configured with a COMP_CMD_SET_DATA command through module_adapter_cmd() and prepared and run through module_prepare() and module_process_sink_src(). The suite links the DC blocker sources of the CMocka build, the module adapter, buffer, source/sink, component, data blob, objpool and IPC3 helper code they need, the real SOF allocator zephyr/lib/alloc.c with the host heap back end (CONFIG_SOF_NATIVE_SIM_HOST_HEAP) so that ASan and LSan see the allocations, and the minimal sof_get() from test/ztest/unit/common. The pipeline sources, ipc-common.c, ipc-common-kernel.c and the notifier mocks of the CMocka build are not needed and are dropped. The CMocka setup and teardown become a helper called by each case and a ztest after-hook, so the component and buffers are released also when an assertion fails. The stream parameters handed to module_prepare() are zero initialised; CMocka test_malloc() filled them with 0xba bytes apart from the channel count. This suite is separate from test/ztest/unit/math/dcblock, which covers the dcblock_math_test CMocka test of the filter functions alone. cmocka_chirp_2ch.h is included in place from test/cmocka/include, which is still shared with other CMocka tests. 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 dcblock_process test that has been successfully converted to the new framework (from cmock to ztest), together with its audio_for_dcblock helper library. It was the last test in test/cmocka/src/audio/dcblock, so the directory and its add_subdirectory() entry are removed too. The test computes its reference output itself and has no reference data files to move. Code coverage testing did not reveal any regression. CMock stats for dcblock.c, dcblock_ipc3.c, dcblock_generic.c (host gcc, unit_test_defconfig) - lines: 79.2 % (164/207) - branches: 57.1 % (72/126) Ztest stats for dcblock.c, dcblock_ipc3.c, dcblock_generic.c (native_sim, host LLVM) - lines: 69.1 % (163/236) - branches: 57.9 % (44/76) Every line covered by the CMocka test in these files is also covered by the ztest suite. The ztest line count is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in the float path (dcblock_generic_float() and dcblock_float_default()), which neither test exercises and which the CMocka build does not compile. The totals also 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>
lgirdwood
force-pushed
the
kernel-user/ztest-port-b
branch
from
November 28, 2026 18:32
4e6a725 to
e6df678
Compare
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. Second of three PRs, after #11556 (merged); #11558 removes the framework: convert the CMocka tests of the processing modules to ztest suites that run on native_sim with ASan and LSan. As in the earlier conversions, one commit adds the ztest suite and the next removes the CMocka test and records the coverage of both.
Patches
audio/volumeaudio/mixeraudio/selector, new IPC3 scenarioaudio/eq_firaudio/eq_iiraudio/dcblockmalloc(), so that ASan and LSan cover it.git mvinto the ztest suites, and the Octave scripts that generate it write it there.test/cmocka/include; test: convert CMocka tests to ztest, part 3: pipeline, and remove CMocka #11558 moves it.selector_generic.ccompiles different functions. The CMocka test covered the IPC3 channel selection functions, so its cases go into a new IPC3 scenario of the same suite. The existing IPC4 cases are unchanged.Coverage
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. The ztest totals are lower mainly because native_sim enables
CONFIG_FORMAT_FLOAT, which compiles float paths that neither test runs, and because gcc and LLVM count lines differently.What the ports found
The selector's S32 checks compared only the low 16 bits of each sample, which are zero for the whole test signal, so they could not fail. The ztest version compares all 32 bits.
Testing
All of the above was run on c04d3f1 (main), and ZTest and CMocka again after rebasing onto 817cefb (current main, with #11556).
Changes since the last push
🤖 Generated with Claude Code