diff --git a/tests/Makefile b/tests/Makefile index d711f049d5f641436ac5298ecf98427cf9085138..6263367b1ade63fc05f272cf05cdf73dfcee4cb9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -179,7 +179,6 @@ NAMES=\ sa_restart \ sigchld \ stdio/ctermid \ - sigqueue \ stdio/tempnam \ stdio/tmpnam \ stdlib/bsearch \ @@ -216,6 +215,7 @@ NAMES=\ grp/gr_iter \ # resource/getrusage # time/times +# sigqueue # Tests run with `expect` (require a .c file and an .exp file # that takes the produced binary as the first argument) diff --git a/tests/sigqueue.c b/tests/sigqueue.c index d4afe0a8628de35a077ecaf6d7b686e655d51661..57a84850bbae0cb8f2a90daea6f187421d73eabc 100644 --- a/tests/sigqueue.c +++ b/tests/sigqueue.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <sys/wait.h> #include <signal.h> #include <stdio.h> #include <pthread.h> @@ -14,7 +15,8 @@ volatile sig_atomic_t num = 0; int parent; -void validate(int sig, const siginfo_t *info) { +void validate(int sig, const siginfo_t *info) +{ assert(sig == THE_SIG); assert(info != NULL); assert(info->si_signo == THE_SIG); @@ -23,15 +25,16 @@ void validate(int sig, const siginfo_t *info) { assert(info->si_pid == parent); } -void action(int sig, siginfo_t *info, void *context) { +void action(int sig, siginfo_t *info, void *context) +{ (void)context; assert(context != NULL); validate(sig, info); - write(1, "action\n", 7); num++; } -int main(void) { +int main(void) +{ int status, fds[2]; status = pipe(fds); @@ -72,17 +75,18 @@ int main(void) { ERROR_IF(close, status, == -1); struct sigaction sa; - memcpy(&sa.sa_mask, &set, sizeof (sigset_t)); + memcpy(&sa.sa_mask, &set, sizeof(sigset_t)); sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = action; status = sigaction(THE_SIG, &sa, NULL); ERROR_IF(sigaction, status, == -1); - if (child == 0) { + if (child == 0) + { assert(num == 0); siginfo_t info; - struct timespec t = (struct timespec){ .tv_sec = 1, .tv_nsec = 0 }; + struct timespec t = (struct timespec){.tv_sec = 1, .tv_nsec = 200000000}; status = sigtimedwait(&set, &info, &t); ERROR_IF(sigtimedwait, status, == -1); validate(THE_SIG, &info); @@ -92,9 +96,9 @@ int main(void) { // TODO: check status status = sigsuspend(&empty_set); - if (status == -1) { - perror("error in sigsuspend"); - puts("[EINTR] is usually expected"); + if (status == -1) + { + UNEXP_IF(sigsuspend, errno, != EINTR); } assert(num == 2); // ensure signal handler ran @@ -102,19 +106,40 @@ int main(void) { status = sigprocmask(SIG_SETMASK, &empty_set, NULL); ERROR_IF(sigprocmask, status, == -1); - while (num < 31) {} + while (num < 31) + { + } status = write(fds[1], "A", 1); ERROR_IF(write, status, == -1); - } else { - for (int n = 0; n <= 31; n++) { - status = sigqueue(child, THE_SIG, (union sigval){ .sival_int = n }); + } + else + { + struct timespec t = (struct timespec){.tv_sec = 0, .tv_nsec = 100000000}; + status = nanosleep(&t, NULL); + ERROR_IF(nanosleep, status, < 0); + + for (int n = 0; n <= 31; n++) + { + status = sigqueue(child, THE_SIG, (union sigval){.sival_int = n}); ERROR_IF(sigqueue, status, == -1); } char buf[1]; status = read(fds[0], buf, 1); ERROR_IF(read, status, == -1); + + pid_t wait_pid = 0; + int wait_status = 0; + wait_pid = wait(&wait_status); + ERROR_IF(wait, wait_pid, < 0); + UNEXP_IF(wait, wait_pid, != child); + if (!WIFEXITED(wait_status) || WEXITSTATUS(wait_status) != EXIT_SUCCESS) + { + fprintf(stderr, "Unexpected result, WIFEXITED %s, WEXITSTATUS %d\n", + WIFEXITED(wait_status) ? "true" : "false", WEXITSTATUS(wait_status)); + return EXIT_FAILURE; + } } - return 0; + return EXIT_SUCCESS; }