Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Test lib/libc/sys/t_timerfd often fails w...



details:   https://anonhg.NetBSD.org/src/rev/f4e0c3cf1d57
branches:  trunk
changeset: 990661:f4e0c3cf1d57
user:      hannken <hannken%NetBSD.org@localhost>
date:      Mon Nov 01 14:33:41 2021 +0000

description:
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".

diffstat:

 tests/lib/libc/sys/Makefile    |   4 +++-
 tests/lib/libc/sys/t_timerfd.c |  39 +++++++++++++++++++++++++++++++--------
 2 files changed, 34 insertions(+), 9 deletions(-)

diffs (112 lines):

diff -r 4bcb0a18a642 -r f4e0c3cf1d57 tests/lib/libc/sys/Makefile
--- a/tests/lib/libc/sys/Makefile       Mon Nov 01 13:30:11 2021 +0000
+++ b/tests/lib/libc/sys/Makefile       Mon Nov 01 14:33:41 2021 +0000
@@ -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 @@
 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
diff -r 4bcb0a18a642 -r f4e0c3cf1d57 tests/lib/libc/sys/t_timerfd.c
--- a/tests/lib/libc/sys/t_timerfd.c    Mon Nov 01 13:30:11 2021 +0000
+++ b/tests/lib/libc/sys/t_timerfd.c    Mon Nov 01 14:33:41 2021 +0000
@@ -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 @@
 
 #include <atf-c.h>
 
+#include "isqemu.h"
+
 struct helper_context {
        int     fd;
 
@@ -70,6 +72,26 @@
        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_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_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_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);
 }



Home | Main Index | Thread Index | Old Index