tests: kernel: pipe_api: move to new ztest API

Move tests/kernel/pipe/pipe_api/ to use new ztest API.

Signed-off-by: Guo Lixin <lixinx.guo@intel.com>
This commit is contained in:
Guo Lixin 2022-07-04 10:43:34 +08:00 committed by Anas Nashif
parent af1e0c5a00
commit 05c13ac094
5 changed files with 35 additions and 116 deletions

View file

@ -4,3 +4,4 @@ CONFIG_TEST_USERSPACE=y
CONFIG_DYNAMIC_OBJECTS=y
CONFIG_MP_NUM_CPUS=1
CONFIG_ZTEST_FATAL_HOOK=y
CONFIG_ZTEST_NEW_API=y

View file

@ -12,42 +12,6 @@
*/
#include <ztest.h>
extern void test_pipe_thread2thread(void);
extern void test_pipe_put_fail(void);
extern void test_pipe_get_fail(void);
extern void test_pipe_block_put(void);
extern void test_pipe_block_put_sema(void);
extern void test_pipe_get_put(void);
extern void test_pipe_get_large(void);
extern void test_half_pipe_put_get(void);
extern void test_half_pipe_saturating_block_put(void);
extern void test_half_pipe_block_put_sema(void);
extern void test_pipe_alloc(void);
extern void test_pipe_reader_wait(void);
extern void test_pipe_block_writer_wait(void);
extern void test_pipe_cleanup(void);
#ifdef CONFIG_USERSPACE
extern void test_pipe_user_thread2thread(void);
extern void test_pipe_user_put_fail(void);
extern void test_pipe_user_get_fail(void);
extern void test_resource_pool_auto_free(void);
extern void test_pipe_alloc_not_init(void);
extern void test_pipe_get_null(void);
extern void test_pipe_get_unreach_data(void);
extern void test_pipe_get_unreach_size(void);
extern void test_pipe_put_null(void);
extern void test_pipe_put_unreach_data(void);
extern void test_pipe_put_unreach_size(void);
extern void test_pipe_read_avail_null(void);
extern void test_pipe_write_avail_null(void);
#endif
extern void test_pipe_avail_r_lt_w(void);
extern void test_pipe_avail_w_lt_r(void);
extern void test_pipe_avail_r_eq_w_full(void);
extern void test_pipe_avail_r_eq_w_empty(void);
extern void test_pipe_avail_no_buffer(void);
/* k objects */
extern struct k_pipe pipe, kpipe, khalfpipe, put_get_pipe;
@ -56,30 +20,7 @@ extern struct k_stack tstack;
extern struct k_thread tdata;
extern struct k_heap test_pool;
#ifndef CONFIG_USERSPACE
#define dummy_test(_name) \
static void _name(void) \
{ \
ztest_test_skip(); \
}
dummy_test(test_pipe_user_thread2thread);
dummy_test(test_pipe_user_put_fail);
dummy_test(test_pipe_user_get_fail);
dummy_test(test_resource_pool_auto_free);
dummy_test(test_pipe_alloc_not_init);
dummy_test(test_pipe_get_null);
dummy_test(test_pipe_get_unreach_data);
dummy_test(test_pipe_get_unreach_size);
dummy_test(test_pipe_put_null);
dummy_test(test_pipe_put_unreach_data);
dummy_test(test_pipe_put_unreach_size);
dummy_test(test_pipe_read_avail_null);
dummy_test(test_pipe_write_avail_null);
#endif /* !CONFIG_USERSPACE */
/*test case main entry*/
void test_main(void)
static void *pipe_api_setup(void)
{
k_thread_access_grant(k_current_get(), &pipe,
&kpipe, &end_sema, &tdata, &tstack,
@ -87,33 +28,10 @@ void test_main(void)
k_thread_heap_assign(k_current_get(), &test_pool);
ztest_test_suite(pipe_api,
ztest_1cpu_unit_test(test_pipe_thread2thread),
ztest_1cpu_user_unit_test(test_pipe_user_thread2thread),
ztest_1cpu_user_unit_test(test_pipe_user_put_fail),
ztest_user_unit_test(test_pipe_user_get_fail),
ztest_user_unit_test(test_pipe_alloc_not_init),
ztest_user_unit_test(test_pipe_get_null),
ztest_user_unit_test(test_pipe_get_unreach_data),
ztest_user_unit_test(test_pipe_get_unreach_size),
ztest_user_unit_test(test_pipe_put_null),
ztest_user_unit_test(test_pipe_put_unreach_data),
ztest_user_unit_test(test_pipe_put_unreach_size),
ztest_user_unit_test(test_pipe_read_avail_null),
ztest_user_unit_test(test_pipe_write_avail_null),
ztest_unit_test(test_resource_pool_auto_free),
ztest_1cpu_unit_test(test_pipe_put_fail),
ztest_unit_test(test_pipe_get_fail),
ztest_unit_test(test_half_pipe_put_get),
ztest_unit_test(test_pipe_get_put),
ztest_unit_test(test_pipe_get_large),
ztest_1cpu_unit_test(test_pipe_alloc),
ztest_unit_test(test_pipe_cleanup),
ztest_unit_test(test_pipe_reader_wait),
ztest_unit_test(test_pipe_avail_r_lt_w),
ztest_unit_test(test_pipe_avail_w_lt_r),
ztest_unit_test(test_pipe_avail_r_eq_w_full),
ztest_unit_test(test_pipe_avail_r_eq_w_empty),
ztest_unit_test(test_pipe_avail_no_buffer));
ztest_run_test_suite(pipe_api);
return NULL;
}
ZTEST_SUITE(pipe_api, NULL, pipe_api_setup, NULL, NULL, NULL);
ZTEST_SUITE(pipe_api_1cpu, NULL, pipe_api_setup,
ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL);

View file

@ -40,7 +40,7 @@ static struct k_pipe bufferless1 = {
* simultaneously return 0 for a buffered pipe, but they will both return 0
* for an unbuffered pipe.
*/
void test_pipe_avail_no_buffer(void)
ZTEST(pipe_api, test_pipe_avail_no_buffer)
{
size_t r_avail;
size_t w_avail;
@ -80,7 +80,7 @@ void test_pipe_avail_no_buffer(void)
* w_avail = N - (w - r) = 5
* would overwrite: e f g h
*/
void test_pipe_avail_r_lt_w(void)
ZTEST(pipe_api, test_pipe_avail_r_lt_w)
{
size_t r_avail;
size_t w_avail;
@ -119,7 +119,7 @@ void test_pipe_avail_r_lt_w(void)
* w_avail = r - w = 3
* would overwrite: a b c d
*/
void test_pipe_avail_w_lt_r(void)
ZTEST(pipe_api, test_pipe_avail_w_lt_r)
{
size_t r_avail;
size_t w_avail;
@ -162,7 +162,7 @@ void test_pipe_avail_w_lt_r(void)
* w_avail = N - 0 = 8
* would overwrite: e f g h a b c d
*/
void test_pipe_avail_r_eq_w_empty(void)
ZTEST(pipe_api, test_pipe_avail_r_eq_w_empty)
{
size_t r_avail;
size_t w_avail;
@ -205,7 +205,7 @@ void test_pipe_avail_r_eq_w_empty(void)
* w_avail = N - 8 = 0
* would overwrite:
*/
void test_pipe_avail_r_eq_w_full(void)
ZTEST(pipe_api, test_pipe_avail_r_eq_w_full)
{
size_t r_avail;
size_t w_avail;

View file

@ -184,7 +184,7 @@ static void tpipe_get_large_size(struct k_pipe *ppipe, k_timeout_t timeout)
* with various parameters
* @see k_pipe_alloc_init(), k_pipe_cleanup()
*/
void test_pipe_alloc(void)
ZTEST(pipe_api_1cpu, test_pipe_alloc)
{
int ret;
@ -206,7 +206,7 @@ static void thread_for_get_forever(void *p1, void *p2, void *p3)
tpipe_get((struct k_pipe *)p1, K_FOREVER);
}
void test_pipe_cleanup(void)
ZTEST(pipe_api, test_pipe_cleanup)
{
int ret;
@ -289,7 +289,7 @@ static void thread_handler(void *p1, void *p2, void *p3)
* @see k_pipe_init(), k_pipe_put(), #K_PIPE_DEFINE(x)
*/
void test_pipe_thread2thread(void)
ZTEST(pipe_api_1cpu, test_pipe_thread2thread)
{
/**TESTPOINT: test k_pipe_init pipe*/
k_pipe_init(&pipe, data, PIPE_LEN);
@ -304,7 +304,7 @@ void test_pipe_thread2thread(void)
* @brief Test data passing using pipes between user threads
* @see k_pipe_init(), k_pipe_put(), #K_PIPE_DEFINE(x)
*/
void test_pipe_user_thread2thread(void)
ZTEST_USER(pipe_api_1cpu, test_pipe_user_thread2thread)
{
/**TESTPOINT: test k_object_alloc pipe*/
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
@ -323,7 +323,7 @@ void test_pipe_user_thread2thread(void)
* @see k_heap_alloc()
*/
#ifdef CONFIG_USERSPACE
void test_resource_pool_auto_free(void)
ZTEST(pipe_api, test_resource_pool_auto_free)
{
/* Pool has 2 blocks, both should succeed if kernel object and pipe
* buffer are auto-freed when the allocating threads exit
@ -347,7 +347,7 @@ static void tThread_half_pipe_get(void *p1, void *p2, void *p3)
* @brief Test put/get with smaller pipe buffer
* @see k_pipe_put(), k_pipe_get()
*/
void test_half_pipe_put_get(void)
ZTEST(pipe_api, test_half_pipe_put_get)
{
unsigned char rx_data[PIPE_LEN];
size_t rd_byte = 0;
@ -378,7 +378,7 @@ void test_half_pipe_put_get(void)
k_thread_abort(tid2);
}
void test_pipe_get_put(void)
ZTEST(pipe_api, test_pipe_get_put)
{
unsigned char rx_data[PIPE_LEN];
size_t rd_byte = 0;
@ -409,7 +409,7 @@ void test_pipe_get_put(void)
k_thread_abort(tid2);
}
void test_pipe_get_large(void)
ZTEST(pipe_api, test_pipe_get_large)
{
/**TESTPOINT: thread-thread data passing via pipe*/
k_tid_t tid1 = k_thread_create(&tdata1, tstack1, STACK_SIZE,
@ -435,7 +435,7 @@ void test_pipe_get_large(void)
* @brief Test pending reader in pipe
* @see k_pipe_put(), k_pipe_get()
*/
void test_pipe_reader_wait(void)
ZTEST(pipe_api, test_pipe_reader_wait)
{
/**TESTPOINT: test k_pipe_block_put with semaphore*/
k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE,

View file

@ -38,7 +38,7 @@ static void put_fail(struct k_pipe *p)
* @ingroup kernel_pipe_tests
* @see k_pipe_init(), k_pipe_put()
*/
void test_pipe_put_fail(void)
ZTEST(pipe_api_1cpu, test_pipe_put_fail)
{
k_pipe_init(&put_get_pipe, data, PIPE_LEN);
@ -50,7 +50,7 @@ void test_pipe_put_fail(void)
* @see k_pipe_put()
*/
#ifdef CONFIG_USERSPACE
void test_pipe_user_put_fail(void)
ZTEST_USER(pipe_api_1cpu, test_pipe_user_put_fail)
{
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
@ -87,7 +87,7 @@ static void get_fail(struct k_pipe *p)
* @ingroup kernel_pipe_tests
* @see k_pipe_init(), k_pipe_get()
*/
void test_pipe_get_fail(void)
ZTEST(pipe_api, test_pipe_get_fail)
{
k_pipe_init(&put_get_pipe, data, PIPE_LEN);
@ -103,7 +103,7 @@ static size_t unreach_byte;
* @ingroup kernel_pipe_tests
* @see k_pipe_alloc_init()
*/
void test_pipe_user_get_fail(void)
ZTEST_USER(pipe_api, test_pipe_user_get_fail)
{
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
@ -123,7 +123,7 @@ void test_pipe_user_get_fail(void)
*
* @see k_pipe_alloc_init()
*/
void test_pipe_alloc_not_init(void)
ZTEST_USER(pipe_api, test_pipe_alloc_not_init)
{
struct k_pipe pipe;
@ -141,7 +141,7 @@ void test_pipe_alloc_not_init(void)
*
* @see k_pipe_get()
*/
void test_pipe_get_null(void)
ZTEST_USER(pipe_api, test_pipe_get_null)
{
unsigned char rx_data[PIPE_LEN];
size_t rd_byte = 0;
@ -161,7 +161,7 @@ void test_pipe_get_null(void)
*
* @see k_pipe_get()
*/
void test_pipe_get_unreach_data(void)
ZTEST_USER(pipe_api, test_pipe_get_unreach_data)
{
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
size_t rd_byte = 0;
@ -185,7 +185,7 @@ void test_pipe_get_unreach_data(void)
*
* @see k_pipe_get()
*/
void test_pipe_get_unreach_size(void)
ZTEST_USER(pipe_api, test_pipe_get_unreach_size)
{
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
unsigned char rx_data[PIPE_LEN];
@ -209,7 +209,7 @@ void test_pipe_get_unreach_size(void)
*
* @see k_pipe_put()
*/
void test_pipe_put_null(void)
ZTEST_USER(pipe_api, test_pipe_put_null)
{
unsigned char tx_data = 0xa;
size_t to_wt = 0, wt_byte = 0;
@ -229,7 +229,7 @@ void test_pipe_put_null(void)
*
* @see k_pipe_put()
*/
void test_pipe_put_unreach_data(void)
ZTEST_USER(pipe_api, test_pipe_put_unreach_data)
{
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
size_t to_wt = 0, wt_byte = 0;
@ -253,7 +253,7 @@ void test_pipe_put_unreach_data(void)
*
* @see k_pipe_put()
*/
void test_pipe_put_unreach_size(void)
ZTEST_USER(pipe_api, test_pipe_put_unreach_size)
{
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
unsigned char tx_data = 0xa;
@ -277,7 +277,7 @@ void test_pipe_put_unreach_size(void)
*
* @see k_pipe_read_avail()
*/
void test_pipe_read_avail_null(void)
ZTEST_USER(pipe_api, test_pipe_read_avail_null)
{
ztest_set_fault_valid(true);
k_pipe_read_avail(NULL);
@ -293,7 +293,7 @@ void test_pipe_read_avail_null(void)
*
* @see k_pipe_write_avail()
*/
void test_pipe_write_avail_null(void)
ZTEST_USER(pipe_api, test_pipe_write_avail_null)
{
ztest_set_fault_valid(true);
k_pipe_write_avail(NULL);