membar_ops(3): Simplify alarm handling in membar tests.
This commit is contained in:
parent
568eb77ef2
commit
ea43e3d5a0
|
@ -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.
|
* Copyright (c) 2022 The NetBSD Foundation, Inc.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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/atomic.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -39,7 +39,6 @@ __RCSID("$NetBSD: t_dekker.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $");
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -95,14 +94,6 @@ unlock(unsigned me)
|
||||||
membar_producer();
|
membar_producer();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
alarm_handler(int signo)
|
|
||||||
{
|
|
||||||
|
|
||||||
(void)signo;
|
|
||||||
times_up = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
thread(void *cookie)
|
thread(void *cookie)
|
||||||
{
|
{
|
||||||
|
@ -135,21 +126,22 @@ ATF_TC_BODY(dekker, tc)
|
||||||
size_t ncpulen = sizeof(ncpu);
|
size_t ncpulen = sizeof(ncpu);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
alarm(10);
|
||||||
|
|
||||||
if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
|
if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
|
||||||
atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
|
atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
|
||||||
assert(ncpulen == sizeof(ncpu));
|
assert(ncpulen == sizeof(ncpu));
|
||||||
if (ncpu == 1)
|
if (ncpu == 1)
|
||||||
atf_tc_skip("membar tests are only for multicore systems");
|
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++) {
|
for (i = 0; i < 2; i++) {
|
||||||
error = pthread_create(&t[i], NULL, &thread,
|
error = pthread_create(&t[i], NULL, &thread,
|
||||||
(void *)(uintptr_t)i);
|
(void *)(uintptr_t)i);
|
||||||
if (error)
|
if (error)
|
||||||
errc(1, error, "pthread_create");
|
errc(1, error, "pthread_create");
|
||||||
}
|
}
|
||||||
|
sleep(5);
|
||||||
|
times_up = 1;
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
error = pthread_join(t[i], NULL);
|
error = pthread_join(t[i], NULL);
|
||||||
if (error)
|
if (error)
|
||||||
|
|
|
@ -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.
|
* Copyright (c) 2022 The NetBSD Foundation, Inc.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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/atomic.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -39,7 +39,6 @@ __RCSID("$NetBSD: t_seqlock.c,v 1.1 2022/04/08 23:35:52 riastradh Exp $");
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -64,14 +63,6 @@ volatile struct {
|
||||||
|
|
||||||
uint64_t results[2];
|
uint64_t results[2];
|
||||||
|
|
||||||
static void
|
|
||||||
alarm_handler(int signo)
|
|
||||||
{
|
|
||||||
|
|
||||||
(void)signo;
|
|
||||||
times_up = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
writer(void *cookie)
|
writer(void *cookie)
|
||||||
{
|
{
|
||||||
|
@ -163,21 +154,22 @@ ATF_TC_BODY(seqlock, tc)
|
||||||
size_t ncpulen = sizeof(ncpu);
|
size_t ncpulen = sizeof(ncpu);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
alarm(10);
|
||||||
|
|
||||||
if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
|
if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
|
||||||
atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
|
atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
|
||||||
assert(ncpulen == sizeof(ncpu));
|
assert(ncpulen == sizeof(ncpu));
|
||||||
if (ncpu == 1)
|
if (ncpu == 1)
|
||||||
atf_tc_skip("membar tests are only for multicore systems");
|
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++) {
|
for (i = 0; i < 2; i++) {
|
||||||
error = pthread_create(&t[i], NULL, start[i],
|
error = pthread_create(&t[i], NULL, start[i],
|
||||||
(void *)(uintptr_t)i);
|
(void *)(uintptr_t)i);
|
||||||
if (error)
|
if (error)
|
||||||
errc(1, error, "pthread_create");
|
errc(1, error, "pthread_create");
|
||||||
}
|
}
|
||||||
|
sleep(5);
|
||||||
|
times_up = 1;
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
error = pthread_join(t[i], NULL);
|
error = pthread_join(t[i], NULL);
|
||||||
if (error)
|
if (error)
|
||||||
|
|
|
@ -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.
|
* Copyright (c) 2022 The NetBSD Foundation, Inc.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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/atomic.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -39,7 +39,6 @@ __RCSID("$NetBSD: t_spinlock.c,v 1.2 2022/04/09 23:32:53 riastradh Exp $");
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -80,14 +79,6 @@ unlock(void)
|
||||||
lockbit = 0;
|
lockbit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
alarm_handler(int signo)
|
|
||||||
{
|
|
||||||
|
|
||||||
(void)signo;
|
|
||||||
times_up = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
thread(void *cookie)
|
thread(void *cookie)
|
||||||
{
|
{
|
||||||
|
@ -125,21 +116,22 @@ ATF_TC_BODY(spinlock, tc)
|
||||||
size_t ncpulen = sizeof(ncpu);
|
size_t ncpulen = sizeof(ncpu);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
alarm(10);
|
||||||
|
|
||||||
if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
|
if (sysctlbyname("hw.ncpu", &ncpu, &ncpulen, NULL, 0) == -1)
|
||||||
atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
|
atf_tc_fail("hw.ncpu: (%d) %s", errno, strerror(errno));
|
||||||
assert(ncpulen == sizeof(ncpu));
|
assert(ncpulen == sizeof(ncpu));
|
||||||
if (ncpu == 1)
|
if (ncpu == 1)
|
||||||
atf_tc_skip("membar tests are only for multicore systems");
|
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++) {
|
for (i = 0; i < 2; i++) {
|
||||||
error = pthread_create(&t[i], NULL, &thread,
|
error = pthread_create(&t[i], NULL, &thread,
|
||||||
(void *)(uintptr_t)i);
|
(void *)(uintptr_t)i);
|
||||||
if (error)
|
if (error)
|
||||||
errc(1, error, "pthread_create");
|
errc(1, error, "pthread_create");
|
||||||
}
|
}
|
||||||
|
sleep(5);
|
||||||
|
times_up = 1;
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
error = pthread_join(t[i], NULL);
|
error = pthread_join(t[i], NULL);
|
||||||
if (error)
|
if (error)
|
||||||
|
|
Loading…
Reference in New Issue