Skip to content

Commit 331e06c

Browse files
committed
test: add a user-space test for PTL
PTL supports user-space, add a boot test for it. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 50dbd53 commit 331e06c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

zephyr/test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ if (CONFIG_SOF_BOOT_TEST)
33
vmh.c
44
)
55
endif()
6+
7+
if (CONFIG_ACE_VERSION_3_0)
8+
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
9+
userspace/ksem.c
10+
)
11+
endif()

zephyr/test/userspace/ksem.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 <zephyr/ztest.h>
10+
#include <zephyr/logging/log.h>
11+
12+
LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG);
13+
14+
#define USER_STACKSIZE 2048
15+
16+
static struct k_thread user_thread;
17+
static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);
18+
K_SEM_DEFINE(user_sem, 0, 1);
19+
20+
static void user_function(void *p1, void *p2, void *p3)
21+
{
22+
__ASSERT(k_is_user_context(), "isn't user");
23+
LOG_INF("SOF thread %s (%s)",
24+
k_is_user_context() ? "UserSpace!" : "privileged mode.",
25+
CONFIG_BOARD_TARGET);
26+
}
27+
28+
static void user_sem_function(void *p1, void *p2, void *p3)
29+
{
30+
__ASSERT(k_is_user_context(), "isn't user");
31+
LOG_INF("SOF thread %s (%s)",
32+
k_is_user_context() ? "UserSpace!" : "privileged mode.",
33+
CONFIG_BOARD_TARGET);
34+
k_sem_give(&user_sem);
35+
}
36+
37+
static void test_user_thread(void)
38+
{
39+
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
40+
user_function, NULL, NULL, NULL,
41+
-1, K_USER, K_MSEC(0));
42+
k_thread_join(&user_thread, K_FOREVER);
43+
}
44+
45+
static void test_user_thread_with_sem(void)
46+
{
47+
/* Start in 10ms to have time to grant the thread access to the semaphore */
48+
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
49+
user_sem_function, NULL, NULL, NULL,
50+
-1, K_USER, K_MSEC(10));
51+
k_thread_access_grant(&user_thread, &user_sem);
52+
k_sem_take(&user_sem, K_FOREVER);
53+
k_thread_join(&user_thread, K_FOREVER);
54+
}
55+
56+
ZTEST(sof_boot, user_space)
57+
{
58+
test_user_thread();
59+
test_user_thread_with_sem();
60+
61+
ztest_test_pass();
62+
}

0 commit comments

Comments
 (0)