tests: kernel: poll: Add checks when having zero events
Make sure that we test scenario when number of events is zero. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
cc6317d7ac
commit
e1b8a2ee7e
2 changed files with 18 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
extern void test_poll_no_wait(void);
|
extern void test_poll_no_wait(void);
|
||||||
extern void test_poll_wait(void);
|
extern void test_poll_wait(void);
|
||||||
|
extern void test_poll_zero_events(void);
|
||||||
extern void test_poll_cancel_main_low_prio(void);
|
extern void test_poll_cancel_main_low_prio(void);
|
||||||
extern void test_poll_cancel_main_high_prio(void);
|
extern void test_poll_cancel_main_high_prio(void);
|
||||||
extern void test_poll_multi(void);
|
extern void test_poll_multi(void);
|
||||||
|
@ -31,6 +32,7 @@ void test_main(void)
|
||||||
ztest_test_suite(poll_api,
|
ztest_test_suite(poll_api,
|
||||||
ztest_1cpu_user_unit_test(test_poll_no_wait),
|
ztest_1cpu_user_unit_test(test_poll_no_wait),
|
||||||
ztest_1cpu_unit_test(test_poll_wait),
|
ztest_1cpu_unit_test(test_poll_wait),
|
||||||
|
ztest_1cpu_unit_test(test_poll_zero_events),
|
||||||
ztest_1cpu_unit_test(test_poll_cancel_main_low_prio),
|
ztest_1cpu_unit_test(test_poll_cancel_main_low_prio),
|
||||||
ztest_1cpu_unit_test(test_poll_cancel_main_high_prio),
|
ztest_1cpu_unit_test(test_poll_cancel_main_high_prio),
|
||||||
ztest_unit_test(test_poll_multi),
|
ztest_unit_test(test_poll_multi),
|
||||||
|
|
|
@ -21,6 +21,7 @@ struct fifo_msg {
|
||||||
static struct k_sem no_wait_sem;
|
static struct k_sem no_wait_sem;
|
||||||
static struct k_fifo no_wait_fifo;
|
static struct k_fifo no_wait_fifo;
|
||||||
static struct k_poll_signal no_wait_signal;
|
static struct k_poll_signal no_wait_signal;
|
||||||
|
static struct k_sem zero_events_sem;
|
||||||
static struct k_thread test_thread;
|
static struct k_thread test_thread;
|
||||||
static struct k_thread test_loprio_thread;
|
static struct k_thread test_loprio_thread;
|
||||||
K_THREAD_STACK_DEFINE(test_stack, STACK_SIZE);
|
K_THREAD_STACK_DEFINE(test_stack, STACK_SIZE);
|
||||||
|
@ -78,10 +79,12 @@ void test_poll_no_wait(void)
|
||||||
* implementation
|
* implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
zassert_equal(k_poll(events, 0, K_NO_WAIT), -EINVAL, NULL);
|
|
||||||
zassert_equal(k_poll(events, INT_MAX, K_NO_WAIT), -EINVAL, NULL);
|
zassert_equal(k_poll(events, INT_MAX, K_NO_WAIT), -EINVAL, NULL);
|
||||||
zassert_equal(k_poll(events, 4096, K_NO_WAIT), -ENOMEM, NULL);
|
zassert_equal(k_poll(events, 4096, K_NO_WAIT), -ENOMEM, NULL);
|
||||||
|
|
||||||
|
/* Allow zero events */
|
||||||
|
zassert_equal(k_poll(events, 0, K_NO_WAIT), -EAGAIN, NULL);
|
||||||
|
|
||||||
struct k_poll_event bad_events[] = {
|
struct k_poll_event bad_events[] = {
|
||||||
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SEM_AVAILABLE,
|
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SEM_AVAILABLE,
|
||||||
K_POLL_NUM_MODES,
|
K_POLL_NUM_MODES,
|
||||||
|
@ -622,3 +625,15 @@ void test_poll_grant_access(void)
|
||||||
&wait_signal, &test_thread,
|
&wait_signal, &test_thread,
|
||||||
&test_stack, &multi_sem, &multi_reply)
|
&test_stack, &multi_sem, &multi_reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_poll_zero_events(void)
|
||||||
|
{
|
||||||
|
struct k_poll_event event;
|
||||||
|
|
||||||
|
k_sem_init(&zero_events_sem, 1, 1);
|
||||||
|
|
||||||
|
k_poll_event_init(&event, K_POLL_TYPE_SEM_AVAILABLE,
|
||||||
|
K_POLL_MODE_NOTIFY_ONLY, &zero_events_sem);
|
||||||
|
|
||||||
|
zassert_equal(k_poll(&event, 0, K_MSEC(50)), -EAGAIN, NULL);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue