1 /*
2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
3  * Copyright (c) 2013, Cyril Hrubis <chrubis@suse.cz>
4  *
5  * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
6  * This file is licensed under the GPL license.  For the full content
7  * of this license, see the COPYING file at the top level of this
8  * source tree.
9  *
10  * Testing invalid signals with sigismember().
11  * After invalid signal set sigismember() should return -1 and set
12  * errno to indicate the error.
13  * Test steps:
14  * 1)  Initialize a full signal set.
15  * 2)  Check for invalid signal from the full signal set.
16  * 3)  Verify that -1 is returned and errno is set to indicate the error.
17  */
18 #include <stdio.h>
19 #include <signal.h>
20 #include <errno.h>
21 #include <stdint.h>
22 #include "posixtest.h"
23 
24 static const int sigs[] = {-1, -10000, INT32_MIN, INT32_MIN + 1};
25 
26 #define	NUMSIGNALS	(sizeof(sigs) / sizeof(sigs[0]))
27 
main(void)28 int main(void)
29 {
30 	sigset_t signalset;
31 	int i, ret, err = 0;
32 
33 	if (sigfillset(&signalset) == -1) {
34 		perror("sigemptyset failed -- test aborted");
35 		return PTS_UNRESOLVED;
36 	}
37 
38 	for (i = 0; i < (int)NUMSIGNALS; i++) {
39 		ret = sigismember(&signalset, sigs[i]);
40 
41 		if (ret != -1 || errno != EINVAL) {
42 			err++;
43 			printf("Failed sigaddset(..., %i) ret=%i errno=%i\n",
44 			       sigs[i], ret, errno);
45 		}
46 	}
47 
48 	if (err) {
49 		printf("Test FAILED\n");
50 		return PTS_FAIL;
51 	} else {
52 		printf("Test PASSED\n");
53 		return PTS_PASS;
54 	}
55 }
56