Skip to content

Commit 5ec00d7

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 c743cbc commit 5ec00d7

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

src/include/sof/sof_syscall.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
*
3+
* Copyright (c) 2025, Intel Corporation.
4+
*/
5+
6+
#ifndef SOF_SYSCALL
7+
#define SOF_SYSCALL
8+
9+
#include <zephyr/toolchain.h>
10+
11+
#include <stdint.h>
12+
13+
__syscall uint32_t sof_local_lock(void);
14+
__syscall void sof_local_unlock(uint32_t flags);
15+
16+
#include <zephyr/syscalls/sof_syscall.h>
17+
18+
#endif

zephyr/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ if(NOT DEFINED PLATFORM)
465465
endif()
466466
zephyr_include_directories(${SOF_PLATFORM_PATH}/${PLATFORM}/include)
467467

468+
zephyr_library_sources_ifdef(CONFIG_USERSPACE
469+
syscall/sof_local_lock.c
470+
)
471+
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/sof_syscall.h)
472+
468473
# Mandatory Files used on all platforms.
469474
# Commented files will be added/removed as integration dictates.
470475
zephyr_library_sources(

zephyr/syscall/sof_local_lock.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright(c) 2025 Intel Corporation.
4+
5+
#include <sof/sof_syscall.h>
6+
#include <rtos/interrupt.h>
7+
8+
uint32_t z_impl_sof_local_lock(void)
9+
{
10+
uint32_t flags;
11+
12+
irq_local_disable(flags);
13+
return flags;
14+
}
15+
16+
void z_impl_sof_local_unlock(uint32_t flags)
17+
{
18+
irq_local_enable(flags);
19+
}
20+
21+
#ifdef CONFIG_USERSPACE
22+
static inline uint32_t z_vrfy_sof_local_lock(void)
23+
{
24+
return z_impl_sof_local_lock();
25+
}
26+
#include <zephyr/syscalls/sof_local_lock_mrsh.c>
27+
28+
static inline void z_vrfy_sof_local_unlock(uint32_t flags)
29+
{
30+
z_impl_sof_local_unlock(flags);
31+
}
32+
#include <zephyr/syscalls/sof_local_unlock_mrsh.c>
33+
#endif /* CONFIG_USERSPACE */

zephyr/test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ if (CONFIG_ACE_VERSION_1_5)
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/local_lock.c
10+
)
11+
endif()

zephyr/test/userspace/local_lock.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2025 Intel Corporation.
4+
*/
5+
6+
#include <sof/boot_test.h>
7+
#include <sof/sof_syscall.h>
8+
9+
#include <zephyr/kernel.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+
__ASSERT(k_is_user_context(), "isn't user");
23+
printf("SOF thread %s (%s)\n",
24+
k_is_user_context() ? "UserSpace!" : "privileged mode.",
25+
CONFIG_BOARD_TARGET);
26+
}
27+
28+
static void user_lock_function(void *p1, void *p2, void *p3)
29+
{
30+
uint32_t flags = sof_local_lock();
31+
32+
__ASSERT(k_is_user_context(), "isn't user");
33+
printf("SOF thread %s (%s)\n",
34+
k_is_user_context() ? "UserSpace!" : "privileged mode.",
35+
CONFIG_BOARD_TARGET);
36+
sof_local_unlock(flags);
37+
}
38+
39+
static void test_user_thread(void)
40+
{
41+
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
42+
user_function, NULL, NULL, NULL,
43+
-1, K_USER, K_MSEC(0));
44+
k_thread_join(&user_thread, K_FOREVER);
45+
}
46+
47+
static void test_user_thread_with_lock(void)
48+
{
49+
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
50+
user_lock_function, NULL, NULL, NULL,
51+
-1, K_USER, K_MSEC(0));
52+
k_thread_join(&user_thread, K_FOREVER);
53+
}
54+
55+
ZTEST(sof_boot, user_space)
56+
{
57+
test_user_thread();
58+
test_user_thread_with_lock();
59+
60+
ztest_test_pass();
61+
}

0 commit comments

Comments
 (0)