From ea43e3d5a060c14963260a83096fdcc54a9e3672 Mon Sep 17 00:00:00 2001 From: riastradh Date: Sun, 10 Apr 2022 11:36:32 +0000 Subject: [PATCH] membar_ops(3): Simplify alarm handling in membar tests. --- 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(-) diff --git a/tests/lib/libc/membar/t_dekker.c b/tests/lib/libc/membar/t_dekker.c index 3ed179dc51d6..03212fe8ae1b 100644 --- a/tests/lib/libc/membar/t_dekker.c +++ b/tests/lib/libc/membar/t_dekker.c @@ -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 -__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 #include @@ -39,7 +39,6 @@ __RCSID("$NetBSD: t_dekker.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $"); #include #include #include -#include #include #include #include @@ -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) diff --git a/tests/lib/libc/membar/t_seqlock.c b/tests/lib/libc/membar/t_seqlock.c index bbce2839da7f..8f2f0d6e2fed 100644 --- a/tests/lib/libc/membar/t_seqlock.c +++ b/tests/lib/libc/membar/t_seqlock.c @@ -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 -__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 #include @@ -39,7 +39,6 @@ __RCSID("$NetBSD: t_seqlock.c,v 1.1 2022/04/08 23:35:52 riastradh Exp $"); #include #include #include -#include #include #include #include @@ -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) diff --git a/tests/lib/libc/membar/t_spinlock.c b/tests/lib/libc/membar/t_spinlock.c index f32008d5f666..7a2f910267f0 100644 --- a/tests/lib/libc/membar/t_spinlock.c +++ b/tests/lib/libc/membar/t_spinlock.c @@ -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 -__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 #include @@ -39,7 +39,6 @@ __RCSID("$NetBSD: t_spinlock.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $"); #include #include #include -#include #include #include #include @@ -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)