2 * Copyright 2016, Cyril Bur, IBM Corp.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Sending one self a signal should always get delivered.
16 #include <sys/types.h>
24 #define MAX_ATTEMPT 500000
27 extern long signal_self(pid_t pid
, int sig
);
29 static sig_atomic_t signaled
;
30 static sig_atomic_t fail
;
32 static void signal_handler(int sig
)
40 static int test_signal()
44 pid_t ppid
= getpid();
47 act
.sa_handler
= signal_handler
;
49 sigemptyset(&act
.sa_mask
);
50 if (sigaction(SIGUSR1
, &act
, NULL
) < 0) {
51 perror("sigaction SIGUSR1");
54 if (sigaction(SIGALRM
, &act
, NULL
) < 0) {
55 perror("sigaction SIGALRM");
59 /* Don't do this for MAX_ATTEMPT, its simply too long */
60 for(i
= 0; i
< 1000; i
++) {
67 signal_self(ppid
, SIGUSR1
);
70 alarm(0); /* Disable any pending */
72 while (!signaled
&& !fail
)
73 asm volatile("": : :"memory");
75 fprintf(stderr
, "Didn't get signal from child\n");
76 FAIL_IF(1); /* For the line number */
78 /* Otherwise we'll loop too fast and fork() will eventually fail */
79 waitpid(pid
, NULL
, 0);
83 for (i
= 0; i
< MAX_ATTEMPT
; i
++) {
86 alarm(0); /* Disable any pending */
89 rc
= signal_self(ppid
, SIGUSR1
);
91 fprintf(stderr
, "(%d) Fail reason: %d rc=0x%lx",
93 FAIL_IF(1); /* For the line number */
95 while (!signaled
&& !fail
)
96 asm volatile("": : :"memory");
98 fprintf(stderr
, "(%d) Fail reason: %d rc=0x%lx",
100 FAIL_IF(1); /* For the line number */
109 test_harness_set_timeout(300);
110 return test_harness(test_signal
, "signal");