Module Name: src Committed By: riastradh Date: Sun Apr 10 11:36:32 UTC 2022
Modified Files: src/tests/lib/libc/membar: t_dekker.c t_seqlock.c t_spinlock.c Log Message: membar_ops(3): Simplify alarm handling in membar tests. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/membar/t_dekker.c \ src/tests/lib/libc/membar/t_spinlock.c cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/membar/t_seqlock.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/membar/t_dekker.c diff -u src/tests/lib/libc/membar/t_dekker.c:1.2 src/tests/lib/libc/membar/t_dekker.c:1.3 --- src/tests/lib/libc/membar/t_dekker.c:1.2 Sat Apr 9 23:32:53 2022 +++ src/tests/lib/libc/membar/t_dekker.c Sun Apr 10 11:36:32 2022 @@ -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 @@ __RCSID("$NetBSD: t_dekker.c,v 1.2 2022/ #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 @@ unlock(unsigned me) membar_producer(); } -static void -alarm_handler(int signo) -{ - - (void)signo; - times_up = 1; -} - static void * thread(void *cookie) { @@ -135,21 +126,22 @@ ATF_TC_BODY(dekker, tc) 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) Index: src/tests/lib/libc/membar/t_spinlock.c diff -u src/tests/lib/libc/membar/t_spinlock.c:1.2 src/tests/lib/libc/membar/t_spinlock.c:1.3 --- src/tests/lib/libc/membar/t_spinlock.c:1.2 Sat Apr 9 23:32:53 2022 +++ src/tests/lib/libc/membar/t_spinlock.c Sun Apr 10 11:36:32 2022 @@ -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 @@ __RCSID("$NetBSD: t_spinlock.c,v 1.2 202 #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 @@ unlock(void) lockbit = 0; } -static void -alarm_handler(int signo) -{ - - (void)signo; - times_up = 1; -} - static void * thread(void *cookie) { @@ -125,21 +116,22 @@ ATF_TC_BODY(spinlock, tc) 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) Index: src/tests/lib/libc/membar/t_seqlock.c diff -u src/tests/lib/libc/membar/t_seqlock.c:1.1 src/tests/lib/libc/membar/t_seqlock.c:1.2 --- src/tests/lib/libc/membar/t_seqlock.c:1.1 Fri Apr 8 23:35:52 2022 +++ src/tests/lib/libc/membar/t_seqlock.c Sun Apr 10 11:36:32 2022 @@ -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 @@ __RCSID("$NetBSD: t_seqlock.c,v 1.1 2022 #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 @@ volatile struct { uint64_t results[2]; -static void -alarm_handler(int signo) -{ - - (void)signo; - times_up = 1; -} - static void * writer(void *cookie) { @@ -163,21 +154,22 @@ ATF_TC_BODY(seqlock, tc) 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)