From 978871c4509659ca320938e16004a44a9baa4e2f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 31 Mar 2025 12:06:45 +1000 Subject: [PATCH] test: abort litest_wait_for_events() if we don't get events after 2s Previously we kept polling but this just delays what will almost certainly be a failure anyway - none of our tests require even 2000ms for an event to arrive. Part-of: --- test/litest.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/litest.c b/test/litest.c index c89a61c6..7f0ae5c1 100644 --- a/test/litest.c +++ b/test/litest.c @@ -3465,17 +3465,33 @@ _litest_wait_for_event_of_type(struct libinput *li, fds.events = POLLIN; fds.revents = 0; + const int timeout = 2000; + uint64_t expiry = 0; + int rc = now_in_us(&expiry); + expiry += ms2us(timeout); + litest_assert_errno_success(rc); + while (1) { size_t i; struct libinput_event *event; + enum libinput_event_type type; while ((type = libinput_next_event_type(li)) == LIBINPUT_EVENT_NONE) { - int rc = poll(&fds, 1, 2000); + int rc = poll(&fds, 1, timeout); litest_assert_errno_success(rc); litest_assert_int_gt(rc, 0); libinput_dispatch(li); } + if (type == LIBINPUT_EVENT_NONE) { + uint64_t now; + now_in_us(&now); + if (now > expiry) { + litest_abort_msg("Waited >%dms for events, but no events are pending", + timeout); + } + } + /* no event mask means wait for any event */ if (ntypes == 0) return;