poll: add a testcase to detect is_polling

Add a testcase to detect is_polling, to avoid some
issues.

Fixed #12405

Signed-off-by: NingX Zhao <ningx.zhao@intel.com>
This commit is contained in:
NingX Zhao 2021-08-18 09:45:39 +08:00 committed by Christopher Friedt
commit c0d18079cc
2 changed files with 51 additions and 1 deletions

View file

@ -16,6 +16,7 @@ extern void test_poll_grant_access(void);
extern void test_poll_fail_grant_access(void);
extern void test_poll_lower_prio(void);
extern void test_condition_met_type_err(void);
extern void test_detect_is_polling(void);
#ifdef CONFIG_USERSPACE
extern void test_k_poll_user_num_err(void);
extern void test_k_poll_user_mem_err(void);
@ -75,6 +76,7 @@ void test_main(void)
ztest_unit_test(test_poll_multi),
ztest_1cpu_unit_test(test_poll_lower_prio),
ztest_1cpu_unit_test(test_poll_threadstate),
ztest_1cpu_unit_test(test_detect_is_polling),
ztest_1cpu_unit_test(test_condition_met_type_err),
ztest_user_unit_test(test_k_poll_user_num_err),
ztest_user_unit_test(test_k_poll_user_mem_err),

View file

@ -24,6 +24,7 @@ struct fifo_msg {
static struct k_sem no_wait_sem;
static struct k_fifo no_wait_fifo;
static struct k_poll_signal no_wait_signal;
static struct k_poll_signal test_signal;
#ifndef CONFIG_USERSPACE
static struct k_msgq no_wait_msgq;
#endif
@ -761,7 +762,7 @@ void test_poll_grant_access(void)
k_thread_access_grant(k_current_get(), &no_wait_sem, &no_wait_fifo,
&no_wait_signal, &wait_sem, &wait_fifo,
&cancel_fifo, &non_cancel_fifo,
&wait_signal, &test_thread,
&wait_signal, &test_thread, &test_signal,
&test_stack, &multi_sem, &multi_reply);
}
@ -776,3 +777,50 @@ void test_poll_zero_events(void)
zassert_equal(k_poll(&event, 0, K_MSEC(50)), -EAGAIN, NULL);
}
/* subthread entry */
void polling_event(void *p1, void *p2, void *p3)
{
k_poll(p1, 1, K_FOREVER);
}
/**
* @brief Detect is_polling is false in signal_poll_event()
*
* @details
* Define and initialize a signal event, and spawn a thread to
* poll event, and set dticks as invalid, check if the value
* of is_polling in function signal_poll_event().
*
* @ingroup kernel_poll_tests
*/
void test_detect_is_polling(void)
{
k_poll_signal_init(&test_signal);
struct k_thread *p = &test_thread;
struct k_poll_event events[1] = {
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY,
&test_signal),
};
k_thread_create(&test_thread, test_stack,
K_THREAD_STACK_SIZEOF(test_stack), polling_event,
events, NULL, NULL, K_PRIO_PREEMPT(0),
K_INHERIT_PERMS, K_NO_WAIT);
/* Set up the thread timeout value to check if
* what happened if dticks is invalid.
*/
p->base.timeout.dticks = _EXPIRED;
/* Wait for register event successfully */
k_sleep(K_MSEC(50));
/* Raise a signal */
int ret = k_poll_signal_raise(&test_signal, 0x1337);
zassert_true(ret == -EAGAIN, "thread expired failed\n");
zassert_true(events[0].poller->is_polling == false,
"the value of is_polling is invalid\n");
}