Module Name: src Committed By: hannken Date: Mon Nov 1 14:33:42 UTC 2021
Modified Files: src/tests/lib/libc/sys: Makefile t_timerfd.c Log Message: Test lib/libc/sys/t_timerfd often fails when run on QEMU because QEMU misses clock interrupts. Always check values against [ lower, upper ] bounds and use "4 * upper" when run under QEMU. Now becomes part of PR kern/43997 "Kernel timer discrepancies". To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/tests/lib/libc/sys/Makefile cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_timerfd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/sys/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.69 src/tests/lib/libc/sys/Makefile:1.70 --- src/tests/lib/libc/sys/Makefile:1.69 Sun Sep 19 15:51:28 2021 +++ src/tests/lib/libc/sys/Makefile Mon Nov 1 14:33:41 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.69 2021/09/19 15:51:28 thorpej Exp $ +# $NetBSD: Makefile,v 1.70 2021/11/01 14:33:41 hannken Exp $ MKMAN= no @@ -117,6 +117,8 @@ LDADD.t_posix_fadvise+= ${LIBRUMPBASE} CPPFLAGS.t_futex_ops.c += -I${.CURDIR}/../../../../lib CPPFLAGS.t_futex_robust.c += -I${.CURDIR}/../../../../lib +CPPFLAGS.t_timerfd.c += -I${.CURDIR}/../gen + CPPFLAGS.t_lwp_create.c += -D_KERNTYPES CPPFLAGS.t_ptrace_sigchld.c += -D__TEST_FENV CPPFLAGS.t_ptrace_wait.c += -D_KERNTYPES -D__TEST_FENV Index: src/tests/lib/libc/sys/t_timerfd.c diff -u src/tests/lib/libc/sys/t_timerfd.c:1.2 src/tests/lib/libc/sys/t_timerfd.c:1.3 --- src/tests/lib/libc/sys/t_timerfd.c:1.2 Sun Sep 19 15:51:28 2021 +++ src/tests/lib/libc/sys/t_timerfd.c Mon Nov 1 14:33:41 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_timerfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $ */ +/* $NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include <sys/cdefs.h> __COPYRIGHT("@(#) Copyright (c) 2020\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_timerfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $"); +__RCSID("$NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $"); #include <sys/types.h> #include <sys/event.h> @@ -47,6 +47,8 @@ __RCSID("$NetBSD: t_timerfd.c,v 1.2 2021 #include <atf-c.h> +#include "isqemu.h" + struct helper_context { int fd; @@ -70,6 +72,26 @@ wait_barrier(struct helper_context * con return rv == 0 || rv == PTHREAD_BARRIER_SERIAL_THREAD; } +static bool +check_value_against_bounds(uint64_t value, uint64_t lower, uint64_t upper) +{ + + /* + * If running under QEMU make sure the upper bound is large + * enough for the effect of kern/43997 + */ + if (isQEMU()) { + upper *= 4; + } + + if (value < lower || value > upper) { + printf("val %" PRIu64 " not in [ %" PRIu64 ", %" PRIu64 " ]\n", + value, lower, upper); + } + + return value >= lower && value <= upper; +} + /*****************************************************************************/ static int @@ -169,10 +191,10 @@ ATF_TC_BODY(timerfd_block, tc) ATF_REQUIRE(timerfd_settime(fd, 0, &its, NULL) == 0); ATF_REQUIRE(timerfd_read(fd, &val) == 0); ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &now) == 0); - ATF_REQUIRE(val == 1); + ATF_REQUIRE(check_value_against_bounds(val, 1, 1)); timespecsub(&now, &then, &delta); - ATF_REQUIRE(delta.tv_sec == 1); + ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1)); (void) close(fd); } @@ -203,10 +225,11 @@ ATF_TC_BODY(timerfd_repeating, tc) ATF_REQUIRE(sleep(1) == 0); ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &now) == 0); ATF_REQUIRE(timerfd_read(fd, &val) == 0); - ATF_REQUIRE(val >= 3 && val <= 5); /* allow some slop */ + /* allow some slop */ + ATF_REQUIRE(check_value_against_bounds(val, 3, 5)); timespecsub(&now, &then, &delta); - ATF_REQUIRE(delta.tv_sec == 1); + ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1)); (void) close(fd); } @@ -237,10 +260,10 @@ ATF_TC_BODY(timerfd_abstime, tc) ATF_REQUIRE(timerfd_settime(fd, TFD_TIMER_ABSTIME, &its, NULL) == 0); ATF_REQUIRE(timerfd_read(fd, &val) == 0); ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &now) == 0); - ATF_REQUIRE(val == 1); + ATF_REQUIRE(check_value_against_bounds(val, 1, 1)); timespecsub(&now, &then, &delta); - ATF_REQUIRE(delta.tv_sec == 1); + ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1)); (void) close(fd); }