Skip to content

Commit 47c52cc

Browse files
btian1kv2019i
authored andcommitted
Component: move comp_copy from header file to source file an
On sof zephyr ipc4 build, component performance profiling logs can't be enabled due to current xcc compiler does not support inline logging in header file, logs as below: log_level undeclared (first use in this function) log_current_const_data undeclared (first use in this function) Move comp_copy to component.c can resolve this limitation. However, this brings another cmocka issue for mixer unit test, this patch also fixed cmocka mixer unit test issue. BugLink: zephyrproject-rtos/zephyr#43786 Signed-off-by: Baofeng Tian <baofeng.tian@intel.com>
1 parent 177b614 commit 47c52cc

File tree

13 files changed

+54
-32
lines changed

13 files changed

+54
-32
lines changed

src/audio/component.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,27 @@ void audio_stream_copy_to_linear(const struct audio_stream __sparse_cache *sourc
234234
snk += bytes_copied;
235235
}
236236
}
237+
238+
/** See comp_ops::copy */
239+
int comp_copy(struct comp_dev *dev)
240+
{
241+
int ret = 0;
242+
243+
assert(dev->drv->ops.copy);
244+
245+
/* copy only if we are the owner of the component */
246+
if (cpu_is_me(dev->ipc_config.core)) {
247+
#if CONFIG_PERFORMANCE_COUNTERS
248+
perf_cnt_init(&dev->pcd);
249+
#endif
250+
251+
ret = dev->drv->ops.copy(dev);
252+
253+
#if CONFIG_PERFORMANCE_COUNTERS
254+
perf_cnt_stamp(&dev->pcd, comp_perf_info, dev);
255+
perf_cnt_average(&dev->pcd, comp_perf_avg_info, dev);
256+
#endif
257+
}
258+
259+
return ret;
260+
}

src/audio/mixer/mixer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,10 @@ static const struct comp_driver comp_mixer = {
470470
},
471471
};
472472

473-
static SHARED_DATA struct comp_driver_info comp_mixer_info = {
473+
#ifndef UNIT_TEST
474+
static
475+
#endif
476+
SHARED_DATA struct comp_driver_info comp_mixer_info = {
474477
.drv = &comp_mixer,
475478
};
476479

src/include/sof/audio/component_ext.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,35 +171,8 @@ static inline int comp_prepare(struct comp_dev *dev)
171171
return 0;
172172
}
173173

174-
/** See comp_ops::copy */
175-
static inline int comp_copy(struct comp_dev *dev)
176-
{
177-
int ret = 0;
178-
179-
assert(dev->drv->ops.copy);
180-
181-
/* copy only if we are the owner of the component */
182-
if (cpu_is_me(dev->ipc_config.core)) {
183-
/* BugLink: https://github.com/zephyrproject-rtos/zephyr/issues/43786
184-
* TODO: Remove this once the bug gets fixed.
185-
*/
186-
#ifndef __ZEPHYR__
187-
perf_cnt_init(&dev->pcd);
188-
#endif
189-
190-
ret = dev->drv->ops.copy(dev);
174+
int comp_copy(struct comp_dev *dev);
191175

192-
/* BugLink: https://github.com/zephyrproject-rtos/zephyr/issues/43786
193-
* TODO: Remove this once the bug gets fixed.
194-
*/
195-
#ifndef __ZEPHYR__
196-
perf_cnt_stamp(&dev->pcd, comp_perf_info, dev);
197-
perf_cnt_average(&dev->pcd, comp_perf_avg_info, dev);
198-
#endif
199-
}
200-
201-
return ret;
202-
}
203176

