1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2016, Cyril Bur, IBM Corp.
5 * Sending one self a signal should always get delivered.
12 #include <sys/types.h>
20 #define MAX_ATTEMPT 500000
23 extern long signal_self(pid_t pid, int sig);
25 static sig_atomic_t signaled;
26 static sig_atomic_t fail;
28 static void signal_handler(int sig)
36 static int test_signal()
40 pid_t ppid = getpid();
43 act.sa_handler = signal_handler;
45 sigemptyset(&act.sa_mask);
46 if (sigaction(SIGUSR1, &act, NULL) < 0) {
47 perror("sigaction SIGUSR1");
50 if (sigaction(SIGALRM, &act, NULL) < 0) {
51 perror("sigaction SIGALRM");
55 /* Don't do this for MAX_ATTEMPT, its simply too long */
56 for(i = 0; i < 1000; i++) {
63 signal_self(ppid, SIGUSR1);
66 alarm(0); /* Disable any pending */
68 while (!signaled && !fail)
69 asm volatile("": : :"memory");
71 fprintf(stderr, "Didn't get signal from child\n");
72 FAIL_IF(1); /* For the line number */
74 /* Otherwise we'll loop too fast and fork() will eventually fail */
75 waitpid(pid, NULL, 0);
79 for (i = 0; i < MAX_ATTEMPT; i++) {
82 alarm(0); /* Disable any pending */
85 rc = signal_self(ppid, SIGUSR1);
87 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx",
89 FAIL_IF(1); /* For the line number */
91 while (!signaled && !fail)
92 asm volatile("": : :"memory");
94 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx",
96 FAIL_IF(1); /* For the line number */
105 test_harness_set_timeout(300);
106 return test_harness(test_signal, "signal");