Skip to content

Commit 77a2711

Browse files
Test(cmocka, crossover): move source/sink stubs to a shared mock unit
Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
1 parent 937569b commit 77a2711

3 files changed

Lines changed: 85 additions & 15 deletions

File tree

test/cmocka/src/audio/crossover/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ cmocka_test(crossover_lr4_test
1313
target_link_libraries(crossover_lr4_test PRIVATE m)
1414

1515
# crossover_split_test: tests the split_2way / split_3way / split_4way routing
16-
# topology by compiling crossover_generic.c directly. The FORMAT macros are
17-
# left undefined so that only the split functions (no audio_stream dependency)
18-
# are exercised; audio_stream_copy is stubbed inside crossover_split_test.c.
16+
# topology by compiling crossover_generic.c directly. The per-format processing
17+
# functions in crossover_generic.c reference the source/sink API; those symbols
18+
# are satisfied by the trivial stubs in crossover_test_mocks.c (shareable by any
19+
# test that links crossover_generic.c).
1920

2021
add_compile_options(-DUNIT_TEST)
2122

2223
cmocka_test(crossover_split_test
2324
crossover_split_test.c
25+
crossover_test_mocks.c
2426
${PROJECT_SOURCE_DIR}/src/audio/crossover/crossover_generic.c
2527
${PROJECT_SOURCE_DIR}/src/math/iir_df1.c
2628
${PROJECT_SOURCE_DIR}/src/math/iir_df1_generic.c

test/cmocka/src/audio/crossover/crossover_split_test.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,9 @@
4545
#include <stdio.h>
4646
#include <cmocka.h>
4747

48-
/* audio_stream_copy is referenced by crossover_default_pass() which is
49-
* compiled as part of crossover_generic.c. The split functions under test
50-
* never call it, but the linker needs a definition.
48+
/* The source/sink API stubs required to link crossover_generic.c live in
49+
* crossover_test_mocks.c, added to this test's sources via CMake.
5150
*/
52-
#include <sof/audio/audio_stream.h>
53-
54-
int audio_stream_copy(const struct audio_stream *source, uint32_t ioffset,
55-
struct audio_stream *sink, uint32_t ooffset, uint32_t samples)
56-
{
57-
(void)source; (void)ioffset; (void)sink; (void)ooffset; (void)samples;
58-
return 0;
59-
}
60-
6151
#include <sof/audio/format.h>
6252
#include <sof/math/iir_df1.h>
6353
#include <module/crossover/crossover_common.h>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright(c) 2025 Intel Corporation. All rights reserved.
4+
//
5+
// Author: Piotr Hoppe <piotr.hoppe@intel.com>
6+
7+
/**
8+
* @file crossover_test_mocks.c
9+
* @brief Trivial source/sink API stubs for the crossover unit tests.
10+
*
11+
* The crossover_generic.c translation unit also contains the per-format
12+
* processing functions (crossover_s16/s24/s32_default and the passthrough),
13+
* which reference the source/sink API. The split functions under test never
14+
* call them, but the linker still needs the referenced symbols defined.
15+
*
16+
* The stubs are provided by this separate translation unit so that any number
17+
* of test executables can link them via CMake without risking multiple
18+
* definitions. The prototypes come from the real source/sink API headers.
19+
*/
20+
21+
#include <stdbool.h>
22+
#include <stddef.h>
23+
#include <stdint.h>
24+
#include <sof/audio/source_api.h>
25+
#include <sof/audio/sink_api.h>
26+
#include <sof/audio/sink_source_utils.h>
27+
28+
size_t source_get_frame_bytes(struct sof_source *source)
29+
{
30+
(void)source;
31+
return 0;
32+
}
33+
34+
int source_get_data_s16(struct sof_source *source, size_t req_size, int16_t const **data_ptr,
35+
int16_t const **buffer_start, int *buffer_samples)
36+
{
37+
(void)source; (void)req_size; (void)data_ptr; (void)buffer_start; (void)buffer_samples;
38+
return 0;
39+
}
40+
41+
int source_get_data_s32(struct sof_source *source, size_t req_size, int32_t const **data_ptr,
42+
int32_t const **buffer_start, int *buffer_samples)
43+
{
44+
(void)source; (void)req_size; (void)data_ptr; (void)buffer_start; (void)buffer_samples;
45+
return 0;
46+
}
47+
48+
int source_release_data(struct sof_source *source, size_t free_size)
49+
{
50+
(void)source; (void)free_size;
51+
return 0;
52+
}
53+
54+
int sink_get_buffer_s16(struct sof_sink *sink, size_t req_size, int16_t **data_ptr,
55+
int16_t **buffer_start, int *buffer_samples)
56+
{
57+
(void)sink; (void)req_size; (void)data_ptr; (void)buffer_start; (void)buffer_samples;
58+
return 0;
59+
}
60+
61+
int sink_get_buffer_s32(struct sof_sink *sink, size_t req_size, int32_t **data_ptr,
62+
int32_t **buffer_start, int *buffer_samples)
63+
{
64+
(void)sink; (void)req_size; (void)data_ptr; (void)buffer_start; (void)buffer_samples;
65+
return 0;
66+
}
67+
68+
int sink_commit_buffer(struct sof_sink *sink, size_t commit_size)
69+
{
70+
(void)sink; (void)commit_size;
71+
return 0;
72+
}
73+
74+
int source_to_sink_copy(struct sof_source *source, struct sof_sink *sink, bool free, size_t size)
75+
{
76+
(void)source; (void)sink; (void)free; (void)size;
77+
return 0;
78+
}

0 commit comments

Comments
 (0)