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