Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | /* * Copyright (c) 2017 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #include "test_queue.h" #define TIMEOUT K_MSEC(100) #define STACK_SIZE (512 + CONFIG_TEST_EXTRA_STACKSIZE) #define LIST_LEN 2 static K_THREAD_STACK_DEFINE(tstack, STACK_SIZE); static struct k_thread tdata; /*test cases*/ /** * @brief Test k_queue_get() failure scenario * @ingroup kernel_queue_tests * @see k_queue_get() */ void test_queue_get_fail(void) { struct k_queue queue; k_queue_init(&queue); /**TESTPOINT: queue get returns NULL*/ zassert_is_null(k_queue_get(&queue, K_NO_WAIT), NULL); zassert_is_null(k_queue_get(&queue, TIMEOUT), NULL); } /* The sub-thread entry */ static void tThread_entry(void *p1, void *p2, void *p3) { /* wait the queue for data */ k_queue_get((struct k_queue *)p1, K_FOREVER); } /** * @brief Test k_queue_append_list() failure scenario * * @details Accroding to the API k_queue_append_list to * design some error condition to verify error branch of * the API. * 1. Verify that the list's head is empty. * 2. Verify that the list's tail is empty. * 3. Verify that append list to the queue when a * sub-thread is waiting for data. * * @ingroup kernel_queue_tests * * @see k_queue_append_list() */ void test_queue_append_list_error(void) { qdata_t data_l[2]; struct k_queue queue; qdata_t *head = NULL, *tail = &data_l[1]; k_queue_init(&queue); memset(data_l, 0, sizeof(data_l)); /* Check if the list of head is equal to null */ zassert_true(k_queue_append_list(&queue, (uint32_t *)head, (uint32_t *)tail) == -EINVAL, "failed to CHECKIF head == NULL"); /* Check if the list of tail is equal to null */ head = &data_l[0]; tail = NULL; zassert_true(k_queue_append_list(&queue, (uint32_t *)head, (uint32_t *)tail) == -EINVAL, "failed to CHECKIF tail == NULL"); /* Initializing the queue for re-using below */ k_queue_init(&queue); k_thread_create(&tdata, tstack, STACK_SIZE, tThread_entry, &queue, NULL, NULL, K_PRIO_PREEMPT(0), 0, K_NO_WAIT); /* Delay for thread initializing */ k_sleep(K_MSEC(500)); /* Append list into the queue for sub-thread */ head = &data_l[0]; tail = &data_l[1]; head->snode.next = (sys_snode_t *)tail; tail->snode.next = NULL; k_queue_append_list(&queue, (uint32_t *)head, (uint32_t *)tail); } /** * @brief Test k_queue_merge_slist() failure scenario * * @details Verify the API k_queue_merge_slist when * a slist is empty or a slist's tail is null. * * @ingroup kernel_queue_tests * * @see k_queue_merge_slist() */ void test_queue_merge_list_error(void) { qdata_t data_sl[2]; struct k_queue queue; sys_slist_t slist; k_queue_init(&queue); sys_slist_init(&slist); memset(data_sl, 0, sizeof(data_sl)); /* Check if the slist is empty */ zassert_true(k_queue_merge_slist(&queue, &slist) == -EINVAL, "Failed to CHECKIF slist is empty"); /* Check if the tail of the slist is null */ sys_slist_append(&slist, (sys_snode_t *)&(data_sl[0].snode)); sys_slist_append(&slist, (sys_snode_t *)&(data_sl[1].snode)); slist.tail = NULL; zassert_true(k_queue_merge_slist(&queue, &slist) != 0, "Failed to CHECKIF the tail of slist == null"); } #ifdef CONFIG_USERSPACE /** * @brief Test k_queue_init() failure scenario * * @details Verify that the parameter of API k_queue_init() is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_init() */ void test_queue_init_null(void) { ztest_set_fault_valid(true); k_queue_init(NULL); } /** * @brief Test k_queue_alloc_append() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_alloc_append() */ void test_queue_alloc_append_null(void) { qdata_t data; memset(&data, 0, sizeof(data)); ztest_set_fault_valid(true); k_queue_alloc_append(NULL, &data); } /** * @brief Test k_queue_alloc_prepend() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_alloc_prepend() */ void test_queue_alloc_prepend_null(void) { qdata_t data; memset(&data, 0, sizeof(data)); ztest_set_fault_valid(true); k_queue_alloc_prepend(NULL, &data); } /** * @brief Test k_queue_get() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_get() */ void test_queue_get_null(void) { ztest_set_fault_valid(true); k_queue_get(NULL, K_FOREVER); } /** * @brief Test k_queue_is_empty() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_is_empty() */ void test_queue_is_empty_null(void) { ztest_set_fault_valid(true); k_queue_is_empty(NULL); } /** * @brief Test k_queue_peek_head() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_peek_head() */ void test_queue_peek_head_null(void) { ztest_set_fault_valid(true); k_queue_peek_head(NULL); } /** * @brief Test k_queue_peek_tail() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_peek_tail() */ void test_queue_peek_tail_null(void) { ztest_set_fault_valid(true); k_queue_peek_tail(NULL); } /** * @brief Test k_queue_merge_slist() failure scenario * * @details Verify that the parameter of the API is * NULL, what will happen. * * @ingroup kernel_queue_tests * * @see k_queue_merge_slist() */ void test_queue_cancel_wait_error(void) { struct k_queue *q; q = k_object_alloc(K_OBJ_QUEUE); zassert_not_null(q, "no memory for allocated queue object"); k_queue_init(q); /* Check if cancel a qeueu that no thread to wait */ k_queue_cancel_wait(q); /* Check if cancel a null pointer */ ztest_set_fault_valid(true); k_queue_cancel_wait(NULL); } #endif /* CONFIG_USERSPACE */ |