Kernel timeouts have always been a 32 bit integer despite the existence of generation macros, and existing code has been inconsistent about using them. Upcoming commits are going to make the timeout arguments opaque, so fix things up to be rigorously correct. Changes include: + Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout values for equality (e.g. with K_FOREVER or K_NO_WAIT). + Adding a k_msleep() synonym for k_sleep() which can continue to take integral arguments as k_sleep() moves away to timeout arguments. + Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to generate timeout arguments. + Removing the usage of K_NO_WAIT as the final argument to K_THREAD_DEFINE(). This is just a count of milliseconds and we need to use a zero. This patch include no logic changes and should not affect generated code at all. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
105 lines
2.2 KiB
C
105 lines
2.2 KiB
C
/*
|
|
* Copyright (c) 2016 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
|
|
#include <ztest.h>
|
|
|
|
#define TIMEOUT K_MSEC(100)
|
|
#define PIPE_LEN 8
|
|
|
|
static ZTEST_DMEM unsigned char __aligned(4) data[] = "abcd1234";
|
|
|
|
struct k_pipe put_get_pipe;
|
|
|
|
|
|
static void put_fail(struct k_pipe *p)
|
|
{
|
|
size_t wt_byte = 0;
|
|
|
|
zassert_false(k_pipe_put(p, data, PIPE_LEN, &wt_byte,
|
|
1, K_FOREVER), NULL);
|
|
/**TESTPOINT: pipe put returns -EIO*/
|
|
zassert_equal(k_pipe_put(p, data, PIPE_LEN, &wt_byte,
|
|
1, K_NO_WAIT), -EIO, NULL);
|
|
zassert_false(wt_byte, NULL);
|
|
/**TESTPOINT: pipe put returns -EAGAIN*/
|
|
zassert_equal(k_pipe_put(p, data, PIPE_LEN, &wt_byte,
|
|
1, TIMEOUT), -EAGAIN, NULL);
|
|
zassert_true(wt_byte < 1, NULL);
|
|
}
|
|
|
|
/**
|
|
* @brief Test pipe put failure scenario
|
|
* @ingroup kernel_pipe_tests
|
|
* @see k_pipe_init(), k_pipe_put()
|
|
*/
|
|
void test_pipe_put_fail(void)
|
|
{
|
|
k_pipe_init(&put_get_pipe, data, PIPE_LEN);
|
|
|
|
put_fail(&put_get_pipe);
|
|
}
|
|
/**
|
|
* @brief Test pipe put by a user thread
|
|
* @ingroup kernel_pipe_tests
|
|
* @see k_pipe_put()
|
|
*/
|
|
#ifdef CONFIG_USERSPACE
|
|
void test_pipe_user_put_fail(void)
|
|
{
|
|
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
|
|
|
|
zassert_true(p != NULL, NULL);
|
|
zassert_false(k_pipe_alloc_init(p, PIPE_LEN), NULL);
|
|
|
|
put_fail(p);
|
|
}
|
|
#endif
|
|
|
|
static void get_fail(struct k_pipe *p)
|
|
{
|
|
unsigned char rx_data[PIPE_LEN];
|
|
size_t rd_byte = 0;
|
|
|
|
/**TESTPOINT: pipe put returns -EIO*/
|
|
zassert_equal(k_pipe_get(p, rx_data, PIPE_LEN, &rd_byte, 1,
|
|
K_NO_WAIT), -EIO, NULL);
|
|
zassert_false(rd_byte, NULL);
|
|
/**TESTPOINT: pipe put returns -EAGAIN*/
|
|
zassert_equal(k_pipe_get(p, rx_data, PIPE_LEN, &rd_byte, 1,
|
|
TIMEOUT), -EAGAIN, NULL);
|
|
zassert_true(rd_byte < 1, NULL);
|
|
}
|
|
|
|
/**
|
|
* @brief Test pipe get failure scenario
|
|
* @ingroup kernel_pipe_tests
|
|
* @see k_pipe_init(), k_pipe_get()
|
|
*/
|
|
void test_pipe_get_fail(void)
|
|
{
|
|
k_pipe_init(&put_get_pipe, data, PIPE_LEN);
|
|
|
|
get_fail(&put_get_pipe);
|
|
}
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
/**
|
|
* @brief Test pipe get by a user thread
|
|
* @ingroup kernel_pipe_tests
|
|
* @see k_pipe_alloc_init()
|
|
*/
|
|
void test_pipe_user_get_fail(void)
|
|
{
|
|
struct k_pipe *p = k_object_alloc(K_OBJ_PIPE);
|
|
|
|
zassert_true(p != NULL, NULL);
|
|
zassert_false(k_pipe_alloc_init(p, PIPE_LEN), NULL);
|
|
|
|
get_fail(p);
|
|
}
|
|
#endif
|