In slow or emulated environments, the hardcoded 1-second watchdog
timeout in kill_timeout() can easily expire before threads finish
scheduling and processing events, causing spurious test failures.

Add support for KSFT_MACHINE_SLOW, which is already used in kselftest,
to increase the timeout multiplier to 10x (10 seconds). Furthermore,
allow KSFT_TIMEOUT_MUL to explicitly override the multiplier.

Signed-off-by: Florian Schmaus <[email protected]>
---
 .../filesystems/epoll/epoll_wakeup_test.c          | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c 
b/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
index 81a994943e12..8d5b15a09439 100644
--- a/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
+++ b/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
@@ -40,9 +40,29 @@ static void signal_handler(int signum)
 {
 }
 
+static unsigned int get_timeout_multiplier(void)
+{
+       const char *mul_str = getenv("KSFT_TIMEOUT_MUL");
+       const char *slow_str = getenv("KSFT_MACHINE_SLOW");
+       unsigned int mul = 1;
+
+       if (slow_str)
+               mul = 10;
+
+       if (mul_str) {
+               int val;
+
+               val = atoi(mul_str);
+               if (val > 0)
+                       mul = (unsigned int)val;
+       }
+
+       return mul;
+}
+
 static void kill_timeout(struct epoll_mtcontext *ctx)
 {
-       usleep(1000000);
+       usleep(1000000 * get_timeout_multiplier());
        pthread_kill(ctx->main, SIGUSR1);
        pthread_kill(ctx->waiter, SIGUSR1);
 }

---
base-commit: 1b78070aaef63512688aebfbc82365ef9d6660f1
change-id: 20260828-selftest-epoll-timeout-0d47c17beaa2

Best regards,
--  
Florian Schmaus <[email protected]>


Reply via email to