1 /*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "test_msgq.h"
7
8 static ZTEST_BMEM char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
9 static ZTEST_DMEM uint32_t data[MSGQ_LEN] = { MSG0, MSG1 };
10 extern struct k_msgq msgq;
11
put_fail(struct k_msgq * q)12 static void put_fail(struct k_msgq *q)
13 {
14 int ret = k_msgq_put(q, (void *)&data[0], K_NO_WAIT);
15
16 zassert_false(ret);
17 ret = k_msgq_put(q, (void *)&data[0], K_NO_WAIT);
18 zassert_false(ret);
19 /**TESTPOINT: msgq put returns -ENOMSG*/
20 ret = k_msgq_put(q, (void *)&data[1], K_NO_WAIT);
21 zassert_equal(ret, -ENOMSG);
22 /**TESTPOINT: msgq put returns -EAGAIN*/
23 ret = k_msgq_put(q, (void *)&data[0], TIMEOUT);
24 zassert_equal(ret, -EAGAIN);
25
26 k_msgq_purge(q);
27 }
28
get_fail(struct k_msgq * q)29 static void get_fail(struct k_msgq *q)
30 {
31 uint32_t rx_data;
32
33 /**TESTPOINT: msgq get returns -ENOMSG*/
34 int ret = k_msgq_get(q, &rx_data, K_NO_WAIT);
35
36 zassert_equal(ret, -ENOMSG);
37 /**TESTPOINT: msgq get returns -EAGAIN*/
38 ret = k_msgq_get(q, &rx_data, TIMEOUT);
39 zassert_equal(ret, -EAGAIN);
40 }
41
42 /**
43 * @addtogroup kernel_message_queue_tests
44 * @{
45 */
46
47 /**
48 * @brief Test returned error code during writing in msgq
49 * @see k_msgq_init()
50 */
ZTEST(msgq_api_1cpu,test_msgq_put_fail)51 ZTEST(msgq_api_1cpu, test_msgq_put_fail)
52 {
53 k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);
54 put_fail(&msgq);
55 }
56
57 #ifdef CONFIG_USERSPACE
58 /**
59 * @brief Test returned error code during writing in msgq
60 * @see k_msgq_alloc_init()
61 */
ZTEST_USER(msgq_api,test_msgq_user_put_fail)62 ZTEST_USER(msgq_api, test_msgq_user_put_fail)
63 {
64 struct k_msgq *q;
65
66 q = k_object_alloc(K_OBJ_MSGQ);
67 zassert_not_null(q, "couldn't alloc message queue");
68 zassert_false(k_msgq_alloc_init(q, MSG_SIZE, MSGQ_LEN));
69 put_fail(q);
70 }
71 #endif /* CONFIG_USERSPACE */
72
73 /**
74 * @brief Test returned error code during reading from msgq
75 * @see k_msgq_init(), k_msgq_put()
76 */
ZTEST(msgq_api_1cpu,test_msgq_get_fail)77 ZTEST(msgq_api_1cpu, test_msgq_get_fail)
78 {
79 k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);
80 get_fail(&msgq);
81 }
82
83 #ifdef CONFIG_USERSPACE
84 /**
85 * @brief Test returned error code during reading from msgq
86 * @see k_msgq_alloc_init(), k_msgq_get()
87 */
ZTEST_USER(msgq_api,test_msgq_user_get_fail)88 ZTEST_USER(msgq_api, test_msgq_user_get_fail)
89 {
90 struct k_msgq *q;
91
92 q = k_object_alloc(K_OBJ_MSGQ);
93 zassert_not_null(q, "couldn't alloc message queue");
94 zassert_false(k_msgq_alloc_init(q, MSG_SIZE, MSGQ_LEN));
95 get_fail(q);
96 }
97 #endif /* CONFIG_USERSPACE */
98
99 /**
100 * @}
101 */
102