From 64579bc4905c2bdf544707dd8df3de85944091d2 Mon Sep 17 00:00:00 2001 From: jing wang Date: Tue, 27 Dec 2016 10:32:15 +0800 Subject: [PATCH] tests: add threads customdata api test case with unified kernel the commit cover basic customdata apis: k_thread_custom_data_set() k_thread_custom_data_get() Change-Id: Ide27cfd59230303767414c7f827d6ad627989a6f Signed-off-by: jing wang --- .../threads_customdata/cdata_api/Makefile | 4 ++ .../threads_customdata/cdata_api/README | 10 +++ .../threads_customdata/cdata_api/prj.conf | 2 + .../threads_customdata/cdata_api/src/Makefile | 3 + .../threads_customdata/cdata_api/src/main.c | 38 ++++++++++ .../cdata_api/src/test_cdata.h | 23 ++++++ .../cdata_api/src/test_customdata_api.c | 70 +++++++++++++++++++ .../threads_customdata/cdata_api/testcase.ini | 2 + 8 files changed, 152 insertions(+) create mode 100644 tests/kernel/threads_customdata/cdata_api/Makefile create mode 100644 tests/kernel/threads_customdata/cdata_api/README create mode 100644 tests/kernel/threads_customdata/cdata_api/prj.conf create mode 100644 tests/kernel/threads_customdata/cdata_api/src/Makefile create mode 100644 tests/kernel/threads_customdata/cdata_api/src/main.c create mode 100644 tests/kernel/threads_customdata/cdata_api/src/test_cdata.h create mode 100644 tests/kernel/threads_customdata/cdata_api/src/test_customdata_api.c create mode 100644 tests/kernel/threads_customdata/cdata_api/testcase.ini diff --git a/tests/kernel/threads_customdata/cdata_api/Makefile b/tests/kernel/threads_customdata/cdata_api/Makefile new file mode 100644 index 00000000000..4de50f93d4d --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/Makefile @@ -0,0 +1,4 @@ +BOARD ?= qemu_x86 +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/kernel/threads_customdata/cdata_api/README b/tests/kernel/threads_customdata/cdata_api/README new file mode 100644 index 00000000000..2b8dc376f0a --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/README @@ -0,0 +1,10 @@ +$make qemu +Running test suite test_customdata_api +tc_start() - test_customdata_get_set_coop +=================================================================== +PASS - test_customdata_get_set_coop. +tc_start() - test_customdata_get_set_preempt +=================================================================== +PASS - test_customdata_get_set_preempt. +=================================================================== +PROJECT EXECUTION SUCCESSFUL diff --git a/tests/kernel/threads_customdata/cdata_api/prj.conf b/tests/kernel/threads_customdata/cdata_api/prj.conf new file mode 100644 index 00000000000..d19121a8d4d --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_THREAD_CUSTOM_DATA=y diff --git a/tests/kernel/threads_customdata/cdata_api/src/Makefile b/tests/kernel/threads_customdata/cdata_api/src/Makefile new file mode 100644 index 00000000000..b3b496ad33c --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/src/Makefile @@ -0,0 +1,3 @@ +include $(ZEPHYR_BASE)/tests/Makefile.test + +obj-y = main.o test_customdata_api.o diff --git a/tests/kernel/threads_customdata/cdata_api/src/main.c b/tests/kernel/threads_customdata/cdata_api/src/main.c new file mode 100644 index 00000000000..ea356277c4d --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/src/main.c @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#include +#include "test_cdata.h" + +/** + * @addtogroup t_threads_customdata + * @{ + * @defgroup t_threads_customdata_api test_threads_customdata_api + * @} + */ + +/*test case main entry*/ +void test_main(void *p1, void *p2, void *p3) +{ + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + + ztest_test_suite(test_customdata_api, + ztest_unit_test(test_customdata_get_set_coop), + ztest_unit_test(test_customdata_get_set_preempt)); + ztest_run_test_suite(test_customdata_api); +} diff --git a/tests/kernel/threads_customdata/cdata_api/src/test_cdata.h b/tests/kernel/threads_customdata/cdata_api/src/test_cdata.h new file mode 100644 index 00000000000..54cfa77f13c --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/src/test_cdata.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef __TEST_CUSTOMDATA_H__ +#define __TEST_CUSTOMDATA_H__ + +void test_customdata_get_set_coop(void); +void test_customdata_get_set_preempt(void); + +#endif /* __TEST_CUSTOMDATA_H__ */ diff --git a/tests/kernel/threads_customdata/cdata_api/src/test_customdata_api.c b/tests/kernel/threads_customdata/cdata_api/src/test_customdata_api.c new file mode 100644 index 00000000000..1176da16a40 --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/src/test_customdata_api.c @@ -0,0 +1,70 @@ +/* + * 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. + */ + +#include + +/*macro definition*/ +#define STACK_SIZE 256 + +/*local variables*/ +static char __stack tstack[STACK_SIZE]; + +static void customdata_entry(void *p1, void *p2, void *p3) +{ + uint32_t data = 1; + + assert_is_null(k_thread_custom_data_get(), NULL); + while (1) { + k_thread_custom_data_set((void *)data); + /* relinguish cpu for a while */ + k_sleep(50); + /** TESTPOINT: custom data comparison */ + assert_equal(data, (uint32_t)k_thread_custom_data_get(), NULL); + data++; + } +} + +/* test cases */ +/** + * @ingroup t_customdata_api + * @brief test thread custom data get/set from coop thread + */ +void test_customdata_get_set_coop(void) +{ + k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, + customdata_entry, NULL, NULL, NULL, + K_PRIO_COOP(1), 0, 0); + k_sleep(500); + + /* cleanup environment */ + k_thread_abort(tid); +} + +/** + * @ingroup t_customdata_api + * @brief test thread custom data get/set from preempt thread + */ +void test_customdata_get_set_preempt(void) +{ + /** TESTPOINT: custom data of preempt thread */ + k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, + customdata_entry, NULL, NULL, NULL, + K_PRIO_PREEMPT(0), 0, 0); + k_sleep(500); + + /* cleanup environment */ + k_thread_abort(tid); +} diff --git a/tests/kernel/threads_customdata/cdata_api/testcase.ini b/tests/kernel/threads_customdata/cdata_api/testcase.ini new file mode 100644 index 00000000000..58c4d1a1747 --- /dev/null +++ b/tests/kernel/threads_customdata/cdata_api/testcase.ini @@ -0,0 +1,2 @@ +[test] +tags = kernel