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 <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2016-10-28 14:44:17 -04:00 committed by Anas Nashif
parent 70ff94c42a
commit a32579749b
15 changed files with 39 additions and 37 deletions

View file

@ -1,5 +1,5 @@
BOARD ?= qemu_x86
KERNEL_TYPE ?= nano
KERNEL_TYPE ?= unified
CONF_FILE ?= prj.conf
include $(ZEPHYR_BASE)/Makefile.inc

View file

@ -1,2 +1,3 @@
[test]
tags = my_tags
kernel = unified

View file

@ -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

View file

@ -1,4 +1,4 @@
[test]
tags = byteorder
build_only = true
arch_whitelist = x86 arm arc
kernel = unified

View file

@ -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

View file

@ -1,5 +0,0 @@
% Application : Buffer test
% TASK NAME PRIO ENTRY STACK GROUPS
% ===================================================
TASK MAIN 7 main 2048 [EXE]

View file

@ -1,6 +1,3 @@
[test]
tags = buf
build_only = true
arch_whitelist = x86
# Doesn't work for ia32_pci
filter = CONFIG_SOC=="ia32"

View file

@ -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

View file

@ -37,7 +37,7 @@
#define PRINT printf
#endif /* !KERNEL */
#include <nanokernel.h>
#include <zephyr.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>

View file

@ -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;

View file

@ -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, &params[i]);
k_fifo_put(fifo, &params[i]);
}
}

View file

@ -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

View file

@ -1,2 +0,0 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_ASSERT_VERBOSE=1

View file

@ -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

View file

@ -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