From b91f962752e540f949a8b86c471286e095e9bbb8 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 15 Jul 2025 17:00:39 +0200 Subject: [PATCH 1/6] boot-test: fix build after an API change SYS_INIT() API has changed, initialisation functions now have to return an integer error code. Fix building SOF boot-test. Signed-off-by: Guennadi Liakhovetski --- zephyr/boot_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zephyr/boot_test.c b/zephyr/boot_test.c index 4cbbfa597d8b..22cbead7ead4 100644 --- a/zephyr/boot_test.c +++ b/zephyr/boot_test.c @@ -12,9 +12,10 @@ LOG_MODULE_REGISTER(sof_boot_test, LOG_LEVEL_DBG); ZTEST_SUITE(sof_boot, NULL, NULL, NULL, NULL, NULL); -void sys_run_boot_tests(void) +int sys_run_boot_tests(void) { ztest_run_all(NULL, false, 1, 1); + return 0; } SYS_INIT(sys_run_boot_tests, APPLICATION, 99); From 5beea0f3eaa2d433cc2e83ca2a63e08d5f2f2270 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 15 Jul 2025 17:03:13 +0200 Subject: [PATCH 2/6] boot-test: vmh: fix build and enable on ACE 2.0 and 3.0 Fix a recent VMH test build breakage and enable it on newer ACE platforms. Signed-off-by: Guennadi Liakhovetski --- zephyr/test/CMakeLists.txt | 8 ++++---- zephyr/test/vmh.c | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/zephyr/test/CMakeLists.txt b/zephyr/test/CMakeLists.txt index e0718b8e0754..ad795f36528d 100644 --- a/zephyr/test/CMakeLists.txt +++ b/zephyr/test/CMakeLists.txt @@ -1,5 +1,5 @@ -if (CONFIG_ACE_VERSION_1_5) - zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST - vmh.c - ) +if (CONFIG_ACE_VERSION_1_5 OR CONFIG_ACE_VERSION_2_0 OR CONFIG_ACE_VERSION_3_0) + zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST + vmh.c + ) endif() diff --git a/zephyr/test/vmh.c b/zephyr/test/vmh.c index 26e044a2d9f0..4a1b7365c4be 100644 --- a/zephyr/test/vmh.c +++ b/zephyr/test/vmh.c @@ -110,7 +110,6 @@ static void test_vmh_multiple_allocs(struct vmh_heap *heap, int num_allocs, { void *ptrs[num_allocs]; uint32_t alloc_size; - bool success; int ret; /* Perform multiple allocations */ @@ -192,7 +191,7 @@ static void test_vmh_alloc_free(bool allocating_continuously) /* Test case for vmh_alloc and vmh_free with and without config */ static void test_heap_creation(void) { - test_vmh_init_and_free_heap(NULL, 0, false, true); + test_vmh_init_and_free_heap(NULL, false, true); /* Try to setup with pre defined heap config */ struct vmh_heap_config config = {0}; @@ -205,7 +204,7 @@ static void test_heap_creation(void) config.block_bundles_table[1].number_of_blocks = 512; - test_vmh_init_and_free_heap(&config, 0, false, true); + test_vmh_init_and_free_heap(&config, false, true); } /* Test case for alloc/free on configured heap */ From 80e70f61a330216480d935c5ac2e377f89174b14 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 15 Jul 2025 16:50:33 +0200 Subject: [PATCH 3/6] test: add a user-space test for PTL PTL supports user-space, add a boot test for it. Signed-off-by: Guennadi Liakhovetski --- src/include/sof/sof_syscall.h | 18 +++++++++ zephyr/CMakeLists.txt | 5 +++ zephyr/syscall/sof_local_lock.c | 33 ++++++++++++++++ zephyr/test/CMakeLists.txt | 6 +++ zephyr/test/userspace/local_lock.c | 61 ++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 src/include/sof/sof_syscall.h create mode 100644 zephyr/syscall/sof_local_lock.c create mode 100644 zephyr/test/userspace/local_lock.c diff --git a/src/include/sof/sof_syscall.h b/src/include/sof/sof_syscall.h new file mode 100644 index 000000000000..963dd8fb49f1 --- /dev/null +++ b/src/include/sof/sof_syscall.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2025, Intel Corporation. + */ + +#ifndef SOF_SYSCALL +#define SOF_SYSCALL + +#include + +#include + +__syscall uint32_t sof_local_lock(void); +__syscall void sof_local_unlock(uint32_t flags); + +#include + +#endif diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 071219fd9d04..a87c7e162f7a 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -466,6 +466,11 @@ if(NOT DEFINED PLATFORM) endif() zephyr_include_directories(${SOF_PLATFORM_PATH}/${PLATFORM}/include) +zephyr_library_sources_ifdef(CONFIG_USERSPACE + syscall/sof_local_lock.c +) +zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/sof_syscall.h) + # Mandatory Files used on all platforms. # Commented files will be added/removed as integration dictates. zephyr_library_sources( diff --git a/zephyr/syscall/sof_local_lock.c b/zephyr/syscall/sof_local_lock.c new file mode 100644 index 000000000000..06524a0a6f6b --- /dev/null +++ b/zephyr/syscall/sof_local_lock.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2025 Intel Corporation. + +#include +#include + +uint32_t z_impl_sof_local_lock(void) +{ + uint32_t flags; + + irq_local_disable(flags); + return flags; +} + +void z_impl_sof_local_unlock(uint32_t flags) +{ + irq_local_enable(flags); +} + +#ifdef CONFIG_USERSPACE +static inline uint32_t z_vrfy_sof_local_lock(void) +{ + return z_impl_sof_local_lock(); +} +#include + +static inline void z_vrfy_sof_local_unlock(uint32_t flags) +{ + z_impl_sof_local_unlock(flags); +} +#include +#endif /* CONFIG_USERSPACE */ diff --git a/zephyr/test/CMakeLists.txt b/zephyr/test/CMakeLists.txt index ad795f36528d..75999fc244e3 100644 --- a/zephyr/test/CMakeLists.txt +++ b/zephyr/test/CMakeLists.txt @@ -3,3 +3,9 @@ if (CONFIG_ACE_VERSION_1_5 OR CONFIG_ACE_VERSION_2_0 OR CONFIG_ACE_VERSION_3_0) vmh.c ) endif() + +if (CONFIG_ACE_VERSION_3_0) + zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST + userspace/local_lock.c + ) +endif() diff --git a/zephyr/test/userspace/local_lock.c b/zephyr/test/userspace/local_lock.c new file mode 100644 index 000000000000..0be0a8eb5635 --- /dev/null +++ b/zephyr/test/userspace/local_lock.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright(c) 2025 Intel Corporation. + */ + +#include +#include + +#include +#include +#include + +LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG); + +#define USER_STACKSIZE 2048 + +static struct k_thread user_thread; +static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE); + +static void user_function(void *p1, void *p2, void *p3) +{ + __ASSERT(k_is_user_context(), "isn't user"); + LOG_INF("SOF thread %s (%s)", + k_is_user_context() ? "UserSpace!" : "privileged mode.", + CONFIG_BOARD_TARGET); +} + +static void user_lock_function(void *p1, void *p2, void *p3) +{ + uint32_t flags = sof_local_lock(); + + __ASSERT(k_is_user_context(), "isn't user"); + LOG_INF("SOF thread %s (%s)", + k_is_user_context() ? "UserSpace!" : "privileged mode.", + CONFIG_BOARD_TARGET); + sof_local_unlock(flags); +} + +static void test_user_thread(void) +{ + k_thread_create(&user_thread, user_stack, USER_STACKSIZE, + user_function, NULL, NULL, NULL, + -1, K_USER, K_MSEC(0)); + k_thread_join(&user_thread, K_FOREVER); +} + +static void test_user_thread_with_lock(void) +{ + k_thread_create(&user_thread, user_stack, USER_STACKSIZE, + user_lock_function, NULL, NULL, NULL, + -1, K_USER, K_MSEC(0)); + k_thread_join(&user_thread, K_FOREVER); +} + +ZTEST(sof_boot, user_space) +{ + test_user_thread(); + test_user_thread_with_lock(); + + ztest_test_pass(); +} From 59b52c871a2f8c855fe76d6a6d1a34578012d7c5 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 15 Jul 2025 17:07:15 +0200 Subject: [PATCH 4/6] boot-test: enable by default in debug builds Re-enable boot-testing now that the DSP panic has been fixed. Signed-off-by: Guennadi Liakhovetski --- app/boards/intel_adsp_ace30_ptl.conf | 4 ++++ app/debug_overlay.conf | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/boards/intel_adsp_ace30_ptl.conf b/app/boards/intel_adsp_ace30_ptl.conf index a90abefa38e5..78c170e920da 100644 --- a/app/boards/intel_adsp_ace30_ptl.conf +++ b/app/boards/intel_adsp_ace30_ptl.conf @@ -90,3 +90,7 @@ CONFIG_LOG_MODE_DEFERRED=y CONFIG_LOG_OUTPUT_FORMAT_LINUX_TIMESTAMP=y CONFIG_LOG_TIMESTAMP_64BIT=y CONFIG_WINSTREAM_CONSOLE=n + +CONFIG_USERSPACE=y +CONFIG_APPLICATION_DEFINED_SYSCALL=y +CONFIG_MAX_THREAD_BYTES=3 diff --git a/app/debug_overlay.conf b/app/debug_overlay.conf index 650b3c09f7f2..4cc9a9207f3f 100644 --- a/app/debug_overlay.conf +++ b/app/debug_overlay.conf @@ -1,9 +1,8 @@ CONFIG_DEBUG=y CONFIG_ASSERT=y -# Disabled until DSP panic #8621 is fixed -# CONFIG_ZTEST=y -# CONFIG_SOF_BOOT_TEST=y +CONFIG_ZTEST=y +CONFIG_SOF_BOOT_TEST=y CONFIG_DAI_VERBOSE_GLITCH_WARNINGS=y From a561fea0f4a0c712b6fc37f66307e96c30d63561 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Wed, 24 Sep 2025 21:48:09 +0300 Subject: [PATCH 5/6] --break-- below is PR10119 tip, needs to be merged first Link: https://github.com/thesofproject/sof/pull/10119 From 868ddf5708f0f3ca0dcfc0a95534a0eacaa53352 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Wed, 24 Sep 2025 13:22:58 +0300 Subject: [PATCH 6/6] zephyr: tests: userspace: add test for cache ops via syscalls Add simple tests that call cache invalidate and flush from a user-space thread. This does not currently have any negative tests (attempt to invalidate an buffer the user space thread does not have access to), as these currently result in kernel oops on xtensa. Signed-off-by: Kai Vehmanen --- zephyr/test/CMakeLists.txt | 1 + zephyr/test/userspace/cache.c | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 zephyr/test/userspace/cache.c diff --git a/zephyr/test/CMakeLists.txt b/zephyr/test/CMakeLists.txt index 75999fc244e3..f757ea73a995 100644 --- a/zephyr/test/CMakeLists.txt +++ b/zephyr/test/CMakeLists.txt @@ -6,6 +6,7 @@ endif() if (CONFIG_ACE_VERSION_3_0) zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST + userspace/cache.c userspace/local_lock.c ) endif() diff --git a/zephyr/test/userspace/cache.c b/zephyr/test/userspace/cache.c new file mode 100644 index 000000000000..18df6373be18 --- /dev/null +++ b/zephyr/test/userspace/cache.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright(c) 2025 Intel Corporation. + */ + +#include + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG); + +#define USER_STACKSIZE 2048 + +static struct k_thread user_thread; +static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE); + +static void user_function(void *p1, void *p2, void *p3) +{ + char stack_buf[64]; + + __ASSERT(k_is_user_context(), "isn't user"); + + LOG_INF("SOF thread %s (%s)", + k_is_user_context() ? "UserSpace!" : "privileged mode.", + CONFIG_BOARD_TARGET); + + /* + * Use rtos/cache.h calls as these are also used by + * src/audio code. + */ + + dcache_writeback_region(stack_buf, sizeof(stack_buf)); + + dcache_invalidate_region(stack_buf, sizeof(stack_buf)); +} + +static void test_user_thread_cache(void) +{ + k_thread_create(&user_thread, user_stack, USER_STACKSIZE, + user_function, NULL, NULL, NULL, + -1, K_USER, K_MSEC(0)); + k_thread_join(&user_thread, K_FOREVER); +} + +ZTEST(sof_boot, user_space_cache) +{ + test_user_thread_cache(); + + ztest_test_pass(); +}