Skip to content

Commit 30a56b6

Browse files
kv2019ilgirdwood
authored andcommitted
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 19a5733 commit 30a56b6

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)