Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/membar membar_ops(3): Simplify alarm handling...



details:   https://anonhg.NetBSD.org/src/rev/01530eadbc58
branches:  trunk
changeset: 365182:01530eadbc58
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Apr 10 11:36:32 2022 +0000

description:
membar_ops(3): Simplify alarm handling in membar tests.

diffstat:

 tests/lib/libc/membar/t_dekker.c   |  20 ++++++--------------
 tests/lib/libc/membar/t_seqlock.c  |  20 ++++++--------------
 tests/lib/libc/membar/t_spinlock.c |  20 ++++++--------------
 3 files changed, 18 insertions(+), 42 deletions(-)

diffs (201 lines):

diff -r e8cae57ffb5d -r 01530eadbc58 tests/lib/libc/membar/t_dekker.c
--- a/tests/lib/libc/membar/t_dekker.c  Sun Apr 10 10:38:33 2022 +0000
+++ b/tests/lib/libc/membar/t_dekker.c  Sun Apr 10 11:36:32 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_dekker.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $   */
+/*     $NetBSD: t_dekker.c,v 1.3 2022/04/10 11:36:32 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_dekker.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $");
+__RCSID("$NetBSD: t_dekker.c,v 1.3 2022/04/10 11:36:32 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/param.h>
@@ -39,7 +39,6 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <pthread.h>
-#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -95,14 +94,6 @@
        membar_producer();
 }
 
-static void
-alarm_handler(int signo)
-{
-
-       (void)signo;
-       times_up = 1;
-}
-
 static void *
 thread(void *cookie)
 {
@@ -135,21 +126,22 @@
        size_t ncpulen = sizeof(ncpu);
        int error;
 
+       alarm(10);
+
        if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
                atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
        assert(ncpulen == sizeof(ncpu));
        if (ncpu == 1)
                atf_tc_skip("membar tests are only for multicore systems");
 
-       if (signal(SIGALRM, alarm_handler) == SIG_ERR)
-               err(1, "signal(SIGALRM");
-       alarm(5);
        for (i = 0; i < 2; i++) {
                error = pthread_create(&t[i], NULL, &thread,
                    (void *)(uintptr_t)i);
                if (error)
                        errc(1, error, "pthread_create");
        }
+       sleep(5);
+       times_up = 1;
        for (i = 0; i < 2; i++) {
                error = pthread_join(t[i], NULL);
                if (error)
diff -r e8cae57ffb5d -r 01530eadbc58 tests/lib/libc/membar/t_seqlock.c
--- a/tests/lib/libc/membar/t_seqlock.c Sun Apr 10 10:38:33 2022 +0000
+++ b/tests/lib/libc/membar/t_seqlock.c Sun Apr 10 11:36:32 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_seqlock.c,v 1.1 2022/04/08 23:35:52 riastradh Exp $  */
+/*     $NetBSD: t_seqlock.c,v 1.2 2022/04/10 11:36:32 riastradh Exp $  */
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_seqlock.c,v 1.1 2022/04/08 23:35:52 riastradh Exp $");
+__RCSID("$NetBSD: t_seqlock.c,v 1.2 2022/04/10 11:36:32 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/param.h>
@@ -39,7 +39,6 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <pthread.h>
-#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -64,14 +63,6 @@
 
 uint64_t results[2];
 
-static void
-alarm_handler(int signo)
-{
-
-       (void)signo;
-       times_up = 1;
-}
-
 static void *
 writer(void *cookie)
 {
@@ -163,21 +154,22 @@
        size_t ncpulen = sizeof(ncpu);
        int error;
 
+       alarm(10);
+
        if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
                atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
        assert(ncpulen == sizeof(ncpu));
        if (ncpu == 1)
                atf_tc_skip("membar tests are only for multicore systems");
 
-       if (signal(SIGALRM, alarm_handler) == SIG_ERR)
-               err(1, "signal(SIGALRM");
-       alarm(5);
        for (i = 0; i < 2; i++) {
                error = pthread_create(&t[i], NULL, start[i],
                    (void *)(uintptr_t)i);
                if (error)
                        errc(1, error, "pthread_create");
        }
+       sleep(5);
+       times_up = 1;
        for (i = 0; i < 2; i++) {
                error = pthread_join(t[i], NULL);
                if (error)
diff -r e8cae57ffb5d -r 01530eadbc58 tests/lib/libc/membar/t_spinlock.c
--- a/tests/lib/libc/membar/t_spinlock.c        Sun Apr 10 10:38:33 2022 +0000
+++ b/tests/lib/libc/membar/t_spinlock.c        Sun Apr 10 11:36:32 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_spinlock.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $ */
+/*     $NetBSD: t_spinlock.c,v 1.3 2022/04/10 11:36:32 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_spinlock.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $");
+__RCSID("$NetBSD: t_spinlock.c,v 1.3 2022/04/10 11:36:32 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/param.h>
@@ -39,7 +39,6 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <pthread.h>
-#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -80,14 +79,6 @@
        lockbit = 0;
 }
 
-static void
-alarm_handler(int signo)
-{
-
-       (void)signo;
-       times_up = 1;
-}
-
 static void *
 thread(void *cookie)
 {
@@ -125,21 +116,22 @@
        size_t ncpulen = sizeof(ncpu);
        int error;
 
+       alarm(10);
+
        if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
                atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
        assert(ncpulen == sizeof(ncpu));
        if (ncpu == 1)
                atf_tc_skip("membar tests are only for multicore systems");
 
-       if (signal(SIGALRM, alarm_handler) == SIG_ERR)
-               err(1, "signal(SIGALRM");
-       alarm(5);
        for (i = 0; i < 2; i++) {
                error = pthread_create(&t[i], NULL, &thread,
                    (void *)(uintptr_t)i);
                if (error)
                        errc(1, error, "pthread_create");
        }
+       sleep(5);
+       times_up = 1;
        for (i = 0; i < 2; i++) {
                error = pthread_join(t[i], NULL);
                if (error)



Home | Main Index | Thread Index | Old Index