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 Fix getrandom() tests.



details:   https://anonhg.NetBSD.org/src/rev/771d57a78f96
branches:  trunk
changeset: 1013306:771d57a78f96
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Aug 25 01:37:38 2020 +0000

description:
Fix getrandom() tests.

Use sigaction() without SA_RESTART -- signal() implies SA_RESTART so
we never got the EINTR.

While here, reduce the timeout to something more reasonable so we
don't waste 20min of testbed time if anything goes wrong and the
one-second alarm doesn't fire.

diffstat:

 tests/lib/libc/sys/t_getrandom.c |  29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diffs (82 lines):

diff -r 98f94c9c2f8f -r 771d57a78f96 tests/lib/libc/sys/t_getrandom.c
--- a/tests/lib/libc/sys/t_getrandom.c  Mon Aug 24 20:15:51 2020 +0000
+++ b/tests/lib/libc/sys/t_getrandom.c  Tue Aug 25 01:37:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_getrandom.c,v 1.2 2020/08/23 17:50:19 riastradh Exp $        */
+/*     $NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,13 +30,14 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_getrandom.c,v 1.2 2020/08/23 17:50:19 riastradh Exp $");
+__RCSID("$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $");
 
 #include <sys/random.h>
 
 #include <atf-c.h>
 #include <errno.h>
 #include <signal.h>
+#include <stdio.h>
 #include <unistd.h>
 
 static uint8_t buf[65536];
@@ -45,6 +46,22 @@
 static void
 alarm_handler(int signo)
 {
+
+       fprintf(stderr, "timeout\n");
+}
+
+static void
+install_alarm_handler(void)
+{
+       struct sigaction sa;
+
+       memset(&sa, 0, sizeof sa);
+       sa.sa_handler = alarm_handler;
+       sigfillset(&sa.sa_mask);
+       sa.sa_flags = 0;        /* no SA_RESTART */
+
+       ATF_CHECK_MSG(sigaction(SIGALRM, &sa, NULL) != -1,
+           "sigaction(SIGALRM): %s", strerror(errno));
 }
 
 /*
@@ -58,14 +75,14 @@
 ATF_TC_HEAD(getrandom_default, tc)
 {
        atf_tc_set_md_var(tc, "descr", "getrandom(..., 0)");
+       atf_tc_set_md_var(tc, "timeout", "2");
 }
 ATF_TC_BODY(getrandom_default, tc)
 {
        ssize_t n;
 
-       ATF_REQUIRE(signal(SIGALRM, &alarm_handler) != SIG_ERR);
-
        /* default */
+       install_alarm_handler();
        alarm(1);
        memset(buf, 0, sizeof buf);
        n = getrandom(buf, sizeof buf, 0);
@@ -141,14 +158,14 @@
 ATF_TC_HEAD(getrandom_random, tc)
 {
        atf_tc_set_md_var(tc, "descr", "getrandom(..., GRND_RANDOM)");
+       atf_tc_set_md_var(tc, "timeout", "2");
 }
 ATF_TC_BODY(getrandom_random, tc)
 {
        ssize_t n;
 
-       ATF_REQUIRE(signal(SIGALRM, &alarm_handler) != SIG_ERR);
-
        /* `random' (hokey) */
+       install_alarm_handler();
        alarm(1);
        memset(buf, 0, sizeof buf);
        n = getrandom(buf, sizeof buf, GRND_RANDOM);



Home | Main Index | Thread Index | Old Index