Home | History | Annotate | Download | only in sigaddset
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Copyright (c) 2013 Cyril Hrubis <chrubis (at) suse.cz>
      4  *
      5  * Created by:  julie.fleischer 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  * Test that sigaddset() will add all defined signal numbers to a signal
     11  * set.
     12  *
     13  *  Test steps:
     14  * 1)  Initialize an empty signal set.
     15  * For each signal number:
     16  *   2)  Add the signal to the empty signal set.
     17  *   3)  Verify that the signal is a member of the signal set.
     18  */
     19 #include <stdio.h>
     20 #include <signal.h>
     21 #include "posixtest.h"
     22 
     23 static const int sigs[] = {
     24 	SIGABRT, SIGALRM, SIGBUS,  SIGCHLD, SIGCONT,
     25 	SIGFPE,  SIGHUP,  SIGILL,  SIGINT,  SIGKILL,
     26 	SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM,
     27 	SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2,
     28 	SIGURG,
     29 };
     30 
     31 int main(void)
     32 {
     33 	sigset_t signalset;
     34 	unsigned int i;
     35 	int err = 0;
     36 
     37 	if (sigemptyset(&signalset) == -1) {
     38 		perror("sigemptyset failed -- test aborting\n");
     39 		return PTS_UNRESOLVED;
     40 	}
     41 
     42 	for (i = 0; i < sizeof(sigs)/sizeof(int); i++) {
     43 		if (sigaddset(&signalset, sigs[i]) == 0) {
     44 			if (sigismember(&signalset, sigs[i]) != 1) {
     45 				err++;
     46 				printf("Signal %d wasn't added \n", sigs[i]);
     47 			}
     48 		} else {
     49 			err++;
     50 			printf("Failed to add sinal %d\n", sigs[i]);
     51 		}
     52 	}
     53 
     54 	if (err) {
     55 		printf("FAILED: Some signals not added\n");
     56 		return PTS_FAIL;
     57 	} else {
     58 		printf("Test PASSED: All signals added\n");
     59 		return PTS_PASS;
     60 	}
     61 }
     62