summaryrefslogtreecommitdiffstats
path: root/tests/sighook.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-07-07 12:59:39 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-07-07 13:12:56 -0400
commit3206124fb3af2481fc45e705f7bba3ea56016433 (patch)
tree994f03b0d9d1db2e410a7bef155f0e5b4e03fe28 /tests/sighook.c
parent144353ab004bcd3e85f4cdd0a848add7811df2fe (diff)
downloadbfs-3206124fb3af2481fc45e705f7bba3ea56016433.tar.xz
tests: Simplify unit tests with a global variable
It's a little awkward to thread the test result through manually; much easier to just make bfs_check() update a global variable.
Diffstat (limited to 'tests/sighook.c')
-rw-r--r--tests/sighook.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/tests/sighook.c b/tests/sighook.c
index b938edf..f1c4c27 100644
--- a/tests/sighook.c
+++ b/tests/sighook.c
@@ -52,44 +52,37 @@ static int block_signal(int sig, sigset_t *old) {
return 0;
}
-bool check_sighook(void) {
- bool ret = true;
-
+void check_sighook(void) {
struct sighook *hook = sighook(SIGALRM, alrm_hook, NULL, SH_CONTINUE);
- ret &= bfs_echeck(hook, "sighook(SIGALRM)");
- if (!ret) {
- goto done;
+ if (!bfs_echeck(hook, "sighook(SIGALRM)")) {
+ return;
}
// Create a timer that sends SIGALRM every 100 microseconds
struct itimerval ival = {0};
ival.it_value.tv_usec = 100;
ival.it_interval.tv_usec = 100;
- ret &= bfs_echeck(setitimer(ITIMER_REAL, &ival, NULL) == 0);
- if (!ret) {
+ if (!bfs_echeck(setitimer(ITIMER_REAL, &ival, NULL) == 0)) {
goto unhook;
}
// Create a background thread to receive signals
pthread_t thread;
- ret &= bfs_echeck(thread_create(&thread, NULL, hook_thread, NULL) == 0);
- if (!ret) {
+ if (!bfs_echeck(thread_create(&thread, NULL, hook_thread, NULL) == 0)) {
goto untime;
}
// Block SIGALRM in this thread so the handler runs concurrently with
// sighook()/sigunhook()
sigset_t mask;
- ret &= bfs_echeck(block_signal(SIGALRM, &mask) == 0);
- if (!ret) {
+ if (!bfs_echeck(block_signal(SIGALRM, &mask) == 0)) {
goto untime;
}
// Rapidly register/unregister SIGALRM hooks
while (load(&count, relaxed) < 1000) {
struct sighook *next = sighook(SIGALRM, alrm_hook, NULL, SH_CONTINUE);
- ret &= bfs_echeck(next, "sighook(SIGALRM)");
- if (!ret) {
+ if (!bfs_echeck(next, "sighook(SIGALRM)")) {
break;
}
@@ -106,18 +99,12 @@ bool check_sighook(void) {
// Restore the old signal mask
errno = pthread_sigmask(SIG_SETMASK, &mask, NULL);
- ret &= bfs_echeck(errno == 0, "pthread_sigmask()");
+ bfs_echeck(errno == 0, "pthread_sigmask()");
untime:
// Stop the timer
ival.it_value.tv_usec = 0;
- ret &= bfs_echeck(setitimer(ITIMER_REAL, &ival, NULL) == 0);
- if (!ret) {
- goto unhook;
- }
-
+ bfs_echeck(setitimer(ITIMER_REAL, &ival, NULL) == 0);
unhook:
// Unregister the SIGALRM hook
sigunhook(hook);
-done:
- return ret;
}