From 7dd2f8d08e23e1abed0a65a1056153656d9c781f Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:09:58 +0100 Subject: [PATCH 1/8] cmocka: Remove a_law_codec test This patch removes the a_law_codec test that has been successfully converted to the new framework (from cmock to ztest). a_law_codec.h is moved with git mv into the ztest suite's own directory, since it is only needed by this test. ref_chirp_mono_8k_s16.h stays #included in place from the CMocka tree for now: it is still shared with the CMocka mu_law test, and will move once that test is removed too. Code coverage testing did not reveal any regression. CMock stats for a_law.c - lines: 100.0 % (32/32) - branches: 100.0 % (8/8) Ztest stats for a_law.c - lines: 96.6 % (28/29) - branches: 90.0 % (9/10) The denominators differ because gcc and clang instrument the same source at different line/branch granularity; both frameworks exercise the same chirp reference vectors end to end. Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- .../cmocka/src/math/arithmetic/CMakeLists.txt | 5 -- test/cmocka/src/math/arithmetic/a_law_codec.c | 62 ------------------- test/ztest/unit/math/a_law/CMakeLists.txt | 4 +- .../unit/math/a_law}/a_law_codec.h | 0 .../unit/math/a_law/test_a_law_codec_ztest.c | 8 ++- 5 files changed, 7 insertions(+), 72 deletions(-) delete mode 100644 test/cmocka/src/math/arithmetic/a_law_codec.c rename test/{cmocka/src/math/arithmetic => ztest/unit/math/a_law}/a_law_codec.h (100%) diff --git a/test/cmocka/src/math/arithmetic/CMakeLists.txt b/test/cmocka/src/math/arithmetic/CMakeLists.txt index 6625aef444ef..9eeba6c27081 100644 --- a/test/cmocka/src/math/arithmetic/CMakeLists.txt +++ b/test/cmocka/src/math/arithmetic/CMakeLists.txt @@ -1,10 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -cmocka_test(a_law_codec - a_law_codec.c - ${PROJECT_SOURCE_DIR}/src/math/a_law.c -) - cmocka_test(mu_law_codec mu_law_codec.c ${PROJECT_SOURCE_DIR}/src/math/mu_law.c diff --git a/test/cmocka/src/math/arithmetic/a_law_codec.c b/test/cmocka/src/math/arithmetic/a_law_codec.c deleted file mode 100644 index a0bc4f7aef41..000000000000 --- a/test/cmocka/src/math/arithmetic/a_law_codec.c +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2025 Intel Corporation. - -#include -#include -#include -#include -#include -#include - -#include "ref_chirp_mono_8k_s16.h" -#include "a_law_codec.h" - -static void test_a_law_encode(void **state) -{ - (void)state; - - uint8_t a_law_sample, a_law_ref; - int i; - - for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) { - a_law_sample = sofm_a_law_encode(chirp_mono_8k_s16[i]); - a_law_ref = ref_alaw_enc_data[i]; - - if (a_law_sample != a_law_ref) { - printf("%s: difference found at %d, encoded %d, ref %d, lin %d\n", - __func__, i, a_law_sample, a_law_ref, chirp_mono_8k_s16[i]); - assert_true(false); - } - } -} - -static void test_a_law_decode(void **state) -{ - (void)state; - - int16_t s16_sample, s16_ref; - int i; - - for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) { - s16_sample = sofm_a_law_decode(ref_alaw_enc_data[i]); - s16_ref = ref_alaw_dec_data[i]; - if (s16_sample != s16_ref) { - printf("%s: difference found at %d, decoded %d, ref %d\n", - __func__, i, s16_sample, s16_ref); - assert_true(false); - } - } -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_a_law_encode), - cmocka_unit_test(test_a_law_decode), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/a_law/CMakeLists.txt b/test/ztest/unit/math/a_law/CMakeLists.txt index b1ffae46d4d3..8e530e6b8141 100644 --- a/test/ztest/unit/math/a_law/CMakeLists.txt +++ b/test/ztest/unit/math/a_law/CMakeLists.txt @@ -12,8 +12,8 @@ set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..") target_include_directories(app PRIVATE ${SOF_ROOT}/zephyr/include ${SOF_ROOT}/src/include - # Reference test vectors are #included in place from the CMocka tree - # rather than copied, so both frameworks share identical data. + # ref_chirp_mono_8k_s16.h is still shared with the CMocka mu_law test + # via this include path; a_law_codec.h is colocated with this test. ${SOF_ROOT}/test/cmocka/src/math/arithmetic ) diff --git a/test/cmocka/src/math/arithmetic/a_law_codec.h b/test/ztest/unit/math/a_law/a_law_codec.h similarity index 100% rename from test/cmocka/src/math/arithmetic/a_law_codec.h rename to test/ztest/unit/math/a_law/a_law_codec.h diff --git a/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c b/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c index be7ccf735bd0..ac429f50deba 100644 --- a/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c +++ b/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c @@ -14,9 +14,11 @@ #include #include -/* Reference test vectors shared with the legacy CMocka test. They are - * #included in place from the CMocka tree (added to the include path in - * CMakeLists.txt) so the exact same fixed-point data is exercised. +/* a_law_codec.h was moved here from the legacy CMocka tree + * (test/cmocka/src/math/arithmetic/) when that CMocka test was removed. + * ref_chirp_mono_8k_s16.h is still shared with the CMocka mu_law test and + * stays #included in place from the CMocka tree until that test is removed + * too, so both frameworks keep exercising identical fixed-point data. */ #include "ref_chirp_mono_8k_s16.h" #include "a_law_codec.h" From 40291d20835bd8f617a73d80bb0b6f14d002cb5e Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:16:50 +0100 Subject: [PATCH 2/8] cmocka: Remove mu_law_codec test This patch removes the mu_law_codec test that has been successfully converted to the new framework (from cmock to ztest). mu_law_codec.h is moved with git mv into the ztest suite's own directory. This was the last CMocka consumer of ref_chirp_mono_8k_s16.h and a_law_mu_law_test_vectors.m, which also move with git mv into a new shared test/ztest/unit/math/ arithmetic directory; the a_law suite (already ported and ref_chirp consumer) now points its include path there instead of the CMocka tree. With both arithmetic tests gone, test/cmocka/src/math/arithmetic/ is now empty and is removed along with its add_subdirectory() call. Code coverage testing did not reveal any regression. CMock stats for mu_law.c - lines: 100.0 % (31/31) - branches: 100.0 % (6/6) Ztest stats for mu_law.c - lines: 100.0 % (26/26) - branches: 100.0 % (6/6) Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/CMakeLists.txt | 1 - .../cmocka/src/math/arithmetic/CMakeLists.txt | 6 -- .../cmocka/src/math/arithmetic/mu_law_codec.c | 62 ------------------- test/ztest/unit/math/a_law/CMakeLists.txt | 6 +- .../unit/math/a_law/test_a_law_codec_ztest.c | 10 +-- .../arithmetic/a_law_mu_law_test_vectors.m | 0 .../math/arithmetic/ref_chirp_mono_8k_s16.h | 0 test/ztest/unit/math/mu_law/CMakeLists.txt | 5 +- .../unit/math/mu_law}/mu_law_codec.h | 0 .../math/mu_law/test_mu_law_codec_ztest.c | 6 ++ 10 files changed, 17 insertions(+), 79 deletions(-) delete mode 100644 test/cmocka/src/math/arithmetic/CMakeLists.txt delete mode 100644 test/cmocka/src/math/arithmetic/mu_law_codec.c rename test/{cmocka/src => ztest/unit}/math/arithmetic/a_law_mu_law_test_vectors.m (100%) rename test/{cmocka/src => ztest/unit}/math/arithmetic/ref_chirp_mono_8k_s16.h (100%) rename test/{cmocka/src/math/arithmetic => ztest/unit/math/mu_law}/mu_law_codec.h (100%) diff --git a/test/cmocka/src/math/CMakeLists.txt b/test/cmocka/src/math/CMakeLists.txt index 83180953eb55..3eed3626fab9 100644 --- a/test/cmocka/src/math/CMakeLists.txt +++ b/test/cmocka/src/math/CMakeLists.txt @@ -1,6 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -add_subdirectory(arithmetic) add_subdirectory(fft) add_subdirectory(window) add_subdirectory(matrix) diff --git a/test/cmocka/src/math/arithmetic/CMakeLists.txt b/test/cmocka/src/math/arithmetic/CMakeLists.txt deleted file mode 100644 index 9eeba6c27081..000000000000 --- a/test/cmocka/src/math/arithmetic/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(mu_law_codec - mu_law_codec.c - ${PROJECT_SOURCE_DIR}/src/math/mu_law.c -) diff --git a/test/cmocka/src/math/arithmetic/mu_law_codec.c b/test/cmocka/src/math/arithmetic/mu_law_codec.c deleted file mode 100644 index cee690e9e947..000000000000 --- a/test/cmocka/src/math/arithmetic/mu_law_codec.c +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2025 Intel Corporation. - -#include -#include -#include -#include -#include -#include - -#include "ref_chirp_mono_8k_s16.h" -#include "mu_law_codec.h" - -static void test_mu_law_encode(void **state) -{ - (void)state; - - uint8_t mu_law_sample, mu_law_ref; - int i; - - for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) { - mu_law_sample = sofm_mu_law_encode(chirp_mono_8k_s16[i]); - mu_law_ref = ref_mulaw_enc_data[i]; - - if (mu_law_sample != mu_law_ref) { - printf("%s: difference found at %d, encoded %d, ref %d, lin %d\n", - __func__, i, mu_law_sample, mu_law_ref, chirp_mono_8k_s16[i]); - assert_true(false); - } - } -} - -static void test_mu_law_decode(void **state) -{ - (void)state; - - int16_t s16_sample, s16_ref; - int i; - - for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) { - s16_sample = sofm_mu_law_decode(ref_mulaw_enc_data[i]); - s16_ref = ref_mulaw_dec_data[i]; - if (s16_sample != s16_ref) { - printf("%s: difference found at %d, byte %d, decoded %d, ref %d\n", - __func__, i, ref_mulaw_enc_data[i], s16_sample, s16_ref); - assert_true(false); - } - } -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_mu_law_encode), - cmocka_unit_test(test_mu_law_decode), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/a_law/CMakeLists.txt b/test/ztest/unit/math/a_law/CMakeLists.txt index 8e530e6b8141..d4e4d6fbe438 100644 --- a/test/ztest/unit/math/a_law/CMakeLists.txt +++ b/test/ztest/unit/math/a_law/CMakeLists.txt @@ -12,9 +12,9 @@ set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..") target_include_directories(app PRIVATE ${SOF_ROOT}/zephyr/include ${SOF_ROOT}/src/include - # ref_chirp_mono_8k_s16.h is still shared with the CMocka mu_law test - # via this include path; a_law_codec.h is colocated with this test. - ${SOF_ROOT}/test/cmocka/src/math/arithmetic + # ref_chirp_mono_8k_s16.h is shared with the mu_law suite; a_law_codec.h + # is colocated with this test. + ${SOF_ROOT}/test/ztest/unit/math/arithmetic ) # Define SOF-specific configurations for unit testing diff --git a/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c b/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c index ac429f50deba..3a147450c3e5 100644 --- a/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c +++ b/test/ztest/unit/math/a_law/test_a_law_codec_ztest.c @@ -14,11 +14,11 @@ #include #include -/* a_law_codec.h was moved here from the legacy CMocka tree - * (test/cmocka/src/math/arithmetic/) when that CMocka test was removed. - * ref_chirp_mono_8k_s16.h is still shared with the CMocka mu_law test and - * stays #included in place from the CMocka tree until that test is removed - * too, so both frameworks keep exercising identical fixed-point data. +/* ref_chirp_mono_8k_s16.h is shared with the mu_law suite via the + * test/ztest/unit/math/arithmetic include path; a_law_codec.h is colocated + * with this test. Both were moved here from the legacy CMocka tree + * (test/cmocka/src/math/arithmetic/) when the CMocka a_law/mu_law tests + * were removed, preserving the exact same fixed-point data. */ #include "ref_chirp_mono_8k_s16.h" #include "a_law_codec.h" diff --git a/test/cmocka/src/math/arithmetic/a_law_mu_law_test_vectors.m b/test/ztest/unit/math/arithmetic/a_law_mu_law_test_vectors.m similarity index 100% rename from test/cmocka/src/math/arithmetic/a_law_mu_law_test_vectors.m rename to test/ztest/unit/math/arithmetic/a_law_mu_law_test_vectors.m diff --git a/test/cmocka/src/math/arithmetic/ref_chirp_mono_8k_s16.h b/test/ztest/unit/math/arithmetic/ref_chirp_mono_8k_s16.h similarity index 100% rename from test/cmocka/src/math/arithmetic/ref_chirp_mono_8k_s16.h rename to test/ztest/unit/math/arithmetic/ref_chirp_mono_8k_s16.h diff --git a/test/ztest/unit/math/mu_law/CMakeLists.txt b/test/ztest/unit/math/mu_law/CMakeLists.txt index 2b2ac8f580af..ea427ad68e3f 100644 --- a/test/ztest/unit/math/mu_law/CMakeLists.txt +++ b/test/ztest/unit/math/mu_law/CMakeLists.txt @@ -12,8 +12,9 @@ set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..") target_include_directories(app PRIVATE ${SOF_ROOT}/zephyr/include ${SOF_ROOT}/src/include - # Share the reference vectors with the legacy CMocka test. - ${SOF_ROOT}/test/cmocka/src/math/arithmetic + # ref_chirp_mono_8k_s16.h is shared with the a_law suite; mu_law_codec.h + # is colocated with this test. + ${SOF_ROOT}/test/ztest/unit/math/arithmetic ) target_compile_definitions(app PRIVATE diff --git a/test/cmocka/src/math/arithmetic/mu_law_codec.h b/test/ztest/unit/math/mu_law/mu_law_codec.h similarity index 100% rename from test/cmocka/src/math/arithmetic/mu_law_codec.h rename to test/ztest/unit/math/mu_law/mu_law_codec.h diff --git a/test/ztest/unit/math/mu_law/test_mu_law_codec_ztest.c b/test/ztest/unit/math/mu_law/test_mu_law_codec_ztest.c index c277222afe6e..727a2ff5a387 100644 --- a/test/ztest/unit/math/mu_law/test_mu_law_codec_ztest.c +++ b/test/ztest/unit/math/mu_law/test_mu_law_codec_ztest.c @@ -11,6 +11,12 @@ #include /* Include the same fixed-point reference vectors as the CMocka test. */ +/* ref_chirp_mono_8k_s16.h is shared with the a_law suite via the + * test/ztest/unit/math/arithmetic include path; mu_law_codec.h is colocated + * with this test. Both were moved here from the legacy CMocka tree + * (test/cmocka/src/math/arithmetic/) when the CMocka a_law/mu_law tests + * were removed, preserving the exact same fixed-point data. + */ #include "ref_chirp_mono_8k_s16.h" #include "mu_law_codec.h" From a0b6c2c765195cb96639bc2a33b101f6580405cd Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:21:11 +0100 Subject: [PATCH 3/8] cmocka: Remove fft test This patch removes the fft test that has been successfully converted to the new framework (from cmock to ztest). input.h is moved with git mv into the ztest suite's own directory, since it was only needed by this test; the dft3 and fft_multi targets in the same CMocka directory use their own separate reference headers and are unaffected. Code coverage testing did not reveal any regression. CMock stats for fft_common.c, fft_32.c, fft_16.c - lines: 87.9 % (124/141) - branches: 64.0 % (57/89) Ztest stats for fft_common.c, fft_32.c, fft_16.c - lines: 84.5 % (109/129) - branches: 74.7 % (56/75) Both suites exercise mod_fft_plan_new()/mod_fft_plan_free() and fft_execute_16()/fft_execute_32() identically; the fft_16_hifi3.c and fft_32_hifi3.c sources remain linked but inert on native_sim/host (gated by FFT_HIFI3, only active under __XCC__). Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/fft/CMakeLists.txt | 30 - test/cmocka/src/math/fft/fft.c | 841 ------------------ test/ztest/unit/math/fft/CMakeLists.txt | 3 - .../src => ztest/unit}/math/fft/input.h | 0 test/ztest/unit/math/fft/test_fft_ztest.c | 5 +- 5 files changed, 2 insertions(+), 877 deletions(-) delete mode 100644 test/cmocka/src/math/fft/fft.c rename test/{cmocka/src => ztest/unit}/math/fft/input.h (100%) diff --git a/test/cmocka/src/math/fft/CMakeLists.txt b/test/cmocka/src/math/fft/CMakeLists.txt index 79234b7b12f9..31b64f080159 100644 --- a/test/cmocka/src/math/fft/CMakeLists.txt +++ b/test/cmocka/src/math/fft/CMakeLists.txt @@ -1,35 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -cmocka_test(fft - fft.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_common.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_16.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_16_hifi3.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_32.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_32_hifi3.c - ${PROJECT_SOURCE_DIR}/src/audio/buffers/comp_buffer.c - ${PROJECT_SOURCE_DIR}/src/audio/buffers/audio_buffer.c - ${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c - ${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c - ${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c - ${PROJECT_SOURCE_DIR}/src/audio/audio_stream.c - ${PROJECT_SOURCE_DIR}/src/module/audio/source_api.c - ${PROJECT_SOURCE_DIR}/src/module/audio/sink_api.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c - ${PROJECT_SOURCE_DIR}/src/kernel/ipc/ipc3/helper.c - ${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c - ${PROJECT_SOURCE_DIR}/src/kernel/ipc/ipc-common-kernel.c - ${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c - ${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-graph.c - ${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-params.c - ${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c - ${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c - ${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c - ${PROJECT_SOURCE_DIR}/src/audio/component.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) - cmocka_test(dft3 dft3.c ${PROJECT_SOURCE_DIR}/src/math/fft/fft_multi.c diff --git a/test/cmocka/src/math/fft/fft.c b/test/cmocka/src/math/fft/fft.c deleted file mode 100644 index dc3dc8e70524..000000000000 --- a/test/cmocka/src/math/fft/fft.c +++ /dev/null @@ -1,841 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2020 Intel Corporation. All rights reserved. -// -// Author: Keyon Jie - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "input.h" - -/* SNR DB threshold */ -#define FFT_DB_TH_16 27.0 -#define FFT_DB_TH 95.0 -#define SINE_HZ 1000 - -/* For rectangular window frequency matched sine wave test */ -#define TWO_PI 6.28318530717959 -#define SINE_SCALE_S16 32767.0 -#define SINE_SCALE_S32 2147483647.0 -#define SINE_FS 48000.0 -#define SINE_BASE (SINE_FS / 256.0) /* One perid exactly 256 samples, 187.5 Hz */ -#define SINE_FREQ (4.0 * SINE_BASE) /* Four periods, 1125 Hz */ -#define MIN_SNR_256_16 49.0 -#define MIN_SNR_512_16 42.0 -#define MIN_SNR_1024_16 38.0 -#define MIN_SNR_256 132.0 -#define MIN_SNR_512 125.0 -#define MIN_SNR_1024 119.0 - -struct processing_module dummy; - -/** - * \brief Doing Fast Fourier Transform (FFT) for mono real input buffers. - * \param[in] src - pointer to input buffer. - * \param[out] dst - pointer to output buffer, FFT output for input buffer. - * \param[in] size - input buffer sample count. - */ -static void fft_real(struct comp_buffer *src, struct comp_buffer *dst, uint32_t size) -{ - struct icomplex32 *inb; - struct icomplex32 *outb; - struct fft_plan *plan; - int i; - - if (audio_stream_get_channels(&src->stream) != 1) - return; - - if (src->stream.size < size * sizeof(int32_t) || - dst->stream.size < size * sizeof(struct icomplex32)) - return; - - inb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex32)); - if (!inb) - return; - outb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex32)); - if (!outb) - goto err_outb; - - plan = mod_fft_plan_new(&dummy, inb, outb, size, 32); - if (!plan) - goto err_plan; - - for (i = 0; i < size; i++) { - inb[i].real = *((int32_t *)src->stream.addr + i); - inb[i].imag = 0; - } - - /* perform a single FFT transform */ - fft_execute_32(plan, false); - - for (i = 0; i < size; i++) { - *((int32_t *)dst->stream.addr + 2 * i) = outb[i].real; - *((int32_t *)dst->stream.addr + 2 * i + 1) = outb[i].imag; - } - - mod_fft_plan_free(&dummy, plan); - -err_plan: - rfree(outb); -err_outb: - rfree(inb); -} - -/** - * \brief Doing Inverse Fast Fourier Transform (IFFT) for mono complex input buffers. - * \param[in] src - pointer to input buffer. - * \param[out] dst - pointer to output buffer, FFT output for input buffer. - * \param[in] size - input buffer sample count. - */ -static void ifft_complex(struct comp_buffer *src, struct comp_buffer *dst, uint32_t size) -{ - struct icomplex32 *inb; - struct icomplex32 *outb; - struct fft_plan *plan; - int i; - - if (audio_stream_get_channels(&src->stream) != 1) - return; - - if (src->stream.size < size * sizeof(struct icomplex32) || - dst->stream.size < size * sizeof(struct icomplex32)) - return; - - inb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex32)); - if (!inb) - return; - - outb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex32)); - if (!outb) - goto err_outb; - - plan = mod_fft_plan_new(&dummy, inb, outb, size, 32); - if (!plan) - goto err_plan; - - for (i = 0; i < size; i++) { - inb[i].real = *((int32_t *)src->stream.addr + 2 * i); - inb[i].imag = *((int32_t *)src->stream.addr + 2 * i + 1); - } - - /* perform a single IFFT transform */ - fft_execute_32(plan, true); - - for (i = 0; i < size; i++) { - *((int32_t *)dst->stream.addr + 2 * i) = outb[i].real; - *((int32_t *)dst->stream.addr + 2 * i + 1) = outb[i].imag; - } - - mod_fft_plan_free(&dummy, plan); - -err_plan: - rfree(outb); -err_outb: - rfree(inb); -} - -/** - * \brief Doing Fast Fourier Transform (FFT) for 2 real input buffers. - * \param[in] src - pointer to input buffer (2 channels). - * \param[out] dst1 - pointer to output buffer, FFT output for input buffer 1. - * \param[out] dst2 - pointer to output buffer, FFT output for input buffer 2. - * \param[in] size - input buffer sample count. - */ -static void fft_real_2(struct comp_buffer *src, struct comp_buffer *dst1, - struct comp_buffer *dst2, uint32_t size) -{ - struct icomplex32 *inb; - struct icomplex32 *outb; - struct fft_plan *plan; - int i; - - if (audio_stream_get_channels(&src->stream) != 2) - return; - - if (src->stream.size < size * sizeof(int32_t) * 2 || - dst1->stream.size < size * sizeof(struct icomplex32) || - dst2->stream.size < size * sizeof(struct icomplex32)) - return; - - inb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex32)); - if (!inb) - return; - - outb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex32)); - if (!outb) - goto err_outb; - - plan = mod_fft_plan_new(&dummy, inb, outb, size, 32); - if (!plan) - goto err_plan; - - /* generate complex inputs */ - for (i = 0; i < size; i++) { - inb[i].real = *((int32_t *)src->stream.addr + 2 * i); - inb[i].imag = *((int32_t *)src->stream.addr + 2 * i + 1); - } - - /* perform a single FFT transform */ - fft_execute_32(plan, false); - - /* calculate the outputs */ - *((int32_t *)dst1->stream.addr) = outb[0].real; - *((int32_t *)dst1->stream.addr + 1) = 0; - *((int32_t *)dst2->stream.addr) = 0; - *((int32_t *)dst2->stream.addr + 1) = -outb[0].imag; - for (i = 1; i < size; i++) { - *((int32_t *)dst1->stream.addr + 2 * i) = - (outb[i].real + outb[size - i].real) / 2; - *((int32_t *)dst1->stream.addr + 2 * i + 1) = - (outb[i].imag - outb[size - i].imag) / 2; - *((int32_t *)dst2->stream.addr + 2 * i) = - (outb[i].imag + outb[size - i].imag) / 2; - *((int32_t *)dst2->stream.addr + 2 * i + 1) = - (outb[size - i].real - outb[i].real) / 2; - } - - mod_fft_plan_free(&dummy, plan); - -err_plan: - rfree(outb); -err_outb: - rfree(inb); -} - -static int power_peak_index_32(struct icomplex32 *out, int fft_size) -{ - int64_t p; - int64_t peak = 0; - int i; - int r = 0; - - /* looking for the peak */ - for (i = 0; i < fft_size / 2; i++) { - p = (int64_t)out[i].real * out[i].real + (int64_t)out[i].imag * out[i].imag; - if (p > peak) { - peak = p; - r = i; - } - } - - return r; -} - -static double integrate_power_32(struct icomplex32 *s, int start_idx, int end_idx) -{ - double energy = 0; - int i; - - for (i = start_idx; i <= end_idx; i++) - energy += (double)s[i].real * s[i].real + (double)s[i].imag * s[i].imag; - - return energy; -} - -static void get_sine_32(int32_t *in, double sine_freq, double fs, int fft_size) -{ - double c = TWO_PI * sine_freq / fs; - double w; - int i; - - for (i = 0; i < fft_size; i++) { - w = c * i; - in[i] = (int32_t)round(SINE_SCALE_S32 * sin(w)); - } -} - -static void test_math_fft_256(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 256 * 2 * sizeof(int32_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex32 *out = (struct icomplex32 *)sink->stream.addr; - int32_t *in = (int32_t *)source->stream.addr; - int fft_size = 256; - int r; - int i; - double signal; - double noise; - double snr; - - (void)state; - - /* create sine wave */ - get_sine_32(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real(source, sink, fft_size); - - /* find peak */ - r = power_peak_index_32(out, fft_size); - i = (int)round((SINE_FREQ * fft_size) / SINE_FS); - printf("%s: peak at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* the min. SNR should be met */ - noise = integrate_power_32(out, 0, i - 2); - signal = integrate_power_32(out, i - 1, i + 1); - noise += integrate_power_32(out, i + 2, fft_size / 2 - 1); - snr = 10 * log10(signal / noise); - printf("%s: SNR %5.2f dB\n", __func__, snr); - assert_int_equal(snr < MIN_SNR_256, 0); - - buffer_free(source); - buffer_free(sink); -} - -static void test_math_fft_512(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 512 * 2 * sizeof(int32_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex32 *out = (struct icomplex32 *)sink->stream.addr; - int32_t *in = (int32_t *)source->stream.addr; - int fft_size = 512; - int r; - int i; - double signal; - double noise; - double snr; - - (void)state; - - /* create sine wave */ - get_sine_32(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real(source, sink, fft_size); - - /* find peak */ - r = power_peak_index_32(out, fft_size); - i = (int)round((SINE_FREQ * fft_size) / SINE_FS); - printf("%s: peak at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* the min. SNR should be met */ - noise = integrate_power_32(out, 0, i - 2); - signal = integrate_power_32(out, i - 1, i + 1); - noise += integrate_power_32(out, i + 2, fft_size / 2 - 1); - snr = 10 * log10(signal / noise); - printf("%s: SNR %5.2f dB\n", __func__, snr); - assert_int_equal(snr < MIN_SNR_512, 0); - - buffer_free(source); - buffer_free(sink); -} - -static void test_math_fft_1024(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 1024 * 2 * sizeof(int32_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex32 *out = (struct icomplex32 *)sink->stream.addr; - int32_t *in = (int32_t *)source->stream.addr; - int fft_size = 1024; - int r; - int i; - double signal; - double noise; - double snr; - - (void)state; - - /* create sine wave */ - get_sine_32(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real(source, sink, fft_size); - - /* find peak */ - r = power_peak_index_32(out, fft_size); - i = (int)round((SINE_FREQ * fft_size) / SINE_FS); - printf("%s: peak at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* the min. SNR should be met */ - noise = integrate_power_32(out, 0, i - 2); - signal = integrate_power_32(out, i - 1, i + 1); - noise += integrate_power_32(out, i + 2, fft_size / 2 - 1); - snr = 10 * log10(signal / noise); - printf("%s: SNR %5.2f dB\n", __func__, snr); - assert_int_equal(snr < MIN_SNR_1024, 0); - - buffer_free(source); - buffer_free(sink); -} - -static void test_math_fft_1024_ifft(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 1024 * 4 * 2, - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *intm = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex32 *out = (struct icomplex32 *)sink->stream.addr; - float db; - int64_t signal = 0; - int64_t noise = 0; - uint32_t fft_size = 1024; - int32_t *in = (int32_t *)source->stream.addr; - int i; - - (void)state; - - get_sine_32(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real(source, intm, fft_size); - - audio_stream_set_channels(&intm->stream, 1); - /* do ifft transform */ - ifft_complex(intm, sink, fft_size); - - /* calculate signal and noise */ - for (i = 0; i < fft_size; i++) { - signal += (int64_t)(in[i] / 32) * (in[i] / 32); - noise += (int64_t)((out[i].real - in[i]) / 32) * - ((out[i].real - in[i]) / 32) + - (int64_t)(out[i].imag / 32) * (out[i].imag / 32); - } - - db = 10 * log10((float)signal / noise); - printf("%s: SNR: %6.2f dB\n", __func__, db); - assert_int_equal(db < FFT_DB_TH, 0); - - buffer_free(source); - buffer_free(intm); - buffer_free(sink); -} - -static void test_math_fft_512_2ch(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 512 * 4 * 2, - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink1 = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink2 = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex32 *out1 = (struct icomplex32 *)sink1->stream.addr; - struct icomplex32 *out2 = (struct icomplex32 *)sink2->stream.addr; - uint32_t fft_size = 512; - int i; - int r; - - (void)state; - - for (i = 0; i < fft_size; i++) { - *((int32_t *)source->stream.addr + 2 * i) = input_samples[i]; - *((int32_t *)source->stream.addr + 2 * i + 1) = input_samples[fft_size + i]; - } - - audio_stream_set_channels(&source->stream, 2); - /* do fft transform */ - fft_real_2(source, sink1, sink2, fft_size); - - /* looking for the peak for channel 0 */ - r = power_peak_index_32(out1, fft_size); - i = (SINE_HZ * fft_size) / 48000; - printf("%s: peak for channel 0 at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* looking for the peak for channel 1 */ - r = power_peak_index_32(out2, fft_size); - i = (SINE_HZ * fft_size) / 48000; - printf("%s: peak for channel 1 at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - buffer_free(source); - buffer_free(sink1); - buffer_free(sink2); -} - -/** - * \brief Doing Fast Fourier Transform (FFT) for mono real input buffers. - * \param[in] src - pointer to input buffer. - * \param[out] dst - pointer to output buffer, FFT output for input buffer. - * \param[in] size - input buffer sample count. - */ -static void fft_real_16(struct comp_buffer *src, struct comp_buffer *dst, uint32_t size) -{ - struct icomplex16 *inb; - struct icomplex16 *outb; - struct fft_plan *plan; - int i; - - if (audio_stream_get_channels(&src->stream) != 1) - return; - - if (src->stream.size < size * sizeof(int16_t) || - dst->stream.size < size * sizeof(struct icomplex16)) - return; - - inb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex16)); - if (!inb) - return; - outb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex16)); - if (!outb) - goto err_outb; - - plan = mod_fft_plan_new(&dummy, inb, outb, size, 16); - if (!plan) - goto err_plan; - - for (i = 0; i < size; i++) { - inb[i].real = *((int16_t *)src->stream.addr + i); - inb[i].imag = 0; - } - - /* perform a single FFT transform */ - fft_execute_16(plan, false); - - for (i = 0; i < size; i++) { - *((int16_t *)dst->stream.addr + 2 * i) = outb[i].real; - *((int16_t *)dst->stream.addr + 2 * i + 1) = outb[i].imag; - } - - mod_fft_plan_free(&dummy, plan); - -err_plan: - rfree(outb); -err_outb: - rfree(inb); -} - -/** - * \brief Doing Inverse Fast Fourier Transform (IFFT) for mono complex input buffers. - * \param[in] src - pointer to input buffer. - * \param[out] dst - pointer to output buffer, FFT output for input buffer. - * \param[in] size - input buffer sample count. - */ -static void ifft_complex_16(struct comp_buffer *src, struct comp_buffer *dst, uint32_t size) -{ - struct icomplex16 *inb; - struct icomplex16 *outb; - struct fft_plan *plan; - int i; - - if (audio_stream_get_channels(&src->stream) != 1) - return; - - if (src->stream.size < size * sizeof(struct icomplex16) || - dst->stream.size < size * sizeof(struct icomplex16)) - return; - - inb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex16)); - if (!inb) - return; - - outb = rzalloc(SOF_MEM_FLAG_USER, - size * sizeof(struct icomplex16)); - if (!outb) - goto err_outb; - - plan = mod_fft_plan_new(&dummy, inb, outb, size, 16); - if (!plan) - goto err_plan; - - for (i = 0; i < size; i++) { - inb[i].real = *((int16_t *)src->stream.addr + 2 * i); - inb[i].imag = *((int16_t *)src->stream.addr + 2 * i + 1); - } - - /* perform a single IFFT transform */ - fft_execute_16(plan, true); - - for (i = 0; i < size; i++) { - *((int16_t *)dst->stream.addr + 2 * i) = outb[i].real; - *((int16_t *)dst->stream.addr + 2 * i + 1) = outb[i].imag; - } - - mod_fft_plan_free(&dummy, plan); - -err_plan: - rfree(outb); -err_outb: - rfree(inb); -} - -static int power_peak_index_16(struct icomplex16 *out, int fft_size) -{ - int32_t p; - int32_t peak = 0; - int i; - int r = 0; - - /* looking for the peak */ - for (i = 0; i < fft_size / 2; i++) { - p = (int32_t)out[i].real * out[i].real + (int32_t)out[i].imag * out[i].imag; - if (p > peak) { - peak = p; - r = i; - } - } - - return r; -} - -static double integrate_power_16(struct icomplex16 *s, int start_idx, int end_idx) -{ - double energy = 0; - int i; - - for (i = start_idx; i <= end_idx; i++) - energy += (double)s[i].real * s[i].real + (double)s[i].imag * s[i].imag; - - return energy; -} - -static void get_sine_16(int16_t *in, double sine_freq, double fs, int fft_size) -{ - double c = TWO_PI * sine_freq / fs; - double w; - int i; - - for (i = 0; i < fft_size; i++) { - w = c * i; - in[i] = (int16_t)round(SINE_SCALE_S16 * sin(w)); - } -} - -static void test_math_fft_256_16(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 256 * 2 * sizeof(int16_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex16 *out = (struct icomplex16 *)sink->stream.addr; - int16_t *in = (int16_t *)source->stream.addr; - int fft_size = 256; - int r; - int i; - double signal; - double noise; - double snr; - - (void)state; - - /* create sine wave */ - get_sine_16(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real_16(source, sink, fft_size); - - /* find peak */ - r = power_peak_index_16(out, fft_size); - i = (int)round((SINE_FREQ * fft_size) / SINE_FS); - printf("%s: peak at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* the min. SNR should be met */ - noise = integrate_power_16(out, 0, i - 2); - signal = integrate_power_16(out, i - 1, i + 1); - noise += integrate_power_16(out, i + 2, fft_size / 2 - 1); - snr = 10 * log10(signal / noise); - printf("%s: SNR %5.2f dB\n", __func__, snr); - assert_int_equal(snr < MIN_SNR_256_16, 0); - - buffer_free(source); - buffer_free(sink); -} - -static void test_math_fft_512_16(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 512 * 2 * sizeof(int16_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex16 *out = (struct icomplex16 *)sink->stream.addr; - int16_t *in = (int16_t *)source->stream.addr; - int fft_size = 512; - int r; - int i; - double signal; - double noise; - double snr; - - (void)state; - - /* create sine wave */ - get_sine_16(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real_16(source, sink, fft_size); - - /* find peak */ - r = power_peak_index_16(out, fft_size); - i = (int)round((SINE_FREQ * fft_size) / SINE_FS); - printf("%s: peak at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* the min. SNR should be met */ - noise = integrate_power_16(out, 0, i - 2); - signal = integrate_power_16(out, i - 1, i + 1); - noise += integrate_power_16(out, i + 2, fft_size / 2 - 1); - snr = 10 * log10(signal / noise); - printf("%s: SNR %5.2f dB\n", __func__, snr); - assert_int_equal(snr < MIN_SNR_512_16, 0); - - buffer_free(source); - buffer_free(sink); -} - -static void test_math_fft_1024_16(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 1024 * 2 * sizeof(int16_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex16 *out = (struct icomplex16 *)sink->stream.addr; - int16_t *in = (int16_t *)source->stream.addr; - int fft_size = 1024; - int r; - int i; - double signal; - double noise; - double snr; - - (void)state; - - /* create sine wave */ - get_sine_16(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real_16(source, sink, fft_size); - - /* find peak */ - r = power_peak_index_16(out, fft_size); - i = (int)round((SINE_FREQ * fft_size) / SINE_FS); - printf("%s: peak at point %d\n", __func__, r); - - /* the peak should be in range i +/-1 */ - assert_in_range(r, i - 1, i + 1); - - /* the min. SNR should be met */ - noise = integrate_power_16(out, 0, i - 2); - signal = integrate_power_16(out, i - 1, i + 1); - noise += integrate_power_16(out, i + 2, fft_size / 2 - 1); - snr = 10 * log10(signal / noise); - printf("%s: SNR %5.2f dB\n", __func__, snr); - assert_int_equal(snr < MIN_SNR_1024_16, 0); - - buffer_free(source); - buffer_free(sink); -} - -static void test_math_fft_1024_ifft_16(void **state) -{ - struct sof_ipc_buffer test_buf_desc = { - .size = 1024 * 2 * sizeof(int16_t), - }; - struct comp_buffer *source = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *intm = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *sink = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct icomplex16 *out = (struct icomplex16 *)sink->stream.addr; - float db; - int64_t signal = 0; - int64_t noise = 0; - uint32_t fft_size = 1024; - int16_t *in = (int16_t *)source->stream.addr; - int i; - - (void)state; - - get_sine_16(in, SINE_FREQ, SINE_FS, fft_size); - audio_stream_set_channels(&source->stream, 1); - - /* do fft transform */ - fft_real_16(source, intm, fft_size); - - audio_stream_set_channels(&intm->stream, 1); - /* do ifft transform */ - ifft_complex_16(intm, sink, fft_size); - - /* calculate signal and noise */ - for (i = 0; i < fft_size; i++) { - signal += (int64_t)in[i] * in[i]; - noise += (int64_t)(out[i].real - in[i]) * (out[i].real - in[i]) + - (int64_t)out[i].imag * out[i].imag; - } - - db = 10 * log10((float)signal / noise); - printf("%s: SNR: %6.2f dB\n", __func__, db); - assert_int_equal(db < FFT_DB_TH_16, 0); - - buffer_free(source); - buffer_free(intm); - buffer_free(sink); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_math_fft_256_16), - cmocka_unit_test(test_math_fft_512_16), - cmocka_unit_test(test_math_fft_1024_16), - cmocka_unit_test(test_math_fft_1024_ifft_16), - cmocka_unit_test(test_math_fft_256), - cmocka_unit_test(test_math_fft_512), - cmocka_unit_test(test_math_fft_1024), - cmocka_unit_test(test_math_fft_1024_ifft), - cmocka_unit_test(test_math_fft_512_2ch), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/fft/CMakeLists.txt b/test/ztest/unit/math/fft/CMakeLists.txt index 0c7a8f13783f..1cdcd62ef978 100644 --- a/test/ztest/unit/math/fft/CMakeLists.txt +++ b/test/ztest/unit/math/fft/CMakeLists.txt @@ -20,9 +20,6 @@ target_include_directories(app PRIVATE ${SOF_ROOT}/src/audio ${SOF_ROOT}/test/ztest/unit/common ${SOF_ROOT}/test/cmocka/include - # Reference test vectors are #included in place from the CMocka tree - # rather than copied, so both frameworks share identical data. - ${SOF_ROOT}/test/cmocka/src/math/fft ${PROJECT_BINARY_DIR}/include/generated ) diff --git a/test/cmocka/src/math/fft/input.h b/test/ztest/unit/math/fft/input.h similarity index 100% rename from test/cmocka/src/math/fft/input.h rename to test/ztest/unit/math/fft/input.h diff --git a/test/ztest/unit/math/fft/test_fft_ztest.c b/test/ztest/unit/math/fft/test_fft_ztest.c index 28b9ce33cbf2..03bedcc4c457 100644 --- a/test/ztest/unit/math/fft/test_fft_ztest.c +++ b/test/ztest/unit/math/fft/test_fft_ztest.c @@ -27,9 +27,8 @@ #include "mod_alloc.h" -/* Reference test vectors shared with the legacy CMocka test. They are - * #included in place from the CMocka tree (added to the include path in - * CMakeLists.txt) so the exact same fixed-point data is exercised. +/* input.h was moved here from the legacy CMocka tree + * (test/cmocka/src/math/fft/) when that CMocka test was removed. */ #include "input.h" From 69988add1c2cb6a4dc30cd589ff4608e8dd1c46e Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:24:48 +0100 Subject: [PATCH 4/8] cmocka: Remove fft_multi test This patch removes the fft_multi test that has been successfully converted to the new framework (from cmock to ztest). The eleven ref_fft_multi_*_32.h / ref_ifft_multi_*_32.h reference vectors and the ref_fft_multi.m generation script are moved with git mv into the ztest suite's own directory. The dft3 target in the same CMocka directory uses its own separate ref_dft3_32.h and is unaffected. Code coverage testing did not reveal any regression. CMock stats for fft_multi_generic.c - lines: 100.0 % (62/62) - branches: 75.0 % (36/48) Ztest stats for fft_multi_generic.c - lines: 100.0 % (66/66) - branches: 100.0 % (24/24) Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/fft/CMakeLists.txt | 11 - test/cmocka/src/math/fft/fft_multi.c | 193 ------------------ test/ztest/unit/math/fft_multi/CMakeLists.txt | 3 - .../unit/math/fft_multi}/ref_fft_multi.m | 0 .../math/fft_multi}/ref_fft_multi_1024_32.h | 0 .../math/fft_multi}/ref_fft_multi_1536_32.h | 0 .../math/fft_multi}/ref_fft_multi_3072_32.h | 0 .../math/fft_multi}/ref_fft_multi_512_32.h | 0 .../math/fft_multi}/ref_fft_multi_768_32.h | 0 .../math/fft_multi}/ref_fft_multi_96_32.h | 0 .../math/fft_multi}/ref_ifft_multi_1024_32.h | 0 .../math/fft_multi}/ref_ifft_multi_1536_32.h | 0 .../math/fft_multi}/ref_ifft_multi_24_32.h | 0 .../math/fft_multi}/ref_ifft_multi_256_32.h | 0 .../math/fft_multi}/ref_ifft_multi_3072_32.h | 0 .../math/fft_multi/test_fft_multi_ztest.c | 5 +- 16 files changed, 2 insertions(+), 210 deletions(-) delete mode 100644 test/cmocka/src/math/fft/fft_multi.c rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi.m (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi_1024_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi_1536_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi_3072_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi_512_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi_768_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_fft_multi_96_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_ifft_multi_1024_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_ifft_multi_1536_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_ifft_multi_24_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_ifft_multi_256_32.h (100%) rename test/{cmocka/src/math/fft => ztest/unit/math/fft_multi}/ref_ifft_multi_3072_32.h (100%) diff --git a/test/cmocka/src/math/fft/CMakeLists.txt b/test/cmocka/src/math/fft/CMakeLists.txt index 31b64f080159..c481c7e9afee 100644 --- a/test/cmocka/src/math/fft/CMakeLists.txt +++ b/test/cmocka/src/math/fft/CMakeLists.txt @@ -10,14 +10,3 @@ cmocka_test(dft3 ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c ) - -cmocka_test(fft_multi - fft_multi.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_multi.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_multi_generic.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_multi_hifi3.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_common.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_32.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c -) diff --git a/test/cmocka/src/math/fft/fft_multi.c b/test/cmocka/src/math/fft/fft_multi.c deleted file mode 100644 index bf5bd49efb08..000000000000 --- a/test/cmocka/src/math/fft/fft_multi.c +++ /dev/null @@ -1,193 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2025 Intel Corporation. All rights reserved. -// -// Author: Seppo Ingalsuo - -#include -#include -#include -#include -#include "ref_fft_multi_96_32.h" -#include "ref_fft_multi_512_32.h" -#include "ref_fft_multi_768_32.h" -#include "ref_fft_multi_1024_32.h" -#include "ref_fft_multi_1536_32.h" -#include "ref_fft_multi_3072_32.h" - -#include "ref_ifft_multi_24_32.h" -#include "ref_ifft_multi_256_32.h" -#include "ref_ifft_multi_1024_32.h" -#include "ref_ifft_multi_1536_32.h" -#include "ref_ifft_multi_3072_32.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FFT_MAX_ERROR_ABS 1050.0 /* about -126 dB */ -#define FFT_MAX_ERROR_RMS 35.0 /* about -156 dB */ -#define IFFT_MAX_ERROR_ABS 2400000.0 /* about -59 dB */ -#define IFFT_MAX_ERROR_RMS 44000.0 /* about -94 dB */ - -struct processing_module dummy; - -static void fft_multi_32_test(const int32_t *in_real, const int32_t *in_imag, - const int32_t *ref_real, const int32_t *ref_imag, - int num_bins, int num_tests, double max_error_abs, - double max_error_rms, bool do_ifft) -{ - struct icomplex32 *x; - struct icomplex32 *y; - struct fft_multi_plan *plan; - double delta; - double error_rms; - double delta_max = 0; - double sum_squares = 0; - const int32_t *p_in_real = in_real; - const int32_t *p_in_imag = in_imag; - const int32_t *p_ref_real = ref_real; - const int32_t *p_ref_imag = ref_imag; - int i, j; - FILE *fh1, *fh2; - - x = malloc(num_bins * sizeof(struct icomplex32)); - if (!x) { - fprintf(stderr, "Failed to allocate input data buffer.\n"); - assert_true(false); - } - - y = malloc(num_bins * sizeof(struct icomplex32)); - if (!y) { - fprintf(stderr, "Failed to allocate output data buffer.\n"); - assert_true(false); - } - - plan = mod_fft_multi_plan_new(&dummy, x, y, num_bins, 32); - if (!plan) { - fprintf(stderr, "Failed to allocate FFT plan.\n"); - assert_true(false); - } - - fh1 = fopen("debug_fft_multi_in.txt", "w"); - fh2 = fopen("debug_fft_multi_out.txt", "w"); - - for (i = 0; i < num_tests; i++) { - for (j = 0; j < num_bins; j++) { - x[j].real = *p_in_real++; - x[j].imag = *p_in_imag++; - fprintf(fh1, "%d %d\n", x[j].real, x[j].imag); - } - - fft_multi_execute_32(plan, do_ifft); - - for (j = 0; j < num_bins; j++) { - fprintf(fh2, "%d %d %d %d\n", - y[j].real, y[j].imag, *p_ref_real, *p_ref_imag); - delta = (double)*p_ref_real - (double)y[j].real; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - - delta = (double)*p_ref_imag - (double)y[j].imag; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - - p_ref_real++; - p_ref_imag++; - } - - } - - mod_fft_multi_plan_free(&dummy, plan); - free(y); - free(x); - fclose(fh1); fclose(fh2); - - error_rms = sqrt(sum_squares / (double)(2 * num_bins * num_tests)); - printf("Max absolute error = %5.2f (limit %5.2f), error RMS = %5.2f (limit %5.2f)\n", - delta_max, max_error_abs, error_rms, max_error_rms); - - assert_true(error_rms < max_error_rms); - assert_true(delta_max < max_error_abs); -} - -static void fft_multi_32_test_1(void **state) -{ - (void)state; - - /* Test FFT */ - fft_multi_32_test(fft_in_real_96_q31, fft_in_imag_96_q31, - fft_ref_real_96_q31, fft_ref_imag_96_q31, - 96, REF_SOFM_FFT_MULTI_96_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - fft_multi_32_test(fft_in_real_512_q31, fft_in_imag_512_q31, - fft_ref_real_512_q31, fft_ref_imag_512_q31, - 512, REF_SOFM_FFT_MULTI_512_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - fft_multi_32_test(fft_in_real_768_q31, fft_in_imag_768_q31, - fft_ref_real_768_q31, fft_ref_imag_768_q31, - 768, REF_SOFM_FFT_MULTI_768_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - fft_multi_32_test(fft_in_real_1024_q31, fft_in_imag_1024_q31, - fft_ref_real_1024_q31, fft_ref_imag_1024_q31, - 1024, REF_SOFM_FFT_MULTI_1024_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - fft_multi_32_test(fft_in_real_1536_q31, fft_in_imag_1536_q31, - fft_ref_real_1536_q31, fft_ref_imag_1536_q31, - 1536, REF_SOFM_FFT_MULTI_1536_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - fft_multi_32_test(fft_in_real_3072_q31, fft_in_imag_3072_q31, - fft_ref_real_3072_q31, fft_ref_imag_3072_q31, - 3072, REF_SOFM_FFT_MULTI_3072_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - fft_multi_32_test(fft_in_real_3072_q31, fft_in_imag_3072_q31, - fft_ref_real_3072_q31, fft_ref_imag_3072_q31, - 3072, REF_SOFM_FFT_MULTI_3072_NUM_TESTS, - FFT_MAX_ERROR_ABS, FFT_MAX_ERROR_RMS, false); - - /* Test IFFT */ - fft_multi_32_test(ifft_in_real_24_q31, ifft_in_imag_24_q31, - ifft_ref_real_24_q31, ifft_ref_imag_24_q31, - 24, REF_SOFM_IFFT_MULTI_24_NUM_TESTS, - IFFT_MAX_ERROR_ABS, IFFT_MAX_ERROR_RMS, true); - fft_multi_32_test(ifft_in_real_256_q31, ifft_in_imag_256_q31, - ifft_ref_real_256_q31, ifft_ref_imag_256_q31, - 256, REF_SOFM_IFFT_MULTI_256_NUM_TESTS, - IFFT_MAX_ERROR_ABS, IFFT_MAX_ERROR_RMS, true); - fft_multi_32_test(ifft_in_real_1024_q31, ifft_in_imag_1024_q31, - ifft_ref_real_1024_q31, ifft_ref_imag_1024_q31, - 1024, REF_SOFM_IFFT_MULTI_1024_NUM_TESTS, - IFFT_MAX_ERROR_ABS, IFFT_MAX_ERROR_RMS, true); - fft_multi_32_test(ifft_in_real_1536_q31, ifft_in_imag_1536_q31, - ifft_ref_real_1536_q31, ifft_ref_imag_1536_q31, - 1536, REF_SOFM_IFFT_MULTI_1536_NUM_TESTS, - IFFT_MAX_ERROR_ABS, IFFT_MAX_ERROR_RMS, true); - fft_multi_32_test(ifft_in_real_3072_q31, ifft_in_imag_3072_q31, - ifft_ref_real_3072_q31, ifft_ref_imag_3072_q31, - 3072, REF_SOFM_IFFT_MULTI_3072_NUM_TESTS, - IFFT_MAX_ERROR_ABS, IFFT_MAX_ERROR_RMS, true); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(fft_multi_32_test_1), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/fft_multi/CMakeLists.txt b/test/ztest/unit/math/fft_multi/CMakeLists.txt index 3287559f3050..ce7d7d3b2b6e 100644 --- a/test/ztest/unit/math/fft_multi/CMakeLists.txt +++ b/test/ztest/unit/math/fft_multi/CMakeLists.txt @@ -19,9 +19,6 @@ target_include_directories(app PRIVATE ${SOF_ROOT}/src/kernel/platform/posix/include ${SOF_ROOT}/test/ztest/unit/common ${SOF_ROOT}/test/cmocka/include - # Reference test vectors are #included in place from the CMocka tree - # rather than copied, so both frameworks share identical data. - ${SOF_ROOT}/test/cmocka/src/math/fft ${PROJECT_BINARY_DIR}/include/generated ) diff --git a/test/cmocka/src/math/fft/ref_fft_multi.m b/test/ztest/unit/math/fft_multi/ref_fft_multi.m similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi.m rename to test/ztest/unit/math/fft_multi/ref_fft_multi.m diff --git a/test/cmocka/src/math/fft/ref_fft_multi_1024_32.h b/test/ztest/unit/math/fft_multi/ref_fft_multi_1024_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi_1024_32.h rename to test/ztest/unit/math/fft_multi/ref_fft_multi_1024_32.h diff --git a/test/cmocka/src/math/fft/ref_fft_multi_1536_32.h b/test/ztest/unit/math/fft_multi/ref_fft_multi_1536_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi_1536_32.h rename to test/ztest/unit/math/fft_multi/ref_fft_multi_1536_32.h diff --git a/test/cmocka/src/math/fft/ref_fft_multi_3072_32.h b/test/ztest/unit/math/fft_multi/ref_fft_multi_3072_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi_3072_32.h rename to test/ztest/unit/math/fft_multi/ref_fft_multi_3072_32.h diff --git a/test/cmocka/src/math/fft/ref_fft_multi_512_32.h b/test/ztest/unit/math/fft_multi/ref_fft_multi_512_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi_512_32.h rename to test/ztest/unit/math/fft_multi/ref_fft_multi_512_32.h diff --git a/test/cmocka/src/math/fft/ref_fft_multi_768_32.h b/test/ztest/unit/math/fft_multi/ref_fft_multi_768_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi_768_32.h rename to test/ztest/unit/math/fft_multi/ref_fft_multi_768_32.h diff --git a/test/cmocka/src/math/fft/ref_fft_multi_96_32.h b/test/ztest/unit/math/fft_multi/ref_fft_multi_96_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_fft_multi_96_32.h rename to test/ztest/unit/math/fft_multi/ref_fft_multi_96_32.h diff --git a/test/cmocka/src/math/fft/ref_ifft_multi_1024_32.h b/test/ztest/unit/math/fft_multi/ref_ifft_multi_1024_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_ifft_multi_1024_32.h rename to test/ztest/unit/math/fft_multi/ref_ifft_multi_1024_32.h diff --git a/test/cmocka/src/math/fft/ref_ifft_multi_1536_32.h b/test/ztest/unit/math/fft_multi/ref_ifft_multi_1536_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_ifft_multi_1536_32.h rename to test/ztest/unit/math/fft_multi/ref_ifft_multi_1536_32.h diff --git a/test/cmocka/src/math/fft/ref_ifft_multi_24_32.h b/test/ztest/unit/math/fft_multi/ref_ifft_multi_24_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_ifft_multi_24_32.h rename to test/ztest/unit/math/fft_multi/ref_ifft_multi_24_32.h diff --git a/test/cmocka/src/math/fft/ref_ifft_multi_256_32.h b/test/ztest/unit/math/fft_multi/ref_ifft_multi_256_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_ifft_multi_256_32.h rename to test/ztest/unit/math/fft_multi/ref_ifft_multi_256_32.h diff --git a/test/cmocka/src/math/fft/ref_ifft_multi_3072_32.h b/test/ztest/unit/math/fft_multi/ref_ifft_multi_3072_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_ifft_multi_3072_32.h rename to test/ztest/unit/math/fft_multi/ref_ifft_multi_3072_32.h diff --git a/test/ztest/unit/math/fft_multi/test_fft_multi_ztest.c b/test/ztest/unit/math/fft_multi/test_fft_multi_ztest.c index 2df55b4480ad..0747c3777d0b 100644 --- a/test/ztest/unit/math/fft_multi/test_fft_multi_ztest.c +++ b/test/ztest/unit/math/fft_multi/test_fft_multi_ztest.c @@ -20,9 +20,8 @@ #include "mod_alloc.h" -/* Reference test vectors shared with the legacy CMocka test. They are - * #included in place from the CMocka tree (added to the include path in - * CMakeLists.txt) so the exact same fixed-point data is exercised. +/* Reference test vectors were moved here from the legacy CMocka tree + * (test/cmocka/src/math/fft/) when that CMocka test was removed. */ #include "ref_fft_multi_96_32.h" #include "ref_fft_multi_512_32.h" From 6decaa9921973f2ad7386f3634a6578f8d86cd31 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:28:04 +0100 Subject: [PATCH 5/8] cmocka: Remove matrix test The matrix math component is already fully covered by the ztest port at test/ztest/unit/math/matrix/. Remove the now-redundant CMocka test and its CMakeLists.txt stanza, along with the whole matrix/ subdirectory (it was the last remaining test there). Move the reference test vectors reused by the ztest port (ref_matrix_mult_16_test{1,2,3,4}.h, ref_matrix.m) with git mv into test/ztest/unit/math/matrix/ to preserve file history, and drop the now-unneeded CMocka include path from the ztest CMakeLists.txt. CMock stats for src/math/matrix.c: - lines: 90% (48/53) - branches: 70% (24/34) Ztest stats for src/math/matrix.c: - lines: 85% (54/63) - branches: 70% (24/34) Branch coverage is identical between the two builds (same uncovered logic). The small line-coverage percentage difference is due to gcc vs clang instrumentation granularity (different line-count denominators for the same source), not a regression. Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/CMakeLists.txt | 1 - test/cmocka/src/math/matrix/CMakeLists.txt | 7 - test/cmocka/src/math/matrix/matrix.c | 183 ------------------ test/ztest/unit/math/matrix/CMakeLists.txt | 3 - .../unit}/math/matrix/ref_matrix.m | 0 .../math/matrix/ref_matrix_mult_16_test1.h | 0 .../math/matrix/ref_matrix_mult_16_test2.h | 0 .../math/matrix/ref_matrix_mult_16_test3.h | 0 .../math/matrix/ref_matrix_mult_16_test4.h | 0 .../unit/math/matrix/test_matrix_ztest.c | 5 +- 10 files changed, 2 insertions(+), 197 deletions(-) delete mode 100644 test/cmocka/src/math/matrix/CMakeLists.txt delete mode 100644 test/cmocka/src/math/matrix/matrix.c rename test/{cmocka/src => ztest/unit}/math/matrix/ref_matrix.m (100%) rename test/{cmocka/src => ztest/unit}/math/matrix/ref_matrix_mult_16_test1.h (100%) rename test/{cmocka/src => ztest/unit}/math/matrix/ref_matrix_mult_16_test2.h (100%) rename test/{cmocka/src => ztest/unit}/math/matrix/ref_matrix_mult_16_test3.h (100%) rename test/{cmocka/src => ztest/unit}/math/matrix/ref_matrix_mult_16_test4.h (100%) diff --git a/test/cmocka/src/math/CMakeLists.txt b/test/cmocka/src/math/CMakeLists.txt index 3eed3626fab9..c5764550541f 100644 --- a/test/cmocka/src/math/CMakeLists.txt +++ b/test/cmocka/src/math/CMakeLists.txt @@ -2,6 +2,5 @@ add_subdirectory(fft) add_subdirectory(window) -add_subdirectory(matrix) add_subdirectory(auditory) add_subdirectory(dct) diff --git a/test/cmocka/src/math/matrix/CMakeLists.txt b/test/cmocka/src/math/matrix/CMakeLists.txt deleted file mode 100644 index 2c5c0420fb35..000000000000 --- a/test/cmocka/src/math/matrix/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(matrix - matrix.c - ${PROJECT_SOURCE_DIR}/src/math/matrix.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c -) diff --git a/test/cmocka/src/math/matrix/matrix.c b/test/cmocka/src/math/matrix/matrix.c deleted file mode 100644 index 63632ba58c4b..000000000000 --- a/test/cmocka/src/math/matrix/matrix.c +++ /dev/null @@ -1,183 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2022 Intel Corporation. All rights reserved. -// -// Author: Seppo Ingalsuo - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ref_matrix_mult_16_test1.h" -#include "ref_matrix_mult_16_test2.h" -#include "ref_matrix_mult_16_test3.h" -#include "ref_matrix_mult_16_test4.h" - -#define MATRIX_MULT_16_MAX_ERROR_ABS 1.5 -#define MATRIX_MULT_16_MAX_ERROR_RMS 0.5 - -struct processing_module dummy; - -static void matrix_mult_16_test(const int16_t *a_ref, const int16_t *b_ref, const int16_t *c_ref, - int elementwise, int a_rows, int a_columns, - int b_rows, int b_columns, int c_rows, int c_columns, - int a_frac, int b_frac, int c_frac) -{ - struct mat_matrix_16b *a_matrix; - struct mat_matrix_16b *b_matrix; - struct mat_matrix_16b *c_matrix; - float delta; - float sum_squares = 0; - float error_rms; - float delta_max = 0; - int16_t x; - int i, j, k; - - a_matrix = mod_mat_matrix_alloc_16b(&dummy, a_rows, a_columns, a_frac); - if (!a_matrix) - exit(EXIT_FAILURE); - - b_matrix = mod_mat_matrix_alloc_16b(&dummy, b_rows, b_columns, b_frac); - if (!b_matrix) { - mod_free(&dummy, a_matrix); - exit(EXIT_FAILURE); - } - - c_matrix = mod_mat_matrix_alloc_16b(&dummy, c_rows, c_columns, c_frac); - if (!c_matrix) { - mod_free(&dummy, a_matrix); - mod_free(&dummy, b_matrix); - exit(EXIT_FAILURE); - } - - /* Initialize matrices a and b from test vectors and do matrix multiply */ - mat_copy_from_linear_16b(a_matrix, a_ref); - mat_copy_from_linear_16b(b_matrix, b_ref); - if (elementwise) - mat_multiply_elementwise(a_matrix, b_matrix, c_matrix); - else - mat_multiply(a_matrix, b_matrix, c_matrix); - - /* Check */ - k = 0; - for (i = 0; i < c_matrix->rows; i++) { - for (j = 0; j < c_matrix->columns; j++) { - x = mat_get_scalar_16b(c_matrix, i, j); - delta = (float)x - (float)c_ref[k++]; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - } - } - - error_rms = sqrt(sum_squares / (float)(c_matrix->rows * c_matrix->columns)); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, MATRIX_MULT_16_MAX_ERROR_ABS, error_rms, MATRIX_MULT_16_MAX_ERROR_RMS); - - assert_true(error_rms < MATRIX_MULT_16_MAX_ERROR_RMS); - assert_true(delta_max < MATRIX_MULT_16_MAX_ERROR_ABS); - - mod_free(&dummy, a_matrix); - mod_free(&dummy, b_matrix); - mod_free(&dummy, c_matrix); -} - -static void test_matrix_mult_16_test1(void **state) -{ - (void)state; - - matrix_mult_16_test(matrix_mult_16_test1_a, - matrix_mult_16_test1_b, - matrix_mult_16_test1_c, - MATRIX_MULT_16_TEST1_ELEMENTWISE, - MATRIX_MULT_16_TEST1_A_ROWS, - MATRIX_MULT_16_TEST1_A_COLUMNS, - MATRIX_MULT_16_TEST1_B_ROWS, - MATRIX_MULT_16_TEST1_B_COLUMNS, - MATRIX_MULT_16_TEST1_C_ROWS, - MATRIX_MULT_16_TEST1_C_COLUMNS, - MATRIX_MULT_16_TEST1_A_QXY_Y, - MATRIX_MULT_16_TEST1_B_QXY_Y, - MATRIX_MULT_16_TEST1_C_QXY_Y); -} - -static void test_matrix_mult_16_test2(void **state) -{ - (void)state; - - matrix_mult_16_test(matrix_mult_16_test2_a, - matrix_mult_16_test2_b, - matrix_mult_16_test2_c, - MATRIX_MULT_16_TEST2_ELEMENTWISE, - MATRIX_MULT_16_TEST2_A_ROWS, - MATRIX_MULT_16_TEST2_A_COLUMNS, - MATRIX_MULT_16_TEST2_B_ROWS, - MATRIX_MULT_16_TEST2_B_COLUMNS, - MATRIX_MULT_16_TEST2_C_ROWS, - MATRIX_MULT_16_TEST2_C_COLUMNS, - MATRIX_MULT_16_TEST2_A_QXY_Y, - MATRIX_MULT_16_TEST2_B_QXY_Y, - MATRIX_MULT_16_TEST2_C_QXY_Y); -} - -static void test_matrix_mult_16_test3(void **state) -{ - (void)state; - - matrix_mult_16_test(matrix_mult_16_test3_a, - matrix_mult_16_test3_b, - matrix_mult_16_test3_c, - MATRIX_MULT_16_TEST3_ELEMENTWISE, - MATRIX_MULT_16_TEST3_A_ROWS, - MATRIX_MULT_16_TEST3_A_COLUMNS, - MATRIX_MULT_16_TEST3_B_ROWS, - MATRIX_MULT_16_TEST3_B_COLUMNS, - MATRIX_MULT_16_TEST3_C_ROWS, - MATRIX_MULT_16_TEST3_C_COLUMNS, - MATRIX_MULT_16_TEST3_A_QXY_Y, - MATRIX_MULT_16_TEST3_B_QXY_Y, - MATRIX_MULT_16_TEST3_C_QXY_Y); -} - -static void test_matrix_mult_16_test4(void **state) -{ - (void)state; - - matrix_mult_16_test(matrix_mult_16_test4_a, - matrix_mult_16_test4_b, - matrix_mult_16_test4_c, - MATRIX_MULT_16_TEST4_ELEMENTWISE, - MATRIX_MULT_16_TEST4_A_ROWS, - MATRIX_MULT_16_TEST4_A_COLUMNS, - MATRIX_MULT_16_TEST4_B_ROWS, - MATRIX_MULT_16_TEST4_B_COLUMNS, - MATRIX_MULT_16_TEST4_C_ROWS, - MATRIX_MULT_16_TEST4_C_COLUMNS, - MATRIX_MULT_16_TEST4_A_QXY_Y, - MATRIX_MULT_16_TEST4_B_QXY_Y, - MATRIX_MULT_16_TEST4_C_QXY_Y); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_matrix_mult_16_test1), - cmocka_unit_test(test_matrix_mult_16_test2), - cmocka_unit_test(test_matrix_mult_16_test3), - cmocka_unit_test(test_matrix_mult_16_test4), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/matrix/CMakeLists.txt b/test/ztest/unit/math/matrix/CMakeLists.txt index 1dbfea88a08a..bfc764066192 100644 --- a/test/ztest/unit/math/matrix/CMakeLists.txt +++ b/test/ztest/unit/math/matrix/CMakeLists.txt @@ -18,9 +18,6 @@ target_include_directories(app PRIVATE ${SOF_ROOT}/src/include ${SOF_ROOT}/src/kernel/platform/posix/include ${SOF_ROOT}/test/ztest/unit/common - # Reference test vectors are #included in place from the CMocka tree - # rather than copied, so both frameworks share identical data. - ${SOF_ROOT}/test/cmocka/src/math/matrix ${PROJECT_BINARY_DIR}/include/generated ) diff --git a/test/cmocka/src/math/matrix/ref_matrix.m b/test/ztest/unit/math/matrix/ref_matrix.m similarity index 100% rename from test/cmocka/src/math/matrix/ref_matrix.m rename to test/ztest/unit/math/matrix/ref_matrix.m diff --git a/test/cmocka/src/math/matrix/ref_matrix_mult_16_test1.h b/test/ztest/unit/math/matrix/ref_matrix_mult_16_test1.h similarity index 100% rename from test/cmocka/src/math/matrix/ref_matrix_mult_16_test1.h rename to test/ztest/unit/math/matrix/ref_matrix_mult_16_test1.h diff --git a/test/cmocka/src/math/matrix/ref_matrix_mult_16_test2.h b/test/ztest/unit/math/matrix/ref_matrix_mult_16_test2.h similarity index 100% rename from test/cmocka/src/math/matrix/ref_matrix_mult_16_test2.h rename to test/ztest/unit/math/matrix/ref_matrix_mult_16_test2.h diff --git a/test/cmocka/src/math/matrix/ref_matrix_mult_16_test3.h b/test/ztest/unit/math/matrix/ref_matrix_mult_16_test3.h similarity index 100% rename from test/cmocka/src/math/matrix/ref_matrix_mult_16_test3.h rename to test/ztest/unit/math/matrix/ref_matrix_mult_16_test3.h diff --git a/test/cmocka/src/math/matrix/ref_matrix_mult_16_test4.h b/test/ztest/unit/math/matrix/ref_matrix_mult_16_test4.h similarity index 100% rename from test/cmocka/src/math/matrix/ref_matrix_mult_16_test4.h rename to test/ztest/unit/math/matrix/ref_matrix_mult_16_test4.h diff --git a/test/ztest/unit/math/matrix/test_matrix_ztest.c b/test/ztest/unit/math/matrix/test_matrix_ztest.c index cea589d6eb3f..716145b4ab69 100644 --- a/test/ztest/unit/math/matrix/test_matrix_ztest.c +++ b/test/ztest/unit/math/matrix/test_matrix_ztest.c @@ -17,9 +17,8 @@ #include #include -/* Reference test vectors shared with the legacy CMocka test. They are - * #included in place from the CMocka tree (added to the include path in - * CMakeLists.txt) so the exact same fixed-point data is exercised. +/* Reference test vectors were moved here from the legacy CMocka tree + * (test/cmocka/src/math/matrix/) when that CMocka test was removed. */ #include "ref_matrix_mult_16_test1.h" #include "ref_matrix_mult_16_test2.h" From 35c28ec51ebcaa5ae6bb2b4355c94b8a77ea2d6d Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:31:25 +0100 Subject: [PATCH 6/8] cmocka: Remove auditory test The auditory math component (Mel filterbank, Hz<->Mel conversion) is already fully covered by the ztest port at test/ztest/unit/math/auditory/. Remove the now-redundant CMocka test and its CMakeLists.txt stanza, along with the whole auditory/ subdirectory (it was the last remaining test there). Move the reference test vectors and their Octave/MATLAB generator scripts reused by the ztest port (ref_hz_to_mel.h, ref_mel_filterbank_{16,32}_test{1-4}.h, mfcc_*.m, plot_filterbank_test.m, ref_auditory.m) with git mv into test/ztest/unit/math/auditory/ to preserve file history, and drop the now-unneeded CMocka include path from the ztest CMakeLists.txt. CMock stats for auditory.c + mel_filterbank_{16,32}.c (combined): - lines: 96% (189/195) - branches: 67% (51/76) Ztest stats for auditory.c + mel_filterbank_{16,32}.c (combined): - lines: 90% (160/176) - branches: 76% (60/78) Branch coverage is higher on the ztest side; the slightly lower line percentage is due to gcc vs clang instrumentation granularity (different line-count denominators for the same source), not a regression. Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/CMakeLists.txt | 1 - test/cmocka/src/math/auditory/CMakeLists.txt | 12 - test/cmocka/src/math/auditory/auditory.c | 450 ------------------ test/ztest/unit/math/auditory/CMakeLists.txt | 3 - .../math/auditory/mfcc_get_mel_filterbank.m | 0 .../unit}/math/auditory/mfcc_hz_to_mel.m | 0 .../unit}/math/auditory/mfcc_mel_to_hz.m | 0 .../math/auditory/mfcc_power_to_mel_log.m | 0 .../math/auditory/plot_filterbank_test.m | 0 .../unit}/math/auditory/ref_auditory.m | 0 .../unit}/math/auditory/ref_hz_to_mel.h | 0 .../auditory/ref_mel_filterbank_16_test1.h | 0 .../auditory/ref_mel_filterbank_16_test2.h | 0 .../auditory/ref_mel_filterbank_16_test3.h | 0 .../auditory/ref_mel_filterbank_16_test4.h | 0 .../auditory/ref_mel_filterbank_32_test1.h | 0 .../auditory/ref_mel_filterbank_32_test2.h | 0 .../auditory/ref_mel_filterbank_32_test3.h | 0 .../auditory/ref_mel_filterbank_32_test4.h | 0 .../unit/math/auditory/test_auditory_ztest.c | 5 +- 20 files changed, 2 insertions(+), 469 deletions(-) delete mode 100644 test/cmocka/src/math/auditory/CMakeLists.txt delete mode 100644 test/cmocka/src/math/auditory/auditory.c rename test/{cmocka/src => ztest/unit}/math/auditory/mfcc_get_mel_filterbank.m (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/mfcc_hz_to_mel.m (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/mfcc_mel_to_hz.m (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/mfcc_power_to_mel_log.m (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/plot_filterbank_test.m (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_auditory.m (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_hz_to_mel.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_16_test1.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_16_test2.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_16_test3.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_16_test4.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_32_test1.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_32_test2.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_32_test3.h (100%) rename test/{cmocka/src => ztest/unit}/math/auditory/ref_mel_filterbank_32_test4.h (100%) diff --git a/test/cmocka/src/math/CMakeLists.txt b/test/cmocka/src/math/CMakeLists.txt index c5764550541f..0fa86333de69 100644 --- a/test/cmocka/src/math/CMakeLists.txt +++ b/test/cmocka/src/math/CMakeLists.txt @@ -2,5 +2,4 @@ add_subdirectory(fft) add_subdirectory(window) -add_subdirectory(auditory) add_subdirectory(dct) diff --git a/test/cmocka/src/math/auditory/CMakeLists.txt b/test/cmocka/src/math/auditory/CMakeLists.txt deleted file mode 100644 index fe200e6b15eb..000000000000 --- a/test/cmocka/src/math/auditory/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(auditory - auditory.c - ${PROJECT_SOURCE_DIR}/src/math/auditory/auditory.c - ${PROJECT_SOURCE_DIR}/src/math/auditory/mel_filterbank_16.c - ${PROJECT_SOURCE_DIR}/src/math/auditory/mel_filterbank_32.c - ${PROJECT_SOURCE_DIR}/src/math/log_e.c - ${PROJECT_SOURCE_DIR}/src/math/base2log.c - ${PROJECT_SOURCE_DIR}/src/math/decibels.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) diff --git a/test/cmocka/src/math/auditory/auditory.c b/test/cmocka/src/math/auditory/auditory.c deleted file mode 100644 index ff222e52fadd..000000000000 --- a/test/cmocka/src/math/auditory/auditory.c +++ /dev/null @@ -1,450 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2022 Intel Corporation. All rights reserved. -// -// Author: Seppo Ingalsuo - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ref_hz_to_mel.h" -#include "ref_mel_filterbank_16_test1.h" -#include "ref_mel_filterbank_32_test1.h" -#include "ref_mel_filterbank_16_test2.h" -#include "ref_mel_filterbank_32_test2.h" -#include "ref_mel_filterbank_16_test3.h" -#include "ref_mel_filterbank_32_test3.h" -#include "ref_mel_filterbank_16_test4.h" -#include "ref_mel_filterbank_32_test4.h" - -#define HZ_TO_MEL_MAX_ERROR_ABS 1.5 -#define HZ_TO_MEL_MAX_ERROR_RMS 0.5 -#define MEL_TO_HZ_MAX_ERROR_ABS 5.0 -#define MEL_TO_HZ_MAX_ERROR_RMS 1.5 - -#define MEL_FB16_MAX_ERROR_ABS 5.0 -#define MEL_FB16_MAX_ERROR_RMS 3.0 -#define MEL_FB32_MAX_ERROR_ABS 5.0 -#define MEL_FB32_MAX_ERROR_RMS 3.0 - -#undef DEBUGFILES /* Change this to #define to get output data files for debugging */ - -struct processing_module dummy; - -static void filterbank_16_test(const int16_t *fft_real, const int16_t *fft_imag, - const int16_t *ref_mel_log, - int num_fft_bins, int num_mel_bins, int norm_slaney, - enum psy_mel_log_scale mel_log_type, int shift) -{ - struct psy_mel_filterbank fb; - struct icomplex16 *fft_buf; - struct icomplex16 *fft_out; - float delta; - float sum_squares = 0; - float error_rms; - float delta_max = 0; - int32_t *power_spectra; - int16_t *mel_log; - int i; - const int half_fft = num_fft_bins / 2 + 1; - const int fft_size = num_fft_bins * sizeof(struct icomplex16); - int ret; - - fft_buf = malloc(fft_size); - if (!fft_buf) { - fprintf(stderr, "Failed to allocate fft_buf\n"); - exit(EXIT_FAILURE); - } - - fft_out = malloc(fft_size); - if (!fft_out) { - fprintf(stderr, "Failed to allocate fft_out\n"); - goto err_out_alloc; - } - - mel_log = malloc(num_mel_bins * sizeof(int16_t)); - if (!mel_log) { - fprintf(stderr, "Failed to allocate output vector\n"); - goto err_mel_alloc; - } - - fb.samplerate = 16000; - fb.start_freq = 100; - fb.end_freq = 7500; - fb.mel_bins = num_mel_bins; - fb.slaney_normalize = (norm_slaney > 0); - fb.mel_log_scale = mel_log_type; - fb.fft_bins = num_fft_bins; - fb.half_fft_bins = half_fft; - fb.scratch_data1 = (int16_t *)fft_buf; - fb.scratch_data2 = (int16_t *)fft_out; - fb.scratch_length1 = fft_size / sizeof(int16_t); - fb.scratch_length2 = fft_size / sizeof(int16_t); - ret = mod_psy_get_mel_filterbank(&dummy, &fb); - if (ret < 0) { - fprintf(stderr, "Failed Mel filterbank\n"); - goto err_get_filterbank; - } - - /* Copy input from test vectors */ - for (i = 0; i < half_fft; i++) { - fft_out[i].real = fft_real[i]; - fft_out[i].imag = fft_imag[i]; - } - - /* Run filterbank */ - power_spectra = (int32_t *)&fft_buf[0]; - psy_apply_mel_filterbank_16(&fb, fft_out, power_spectra, mel_log, shift); - - /* Check */ - for (i = 0; i < num_mel_bins; i++) { - delta = (float)ref_mel_log[i] - (float)mel_log[i]; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - } - - error_rms = sqrt(sum_squares / (float)num_mel_bins); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, MEL_FB16_MAX_ERROR_ABS, error_rms, MEL_FB16_MAX_ERROR_RMS); - -#ifdef DEBUGFILES - FILE *fh = fopen("mel_filterbank_16.txt", "w"); - - for (i = 0; i < num_mel_bins; i++) - fprintf(fh, "%d %d\n", ref_mel_log[i], mel_log[i]); - - fclose(fh); -#endif - - assert_true(error_rms < MEL_FB16_MAX_ERROR_RMS); - assert_true(delta_max < MEL_FB16_MAX_ERROR_ABS); - free(mel_log); - free(fft_buf); - free(fft_out); - mod_psy_free_mel_filterbank(&dummy, &fb); - return; - -err_get_filterbank: - free(mel_log); - -err_mel_alloc: - free(fft_buf); - -err_out_alloc: - free(fft_out); - exit(EXIT_FAILURE); -} - -static void filterbank_32_test(const int32_t *fft_real, const int32_t *fft_imag, - const int16_t *ref_mel_log, - int num_fft_bins, int num_mel_bins, int norm_slaney, - enum psy_mel_log_scale mel_log_type, int shift) -{ - struct psy_mel_filterbank fb; - struct icomplex32 *fft_buf; - struct icomplex32 *fft_out; - float delta; - float sum_squares = 0; - float error_rms; - float delta_max = 0; - int32_t *power_spectra; - int32_t *mel_log; - int16_t mel_log_16; - int i; - const int half_fft = num_fft_bins / 2 + 1; - const int fft_size = num_fft_bins * sizeof(struct icomplex32); - int ret; - - fft_buf = malloc(fft_size); - if (!fft_buf) { - fprintf(stderr, "Failed to allocate fft_buf\n"); - exit(EXIT_FAILURE); - } - - fft_out = malloc(fft_size); - if (!fft_out) { - fprintf(stderr, "Failed to allocate fft_out\n"); - goto err_out_alloc; - } - - mel_log = malloc(num_mel_bins * sizeof(int32_t)); - if (!mel_log) { - fprintf(stderr, "Failed to allocate output vector\n"); - goto err_mel_alloc; - } - - fb.samplerate = 16000; - fb.start_freq = 100; - fb.end_freq = 7500; - fb.mel_bins = num_mel_bins; - fb.slaney_normalize = (norm_slaney > 0); - fb.mel_log_scale = mel_log_type; - fb.fft_bins = num_fft_bins; - fb.half_fft_bins = half_fft; - fb.scratch_data1 = (int16_t *)fft_buf; - fb.scratch_data2 = (int16_t *)fft_out; - fb.scratch_length1 = fft_size / sizeof(int16_t); - fb.scratch_length2 = fft_size / sizeof(int16_t); - ret = mod_psy_get_mel_filterbank(&dummy, &fb); - if (ret < 0) { - fprintf(stderr, "Failed Mel filterbank\n"); - goto err_get_filterbank; - } - - /* Copy input from test vectors */ - for (i = 0; i < half_fft; i++) { - fft_out[i].real = fft_real[i]; - fft_out[i].imag = fft_imag[i]; - } - - /* Run filterbank */ - power_spectra = (int32_t *)&fft_buf[0]; - psy_apply_mel_filterbank_32(&fb, fft_out, power_spectra, mel_log, shift); - - /* Check: convert Q9.23 output to Q9.7 for comparison with reference */ - for (i = 0; i < num_mel_bins; i++) { - mel_log_16 = (int16_t)(mel_log[i] >> 16); - delta = (float)ref_mel_log[i] - (float)mel_log_16; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - } - - error_rms = sqrt(sum_squares / (float)num_mel_bins); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, MEL_FB32_MAX_ERROR_ABS, error_rms, MEL_FB32_MAX_ERROR_RMS); - -#ifdef DEBUGFILES - FILE *fh = fopen("mel_filterbank_32.txt", "w"); - - for (i = 0; i < num_mel_bins; i++) - fprintf(fh, "%d %d\n", ref_mel_log[i], (int16_t)(mel_log[i] >> 16)); - - fclose(fh); -#endif - - assert_true(error_rms < MEL_FB32_MAX_ERROR_RMS); - assert_true(delta_max < MEL_FB32_MAX_ERROR_ABS); - free(mel_log); - free(fft_buf); - free(fft_out); - mod_psy_free_mel_filterbank(&dummy, &fb); - return; - -err_get_filterbank: - free(mel_log); - -err_mel_alloc: - free(fft_buf); - -err_out_alloc: - free(fft_out); - exit(EXIT_FAILURE); -} - -static void test_hz_to_mel(void **state) -{ - float error_rms; - float delta_max = 0.0; - float delta; - float sum_squares = 0.0; - int16_t test_mel; - int i; - - (void)state; - - for (i = 0; i < HZ_TO_MEL_NPOINTS; i++) { - test_mel = psy_hz_to_mel(ref_hz[i]); - delta = (float)ref_mel[i] - (float)test_mel; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - } - - error_rms = sqrt(sum_squares / (float)HZ_TO_MEL_NPOINTS); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, HZ_TO_MEL_MAX_ERROR_ABS, error_rms, HZ_TO_MEL_MAX_ERROR_RMS); - - assert_true(error_rms < HZ_TO_MEL_MAX_ERROR_RMS); - assert_true(delta_max < HZ_TO_MEL_MAX_ERROR_ABS); -} - -static void test_mel_to_hz(void **state) -{ - float error_rms; - float delta_max = 0.0; - float delta; - float sum_squares = 0.0; - int16_t test_hz; - int i; - - (void)state; - - for (i = 0; i < HZ_TO_MEL_NPOINTS; i++) { - test_hz = psy_mel_to_hz(ref_mel[i]); - delta = (float)ref_revhz[i] - (float)test_hz; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - } - - error_rms = sqrt(sum_squares / (float)HZ_TO_MEL_NPOINTS); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, MEL_TO_HZ_MAX_ERROR_ABS, error_rms, MEL_TO_HZ_MAX_ERROR_RMS); - - assert_true(error_rms < MEL_TO_HZ_MAX_ERROR_RMS); - assert_true(delta_max < MEL_TO_HZ_MAX_ERROR_ABS); -} - -static void test_mel_filterbank_16_test1(void **state) -{ - (void)state; - - filterbank_16_test(mel_filterbank_16_test1_real, - mel_filterbank_16_test1_imag, - mel_filterbank_16_test1_mel_log, - MEL_FILTERBANK_16_TEST1_FFT_SIZE, - MEL_FILTERBANK_16_TEST1_NUM_MEL_BINS, - MEL_FILTERBANK_16_TEST1_NORM_SLANEY, - MEL_FILTERBANK_16_TEST1_MEL_LOG, - MEL_FILTERBANK_16_TEST1_SHIFT); -} - -static void test_mel_filterbank_32_test1(void **state) -{ - (void)state; - - filterbank_32_test(mel_filterbank_32_test1_real, - mel_filterbank_32_test1_imag, - mel_filterbank_32_test1_mel_log, - MEL_FILTERBANK_32_TEST1_FFT_SIZE, - MEL_FILTERBANK_32_TEST1_NUM_MEL_BINS, - MEL_FILTERBANK_32_TEST1_NORM_SLANEY, - MEL_FILTERBANK_32_TEST1_MEL_LOG, - MEL_FILTERBANK_32_TEST1_SHIFT); -} - -static void test_mel_filterbank_16_test2(void **state) -{ - (void)state; - - filterbank_16_test(mel_filterbank_16_test2_real, - mel_filterbank_16_test2_imag, - mel_filterbank_16_test2_mel_log, - MEL_FILTERBANK_16_TEST2_FFT_SIZE, - MEL_FILTERBANK_16_TEST2_NUM_MEL_BINS, - MEL_FILTERBANK_16_TEST2_NORM_SLANEY, - MEL_FILTERBANK_16_TEST2_MEL_LOG, - MEL_FILTERBANK_16_TEST2_SHIFT); -} - -static void test_mel_filterbank_32_test2(void **state) -{ - (void)state; - - filterbank_32_test(mel_filterbank_32_test2_real, - mel_filterbank_32_test2_imag, - mel_filterbank_32_test2_mel_log, - MEL_FILTERBANK_32_TEST2_FFT_SIZE, - MEL_FILTERBANK_32_TEST2_NUM_MEL_BINS, - MEL_FILTERBANK_32_TEST2_NORM_SLANEY, - MEL_FILTERBANK_32_TEST2_MEL_LOG, - MEL_FILTERBANK_32_TEST2_SHIFT); -} - -static void test_mel_filterbank_16_test3(void **state) -{ - (void)state; - - filterbank_16_test(mel_filterbank_16_test3_real, - mel_filterbank_16_test3_imag, - mel_filterbank_16_test3_mel_log, - MEL_FILTERBANK_16_TEST3_FFT_SIZE, - MEL_FILTERBANK_16_TEST3_NUM_MEL_BINS, - MEL_FILTERBANK_16_TEST3_NORM_SLANEY, - MEL_FILTERBANK_16_TEST3_MEL_LOG, - MEL_FILTERBANK_16_TEST3_SHIFT); -} - -static void test_mel_filterbank_32_test3(void **state) -{ - (void)state; - - filterbank_32_test(mel_filterbank_32_test3_real, - mel_filterbank_32_test3_imag, - mel_filterbank_32_test3_mel_log, - MEL_FILTERBANK_32_TEST3_FFT_SIZE, - MEL_FILTERBANK_32_TEST3_NUM_MEL_BINS, - MEL_FILTERBANK_32_TEST3_NORM_SLANEY, - MEL_FILTERBANK_32_TEST3_MEL_LOG, - MEL_FILTERBANK_32_TEST3_SHIFT); -} - -static void test_mel_filterbank_16_test4(void **state) -{ - (void)state; - - filterbank_16_test(mel_filterbank_16_test4_real, - mel_filterbank_16_test4_imag, - mel_filterbank_16_test4_mel_log, - MEL_FILTERBANK_16_TEST4_FFT_SIZE, - MEL_FILTERBANK_16_TEST4_NUM_MEL_BINS, - MEL_FILTERBANK_16_TEST4_NORM_SLANEY, - MEL_FILTERBANK_16_TEST4_MEL_LOG, - MEL_FILTERBANK_16_TEST4_SHIFT); -} - -static void test_mel_filterbank_32_test4(void **state) -{ - (void)state; - - filterbank_32_test(mel_filterbank_32_test4_real, - mel_filterbank_32_test4_imag, - mel_filterbank_32_test4_mel_log, - MEL_FILTERBANK_32_TEST4_FFT_SIZE, - MEL_FILTERBANK_32_TEST4_NUM_MEL_BINS, - MEL_FILTERBANK_32_TEST4_NORM_SLANEY, - MEL_FILTERBANK_32_TEST4_MEL_LOG, - MEL_FILTERBANK_32_TEST4_SHIFT); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_mel_filterbank_16_test1), - cmocka_unit_test(test_mel_filterbank_32_test1), - cmocka_unit_test(test_mel_filterbank_16_test2), - cmocka_unit_test(test_mel_filterbank_32_test2), - cmocka_unit_test(test_mel_filterbank_16_test3), - cmocka_unit_test(test_mel_filterbank_32_test3), - cmocka_unit_test(test_mel_filterbank_16_test4), - cmocka_unit_test(test_mel_filterbank_32_test4), - cmocka_unit_test(test_hz_to_mel), - cmocka_unit_test(test_mel_to_hz), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/auditory/CMakeLists.txt b/test/ztest/unit/math/auditory/CMakeLists.txt index d09c724d80af..d2cc165eed3f 100644 --- a/test/ztest/unit/math/auditory/CMakeLists.txt +++ b/test/ztest/unit/math/auditory/CMakeLists.txt @@ -18,9 +18,6 @@ target_include_directories(app PRIVATE ${SOF_ROOT}/src/include ${SOF_ROOT}/src/kernel/platform/posix/include ${SOF_ROOT}/test/ztest/unit/common - # Reference test vectors are #included in place from the CMocka tree - # rather than copied, so both frameworks share identical data. - ${SOF_ROOT}/test/cmocka/src/math/auditory ${PROJECT_BINARY_DIR}/include/generated ) diff --git a/test/cmocka/src/math/auditory/mfcc_get_mel_filterbank.m b/test/ztest/unit/math/auditory/mfcc_get_mel_filterbank.m similarity index 100% rename from test/cmocka/src/math/auditory/mfcc_get_mel_filterbank.m rename to test/ztest/unit/math/auditory/mfcc_get_mel_filterbank.m diff --git a/test/cmocka/src/math/auditory/mfcc_hz_to_mel.m b/test/ztest/unit/math/auditory/mfcc_hz_to_mel.m similarity index 100% rename from test/cmocka/src/math/auditory/mfcc_hz_to_mel.m rename to test/ztest/unit/math/auditory/mfcc_hz_to_mel.m diff --git a/test/cmocka/src/math/auditory/mfcc_mel_to_hz.m b/test/ztest/unit/math/auditory/mfcc_mel_to_hz.m similarity index 100% rename from test/cmocka/src/math/auditory/mfcc_mel_to_hz.m rename to test/ztest/unit/math/auditory/mfcc_mel_to_hz.m diff --git a/test/cmocka/src/math/auditory/mfcc_power_to_mel_log.m b/test/ztest/unit/math/auditory/mfcc_power_to_mel_log.m similarity index 100% rename from test/cmocka/src/math/auditory/mfcc_power_to_mel_log.m rename to test/ztest/unit/math/auditory/mfcc_power_to_mel_log.m diff --git a/test/cmocka/src/math/auditory/plot_filterbank_test.m b/test/ztest/unit/math/auditory/plot_filterbank_test.m similarity index 100% rename from test/cmocka/src/math/auditory/plot_filterbank_test.m rename to test/ztest/unit/math/auditory/plot_filterbank_test.m diff --git a/test/cmocka/src/math/auditory/ref_auditory.m b/test/ztest/unit/math/auditory/ref_auditory.m similarity index 100% rename from test/cmocka/src/math/auditory/ref_auditory.m rename to test/ztest/unit/math/auditory/ref_auditory.m diff --git a/test/cmocka/src/math/auditory/ref_hz_to_mel.h b/test/ztest/unit/math/auditory/ref_hz_to_mel.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_hz_to_mel.h rename to test/ztest/unit/math/auditory/ref_hz_to_mel.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_16_test1.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_16_test1.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_16_test1.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_16_test1.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_16_test2.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_16_test2.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_16_test2.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_16_test2.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_16_test3.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_16_test3.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_16_test3.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_16_test3.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_16_test4.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_16_test4.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_16_test4.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_16_test4.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_32_test1.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_32_test1.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_32_test1.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_32_test1.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_32_test2.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_32_test2.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_32_test2.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_32_test2.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_32_test3.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_32_test3.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_32_test3.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_32_test3.h diff --git a/test/cmocka/src/math/auditory/ref_mel_filterbank_32_test4.h b/test/ztest/unit/math/auditory/ref_mel_filterbank_32_test4.h similarity index 100% rename from test/cmocka/src/math/auditory/ref_mel_filterbank_32_test4.h rename to test/ztest/unit/math/auditory/ref_mel_filterbank_32_test4.h diff --git a/test/ztest/unit/math/auditory/test_auditory_ztest.c b/test/ztest/unit/math/auditory/test_auditory_ztest.c index 430d7b656f79..16c9d6789f10 100644 --- a/test/ztest/unit/math/auditory/test_auditory_ztest.c +++ b/test/ztest/unit/math/auditory/test_auditory_ztest.c @@ -21,9 +21,8 @@ #include #include -/* Reference test vectors shared with the legacy CMocka test. They are - * #included in place from the CMocka tree (added to the include path in - * CMakeLists.txt) so the exact same fixed-point data is exercised. +/* Reference test vectors were moved here from the legacy CMocka tree + * (test/cmocka/src/math/auditory/) when that CMocka test was removed. */ #include "ref_hz_to_mel.h" #include "ref_mel_filterbank_16_test1.h" From 827552d6176458208fe368bdfd0fcb105784090c Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:34:21 +0100 Subject: [PATCH 7/8] cmocka: Remove dct test The DCT (Discrete Cosine Transform) matrix generation code is already fully covered by the ztest port at test/ztest/unit/math/dct/. Remove the now-redundant CMocka test and its CMakeLists.txt stanza, along with the whole dct/ subdirectory (it was the last remaining test there). Move the reference DCT matrices and their Octave/MATLAB generator scripts reused by the ztest port (ref_dct_matrix_16_test{1,2}.h, mfcc_get_dct_matrix.m, ref_dct.m) with git mv into test/ztest/unit/math/dct/ to preserve file history, and drop the now-unneeded CMocka include path from the ztest CMakeLists.txt. CMock stats for src/math/dct.c: - lines: 100% (29/29) - branches: 65% (13/20) Ztest stats for src/math/dct.c: - lines: 86% (25/29) - branches: 65% (13/20) Branch coverage is identical between the two builds, including the same missing branches, confirming equivalent test behaviour. The line percentage difference is a gcc vs clang line-hit accounting artifact for the same source file, not a regression. Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/CMakeLists.txt | 1 - test/cmocka/src/math/dct/CMakeLists.txt | 9 -- test/cmocka/src/math/dct/dct.c | 110 ------------------ test/ztest/unit/math/dct/CMakeLists.txt | 3 - .../unit}/math/dct/mfcc_get_dct_matrix.m | 0 .../src => ztest/unit}/math/dct/ref_dct.m | 0 .../unit}/math/dct/ref_dct_matrix_16_test1.h | 0 .../unit}/math/dct/ref_dct_matrix_16_test2.h | 0 test/ztest/unit/math/dct/test_dct_ztest.c | 5 +- 9 files changed, 2 insertions(+), 126 deletions(-) delete mode 100644 test/cmocka/src/math/dct/CMakeLists.txt delete mode 100644 test/cmocka/src/math/dct/dct.c rename test/{cmocka/src => ztest/unit}/math/dct/mfcc_get_dct_matrix.m (100%) rename test/{cmocka/src => ztest/unit}/math/dct/ref_dct.m (100%) rename test/{cmocka/src => ztest/unit}/math/dct/ref_dct_matrix_16_test1.h (100%) rename test/{cmocka/src => ztest/unit}/math/dct/ref_dct_matrix_16_test2.h (100%) diff --git a/test/cmocka/src/math/CMakeLists.txt b/test/cmocka/src/math/CMakeLists.txt index 0fa86333de69..fa108874e19d 100644 --- a/test/cmocka/src/math/CMakeLists.txt +++ b/test/cmocka/src/math/CMakeLists.txt @@ -2,4 +2,3 @@ add_subdirectory(fft) add_subdirectory(window) -add_subdirectory(dct) diff --git a/test/cmocka/src/math/dct/CMakeLists.txt b/test/cmocka/src/math/dct/CMakeLists.txt deleted file mode 100644 index a50dd6ee524f..000000000000 --- a/test/cmocka/src/math/dct/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(dct - dct.c - ${PROJECT_SOURCE_DIR}/src/math/dct.c - ${PROJECT_SOURCE_DIR}/src/math/trig.c - ${PROJECT_SOURCE_DIR}/src/math/sqrt_int16.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c -) diff --git a/test/cmocka/src/math/dct/dct.c b/test/cmocka/src/math/dct/dct.c deleted file mode 100644 index ea35d170e66e..000000000000 --- a/test/cmocka/src/math/dct/dct.c +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2022 Intel Corporation. All rights reserved. -// -// Author: Seppo Ingalsuo - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ref_dct_matrix_16_test1.h" -#include "ref_dct_matrix_16_test2.h" - -#define MATRIX_MULT_16_MAX_ERROR_ABS 2.5 -#define MATRIX_MULT_16_MAX_ERROR_RMS 1.1 - -struct processing_module dummy; - -static void dct_matrix_16_test(const int16_t *ref, int num_in, int num_out, - enum dct_type type, bool ortho) -{ - struct dct_plan_16 dct; - double delta; - double sum_squares = 0; - double error_rms; - double delta_max = 0; - int16_t x; - int rows; - int columns; - int ret; - int i, j, k; - - /* Calculate DCT matrix */ - dct.num_in = num_in; - dct.num_out = num_out; - dct.type = type; - dct.ortho = ortho; - ret = mod_dct_initialize_16(&dummy, &dct); - if (ret) { - fprintf(stderr, "Failed to initialize DCT.\n"); - exit(EXIT_FAILURE); - } - - /* Check */ - rows = dct.matrix->rows; - columns = dct.matrix->columns; - k = 0; - for (i = 0; i < rows; i++) { - for (j = 0; j < columns; j++) { - x = mat_get_scalar_16b(dct.matrix, i, j); - delta = (double)x - (double)ref[k++]; - sum_squares += delta * delta; - if (delta > delta_max) - delta_max = delta; - else if (-delta > delta_max) - delta_max = -delta; - } - } - - error_rms = sqrt(sum_squares / (double)(rows * columns)); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, MATRIX_MULT_16_MAX_ERROR_ABS, error_rms, MATRIX_MULT_16_MAX_ERROR_RMS); - - assert_true(error_rms < MATRIX_MULT_16_MAX_ERROR_RMS); - assert_true(delta_max < MATRIX_MULT_16_MAX_ERROR_ABS); - - mod_dct_free_16(&dummy, &dct); -} - -static void test_dct_matrix_16_test1(void **state) -{ - (void)state; - - dct_matrix_16_test(dct_matrix_16_test1_matrix, - DCT_MATRIX_16_TEST1_NUM_IN, - DCT_MATRIX_16_TEST1_NUM_OUT, - DCT_MATRIX_16_TEST1_TYPE, - DCT_MATRIX_16_TEST1_ORTHO); -} - -static void test_dct_matrix_16_test2(void **state) -{ - (void)state; - - dct_matrix_16_test(dct_matrix_16_test2_matrix, - DCT_MATRIX_16_TEST2_NUM_IN, - DCT_MATRIX_16_TEST2_NUM_OUT, - DCT_MATRIX_16_TEST2_TYPE, - DCT_MATRIX_16_TEST2_ORTHO); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_dct_matrix_16_test1), - cmocka_unit_test(test_dct_matrix_16_test2), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/dct/CMakeLists.txt b/test/ztest/unit/math/dct/CMakeLists.txt index 3bddbf06e6ea..6abe6c1d6e2c 100644 --- a/test/ztest/unit/math/dct/CMakeLists.txt +++ b/test/ztest/unit/math/dct/CMakeLists.txt @@ -18,9 +18,6 @@ target_include_directories(app PRIVATE ${SOF_ROOT}/src/include ${SOF_ROOT}/src/kernel/platform/posix/include ${SOF_ROOT}/test/ztest/unit/common - # Reference test vectors are #included in place from the CMocka tree - # rather than copied, so both frameworks share identical data. - ${SOF_ROOT}/test/cmocka/src/math/dct ${PROJECT_BINARY_DIR}/include/generated ) diff --git a/test/cmocka/src/math/dct/mfcc_get_dct_matrix.m b/test/ztest/unit/math/dct/mfcc_get_dct_matrix.m similarity index 100% rename from test/cmocka/src/math/dct/mfcc_get_dct_matrix.m rename to test/ztest/unit/math/dct/mfcc_get_dct_matrix.m diff --git a/test/cmocka/src/math/dct/ref_dct.m b/test/ztest/unit/math/dct/ref_dct.m similarity index 100% rename from test/cmocka/src/math/dct/ref_dct.m rename to test/ztest/unit/math/dct/ref_dct.m diff --git a/test/cmocka/src/math/dct/ref_dct_matrix_16_test1.h b/test/ztest/unit/math/dct/ref_dct_matrix_16_test1.h similarity index 100% rename from test/cmocka/src/math/dct/ref_dct_matrix_16_test1.h rename to test/ztest/unit/math/dct/ref_dct_matrix_16_test1.h diff --git a/test/cmocka/src/math/dct/ref_dct_matrix_16_test2.h b/test/ztest/unit/math/dct/ref_dct_matrix_16_test2.h similarity index 100% rename from test/cmocka/src/math/dct/ref_dct_matrix_16_test2.h rename to test/ztest/unit/math/dct/ref_dct_matrix_16_test2.h diff --git a/test/ztest/unit/math/dct/test_dct_ztest.c b/test/ztest/unit/math/dct/test_dct_ztest.c index c2ae828855b4..38fd1c171828 100644 --- a/test/ztest/unit/math/dct/test_dct_ztest.c +++ b/test/ztest/unit/math/dct/test_dct_ztest.c @@ -19,9 +19,8 @@ #include #include -/* Reference DCT matrices shared with the legacy CMocka test. They are - * #included in place from the CMocka tree (added to the include path in - * CMakeLists.txt) so the exact same fixed-point data is exercised. +/* Reference DCT matrices were moved here from the legacy CMocka tree + * (test/cmocka/src/math/dct/) when that CMocka test was removed. */ #include "ref_dct_matrix_16_test1.h" #include "ref_dct_matrix_16_test2.h" From 2411143280366c59e45bae614ccf4397f737e8f6 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Wed, 11 Nov 2026 01:39:04 +0100 Subject: [PATCH 8/8] cmocka: Remove window test The window generation code (rectangular, Blackman, Hamming, Povey) is already fully covered by the ztest port at test/ztest/unit/math/window/. Remove the now-redundant CMocka test and its CMakeLists.txt stanza, along with the whole window/ subdirectory (it was the last remaining test there). This also removes the last non-dft3 subdirectory from test/cmocka/src/math/, leaving only fft/ (dft3, deferred to a later phase). Move the reference windows and their Octave/MATLAB generator scripts reused by the ztest port (ref_window_{rectangular,blackman,hamming, povey}.h, mfcc_blackman.m, mfcc_povey.m, ref_window.m) with git mv into test/ztest/unit/math/window/ to preserve file history, and drop the now-unneeded CMocka include path from the ztest CMakeLists.txt. CMock stats for src/math/window.c: - lines: 48% (54/111) - branches: 34% (11/32) Ztest stats for src/math/window.c: - lines: 46% (38/81) - branches: 44% (8/18) Every branch missing on the ztest side is also missing on the CMock side (same untested logic paths), confirming no regression. The differing line/branch denominators for the identical source file are a gcc vs clang instrumentation/optimization-level artifact, not a behavioural difference. Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Tomasz Leman --- test/cmocka/src/math/CMakeLists.txt | 1 - test/cmocka/src/math/window/CMakeLists.txt | 10 -- test/cmocka/src/math/window/window.c | 137 ------------------ test/ztest/unit/math/window/CMakeLists.txt | 3 - .../unit}/math/window/mfcc_blackman.m | 0 .../unit}/math/window/mfcc_povey.m | 0 .../unit}/math/window/ref_window.m | 0 .../unit}/math/window/ref_window_blackman.h | 0 .../unit}/math/window/ref_window_hamming.h | 0 .../unit}/math/window/ref_window_povey.h | 0 .../math/window/ref_window_rectangular.h | 0 .../unit/math/window/test_window_ztest.c | 5 +- 12 files changed, 2 insertions(+), 154 deletions(-) delete mode 100644 test/cmocka/src/math/window/CMakeLists.txt delete mode 100644 test/cmocka/src/math/window/window.c rename test/{cmocka/src => ztest/unit}/math/window/mfcc_blackman.m (100%) rename test/{cmocka/src => ztest/unit}/math/window/mfcc_povey.m (100%) rename test/{cmocka/src => ztest/unit}/math/window/ref_window.m (100%) rename test/{cmocka/src => ztest/unit}/math/window/ref_window_blackman.h (100%) rename test/{cmocka/src => ztest/unit}/math/window/ref_window_hamming.h (100%) rename test/{cmocka/src => ztest/unit}/math/window/ref_window_povey.h (100%) rename test/{cmocka/src => ztest/unit}/math/window/ref_window_rectangular.h (100%) diff --git a/test/cmocka/src/math/CMakeLists.txt b/test/cmocka/src/math/CMakeLists.txt index fa108874e19d..63fee59d926c 100644 --- a/test/cmocka/src/math/CMakeLists.txt +++ b/test/cmocka/src/math/CMakeLists.txt @@ -1,4 +1,3 @@ # SPDX-License-Identifier: BSD-3-Clause add_subdirectory(fft) -add_subdirectory(window) diff --git a/test/cmocka/src/math/window/CMakeLists.txt b/test/cmocka/src/math/window/CMakeLists.txt deleted file mode 100644 index 0d4365694523..000000000000 --- a/test/cmocka/src/math/window/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(window - window.c - ${PROJECT_SOURCE_DIR}/src/math/window.c - ${PROJECT_SOURCE_DIR}/src/math/trig.c - ${PROJECT_SOURCE_DIR}/src/math/log_e.c - ${PROJECT_SOURCE_DIR}/src/math/base2log.c - ${PROJECT_SOURCE_DIR}/src/math/decibels.c -) diff --git a/test/cmocka/src/math/window/window.c b/test/cmocka/src/math/window/window.c deleted file mode 100644 index 82e0f66a6bec..000000000000 --- a/test/cmocka/src/math/window/window.c +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2022 Intel Corporation. All rights reserved. -// -// Author: Seppo Ingalsuo - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ref_window_rectangular.h" -#include "ref_window_blackman.h" -#include "ref_window_hamming.h" -#include "ref_window_povey.h" - -#define MAX_ERR_RMS 1.0 -#define MAX_STR_SIZE 256 -#define MAX_WIN_LENGTH 4096 -#undef DEBUG_FILES /* Change to #define to get file output */ - -static float window_delta_rms(const int16_t *ref_win, int16_t *win, int win_length) -{ - float err_squared = 0.0; - int i; - - for (i = 0; i < win_length; i++) { - err_squared += ((float)ref_win[i] - (float)win[i]) * - ((float)ref_win[i] - (float)win[i]); - } - - return sqrt(err_squared / (float)win_length); -} - -static float test_window(char *window_name, const int16_t *ref_win, int window_length) -{ - float err_rms; - int16_t *win; - - win = malloc(window_length * sizeof(int16_t)); - if (!win) { - fprintf(stderr, "Failed to allocate reference window.\n"); - exit(EXIT_FAILURE); - } - - /* calculate window and get RMS error vs. reference */ - if (!strcmp(window_name, "rectangular")) { - win_rectangular_16b(win, window_length); - } else if (!strcmp(window_name, "blackman")) { - win_blackman_16b(win, window_length, WIN_BLACKMAN_A0_Q15); - } else if (!strcmp(window_name, "hamming")) { - win_hamming_16b(win, window_length); - } else if (!strcmp(window_name, "povey")) { - win_povey_16b(win, window_length); - } else { - fprintf(stderr, "Illegal window %s.\n", window_name); - free(win); - exit(EXIT_FAILURE); - } - -#ifdef DEBUG_FILES - FILE *fh; - int i; - - fh = fopen("window.txt", "w"); - for (i = 0; i < window_length; i++) - fprintf(fh, "%d %d\n", win[i], ref_win[i]); - - fclose(fh); -#endif - - err_rms = window_delta_rms(ref_win, win, window_length); - printf("Window %s RMS error = %5.2f LSB (max %5.2f)\n", window_name, err_rms, MAX_ERR_RMS); - free(win); - return err_rms; -} - -static void test_math_window_rectangular(void **state) -{ - float err_rms; - - (void)state; - - err_rms = test_window("rectangular", ref_rectangular, LENGTH_RECTANGULAR); - assert_true(err_rms < MAX_ERR_RMS); -} - -static void test_math_window_blackman(void **state) -{ - float err_rms; - - (void)state; - - err_rms = test_window("blackman", ref_blackman, LENGTH_BLACKMAN); - assert_true(err_rms < MAX_ERR_RMS); -} - -static void test_math_window_hamming(void **state) -{ - float err_rms; - - (void)state; - - err_rms = test_window("hamming", ref_hamming, LENGTH_HAMMING); - assert_true(err_rms < MAX_ERR_RMS); -} - -static void test_math_window_povey(void **state) -{ - float err_rms; - - (void)state; - - err_rms = test_window("povey", ref_povey, LENGTH_POVEY); - assert_true(err_rms < MAX_ERR_RMS); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_math_window_rectangular), - cmocka_unit_test(test_math_window_blackman), - cmocka_unit_test(test_math_window_hamming), - cmocka_unit_test(test_math_window_povey), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/math/window/CMakeLists.txt b/test/ztest/unit/math/window/CMakeLists.txt index 1d6aeb557f6c..4d72339dbdc7 100644 --- a/test/ztest/unit/math/window/CMakeLists.txt +++ b/test/ztest/unit/math/window/CMakeLists.txt @@ -12,9 +12,6 @@ set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..") target_include_directories(app PRIVATE ${SOF_ROOT}/zephyr/include ${SOF_ROOT}/src/include - # Reference windows are #included in place from the CMocka tree rather - # than copied, so both frameworks share identical data. - ${SOF_ROOT}/test/cmocka/src/math/window ) target_compile_definitions(app PRIVATE diff --git a/test/cmocka/src/math/window/mfcc_blackman.m b/test/ztest/unit/math/window/mfcc_blackman.m similarity index 100% rename from test/cmocka/src/math/window/mfcc_blackman.m rename to test/ztest/unit/math/window/mfcc_blackman.m diff --git a/test/cmocka/src/math/window/mfcc_povey.m b/test/ztest/unit/math/window/mfcc_povey.m similarity index 100% rename from test/cmocka/src/math/window/mfcc_povey.m rename to test/ztest/unit/math/window/mfcc_povey.m diff --git a/test/cmocka/src/math/window/ref_window.m b/test/ztest/unit/math/window/ref_window.m similarity index 100% rename from test/cmocka/src/math/window/ref_window.m rename to test/ztest/unit/math/window/ref_window.m diff --git a/test/cmocka/src/math/window/ref_window_blackman.h b/test/ztest/unit/math/window/ref_window_blackman.h similarity index 100% rename from test/cmocka/src/math/window/ref_window_blackman.h rename to test/ztest/unit/math/window/ref_window_blackman.h diff --git a/test/cmocka/src/math/window/ref_window_hamming.h b/test/ztest/unit/math/window/ref_window_hamming.h similarity index 100% rename from test/cmocka/src/math/window/ref_window_hamming.h rename to test/ztest/unit/math/window/ref_window_hamming.h diff --git a/test/cmocka/src/math/window/ref_window_povey.h b/test/ztest/unit/math/window/ref_window_povey.h similarity index 100% rename from test/cmocka/src/math/window/ref_window_povey.h rename to test/ztest/unit/math/window/ref_window_povey.h diff --git a/test/cmocka/src/math/window/ref_window_rectangular.h b/test/ztest/unit/math/window/ref_window_rectangular.h similarity index 100% rename from test/cmocka/src/math/window/ref_window_rectangular.h rename to test/ztest/unit/math/window/ref_window_rectangular.h diff --git a/test/ztest/unit/math/window/test_window_ztest.c b/test/ztest/unit/math/window/test_window_ztest.c index 47efa8e8df77..da57e6745b21 100644 --- a/test/ztest/unit/math/window/test_window_ztest.c +++ b/test/ztest/unit/math/window/test_window_ztest.c @@ -16,9 +16,8 @@ #include #include -/* Reference windows shared with the legacy CMocka test. They are #included - * in place from the CMocka tree (added to the include path in CMakeLists.txt) - * so the exact same fixed-point data is exercised. +/* Reference windows were moved here from the legacy CMocka tree + * (test/cmocka/src/math/window/) when that CMocka test was removed. */ #include "ref_window_rectangular.h" #include "ref_window_blackman.h"