• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 tests the assertion that if sigwaitinfo() was called and that
9    no signal in set was pending at the time of the call, then sigwaitinfo()
10    shall be suspended until a signal in set becomes pending.
11 
12   Steps:
13   1. In the child process, register SIGTOTEST with handler.
14   2. call sigwaitinfo() with SIGTOTEST in set.
15   3. From the parent process, send a SIGTOTEST using kill.
16   4. Verify that the return value of the child is PTS_PASS, which indicates
17      that sigwaitinfo() has returned from it's suspended state.
18 
19 */
20 
21 #include <signal.h>
22 #include <sys/types.h>
23 #include <sys/wait.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include "posixtest.h"
28 
handler(int signo)29 void handler(int signo)
30 {
31 	printf("Inside dummy handler\n");
32 }
33 
main(void)34 int main(void)
35 {
36 	pid_t pid;
37 	pid = fork();
38 
39 	if (pid == 0) {
40 		/* child */
41 		sigset_t selectset;
42 
43 		struct sigaction act;
44 
45 		act.sa_handler = handler;
46 		act.sa_flags = 0;
47 		sigemptyset(&act.sa_mask);
48 
49 		if (sigaction(SIGUSR1, &act, 0) == -1) {
50 			perror
51 			    ("Unexpected error while attempting to pre-conditions");
52 			return PTS_UNRESOLVED;
53 		}
54 
55 		sigemptyset(&selectset);
56 		sigaddset(&selectset, SIGUSR1);
57 
58 		printf("Child calling sigwaitinfo()\n");
59 
60 		if (sigwaitinfo(&selectset, NULL) == -1) {
61 			perror("Call to sigwaitinfo() failed\n");
62 			return PTS_UNRESOLVED;
63 		}
64 
65 		printf("returned from sigwaitinfo\n");
66 		sleep(1);
67 		return PTS_PASS;
68 
69 	} else {
70 		int s;
71 		int exit_status;
72 
73 		/* parent */
74 		sleep(1);
75 
76 		printf("parent sending child a SIGUSR1 signal\n");
77 		kill(pid, SIGUSR1);
78 
79 		if (wait(&s) == -1) {
80 			perror("Unexpected error while setting up test "
81 			       "pre-conditions");
82 			return PTS_UNRESOLVED;
83 		}
84 
85 		if (!WIFEXITED(s)) {
86 			printf("Test FAILED: Did not exit normally\n");
87 			return PTS_FAIL;
88 		}
89 
90 		exit_status = WEXITSTATUS(s);
91 
92 		printf("Exit status from child is %d\n", exit_status);
93 
94 		if (exit_status != PTS_PASS) {
95 			printf("Test FAILED\n");
96 			return PTS_FAIL;
97 		}
98 
99 		printf("Test PASSED\n");
100 		return PTS_PASS;
101 	}
102 }
103