blob: a253aa90c6e1ccf62fc3c69f88299fd0eb040139 [file] [log] [blame]
robbiew0dc07652005-06-03 16:29:48 +00001/*
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
Garrett Cooper2c282152010-12-16 00:55:50 -08005 * of this license, see the COPYING file at the top level of this
robbiew0dc07652005-06-03 16:29:48 +00006 * source tree.
7
8 This program tests the assertion that the process's signal mask will be
9 restored to the state that it was in prior to the delivery of the signal
10
11 Steps:
12 1. Empty the signal mask
13 2. Deliver the signal
Garrett Cooper2c282152010-12-16 00:55:50 -080014 3. When we return from the signal handler, verify that the signal mask
robbiew0dc07652005-06-03 16:29:48 +000015 is still empty, otherwise fail.
16
17*/
18
19#define _XOPEN_SOURCE 600
20
21#include <signal.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include "posixtest.h"
25
Garrett Coopera1a92072011-01-16 18:07:18 -080026#define NUMSIGNALS (sizeof(siglist) / sizeof(siglist[0]))
robbiew0dc07652005-06-03 16:29:48 +000027
Wanlong Gao354ebb42012-12-07 10:10:04 +080028int is_empty(sigset_t * set)
29{
robbiew0dc07652005-06-03 16:29:48 +000030
Wanlong Gao354ebb42012-12-07 10:10:04 +080031 int i;
32 int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
33 SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
34 SIGPIPE, SIGQUIT, SIGSEGV,
35 SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
36 SIGUSR1, SIGUSR2,
Garrett Cooper62691462010-07-19 01:29:18 -070037#ifdef SIGPOLL
38 SIGPOLL,
39#endif
Garrett Cooperd3df7e02011-01-16 17:55:25 -080040#ifdef SIGPROF
41 SIGPROF,
42#endif
43 SIGSYS,
Wanlong Gao354ebb42012-12-07 10:10:04 +080044 SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ
45 };
robbiew0dc07652005-06-03 16:29:48 +000046
Wanlong Gao354ebb42012-12-07 10:10:04 +080047 for (i = 0; i < NUMSIGNALS; i++) {
robbiew0dc07652005-06-03 16:29:48 +000048 if (sigismember(set, siglist[i]) != 0)
49 return 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +080050 }
51 return 1;
robbiew0dc07652005-06-03 16:29:48 +000052}
53
54void myhandler(int signo)
55{
robbiew0dc07652005-06-03 16:29:48 +000056}
57
58int main()
59{
60 sigset_t mask;
61 sigemptyset(&mask);
62
Garrett Cooper62691462010-07-19 01:29:18 -070063 if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
64 perror("sigprocmask(SIG_SETMASK, &mask, NULL) failed");
65 return PTS_UNRESOLVED;
66 }
robbiew0dc07652005-06-03 16:29:48 +000067
68 if (sigset(SIGCHLD, myhandler) == SIG_ERR) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080069 perror("Unexpected error while using sigset()");
70 return PTS_UNRESOLVED;
71 }
robbiew0dc07652005-06-03 16:29:48 +000072
73 raise(SIGCHLD);
74 sigprocmask(SIG_SETMASK, NULL, &mask);
75
76 if (is_empty(&mask) != 1) {
77 printf("Test FAILED: signal mask should be empty\n");
78 return PTS_FAIL;
79 }
80 return PTS_PASS;
Garrett Cooperd3df7e02011-01-16 17:55:25 -080081}