204177
/** See comp_ops::get_attribute */
205178
static inline int comp_get_attribute(struct comp_dev *dev, uint32_t type,

src/include/sof/audio/mixer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#ifdef UNIT_TEST
1919
void sys_comp_mixer_init(void);
20+
extern struct comp_driver_info comp_mixer_info;
2021
#endif
2122

2223
#define MIXER_GENERIC

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cmocka_test(buffer_copy
1212
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
1313
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
1414
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
15+
${PROJECT_SOURCE_DIR}/src/audio/component.c
1516
)
1617

1718
cmocka_test(buffer_new
@@ -27,6 +28,7 @@ cmocka_test(buffer_new
2728
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
2829
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
2930
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
31+
${PROJECT_SOURCE_DIR}/src/audio/component.c
3032
)
3133

3234
cmocka_test(buffer_wrap
@@ -42,6 +44,7 @@ cmocka_test(buffer_wrap
4244
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
4345
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
4446
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
47+
${PROJECT_SOURCE_DIR}/src/audio/component.c
4548
)
4649

4750
cmocka_test(buffer_write
@@ -57,4 +60,5 @@ cmocka_test(buffer_write
5760
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
5861
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
5962
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
63+
${PROJECT_SOURCE_DIR}/src/audio/component.c
6064
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
cmocka_test(mixer
44
mixer_test.c
55
comp_mock.c
6+
${PROJECT_SOURCE_DIR}/src/audio/component.c
67
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
78
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
89
${PROJECT_SOURCE_DIR}/src/audio/mixer/mixer.c

test/cmocka/src/audio/mixer/comp_mock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ static struct comp_driver_info comp_mock_info = {
7979

8080
void sys_comp_mock_init(void)
8181
{
82-
comp_register(&comp_mock_info);
82+
mock_comp_register(&comp_mock_info);
8383
}
8484

test/cmocka/src/audio/mixer/comp_mock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
#define SOF_COMP_MOCK ((uint32_t)-1)
1212

1313
void sys_comp_mock_init(void);
14+
int mock_comp_register(struct comp_driver_info *info);

test/cmocka/src/audio/mixer/mixer_test.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct comp_dev *post_mixer_comp;
3939
struct comp_buffer *post_mixer_buf;
4040

4141
/* Mocking comp_register here so we can register our components properly */
42-
int comp_register(struct comp_driver_info *info)
42+
int mock_comp_register(struct comp_driver_info *info)
4343
{
4444
void *dst;
4545
int err;
@@ -63,6 +63,12 @@ int comp_register(struct comp_driver_info *info)
6363
return err;
6464
}
6565

66+
static void ut_comp_mixer_init(void)
67+
{
68+
mock_comp_register(platform_shared_get(&comp_mixer_info,
69+
sizeof(comp_mixer_info)));
70+
}
71+
6672
struct source {
6773
struct comp_dev *comp;
6874
struct comp_buffer *buf;
@@ -180,7 +186,7 @@ static void activate_periph_comps(struct mix_test_case *tc)
180186

181187
static int test_group_setup(void **state)
182188
{
183-
sys_comp_mixer_init();
189+
ut_comp_mixer_init();
184190
sys_comp_mock_init();
185191

186192
return 0;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ endif()
1919

2020
cmocka_test(pipeline_new
2121
pipeline_new.c
22+
${PROJECT_SOURCE_DIR}/src/audio/component.c
2223
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
2324
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
2425
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
@@ -29,11 +30,13 @@ cmocka_test(pipeline_new
2930
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
3031
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
3132
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
33+
${PROJECT_SOURCE_DIR}/src/audio/component.c
3234
)
3335

3436
cmocka_test(pipeline_connect_upstream
3537
pipeline_connect_upstream.c
3638
pipeline_connection_mocks.c
39+
${PROJECT_SOURCE_DIR}/src/audio/component.c
3740
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
3841
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
3942
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
@@ -44,11 +47,13 @@ cmocka_test(pipeline_connect_upstream
4447
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
4548
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
4649
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
50+
${PROJECT_SOURCE_DIR}/src/audio/component.c
4751
)
4852

4953
cmocka_test(pipeline_free
5054
pipeline_free.c
5155
pipeline_connection_mocks.c
56+
${PROJECT_SOURCE_DIR}/src/audio/component.c
5257
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
5358
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
5459
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
@@ -59,4 +64,5 @@ cmocka_test(pipeline_free
5964
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c
6065
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-stream.c
6166
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-xrun.c
67+
${PROJECT_SOURCE_DIR}/src/audio/component.c
6268
)

0 commit comments

Comments
 (0)