1 /*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @defgroup kernel_message_queue_tests Message Queue
9 * @ingroup all_tests
10 * @{
11 * @}
12 */
13
14 #include <zephyr/ztest.h>
15
16 #include "test_msgq.h"
17
18 #ifdef CONFIG_64BIT
19 #define MAX_SZ 256
20 #else
21 #define MAX_SZ 128
22 #endif
23
24 K_HEAP_DEFINE(test_pool, MAX_SZ * 2);
25
26 extern struct k_msgq kmsgq;
27 extern struct k_msgq msgq;
28 extern struct k_sem end_sema;
29 extern struct k_thread tdata;
30 extern k_tid_t tids[2];
31 K_THREAD_STACK_DECLARE(tstack, STACK_SIZE);
32
msgq_api_setup(void)33 void *msgq_api_setup(void)
34 {
35 k_thread_access_grant(k_current_get(), &kmsgq, &msgq, &end_sema,
36 &tdata, &tstack);
37 k_thread_heap_assign(k_current_get(), &test_pool);
38 return NULL;
39 }
40
test_end_threads_join(void)41 static void test_end_threads_join(void)
42 {
43 for (int i = 0; i < ARRAY_SIZE(tids); i++) {
44 if (tids[i] != NULL) {
45 k_thread_join(tids[i], K_FOREVER);
46 tids[i] = NULL;
47 }
48 }
49 }
50
msgq_api_test_after(void * data)51 static void msgq_api_test_after(void *data)
52 {
53 test_end_threads_join();
54 }
55
msgq_api_test_1cpu_after(void * data)56 static void msgq_api_test_1cpu_after(void *data)
57 {
58 test_end_threads_join();
59
60 ztest_simple_1cpu_after(data);
61 }
62
63 ZTEST_SUITE(msgq_api, NULL, msgq_api_setup, NULL, msgq_api_test_after, NULL);
64 ZTEST_SUITE(msgq_api_1cpu, NULL, msgq_api_setup,
65 ztest_simple_1cpu_before, msgq_api_test_1cpu_after, NULL);
66