diff options
author | jing wang <jing.j.wang@intel.com> | 2016-11-14 16:59:07 +0800 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2017-01-20 12:09:11 +0000 |
commit | e49480d5904926a23b1ebf5b5d2c571ea7a184f5 (patch) | |
tree | d852f117ab8495f4a1f2db5c02d6109c85e300f5 /tests | |
parent | c570efd63b6f6f24259a39e553a1d6e71ffef825 (diff) |
tests: add fifo/lifo test cases with unified kernel
Add fifo/fifo test cases with unified kernel, which cover
basic apis across differnt contexts - thread and isr
Change-Id: Icb61d3dcd564167b0bd70419c652e0b000869959
Signed-off-by: jing wang <jing.j.wang@intel.com>
Diffstat (limited to 'tests')
18 files changed, 750 insertions, 0 deletions
diff --git a/tests/kernel/fifo/test_fifo_api/Makefile b/tests/kernel/fifo/test_fifo_api/Makefile new file mode 100644 index 000000000..4de50f93d --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/Makefile @@ -0,0 +1,4 @@ +BOARD ?= qemu_x86 +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/kernel/fifo/test_fifo_api/prj.conf b/tests/kernel/fifo/test_fifo_api/prj.conf new file mode 100644 index 000000000..9a75212e8 --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_IRQ_OFFLOAD=y diff --git a/tests/kernel/fifo/test_fifo_api/src/Makefile b/tests/kernel/fifo/test_fifo_api/src/Makefile new file mode 100644 index 000000000..93b509eae --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/src/Makefile @@ -0,0 +1,3 @@ +include $(ZEPHYR_BASE)/tests/Makefile.test + +obj-y = main.o test_fifo_contexts.o test_fifo_fail.o test_fifo_loop.o diff --git a/tests/kernel/fifo/test_fifo_api/src/main.c b/tests/kernel/fifo/test_fifo_api/src/main.c new file mode 100644 index 000000000..65c99332c --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/src/main.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_fifo + * @{ + * @defgroup t_fifo_api test_fifo_api + * @} + */ + +#include <ztest.h> +extern void test_fifo_thread2thread(void); +extern void test_fifo_thread2isr(void); +extern void test_fifo_isr2thread(void); +extern void test_fifo_get_fail(void); +extern void test_fifo_loop(void); + +/*test case main entry*/ +void test_main(void *p1, void *p2, void *p3) +{ + ztest_test_suite(test_fifo_api, + ztest_unit_test(test_fifo_thread2thread), + ztest_unit_test(test_fifo_thread2isr), + ztest_unit_test(test_fifo_isr2thread), + ztest_unit_test(test_fifo_get_fail), + ztest_unit_test(test_fifo_loop)); + ztest_run_test_suite(test_fifo_api); +} diff --git a/tests/kernel/fifo/test_fifo_api/src/test_fifo.h b/tests/kernel/fifo/test_fifo_api/src/test_fifo.h new file mode 100644 index 000000000..f6a2b45dd --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/src/test_fifo.h @@ -0,0 +1,11 @@ +#ifndef __TEST_FIFO_H__ +#define __TEST_FIFO_H__ + +#include <ztest.h> +#include <irq_offload.h> + +typedef struct fdata { + sys_snode_t snode; + uint32_t data; +} fdata_t; +#endif diff --git a/tests/kernel/fifo/test_fifo_api/src/test_fifo_contexts.c b/tests/kernel/fifo/test_fifo_api/src/test_fifo_contexts.c new file mode 100644 index 000000000..70e0f0baf --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/src/test_fifo_contexts.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND + , either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_fifo_api + * @{ + * @defgroup t_fifo_api_basic test_fifo_api_basic + * @brief TestPurpose: verify zephyr fifo apis under different context + * - API coverage + * -# k_fifo_init K_FIFO_DEFINE + * -# k_fifo_put k_fifo_put_list k_fifo_put_slist + * -# k_fifo_get + * @} + */ + +#include "test_fifo.h" + +#define STACK_SIZE 512 +#define LIST_LEN 2 +/**TESTPOINT: init via K_FIFO_DEFINE*/ +K_FIFO_DEFINE(kfifo); + +struct k_fifo fifo; +static fdata_t data[LIST_LEN]; +static fdata_t data_l[LIST_LEN]; +static fdata_t data_sl[LIST_LEN]; + +static char __noinit __stack tstack[STACK_SIZE]; +static struct k_sem end_sema; + +static void tfifo_put(struct k_fifo *pfifo) +{ + for (int i = 0; i < LIST_LEN; i++) { + /**TESTPOINT: fifo put*/ + k_fifo_put(pfifo, (void *)&data[i]); + } + + /**TESTPOINT: fifo put list*/ + static fdata_t *head = &data_l[0], *tail = &data_l[LIST_LEN-1]; + + head->snode.next = (sys_snode_t *)tail; + tail->snode.next = NULL; + k_fifo_put_list(pfifo, (uint32_t *)head, (uint32_t *)tail); + + /**TESTPOINT: fifo put slist*/ + sys_slist_t slist; + + sys_slist_init(&slist); + sys_slist_append(&slist, (sys_snode_t *)&(data_sl[0].snode)); + sys_slist_append(&slist, (sys_snode_t *)&(data_sl[1].snode)); + k_fifo_put_slist(pfifo, &slist); +} + +static void tfifo_get(struct k_fifo *pfifo) +{ + void *rx_data; + + /*get fifo data from "fifo_put"*/ + for (int i = 0; i < LIST_LEN; i++) { + /**TESTPOINT: fifo get*/ + rx_data = k_fifo_get(pfifo, K_NO_WAIT); + assert_equal(rx_data, (void *)&data[i], NULL); + } + /*get fifo data from "fifo_put_list"*/ + for (int i = 0; i < LIST_LEN; i++) { + rx_data = k_fifo_get(pfifo, K_NO_WAIT); + assert_equal(rx_data, (void *)&data_l[i], NULL); + } + /*get fifo data from "fifo_put_slist"*/ + for (int i = 0; i < LIST_LEN; i++) { + rx_data = k_fifo_get(pfifo, K_NO_WAIT); + assert_equal(rx_data, (void *)&data_sl[i], NULL); + } +} + +/*entry of contexts*/ +static void tIsr_entry_put(void *p) +{ + tfifo_put((struct k_fifo *)p); +} + +static void tIsr_entry_get(void *p) +{ + tfifo_get((struct k_fifo *)p); +} + +static void tThread_entry(void *p1, void *p2, void *p3) +{ + tfifo_get((struct k_fifo *)p1); + k_sem_give(&end_sema); +} + +static void tfifo_thread_thread(struct k_fifo *pfifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: thread-thread data passing via fifo*/ + k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, + tThread_entry, pfifo, NULL, NULL, + K_PRIO_PREEMPT(0), 0, 0); + tfifo_put(pfifo); + k_sem_take(&end_sema, K_FOREVER); + k_thread_abort(tid); +} + +static void tfifo_thread_isr(struct k_fifo *pfifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: thread-isr data passing via fifo*/ + irq_offload(tIsr_entry_put, pfifo); + tfifo_get(pfifo); +} + +static void tfifo_isr_thread(struct k_fifo *pfifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: isr-thread data passing via fifo*/ + tfifo_put(pfifo); + irq_offload(tIsr_entry_get, pfifo); +} + +/*test cases*/ +void test_fifo_thread2thread(void) +{ + /**TESTPOINT: init via k_fifo_init*/ + k_fifo_init(&fifo); + tfifo_thread_thread(&fifo); + + /**TESTPOINT: test K_FIFO_DEFINEed fifo*/ + tfifo_thread_thread(&kfifo); +} + +void test_fifo_thread2isr(void) +{ + /**TESTPOINT: init via k_fifo_init*/ + k_fifo_init(&fifo); + tfifo_thread_isr(&fifo); + + /**TESTPOINT: test K_FIFO_DEFINEed fifo*/ + tfifo_thread_isr(&kfifo); +} + +void test_fifo_isr2thread(void) +{ + /**TESTPOINT: test k_fifo_init fifo*/ + k_fifo_init(&fifo); + tfifo_isr_thread(&fifo); + + /**TESTPOINT: test K_FIFO_DEFINE fifo*/ + tfifo_isr_thread(&kfifo); +} diff --git a/tests/kernel/fifo/test_fifo_api/src/test_fifo_fail.c b/tests/kernel/fifo/test_fifo_api/src/test_fifo_fail.c new file mode 100644 index 000000000..a34149dec --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/src/test_fifo_fail.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_fifo_api + * @{ + * @defgroup t_fifo_get_fail test_fifo_get_fail + * @brief TestPurpose: verify zephyr fifo_get when no data + * - API coverage + * -# k_fifo_init + * -# k_fifo_get + * @} + */ + +#include "test_fifo.h" + +#define TIMEOUT 100 + +/*test cases*/ +void test_fifo_get_fail(void *p1, void *p2, void *p3) +{ + struct k_fifo fifo; + + k_fifo_init(&fifo); + /**TESTPOINT: fifo get returns NULL*/ + assert_is_null(k_fifo_get(&fifo, K_NO_WAIT), NULL); + assert_is_null(k_fifo_get(&fifo, TIMEOUT), NULL); +} + diff --git a/tests/kernel/fifo/test_fifo_api/src/test_fifo_loop.c b/tests/kernel/fifo/test_fifo_api/src/test_fifo_loop.c new file mode 100644 index 000000000..246ba5683 --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/src/test_fifo_loop.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND + , either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_fifo_api + * @{ + * @defgroup t_fifo_loop test_fifo_loop + * @brief TestPurpose: verify zephyr fifo continuous read write + * in loop + * @details + * - Test Steps + * -# fifo put from main thread + * -# fifo read from isr + * -# fifo put from isr + * -# fifo get from spawn thread + * -# loop above steps for LOOPs times + * - Expected Results + * -# fifo data pass correctly and stably across contexts + * - API coverage + * -# k_fifo_init + * -# k_fifo_put + * -# k_fifo_get + * @} + */ + +#include "test_fifo.h" + +#define STACK_SIZE 512 +#define LIST_LEN 4 +#define LOOPS 32 + +static fdata_t data[LIST_LEN]; +static struct k_fifo fifo; +static char __noinit __stack tstack[STACK_SIZE]; +static struct k_sem end_sema; + +static void tfifo_put(struct k_fifo *pfifo) +{ + /**TESTPOINT: fifo put*/ + for (int i = 0; i < LIST_LEN; i++) { + k_fifo_put(pfifo, (void *)&data[i]); + } +} + +static void tfifo_get(struct k_fifo *pfifo) +{ + void *rx_data; + + /*get fifo data from "fifo_put"*/ + for (int i = 0; i < LIST_LEN; i++) { + /**TESTPOINT: fifo get*/ + rx_data = k_fifo_get(pfifo, K_NO_WAIT); + assert_equal(rx_data, (void *)&data[i], NULL); + } +} + +/*entry of contexts*/ +static void tIsr_entry(void *p) +{ + TC_PRINT("isr fifo get\n"); + tfifo_get((struct k_fifo *)p); + TC_PRINT("isr fifo put ---> "); + tfifo_put((struct k_fifo *)p); +} + +static void tThread_entry(void *p1, void *p2, void *p3) +{ + TC_PRINT("thread fifo get\n"); + tfifo_get((struct k_fifo *)p1); + k_sem_give(&end_sema); + TC_PRINT("thread fifo put ---> "); + tfifo_put((struct k_fifo *)p1); + k_sem_give(&end_sema); +} + +/* fifo read write job */ +static void tfifo_read_write(struct k_fifo *pfifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: thread-isr-thread data passing via fifo*/ + k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, + tThread_entry, pfifo, NULL, NULL, + K_PRIO_PREEMPT(0), 0, 0); + + TC_PRINT("main fifo put ---> "); + tfifo_put(pfifo); + irq_offload(tIsr_entry, pfifo); + k_sem_take(&end_sema, K_FOREVER); + k_sem_take(&end_sema, K_FOREVER); + + TC_PRINT("main fifo get\n"); + tfifo_get(pfifo); + k_thread_abort(tid); + TC_PRINT("\n"); +} + +/*test cases*/ +void test_fifo_loop(void) +{ + k_fifo_init(&fifo); + for (int i = 0; i < LOOPS; i++) { + TC_PRINT("* Pass data by fifo in loop %d\n", i); + tfifo_read_write(&fifo); + } +} diff --git a/tests/kernel/fifo/test_fifo_api/testcase.ini b/tests/kernel/fifo/test_fifo_api/testcase.ini new file mode 100644 index 000000000..58c4d1a17 --- /dev/null +++ b/tests/kernel/fifo/test_fifo_api/testcase.ini @@ -0,0 +1,2 @@ +[test] +tags = kernel diff --git a/tests/kernel/lifo/test_lifo_api/Makefile b/tests/kernel/lifo/test_lifo_api/Makefile new file mode 100644 index 000000000..4de50f93d --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/Makefile @@ -0,0 +1,4 @@ +BOARD ?= qemu_x86 +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/kernel/lifo/test_lifo_api/prj.conf b/tests/kernel/lifo/test_lifo_api/prj.conf new file mode 100644 index 000000000..9a75212e8 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_IRQ_OFFLOAD=y diff --git a/tests/kernel/lifo/test_lifo_api/src/Makefile b/tests/kernel/lifo/test_lifo_api/src/Makefile new file mode 100644 index 000000000..3895ce309 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/src/Makefile @@ -0,0 +1,3 @@ +include $(ZEPHYR_BASE)/tests/Makefile.test + +obj-y = main.o test_lifo_contexts.o test_lifo_fail.o test_lifo_loop.o diff --git a/tests/kernel/lifo/test_lifo_api/src/main.c b/tests/kernel/lifo/test_lifo_api/src/main.c new file mode 100644 index 000000000..0bf8522e4 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/src/main.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_lifo + * @{ + * @defgroup t_lifo_api test_lifo_api + * @} + */ + +#include <ztest.h> +extern void test_lifo_thread2thread(void); +extern void test_lifo_thread2isr(void); +extern void test_lifo_isr2thread(void); +extern void test_lifo_get_fail(void); +extern void test_lifo_loop(void); + +/*test case main entry*/ +void test_main(void *p1, void *p2, void *p3) +{ + ztest_test_suite(test_lifo_api, + ztest_unit_test(test_lifo_thread2thread), + ztest_unit_test(test_lifo_thread2isr), + ztest_unit_test(test_lifo_isr2thread), + ztest_unit_test(test_lifo_get_fail), + ztest_unit_test(test_lifo_loop)); + ztest_run_test_suite(test_lifo_api); +} diff --git a/tests/kernel/lifo/test_lifo_api/src/test_lifo.h b/tests/kernel/lifo/test_lifo_api/src/test_lifo.h new file mode 100644 index 000000000..77f14eda3 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/src/test_lifo.h @@ -0,0 +1,11 @@ +#ifndef __TEST_LIFO_H__ +#define __TEST_LIFO_H__ + +#include <ztest.h> +#include <irq_offload.h> + +typedef struct ldata { + sys_snode_t snode; + uint32_t data; +} ldata_t; +#endif diff --git a/tests/kernel/lifo/test_lifo_api/src/test_lifo_contexts.c b/tests/kernel/lifo/test_lifo_api/src/test_lifo_contexts.c new file mode 100644 index 000000000..f006e8749 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/src/test_lifo_contexts.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND + , either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_lifo_api + * @{ + * @defgroup t_lifo_api_basic test_lifo_api_basic + * @brief TestPurpose: verify zephyr lifo apis under different context + * - API coverage + * -# k_lifo_init K_LIFO_DEFINE + * -# k_lifo_put + * -# k_lifo_get + * @} + */ + + +#include "test_lifo.h" + +#define STACK_SIZE 512 +#define LIST_LEN 2 +/**TESTPOINT: init via K_LIFO_DEFINE*/ +K_LIFO_DEFINE(klifo); + +struct k_lifo lifo; +static ldata_t data[LIST_LEN]; + +static char __noinit __stack tstack[STACK_SIZE]; +static struct k_sem end_sema; + +static void tlifo_put(struct k_lifo *plifo) +{ + for (int i = 0; i < LIST_LEN; i++) { + /**TESTPOINT: lifo put*/ + k_lifo_put(plifo, (void *)&data[i]); + } +} + +static void tlifo_get(struct k_lifo *plifo) +{ + void *rx_data; + + /*get lifo data*/ + for (int i = LIST_LEN-1; i >= 0; i--) { + /**TESTPOINT: lifo get*/ + rx_data = k_lifo_get(plifo, K_FOREVER); + assert_equal(rx_data, (void *)&data[i], NULL); + } +} + +/*entry of contexts*/ +static void tIsr_entry_put(void *p) +{ + tlifo_put((struct k_lifo *)p); +} + +static void tIsr_entry_get(void *p) +{ + tlifo_get((struct k_lifo *)p); +} + +static void tThread_entry(void *p1, void *p2, void *p3) +{ + tlifo_get((struct k_lifo *)p1); + k_sem_give(&end_sema); +} + +static void tlifo_thread_thread(struct k_lifo *plifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: thread-thread data passing via lifo*/ + k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, + tThread_entry, plifo, NULL, NULL, + K_PRIO_PREEMPT(0), 0, 0); + tlifo_put(plifo); + k_sem_take(&end_sema, K_FOREVER); + k_thread_abort(tid); +} + +static void tlifo_thread_isr(struct k_lifo *plifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: thread-isr data passing via lifo*/ + irq_offload(tIsr_entry_put, plifo); + tlifo_get(plifo); +} + +static void tlifo_isr_thread(struct k_lifo *plifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: isr-thread data passing via lifo*/ + tlifo_put(plifo); + irq_offload(tIsr_entry_get, plifo); +} + +/*test cases*/ +void test_lifo_thread2thread(void) +{ + /**TESTPOINT: init via k_lifo_init*/ + k_lifo_init(&lifo); + tlifo_thread_thread(&lifo); + + /**TESTPOINT: test K_LIFO_DEFINEed lifo*/ + tlifo_thread_thread(&klifo); +} + +void test_lifo_thread2isr(void) +{ + /**TESTPOINT: init via k_lifo_init*/ + k_lifo_init(&lifo); + tlifo_thread_isr(&lifo); + + /**TESTPOINT: test K_LIFO_DEFINEed lifo*/ + tlifo_thread_isr(&klifo); +} + +void test_lifo_isr2thread(void) +{ + /**TESTPOINT: test k_lifo_init lifo*/ + k_lifo_init(&lifo); + tlifo_isr_thread(&lifo); + + /**TESTPOINT: test K_LIFO_DEFINE lifo*/ + tlifo_isr_thread(&klifo); +} diff --git a/tests/kernel/lifo/test_lifo_api/src/test_lifo_fail.c b/tests/kernel/lifo/test_lifo_api/src/test_lifo_fail.c new file mode 100644 index 000000000..ea4a433b8 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/src/test_lifo_fail.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_lifo_api + * @{ + * @defgroup t_lifo_get_fail test_lifo_get_fail + * @brief TestPurpose: verify zephyr lifo_get when no data + * - API coverage + * -# k_lifo_init + * -# k_lifo_get [TIMEOUT|K_NO_WAIT] + * @} + */ + +#include "test_lifo.h" + +#define TIMEOUT 100 + +/*test cases*/ +void test_lifo_get_fail(void *p1, void *p2, void *p3) +{ + struct k_lifo lifo; + + k_lifo_init(&lifo); + /**TESTPOINT: lifo get returns NULL*/ + assert_is_null(k_lifo_get(&lifo, K_NO_WAIT), NULL); + assert_is_null(k_lifo_get(&lifo, TIMEOUT), NULL); +} + diff --git a/tests/kernel/lifo/test_lifo_api/src/test_lifo_loop.c b/tests/kernel/lifo/test_lifo_api/src/test_lifo_loop.c new file mode 100644 index 000000000..e98864e28 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/src/test_lifo_loop.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND + , either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_lifo_api + * @{ + * @defgroup t_lifo_loop test_lifo_loop + * @brief TestPurpose: verify zephyr lifo continuous read write + * in loop + * @details + * - Test Steps + * -# lifo put from main thread + * -# lifo read from isr + * -# lifo put from isr + * -# lifo get from spawn thread + * -# loop above steps for LOOPs times + * - Expected Results + * -# lifo data pass correctly and stably across contexts + * - API coverage + * -# k_lifo_init + * -# k_lifo_put + * -# k_lifo_get + * @} + */ + +#include "test_lifo.h" + +#define STACK_SIZE 512 +#define LIST_LEN 4 +#define LOOPS 32 + +static ldata_t data[LIST_LEN]; +static struct k_lifo lifo; +static char __noinit __stack tstack[STACK_SIZE]; +static struct k_sem end_sema; + +static void tlifo_put(struct k_lifo *plifo) +{ + for (int i = 0; i < LIST_LEN; i++) { + /**TESTPOINT: lifo put*/ + k_lifo_put(plifo, (void *)&data[i]); + } +} + +static void tlifo_get(struct k_lifo *plifo) +{ + void *rx_data; + + /*get lifo data*/ + for (int i = LIST_LEN-1; i >= 0; i--) { + /**TESTPOINT: lifo get*/ + rx_data = k_lifo_get(plifo, K_FOREVER); + assert_equal(rx_data, (void *)&data[i], NULL); + } +} + +/*entry of contexts*/ +static void tIsr_entry(void *p) +{ + TC_PRINT("isr lifo get\n"); + tlifo_get((struct k_lifo *)p); + TC_PRINT("isr lifo put ---> "); + tlifo_put((struct k_lifo *)p); +} + +static void tThread_entry(void *p1, void *p2, void *p3) +{ + TC_PRINT("thread lifo get\n"); + tlifo_get((struct k_lifo *)p1); + k_sem_give(&end_sema); + TC_PRINT("thread lifo put ---> "); + tlifo_put((struct k_lifo *)p1); + k_sem_give(&end_sema); +} + +/* lifo read write job */ +static void tlifo_read_write(struct k_lifo *plifo) +{ + k_sem_init(&end_sema, 0, 1); + /**TESTPOINT: thread-isr-thread data passing via lifo*/ + k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, + tThread_entry, plifo, NULL, NULL, + K_PRIO_PREEMPT(0), 0, 0); + + TC_PRINT("main lifo put ---> "); + tlifo_put(plifo); + irq_offload(tIsr_entry, plifo); + k_sem_take(&end_sema, K_FOREVER); + k_sem_take(&end_sema, K_FOREVER); + + TC_PRINT("main lifo get\n"); + tlifo_get(plifo); + k_thread_abort(tid); + TC_PRINT("\n"); +} + +/*test cases*/ +void test_lifo_loop(void) +{ + k_lifo_init(&lifo); + for (int i = 0; i < LOOPS; i++) { + TC_PRINT("* Pass data by lifo in loop %d\n", i); + tlifo_read_write(&lifo); + } +} diff --git a/tests/kernel/lifo/test_lifo_api/testcase.ini b/tests/kernel/lifo/test_lifo_api/testcase.ini new file mode 100644 index 000000000..58c4d1a17 --- /dev/null +++ b/tests/kernel/lifo/test_lifo_api/testcase.ini @@ -0,0 +1,2 @@ +[test] +tags = kernel |