Skip to content

Commit 9ecca3b

Browse files
committed
zephyr: test: add test case for user-space ll scheduling
Add a test case to run tasks with low-latency (LL) scheduler in user-space. The test does not yet use any audio pipeline functionality, but uses similar interfaces towards the SOF scheduler interface. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 9a465e5 commit 9ecca3b

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

zephyr/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ endif()
1919
if (CONFIG_SOF_BOOT_TEST_STANDALONE AND CONFIG_USERSPACE)
2020
zephyr_library_sources(userspace/test_mailbox.c)
2121
endif()
22+
23+
if (CONFIG_SOF_BOOT_TEST_STANDALONE AND CONFIG_SOF_USERSPACE_LL)
24+
zephyr_library_sources(userspace/test_ll_task.c)
25+
endif()

zephyr/test/userspace/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ Available tests:
1212
- Test Zephyr DAI interface, together with SOF DMA
1313
wrapper from a user thread. Mimics the call flows done in
1414
sof/src/audio/dai-zephyr.c. Use cavstool.py as host runner.
15+
- test_ll_test.c
16+
- Test Low-Latency (LL) scheduler in user-space mode. Creates
17+
a user-space LL scheduler, and uses it to create and run tasks.
18+
- Tests functionality used by SOF audio pipeline framework to
19+
create tasks for audio pipeline logic.
1520
- test_mailbox.c
1621
- Test use of sof/mailbox.h interface from a Zephyr user thread.
1722

1823
Building for Intel Panther Lake:
1924
./scripts/xtensa-build-zephyr.py --cmake-args=-DCONFIG_SOF_BOOT_TEST_STANDALONE=y \
2025
--cmake-args=-DCONFIG_SOF_USERSPACE_INTERFACE_DMA=y \
26+
--cmake-args=-DCONFIG_SOF_USERSPACE_LL=y \
2127
-o app/overlays/ptl/userspace_overlay.conf -o app/winconsole_overlay.conf ptl
2228

2329
Running test:
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2026 Intel Corporation.
4+
*/
5+
6+
/*
7+
* Test case for creation of low-latency threads in user-space.
8+
*/
9+
10+
#include <sof/boot_test.h>
11+
#include <sof/lib/mailbox.h>
12+
#include <sof/lib/uuid.h>
13+
#include <sof/schedule/schedule.h>
14+
#include <sof/schedule/ll_schedule.h>
15+
#include <rtos/task.h>
16+
#include <rtos/userspace_helper.h>
17+
#include <ipc4/fw_reg.h>
18+
19+
#include <zephyr/kernel.h>
20+
#include <zephyr/ztest.h>
21+
#include <zephyr/logging/log.h>
22+
#include <zephyr/app_memory/app_memdomain.h>
23+
24+
#include <stddef.h> /* offsetof() */
25+
26+
LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG);
27+
28+
/* f11818eb-e92e-4082-82a3-dc54c604ebf3 */
29+
SOF_DEFINE_UUID("test_task", test_task_uuid, 0xf11818eb, 0xe92e, 0x4082,
30+
0x82, 0xa3, 0xdc, 0x54, 0xc6, 0x04, 0xeb, 0xf3);
31+
32+
K_APPMEM_PARTITION_DEFINE(userspace_ll_part);
33+
34+
/* Global variable for test runs counter, accessible from user-space */
35+
K_APP_BMEM(userspace_ll_part) static int test_runs;
36+
37+
static enum task_state task_callback(void *arg)
38+
{
39+
LOG_INF("entry");
40+
41+
if (++test_runs > 3)
42+
return SOF_TASK_STATE_COMPLETED;
43+
44+
return SOF_TASK_STATE_RESCHEDULE;
45+
}
46+
47+
static void ll_task_test(void)
48+
{
49+
struct task *task;
50+
int priority = 0;
51+
int core = 0;
52+
int ret;
53+
54+
/* Initialize global test runs counter */
55+
test_runs = 0;
56+
57+
task = zephyr_ll_task_alloc();
58+
59+
/* allow user space to report status via 'test_runs' */
60+
k_mem_domain_add_partition(zephyr_ll_mem_domain(), &userspace_ll_part);
61+
62+
/* work in progress, see pipeline-schedule.c */
63+
ret = schedule_task_init_ll(task, SOF_UUID(test_task_uuid), SOF_SCHEDULE_LL_TIMER,
64+
priority, task_callback,
65+
(void *)&test_runs, core, 0);
66+
zassert_equal(ret, 0);
67+
68+
LOG_INF("task init done");
69+
70+
/* Schedule the task to run immediately with 1ms period */
71+
ret = schedule_task(task, 0, 1000); /* 0 = start now, 1000us = 1ms period */
72+
zassert_equal(ret, 0);
73+
74+
LOG_INF("task scheduled and running");
75+
76+
/* Let the task run for a bit */
77+
k_sleep(K_MSEC(10));
78+
79+
/* Cancel the task to stop any scheduled execution */
80+
ret = schedule_task_cancel(task);
81+
zassert_equal(ret, 0);
82+
83+
/* Free task resources */
84+
ret = schedule_task_free(task);
85+
zassert_equal(ret, 0);
86+
87+
LOG_INF("test complete");
88+
}
89+
90+
ZTEST(userspace_ll, ll_task_test)
91+
{
92+
ll_task_test();
93+
ztest_test_pass();
94+
}
95+
96+
ZTEST_SUITE(userspace_ll, NULL, NULL, NULL, NULL, NULL);
97+
98+
/**
99+
* SOF main has booted up and IPC handling is stopped.
100+
* Run test suites with ztest_run_all.
101+
*/
102+
static int run_tests(void)
103+
{
104+
ztest_run_test_suite(userspace_ll, false, 1, 1, NULL);
105+
return 0;
106+
}
107+
108+
SYS_INIT(run_tests, APPLICATION, 99);

0 commit comments

Comments
 (0)