Skip to content

Commit 94b9640

Browse files
Andrew Boienashif
authored andcommitted
tests: poll: expand userspace coverage
The syscall handler for k_poll() returns error values instead of killing the caller for various bad arguments, cover these cases. Signed-off-by: Andrew Boie <[email protected]>
1 parent db84a76 commit 94b9640

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/kernel/poll/src/test_poll.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@ void test_poll_no_wait(void)
7070
NULL),
7171
};
7272

73+
#ifdef CONFIG_USERSPACE
74+
/* Test that k_poll() syscall handler safely handles being
75+
* fed garbage
76+
*
77+
* TODO: Where possible migrate these to the main k_poll()
78+
* implementation
79+
*/
80+
81+
zassert_equal(k_poll(events, 0, 0), -EINVAL, NULL);
82+
zassert_equal(k_poll(events, INT_MAX, 0), -EINVAL, NULL);
83+
zassert_equal(k_poll(events, 4096, 0), -ENOMEM, NULL);
84+
85+
struct k_poll_event bad_events[] = {
86+
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SEM_AVAILABLE,
87+
K_POLL_NUM_MODES,
88+
&no_wait_sem),
89+
};
90+
zassert_equal(k_poll(bad_events, ARRAY_SIZE(bad_events), 0), -EINVAL,
91+
NULL);
92+
93+
struct k_poll_event bad_events2[] = {
94+
K_POLL_EVENT_INITIALIZER(0xFU,
95+
K_POLL_MODE_NOTIFY_ONLY,
96+
&no_wait_sem),
97+
};
98+
zassert_equal(k_poll(bad_events2, ARRAY_SIZE(bad_events), 0), -EINVAL,
99+
NULL);
100+
#endif /* CONFIG_USERSPACE */
101+
73102
/* test polling events that are already ready */
74103
zassert_false(k_fifo_alloc_put(&no_wait_fifo, &msg), NULL);
75104
k_poll_signal_raise(&no_wait_signal, SIGNAL_RESULT);

0 commit comments

Comments
 (0)