tests: errno: convert test case to use ztest

This patch convert normal test case to use ztest framework
APIs and remove unnecessary output.

Signed-off-by: Punit Vara <punit.vara@intel.com>
This commit is contained in:
Punit Vara 2017-07-25 16:25:46 +05:30 committed by Anas Nashif
commit cbf40bc6d3
5 changed files with 105 additions and 81 deletions

View file

@ -1 +1 @@
# nothing yet
CONFIG_ZTEST=y

View file

@ -1 +1,2 @@
CONFIG_NEWLIB_LIBC=y
CONFIG_ZTEST=y

View file

@ -1,3 +1,4 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
include $(ZEPHYR_BASE)/tests/Makefile.test
obj-y = main.o
obj-y = main.o errno.o

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ztest.h>
#include <zephyr.h>
#include <errno.h>
#include <tc_util.h>
#define N_THREADS 2
#define STACK_SIZE 384
static K_THREAD_STACK_ARRAY_DEFINE(stacks, N_THREADS, STACK_SIZE);
static struct k_thread threads[N_THREADS];
static int errno_values[N_THREADS + 1] = {
0xbabef00d,
0xdeadbeef,
0xabad1dea,
};
struct result {
void *q;
int pass;
};
struct result result[N_THREADS];
struct k_fifo fifo;
static void errno_fiber(int n, int my_errno)
{
errno = my_errno;
k_sleep(30 - (n * 10));
if (errno == my_errno) {
result[n].pass = 1;
}
zassert_equal(errno, my_errno, NULL);
k_fifo_put(&fifo, &result[n]);
}
void test_thread_context(void)
{
int rv = TC_PASS, test_errno;
k_fifo_init(&fifo);
errno = errno_values[N_THREADS];
test_errno = errno;
for (int ii = 0; ii < N_THREADS; ii++) {
result[ii].pass = TC_FAIL;
}
/**TESTPOINT: thread- threads stacks are separate */
for (int ii = 0; ii < N_THREADS; ii++) {
k_thread_create(&threads[ii], stacks[ii], STACK_SIZE,
(k_thread_entry_t) errno_fiber,
(void *) ii, (void *) errno_values[ii], NULL,
K_PRIO_PREEMPT(ii + 5), 0, K_NO_WAIT);
}
for (int ii = 0; ii < N_THREADS; ii++) {
struct result *p = k_fifo_get(&fifo, 100);
if (!p || !p->pass) {
rv = TC_FAIL;
}
}
zassert_equal(errno, test_errno, NULL);
if (errno != errno_values[N_THREADS]) {
rv = TC_FAIL;
}
}

View file

@ -1,86 +1,26 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <errno.h>
#include <tc_util.h>
#define N_THREADS 2
#define STACK_SIZE 384
static K_THREAD_STACK_ARRAY_DEFINE(stacks, N_THREADS, STACK_SIZE);
static struct k_thread threads[N_THREADS];
static int errno_values[N_THREADS + 1] = {
0xbabef00d,
0xdeadbeef,
0xabad1dea,
};
struct result {
void *q;
int pass;
};
struct result result[N_THREADS];
struct k_fifo fifo;
static void errno_fiber(int n, int my_errno)
/**
* @addgroup t_thread_contex
* @{
* @defgroup t_thread_contex test_thread
* @brief TestPurpose: verify thread context
* @details Check whether variable value per-thread and saved during
* context switch
* - API coverage
* - k_thread_create
* @}
*/
#include <ztest.h>
extern void test_thread_context(void);
/*test case main entry*/
void test_main(void *p1, void *p2, void *p3)
{
errno = my_errno;
printk("co-op thread %d, errno before sleep: %x\n", n, errno);
k_sleep(30 - (n * 10));
if (errno == my_errno) {
result[n].pass = 1;
}
printk("co-op thread %d, errno after sleep: %x\n", n, errno);
k_fifo_put(&fifo, &result[n]);
}
void main(void)
{
int rv = TC_PASS;
TC_START("kernel_errno");
k_fifo_init(&fifo);
errno = errno_values[N_THREADS];
printk("main thread, errno before starting co-op threads: %x\n", errno);
for (int ii = 0; ii < N_THREADS; ii++) {
result[ii].pass = TC_FAIL;
}
for (int ii = 0; ii < N_THREADS; ii++) {
k_thread_create(&threads[ii], stacks[ii], STACK_SIZE,
(k_thread_entry_t) errno_fiber,
(void *) ii, (void *) errno_values[ii], NULL,
K_PRIO_PREEMPT(ii + 5), 0, K_NO_WAIT);
}
for (int ii = 0; ii < N_THREADS; ii++) {
struct result *p = k_fifo_get(&fifo, 100);
if (!p || !p->pass) {
rv = TC_FAIL;
}
}
printk("main thread, errno after running co-op threads: %x\n", errno);
if (errno != errno_values[N_THREADS]) {
rv = TC_FAIL;
}
TC_END_RESULT(rv);
TC_END_REPORT(rv);
ztest_test_suite(test_context_errno,
ztest_unit_test(test_thread_context));
ztest_run_test_suite(test_context_errno);
}