Skip to content

Commit 4f3ae65

Browse files
committed
debug: use a boot-time test runner to test virtual heap
Add a simple API to run tests at start up and use it to test the virtual heap allocator. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 4936396 commit 4f3ae65

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

app/debug_overlay.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONFIG_DEBUG=y
22
CONFIG_ASSERT=y
3+
CONFIG_SOF_BOOT_TEST=y
34

45
# Following options can be enabled additionally,
56
# but will incur a higher runtime cost, so are thus

src/include/sof/boot_test.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
*
3+
* Copyright(c) 2023 Intel Corporation. All rights reserved.
4+
*
5+
* Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
6+
*/
7+
8+
#ifndef __SOF_BOOT_TEST_H__
9+
#define __SOF_BOOT_TEST_H__
10+
11+
#include <sof/list.h>
12+
#include <zephyr/init.h>
13+
14+
struct boot_test {
15+
struct list_item list;
16+
int (*test)(void);
17+
};
18+
19+
#if CONFIG_SOF_BOOT_TEST
20+
void sof_boot_test(void);
21+
void sof_boot_test_register(struct boot_test *test);
22+
#else
23+
#define sof_boot_test() do {} while (0)
24+
#define sof_boot_test_register(x) do {} while (0)
25+
#endif
26+
27+
#define SOF_BOOT_TEST(x) \
28+
static struct boot_test x##_test = {.test = x}; \
29+
static int x##_init(void) \
30+
{ \
31+
sof_boot_test_register(&x##_test); \
32+
return 0; \
33+
} \
34+
SYS_INIT(x##_init, APPLICATION, 0)
35+
36+
#define run_once(fn, ...) do { \
37+
static bool once; \
38+
if (!once) { \
39+
once = true; \
40+
fn(__VA_ARGS__); \
41+
} \
42+
} while (0)
43+
44+
#endif

src/ipc/ipc4/handler.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sof/audio/buffer.h>
1515
#include <sof/audio/component_ext.h>
1616
#include <sof/audio/pipeline.h>
17+
#include <sof/boot_test.h>
1718
#include <sof/common.h>
1819
#include <sof/ipc/topology.h>
1920
#include <sof/ipc/common.h>
@@ -1226,4 +1227,12 @@ void ipc_cmd(struct ipc_cmd_hdr *_hdr)
12261227

12271228
ipc_msg_send(&msg_reply, data, true);
12281229
}
1230+
1231+
/*
1232+
* When the first FW_GEN IPC has been processed we are in a stable
1233+
* running state, now if a test causes an exception, we have a good
1234+
* chance of capturing it.
1235+
*/
1236+
if (target == SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG)
1237+
run_once(sof_boot_test);
12291238
}

zephyr/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,16 @@ zephyr_library_sources_ifdef(CONFIG_DW_DMA
763763
${SOF_DRIVERS_PATH}/dw/dma.c
764764
)
765765

766+
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
767+
boot_test.c
768+
)
769+
770+
if (CONFIG_ACE_VERSION_1_5)
771+
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
772+
test/vmh.c
773+
)
774+
endif()
775+
766776
zephyr_library_link_libraries(SOF)
767777
target_link_libraries(SOF INTERFACE zephyr_interface)
768778

zephyr/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ config ZEPHYR_DP_SCHEDULER
5656
DP modules can be located in dieffrent cores than LL pipeline modules, may have
5757
different tick (i.e. 300ms for speech reccognition, etc.)
5858

59+
config SOF_BOOT_TEST
60+
bool "enable SOF run-time testing"
61+
help
62+
run tests during boot
63+
5964
endif

zephyr/boot_test.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2023 Intel Corporation. All rights reserved.
4+
*
5+
* Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
6+
*/
7+
8+
/* need zephyr_tr */
9+
#include <rtos/interrupt.h>
10+
11+
#include <sof/boot_test.h>
12+
#include <sof/list.h>
13+
#include <sof/trace/trace.h>
14+
15+
#include <zephyr/logging/log.h>
16+
17+
LOG_MODULE_REGISTER(boot_test, CONFIG_SOF_LOG_LEVEL);
18+
19+
static struct list_item test_list = LIST_INIT(test_list);
20+
21+
void sof_boot_test_register(struct boot_test *test)
22+
{
23+
list_item_append(&test->list, &test_list);
24+
}
25+
26+
void sof_boot_test(void)
27+
{
28+
struct list_item *list;
29+
30+
list_for_item (list, &test_list) {
31+
struct boot_test *test = list_item(list, struct boot_test, list);
32+
/* TODO: measure time */
33+
int ret = test->test();
34+
35+
tr_info(&zephyr_tr, "test %p returned %d", test->test, ret);
36+
}
37+
}

zephyr/test/vmh.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2023 Intel Corporation. All rights reserved.
4+
*
5+
* Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
6+
*/
7+
8+
#include <errno.h>
9+
#include <stdbool.h>
10+
11+
#include <adsp_memory_regions.h>
12+
#include <sof/boot_test.h>
13+
#include <sof/lib/regions_mm.h>
14+
15+
static int vmh_test(void)
16+
{
17+
struct virtual_memory_heap *h = vmh_init_heap(NULL, MEM_REG_ATTR_CORE_HEAP, 0, false);
18+
19+
if (!h)
20+
return -EINVAL;
21+
22+
return vmh_free_heap(h);
23+
}
24+
25+
SOF_BOOT_TEST(vmh_test);

0 commit comments

Comments
 (0)