tests: add pipe test cases which use unified kernel
Add kernel pipe test cases which cover basic pipe apis usage across thread and isr Change-Id: I11899411b305535297f2e25056678d5b7df8fb95 Signed-off-by: jing wang <jing.j.wang@intel.com>
This commit is contained in:
parent
e49480d590
commit
6ffe10f50f
7 changed files with 268 additions and 0 deletions
4
tests/kernel/pipe/test_pipe_api/Makefile
Normal file
4
tests/kernel/pipe/test_pipe_api/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
BOARD ?= qemu_x86
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
2
tests/kernel/pipe/test_pipe_api/prj.conf
Normal file
2
tests/kernel/pipe/test_pipe_api/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_IRQ_OFFLOAD=y
|
3
tests/kernel/pipe/test_pipe_api/src/Makefile
Normal file
3
tests/kernel/pipe/test_pipe_api/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
include $(ZEPHYR_BASE)/tests/Makefile.test
|
||||
|
||||
obj-y = main.o test_pipe_contexts.o test_pipe_fail.o
|
39
tests/kernel/pipe/test_pipe_api/src/main.c
Normal file
39
tests/kernel/pipe/test_pipe_api/src/main.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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_pipe
|
||||
* @{
|
||||
* @defgroup t_pipe_api test_pipe_api
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
extern void test_pipe_thread2thread(void);
|
||||
extern void test_pipe_thread2isr(void);
|
||||
extern void test_pipe_put_fail(void);
|
||||
extern void test_pipe_get_fail(void);
|
||||
|
||||
/*test case main entry*/
|
||||
void test_main(void *p1, void *p2, void *p3)
|
||||
{
|
||||
ztest_test_suite(test_pipe_api,
|
||||
ztest_unit_test(test_pipe_thread2thread),
|
||||
ztest_unit_test(test_pipe_thread2isr),
|
||||
ztest_unit_test(test_pipe_put_fail),
|
||||
ztest_unit_test(test_pipe_get_fail));
|
||||
ztest_run_test_suite(test_pipe_api);
|
||||
}
|
148
tests/kernel/pipe/test_pipe_api/src/test_pipe_contexts.c
Normal file
148
tests/kernel/pipe/test_pipe_api/src/test_pipe_contexts.c
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* 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_pipe_api
|
||||
* @{
|
||||
* @defgroup t_pipe_api_basic test_pipe_api_basic
|
||||
* @brief TestPurpose: verify zephyr pipe apis under different context
|
||||
* - API coverage
|
||||
* -# k_pipe_init K_PIPE_DEFINE
|
||||
* -# k_pipe_put
|
||||
* -# k_pipe_get
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <irq_offload.h>
|
||||
|
||||
#define STACK_SIZE 512
|
||||
#define PIPE_LEN 8
|
||||
#define BYTES_TO_WRITE (PIPE_LEN>>1)
|
||||
#define BYTES_TO_READ BYTES_TO_WRITE
|
||||
|
||||
static unsigned char __aligned(4) data[] = "abcd1234";
|
||||
/**TESTPOINT: init via K_PIPE_DEFINE*/
|
||||
K_PIPE_DEFINE(kpipe, PIPE_LEN, 4);
|
||||
static struct k_pipe pipe;
|
||||
|
||||
static char __noinit __stack tstack[STACK_SIZE];
|
||||
static struct k_sem end_sema;
|
||||
|
||||
static void tpipe_put(struct k_pipe *ppipe)
|
||||
{
|
||||
size_t to_wt, wt_byte = 0;
|
||||
|
||||
for (int i = 0; i < PIPE_LEN; i += wt_byte) {
|
||||
/**TESTPOINT: pipe put*/
|
||||
to_wt = (PIPE_LEN - i) >= BYTES_TO_WRITE ?
|
||||
BYTES_TO_WRITE : (PIPE_LEN - i);
|
||||
assert_false(k_pipe_put(ppipe, &data[i], to_wt,
|
||||
&wt_byte, 1, K_NO_WAIT), NULL);
|
||||
assert_true(wt_byte == to_wt || wt_byte == 1, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void tpipe_get(struct k_pipe *ppipe)
|
||||
{
|
||||
unsigned char rx_data[PIPE_LEN];
|
||||
size_t to_rd, rd_byte = 0;
|
||||
|
||||
/*get pipe data from "pipe_put"*/
|
||||
for (int i = 0; i < PIPE_LEN; i += rd_byte) {
|
||||
/**TESTPOINT: pipe get*/
|
||||
to_rd = (PIPE_LEN - i) >= BYTES_TO_READ ?
|
||||
BYTES_TO_READ : (PIPE_LEN - i);
|
||||
assert_false(k_pipe_get(ppipe, &rx_data[i], to_rd,
|
||||
&rd_byte, 1, K_NO_WAIT), NULL);
|
||||
assert_true(rd_byte == to_rd || rd_byte == 1, NULL);
|
||||
}
|
||||
for (int i = 0; i < PIPE_LEN; i++) {
|
||||
assert_equal(rx_data[i], data[i], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*entry of contexts*/
|
||||
static void tIsr_entry_put(void *p)
|
||||
{
|
||||
tpipe_put((struct k_pipe *)p);
|
||||
}
|
||||
|
||||
static void tIsr_entry_get(void *p)
|
||||
{
|
||||
tpipe_get((struct k_pipe *)p);
|
||||
}
|
||||
|
||||
static void tThread_entry(void *p1, void *p2, void *p3)
|
||||
{
|
||||
tpipe_get((struct k_pipe *)p1);
|
||||
k_sem_give(&end_sema);
|
||||
|
||||
tpipe_put((struct k_pipe *)p1);
|
||||
k_sem_give(&end_sema);
|
||||
}
|
||||
|
||||
static void tpipe_thread_thread(struct k_pipe *ppipe)
|
||||
{
|
||||
k_sem_init(&end_sema, 0, 1);
|
||||
|
||||
/**TESTPOINT: thread-thread data passing via pipe*/
|
||||
k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE,
|
||||
tThread_entry, ppipe, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0), 0, 0);
|
||||
tpipe_put(ppipe);
|
||||
k_sem_take(&end_sema, K_FOREVER);
|
||||
|
||||
k_sem_take(&end_sema, K_FOREVER);
|
||||
tpipe_get(ppipe);
|
||||
|
||||
/* clear the spawned thread avoid side effect */
|
||||
k_thread_abort(tid);
|
||||
}
|
||||
|
||||
static void tpipe_thread_isr(struct k_pipe *ppipe)
|
||||
{
|
||||
k_sem_init(&end_sema, 0, 1);
|
||||
|
||||
/**TESTPOINT: thread-isr data passing via pipe*/
|
||||
irq_offload(tIsr_entry_put, ppipe);
|
||||
tpipe_get(ppipe);
|
||||
|
||||
tpipe_put(ppipe);
|
||||
irq_offload(tIsr_entry_get, ppipe);
|
||||
}
|
||||
|
||||
/*test cases*/
|
||||
void test_pipe_thread2thread(void)
|
||||
{
|
||||
/**TESTPOINT: test k_pipe_init pipe*/
|
||||
k_pipe_init(&pipe, data, PIPE_LEN);
|
||||
tpipe_thread_thread(&pipe);
|
||||
|
||||
/**TESTPOINT: test K_PIPE_DEFINE pipe*/
|
||||
tpipe_thread_thread(&kpipe);
|
||||
}
|
||||
|
||||
void test_pipe_thread2isr(void)
|
||||
{
|
||||
/**TESTPOINT: test k_pipe_init pipe*/
|
||||
k_pipe_init(&pipe, data, PIPE_LEN);
|
||||
tpipe_thread_isr(&pipe);
|
||||
|
||||
/**TESTPOINT: test K_PIPE_DEFINE pipe*/
|
||||
tpipe_thread_isr(&kpipe);
|
||||
}
|
70
tests/kernel/pipe/test_pipe_api/src/test_pipe_fail.c
Normal file
70
tests/kernel/pipe/test_pipe_api/src/test_pipe_fail.c
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup t_pipe_api
|
||||
* @{
|
||||
* @defgroup t_pipe_fail_get_put test_pipe_fail_get_put
|
||||
* @brief TestPurpose: verify zephyr pipe get/put under differnt condition
|
||||
* - API coverage
|
||||
* -# k_pipe_get [TIMEOUT K_NO_WAIT]
|
||||
* -# k_pipe_put [K_FOREVER TIMEOUT K_NO_WAIT]
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <irq_offload.h>
|
||||
|
||||
#define TIMEOUT 100
|
||||
#define PIPE_LEN 8
|
||||
|
||||
static unsigned char __aligned(4) data[] = "abcd1234";
|
||||
|
||||
/*test cases*/
|
||||
void test_pipe_put_fail(void *p1, void *p2, void *p3)
|
||||
{
|
||||
struct k_pipe pipe;
|
||||
size_t wt_byte = 0;
|
||||
|
||||
k_pipe_init(&pipe, data, PIPE_LEN);
|
||||
assert_false(k_pipe_put(&pipe, data, PIPE_LEN, &wt_byte,
|
||||
1, K_FOREVER), NULL);
|
||||
/**TESTPOINT: pipe put returns -EIO*/
|
||||
assert_equal(k_pipe_put(&pipe, data, PIPE_LEN, &wt_byte,
|
||||
1, K_NO_WAIT), -EIO, NULL);
|
||||
assert_false(wt_byte, NULL);
|
||||
/**TESTPOINT: pipe put returns -EAGAIN*/
|
||||
assert_equal(k_pipe_put(&pipe, data, PIPE_LEN, &wt_byte,
|
||||
1, TIMEOUT), -EAGAIN, NULL);
|
||||
assert_true(wt_byte < 1, NULL);
|
||||
}
|
||||
|
||||
void test_pipe_get_fail(void *p1, void *p2, void *p3)
|
||||
{
|
||||
struct k_pipe pipe;
|
||||
unsigned char rx_data[PIPE_LEN];
|
||||
size_t rd_byte = 0;
|
||||
|
||||
k_pipe_init(&pipe, data, PIPE_LEN);
|
||||
/**TESTPOINT: pipe put returns -EIO*/
|
||||
assert_equal(k_pipe_get(&pipe, rx_data, PIPE_LEN, &rd_byte, 1,
|
||||
K_NO_WAIT), -EIO, NULL);
|
||||
assert_false(rd_byte, NULL);
|
||||
/**TESTPOINT: pipe put returns -EAGAIN*/
|
||||
assert_equal(k_pipe_get(&pipe, rx_data, PIPE_LEN, &rd_byte, 1,
|
||||
TIMEOUT), -EAGAIN, NULL);
|
||||
assert_true(rd_byte < 1, NULL);
|
||||
}
|
2
tests/kernel/pipe/test_pipe_api/testcase.ini
Normal file
2
tests/kernel/pipe/test_pipe_api/testcase.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
[test]
|
||||
tags = kernel
|
Loading…
Add table
Add a link
Reference in a new issue