|
| 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