diff --git a/test/cmocka/src/CMakeLists.txt b/test/cmocka/src/CMakeLists.txt index 2c244aea9d0d..1cdd0d2137a9 100644 --- a/test/cmocka/src/CMakeLists.txt +++ b/test/cmocka/src/CMakeLists.txt @@ -1,5 +1,3 @@ # SPDX-License-Identifier: BSD-3-Clause add_subdirectory(audio) -add_subdirectory(lib) -add_subdirectory(math) diff --git a/test/cmocka/src/audio/CMakeLists.txt b/test/cmocka/src/audio/CMakeLists.txt index a5b300b6f232..ea0b424069b1 100644 --- a/test/cmocka/src/audio/CMakeLists.txt +++ b/test/cmocka/src/audio/CMakeLists.txt @@ -1,8 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause -add_subdirectory(buffer) add_subdirectory(component) -add_subdirectory(pcm_converter) if(CONFIG_COMP_MIXER) add_subdirectory(mixer) endif() @@ -10,9 +8,6 @@ add_subdirectory(pipeline) if(CONFIG_COMP_VOLUME) add_subdirectory(volume) endif() -if(CONFIG_COMP_MUX) - add_subdirectory(mux) -endif() if(CONFIG_COMP_SEL) add_subdirectory(selector) endif() @@ -22,9 +17,6 @@ endif() if(CONFIG_COMP_FIR) add_subdirectory(eq_fir) endif() -if(CONFIG_COMP_DRC) - add_subdirectory(drc) -endif() if(CONFIG_COMP_DCBLOCK) add_subdirectory(dcblock) endif() diff --git a/test/cmocka/src/audio/buffer/CMakeLists.txt b/test/cmocka/src/audio/buffer/CMakeLists.txt deleted file mode 100644 index 805aaa2da784..000000000000 --- a/test/cmocka/src/audio/buffer/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(buffer_copy - buffer_copy.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.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}/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}/src/audio/component.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) - -cmocka_test(buffer_new - buffer_new.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.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}/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}/src/audio/component.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) - -cmocka_test(buffer_wrap - buffer_wrap.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.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}/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}/src/audio/component.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) - -cmocka_test(buffer_write - buffer_write.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/common_mocks.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.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}/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}/src/audio/component.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) diff --git a/test/cmocka/src/audio/buffer/buffer_copy.c b/test/cmocka/src/audio/buffer/buffer_copy.c deleted file mode 100644 index 35a3dbc73b0e..000000000000 --- a/test/cmocka/src/audio/buffer/buffer_copy.c +++ /dev/null @@ -1,171 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Slawomir Blauciak - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static void test_audio_buffer_copy_underrun(void **state) -{ - int copy_bytes; - - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *src = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *snk = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(src); - assert_non_null(snk); - - comp_update_buffer_produce(src, 10); - copy_bytes = - audio_stream_can_copy_bytes(&src->stream, &snk->stream, 16); - - assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 10); - assert_int_equal(copy_bytes, -1); - - buffer_free(src); - buffer_free(snk); -} - -static void test_audio_buffer_copy_overrun(void **state) -{ - int copy_bytes; - - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *src = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *snk = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(src); - assert_non_null(snk); - - comp_update_buffer_produce(src, 16); - comp_update_buffer_produce(snk, 246); - copy_bytes = - audio_stream_can_copy_bytes(&src->stream, &snk->stream, 16); - - assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 16); - assert_int_equal(audio_stream_get_free_bytes(&snk->stream), 10); - assert_int_equal(copy_bytes, 1); - - buffer_free(src); - buffer_free(snk); -} - -static void test_audio_buffer_copy_success(void **state) -{ - int copy_bytes; - - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *src = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *snk = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(src); - assert_non_null(snk); - - comp_update_buffer_produce(src, 10); - copy_bytes = audio_stream_can_copy_bytes(&src->stream, &snk->stream, 0); - - assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 10); - assert_int_equal(copy_bytes, 0); - - buffer_free(src); - buffer_free(snk); -} - -static void test_audio_buffer_copy_fit_space_constraint(void **state) -{ - int copy_bytes; - - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *src = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *snk = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(src); - assert_non_null(snk); - - comp_update_buffer_produce(src, 16); - comp_update_buffer_produce(snk, 246); - copy_bytes = audio_stream_get_copy_bytes(&src->stream, &snk->stream); - - assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 16); - assert_int_equal(audio_stream_get_free_bytes(&snk->stream), 10); - assert_int_equal(copy_bytes, 10); - - buffer_free(src); - buffer_free(snk); -} - -static void test_audio_buffer_copy_fit_no_space_constraint(void **state) -{ - int copy_bytes; - - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *src = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - struct comp_buffer *snk = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(src); - assert_non_null(snk); - - comp_update_buffer_produce(src, 16); - copy_bytes = audio_stream_get_copy_bytes(&src->stream, &snk->stream); - - assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 16); - assert_int_equal(copy_bytes, 16); - - buffer_free(src); - buffer_free(snk); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_audio_buffer_copy_underrun), - cmocka_unit_test(test_audio_buffer_copy_overrun), - cmocka_unit_test(test_audio_buffer_copy_success), - cmocka_unit_test(test_audio_buffer_copy_fit_space_constraint), - cmocka_unit_test(test_audio_buffer_copy_fit_no_space_constraint) - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/audio/buffer/buffer_new.c b/test/cmocka/src/audio/buffer/buffer_new.c deleted file mode 100644 index 8aee748b029d..000000000000 --- a/test/cmocka/src/audio/buffer/buffer_new.c +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Slawomir Blauciak - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static void test_audio_buffer_new(void **state) -{ - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *buf = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(buf); - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 0); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 256); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - buffer_free(buf); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_audio_buffer_new) - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/audio/buffer/buffer_wrap.c b/test/cmocka/src/audio/buffer/buffer_wrap.c deleted file mode 100644 index 282249ee9a9a..000000000000 --- a/test/cmocka/src/audio/buffer/buffer_wrap.c +++ /dev/null @@ -1,89 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Slawomir Blauciak - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static void test_audio_buffer_write_fill_10_bytes_and_write_5(void **state) -{ - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 10 - }; - - struct comp_buffer *buf = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(buf); - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 0); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 10); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - - int i; - uint8_t *ptr; - - for (i = 0; i < ARRAY_SIZE(bytes); i++) { - ptr = audio_stream_write_frag(&buf->stream, i, sizeof(uint8_t)); - *ptr = bytes[i]; - } - comp_update_buffer_produce(buf, sizeof(bytes)); - - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), sizeof(bytes)); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 0); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - uint8_t more_bytes[5] = {10, 11, 12, 13, 14}; - - for (i = 0; i < ARRAY_SIZE(more_bytes); i++) { - ptr = audio_stream_write_frag(&buf->stream, i, sizeof(uint8_t)); - *ptr = more_bytes[i]; - } - comp_update_buffer_produce(buf, sizeof(more_bytes)); - - uint8_t ref_1[5] = {5, 6, 7, 8, 9}; - uint8_t ref_2[5] = {10, 11, 12, 13, 14}; - - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 10); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 0); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - for (i = 0; i < ARRAY_SIZE(ref_1); i++) { - ptr = audio_stream_read_frag(&buf->stream, i, sizeof(uint8_t)); - assert_int_equal(*ptr, ref_1[i]); - } - comp_update_buffer_consume(buf, sizeof(ref_1)); - for (i = 0; i < ARRAY_SIZE(ref_2); i++) { - ptr = audio_stream_read_frag(&buf->stream, i, sizeof(uint8_t)); - assert_int_equal(*ptr, ref_2[i]); - } - - buffer_free(buf); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test - (test_audio_buffer_write_fill_10_bytes_and_write_5) - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/audio/buffer/buffer_write.c b/test/cmocka/src/audio/buffer/buffer_write.c deleted file mode 100644 index 7982c22fb32d..000000000000 --- a/test/cmocka/src/audio/buffer/buffer_write.c +++ /dev/null @@ -1,96 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Slawomir Blauciak - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static void test_audio_buffer_write_10_bytes_out_of_256_and_read_back - (void **state) -{ - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 256 - }; - - struct comp_buffer *buf = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(buf); - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 0); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 256); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - - memcpy_s(buf->stream.w_ptr, test_buf_desc.size, &bytes, 10); - comp_update_buffer_produce(buf, 10); - - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 10); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 246); - assert_ptr_equal(buf->stream.w_ptr, (char *)buf->stream.r_ptr + 10); - - assert_int_equal(memcmp(buf->stream.r_ptr, &bytes, 10), 0); - - comp_update_buffer_consume(buf, 10); - - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 0); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 256); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - buffer_free(buf); -} - -static void test_audio_buffer_fill_10_bytes(void **state) -{ - (void)state; - - struct sof_ipc_buffer test_buf_desc = { - .size = 10 - }; - - struct comp_buffer *buf = buffer_new(NULL, &test_buf_desc, BUFFER_USAGE_NOT_SHARED); - - assert_non_null(buf); - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 0); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 10); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - - memcpy_s(buf->stream.w_ptr, test_buf_desc.size, &bytes, 10); - comp_update_buffer_produce(buf, 10); - - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 10); - assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 0); - assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - - buffer_free(buf); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test - (test_audio_buffer_write_10_bytes_out_of_256_and_read_back), - cmocka_unit_test(test_audio_buffer_fill_10_bytes) - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/audio/dcblock/CMakeLists.txt b/test/cmocka/src/audio/dcblock/CMakeLists.txt index 0e5754b022d5..fe6294d64635 100644 --- a/test/cmocka/src/audio/dcblock/CMakeLists.txt +++ b/test/cmocka/src/audio/dcblock/CMakeLists.txt @@ -1,14 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -cmocka_test(dcblock_math_test - dcblock_math_test.c - ${PROJECT_SOURCE_DIR}/src/audio/dcblock/dcblock_generic.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c -) - -target_include_directories(dcblock_math_test PRIVATE ${PROJECT_SOURCE_DIR}/src/audio) -target_include_directories(dcblock_math_test PRIVATE ${PROJECT_SOURCE_DIR}/src/audio/dcblock) - cmocka_test(dcblock_process dcblock_process.c ) diff --git a/test/cmocka/src/audio/dcblock/dcblock_math_test.c b/test/cmocka/src/audio/dcblock/dcblock_math_test.c deleted file mode 100644 index d41288c231ad..000000000000 --- a/test/cmocka/src/audio/dcblock/dcblock_math_test.c +++ /dev/null @@ -1,345 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2026 Intel Corporation. - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "dcblock.h" - -#define TEST_CHANNELS 2 -#define TEST_FRAMES 256 - -/* - * The dcblock processing functions operate on struct cir_buf_source / - * struct cir_buf_sink circular buffer views. The tests use static, non - * wrapping sample buffers, so the views simply span the whole array. - */ -static void cir_buf_src_setup(struct cir_buf_source *s, const void *data, size_t bytes) -{ - s->buf_start = data; - s->buf_end = (const char *)data + bytes; - s->ptr = data; -} - -static void cir_buf_snk_setup(struct cir_buf_sink *s, void *data, size_t bytes) -{ - s->buf_start = data; - s->buf_end = (char *)data + bytes; - s->ptr = data; -} - -/* Q2.30 coefficient close to 1.0 used for the DC removal test cases. */ -#define R_COEF_NEAR_ONE 1063004406 /* ~0.99 in Q2.30 */ - -/* - * Reference DC blocking filter implemented in floating point. Mirrors the - * fixed point recurrence y[n] = x[n] - x[n-1] + R * y[n-1] where R is the - * Q2.30 coefficient converted to a real number. - */ -struct ref_state { - double x_prev; - double y_prev; -}; - -static double dcblock_ref(struct ref_state *s, double r, double x) -{ - double y = x - s->x_prev + r * s->y_prev; - - s->x_prev = x; - s->y_prev = y; - return y; -} - -/* Fill the source buffer with a per-channel sinusoid plus a DC offset. */ -static void gen_input(double *ref_in, int channels, int frames, double dc) -{ - int ch, i; - - for (i = 0; i < frames; i++) { - for (ch = 0; ch < channels; ch++) { - double phase = 2.0 * M_PI * (i + 1) * (ch + 1) / 64.0; - - ref_in[i * channels + ch] = dc + 0.3 * sin(phase); - } - } -} - -/* - * Runs the S32 processing function and compares it to the floating point - * reference. Returns the mean absolute value of the last quarter of the - * output which is used to check DC convergence. - */ -static double run_s32_case(int32_t r_coeff, double dc, double tol_rel) -{ - struct comp_data cd; - struct cir_buf_source csrc; - struct cir_buf_sink csnk; - int32_t src[TEST_FRAMES * TEST_CHANNELS]; - int32_t dst[TEST_FRAMES * TEST_CHANNELS]; - double ref_in[TEST_FRAMES * TEST_CHANNELS]; - struct ref_state rstate[TEST_CHANNELS]; - double r = (double)r_coeff / (double)ONE_Q2_30; - double tail_abs_sum = 0.0; - int tail_count = 0; - dcblock_func func; - int ch, i; - - memset(&cd, 0, sizeof(cd)); - cd.channels = TEST_CHANNELS; - for (ch = 0; ch < TEST_CHANNELS; ch++) - cd.R_coeffs[ch] = r_coeff; - - memset(rstate, 0, sizeof(rstate)); - gen_input(ref_in, TEST_CHANNELS, TEST_FRAMES, dc); - - for (i = 0; i < TEST_FRAMES * TEST_CHANNELS; i++) - src[i] = (int32_t)round(ref_in[i] * 2147483647.0); - - cir_buf_src_setup(&csrc, src, sizeof(src)); - cir_buf_snk_setup(&csnk, dst, sizeof(dst)); - - func = dcblock_find_func(SOF_IPC_FRAME_S32_LE); - assert_non_null(func); - assert_int_equal(func(&cd, &csrc, &csnk, TEST_FRAMES), 0); - - for (i = 0; i < TEST_FRAMES; i++) { - for (ch = 0; ch < TEST_CHANNELS; ch++) { - int idx = i * TEST_CHANNELS + ch; - double refy = dcblock_ref(&rstate[ch], r, - (double)src[idx] / 2147483648.0); - double outy = (double)dst[idx] / 2147483648.0; - double delta = fabs(refy - outy); - - if (delta > tol_rel) { - printf("s32 mismatch idx %d ref %g out %g delta %g\n", - idx, refy, outy, delta); - assert_true(delta <= tol_rel); - } - - if (i >= TEST_FRAMES * 3 / 4) { - tail_abs_sum += fabs(outy); - tail_count++; - } - } - } - - return tail_count ? tail_abs_sum / tail_count : 0.0; -} - -/* Passthrough: R = 1.0 gives y[n] = x[n] - x[n-1], a pure differentiator. */ -static void test_dcblock_passthrough(void **state) -{ - (void)state; - - /* With no DC and R=1.0 the reference matches bit-close. */ - run_s32_case(ONE_Q2_30, 0.0, 1.0e-6); -} - -/* A strong DC offset must be attenuated towards zero in steady state. */ -static void test_dcblock_dc_removal(void **state) -{ - (void)state; - - double tail = run_s32_case(R_COEF_NEAR_ONE, 0.5, 1.0e-6); - - /* The residual DC plus small sinusoid must be well below the input DC. */ - printf("dc_removal tail mean abs = %g\n", tail); - assert_true(tail < 0.25); -} - -/* Full scale input must not overflow (saturation path in dcblock_generic). */ -static void test_dcblock_saturation(void **state) -{ - (void)state; - - struct comp_data cd; - struct cir_buf_source csrc; - struct cir_buf_sink csnk; - int32_t src[TEST_FRAMES * TEST_CHANNELS]; - int32_t dst[TEST_FRAMES * TEST_CHANNELS]; - dcblock_func func; - int i; - - memset(&cd, 0, sizeof(cd)); - cd.channels = TEST_CHANNELS; - for (i = 0; i < TEST_CHANNELS; i++) - cd.R_coeffs[i] = R_COEF_NEAR_ONE; - - /* - * Alternate per frame so that every channel sees the full-scale - * transitions and exercises the saturation path. - */ - for (i = 0; i < TEST_FRAMES * TEST_CHANNELS; i++) - src[i] = ((i / TEST_CHANNELS) & 1) ? INT32_MAX : INT32_MIN; - - cir_buf_src_setup(&csrc, src, sizeof(src)); - cir_buf_snk_setup(&csnk, dst, sizeof(dst)); - - func = dcblock_find_func(SOF_IPC_FRAME_S32_LE); - assert_non_null(func); - assert_int_equal(func(&cd, &csrc, &csnk, TEST_FRAMES), 0); - - for (i = 0; i < TEST_FRAMES * TEST_CHANNELS; i++) { - int32_t expected = ((i / TEST_CHANNELS) & 1) ? INT32_MAX : INT32_MIN; - - assert_int_equal(dst[i], expected); - } -} - -/* Bit-exactness check against the floating point reference for S32. */ -static void test_dcblock_bitexact_s32(void **state) -{ - (void)state; - - run_s32_case(R_COEF_NEAR_ONE, 0.1, 1.0e-6); -} - -/* - * Runs the S16 processing function and compares it to the floating point - * reference. The component internally works in Q1.31, so the tolerance must - * account for the 16-bit output quantization step (2 LSB of S16). - */ -static void run_s16_case(int32_t r_coeff, double dc) -{ - struct comp_data cd; - struct cir_buf_source csrc; - struct cir_buf_sink csnk; - int16_t src[TEST_FRAMES * TEST_CHANNELS]; - int16_t dst[TEST_FRAMES * TEST_CHANNELS]; - double ref_in[TEST_FRAMES * TEST_CHANNELS]; - struct ref_state rstate[TEST_CHANNELS]; - double r = (double)r_coeff / (double)ONE_Q2_30; - double tol = 2.0 / 32768.0; - dcblock_func func; - int ch, i; - - memset(&cd, 0, sizeof(cd)); - cd.channels = TEST_CHANNELS; - for (ch = 0; ch < TEST_CHANNELS; ch++) - cd.R_coeffs[ch] = r_coeff; - - memset(rstate, 0, sizeof(rstate)); - gen_input(ref_in, TEST_CHANNELS, TEST_FRAMES, dc); - - for (i = 0; i < TEST_FRAMES * TEST_CHANNELS; i++) - src[i] = (int16_t)round(ref_in[i] * 32767.0); - - cir_buf_src_setup(&csrc, src, sizeof(src)); - cir_buf_snk_setup(&csnk, dst, sizeof(dst)); - - func = dcblock_find_func(SOF_IPC_FRAME_S16_LE); - assert_non_null(func); - assert_int_equal(func(&cd, &csrc, &csnk, TEST_FRAMES), 0); - - for (i = 0; i < TEST_FRAMES; i++) { - for (ch = 0; ch < TEST_CHANNELS; ch++) { - int idx = i * TEST_CHANNELS + ch; - double refy = dcblock_ref(&rstate[ch], r, - (double)src[idx] / 32768.0); - double outy = (double)dst[idx] / 32768.0; - double delta = fabs(refy - outy); - - if (delta > tol) { - printf("s16 mismatch idx %d ref %g out %g delta %g\n", - idx, refy, outy, delta); - assert_true(delta <= tol); - } - } - } -} - -/* Bit-exactness check against the floating point reference for S16. */ -static void test_dcblock_bitexact_s16(void **state) -{ - (void)state; - - run_s16_case(R_COEF_NEAR_ONE, 0.1); -} - -/* - * Runs the S24 (in 32-bit container) processing function and compares it to - * the floating point reference with a tolerance of 2 LSB of S24. - */ -static void run_s24_case(int32_t r_coeff, double dc) -{ - struct comp_data cd; - struct cir_buf_source csrc; - struct cir_buf_sink csnk; - int32_t src[TEST_FRAMES * TEST_CHANNELS]; - int32_t dst[TEST_FRAMES * TEST_CHANNELS]; - double ref_in[TEST_FRAMES * TEST_CHANNELS]; - struct ref_state rstate[TEST_CHANNELS]; - double r = (double)r_coeff / (double)ONE_Q2_30; - double tol = 2.0 / 8388608.0; - dcblock_func func; - int ch, i; - - memset(&cd, 0, sizeof(cd)); - cd.channels = TEST_CHANNELS; - for (ch = 0; ch < TEST_CHANNELS; ch++) - cd.R_coeffs[ch] = r_coeff; - - memset(rstate, 0, sizeof(rstate)); - gen_input(ref_in, TEST_CHANNELS, TEST_FRAMES, dc); - - for (i = 0; i < TEST_FRAMES * TEST_CHANNELS; i++) - src[i] = (int32_t)round(ref_in[i] * 8388607.0); - - cir_buf_src_setup(&csrc, src, sizeof(src)); - cir_buf_snk_setup(&csnk, dst, sizeof(dst)); - - func = dcblock_find_func(SOF_IPC_FRAME_S24_4LE); - assert_non_null(func); - assert_int_equal(func(&cd, &csrc, &csnk, TEST_FRAMES), 0); - - for (i = 0; i < TEST_FRAMES; i++) { - for (ch = 0; ch < TEST_CHANNELS; ch++) { - int idx = i * TEST_CHANNELS + ch; - double refy = dcblock_ref(&rstate[ch], r, - (double)src[idx] / 8388608.0); - double outy = (double)dst[idx] / 8388608.0; - double delta = fabs(refy - outy); - - if (delta > tol) { - printf("s24 mismatch idx %d ref %g out %g delta %g\n", - idx, refy, outy, delta); - assert_true(delta <= tol); - } - } - } -} - -/* Bit-exactness check against the floating point reference for S24. */ -static void test_dcblock_bitexact_s24(void **state) -{ - (void)state; - - run_s24_case(R_COEF_NEAR_ONE, 0.1); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_dcblock_passthrough), - cmocka_unit_test(test_dcblock_dc_removal), - cmocka_unit_test(test_dcblock_saturation), - cmocka_unit_test(test_dcblock_bitexact_s32), - cmocka_unit_test(test_dcblock_bitexact_s16), - cmocka_unit_test(test_dcblock_bitexact_s24), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/audio/drc/CMakeLists.txt b/test/cmocka/src/audio/drc/CMakeLists.txt deleted file mode 100644 index f0c351e5c90a..000000000000 --- a/test/cmocka/src/audio/drc/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(drc_math_test - drc_math_test.c - ${PROJECT_SOURCE_DIR}/src/audio/drc/drc_math_generic.c - ${PROJECT_SOURCE_DIR}/src/audio/drc/drc_math_hifi3.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c - ${PROJECT_SOURCE_DIR}/src/math/exp_fcn.c - ${PROJECT_SOURCE_DIR}/src/math/exp_fcn_hifi.c -) - -target_include_directories(drc_math_test PRIVATE ${PROJECT_SOURCE_DIR}/src/audio) diff --git a/test/cmocka/src/audio/mux/CMakeLists.txt b/test/cmocka/src/audio/mux/CMakeLists.txt deleted file mode 100644 index ef1eebecd1a6..000000000000 --- a/test/cmocka/src/audio/mux/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -# make small lib for stripping so we don't have to care -# about unused missing references - -add_compile_options(-fdata-sections -ffunction-sections -DUNIT_TEST) -link_libraries(-Wl,--gc-sections) - -add_library( - audio_mux - STATIC - ${PROJECT_SOURCE_DIR}/src/audio/mux/mux.c - ${PROJECT_SOURCE_DIR}/src/audio/mux/mux_ipc3.c - ${PROJECT_SOURCE_DIR}/src/audio/mux/mux_generic.c - ${PROJECT_SOURCE_DIR}/src/audio/component.c - ${PROJECT_SOURCE_DIR}/src/audio/data_blob.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}/src/math/numbers.c - ${PROJECT_SOURCE_DIR}/src/kernel/ipc/ipc3/helper.c - ${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c - ${PROJECT_SOURCE_DIR}/src/lib/objpool.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c - ${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c - ${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter_ipc3.c - ${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c -) -sof_append_relative_path_definitions(audio_mux) - -target_link_libraries(audio_mux PRIVATE sof_options) - -link_libraries(audio_mux) - -cmocka_test( - mux_get_processing_function - mux_get_processing_function.c -) - -cmocka_test( - mux_copy - mux_copy.c -) - -cmocka_test( - demux_copy - demux_copy.c -) - -target_include_directories(audio_mux PRIVATE ${PROJECT_SOURCE_DIR}/src/audio) -target_include_directories(mux_get_processing_function PRIVATE ${PROJECT_SOURCE_DIR}/src/audio) -target_include_directories(mux_copy PRIVATE ${PROJECT_SOURCE_DIR}/src/audio) -target_include_directories(demux_copy PRIVATE ${PROJECT_SOURCE_DIR}/src/audio) diff --git a/test/cmocka/src/audio/mux/demux_copy.c b/test/cmocka/src/audio/mux/demux_copy.c deleted file mode 100644 index 270f9f61dd04..000000000000 --- a/test/cmocka/src/audio/mux/demux_copy.c +++ /dev/null @@ -1,348 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2019 Intel Corporation. All rights reserved. -// -// Author: Daniel Bogdzia -// Janusz Jankowski - -#include "../../util.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -struct test_data { - struct comp_dev *dev; - struct processing_module *mod; - struct comp_data *cd; - struct comp_buffer *sinks[MUX_MAX_STREAMS]; - struct comp_buffer *source; - void *outputs[MUX_MAX_STREAMS]; - uint32_t format; - uint8_t mask[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; -}; - -static int16_t input_16b[CONFIG_PLATFORM_MAX_CHANNELS] = { - 0x101, 0x102, 0x104, 0x108, - 0x111, 0x112, 0x114, 0x118, -}; - -static int32_t input_24b[CONFIG_PLATFORM_MAX_CHANNELS] = { - 0x1a1001, 0x2a2002, 0x4a4004, 0x8a8008, - 0x1b1011, 0x2b2012, 0x4b4014, 0x8b8018, -}; - -static int32_t input_32b[CONFIG_PLATFORM_MAX_CHANNELS] = { - 0xd1a1001, 0xd2a2002, 0xd4a4004, 0xd8a8008, - 0xe1b1011, 0xe2b2012, 0xe4b4014, 0xe8b8018, -}; - -static uint16_t valid_formats[] = { - SOF_IPC_FRAME_S16_LE, - SOF_IPC_FRAME_S24_4LE, - SOF_IPC_FRAME_S32_LE, -}; - -static uint8_t masks[][MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { - { { 0x01, }, }, - { { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, - { { }, - { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, - { { }, - { }, - { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, - { { }, - { }, - { }, - { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, - { { 0x01, }, - { 0x00, 0x01, }, - { 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10}, }, - { { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10}, - { 0x00, 0x00, 0x01, }, - { 0x00, 0x01, }, - { 0x01, }, }, - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, - { 0x10, 0x08, 0x04, 0x02, 0x01, },}, - { { 0x01, }, - { 0x00, 0x01, }, - { 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x01, },}, -}; - -static int setup_group(void **state) -{ - sys_comp_init(sof_get()); - sys_comp_module_demux_interface_init(); - return 0; -} - -static struct sof_ipc_comp_process *create_demux_comp_ipc(struct test_data *td) -{ - struct sof_ipc_comp_process *ipc; - struct sof_mux_config *mux; - size_t ipc_size = sizeof(struct sof_ipc_comp_process); - size_t mux_size = sizeof(struct sof_mux_config) + - MUX_MAX_STREAMS * sizeof(struct mux_stream_data); - const struct sof_uuid uuid = SOF_REG_UUID(demux); - int i, j; - - ipc = calloc(1, ipc_size + mux_size + SOF_UUID_SIZE); - memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE); - mux = (struct sof_mux_config *)((char *)(ipc + 1) + SOF_UUID_SIZE); - ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE; - ipc->comp.type = SOF_COMP_MODULE_ADAPTER; - ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = mux_size; - ipc->comp.ext_data_length = SOF_UUID_SIZE; - - mux->num_streams = MUX_MAX_STREAMS; - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - mux->streams[i].pipeline_id = i; - for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) - mux->streams[i].mask[j] = td->mask[i][j]; - } - - return ipc; -} - -static void prepare_sinks(struct test_data *td, size_t sample_size) -{ - int i; - uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; - - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - td->sinks[i] = create_test_sink(td->dev, i, td->format, CONFIG_PLATFORM_MAX_CHANNELS, - buffer_size); - - td->outputs[i] = td->sinks[i]->stream.addr; - assert_int_equal(audio_stream_get_free_bytes(&td->sinks[i]->stream), buffer_size); - } -} - -static void prepare_source(struct test_data *td, size_t sample_size) -{ - uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; - - td->source = create_test_source(td->dev, MUX_MAX_STREAMS + 1, td->format, - CONFIG_PLATFORM_MAX_CHANNELS, buffer_size); - - if (td->format == SOF_IPC_FRAME_S16_LE) - memcpy_s(td->source->stream.addr, buffer_size, input_16b, buffer_size); - else if (td->format == SOF_IPC_FRAME_S24_4LE) - memcpy_s(td->source->stream.addr, buffer_size, input_24b, buffer_size); - else - memcpy_s(td->source->stream.addr, buffer_size, input_32b, buffer_size); - - audio_stream_produce(&td->source->stream, buffer_size); - assert_int_equal(audio_stream_get_avail_bytes(&td->source->stream), buffer_size); -} - -static int setup_test_case(void **state) -{ - struct test_data *td = *((struct test_data **)state); - struct comp_dev *dev; - struct processing_module *mod; - struct sof_ipc_comp_process *ipc; - size_t sample_size = td->format == SOF_IPC_FRAME_S16_LE ? sizeof(int16_t) : sizeof(int32_t); - struct pipeline *dummy_pipe; - - ipc = create_demux_comp_ipc(td); - dev = comp_new((struct sof_ipc_comp *)ipc); - free(ipc); - if (!dev) - return -EINVAL; - - /* Add dummy pipeline to bypass comp_check_eos() */ - dummy_pipe = test_malloc(sizeof(*dummy_pipe)); - if (!dummy_pipe) - return -ENOMEM; - dev->expect_eos = false; - dev->pipeline = dummy_pipe; - - mod = comp_mod(dev); - td->dev = dev; - td->mod = mod; - td->cd = module_get_private_data(mod); - - prepare_sinks(td, sample_size); - prepare_source(td, sample_size); - - return comp_prepare(td->dev); -} - -static int teardown_test_case(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int i; - - free_test_source(td->source); - - for (i = 0; i < MUX_MAX_STREAMS; ++i) - free_test_sink(td->sinks[i]); - - test_free(td->dev->pipeline); - td->dev->pipeline = NULL; - comp_free(td->dev); - - return 0; -} - -static void test_demux_copy_proc_16(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int16_t expected_results[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; - int i, j, k; - - assert_int_equal(comp_copy(td->dev), 0); - - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) { - int64_t sample = 0; - - for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) - if (td->mask[i][j] & BIT(k)) - sample = input_16b[k]; - - expected_results[i][j] = sample; - } - } - - for (i = 0; i < MUX_MAX_STREAMS; ++i) - assert_memory_equal(td->outputs[i], expected_results[i], - sizeof(expected_results[0])); -} - -static void test_demux_copy_proc_24(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int32_t expected_results[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; - int i, j, k; - - assert_int_equal(comp_copy(td->dev), 0); - - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) { - int32_t sample = 0; - - for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) - if (td->mask[i][j] & BIT(k)) - sample = input_24b[k]; - - expected_results[i][j] = sample; - } - } - - for (i = 0; i < MUX_MAX_STREAMS; ++i) - assert_memory_equal(td->outputs[i], expected_results[i], - sizeof(expected_results[0])); -} - -static void test_demux_copy_proc_32(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int32_t expected_results[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; - int i, j, k; - - assert_int_equal(comp_copy(td->dev), 0); - - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) { - int32_t sample = 0; - - for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) - if (td->mask[i][j] & BIT(k)) - sample = input_32b[k]; - - expected_results[i][j] = sample; - } - } - - for (i = 0; i < MUX_MAX_STREAMS; ++i) - assert_memory_equal(td->outputs[i], expected_results[i], - sizeof(expected_results[0])); -} - -static char *get_test_name(int mask_index, const char *format_name) -{ - int length = snprintf(NULL, 0, "test_demux_copy_%s_mask_%d", - format_name, mask_index) + 1; - char *buffer = malloc(length); - - snprintf(buffer, length, "test_demux_copy_%s_mask_%d", - format_name, mask_index); - - return buffer; -} - -int main(void) -{ - struct CMUnitTest tests[ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks)]; - struct test_data *td; - int i, j, ti, ret; - - for (i = 0; i < ARRAY_SIZE(valid_formats); ++i) { - for (j = 0; j < ARRAY_SIZE(masks); ++j) { - ti = i * ARRAY_SIZE(masks) + j; - td = malloc(sizeof(struct test_data)); - - td->format = valid_formats[i]; - - memcpy_s(td->mask, sizeof(td->mask), - masks[j], sizeof(masks[0])); - - switch (td->format) { -#if CONFIG_FORMAT_S16LE - case SOF_IPC_FRAME_S16_LE: - tests[ti].name = get_test_name(j, "s16le"); - tests[ti].test_func = test_demux_copy_proc_16; - break; -#endif /* CONFIG_FORMAT_S16LE */ -#if CONFIG_FORMAT_S24LE - case SOF_IPC_FRAME_S24_4LE: - tests[ti].name = get_test_name(j, "s24_4le"); - tests[ti].test_func = test_demux_copy_proc_24; - break; -#endif /* CONFIG_FORMAT_S24LE */ -#if CONFIG_FORMAT_S32LE - case SOF_IPC_FRAME_S32_LE: - tests[ti].name = get_test_name(j, "s32le"); - tests[ti].test_func = test_demux_copy_proc_32; - break; -#endif /* CONFIG_FORMAT_S32LE */ -#if CONFIG_FORMAT_S24_3LE - case SOF_IPC_FRAME_S24_3LE: - break; -#endif /* CONFIG_FORMAT_S24_3LE */ - default: - return -EINVAL; - } - - tests[ti].initial_state = td; - tests[ti].setup_func = setup_test_case; - tests[ti].teardown_func = teardown_test_case; - } - } - - cmocka_set_message_output(CM_OUTPUT_TAP); - ret = cmocka_run_group_tests(tests, setup_group, NULL); - - for (ti = 0; ti < ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks); ti++) { - free(tests[ti].initial_state); - free((void *)tests[ti].name); - } - - return ret; -} diff --git a/test/cmocka/src/audio/mux/mux_copy.c b/test/cmocka/src/audio/mux/mux_copy.c deleted file mode 100644 index df9d00252d15..000000000000 --- a/test/cmocka/src/audio/mux/mux_copy.c +++ /dev/null @@ -1,366 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2019 Intel Corporation. All rights reserved. -// -// Author: Daniel Bogdzia -// Janusz Jankowski - -#include "../../util.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -struct test_data { - struct comp_dev *dev; - struct processing_module *mod; - struct comp_data *cd; - struct comp_buffer *sources[MUX_MAX_STREAMS]; - struct comp_buffer *sink; - void *output; - uint32_t format; - uint8_t mask[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; -}; - -static int16_t input_16b[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { - { 0x101, 0x102, 0x104, 0x108, - 0x111, 0x112, 0x114, 0x118, }, - { 0x201, 0x202, 0x204, 0x208, - 0x211, 0x212, 0x214, 0x218, }, - { 0x301, 0x302, 0x304, 0x308, - 0x311, 0x312, 0x314, 0x318, }, - { 0x401, 0x402, 0x404, 0x408, - 0x411, 0x412, 0x414, 0x418, }, -}; - -static int32_t input_24b[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { - { 0x1a1001, 0x2a2002, 0x4a4004, 0x8a8008, - 0x1b1011, 0x2b2012, 0x4b4014, 0x8b8018, }, - { 0x1a1101, 0x2a2102, 0x4a4104, 0x8a8108, - 0x1b1111, 0x2b2112, 0x4b4114, 0x8b8118, }, - { 0x1a1201, 0x2a2202, 0x4a4204, 0x8a8208, - 0x1b1211, 0x2b2212, 0x4b4214, 0x8b8218, }, - { 0x1a1401, 0x2a2402, 0x4a4404, 0x8a8408, - 0x1b1411, 0x2b2412, 0x4b4414, 0x8b8418, }, -}; - -static int32_t input_32b[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { - { 0xd1a1001, 0xd2a2002, 0xd4a4004, 0xd8a8008, - 0xe1b1011, 0xe2b2012, 0xe4b4014, 0xe8b8018, }, - { 0xd1a1101, 0xd2a2102, 0xd4a4104, 0xd8a8108, - 0xe1b1111, 0xe2b2112, 0xe4b4114, 0xe8b8118, }, - { 0xd1a1201, 0xd2a2202, 0xd4a4204, 0xd8a8208, - 0xe1b1211, 0xe2b2212, 0xe4b4214, 0xe8b8218, }, - { 0xd1a1401, 0xd2a2402, 0xd4a4404, 0xd8a8408, - 0xe1b1411, 0xe2b2412, 0xe4b4414, 0xe8b8418, }, -}; - -static uint16_t valid_formats[] = { - SOF_IPC_FRAME_S16_LE, - SOF_IPC_FRAME_S24_4LE, - SOF_IPC_FRAME_S32_LE, -}; - -static uint8_t masks[][MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { - { { 0x01, }, }, - { { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, - { { }, - { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, - { { }, - { }, - { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, - { { }, - { }, - { }, - { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, - { { 0x01, }, - { 0x00, 0x01, }, - { 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10 }, }, - { { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10 }, - { 0x00, 0x00, 0x01, }, - { 0x00, 0x01, }, - { 0x01, }, }, - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, - { 0x10, 0x08, 0x04, 0x02, 0x01, }, }, - { { 0x01, }, - { 0x00, 0x01, }, - { 0x00, 0x00, 0x01, }, - { 0x00, 0x00, 0x00, 0x01, }, }, -}; - -static int setup_group(void **state) -{ - sys_comp_init(sof_get()); - sys_comp_module_mux_interface_init(); - return 0; -} - -static struct sof_ipc_comp_process *create_mux_comp_ipc(struct test_data *td) -{ - struct sof_ipc_comp_process *ipc; - struct sof_mux_config *mux; - size_t ipc_size = sizeof(struct sof_ipc_comp_process); - size_t mux_size = sizeof(struct sof_mux_config) + - MUX_MAX_STREAMS * sizeof(struct mux_stream_data); - const struct sof_uuid uuid = SOF_REG_UUID(mux); - int i, j; - - ipc = calloc(1, ipc_size + mux_size + SOF_UUID_SIZE); - memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE); - mux = (struct sof_mux_config *)((char *)(ipc + 1) + SOF_UUID_SIZE); - ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE; - ipc->comp.type = SOF_COMP_MODULE_ADAPTER; - ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = mux_size; - ipc->comp.ext_data_length = SOF_UUID_SIZE; - - mux->num_streams = MUX_MAX_STREAMS; - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - mux->streams[i].pipeline_id = i; - for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) - mux->streams[i].mask[j] = td->mask[i][j]; - } - - return ipc; -} - -static void prepare_sink(struct test_data *td, size_t sample_size) -{ - uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; - - td->sink = create_test_sink(td->dev, MUX_MAX_STREAMS + 1, td->format, CONFIG_PLATFORM_MAX_CHANNELS, - buffer_size); - td->output = td->sink->stream.addr; - - assert_int_equal(audio_stream_get_free_bytes(&td->sink->stream), buffer_size); -} - -static void prepare_sources(struct test_data *td, size_t sample_size) -{ - int i; - uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; - - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - td->sources[i] = create_test_source(td->dev, i, td->format, CONFIG_PLATFORM_MAX_CHANNELS, - buffer_size); - - if (td->format == SOF_IPC_FRAME_S16_LE) - memcpy_s(td->sources[i]->stream.addr, buffer_size, &input_16b[i], - buffer_size); - else if (td->format == SOF_IPC_FRAME_S24_4LE) - memcpy_s(td->sources[i]->stream.addr, buffer_size, &input_24b[i], - buffer_size); - else - memcpy_s(td->sources[i]->stream.addr, buffer_size, &input_32b[i], - buffer_size); - - audio_stream_produce(&td->sources[i]->stream, buffer_size); - assert_int_equal(audio_stream_get_avail_bytes(&td->sources[i]->stream), - buffer_size); - } -} - -static int setup_test_case(void **state) -{ - struct test_data *td = *((struct test_data **)state); - struct comp_dev *dev; - struct processing_module *mod; - struct sof_ipc_comp_process *ipc; - size_t sample_size = td->format == SOF_IPC_FRAME_S16_LE ? sizeof(int16_t) : sizeof(int32_t); - struct pipeline *dummy_pipe; - - ipc = create_mux_comp_ipc(td); - dev = comp_new((struct sof_ipc_comp *)ipc); - free(ipc); - if (!dev) - return -EINVAL; - - /* Add dummy pipeline to bypass comp_check_eos() */ - dummy_pipe = test_malloc(sizeof(*dummy_pipe)); - if (!dummy_pipe) - return -ENOMEM; - dev->expect_eos = false; - dev->pipeline = dummy_pipe; - - mod = comp_mod(dev); - td->dev = dev; - td->mod = mod; - td->cd = module_get_private_data(mod); - - prepare_sink(td, sample_size); - prepare_sources(td, sample_size); - - return comp_prepare(td->dev); - -} - -static int teardown_test_case(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int i; - - for (i = 0; i < MUX_MAX_STREAMS; ++i) - free_test_source(td->sources[i]); - - free_test_sink(td->sink); - test_free(td->dev->pipeline); - td->dev->pipeline = NULL; - comp_free(td->dev); - return 0; -} - -static void test_mux_copy_proc_16(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int16_t expected_result[CONFIG_PLATFORM_MAX_CHANNELS]; - int i, j, k; - - assert_int_equal(comp_copy(td->dev), 0); - - for (i = 0; i < CONFIG_PLATFORM_MAX_CHANNELS; ++i) { - int32_t sample = 0; - - for (j = 0; j < MUX_MAX_STREAMS; ++j) { - for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) { - if (td->mask[j][k] & BIT(i)) - sample = input_16b[j][k]; - } - } - expected_result[i] = sample; - } - - assert_memory_equal(td->output, expected_result, - sizeof(expected_result)); -} - -static void test_mux_copy_proc_24(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int32_t expected_result[CONFIG_PLATFORM_MAX_CHANNELS]; - int i, j, k; - - assert_int_equal(comp_copy(td->dev), 0); - - for (i = 0; i < CONFIG_PLATFORM_MAX_CHANNELS; ++i) { - int32_t sample = 0; - - for (j = 0; j < MUX_MAX_STREAMS; ++j) { - for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) { - if (td->mask[j][k] & BIT(i)) - sample = input_24b[j][k]; - } - } - expected_result[i] = sample; - } - - assert_memory_equal(td->output, expected_result, - sizeof(expected_result)); -} - -static void test_mux_copy_proc_32(void **state) -{ - struct test_data *td = *((struct test_data **)state); - int32_t expected_result[CONFIG_PLATFORM_MAX_CHANNELS]; - int i, j, k; - - assert_int_equal(comp_copy(td->dev), 0); - - for (i = 0; i < CONFIG_PLATFORM_MAX_CHANNELS; ++i) { - int32_t sample = 0; - - for (j = 0; j < MUX_MAX_STREAMS; ++j) { - for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) { - if (td->mask[j][k] & BIT(i)) - sample = input_32b[j][k]; - } - } - expected_result[i] = sample; - } - - assert_memory_equal(td->output, expected_result, - sizeof(expected_result)); -} - -static char *get_test_name(int mask_index, const char *format_name) -{ - int length = snprintf(NULL, 0, "test_mux_copy_%s_mask_%d", - format_name, mask_index) + 1; - char *buffer = malloc(length); - - snprintf(buffer, length, "test_mux_copy_%s_mask_%d", - format_name, mask_index); - - return buffer; -} - -int main(void) -{ - struct test_data *td; - struct CMUnitTest tests[ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks)]; - int i, j, ti, ret; - - for (i = 0; i < ARRAY_SIZE(valid_formats); ++i) { - for (j = 0; j < ARRAY_SIZE(masks); ++j) { - ti = i * ARRAY_SIZE(masks) + j; - td = malloc(sizeof(struct test_data)); - - td->format = valid_formats[i]; - - memcpy_s(td->mask, sizeof(td->mask), - masks[j], sizeof(masks[0])); - - switch (td->format) { -#if CONFIG_FORMAT_S16LE - case SOF_IPC_FRAME_S16_LE: - tests[ti].name = get_test_name(j, "s16le"); - tests[ti].test_func = test_mux_copy_proc_16; - break; -#endif /* CONFIG_FORMAT_S16LE */ -#if CONFIG_FORMAT_S24LE - case SOF_IPC_FRAME_S24_4LE: - tests[ti].name = get_test_name(j, "s24_4le"); - tests[ti].test_func = test_mux_copy_proc_24; - break; -#endif /* CONFIG_FORMAT_S24LE */ -#if CONFIG_FORMAT_S32LE - case SOF_IPC_FRAME_S32_LE: - tests[ti].name = get_test_name(j, "s32le"); - tests[ti].test_func = test_mux_copy_proc_32; - break; -#endif /* CONFIG_FORMAT_S32LE */ -#if CONFIG_FORMAT_S24_3LE - case SOF_IPC_FRAME_S24_3LE: - break; -#endif /* CONFIG_FORMAT_S24_3LE */ - default: - return -EINVAL; - } - - tests[ti].initial_state = td; - tests[ti].setup_func = setup_test_case; - tests[ti].teardown_func = teardown_test_case; - } - } - - cmocka_set_message_output(CM_OUTPUT_TAP); - ret = cmocka_run_group_tests(tests, setup_group, NULL); - - for (ti = 0; ti < ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks); ti++) { - free(tests[ti].initial_state); - free((void *)tests[ti].name); - } - - return ret; -} diff --git a/test/cmocka/src/audio/mux/mux_get_processing_function.c b/test/cmocka/src/audio/mux/mux_get_processing_function.c deleted file mode 100644 index 9745d4315c21..000000000000 --- a/test/cmocka/src/audio/mux/mux_get_processing_function.c +++ /dev/null @@ -1,199 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2019 Intel Corporation. All rights reserved. -// -// Author: Daniel Bogdzia -// Janusz Jankowski - -#include "../../util.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -struct test_data { - struct comp_dev *dev; - struct processing_module *mod; - struct comp_data *cd; - struct comp_buffer *sink; -}; - -static int setup_group(void **state) -{ - sys_comp_init(sof_get()); - sys_comp_module_mux_interface_init(); - - return 0; -} - -static struct sof_ipc_comp_process *create_mux_comp_ipc(struct test_data *td) -{ - struct sof_ipc_comp_process *ipc; - struct sof_mux_config *mux; - size_t ipc_size = sizeof(struct sof_ipc_comp_process); - size_t mux_size = sizeof(struct sof_mux_config) + - MUX_MAX_STREAMS * sizeof(struct mux_stream_data); - const struct sof_uuid uuid = SOF_REG_UUID(mux); - int i, j; - - ipc = calloc(1, ipc_size + mux_size + SOF_UUID_SIZE); - memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE); - mux = (struct sof_mux_config *)((char *)(ipc + 1) + SOF_UUID_SIZE); - ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE; - ipc->comp.type = SOF_COMP_MODULE_ADAPTER; - ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = mux_size; - ipc->comp.ext_data_length = SOF_UUID_SIZE; - - mux->num_streams = MUX_MAX_STREAMS; - for (i = 0; i < MUX_MAX_STREAMS; ++i) { - mux->streams[i].pipeline_id = i; - for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) - mux->streams[i].mask[j] = 0; - } - - return ipc; -} - - -static int setup_test_case(void **state) -{ - struct test_data *td; - struct comp_dev *dev; - struct processing_module *mod; - struct sof_ipc_comp_process *ipc; - - td = test_malloc(sizeof(*td)); - if (!td) - return -ENOMEM; - - ipc = create_mux_comp_ipc(td); - dev = comp_new((struct sof_ipc_comp *)ipc); - free(ipc); - if (!dev) - return -EINVAL; - - mod = comp_mod(dev); - td->dev = dev; - td->mod = mod; - td->cd = module_get_private_data(mod); - td->sink = create_test_sink(dev, 0, 0, 0, 4); - - *state = td; - return 0; -} - -static int teardown_test_case(void **state) -{ - struct test_data *td = *state; - - free_test_sink(td->sink); - comp_free(td->dev); - test_free(td); - - return 0; -} - -#if CONFIG_FORMAT_FLOAT -static void test_mux_get_processing_function_valid_float(void **state) -{ - struct test_data *td = *state; - mux_func func = NULL; - - audio_stream_set_frm_fmt(&td->sink->stream, SOF_IPC_FRAME_FLOAT); - - func = mux_get_processing_function(td->mod); - - assert_ptr_not_equal(func, NULL); -} -#endif /* CONFIG_FORMAT_FLOAT */ - -static void test_mux_get_processing_function_invalid_format(void **state) -{ - struct test_data *td = *state; - mux_func func = NULL; - - /* set frame format value to unsupported value */ - audio_stream_set_frm_fmt(&td->sink->stream, SOF_IPC_FRAME_INVALID); - - func = mux_get_processing_function(td->mod); - - assert_ptr_equal(func, NULL); -} - -#if CONFIG_FORMAT_S16LE -static void test_mux_get_processing_function_valid_s16le(void **state) -{ - struct test_data *td = *state; - mux_func func = NULL; - - audio_stream_set_frm_fmt(&td->sink->stream, SOF_IPC_FRAME_S16_LE); - - func = mux_get_processing_function(td->mod); - - assert_ptr_not_equal(func, NULL); -} -#endif /* CONFIG_FORMAT_S16LE */ - -#if CONFIG_FORMAT_S24LE -static void test_mux_get_processing_function_valid_s24_4le(void **state) -{ - struct test_data *td = *state; - mux_func func = NULL; - - audio_stream_set_frm_fmt(&td->sink->stream, SOF_IPC_FRAME_S24_4LE); - - func = mux_get_processing_function(td->mod); - - assert_ptr_not_equal(func, NULL); -} -#endif /* CONFIG_FORMAT_S24LE */ - -#if CONFIG_FORMAT_S32LE -static void test_mux_get_processing_function_valid_s32le(void **state) -{ - struct test_data *td = *state; - mux_func func = NULL; - - audio_stream_set_frm_fmt(&td->sink->stream, SOF_IPC_FRAME_S32_LE); - - func = mux_get_processing_function(td->mod); - - assert_ptr_not_equal(func, NULL); -} -#endif /* CONFIG_FORMAT_S32LE */ - -#define TEST_CASE(name) \ - cmocka_unit_test_setup_teardown(name, \ - setup_test_case, \ - teardown_test_case) - -int main(void) -{ - const struct CMUnitTest tests[] = { -#if CONFIG_FORMAT_FLOAT - TEST_CASE(test_mux_get_processing_function_valid_float), -#endif /* CONFIG_FORMAT_FLOAT */ - TEST_CASE(test_mux_get_processing_function_invalid_format), -#if CONFIG_FORMAT_S16LE - TEST_CASE(test_mux_get_processing_function_valid_s16le), -#endif /* CONFIG_FORMAT_S16LE */ -#if CONFIG_FORMAT_S24LE - TEST_CASE(test_mux_get_processing_function_valid_s24_4le), -#endif /* CONFIG_FORMAT_S24LE */ -#if CONFIG_FORMAT_S32LE - TEST_CASE(test_mux_get_processing_function_valid_s32le), -#endif /* CONFIG_FORMAT_S32LE */ - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, setup_group, NULL); -} diff --git a/test/cmocka/src/audio/pcm_converter/CMakeLists.txt b/test/cmocka/src/audio/pcm_converter/CMakeLists.txt deleted file mode 100644 index ee72311e004b..000000000000 --- a/test/cmocka/src/audio/pcm_converter/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -if(CONFIG_FORMAT_FLOAT) - cmocka_test(pcm_float_generic - pcm_float.c - ${PROJECT_SOURCE_DIR}/src/math/numbers.c - ${PROJECT_SOURCE_DIR}/src/audio/pcm_converter/pcm_converter.c - ${PROJECT_SOURCE_DIR}/src/audio/pcm_converter/pcm_converter_generic.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/audio/component.c - ${PROJECT_SOURCE_DIR}/src/audio/data_blob.c - ${PROJECT_SOURCE_DIR}/src/module/audio/source_api.c - ${PROJECT_SOURCE_DIR}/src/module/audio/sink_api.c - ${PROJECT_SOURCE_DIR}/src/kernel/ipc/ipc3/helper.c - ${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.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 - ) - target_include_directories(pcm_float_generic PRIVATE ${PROJECT_SOURCE_DIR}/src/include) - target_compile_definitions(pcm_float_generic PRIVATE PCM_CONVERTER_GENERIC) - target_link_libraries(pcm_float_generic PRIVATE sof_options) -endif() diff --git a/test/cmocka/src/audio/pcm_converter/pcm_float.c b/test/cmocka/src/audio/pcm_converter/pcm_float.c deleted file mode 100644 index 0fed36a98774..000000000000 --- a/test/cmocka/src/audio/pcm_converter/pcm_float.c +++ /dev/null @@ -1,562 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Karol Trzcinski - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_MALLOC_H -#include -#else -#include -#endif - -#include "../../util.h" - -/* used during float assertions */ -#define EPSILON 0.01f - -/* base number to check combinations for each data format */ -#define PCM_TEST_INT_NUMBERS \ - -0, 0, 0, 0, -1, 1, -2, 2, \ - -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -25, 25, -57, 57, -100, 100 -#define PCM_TEST_FLOAT_NUMBERS \ - -0, 0, 0.1, -0.1f, -0.8f, 0.8f, -1.9f, 1.9f, \ - -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -25, 25, -57, 57, -100, 100 - -/* generate biggest signed value on a 24 bits number */ -#define INT24_MAX ((1 << (24 - 1)) - 1) - -/* generate smallest signed value on a 24 bits number */ -#define INT24_MIN (-INT24_MAX - 1) - -/* conversion ration */ -const float ratio16 = 1.f / (1u << 15); -const float ratio24 = 1.f / (1u << 23); -const float ratio32 = 1.f / (1u << 31); - -/* - * Function design to help debugging conversion between fixed and float numbers. - * - * Usage: - * add declaration of this function for example to pcm_converter_generic.c - * And feel free to use pcm_float_print_values in functions like - * _pcm_convert_i_to_f or _pcm_convert_f_to_i during debugging - * - * param it int number to show - * param fl pointer to float number to show - * param ex expected number - */ -static void pcm_float_print_values(int32_t it, int32_t *fl, double ep, - const char *func_name) -{ - const int32_t mantissa_mask = (1 << 23) - 1; - int32_t ex = ((*fl >> 23) & 0xFF) - 127; - int32_t mt = *fl & mantissa_mask; - float mantissa_value = mt * (1.0f / mantissa_mask) + 1.f; - - print_message("%s: 0x%08Xf => %.3f * 2**%3d = %10.3e f <=> %7d d \t(expected: %10.3e)\n", - func_name, *fl, mantissa_value, ex, *((float *)fl), it, - ep); -} - -static struct comp_buffer *_test_pcm_convert(enum sof_ipc_frame frm_in, enum sof_ipc_frame frm_out, - int samples, const void *data) -{ - /* create buffers - output buffer may be too big for test */ - struct comp_buffer *source; - struct comp_buffer *sink; - pcm_converter_func fun; - const uint8_t fillval = 0xAB; - const int inbytes = samples * get_sample_bytes(frm_in); - const int outbytes = (samples + 1) * get_sample_bytes(frm_out); - - /* create buffers */ - source = create_test_source(NULL, 0, frm_in, 1, inbytes); - sink = create_test_sink(NULL, 0, frm_out, 1, outbytes); - - /* fill source */ - memcpy_s(source->stream.w_ptr, source->stream.size, data, inbytes); - audio_stream_produce(&source->stream, inbytes); - - /* fill sink memory - to validate last value */ - memset(sink->stream.w_ptr, fillval, outbytes); - - /* run conversion */ - fun = pcm_get_conversion_function(frm_in, frm_out); - assert_non_null(fun); - - struct cir_buf_source cir_src = { - .buf_start = source->stream.addr, - .buf_end = source->stream.end_addr, - .ptr = source->stream.r_ptr, - }; - struct cir_buf_sink cir_snk = { - .buf_start = sink->stream.addr, - .buf_end = sink->stream.end_addr, - .ptr = sink->stream.w_ptr, - }; - - fun(&cir_src, audio_stream_get_channels(&source->stream), - &cir_snk, audio_stream_get_channels(&sink->stream), samples, DUMMY_CHMAP); - - /* assert last value in sink is untouched */ - assert_int_equal(((uint8_t *)sink->stream.w_ptr)[outbytes - 1], fillval); - - /* free source and return sink */ - free_test_source(source); - return sink; -} - -static void mask_array(int32_t mask, int32_t *parray, int cnt) -{ - assert_non_null(parray); - while (cnt--) - parray[cnt] &= mask; -} - -static void scale_array(float ratio, float *parray, int cnt) -{ - assert_non_null(parray); - while (cnt--) - parray[cnt] *= ratio; -} - -#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S16LE -static void test_pcm_convert_s16_to_f(void **state) -{ - typedef int16_t Tin; - typedef float Tout; - static const Tin source_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - }; - static Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio16, expected_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_S16_LE, SOF_IPC_FRAME_FLOAT, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(source_buf[i], (int32_t *)read_val, - expected_buf[i], __func__); - assert_float_equal(*read_val, expected_buf[i], EPSILON); - } - - /* free memory */ - free_test_sink(sink); -} - -static void test_pcm_convert_f_to_s16(void **state) -{ - typedef float Tin; - typedef int16_t Tout; - static Tin source_buf[] = { - PCM_TEST_FLOAT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - }; - static const Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio16, source_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S16_LE, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(*read_val, (int32_t *)&source_buf[i], - (float)expected_buf[i], __func__); - assert_int_equal(*read_val, expected_buf[i]); - } - - /* free memory */ - free_test_sink(sink); -} -#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S16LE */ - -#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S24LE -static void test_pcm_convert_s24_in_s32_to_f(void **state) -{ - typedef int32_t Tin; - typedef float Tout; - static const Tin source_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - }; - static Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio24, expected_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_S24_4LE, SOF_IPC_FRAME_FLOAT, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(source_buf[i], (int32_t *)read_val, - expected_buf[i], __func__); - assert_float_equal(*read_val, expected_buf[i], EPSILON); - } - - /* free memory */ - free_test_sink(sink); -} - -static void test_pcm_convert_s24_to_f(void **state) -{ - typedef int32_t Tin; - typedef float Tout; - static Tin source_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - }; - static Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - mask_array(MASK(24, 0), source_buf, N); - scale_array(ratio24, expected_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_S24_4LE, SOF_IPC_FRAME_FLOAT, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(sign_extend_s24(source_buf[i]), - (int32_t *)read_val, expected_buf[i], - __func__); - assert_float_equal(*read_val, expected_buf[i], EPSILON); - } - - /* free memory */ - free_test_sink(sink); -} - -static void test_pcm_convert_f_to_s24(void **state) -{ - typedef float Tin; - typedef int32_t Tout; - static Tin source_buf[] = { - PCM_TEST_FLOAT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - INT24_MIN - 1, INT24_MAX + 1, - }; - static const Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - INT24_MIN, INT24_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio24, source_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S24_4LE, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(*read_val, (int32_t *)&source_buf[i], - (float)expected_buf[i], __func__); - assert_int_equal(*read_val, expected_buf[i]); - } - - /* free memory */ - free_test_sink(sink); -} -#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S24LE */ - -#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S32LE -#define S24TOS32MULT (1 << (32 - 24)) -static void test_pcm_convert_s32_to_f(void **state) -{ - typedef int32_t Tin; - typedef float Tout; - - static const Tin source_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - INT32_MIN + 1, INT32_MIN, - INT32_MAX - 1, INT32_MAX, - }; - static Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - INT24_MIN*S24TOS32MULT, INT24_MIN * S24TOS32MULT, - INT24_MAX*S24TOS32MULT, INT24_MAX * S24TOS32MULT, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio32, expected_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_FLOAT, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(source_buf[i], (int32_t *)read_val, - expected_buf[i], __func__); - assert_float_equal(*read_val, expected_buf[i], EPSILON); - } - - /* free memory */ - free_test_sink(sink); -} - -static void test_pcm_convert_f_to_s32(void **state) -{ - typedef float Tin; - typedef int32_t Tout; - static Tin source_buf[] = { - PCM_TEST_FLOAT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - }; - static const Tout expected_buf[] = { - PCM_TEST_INT_NUMBERS, - INT16_MIN + 1, INT16_MIN, - INT16_MAX - 1, INT16_MAX, - INT24_MIN + 1, INT24_MIN, - INT24_MAX - 1, INT24_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio32, source_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S32_LE, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(*read_val, (int32_t *)&source_buf[i], - (float)expected_buf[i], __func__); - assert_int_equal(*read_val, expected_buf[i]); - } - - /* free memory */ - free_test_sink(sink); -} - -static void test_pcm_convert_f_to_s32_big_neg(void **state) -{ - typedef float Tin; - typedef int32_t Tout; - static Tin source_buf[] = { - INT24_MIN - 127, INT24_MIN - 128, /* 24B mantissa trimming */ - INT32_MIN + 1, INT32_MIN, /* 24B mantissa trimming */ - INT32_MIN * 2.f, INT32_MIN * 10.f, - -INFINITY - }; - static const Tout expected_buf[] = { - INT24_MIN - 127, INT24_MIN - 128, - INT32_MIN + 1, INT32_MIN, - INT32_MIN, INT32_MIN, - INT32_MIN - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio32, source_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S32_LE, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(*read_val, (int32_t *)&source_buf[i], - (float)expected_buf[i], __func__); - /* assert as float because of possible rounding effects */ - assert_float_equal(*read_val, expected_buf[i], 1); - } - - /* free memory */ - free_test_sink(sink); -} - -static void test_pcm_convert_f_to_s32_big_pos(void **state) -{ - typedef float Tin; - typedef int32_t Tout; - static Tin source_buf[] = { - INT24_MAX + 127, INT24_MAX + 128, - INT32_MAX - 255, INT32_MAX - 127, - INT32_MAX - 1, INT32_MAX, - INT32_MAX * 2.f, INT32_MAX * 10.f, - INFINITY, - }; - /* remember about 24B mantissa trimming */ - static const Tout expected_buf[] = { - INT24_MAX + 127, INT24_MAX + 128, - INT32_MAX - 254, INT32_MAX - 126, - INT32_MAX - 1, INT32_MAX, - INT32_MAX, INT32_MAX, - INT32_MAX, - }; - - struct comp_buffer *sink; - int i, N = ARRAY_SIZE(source_buf); - Tout *read_val; - - assert_int_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); - scale_array(ratio32, source_buf, N); - - /* run test */ - sink = _test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S32_LE, - N, source_buf); - - /* check results */ - for (i = 0; i < N; ++i) { - read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); - print_message("%2d/%02d ", i + 1, N); - pcm_float_print_values(*read_val, (int32_t *)&source_buf[i], - (float)expected_buf[i], __func__); - /* assert as float because of possible rounding effects */ - assert_float_equal(*read_val, expected_buf[i], 1); - } - - /* free memory */ - free_test_sink(sink); -} -#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S32LE */ - -int main(void) -{ - const struct CMUnitTest tests[] = { -#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S16LE - cmocka_unit_test(test_pcm_convert_s16_to_f), - cmocka_unit_test(test_pcm_convert_f_to_s16), -#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S16LE */ -#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S24LE - cmocka_unit_test(test_pcm_convert_s24_to_f), - cmocka_unit_test(test_pcm_convert_s24_in_s32_to_f), - cmocka_unit_test(test_pcm_convert_f_to_s24), -#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S24LE */ -#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S32LE - cmocka_unit_test(test_pcm_convert_s32_to_f), - cmocka_unit_test(test_pcm_convert_f_to_s32), - cmocka_unit_test(test_pcm_convert_f_to_s32_big_neg), - cmocka_unit_test(test_pcm_convert_f_to_s32_big_pos), -#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S32LE */ - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - /* log number of converting functions for current configuration */ - print_message("%s start tests, count(pcm_func_map)=%zu\n", - __FILE__, pcm_func_count); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/lib/CMakeLists.txt b/test/cmocka/src/lib/CMakeLists.txt deleted file mode 100644 index ad3788bc98f0..000000000000 --- a/test/cmocka/src/lib/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -add_subdirectory(alloc) -add_subdirectory(lib) -add_subdirectory(fast-get) diff --git a/test/cmocka/src/lib/alloc/CMakeLists.txt b/test/cmocka/src/lib/alloc/CMakeLists.txt deleted file mode 100644 index 5e899d3955af..000000000000 --- a/test/cmocka/src/lib/alloc/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(alloc - alloc.c - ${PROJECT_SOURCE_DIR}/src/lib/alloc.c - ${PROJECT_SOURCE_DIR}/src/kernel/platform/library/lib/memory.c -) - -target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/kernel/platform/intel/cavs/include) -target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/platform/intel/cavs/include) diff --git a/test/cmocka/src/lib/alloc/alloc.c b/test/cmocka/src/lib/alloc/alloc.c deleted file mode 100644 index d666141c45b2..000000000000 --- a/test/cmocka/src/lib/alloc/alloc.c +++ /dev/null @@ -1,299 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Slawomir Blauciak - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -enum test_type { - TEST_BULK = 0, - TEST_ZERO, - TEST_IMMEDIATE_FREE -}; - -struct test_case { - size_t alloc_size; - uint32_t alloc_flags; - uint16_t alloc_num; - enum test_type type; - const char *name; -}; - -#define TEST_CASE(bytes, flags, num, type, name_base) \ - {(bytes), (flags), (num), (type), \ - ("test_lib_alloc_" name_base "__" #flags "__" #bytes "x" #num)} - -static struct test_case test_cases[] = { - /* - * rmalloc tests - */ - - TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_BULK, - "rmalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_BULK, - "rmalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_BULK, - "rmalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_BULK, - "rmalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_BULK, - "rmalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_BULK, - "rmalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_BULK, - "rmalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_BULK, - "rmalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_BULK, - "rmalloc"), - - TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_BULK, - "rmalloc"), - - /* - * TODO: Due to recent changes in relation to multicore support - * the RZONE_BUFFER and RZONE_RUNTIME tests will not work. - */ - - TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_BULK, - "rmalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_BULK, - "rmalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_BULK, - "rmalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_BULK, - "rmalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_BULK, - "rmalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_BULK, - "rmalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_BULK, - "rmalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_BULK, - "rmalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_BULK, - "rmalloc"), - - TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_BULK, - "rmalloc"), - - TEST_CASE(1, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), - 2, TEST_BULK, "rmalloc_dma"), - TEST_CASE(4, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), - 2, TEST_BULK, "rmalloc_dma"), - TEST_CASE(256, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), - 2, TEST_BULK, "rmalloc_dma"), - - /* - * rzalloc tests - */ - - TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_ZERO, - "rzalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_ZERO, - "rzalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_ZERO, - "rzalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_ZERO, - "rzalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_ZERO, - "rzalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_ZERO, - "rzalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_ZERO, - "rzalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_ZERO, - "rzalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_ZERO, - "rzalloc"), - - TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_ZERO, - "rzalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_ZERO, - "rzalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_ZERO, - "rzalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_ZERO, - "rzalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_ZERO, - "rzalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_ZERO, - "rzalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_ZERO, - "rzalloc"), - - TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_ZERO, - "rzalloc"), - TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_ZERO, - "rzalloc"), - TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_ZERO, - "rzalloc"), - - TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_ZERO, - "rzalloc"), - - TEST_CASE(1, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), - 2, TEST_ZERO, "rzalloc_dma"), - TEST_CASE(4, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), - 2, TEST_ZERO, "rzalloc_dma"), - TEST_CASE(256, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), - 2, TEST_ZERO, "rzalloc_dma"), -}; - -static int setup(void **state) -{ - platform_init_memmap(sof_get()); - init_heap(sof_get()); - - return 0; -} - -static int teardown(void **state) -{ - return 0; -} - -static int clear_sys(void **state) -{ - struct mm *memmap = memmap_get(); - int sysheap_idx = 0; - - for (; sysheap_idx < ARRAY_SIZE(memmap->system); ++sysheap_idx) { - struct mm_heap *cpu_heap = &memmap->system[sysheap_idx]; - - cpu_heap->info.used = 0; - cpu_heap->info.free = cpu_heap->size; - } - - return 0; -} - -static void *alloc(struct test_case *tc) -{ - void *mem; - - mem = rmalloc(tc->alloc_flags, - tc->alloc_size); - - return mem; -} - -static void alloc_free(void **mem, struct test_case *tc) -{ - int i; - - for (i = 0; i < tc->alloc_num; ++i) - rfree(mem[i]); -} - -static void test_lib_alloc_bulk_free(struct test_case *tc) -{ - void **all_mem = malloc(sizeof(void *) * tc->alloc_num); - int i; - - for (i = 0; i < tc->alloc_num; ++i) { - void *mem = alloc(tc); - - assert_non_null(mem); - all_mem[i] = mem; - } - - alloc_free(all_mem, tc); - - free(all_mem); -} - -static void test_lib_alloc_immediate_free(struct test_case *tc) -{ - int i; - - for (i = 0; i < tc->alloc_num; ++i) { - void *mem = alloc(tc); - - assert_non_null(mem); - rfree(mem); - } -} - -static void test_lib_alloc_zero(struct test_case *tc) -{ - void **all_mem = malloc(sizeof(void *) * tc->alloc_num); - int i; - - for (i = 0; i < tc->alloc_num; ++i) { - char *mem = rzalloc(tc->alloc_flags, - tc->alloc_size); - int j; - - assert_non_null(mem); - all_mem[i] = mem; - - for (j = 0; j < tc->alloc_size; ++j) - assert_int_equal(mem[j], 0); - } - - alloc_free(all_mem, tc); - - free(all_mem); -} - -static void test_lib_alloc(void **state) -{ - struct test_case *tc = *((struct test_case **)state); - - switch (tc->type) { - case TEST_BULK: - test_lib_alloc_bulk_free(tc); - break; - - case TEST_ZERO: - test_lib_alloc_zero(tc); - break; - - case TEST_IMMEDIATE_FREE: - test_lib_alloc_immediate_free(tc); - break; - } -} - -int main(void) -{ - struct CMUnitTest tests[ARRAY_SIZE(test_cases)]; - - int i; - - for (i = 0; i < ARRAY_SIZE(test_cases); ++i) { - struct CMUnitTest *t = &tests[i]; - - t->name = test_cases[i].name; - t->test_func = test_lib_alloc; - t->initial_state = &test_cases[i]; - t->setup_func = clear_sys; - t->teardown_func = NULL; - } - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, setup, teardown); -} diff --git a/test/cmocka/src/lib/fast-get/CMakeLists.txt b/test/cmocka/src/lib/fast-get/CMakeLists.txt deleted file mode 100644 index cf542366bcce..000000000000 --- a/test/cmocka/src/lib/fast-get/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(fast-get-tests - fast-get-tests.c - ${PROJECT_SOURCE_DIR}/src/lib/objpool.c - ${PROJECT_SOURCE_DIR}/zephyr/lib/fast-get.c - ${PROJECT_SOURCE_DIR}/src/lib/alloc.c - ${PROJECT_SOURCE_DIR}/src/kernel/platform/library/lib/memory.c -) - -target_link_libraries(fast-get-tests PRIVATE "-Wl,--wrap=rzalloc,--wrap=rmalloc,--wrap=rfree") diff --git a/test/cmocka/src/lib/fast-get/fast-get-tests.c b/test/cmocka/src/lib/fast-get/fast-get-tests.c deleted file mode 100644 index bd4a6fedfea3..000000000000 --- a/test/cmocka/src/lib/fast-get/fast-get-tests.c +++ /dev/null @@ -1,192 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2024 Intel Corporation. All rights reserved. -// -// Author: Jyri Sarha - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static const int testdata[33][100] = { - { - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 9, 0, - }, - { 2 }, - { 3 }, - { 4 }, - { 5 }, - { 6 }, - { 7 }, - { 8 }, - { 9 }, - { 10 }, - { 11 }, - { 12 }, - { 13 }, - { 14 }, - { 15 }, - { 16 }, - { 17 }, - { 18 }, - { 19 }, - { 20 }, - { 21 }, - { 23 }, - { 24 }, - { 25 }, - { 26 }, - { 27 }, - { 28 }, - { 29 }, - { 30 }, - { 31 }, - { 32 }, - { 33 }, -}; - -static void test_simple_fast_get_put(void **state) -{ - const void *ret; - - (void)state; /* unused */ - - ret = fast_get(NULL, testdata[0], sizeof(testdata[0])); - - assert(ret); - assert(!memcmp(ret, testdata[0], sizeof(testdata[0]))); - - fast_put(NULL, NULL, ret); -} - -static void test_fast_get_size_missmatch_test(void **state) -{ - const void *ret[2]; - - (void)state; /* unused */ - - ret[0] = fast_get(NULL, testdata[0], sizeof(testdata[0])); - - assert(ret[0]); - assert(!memcmp(ret[0], testdata[0], sizeof(testdata[0]))); - - ret[1] = fast_get(NULL, testdata[0], sizeof(testdata[0]) + 1); - assert(!ret[1]); - - fast_put(NULL, NULL, ret); -} - -static void test_over_32_fast_gets_and_puts(void **state) -{ - const void *copy[ARRAY_SIZE(testdata)]; - int i; - - (void)state; /* unused */ - - for (i = 0; i < ARRAY_SIZE(copy); i++) - copy[i] = fast_get(NULL, testdata[i], sizeof(testdata[0])); - - for (i = 0; i < ARRAY_SIZE(copy); i++) - assert(!memcmp(copy[i], testdata[i], sizeof(testdata[0]))); - - for (i = 0; i < ARRAY_SIZE(copy); i++) - fast_put(NULL, NULL, copy[i]); -} - -static void test_fast_get_refcounting(void **state) -{ - const void *copy[2][ARRAY_SIZE(testdata)]; - int i; - (void)state; /* unused */ - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - copy[0][i] = fast_get(NULL, testdata[i], sizeof(testdata[0])); - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - copy[1][i] = fast_get(NULL, testdata[i], sizeof(testdata[0])); - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - assert(copy[0][i] == copy[1][i]); - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - assert(!memcmp(copy[0][i], testdata[i], sizeof(testdata[0]))); - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - fast_put(NULL, NULL, copy[0][i]); - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - assert(!memcmp(copy[1][i], testdata[i], sizeof(testdata[0]))); - - for (i = 0; i < ARRAY_SIZE(copy[0]); i++) - fast_put(NULL, NULL, copy[1][i]); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_simple_fast_get_put), - cmocka_unit_test(test_fast_get_size_missmatch_test), - cmocka_unit_test(test_over_32_fast_gets_and_puts), - cmocka_unit_test(test_fast_get_refcounting), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} - -void *__wrap_rzalloc(uint32_t flags, size_t bytes); -void *__wrap_rmalloc(uint32_t flags, size_t bytes); -void __wrap_rfree(void *ptr); - -void *__wrap_rzalloc(uint32_t flags, size_t bytes) -{ - void *ret; - (void)flags; - - ret = malloc(bytes); - - assert(ret); - - memset(ret, 0, bytes); - - return ret; -} - -void *__wrap_rmalloc(uint32_t flags, size_t bytes) -{ - void *ret; - (void)flags; - - ret = malloc(bytes); - - assert(ret); - - return ret; -} - -void __wrap_rfree(void *ptr) -{ - free(ptr); -} diff --git a/test/cmocka/src/lib/lib/CMakeLists.txt b/test/cmocka/src/lib/lib/CMakeLists.txt deleted file mode 100644 index 1287a1d14f94..000000000000 --- a/test/cmocka/src/lib/lib/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(rstrcmp - rstrcmp.c - ${PROJECT_SOURCE_DIR}/src/lib/lib.c -) - -cmocka_test(rstrlen - rstrlen.c - ${PROJECT_SOURCE_DIR}/src/lib/lib.c -) diff --git a/test/cmocka/src/lib/lib/rstrcmp.c b/test/cmocka/src/lib/lib/rstrcmp.c deleted file mode 100644 index 8cde07bcd4a6..000000000000 --- a/test/cmocka/src/lib/lib/rstrcmp.c +++ /dev/null @@ -1,222 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Michal Jerzy Wierzbicki - -#include - -#include -#include -#include -#include - -static void test_lib_lib_rstrcmp_for_a_and_a_equals_0(void **state) -{ - int r; - const char *str1 = "a"; - const char *str2 = "a"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrcmp_for_a_and_b_is_negative(void **state) -{ - int r; - const char *str1 = "a"; - const char *str2 = "b"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_true(r < 0); -} - -static void test_lib_lib_rstrcmp_for_b_and_a_is_positive(void **state) -{ - int r; - const char *str1 = "b"; - const char *str2 = "a"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_true(r > 0); -} - -static void test_lib_lib_rstrcmp_for_empty_and_null_str_equals_0(void **state) -{ - int r; - const char *str1 = ""; - const char *str2 = "\0"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrcmp_for_abc_and_abcd_is_negative(void **state) -{ - int r; - const char *str1 = "abc"; - const char *str2 = "abcd"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_true(r < 0); -} - -static void test_lib_lib_rstrcmp_for_abcd_and_abc_is_positive(void **state) -{ - int r; - const char *str1 = "abcd"; - const char *str2 = "abc"; - - (void) state; - - r = rstrcmp(str1, str2); - - assert_true(r > 0); -} - -static void test_lib_lib_rstrcmp_for_abc_and_aBc_is_positive(void **state) -{ - int r; - const char *str1 = "abc"; - const char *str2 = "aBc"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_true(r > 0); -} - -static void test_lib_lib_rstrcmp_for_same_multinull_equals_0(void **state) -{ - int r; - const char *str1 = "Lorem\0Ipsum\0"; - const char *str2 = "Lorem\0Ipsum\0"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrcmp_for_diff_after_null_equals_0(void **state) -{ - int r; - const char *str1 = "Lorem\0Ipsum\0"; - const char *str2 = "Lorem\0IPzum\0"; - - (void) state; - - r = rstrcmp(str1, str2); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrcmp_for_verylongstrings_equals_0(void **state) -{ - int r; - int i; - const int size = 2048; - char str1[size+1]; - char str2[size+1]; - - for (i = 0; i < size; ++i) { - str1[i] = 'a'; - str2[i] = 'a'; - } - str1[size] = 0; - str2[size] = 0; - - (void) state; - - r = rstrcmp(str1, str2); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrcmp_for_verylongstrings_is_positive(void **state) -{ - int r; - int i; - const int size = 2048; - char str1[size+1]; - char str2[size+1]; - - for (i = 0; i < size-1; ++i) { - str1[i] = 'a'; - str2[i] = 'a'; - } - str1[size-1] = 'a'; - str2[size-1] = 'A'; - str1[size] = 0; - str2[size] = 0; - - (void) state; - - r = rstrcmp(str1, str2); - assert_true(r > 0); -} - -static void test_lib_lib_rstrcmp_for_verylongstrings_is_negative(void **state) -{ - int r; - int i; - const int size = 2048; - char str1[size+1]; - char str2[size+1]; - - for (i = 0; i < size-1; ++i) { - str1[i] = 'a'; - str2[i] = 'a'; - } - str1[size-1] = 'A'; - str2[size-1] = 'a'; - str1[size] = 0; - str2[size] = 0; - - (void) state; - - r = rstrcmp(str1, str2); - assert_true(r < 0); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test( - test_lib_lib_rstrcmp_for_a_and_a_equals_0), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_a_and_b_is_negative), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_b_and_a_is_positive), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_empty_and_null_str_equals_0), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_abc_and_abcd_is_negative), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_abcd_and_abc_is_positive), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_abc_and_aBc_is_positive), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_same_multinull_equals_0), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_diff_after_null_equals_0), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_verylongstrings_equals_0), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_verylongstrings_is_positive), - cmocka_unit_test( - test_lib_lib_rstrcmp_for_verylongstrings_is_negative), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/lib/lib/rstrlen.c b/test/cmocka/src/lib/lib/rstrlen.c deleted file mode 100644 index 71e9cf8b6248..000000000000 --- a/test/cmocka/src/lib/lib/rstrlen.c +++ /dev/null @@ -1,105 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Michal Jerzy Wierzbicki - -#include - -#include -#include -#include -#include - -static void test_lib_lib_rstrlen_for_empty_str_equals_0(void **state) -{ - int r; - const char *str = ""; - - (void)state; - - r = rstrlen(str); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrlen_for_null_str_equals_0(void **state) -{ - int r; - const char *str = "\0"; - - (void)state; - - r = rstrlen(str); - assert_int_equal(r, 0); -} - -static void test_lib_lib_rstrlen_for_a_equals_1(void **state) -{ - int r; - const char *str = "a"; - - (void)state; - - r = rstrlen(str); - assert_int_equal(r, 1); -} - -static void test_lib_lib_rstrlen_for_abcd_equals_4(void **state) -{ - int r; - const char *str = "abcd"; - - (void)state; - - r = rstrlen(str); - assert_int_equal(r, 4); -} - -static void test_lib_lib_rstrlen_for_verylongstr(void **state) -{ - int r; - int i; - const int size = 2048; - char str[size + 1]; - - for (i = 0; i < size; ++i) - str[i] = 'a'; - str[size] = 0; - - (void)state; - - r = rstrlen(str); - assert_int_equal(r, size); -} - -static void test_lib_lib_rstrlen_for_multiple_nulls_equals_5(void **state) -{ - int r; - const char *str = "Lorem\0Ipsum\0"; - - (void)state; - - r = rstrlen(str); - assert_int_equal(r, 5); -} - -int main(void) -{ - #define c_u_t(x) cmocka_unit_test(x) - // CHECK: Avoid CamelCase: - #define c_m_unit_test CMUnitTest - const struct c_m_unit_test tests[] = { - c_u_t(test_lib_lib_rstrlen_for_empty_str_equals_0), - c_u_t(test_lib_lib_rstrlen_for_null_str_equals_0), - c_u_t(test_lib_lib_rstrlen_for_a_equals_1), - c_u_t(test_lib_lib_rstrlen_for_abcd_equals_4), - c_u_t(test_lib_lib_rstrlen_for_verylongstr), - c_u_t(test_lib_lib_rstrlen_for_multiple_nulls_equals_5), - }; - #undef c_m_unit_test - #undef c_u_t - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/cmocka/src/math/CMakeLists.txt b/test/cmocka/src/math/CMakeLists.txt deleted file mode 100644 index 63fee59d926c..000000000000 --- a/test/cmocka/src/math/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -add_subdirectory(fft) diff --git a/test/cmocka/src/math/fft/CMakeLists.txt b/test/cmocka/src/math/fft/CMakeLists.txt deleted file mode 100644 index c481c7e9afee..000000000000 --- a/test/cmocka/src/math/fft/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause - -cmocka_test(dft3 - dft3.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_32.c - ${PROJECT_SOURCE_DIR}/src/math/fft/fft_common.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/dft3.c b/test/cmocka/src/math/fft/dft3.c deleted file mode 100644 index a787d8329993..000000000000 --- a/test/cmocka/src/math/fft/dft3.c +++ /dev/null @@ -1,96 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2025 Intel Corporation. All rights reserved. -// -// Author: Seppo Ingalsuo - -#include -#include -#include "ref_dft3_32.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SOFM_DFT3_MAX_ERROR_ABS 3.1 -#define SOFM_DFT3_MAX_ERROR_RMS 1.1 -#define DFT_SIZE 3 - -static void dft3_32_test(const int32_t *in_real, const int32_t *in_imag, - const int32_t *ref_real, const int32_t *ref_imag, int num_tests) - -{ - struct icomplex32 x[DFT_SIZE]; - struct icomplex32 y[DFT_SIZE]; - 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; - - for (i = 0; i < num_tests; i++) { - for (j = 0; j < DFT_SIZE; j++) { - x[j].real = *p_in_real++; - x[j].imag = *p_in_imag++; - } - - dft3_32(x, y); - - for (j = 0; j < DFT_SIZE; j++) { - 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++; - } - } - - error_rms = sqrt(sum_squares / (double)(2 * DFT_SIZE * num_tests)); - printf("Max absolute error = %5.2f (max %5.2f), error RMS = %5.2f (max %5.2f)\n", - delta_max, SOFM_DFT3_MAX_ERROR_ABS, error_rms, SOFM_DFT3_MAX_ERROR_RMS); - - assert_true(error_rms < SOFM_DFT3_MAX_ERROR_RMS); - assert_true(delta_max < SOFM_DFT3_MAX_ERROR_ABS); -} - -static void dft3_32_test_1(void **state) -{ - (void)state; - - dft3_32_test(input_data_real_q31, input_data_imag_q31, - ref_data_real_q31, ref_data_imag_q31, - REF_SOFM_DFT3_NUM_TESTS); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(dft3_32_test_1), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/test/ztest/unit/audio/mux/CMakeLists.txt b/test/ztest/unit/audio/mux/CMakeLists.txt new file mode 100644 index 000000000000..3ad1ef96aad1 --- /dev/null +++ b/test/ztest/unit/audio/mux/CMakeLists.txt @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. +# +# MUX and DEMUX component unit tests converted from CMock to Ztest + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(sof_unit_audio_mux) + +set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..") +set(sof_top_dir ${SOF_ROOT}) + +include(${SOF_ROOT}/scripts/cmake/misc.cmake) +include(${SOF_ROOT}/scripts/cmake/uuid-registry.cmake) + +target_include_directories(app PRIVATE + ${SOF_ROOT}/zephyr/include + ${SOF_ROOT}/src/include + ${SOF_ROOT}/src/kernel/include + ${SOF_ROOT}/src/kernel/platform/posix/include + ${SOF_ROOT}/src/platform/posix/include + ${SOF_ROOT}/src/audio + ${PROJECT_BINARY_DIR}/include/generated +) + +target_compile_definitions(app PRIVATE + -DCONFIG_ZEPHYR_POSIX=1 + -DCONFIG_LIBRARY=1 + -DUNIT_TEST=1 +) + +# Keep full ASan/LSan allocation stacks (twister --enable-asan --enable-lsan) +if(CONFIG_ASAN) + target_compile_options(app PRIVATE -fno-omit-frame-pointer) +endif() + +target_sources(app PRIVATE + mux_test_util.c + mux_copy_ztest.c + demux_copy_ztest.c + mux_get_processing_function_ztest.c + ${SOF_ROOT}/test/ztest/unit/common/sof_context.c + ${SOF_ROOT}/zephyr/lib/alloc.c + ${SOF_ROOT}/src/audio/mux/mux.c + ${SOF_ROOT}/src/audio/mux/mux_ipc3.c + ${SOF_ROOT}/src/audio/mux/mux_generic.c + ${SOF_ROOT}/src/audio/module_adapter/module_adapter.c + ${SOF_ROOT}/src/audio/module_adapter/module_adapter_ipc3.c + ${SOF_ROOT}/src/audio/module_adapter/module/generic.c + ${SOF_ROOT}/src/audio/buffers/comp_buffer.c + ${SOF_ROOT}/src/audio/buffers/audio_buffer.c + ${SOF_ROOT}/src/audio/source_api_helper.c + ${SOF_ROOT}/src/audio/sink_api_helper.c + ${SOF_ROOT}/src/audio/sink_source_utils.c + ${SOF_ROOT}/src/audio/audio_stream.c + ${SOF_ROOT}/src/audio/component.c + ${SOF_ROOT}/src/audio/data_blob.c + ${SOF_ROOT}/src/module/audio/source_api.c + ${SOF_ROOT}/src/module/audio/sink_api.c + ${SOF_ROOT}/src/kernel/ipc/ipc3/helper.c + ${SOF_ROOT}/src/ipc/ipc-helper.c + ${SOF_ROOT}/src/lib/objpool.c + ${SOF_ROOT}/src/math/numbers.c +) + +sof_append_relative_path_definitions(app) diff --git a/test/ztest/unit/audio/mux/demux_copy_ztest.c b/test/ztest/unit/audio/mux/demux_copy_ztest.c new file mode 100644 index 000000000000..4837c98e064d --- /dev/null +++ b/test/ztest/unit/audio/mux/demux_copy_ztest.c @@ -0,0 +1,298 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Converted from CMock to Ztest +// Original tests from test/cmocka/src/audio/mux/demux_copy.c: +// Author: Daniel Bogdzia +// Janusz Jankowski + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mux_test_util.h" + +struct demux_copy_test_data { + struct comp_dev *dev; + struct comp_buffer *sinks[MUX_MAX_STREAMS]; + struct comp_buffer *source; + void *outputs[MUX_MAX_STREAMS]; + uint32_t format; + const uint8_t (*mask)[CONFIG_PLATFORM_MAX_CHANNELS]; +}; + +static struct demux_copy_test_data demux_copy_td; + +static const int16_t input_16b[CONFIG_PLATFORM_MAX_CHANNELS] = { + 0x101, 0x102, 0x104, 0x108, + 0x111, 0x112, 0x114, 0x118, +}; + +static const int32_t input_24b[CONFIG_PLATFORM_MAX_CHANNELS] = { + 0x1a1001, 0x2a2002, 0x4a4004, 0x8a8008, + 0x1b1011, 0x2b2012, 0x4b4014, 0x8b8018, +}; + +static const int32_t input_32b[CONFIG_PLATFORM_MAX_CHANNELS] = { + 0xd1a1001, 0xd2a2002, 0xd4a4004, 0xd8a8008, + 0xe1b1011, 0xe2b2012, 0xe4b4014, 0xe8b8018, +}; + +static const uint8_t masks[][MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { + { { 0x01, }, }, + { { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, + { { }, + { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, + { { }, + { }, + { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, + { { }, + { }, + { }, + { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80}, }, + { { 0x01, }, + { 0x00, 0x01, }, + { 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10}, }, + { { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10}, + { 0x00, 0x00, 0x01, }, + { 0x00, 0x01, }, + { 0x01, }, }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x10, 0x08, 0x04, 0x02, 0x01, },}, + { { 0x01, }, + { 0x00, 0x01, }, + { 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x01, },}, +}; + +/** + * @brief Create one sink buffer per stream, on pipeline i. + */ +static void prepare_sinks(struct demux_copy_test_data *td, size_t sample_size) +{ + uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; + int i; + + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + td->sinks[i] = mux_test_create_sink(td->dev, i, td->format, + CONFIG_PLATFORM_MAX_CHANNELS, buffer_size); + + td->outputs[i] = td->sinks[i]->stream.addr; + zassert_equal(audio_stream_get_free_bytes(&td->sinks[i]->stream), buffer_size); + } +} + +/** + * @brief Create the demux source buffer on pipeline MUX_MAX_STREAMS + 1, + * holding one frame of input. + */ +static void prepare_source(struct demux_copy_test_data *td, size_t sample_size) +{ + uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; + + td->source = mux_test_create_source(td->dev, MUX_MAX_STREAMS + 1, td->format, + CONFIG_PLATFORM_MAX_CHANNELS, buffer_size); + + if (td->format == SOF_IPC_FRAME_S16_LE) + memcpy_s(td->source->stream.addr, buffer_size, input_16b, buffer_size); + else if (td->format == SOF_IPC_FRAME_S24_4LE) + memcpy_s(td->source->stream.addr, buffer_size, input_24b, buffer_size); + else + memcpy_s(td->source->stream.addr, buffer_size, input_32b, buffer_size); + + audio_stream_produce(&td->source->stream, buffer_size); + zassert_equal(audio_stream_get_avail_bytes(&td->source->stream), buffer_size); +} + +/** + * @brief Create and prepare a demux with the given format and routing masks. + */ +static void setup_test_case(struct demux_copy_test_data *td, uint32_t format, int mask_index) +{ + const struct sof_uuid uuid = SOF_REG_UUID(demux); + size_t sample_size = format == SOF_IPC_FRAME_S16_LE ? sizeof(int16_t) : sizeof(int32_t); + struct comp_dev *dev; + + td->format = format; + td->mask = masks[mask_index]; + + dev = mux_test_comp_new(&uuid, td->mask); + zassert_not_null(dev, "comp_new() failed"); + td->dev = dev; + + /* Add dummy pipeline to bypass comp_check_eos() */ + dev->pipeline = calloc(1, sizeof(*dev->pipeline)); + zassert_not_null(dev->pipeline); + dev->expect_eos = false; + + prepare_sinks(td, sample_size); + prepare_source(td, sample_size); + + zassert_ok(comp_prepare(td->dev)); +} + +/** + * @brief Free the demux and its buffers, also after a failed test case. + */ +static void demux_copy_after(void *fixture) +{ + struct demux_copy_test_data *td = &demux_copy_td; + int i; + + (void)fixture; + + mux_test_free_source(td->source); + + for (i = 0; i < MUX_MAX_STREAMS; ++i) + mux_test_free_sink(td->sinks[i]); + + if (td->dev) { + free(td->dev->pipeline); + td->dev->pipeline = NULL; + comp_free(td->dev); + } + + memset(td, 0, sizeof(*td)); +} + +/** + * @brief Copy one frame from the source and check every demux output. + * + * Channel j of output stream i takes the input channel k of the last bit k + * set in mask[i][j], or 0 when the mask is 0. + */ +static void test_demux_copy_proc_16(struct demux_copy_test_data *td) +{ + int16_t expected_results[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; + int i, j, k; + + zassert_equal(comp_copy(td->dev), 0); + + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) { + int64_t sample = 0; + + for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) + if (td->mask[i][j] & BIT(k)) + sample = input_16b[k]; + + expected_results[i][j] = sample; + } + } + + for (i = 0; i < MUX_MAX_STREAMS; ++i) + zassert_mem_equal(td->outputs[i], expected_results[i], + sizeof(expected_results[0]), "stream %d", i); +} + +/** @brief S24_4LE variant of test_demux_copy_proc_16(). */ +static void test_demux_copy_proc_24(struct demux_copy_test_data *td) +{ + int32_t expected_results[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; + int i, j, k; + + zassert_equal(comp_copy(td->dev), 0); + + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) { + int32_t sample = 0; + + for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) + if (td->mask[i][j] & BIT(k)) + sample = input_24b[k]; + + expected_results[i][j] = sample; + } + } + + for (i = 0; i < MUX_MAX_STREAMS; ++i) + zassert_mem_equal(td->outputs[i], expected_results[i], + sizeof(expected_results[0]), "stream %d", i); +} + +/** @brief S32_LE variant of test_demux_copy_proc_16(). */ +static void test_demux_copy_proc_32(struct demux_copy_test_data *td) +{ + int32_t expected_results[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS]; + int i, j, k; + + zassert_equal(comp_copy(td->dev), 0); + + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) { + int32_t sample = 0; + + for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) + if (td->mask[i][j] & BIT(k)) + sample = input_32b[k]; + + expected_results[i][j] = sample; + } + } + + for (i = 0; i < MUX_MAX_STREAMS; ++i) + zassert_mem_equal(td->outputs[i], expected_results[i], + sizeof(expected_results[0]), "stream %d", i); +} + +/* + * One test case per format and mask, named like the CMocka cases + * test_demux_copy__mask_. + */ +#define DEMUX_COPY_TEST(fmt_name, fmt, proc, mask_index) \ + ZTEST(demux_copy, test_demux_copy_##fmt_name##_mask_##mask_index) \ + { \ + BUILD_ASSERT(mask_index < ARRAY_SIZE(masks)); \ + setup_test_case(&demux_copy_td, fmt, mask_index); \ + proc(&demux_copy_td); \ + } + +#define DEMUX_COPY_TESTS(fmt_name, fmt, proc) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 0) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 1) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 2) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 3) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 4) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 5) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 6) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 7) \ + DEMUX_COPY_TEST(fmt_name, fmt, proc, 8) + +BUILD_ASSERT(ARRAY_SIZE(masks) == 9, "DEMUX_COPY_TESTS() must cover every mask"); + +#if CONFIG_FORMAT_S16LE +DEMUX_COPY_TESTS(s16le, SOF_IPC_FRAME_S16_LE, test_demux_copy_proc_16) +#endif /* CONFIG_FORMAT_S16LE */ +#if CONFIG_FORMAT_S24LE +DEMUX_COPY_TESTS(s24_4le, SOF_IPC_FRAME_S24_4LE, test_demux_copy_proc_24) +#endif /* CONFIG_FORMAT_S24LE */ +#if CONFIG_FORMAT_S32LE +DEMUX_COPY_TESTS(s32le, SOF_IPC_FRAME_S32_LE, test_demux_copy_proc_32) +#endif /* CONFIG_FORMAT_S32LE */ + +/** + * @brief Register the demux driver for the suite. + */ +static void *demux_copy_setup(void) +{ + sys_comp_init(sof_get()); + sys_comp_module_demux_interface_init(); + + return NULL; +} + +ZTEST_SUITE(demux_copy, NULL, demux_copy_setup, NULL, demux_copy_after, NULL); diff --git a/test/ztest/unit/audio/mux/mux_copy_ztest.c b/test/ztest/unit/audio/mux/mux_copy_ztest.c new file mode 100644 index 000000000000..df17c0367928 --- /dev/null +++ b/test/ztest/unit/audio/mux/mux_copy_ztest.c @@ -0,0 +1,314 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Converted from CMock to Ztest +// Original tests from test/cmocka/src/audio/mux/mux_copy.c: +// Author: Daniel Bogdzia +// Janusz Jankowski + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mux_test_util.h" + +struct mux_copy_test_data { + struct comp_dev *dev; + struct comp_buffer *sources[MUX_MAX_STREAMS]; + struct comp_buffer *sink; + void *output; + uint32_t format; + const uint8_t (*mask)[CONFIG_PLATFORM_MAX_CHANNELS]; +}; + +static struct mux_copy_test_data mux_copy_td; + +static const int16_t input_16b[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { + { 0x101, 0x102, 0x104, 0x108, + 0x111, 0x112, 0x114, 0x118, }, + { 0x201, 0x202, 0x204, 0x208, + 0x211, 0x212, 0x214, 0x218, }, + { 0x301, 0x302, 0x304, 0x308, + 0x311, 0x312, 0x314, 0x318, }, + { 0x401, 0x402, 0x404, 0x408, + 0x411, 0x412, 0x414, 0x418, }, +}; + +static const int32_t input_24b[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { + { 0x1a1001, 0x2a2002, 0x4a4004, 0x8a8008, + 0x1b1011, 0x2b2012, 0x4b4014, 0x8b8018, }, + { 0x1a1101, 0x2a2102, 0x4a4104, 0x8a8108, + 0x1b1111, 0x2b2112, 0x4b4114, 0x8b8118, }, + { 0x1a1201, 0x2a2202, 0x4a4204, 0x8a8208, + 0x1b1211, 0x2b2212, 0x4b4214, 0x8b8218, }, + { 0x1a1401, 0x2a2402, 0x4a4404, 0x8a8408, + 0x1b1411, 0x2b2412, 0x4b4414, 0x8b8418, }, +}; + +static const int32_t input_32b[MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { + { 0xd1a1001, 0xd2a2002, 0xd4a4004, 0xd8a8008, + 0xe1b1011, 0xe2b2012, 0xe4b4014, 0xe8b8018, }, + { 0xd1a1101, 0xd2a2102, 0xd4a4104, 0xd8a8108, + 0xe1b1111, 0xe2b2112, 0xe4b4114, 0xe8b8118, }, + { 0xd1a1201, 0xd2a2202, 0xd4a4204, 0xd8a8208, + 0xe1b1211, 0xe2b2212, 0xe4b4214, 0xe8b8218, }, + { 0xd1a1401, 0xd2a2402, 0xd4a4404, 0xd8a8408, + 0xe1b1411, 0xe2b2412, 0xe4b4414, 0xe8b8418, }, +}; + +static const uint8_t masks[][MUX_MAX_STREAMS][CONFIG_PLATFORM_MAX_CHANNELS] = { + { { 0x01, }, }, + { { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, + { { }, + { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, + { { }, + { }, + { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, + { { }, + { }, + { }, + { 0x01, 0x02, 0x04, 0x10, 0x20, 0x40, 0x80 }, }, + { { 0x01, }, + { 0x00, 0x01, }, + { 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10 }, }, + { { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10 }, + { 0x00, 0x00, 0x01, }, + { 0x00, 0x01, }, + { 0x01, }, }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x10, 0x08, 0x04, 0x02, 0x01, }, }, + { { 0x01, }, + { 0x00, 0x01, }, + { 0x00, 0x00, 0x01, }, + { 0x00, 0x00, 0x00, 0x01, }, }, +}; + +/** + * @brief Create the mux sink buffer on pipeline MUX_MAX_STREAMS + 1. + */ +static void prepare_sink(struct mux_copy_test_data *td, size_t sample_size) +{ + uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; + + td->sink = mux_test_create_sink(td->dev, MUX_MAX_STREAMS + 1, td->format, + CONFIG_PLATFORM_MAX_CHANNELS, buffer_size); + td->output = td->sink->stream.addr; + + zassert_equal(audio_stream_get_free_bytes(&td->sink->stream), buffer_size); +} + +/** + * @brief Create one source buffer per stream, on pipeline i, holding one frame + * of the input of stream i. + */ +static void prepare_sources(struct mux_copy_test_data *td, size_t sample_size) +{ + uint16_t buffer_size = sample_size * CONFIG_PLATFORM_MAX_CHANNELS; + int i; + + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + td->sources[i] = mux_test_create_source(td->dev, i, td->format, + CONFIG_PLATFORM_MAX_CHANNELS, buffer_size); + + if (td->format == SOF_IPC_FRAME_S16_LE) + memcpy_s(td->sources[i]->stream.addr, buffer_size, &input_16b[i], + buffer_size); + else if (td->format == SOF_IPC_FRAME_S24_4LE) + memcpy_s(td->sources[i]->stream.addr, buffer_size, &input_24b[i], + buffer_size); + else + memcpy_s(td->sources[i]->stream.addr, buffer_size, &input_32b[i], + buffer_size); + + audio_stream_produce(&td->sources[i]->stream, buffer_size); + zassert_equal(audio_stream_get_avail_bytes(&td->sources[i]->stream), + buffer_size); + } +} + +/** + * @brief Create and prepare a mux with the given format and routing masks. + */ +static void setup_test_case(struct mux_copy_test_data *td, uint32_t format, int mask_index) +{ + const struct sof_uuid uuid = SOF_REG_UUID(mux); + size_t sample_size = format == SOF_IPC_FRAME_S16_LE ? sizeof(int16_t) : sizeof(int32_t); + struct comp_dev *dev; + + td->format = format; + td->mask = masks[mask_index]; + + dev = mux_test_comp_new(&uuid, td->mask); + zassert_not_null(dev, "comp_new() failed"); + td->dev = dev; + + /* Add dummy pipeline to bypass comp_check_eos() */ + dev->pipeline = calloc(1, sizeof(*dev->pipeline)); + zassert_not_null(dev->pipeline); + dev->expect_eos = false; + + prepare_sink(td, sample_size); + prepare_sources(td, sample_size); + + zassert_ok(comp_prepare(td->dev)); +} + +/** + * @brief Free the mux and its buffers, also after a failed test case. + */ +static void mux_copy_after(void *fixture) +{ + struct mux_copy_test_data *td = &mux_copy_td; + int i; + + (void)fixture; + + for (i = 0; i < MUX_MAX_STREAMS; ++i) + mux_test_free_source(td->sources[i]); + + mux_test_free_sink(td->sink); + + if (td->dev) { + free(td->dev->pipeline); + td->dev->pipeline = NULL; + comp_free(td->dev); + } + + memset(td, 0, sizeof(*td)); +} + +/** + * @brief Copy one frame from every source and check the mux output. + * + * Output channel i takes the sample of the last stream and input channel + * whose mask has bit i set, or 0 when no mask routes to it. + */ +static void test_mux_copy_proc_16(struct mux_copy_test_data *td) +{ + int16_t expected_result[CONFIG_PLATFORM_MAX_CHANNELS]; + int i, j, k; + + zassert_equal(comp_copy(td->dev), 0); + + for (i = 0; i < CONFIG_PLATFORM_MAX_CHANNELS; ++i) { + int32_t sample = 0; + + for (j = 0; j < MUX_MAX_STREAMS; ++j) { + for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) { + if (td->mask[j][k] & BIT(i)) + sample = input_16b[j][k]; + } + } + expected_result[i] = sample; + } + + zassert_mem_equal(td->output, expected_result, sizeof(expected_result)); +} + +/** @brief S24_4LE variant of test_mux_copy_proc_16(). */ +static void test_mux_copy_proc_24(struct mux_copy_test_data *td) +{ + int32_t expected_result[CONFIG_PLATFORM_MAX_CHANNELS]; + int i, j, k; + + zassert_equal(comp_copy(td->dev), 0); + + for (i = 0; i < CONFIG_PLATFORM_MAX_CHANNELS; ++i) { + int32_t sample = 0; + + for (j = 0; j < MUX_MAX_STREAMS; ++j) { + for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) { + if (td->mask[j][k] & BIT(i)) + sample = input_24b[j][k]; + } + } + expected_result[i] = sample; + } + + zassert_mem_equal(td->output, expected_result, sizeof(expected_result)); +} + +/** @brief S32_LE variant of test_mux_copy_proc_16(). */ +static void test_mux_copy_proc_32(struct mux_copy_test_data *td) +{ + int32_t expected_result[CONFIG_PLATFORM_MAX_CHANNELS]; + int i, j, k; + + zassert_equal(comp_copy(td->dev), 0); + + for (i = 0; i < CONFIG_PLATFORM_MAX_CHANNELS; ++i) { + int32_t sample = 0; + + for (j = 0; j < MUX_MAX_STREAMS; ++j) { + for (k = 0; k < CONFIG_PLATFORM_MAX_CHANNELS; ++k) { + if (td->mask[j][k] & BIT(i)) + sample = input_32b[j][k]; + } + } + expected_result[i] = sample; + } + + zassert_mem_equal(td->output, expected_result, sizeof(expected_result)); +} + +/* + * One test case per format and mask, named like the CMocka cases + * test_mux_copy__mask_. + */ +#define MUX_COPY_TEST(fmt_name, fmt, proc, mask_index) \ + ZTEST(mux_copy, test_mux_copy_##fmt_name##_mask_##mask_index) \ + { \ + BUILD_ASSERT(mask_index < ARRAY_SIZE(masks)); \ + setup_test_case(&mux_copy_td, fmt, mask_index); \ + proc(&mux_copy_td); \ + } + +#define MUX_COPY_TESTS(fmt_name, fmt, proc) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 0) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 1) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 2) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 3) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 4) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 5) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 6) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 7) \ + MUX_COPY_TEST(fmt_name, fmt, proc, 8) + +BUILD_ASSERT(ARRAY_SIZE(masks) == 9, "MUX_COPY_TESTS() must cover every mask"); + +#if CONFIG_FORMAT_S16LE +MUX_COPY_TESTS(s16le, SOF_IPC_FRAME_S16_LE, test_mux_copy_proc_16) +#endif /* CONFIG_FORMAT_S16LE */ +#if CONFIG_FORMAT_S24LE +MUX_COPY_TESTS(s24_4le, SOF_IPC_FRAME_S24_4LE, test_mux_copy_proc_24) +#endif /* CONFIG_FORMAT_S24LE */ +#if CONFIG_FORMAT_S32LE +MUX_COPY_TESTS(s32le, SOF_IPC_FRAME_S32_LE, test_mux_copy_proc_32) +#endif /* CONFIG_FORMAT_S32LE */ + +/** + * @brief Register the mux driver for the suite. + */ +static void *mux_copy_setup(void) +{ + sys_comp_init(sof_get()); + sys_comp_module_mux_interface_init(); + + return NULL; +} + +ZTEST_SUITE(mux_copy, NULL, mux_copy_setup, NULL, mux_copy_after, NULL); diff --git a/test/ztest/unit/audio/mux/mux_get_processing_function_ztest.c b/test/ztest/unit/audio/mux/mux_get_processing_function_ztest.c new file mode 100644 index 000000000000..153405811595 --- /dev/null +++ b/test/ztest/unit/audio/mux/mux_get_processing_function_ztest.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Converted from CMock to Ztest +// Original tests from test/cmocka/src/audio/mux/mux_get_processing_function.c: +// Author: Daniel Bogdzia +// Janusz Jankowski + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "mux_test_util.h" + +struct mux_get_processing_function_fixture { + struct comp_dev *dev; + struct processing_module *mod; + struct comp_buffer *sink; +}; + +static struct mux_get_processing_function_fixture mux_gpf_fixture; + +/** + * @brief Register the mux driver for the suite. + */ +static void *mux_get_processing_function_setup(void) +{ + sys_comp_init(sof_get()); + sys_comp_module_mux_interface_init(); + + return &mux_gpf_fixture; +} + +/** + * @brief Create a mux with all zero routing masks and one 4 byte sink buffer. + */ +static void mux_get_processing_function_before(void *data) +{ + struct mux_get_processing_function_fixture *td = data; + const struct sof_uuid uuid = SOF_REG_UUID(mux); + + td->dev = mux_test_comp_new(&uuid, NULL); + zassert_not_null(td->dev, "comp_new() failed"); + + td->mod = comp_mod(td->dev); + td->sink = mux_test_create_sink(td->dev, 0, 0, 0, 4); +} + +/** + * @brief Free the mux and its sink buffer. + */ +static void mux_get_processing_function_after(void *data) +{ + struct mux_get_processing_function_fixture *td = data; + + mux_test_free_sink(td->sink); + if (td->dev) + comp_free(td->dev); + + memset(td, 0, sizeof(*td)); +} + +#if CONFIG_FORMAT_FLOAT +ZTEST_F(mux_get_processing_function, test_mux_get_processing_function_valid_float) +{ + mux_func func = NULL; + + audio_stream_set_frm_fmt(&fixture->sink->stream, SOF_IPC_FRAME_FLOAT); + + func = mux_get_processing_function(fixture->mod); + + zassert_not_null(func); +} +#endif /* CONFIG_FORMAT_FLOAT */ + +ZTEST_F(mux_get_processing_function, test_mux_get_processing_function_invalid_format) +{ + mux_func func = NULL; + + /* set frame format value to unsupported value */ + audio_stream_set_frm_fmt(&fixture->sink->stream, SOF_IPC_FRAME_INVALID); + + func = mux_get_processing_function(fixture->mod); + + zassert_is_null(func); +} + +#if CONFIG_FORMAT_S16LE +ZTEST_F(mux_get_processing_function, test_mux_get_processing_function_valid_s16le) +{ + mux_func func = NULL; + + audio_stream_set_frm_fmt(&fixture->sink->stream, SOF_IPC_FRAME_S16_LE); + + func = mux_get_processing_function(fixture->mod); + + zassert_not_null(func); +} +#endif /* CONFIG_FORMAT_S16LE */ + +#if CONFIG_FORMAT_S24LE +ZTEST_F(mux_get_processing_function, test_mux_get_processing_function_valid_s24_4le) +{ + mux_func func = NULL; + + audio_stream_set_frm_fmt(&fixture->sink->stream, SOF_IPC_FRAME_S24_4LE); + + func = mux_get_processing_function(fixture->mod); + + zassert_not_null(func); +} +#endif /* CONFIG_FORMAT_S24LE */ + +#if CONFIG_FORMAT_S32LE +ZTEST_F(mux_get_processing_function, test_mux_get_processing_function_valid_s32le) +{ + mux_func func = NULL; + + audio_stream_set_frm_fmt(&fixture->sink->stream, SOF_IPC_FRAME_S32_LE); + + func = mux_get_processing_function(fixture->mod); + + zassert_not_null(func); +} +#endif /* CONFIG_FORMAT_S32LE */ + +ZTEST_SUITE(mux_get_processing_function, NULL, mux_get_processing_function_setup, + mux_get_processing_function_before, mux_get_processing_function_after, NULL); diff --git a/test/ztest/unit/audio/mux/mux_test_util.c b/test/ztest/unit/audio/mux/mux_test_util.c new file mode 100644 index 000000000000..e07141faa746 --- /dev/null +++ b/test/ztest/unit/audio/mux/mux_test_util.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Converted from CMock to Ztest +// Original helpers from test/cmocka/src/util.h and from the +// create_mux_comp_ipc() and create_demux_comp_ipc() functions of the tests in +// test/cmocka/src/audio/mux/ +// Author: Daniel Bogdzia +// Janusz Jankowski + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mux_test_util.h" + +/** + * @brief Allocate a component buffer. + * @param pipeline_id Pipeline ID of the buffer. + * @param frame_fmt Frame format of the buffer. + * @param channels Number of channels of the buffer. + * @param buffer_size Buffer size in bytes. + * @return The new buffer with zeroed data, never NULL. + */ +static struct comp_buffer *mux_test_create_buffer(uint32_t pipeline_id, uint32_t frame_fmt, + uint16_t channels, uint16_t buffer_size) +{ + struct sof_ipc_buffer desc = { + .comp = { + .pipeline_id = pipeline_id, + }, + .size = buffer_size, + }; + struct comp_buffer *buffer = buffer_new(NULL, &desc, BUFFER_USAGE_NOT_SHARED); + + zassert_not_null(buffer, "Failed to allocate a %u byte buffer", buffer_size); + memset(buffer->stream.addr, 0, buffer_size); + audio_stream_set_frm_fmt(&buffer->stream, frame_fmt); + audio_stream_set_channels(&buffer->stream, channels); + + return buffer; +} + +/** + * @brief Allocate the dummy component on the far end of a test buffer. + * @return A zeroed component in the PREPARE state, never NULL. + */ +static struct comp_dev *mux_test_create_far_end(void) +{ + struct comp_dev *dev = calloc(1, sizeof(*dev)); + + zassert_not_null(dev); + dev->state = COMP_STATE_PREPARE; + + return dev; +} + +struct comp_buffer *mux_test_create_sink(struct comp_dev *dev, uint32_t pipeline_id, + uint32_t frame_fmt, uint16_t channels, + uint16_t buffer_size) +{ + struct comp_buffer *buffer; + + buffer = mux_test_create_buffer(pipeline_id, frame_fmt, channels, buffer_size); + buffer->sink = mux_test_create_far_end(); + if (dev) + list_item_append(&buffer->source_list, &dev->bsink_list); + + return buffer; +} + +void mux_test_free_sink(struct comp_buffer *buffer) +{ + if (!buffer) + return; + + free(comp_buffer_get_sink_component(buffer)); + buffer_free(buffer); +} + +struct comp_buffer *mux_test_create_source(struct comp_dev *dev, uint32_t pipeline_id, + uint32_t frame_fmt, uint16_t channels, + uint16_t buffer_size) +{ + struct comp_buffer *buffer; + + buffer = mux_test_create_buffer(pipeline_id, frame_fmt, channels, buffer_size); + buffer->source = mux_test_create_far_end(); + if (dev) + list_item_append(&buffer->sink_list, &dev->bsource_list); + + return buffer; +} + +void mux_test_free_source(struct comp_buffer *buffer) +{ + if (!buffer) + return; + + free(comp_buffer_get_source_component(buffer)); + buffer_free(buffer); +} + +struct comp_dev *mux_test_comp_new(const struct sof_uuid *uuid, + const uint8_t mask[MUX_MAX_STREAMS] + [CONFIG_PLATFORM_MAX_CHANNELS]) +{ + struct sof_ipc_comp_process *ipc; + struct sof_mux_config *mux; + struct comp_dev *dev; + const size_t ipc_size = sizeof(struct sof_ipc_comp_process); + const size_t mux_size = sizeof(struct sof_mux_config) + + MUX_MAX_STREAMS * sizeof(struct mux_stream_data); + int i, j; + + ipc = calloc(1, ipc_size + mux_size + SOF_UUID_SIZE); + zassert_not_null(ipc); + + memcpy_s(ipc + 1, SOF_UUID_SIZE, uuid, SOF_UUID_SIZE); + mux = (struct sof_mux_config *)((char *)(ipc + 1) + SOF_UUID_SIZE); + ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE; + ipc->comp.type = SOF_COMP_MODULE_ADAPTER; + ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); + ipc->size = mux_size; + ipc->comp.ext_data_length = SOF_UUID_SIZE; + + mux->num_streams = MUX_MAX_STREAMS; + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + mux->streams[i].pipeline_id = i; + for (j = 0; j < CONFIG_PLATFORM_MAX_CHANNELS; ++j) + mux->streams[i].mask[j] = mask ? mask[i][j] : 0; + } + + dev = comp_new((struct sof_ipc_comp *)ipc); + free(ipc); + + return dev; +} + +/** + * @brief IDC stub for the remote branch of comp_prepare(). + * + * comp_prepare() is an inline function that forwards the call to another core + * for shared components. The test components are never shared, so the branch + * is not taken, but builds without optimization (for example with --coverage) + * still reference idc_send_msg(). + */ +int idc_send_msg(struct idc_msg *msg, uint32_t mode) +{ + (void)msg; + (void)mode; + + zassert_unreachable("Unexpected IDC message"); + + return -ENOTSUP; +} diff --git a/test/ztest/unit/audio/mux/mux_test_util.h b/test/ztest/unit/audio/mux/mux_test_util.h new file mode 100644 index 000000000000..85319bf6bea9 --- /dev/null +++ b/test/ztest/unit/audio/mux/mux_test_util.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2026 Intel Corporation. + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +#ifndef __TEST_ZTEST_UNIT_AUDIO_MUX_TEST_UTIL_H__ +#define __TEST_ZTEST_UNIT_AUDIO_MUX_TEST_UTIL_H__ + +#include +#include +#include + +#include + +#include + +/** + * @brief Create a buffer that the component under test writes to. + * @param dev Component the buffer is connected to as a sink, or NULL. + * @param pipeline_id Pipeline ID of the buffer, used by mux and demux to + * find the stream configuration of the connection. + * @param frame_fmt Frame format of the buffer. + * @param channels Number of channels of the buffer. + * @param buffer_size Buffer size in bytes. + * @return The new buffer, never NULL. + */ +struct comp_buffer *mux_test_create_sink(struct comp_dev *dev, uint32_t pipeline_id, + uint32_t frame_fmt, uint16_t channels, + uint16_t buffer_size); + +/** + * @brief Free a buffer created by mux_test_create_sink(). + * @param buffer Buffer to free, NULL is ignored. + */ +void mux_test_free_sink(struct comp_buffer *buffer); + +/** + * @brief Create a buffer that the component under test reads from. + * @param dev Component the buffer is connected to as a source, or NULL. + * @param pipeline_id Pipeline ID of the buffer, used by mux and demux to + * find the stream configuration of the connection. + * @param frame_fmt Frame format of the buffer. + * @param channels Number of channels of the buffer. + * @param buffer_size Buffer size in bytes. + * @return The new buffer, never NULL. + */ +struct comp_buffer *mux_test_create_source(struct comp_dev *dev, uint32_t pipeline_id, + uint32_t frame_fmt, uint16_t channels, + uint16_t buffer_size); + +/** + * @brief Free a buffer created by mux_test_create_source(). + * @param buffer Buffer to free, NULL is ignored. + */ +void mux_test_free_source(struct comp_buffer *buffer); + +/** + * @brief Create a mux or demux component through the IPC3 comp_new() path. + * + * The component is configured with MUX_MAX_STREAMS streams, stream i on + * pipeline i with the routing masks in @p mask. + * + * @param uuid UUID of the mux or the demux driver. + * @param mask Routing masks, one row per stream, or NULL for all zero masks. + * @return The new component, or NULL if comp_new() failed. + */ +struct comp_dev *mux_test_comp_new(const struct sof_uuid *uuid, + const uint8_t mask[MUX_MAX_STREAMS] + [CONFIG_PLATFORM_MAX_CHANNELS]); + +#endif /* __TEST_ZTEST_UNIT_AUDIO_MUX_TEST_UTIL_H__ */ diff --git a/test/ztest/unit/audio/mux/prj.conf b/test/ztest/unit/audio/mux/prj.conf new file mode 100644 index 000000000000..35b7bcce3a94 --- /dev/null +++ b/test/ztest/unit/audio/mux/prj.conf @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +CONFIG_ZTEST=y +CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n +CONFIG_COMP_MUX=y +CONFIG_FORMAT_S16LE=y +CONFIG_FORMAT_S24LE=y +CONFIG_FORMAT_S32LE=y +# Route the SOF heap to the host malloc()/free() of the native simulator, so +# that ASan and LSan can see it. They cannot see blocks carved out of the +# static sys_heap arena that zephyr/lib/alloc.c uses by default. +CONFIG_SOF_NATIVE_SIM_HOST_HEAP=y +# The sys_heap arena is still reserved and initialised by heap_init(), and its +# 256 KiB are too large for SYS_HEAP_SMALL_ONLY (see app/boards/native_sim.conf) +CONFIG_SYS_HEAP_BIG_ONLY=y diff --git a/test/ztest/unit/audio/mux/testcase.yaml b/test/ztest/unit/audio/mux/testcase.yaml new file mode 100644 index 000000000000..cbb1ee901906 --- /dev/null +++ b/test/ztest/unit/audio/mux/testcase.yaml @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. +# +# MUX and DEMUX component unit tests converted from CMock to Ztest +# +# These contents may have been developed with support from one or more Intel-operated +# generative artificial intelligence solutions. +# + +common: + tags: + - SOF + - unit_test + - audio + - mux + integration_platforms: + - native_sim + arch_exclude: xtensa + +tests: + sof.unit.audio.mux: + platform_allow: + - native_sim + build_only: false diff --git a/test/ztest/unit/audio/pcm_converter/CMakeLists.txt b/test/ztest/unit/audio/pcm_converter/CMakeLists.txt new file mode 100644 index 000000000000..48f9c0b95293 --- /dev/null +++ b/test/ztest/unit/audio/pcm_converter/CMakeLists.txt @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. +# +# PCM converter float unit tests converted from CMock to Ztest + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(sof_unit_audio_pcm_converter) + +set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..") +set(sof_top_dir ${SOF_ROOT}) + +include(${SOF_ROOT}/scripts/cmake/misc.cmake) +include(${SOF_ROOT}/scripts/cmake/uuid-registry.cmake) + +target_include_directories(app PRIVATE + ${SOF_ROOT}/zephyr/include + ${SOF_ROOT}/src/include + ${SOF_ROOT}/src/kernel/include + ${SOF_ROOT}/src/kernel/platform/posix/include + ${SOF_ROOT}/src/platform/posix/include + ${PROJECT_BINARY_DIR}/include/generated +) + +# pcm_converter.h does not pick an implementation under UNIT_TEST, select the +# generic C one as the CMocka pcm_float_generic target does. +target_compile_definitions(app PRIVATE + -DCONFIG_ZEPHYR_POSIX=1 + -DCONFIG_LIBRARY=1 + -DUNIT_TEST=1 + -DPCM_CONVERTER_GENERIC +) + +# Keep full ASan/LSan allocation stacks (twister --enable-asan --enable-lsan) +if(CONFIG_ASAN) + target_compile_options(app PRIVATE -fno-omit-frame-pointer) +endif() + +target_sources(app PRIVATE + test_pcm_float_ztest.c + ${SOF_ROOT}/src/audio/pcm_converter/pcm_converter.c + ${SOF_ROOT}/src/audio/pcm_converter/pcm_converter_generic.c + # just_copy_*() in pcm_converter.c need cir_buf_copy() + ${SOF_ROOT}/src/audio/component.c + # the test converts between two component buffers + ${SOF_ROOT}/zephyr/lib/alloc.c + ${SOF_ROOT}/src/audio/buffers/comp_buffer.c + ${SOF_ROOT}/src/audio/buffers/audio_buffer.c + ${SOF_ROOT}/src/audio/source_api_helper.c + ${SOF_ROOT}/src/audio/sink_api_helper.c + ${SOF_ROOT}/src/audio/sink_source_utils.c + ${SOF_ROOT}/src/audio/audio_stream.c + ${SOF_ROOT}/src/module/audio/source_api.c + ${SOF_ROOT}/src/module/audio/sink_api.c + ${SOF_ROOT}/src/ipc/ipc-helper.c + # audio_stream_recalc_align() needs gcd() + ${SOF_ROOT}/src/math/numbers.c +) + +sof_append_relative_path_definitions(app) diff --git a/test/ztest/unit/audio/pcm_converter/prj.conf b/test/ztest/unit/audio/pcm_converter/prj.conf new file mode 100644 index 000000000000..0b8a4f43065c --- /dev/null +++ b/test/ztest/unit/audio/pcm_converter/prj.conf @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +CONFIG_ZTEST=y +CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n +# The suite prints float values (%e, %f); without this, printk silently emits +# the format string literally instead of the value. +CONFIG_CBPRINTF_FP_SUPPORT=y +# Route the SOF heap to the host malloc()/free() of the native simulator, so +# that ASan and LSan can see it. They cannot see blocks carved out of the +# static sys_heap arena that zephyr/lib/alloc.c uses by default. +CONFIG_SOF_NATIVE_SIM_HOST_HEAP=y +# The sys_heap arena is still reserved and initialised by heap_init(), and its +# 256 KiB are too large for SYS_HEAP_SMALL_ONLY (see app/boards/native_sim.conf) +CONFIG_SYS_HEAP_BIG_ONLY=y +# The CMocka test was built only with CONFIG_FORMAT_FLOAT, which is the +# native_sim default; make it explicit. +CONFIG_FORMAT_FLOAT=y diff --git a/test/ztest/unit/audio/pcm_converter/test_pcm_float_ztest.c b/test/ztest/unit/audio/pcm_converter/test_pcm_float_ztest.c new file mode 100644 index 000000000000..c0bb3ee76b59 --- /dev/null +++ b/test/ztest/unit/audio/pcm_converter/test_pcm_float_ztest.c @@ -0,0 +1,629 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Converted from CMock to Ztest +// Original tests from test/cmocka/src/audio/pcm_converter/pcm_float.c: +// Author: Karol Trzcinski + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* used during float assertions */ +#define EPSILON 0.01f + +/* base number to check combinations for each data format */ +#define PCM_TEST_INT_NUMBERS \ + -0, 0, 0, 0, -1, 1, -2, 2, \ + -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -25, 25, -57, 57, -100, 100 +#define PCM_TEST_FLOAT_NUMBERS \ + -0, 0, 0.1, -0.1f, -0.8f, 0.8f, -1.9f, 1.9f, \ + -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -25, 25, -57, 57, -100, 100 + +/* generate biggest signed value on a 24 bits number */ +#define INT24_MAX ((1 << (24 - 1)) - 1) + +/* generate smallest signed value on a 24 bits number */ +#define INT24_MIN (-INT24_MAX - 1) + +/* conversion ratio */ +static const float ratio16 = 1.f / (1u << 15); +static const float ratio24 = 1.f / (1u << 23); +static const float ratio32 = 1.f / (1u << 31); + +/** + * @brief Compare two floats like the CMocka assert_float_equal() + * + * The values are equal if they differ by at most epsilon, or by at most + * FLT_EPSILON relative to the larger magnitude of the two. + */ +static bool float_equal(float left, float right, float epsilon) +{ + float diff = fabsf(left - right); + float largest; + + if (diff <= epsilon) + return true; + + largest = fabsf(right) > fabsf(left) ? fabsf(right) : fabsf(left); + + return diff <= largest * FLT_EPSILON; +} + +/** + * @brief Print an int sample and the float it converts from or to + * @param[in] it Int value. + * @param[in] fl Float value, printed also as its bits, mantissa and exponent. + * @param[in] ep Expected value. + * @param[in] func_name Name of the calling test. + */ +static void pcm_float_print_values(int32_t it, const float *fl, double ep, + const char *func_name) +{ + const uint32_t mantissa_mask = (1 << 23) - 1; + uint32_t bits; + int32_t ex; + uint32_t mt; + float mantissa_value; + + memcpy(&bits, fl, sizeof(bits)); + ex = (int32_t)((bits >> 23) & 0xFF) - 127; + mt = bits & mantissa_mask; + mantissa_value = mt * (1.0f / mantissa_mask) + 1.f; + + printk("%s: 0x%08Xf => %.3f * 2**%3d = %10.3e f <=> %7d d \t(expected: %10.3e)\n", + func_name, bits, (double)mantissa_value, ex, (double)*fl, it, ep); +} + +/** + * @brief Allocate a component buffer for the given frame format + * @param[in] frame_fmt Frame format of the stream. + * @param[in] size Buffer size in bytes. + * @return The new buffer, never NULL. + */ +static struct comp_buffer *test_buffer_new(enum sof_ipc_frame frame_fmt, uint32_t size) +{ + struct sof_ipc_buffer desc = {.size = size}; + struct comp_buffer *buf = buffer_new(NULL, &desc, BUFFER_USAGE_NOT_SHARED); + + zassert_not_null(buf, "Failed to allocate a %u byte buffer.", size); + + memset(buf->stream.addr, 0, size); + audio_stream_set_frm_fmt(&buf->stream, frame_fmt); + audio_stream_set_channels(&buf->stream, 1); + + return buf; +} + +/** + * @brief Convert samples between two formats with the PCM converter + * + * The sink is one sample larger than needed, its last byte is checked to be + * left untouched by the conversion. + * + * @param[in] frm_in Source frame format. + * @param[in] frm_out Sink frame format. + * @param[in] samples Number of samples to convert. + * @param[in] data Source samples. + * @return The sink buffer with the converted samples, to be freed by the caller. + */ +static struct comp_buffer *test_pcm_convert(enum sof_ipc_frame frm_in, enum sof_ipc_frame frm_out, + int samples, const void *data) +{ + struct comp_buffer *source; + struct comp_buffer *sink; + pcm_converter_func fun; + const uint8_t fillval = 0xAB; + const int inbytes = samples * get_sample_bytes(frm_in); + const int outbytes = (samples + 1) * get_sample_bytes(frm_out); + + /* create buffers - output buffer may be too big for test */ + source = test_buffer_new(frm_in, inbytes); + sink = test_buffer_new(frm_out, outbytes); + + /* fill source */ + memcpy_s(source->stream.w_ptr, source->stream.size, data, inbytes); + audio_stream_produce(&source->stream, inbytes); + + /* fill sink memory - to validate last value */ + memset(sink->stream.w_ptr, fillval, outbytes); + + /* run conversion */ + fun = pcm_get_conversion_function(frm_in, frm_out); + zassert_not_null(fun, "No conversion function from format %d to %d", frm_in, frm_out); + + struct cir_buf_source cir_src = { + .buf_start = source->stream.addr, + .buf_end = source->stream.end_addr, + .ptr = source->stream.r_ptr, + }; + struct cir_buf_sink cir_snk = { + .buf_start = sink->stream.addr, + .buf_end = sink->stream.end_addr, + .ptr = sink->stream.w_ptr, + }; + + fun(&cir_src, audio_stream_get_channels(&source->stream), + &cir_snk, audio_stream_get_channels(&sink->stream), samples, DUMMY_CHMAP); + + /* assert last value in sink is untouched */ + zassert_equal(((uint8_t *)sink->stream.w_ptr)[outbytes - 1], fillval, + "Conversion wrote past the last sample"); + + /* free source and return sink */ + buffer_free(source); + return sink; +} + +static void mask_array(int32_t mask, int32_t *parray, int cnt) +{ + zassert_not_null(parray); + while (cnt--) + parray[cnt] &= mask; +} + +static void scale_array(float ratio, float *parray, int cnt) +{ + zassert_not_null(parray); + while (cnt--) + parray[cnt] *= ratio; +} + +#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S16LE +/** + * @brief Test S16_LE to float conversion + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_s16_to_f) +{ + typedef int16_t Tin; + typedef float Tout; + static const Tin source_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + }; + Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio16, expected_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_S16_LE, SOF_IPC_FRAME_FLOAT, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(source_buf[i], read_val, (double)expected_buf[i], + __func__); + zassert_true(float_equal(*read_val, expected_buf[i], EPSILON), + "sample %d: %e != %e", i, (double)*read_val, + (double)expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} + +/** + * @brief Test float to S16_LE conversion + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_f_to_s16) +{ + typedef float Tin; + typedef int16_t Tout; + Tin source_buf[] = { + PCM_TEST_FLOAT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + }; + static const Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio16, source_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S16_LE, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(*read_val, &source_buf[i], (double)expected_buf[i], + __func__); + zassert_equal(*read_val, expected_buf[i], "sample %d: %d != %d", i, + *read_val, expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} +#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S16LE */ + +#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S24LE +/** + * @brief Test S24_4LE to float conversion of sign extended samples + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_s24_in_s32_to_f) +{ + typedef int32_t Tin; + typedef float Tout; + static const Tin source_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + }; + Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio24, expected_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_S24_4LE, SOF_IPC_FRAME_FLOAT, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(source_buf[i], read_val, (double)expected_buf[i], + __func__); + zassert_true(float_equal(*read_val, expected_buf[i], EPSILON), + "sample %d: %e != %e", i, (double)*read_val, + (double)expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} + +/** + * @brief Test S24_4LE to float conversion of samples with a zero top byte + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_s24_to_f) +{ + typedef int32_t Tin; + typedef float Tout; + Tin source_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + }; + Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + mask_array(MASK(24, 0), source_buf, N); + scale_array(ratio24, expected_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_S24_4LE, SOF_IPC_FRAME_FLOAT, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(sign_extend_s24(source_buf[i]), read_val, + (double)expected_buf[i], __func__); + zassert_true(float_equal(*read_val, expected_buf[i], EPSILON), + "sample %d: %e != %e", i, (double)*read_val, + (double)expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} + +/** + * @brief Test float to S24_4LE conversion, including saturation + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_f_to_s24) +{ + typedef float Tin; + typedef int32_t Tout; + Tin source_buf[] = { + PCM_TEST_FLOAT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + INT24_MIN - 1, INT24_MAX + 1, + }; + static const Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + INT24_MIN, INT24_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio24, source_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S24_4LE, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(*read_val, &source_buf[i], (double)expected_buf[i], + __func__); + zassert_equal(*read_val, expected_buf[i], "sample %d: %d != %d", i, + *read_val, expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} +#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S24LE */ + +#if CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S32LE +#define S24TOS32MULT (1 << (32 - 24)) +/** + * @brief Test S32_LE to float conversion + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_s32_to_f) +{ + typedef int32_t Tin; + typedef float Tout; + + static const Tin source_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + INT32_MIN + 1, INT32_MIN, + INT32_MAX - 1, INT32_MAX, + }; + Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + INT24_MIN * S24TOS32MULT, INT24_MIN * S24TOS32MULT, + INT24_MAX * S24TOS32MULT, INT24_MAX * S24TOS32MULT, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio32, expected_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_FLOAT, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(source_buf[i], read_val, (double)expected_buf[i], + __func__); + zassert_true(float_equal(*read_val, expected_buf[i], EPSILON), + "sample %d: %e != %e", i, (double)*read_val, + (double)expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} + +/** + * @brief Test float to S32_LE conversion + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_f_to_s32) +{ + typedef float Tin; + typedef int32_t Tout; + Tin source_buf[] = { + PCM_TEST_FLOAT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + }; + static const Tout expected_buf[] = { + PCM_TEST_INT_NUMBERS, + INT16_MIN + 1, INT16_MIN, + INT16_MAX - 1, INT16_MAX, + INT24_MIN + 1, INT24_MIN, + INT24_MAX - 1, INT24_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio32, source_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S32_LE, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(*read_val, &source_buf[i], (double)expected_buf[i], + __func__); + zassert_equal(*read_val, expected_buf[i], "sample %d: %d != %d", i, + *read_val, expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} + +/** + * @brief Test float to S32_LE conversion of large negative values + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_f_to_s32_big_neg) +{ + typedef float Tin; + typedef int32_t Tout; + Tin source_buf[] = { + INT24_MIN - 127, INT24_MIN - 128, /* 24B mantissa trimming */ + /* 24B mantissa trimming, explicit casts as clang rejects implicit lossy ones */ + (float)(INT32_MIN + 1), INT32_MIN, + INT32_MIN * 2.f, INT32_MIN * 10.f, + -INFINITY + }; + static const Tout expected_buf[] = { + INT24_MIN - 127, INT24_MIN - 128, + INT32_MIN + 1, INT32_MIN, + INT32_MIN, INT32_MIN, + INT32_MIN + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio32, source_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S32_LE, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(*read_val, &source_buf[i], (double)expected_buf[i], + __func__); + /* assert as float because of possible rounding effects */ + zassert_true(float_equal((float)*read_val, (float)expected_buf[i], 1), + "sample %d: %d != %d", i, *read_val, expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} + +/** + * @brief Test float to S32_LE conversion of large positive values + */ +ZTEST(audio_pcm_float_suite, test_pcm_convert_f_to_s32_big_pos) +{ + typedef float Tin; + typedef int32_t Tout; + Tin source_buf[] = { + INT24_MAX + 127, INT24_MAX + 128, + INT32_MAX - 255, INT32_MAX - 127, + /* 24B mantissa trimming, explicit casts as clang rejects implicit lossy ones */ + (float)(INT32_MAX - 1), (float)INT32_MAX, + (float)INT32_MAX * 2.f, (float)INT32_MAX * 10.f, + INFINITY, + }; + /* remember about 24B mantissa trimming */ + static const Tout expected_buf[] = { + INT24_MAX + 127, INT24_MAX + 128, + INT32_MAX - 254, INT32_MAX - 126, + INT32_MAX - 1, INT32_MAX, + INT32_MAX, INT32_MAX, + INT32_MAX, + }; + + struct comp_buffer *sink; + int i, N = ARRAY_SIZE(source_buf); + Tout *read_val; + + zassert_equal(ARRAY_SIZE(source_buf), ARRAY_SIZE(expected_buf)); + scale_array(ratio32, source_buf, N); + + /* run test */ + sink = test_pcm_convert(SOF_IPC_FRAME_FLOAT, SOF_IPC_FRAME_S32_LE, + N, source_buf); + + /* check results */ + for (i = 0; i < N; ++i) { + read_val = audio_stream_read_frag(&sink->stream, i, sizeof(Tout)); + printk("%2d/%02d ", i + 1, N); + pcm_float_print_values(*read_val, &source_buf[i], (double)expected_buf[i], + __func__); + /* assert as float because of possible rounding effects */ + zassert_true(float_equal((float)*read_val, (float)expected_buf[i], 1), + "sample %d: %d != %d", i, *read_val, expected_buf[i]); + } + + /* free memory */ + buffer_free(sink); +} +#endif /* CONFIG_FORMAT_FLOAT && CONFIG_FORMAT_S32LE */ + +static void *audio_pcm_float_setup(void) +{ + /* log number of converting functions for current configuration */ + printk("%s start tests, count(pcm_func_map)=%zu\n", __FILE__, pcm_func_count); + + return NULL; +} + +ZTEST_SUITE(audio_pcm_float_suite, NULL, audio_pcm_float_setup, NULL, NULL, NULL); diff --git a/test/ztest/unit/audio/pcm_converter/testcase.yaml b/test/ztest/unit/audio/pcm_converter/testcase.yaml new file mode 100644 index 000000000000..7892d8b11b21 --- /dev/null +++ b/test/ztest/unit/audio/pcm_converter/testcase.yaml @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. +# +# PCM converter float unit tests converted from CMock to Ztest +# +# These contents may have been developed with support from one or more Intel-operated +# generative artificial intelligence solutions. +# + +common: + tags: + - SOF + - unit_test + - audio + - pcm_converter + integration_platforms: + - native_sim + arch_exclude: xtensa + +tests: + sof.unit.audio.pcm_converter: + platform_allow: + - native_sim + build_only: false diff --git a/test/ztest/unit/math/dft3/CMakeLists.txt b/test/ztest/unit/math/dft3/CMakeLists.txt index 7353560f286c..056072211185 100644 --- a/test/ztest/unit/math/dft3/CMakeLists.txt +++ b/test/ztest/unit/math/dft3/CMakeLists.txt @@ -17,9 +17,6 @@ target_include_directories(app PRIVATE ${SOF_ROOT}/zephyr/include ${SOF_ROOT}/src/include ${SOF_ROOT}/src/platform/posix/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_dft3.m b/test/ztest/unit/math/dft3/ref_dft3.m similarity index 98% rename from test/cmocka/src/math/fft/ref_dft3.m rename to test/ztest/unit/math/dft3/ref_dft3.m index c3f55d91b3e3..87afe83342d6 100644 --- a/test/cmocka/src/math/fft/ref_dft3.m +++ b/test/ztest/unit/math/dft3/ref_dft3.m @@ -6,7 +6,7 @@ function ref_dft3() - path(path(), '../../../m'); + path(path(), '../../../../cmocka/m'); opt.describe = export_get_git_describe(); N = 3; diff --git a/test/cmocka/src/math/fft/ref_dft3_32.h b/test/ztest/unit/math/dft3/ref_dft3_32.h similarity index 100% rename from test/cmocka/src/math/fft/ref_dft3_32.h rename to test/ztest/unit/math/dft3/ref_dft3_32.h diff --git a/test/ztest/unit/math/dft3/test_dft3_ztest.c b/test/ztest/unit/math/dft3/test_dft3_ztest.c index fb7743c440ab..18e4d084c5a1 100644 --- a/test/ztest/unit/math/dft3/test_dft3_ztest.c +++ b/test/ztest/unit/math/dft3/test_dft3_ztest.c @@ -12,10 +12,7 @@ #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, generated with ref_dft3.m */ #include "ref_dft3_32.h" #include diff --git a/test/ztest/unit/math/drc/CMakeLists.txt b/test/ztest/unit/math/drc/CMakeLists.txt new file mode 100644 index 000000000000..a9c98f21ff88 --- /dev/null +++ b/test/ztest/unit/math/drc/CMakeLists.txt @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(sof_unit_math_drc) + +set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../../") +set(sof_top_dir ${SOF_ROOT}) + +include(${SOF_ROOT}/scripts/cmake/misc.cmake) +include(${SOF_ROOT}/scripts/cmake/uuid-registry.cmake) + +target_include_directories(app PRIVATE + ${SOF_ROOT}/zephyr/include + ${SOF_ROOT}/src/include + ${SOF_ROOT}/src/platform/posix/include + ${SOF_ROOT}/src/audio + ${PROJECT_BINARY_DIR}/include/generated +) + +target_compile_definitions(app PRIVATE + -DCONFIG_ZEPHYR_POSIX=1 + -DCONFIG_LIBRARY=1 + -DUNIT_TEST=1 +) + +# The same sources as the CMocka drc_math_test target. The HiFi3 variants +# are inert on native_sim, they compile only for Xtensa HiFi targets. +target_sources(app PRIVATE + test_drc_math_ztest.c + ${SOF_ROOT}/src/audio/drc/drc_math_generic.c + ${SOF_ROOT}/src/audio/drc/drc_math_hifi3.c + ${SOF_ROOT}/src/math/numbers.c + ${SOF_ROOT}/src/math/exp_fcn.c + ${SOF_ROOT}/src/math/exp_fcn_hifi.c +) + +sof_append_relative_path_definitions(app) diff --git a/test/ztest/unit/math/drc/prj.conf b/test/ztest/unit/math/drc/prj.conf new file mode 100644 index 000000000000..0be900a6c9e4 --- /dev/null +++ b/test/ztest/unit/math/drc/prj.conf @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +CONFIG_ZTEST=y +CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n +# printk()/zassert messages in this suite print doubles (%g, %e); without +# this, printk silently emits the format string literally instead of the value. +CONFIG_CBPRINTF_FP_SUPPORT=y +# The DRC SIMD level choice depends on COMP_DRC. On native_sim it defaults to +# DRC_HIFI_NONE, which selects the generic drc_math_generic.c implementation. +CONFIG_COMP_DRC=y diff --git a/test/cmocka/src/audio/drc/drc_math_test.c b/test/ztest/unit/math/drc/test_drc_math_ztest.c similarity index 52% rename from test/cmocka/src/audio/drc/drc_math_test.c rename to test/ztest/unit/math/drc/test_drc_math_ztest.c index 03b23577f0c7..9a0e4ba9e433 100644 --- a/test/cmocka/src/audio/drc/drc_math_test.c +++ b/test/ztest/unit/math/drc/test_drc_math_ztest.c @@ -1,18 +1,18 @@ // SPDX-License-Identifier: BSD-3-Clause // -// Copyright(c) 2024 Intel Corporation. +// Copyright(c) 2026 Intel Corporation. +// +// Converted from CMock to Ztest +// Original tests from test/cmocka/src/audio/drc/drc_math_test.c: +// Author: Seppo Ingalsuo -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include + #define TEST_POINTS 500 #define ABS_DELTA_TOLERANCE_T1 1.0e-9 @@ -22,6 +22,13 @@ #define ABS_DELTA_TOLERANCE_T3 3.8e-4 #define REL_DELTA_TOLERANCE_T3 1.9e-6 +/** + * @brief Reference 1/x in double precision, rounded and saturated to int32 + * @param[in] x Input value. + * @param[in] precision_x Fractional bits of x. + * @param[in] precision_y Fractional bits of the result. + * @return 1/x with precision_y fractional bits. + */ static int32_t drc_inv_ref(int32_t x, int32_t precision_x, int32_t precision_y) { double xf, yf, ys; @@ -38,6 +45,16 @@ static int32_t drc_inv_ref(int32_t x, int32_t precision_x, int32_t precision_y) return (int32_t)ys; } +/** + * @brief Compare drc_inv_fixed() with the reference over an input range + * @param[in] x_start First input value. + * @param[in] x_end Last input value, inclusive. + * @param[in] x_step Input increment. + * @param[in] q_in Fractional bits of the input. + * @param[in] q_out Fractional bits of the output. + * @param[in] abs_delta_tolerance Maximum absolute error. + * @param[in] rel_delta_tolerance Maximum relative error. + */ static void drc_math_inv_fixed_test_helper(int32_t x_start, int32_t x_end, int32_t x_step, int q_in, int q_out, double abs_delta_tolerance, double rel_delta_tolerance) @@ -50,8 +67,8 @@ static void drc_math_inv_fixed_test_helper(int32_t x_start, int32_t x_end, double abs_delta_max = 0; double rel_delta_max = 0; - printf("%s: Testing q_in = %d q_out = %d in = %d:%d:%d\n", __func__, - q_in, q_out, x_start, x_step, x_end); + printk("%s: Testing q_in = %d q_out = %d in = %d:%d:%d\n", __func__, + q_in, q_out, x_start, x_step, x_end); x1 = x_start; while (x1 <= x_end) { @@ -61,9 +78,9 @@ static void drc_math_inv_fixed_test_helper(int32_t x_start, int32_t x_end, if (y1 != y2) differences++; - fx = (double)x / (1 << q_in); - fy1 = (double)y1 / (1 << q_out); - fy2 = (double)y2 / (1 << q_out); + fx = (double)x / ((int64_t)1 << q_in); + fy1 = (double)y1 / ((int64_t)1 << q_out); + fy2 = (double)y2 / ((int64_t)1 << q_out); abs_delta = fabs(fy1 - fy2); rel_delta = abs_delta / fy1; if (rel_delta > rel_delta_max) @@ -72,30 +89,27 @@ static void drc_math_inv_fixed_test_helper(int32_t x_start, int32_t x_end, if (abs_delta > abs_delta_max) abs_delta_max = abs_delta; - if (rel_delta > rel_delta_tolerance) { - printf("%s: Relative error %g exceeds limit %g, input %g output %g ref %g.\n", - __func__, rel_delta, rel_delta_tolerance, fx, fy2, fy1); - assert_true(false); - } + zassert_false(rel_delta > rel_delta_tolerance, + "Relative error %g exceeds limit %g, input %g output %g ref %g.", + rel_delta, rel_delta_tolerance, fx, fy2, fy1); - if (abs_delta > abs_delta_tolerance) { - printf("%s: Absolute error %g exceeds limit %g, input %g output %g ref %g.\n", - __func__, abs_delta, abs_delta_tolerance, fx, fy2, fy1); - assert_true(false); - } + zassert_false(abs_delta > abs_delta_tolerance, + "Absolute error %g exceeds limit %g, input %g output %g ref %g.", + abs_delta, abs_delta_tolerance, fx, fy2, fy1); x1 += x_step; } - printf("%s: bit exact differences count = %d\n", __func__, differences); - printf("%s: Absolute max error was %.6e.\n", __func__, abs_delta_max); - printf("%s: Relative max error was %.6e.\n", __func__, rel_delta_max); + printk("%s: bit exact differences count = %d\n", __func__, differences); + printk("%s: Absolute max error was %.6e.\n", __func__, abs_delta_max); + printk("%s: Relative max error was %.6e.\n", __func__, rel_delta_max); } -static void test_function_drc_inv_fixed_q12_q30(void **state) +/** + * @brief Test drc_inv_fixed() with Q12 input and Q30 output + */ +ZTEST(math_drc_suite, test_function_drc_inv_fixed_q12_q30) { - (void)state; - int32_t x_start = 1; int32_t x_end = INT32_MAX; int32_t x_step = (int32_t)(((int64_t)x_end - (int64_t)x_start) / (TEST_POINTS - 1)); @@ -106,10 +120,11 @@ static void test_function_drc_inv_fixed_q12_q30(void **state) ABS_DELTA_TOLERANCE_T1, REL_DELTA_TOLERANCE_T1); } -static void test_function_drc_inv_fixed_q22_q26(void **state) +/** + * @brief Test drc_inv_fixed() with Q22 input and Q26 output + */ +ZTEST(math_drc_suite, test_function_drc_inv_fixed_q22_q26) { - (void)state; - int32_t x_start = 1; int32_t x_end = INT32_MAX; int32_t x_step = (int32_t)(((int64_t)x_end - (int64_t)x_start) / TEST_POINTS); @@ -120,10 +135,11 @@ static void test_function_drc_inv_fixed_q22_q26(void **state) ABS_DELTA_TOLERANCE_T2, REL_DELTA_TOLERANCE_T2); } -static void test_function_drc_inv_fixed_q31_q20(void **state) +/** + * @brief Test drc_inv_fixed() with Q31 input and Q20 output + */ +ZTEST(math_drc_suite, test_function_drc_inv_fixed_q31_q20) { - (void)state; - int32_t x_start = 1; int32_t x_end = INT32_MAX; int32_t x_step = (int32_t)(((int64_t)x_end - (int64_t)x_start) / TEST_POINTS); @@ -134,15 +150,4 @@ static void test_function_drc_inv_fixed_q31_q20(void **state) ABS_DELTA_TOLERANCE_T3, REL_DELTA_TOLERANCE_T3); } -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_function_drc_inv_fixed_q12_q30), - cmocka_unit_test(test_function_drc_inv_fixed_q22_q26), - cmocka_unit_test(test_function_drc_inv_fixed_q31_q20), - }; - - cmocka_set_message_output(CM_OUTPUT_TAP); - - return cmocka_run_group_tests(tests, NULL, NULL); -} +ZTEST_SUITE(math_drc_suite, NULL, NULL, NULL, NULL, NULL); diff --git a/test/ztest/unit/math/drc/testcase.yaml b/test/ztest/unit/math/drc/testcase.yaml new file mode 100644 index 000000000000..9792e0e5134e --- /dev/null +++ b/test/ztest/unit/math/drc/testcase.yaml @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. +# +# DRC math unit tests converted from CMock to Ztest +# +# These contents may have been developed with support from one or more Intel-operated +# generative artificial intelligence solutions. +# + +common: + tags: + - SOF + - unit_test + - math + - drc + integration_platforms: + - native_sim + arch_exclude: xtensa + +tests: + sof.unit.math.drc: + platform_allow: + - native_sim + build_only: false