Skip to content

Commit

Permalink
debug: use a boot-time test runner to test virtual heap
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lyakh committed Jul 27, 2023
1 parent 4936396 commit 4f3ae65
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/debug_overlay.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CONFIG_DEBUG=y
CONFIG_ASSERT=y
CONFIG_SOF_BOOT_TEST=y

# Following options can be enabled additionally,
# but will incur a higher runtime cost, so are thus
Expand Down
44 changes: 44 additions & 0 deletions src/include/sof/boot_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
*/

#ifndef __SOF_BOOT_TEST_H__
#define __SOF_BOOT_TEST_H__

#include <sof/list.h>
#include <zephyr/init.h>

struct boot_test {
struct list_item list;
int (*test)(void);
};

#if CONFIG_SOF_BOOT_TEST
void sof_boot_test(void);
void sof_boot_test_register(struct boot_test *test);
#else
#define sof_boot_test() do {} while (0)
#define sof_boot_test_register(x) do {} while (0)
#endif

#define SOF_BOOT_TEST(x) \
static struct boot_test x##_test = {.test = x}; \
static int x##_init(void) \
{ \
sof_boot_test_register(&x##_test); \
return 0; \
} \
SYS_INIT(x##_init, APPLICATION, 0)

#define run_once(fn, ...) do { \
static bool once; \
if (!once) { \
once = true; \
fn(__VA_ARGS__); \
} \
} while (0)

#endif
9 changes: 9 additions & 0 deletions src/ipc/ipc4/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <sof/audio/buffer.h>
#include <sof/audio/component_ext.h>
#include <sof/audio/pipeline.h>
#include <sof/boot_test.h>
#include <sof/common.h>
#include <sof/ipc/topology.h>
#include <sof/ipc/common.h>
Expand Down Expand Up @@ -1226,4 +1227,12 @@ void ipc_cmd(struct ipc_cmd_hdr *_hdr)

ipc_msg_send(&msg_reply, data, true);
}

/*
* When the first FW_GEN IPC has been processed we are in a stable
* running state, now if a test causes an exception, we have a good
* chance of capturing it.
*/
if (target == SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG)
run_once(sof_boot_test);
}
10 changes: 10 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,16 @@ zephyr_library_sources_ifdef(CONFIG_DW_DMA
${SOF_DRIVERS_PATH}/dw/dma.c
)

zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
boot_test.c
)

if (CONFIG_ACE_VERSION_1_5)
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
test/vmh.c
)
endif()

zephyr_library_link_libraries(SOF)
target_link_libraries(SOF INTERFACE zephyr_interface)

Expand Down
5 changes: 5 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ config ZEPHYR_DP_SCHEDULER
DP modules can be located in dieffrent cores than LL pipeline modules, may have
different tick (i.e. 300ms for speech reccognition, etc.)

config SOF_BOOT_TEST
bool "enable SOF run-time testing"
help
run tests during boot

endif
37 changes: 37 additions & 0 deletions zephyr/boot_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
*/

/* need zephyr_tr */
#include <rtos/interrupt.h>

#include <sof/boot_test.h>
#include <sof/list.h>
#include <sof/trace/trace.h>

#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(boot_test, CONFIG_SOF_LOG_LEVEL);

static struct list_item test_list = LIST_INIT(test_list);

void sof_boot_test_register(struct boot_test *test)
{
list_item_append(&test->list, &test_list);
}

void sof_boot_test(void)
{
struct list_item *list;

list_for_item (list, &test_list) {
struct boot_test *test = list_item(list, struct boot_test, list);
/* TODO: measure time */
int ret = test->test();

tr_info(&zephyr_tr, "test %p returned %d", test->test, ret);
}
}
25 changes: 25 additions & 0 deletions zephyr/test/vmh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
*/

#include <errno.h>
#include <stdbool.h>

#include <adsp_memory_regions.h>
#include <sof/boot_test.h>
#include <sof/lib/regions_mm.h>

static int vmh_test(void)
{
struct virtual_memory_heap *h = vmh_init_heap(NULL, MEM_REG_ATTR_CORE_HEAP, 0, false);

if (!h)
return -EINVAL;

return vmh_free_heap(h);
}

SOF_BOOT_TEST(vmh_test);

0 comments on commit 4f3ae65

Please sign in to comment.