From a32579749baec32884c5f920fba18d2c6927c45e Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 28 Oct 2016 14:44:17 -0400 Subject: [PATCH] ztest: move ztest to unified kernel ztest was not working with unified kernel and v1 APIs and not many tests are using ztest right now, so instead of making it work with old APIs, convert it to unified kernel completely so that new tests written using ztest would be unified kenrel based. Change-Id: Ibfcc7783dcb266abbd388662ba61c4b55d32b10c Signed-off-by: Anas Nashif --- samples/testing/integration/Makefile | 2 +- samples/testing/integration/testcase.ini | 1 + tests/kernel/test_byteorder/Makefile | 2 +- tests/kernel/test_byteorder/testcase.ini | 2 +- tests/net/buf/Makefile | 3 +-- tests/net/buf/prj.mdef | 5 ----- tests/net/buf/testcase.ini | 3 --- tests/ztest/Kconfig | 10 +++++++++- tests/ztest/include/ztest.h | 2 +- tests/ztest/src/ztest.c | 25 ++++++++++++------------ tests/ztest/src/ztest_mock.c | 10 +++++----- tests/ztest/test/base/Makefile | 4 ++-- tests/ztest/test/base/prj.conf | 2 -- tests/ztest/test/base/testcase.ini | 3 +++ tests/ztest/test/mock/Makefile | 2 +- 15 files changed, 39 insertions(+), 37 deletions(-) delete mode 100644 tests/net/buf/prj.mdef delete mode 100644 tests/ztest/test/base/prj.conf diff --git a/samples/testing/integration/Makefile b/samples/testing/integration/Makefile index 2d7db42ee2..e832e38bb5 100644 --- a/samples/testing/integration/Makefile +++ b/samples/testing/integration/Makefile @@ -1,5 +1,5 @@ BOARD ?= qemu_x86 -KERNEL_TYPE ?= nano +KERNEL_TYPE ?= unified CONF_FILE ?= prj.conf include $(ZEPHYR_BASE)/Makefile.inc diff --git a/samples/testing/integration/testcase.ini b/samples/testing/integration/testcase.ini index 60bd7c2edc..99277428f9 100644 --- a/samples/testing/integration/testcase.ini +++ b/samples/testing/integration/testcase.ini @@ -1,2 +1,3 @@ [test] tags = my_tags +kernel = unified diff --git a/tests/kernel/test_byteorder/Makefile b/tests/kernel/test_byteorder/Makefile index b80ea39a8e..c3eaea2f0b 100644 --- a/tests/kernel/test_byteorder/Makefile +++ b/tests/kernel/test_byteorder/Makefile @@ -1,6 +1,6 @@ BOARD ?= qemu_x86 MDEF_FILE = prj.mdef -KERNEL_TYPE ?= nano +KERNEL_TYPE ?= unified CONF_FILE = prj.conf include $(ZEPHYR_BASE)/Makefile.inc diff --git a/tests/kernel/test_byteorder/testcase.ini b/tests/kernel/test_byteorder/testcase.ini index 3c75d8fed9..bb729438c6 100644 --- a/tests/kernel/test_byteorder/testcase.ini +++ b/tests/kernel/test_byteorder/testcase.ini @@ -1,4 +1,4 @@ [test] tags = byteorder -build_only = true arch_whitelist = x86 arm arc +kernel = unified diff --git a/tests/net/buf/Makefile b/tests/net/buf/Makefile index b80ea39a8e..7b2a8f1791 100644 --- a/tests/net/buf/Makefile +++ b/tests/net/buf/Makefile @@ -1,6 +1,5 @@ BOARD ?= qemu_x86 -MDEF_FILE = prj.mdef -KERNEL_TYPE ?= nano +KERNEL_TYPE ?= unified CONF_FILE = prj.conf include $(ZEPHYR_BASE)/Makefile.inc diff --git a/tests/net/buf/prj.mdef b/tests/net/buf/prj.mdef deleted file mode 100644 index 87c5b59d67..0000000000 --- a/tests/net/buf/prj.mdef +++ /dev/null @@ -1,5 +0,0 @@ -% Application : Buffer test - -% TASK NAME PRIO ENTRY STACK GROUPS -% =================================================== - TASK MAIN 7 main 2048 [EXE] diff --git a/tests/net/buf/testcase.ini b/tests/net/buf/testcase.ini index 9277be0a8f..fd0b407460 100644 --- a/tests/net/buf/testcase.ini +++ b/tests/net/buf/testcase.ini @@ -1,6 +1,3 @@ [test] tags = buf build_only = true -arch_whitelist = x86 -# Doesn't work for ia32_pci -filter = CONFIG_SOC=="ia32" diff --git a/tests/ztest/Kconfig b/tests/ztest/Kconfig index 7ef932c972..c8d453d4e5 100644 --- a/tests/ztest/Kconfig +++ b/tests/ztest/Kconfig @@ -22,10 +22,18 @@ config ZTEST if you're writing automated tests. config ZTEST_STACKSIZE - int "Test function fiber stack size" + int "Test function thread stack size" depends on ZTEST default 1000 +config ZTEST_FAIL_FAST + bool "Abort on first failing test" + depends on ZTEST + default n + help + Stop and abort on first failing test. Do not continue with other + tests that might be in the queue. + config ZTEST_ASSERT_VERBOSE int "Assertion verbosity level" depends on ZTEST diff --git a/tests/ztest/include/ztest.h b/tests/ztest/include/ztest.h index 8617f18b5d..2f0601f482 100644 --- a/tests/ztest/include/ztest.h +++ b/tests/ztest/include/ztest.h @@ -37,7 +37,7 @@ #define PRINT printf #endif /* !KERNEL */ -#include +#include #if defined(CONFIG_STDOUT_CONSOLE) #include diff --git a/tests/ztest/src/ztest.c b/tests/ztest/src/ztest.c index 31acda386e..3f0895131d 100644 --- a/tests/ztest/src/ztest.c +++ b/tests/ztest/src/ztest.c @@ -129,26 +129,30 @@ out: /* Zephyr's probably going to cause all tests to fail if one test fails, so * skip the rest of tests if one of them fails */ +#ifdef CONFIG_ZTEST_FAIL_FAST #define FAIL_FAST 1 +#else +#define FAIL_FAST 0 +#endif -static char fiber_stack[CONFIG_ZTEST_STACKSIZE]; +static char thread_stack[CONFIG_ZTEST_STACKSIZE]; static int test_result; -static struct nano_sem mutex; +static struct k_sem mutex; void ztest_test_fail(void) { test_result = -1; - fiber_abort(); + k_thread_abort(k_current_get()); } static void init_testing(void) { - nano_sem_init(&mutex); - nano_fiber_sem_take(&mutex, TICKS_UNLIMITED); + k_sem_init(&mutex, 1, UINT_MAX); + k_sem_take(&mutex, K_FOREVER); } -static void fiber_cb(int a, int b) +static void test_cb(void *a, void *dummy2, void *dummy) { struct unit_test *test = (struct unit_test *)a; @@ -156,7 +160,7 @@ static void fiber_cb(int a, int b) run_test_functions(test); test_result = 0; - nano_fiber_sem_give(&mutex); + k_sem_give(&mutex); } static int run_test(struct unit_test *test) @@ -164,11 +168,8 @@ static int run_test(struct unit_test *test) int ret = TC_PASS; TC_START(test->name); - - task_fiber_start(&fiber_stack[0], sizeof(fiber_stack), - (nano_fiber_entry_t) fiber_cb, (int)test, 0, 7, 0); - - nano_fiber_sem_take(&mutex, TICKS_UNLIMITED); + k_thread_spawn(&thread_stack[0], sizeof(thread_stack), + (k_thread_entry_t) test_cb, (struct unit_test *)test, NULL, NULL, -1, 0, 0); if (test_result) { ret = TC_FAIL; diff --git a/tests/ztest/src/ztest_mock.c b/tests/ztest/src/ztest_mock.c index 0c30517b65..77a79ddac6 100644 --- a/tests/ztest/src/ztest_mock.c +++ b/tests/ztest/src/ztest_mock.c @@ -56,19 +56,19 @@ void _init_mock(void) #else static struct parameter params[CONFIG_ZTEST_PARAMETER_COUNT]; -static struct nano_fifo *fifo; +static struct k_fifo *fifo; static void free_parameter(struct parameter *param) { if (param) { - nano_fifo_put(fifo, param); + k_fifo_put(fifo, param); } } static struct parameter *alloc_parameter(void) { struct parameter *param; - param = nano_fifo_get(fifo, TICKS_NONE); + param = k_fifo_get(fifo, K_NO_WAIT); if (!param) { PRINT("Failed to allocate mock parameter\n"); ztest_test_fail(); @@ -81,10 +81,10 @@ void _init_mock(void) { int i; - nano_fifo_init(fifo); + k_fifo_init(fifo); for (i = 0; i < CONFIG_ZTEST_PARAMETER_COUNT; i++) { - nano_fifo_put(fifo, ¶ms[i]); + k_fifo_put(fifo, ¶ms[i]); } } diff --git a/tests/ztest/test/base/Makefile b/tests/ztest/test/base/Makefile index 2dad078c4e..71e0e59213 100644 --- a/tests/ztest/test/base/Makefile +++ b/tests/ztest/test/base/Makefile @@ -1,8 +1,8 @@ BOARD ?= qemu_x86 ifneq ($(BOARD), unit_testing) - KERNEL_TYPE ?= nano - CONF_FILE ?= prj.conf + KERNEL_TYPE ?= unified + CONF_FILE ?= prj_verbose_0.conf include $(ZEPHYR_BASE)/Makefile.inc else diff --git a/tests/ztest/test/base/prj.conf b/tests/ztest/test/base/prj.conf deleted file mode 100644 index 79028c2796..0000000000 --- a/tests/ztest/test/base/prj.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_ZTEST_ASSERT_VERBOSE=1 diff --git a/tests/ztest/test/base/testcase.ini b/tests/ztest/test/base/testcase.ini index ac78beb388..fd3487b4e3 100644 --- a/tests/ztest/test/base/testcase.ini +++ b/tests/ztest/test/base/testcase.ini @@ -1,11 +1,14 @@ [test_verbose_0] tags = test_framework +extra_args = CONF_FILE=prj_verbose_0.conf [test_verbose_1] tags = test_framework +extra_args = CONF_FILE=prj_verbose_1.conf [test_verbose_2] tags = test_framework +extra_args = CONF_FILE=prj_verbose_2.conf [test] type = unit diff --git a/tests/ztest/test/mock/Makefile b/tests/ztest/test/mock/Makefile index 2dad078c4e..80b678f3d4 100644 --- a/tests/ztest/test/mock/Makefile +++ b/tests/ztest/test/mock/Makefile @@ -1,7 +1,7 @@ BOARD ?= qemu_x86 ifneq ($(BOARD), unit_testing) - KERNEL_TYPE ?= nano + KERNEL_TYPE ?= unified CONF_FILE ?= prj.conf include $(ZEPHYR_BASE)/Makefile.inc