Skip to content

Commit 868ddf5

Browse files
committed
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 <kai.vehmanen@linux.intel.com>
1 parent a561fea commit 868ddf5

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

zephyr/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ endif()
66

77
if (CONFIG_ACE_VERSION_3_0)
88
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
9+
userspace/cache.c
910
userspace/local_lock.c
1011
)
1112
endif()

zephyr/test/userspace/cache.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2025 Intel Corporation.
4+
*/
5+
6+
#include <sof/boot_test.h>
7+
8+
#include <zephyr/kernel.h>
9+
#include <rtos/cache.h>
10+
#include <zephyr/ztest.h>
11+
#include <zephyr/logging/log.h>
12+
13+
LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG);
14+
15+
#define USER_STACKSIZE 2048
16+
17+
static struct k_thread user_thread;
18+
static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);
19+
20+
static void user_function(void *p1, void *p2, void *p3)
21+
{
22+
char stack_buf[64];
23+
24+
__ASSERT(k_is_user_context(), "isn't user");
25+
26+
LOG_INF("SOF thread %s (%s)",
27+
k_is_user_context() ? "UserSpace!" : "privileged mode.",
28+
CONFIG_BOARD_TARGET);
29+
30+
/*
31+
* Use rtos/cache.h calls as these are also used by
32+
* src/audio code.
33+
*/
34+
35+
dcache_writeback_region(stack_buf, sizeof(stack_buf));
36+
37+
dcache_invalidate_region(stack_buf, sizeof(stack_buf));
38+
}
39+
40+
static void test_user_thread_cache(void)
41+
{
42+
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
43+
user_function, NULL, NULL, NULL,
44+
-1, K_USER, K_MSEC(0));
45+
k_thread_join(&user_thread, K_FOREVER);
46+
}
47+
48+
ZTEST(sof_boot, user_space_cache)
49+
{
50+
test_user_thread_cache();
51+
52+
ztest_test_pass();
53+
}

0 commit comments

Comments
 (0)