1 /*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by: salwan.searty REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license. For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8 This program verifies that sigpause() suspends the calling process
9 until it receives a signal.
10
11 Steps:
12 1. From the main() function, create a new thread. Give the new thread a
13 a second to set up for receiving a signal, and to suspend itself using
14 sigpause().
15 2. For about ten seconds, keep checking from main() that the "returned"
16 variable hasn't been set yet. If it has, that means that sigpause
17 returned even before a signal was sent to it, thus FAIL the test.
18 3. After the ten seconds, send the new thread a signal using pthread_kill,
19 and verify that "returned" has now been set to 1, meaning that the
20 sigpause returned from suspension.
21 */
22
23
24 #include <pthread.h>
25 #include <stdio.h>
26 #include <signal.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include "posixtest.h"
30
31 #define SIGTOTEST SIGABRT
32
33 static int returned;
34
handler()35 static void handler()
36 {
37 printf("signal was called\n");
38 return;
39 }
40
a_thread_func()41 static void *a_thread_func()
42 {
43 struct sigaction act;
44 act.sa_flags = 0;
45 act.sa_handler = handler;
46 sigemptyset(&act.sa_mask);
47 sigaction(SIGTOTEST, &act, 0);
48 sigpause(SIGTOTEST);
49 returned = 1;
50 return NULL;
51 }
52
main(void)53 int main(void)
54 {
55 pthread_t new_th;
56 int i;
57
58 if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
59 perror("Error creating thread\n");
60 return PTS_UNRESOLVED;
61 }
62
63 for (i = 0; i < 10; i++) {
64 sleep(1);
65 if (returned == 1) {
66 printf("Test FAILED: sigpause returned before "
67 "it received a signal\n");
68 return PTS_FAIL;
69 }
70 }
71
72 if (pthread_kill(new_th, SIGTOTEST) != 0) {
73 printf("Test UNRESOLVED: Couldn't send signal to thread\n");
74 return PTS_UNRESOLVED;
75 }
76
77 sleep(1);
78
79 if (returned != 1) {
80 printf("Test FAILED: signal was sent, but sigpause "
81 "never returned.\n");
82 return PTS_FAIL;
83 }
84
85 printf("Test PASSED\n");
86 return PTS_PASS;
87 }
88