Skip to content

Commit d370361

Browse files
Christopher Friedtnashif
authored andcommitted
tests: eventfd: blocking read-write test for deadlock bug
Previously, the prototypical use case for `eventfd()` was not possible in Zephyr due to a deadlock associated with the `fdtable.c` `k_mutex`. The prototypical use case for `eventfd()` is to make a blocking call to `eventfd_read()` from one thread, and then from another thread, call `eventfd_write()` to "wake up" the reading thread. This additional test case ensures that Zephyr supports the prototypical `eventfd()` use case. Signed-off-by: Christopher Friedt <[email protected]>
1 parent e6eb0a7 commit d370361

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/posix/eventfd/src/blocking.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,30 @@ ZTEST_F(eventfd, test_unset_poll_event_block)
7070
{
7171
eventfd_poll_unset_common(fixture->fd);
7272
}
73+
74+
K_THREAD_STACK_DEFINE(thread_stack, 2048);
75+
76+
static void thread_fun(void *arg1, void *arg2, void *arg3)
77+
{
78+
eventfd_t value;
79+
struct eventfd_fixture *fixture = arg1;
80+
81+
zassert_ok(eventfd_read(fixture->fd, &value));
82+
zassert_equal(value, 42);
83+
}
84+
85+
ZTEST_F(eventfd, test_read_then_write_block)
86+
{
87+
struct k_thread thread;
88+
89+
k_thread_create(&thread, thread_stack, K_THREAD_STACK_SIZEOF(thread_stack), thread_fun,
90+
fixture, NULL, NULL, 0, 0, K_NO_WAIT);
91+
92+
k_msleep(100);
93+
94+
/* this write never occurs */
95+
zassert_ok(eventfd_write(fixture->fd, 42));
96+
97+
/* unreachable code */
98+
k_thread_join(&thread, K_FOREVER);
99+
}

0 commit comments

Comments
 (0)