Skip to content

Commit 682a53d

Browse files
Andrew Boienashif
authored andcommitted
tests: queue: test k_queue_alloc_*pend()
These were never getting called anywhere from user mode, except for k_queue_alloc_append(), but only by virtue of some workqueue tests. Signed-off-by: Andrew Boie <[email protected]>
1 parent 3f97424 commit 682a53d

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

tests/kernel/queue/src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ static void test_auto_free(void)
1717
{
1818
ztest_test_skip();
1919
}
20+
21+
static void test_queue_alloc_prepend_user(void)
22+
{
23+
ztest_test_skip();
24+
}
25+
26+
static void test_queue_alloc_append_user(void)
27+
{
28+
ztest_test_skip();
29+
}
2030
#endif
31+
K_MEM_POOL_DEFINE(test_pool, 16, 96, 4, 4);
2132

2233
/*test case main entry*/
2334
void test_main(void)
2435
{
36+
k_thread_resource_pool_assign(k_current_get(), &test_pool);
37+
2538
ztest_test_suite(queue_api,
2639
ztest_unit_test(test_queue_supv_to_user),
40+
ztest_user_unit_test(test_queue_alloc_prepend_user),
41+
ztest_user_unit_test(test_queue_alloc_append_user),
2742
ztest_unit_test(test_auto_free),
2843
ztest_unit_test(test_queue_thread2thread),
2944
ztest_unit_test(test_queue_thread2isr),

tests/kernel/queue/src/test_queue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ extern void test_queue_loop(void);
1919
#ifdef CONFIG_USERSPACE
2020
extern void test_queue_supv_to_user(void);
2121
extern void test_auto_free(void);
22+
extern void test_queue_alloc_prepend_user(void);
23+
extern void test_queue_alloc_append_user(void);
2224
#endif
2325
extern void test_queue_alloc(void);
26+
extern struct k_mem_pool test_pool;
2427

2528
typedef struct qdata {
2629
sys_snode_t snode;

tests/kernel/queue/src/test_queue_contexts.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ void test_queue_get_2threads(void)
227227

228228
static void tqueue_alloc(struct k_queue *pqueue)
229229
{
230+
k_thread_resource_pool_assign(k_current_get(), NULL);
231+
230232
/* Alloc append without resource pool */
231233
k_queue_alloc_append(pqueue, (void *)&data_append);
232234

tests/kernel/queue/src/test_queue_user.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ static K_THREAD_STACK_DEFINE(child_stack, STACK_SIZE);
1515
static struct k_thread child_thread;
1616
static ZTEST_BMEM struct qdata qdata[LIST_LEN * 2];
1717

18-
K_MEM_POOL_DEFINE(test_pool, 16, 96, 4, 4);
19-
2018
/**
2119
* @brief Tests for queue
2220
* @defgroup kernel_queue_tests Queues
@@ -76,8 +74,6 @@ void test_queue_supv_to_user(void)
7674
struct k_queue *q;
7775
struct k_sem *sem;
7876

79-
k_thread_resource_pool_assign(k_current_get(), &test_pool);
80-
8177
q = k_object_alloc(K_OBJ_QUEUE);
8278
zassert_not_null(q, "no memory for allocated queue object");
8379
k_queue_init(q);
@@ -113,6 +109,50 @@ void test_queue_supv_to_user(void)
113109
k_sem_take(sem, K_FOREVER);
114110
}
115111

112+
void test_queue_alloc_prepend_user(void)
113+
{
114+
struct k_queue *q;
115+
116+
q = k_object_alloc(K_OBJ_QUEUE);
117+
zassert_not_null(q, "no memory for allocated queue object");
118+
k_queue_init(q);
119+
120+
for (int i = 0; i < LIST_LEN * 2; i++) {
121+
qdata[i].data = i;
122+
zassert_false(k_queue_alloc_prepend(q, &qdata[i]), NULL);
123+
}
124+
125+
for (int i = (LIST_LEN * 2) - 1; i >= 0; i--) {
126+
struct qdata *qd;
127+
128+
qd = k_queue_get(q, K_NO_WAIT);
129+
zassert_true(qd != NULL, NULL);
130+
zassert_equal(qd->data, i, NULL);
131+
}
132+
}
133+
134+
void test_queue_alloc_append_user(void)
135+
{
136+
struct k_queue *q;
137+
138+
q = k_object_alloc(K_OBJ_QUEUE);
139+
zassert_not_null(q, "no memory for allocated queue object");
140+
k_queue_init(q);
141+
142+
for (int i = 0; i < LIST_LEN * 2; i++) {
143+
qdata[i].data = i;
144+
zassert_false(k_queue_alloc_append(q, &qdata[i]), NULL);
145+
}
146+
147+
for (int i = 0; i < LIST_LEN * 2; i++) {
148+
struct qdata *qd;
149+
150+
qd = k_queue_get(q, K_NO_WAIT);
151+
zassert_true(qd != NULL, NULL);
152+
zassert_equal(qd->data, i, NULL);
153+
}
154+
}
155+
116156
/**
117157
* @brief Test to verify free of allocated elements of queue
118158
* @ingroup kernel_queue_tests

0 commit comments

Comments
 (0)