Skip to content

Commit dfbc808

Browse files
committed
test: add vpage and vregion ztests
Add boot-time tests for basic vpage and vregion functionality. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 7ec1269 commit dfbc808

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

zephyr/test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ if(CONFIG_SOF_BOOT_TEST)
22
zephyr_library_sources_ifdef(CONFIG_VIRTUAL_HEAP
33
vmh.c
44
)
5+
zephyr_library_sources_ifdef(CONFIG_SOF_VREGIONS
6+
vpage.c vregion.c
7+
)
58
zephyr_library_sources_ifdef(CONFIG_USERSPACE
69
userspace/ksem.c
710
)

zephyr/test/vpage.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2026 Intel Corporation.
4+
*/
5+
6+
#include <errno.h>
7+
#include <stdbool.h>
8+
#include <stdlib.h>
9+
10+
#include <sof/boot_test.h>
11+
#include <sof/lib/vpage.h>
12+
13+
#include <zephyr/logging/log.h>
14+
#include <zephyr/ztest.h>
15+
16+
LOG_MODULE_DECLARE(sof_boot_test, CONFIG_SOF_LOG_LEVEL);
17+
18+
ZTEST(sof_boot, vpage)
19+
{
20+
void *p1 = vpage_alloc(1);
21+
22+
zassert_not_null(p1);
23+
24+
void *p2 = vpage_alloc(2);
25+
26+
zassert_not_null(p2);
27+
28+
vpage_free(p1);
29+
vpage_free(p2);
30+
31+
p1 = vpage_alloc(2);
32+
33+
zassert_not_null(p1);
34+
35+
vpage_free(p1);
36+
}

zephyr/test/vregion.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2026 Intel Corporation.
4+
*/
5+
6+
#include <errno.h>
7+
#include <stdbool.h>
8+
#include <stdlib.h>
9+
10+
#include <sof/boot_test.h>
11+
#include <sof/lib/vregion.h>
12+
13+
#include <zephyr/logging/log.h>
14+
#include <zephyr/ztest.h>
15+
16+
LOG_MODULE_DECLARE(sof_boot_test, CONFIG_SOF_LOG_LEVEL);
17+
18+
static struct vregion *test_vreg_create(void)
19+
{
20+
struct vregion *vreg = vregion_create(CONFIG_MM_DRV_PAGE_SIZE - 100,
21+
CONFIG_MM_DRV_PAGE_SIZE);
22+
23+
zassert_not_null(vreg);
24+
25+
return vreg;
26+
}
27+
28+
static void test_vreg_alloc_lifet(struct vregion *vreg)
29+
{
30+
void *ptr = vregion_alloc(vreg, VREGION_MEM_TYPE_LIFETIME, 2000);
31+
32+
zassert_not_null(ptr);
33+
34+
void *ptr_align = vregion_alloc_align(vreg, VREGION_MEM_TYPE_LIFETIME, 2000, 16);
35+
36+
zassert_not_null(ptr_align);
37+
zassert_equal((uintptr_t)ptr_align & 15, 0);
38+
39+
void *ptr_nomem = vregion_alloc(vreg, VREGION_MEM_TYPE_LIFETIME, 2000);
40+
41+
zassert_is_null(ptr_nomem);
42+
43+
vregion_free(vreg, ptr_align);
44+
vregion_free(vreg, ptr);
45+
46+
/* Freeing isn't possible with LIFETIME */
47+
ptr_nomem = vregion_alloc(vreg, VREGION_MEM_TYPE_LIFETIME, 2000);
48+
49+
zassert_is_null(ptr_nomem);
50+
}
51+
52+
static void test_vreg_alloc_tmp(struct vregion *vreg)
53+
{
54+
void *ptr = vregion_alloc(vreg, VREGION_MEM_TYPE_INTERIM, 20);
55+
56+
zassert_not_null(ptr);
57+
58+
void *ptr_align = vregion_alloc_align(vreg, VREGION_MEM_TYPE_INTERIM, 2000, 16);
59+
60+
zassert_not_null(ptr_align);
61+
zassert_equal((uintptr_t)ptr_align & 15, 0);
62+
63+
void *ptr_nomem = vregion_alloc(vreg, VREGION_MEM_TYPE_INTERIM, 2000);
64+
65+
zassert_is_null(ptr_nomem);
66+
67+
vregion_free(vreg, ptr_align);
68+
vregion_free(vreg, ptr);
69+
70+
/* Should be possible to allocate again */
71+
ptr = vregion_alloc(vreg, VREGION_MEM_TYPE_INTERIM, 2000);
72+
73+
zassert_not_null(ptr);
74+
}
75+
76+
static void test_vreg_destroy(struct vregion *vreg)
77+
{
78+
vregion_info(vreg);
79+
vregion_destroy(vreg);
80+
}
81+
82+
ZTEST(sof_boot, vregion)
83+
{
84+
struct vregion *vreg = test_vreg_create();
85+
86+
/* Test interim allocations */
87+
test_vreg_alloc_tmp(vreg);
88+
/* Test lifetime allocations */
89+
test_vreg_alloc_lifet(vreg);
90+
91+
test_vreg_destroy(vreg);
92+
}

0 commit comments

Comments
 (0)