Home | History | Annotate | Download | only in raise
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  julie.n.fleischer 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  *  Assertion 4 - that raise() is equivalent to kill(getpid(), sig); is
      9  *  essentially tested implicitly via assertion 1.
     10  *  This test is the reverse test case:  Test assertion 1, but replace
     11  *  raise() with kill(getpid(), sig).  It should pass if assertion 1
     12  *  passes.
     13  *  1) Set up a signal handler for the signal that says we have caught the
     14  *     signal.
     15  *  2) Call kill(getpid(), <signal under test>)
     16  *  3) If signal handler was called, test passed.
     17  *  This test is only performed on one signal.  All other signals are
     18  *  considered to be in the same equivalence class.
     19  */
     20 
     21 #include <signal.h>
     22 #include <stdio.h>
     23 #include <stdlib.h>
     24 #include <sys/types.h>
     25 #include <unistd.h>
     26 #include "posixtest.h"
     27 
     28 #define SIGTOTEST SIGABRT
     29 
     30 void handler(int signo)
     31 {
     32 	printf("Caught signal being tested!\n");
     33 	printf("Test PASSED\n");
     34 	exit(0);
     35 }
     36 
     37 int main(void)
     38 {
     39 	struct sigaction act;
     40 
     41 	act.sa_handler = handler;
     42 	act.sa_flags = 0;
     43 	if (sigemptyset(&act.sa_mask) == -1) {
     44 		perror("Error calling sigemptyset\n");
     45 		return PTS_UNRESOLVED;
     46 	}
     47 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
     48 		perror("Error calling sigaction\n");
     49 		return PTS_UNRESOLVED;
     50 	}
     51 	if (kill(getpid(), SIGTOTEST) != 0) {
     52 		printf("Could not call kill\n");
     53 		return PTS_UNRESOLVED;
     54 	}
     55 
     56 	printf("Should have exited from signal handler\n");
     57 	printf("Test FAILED\n");
     58 	return PTS_FAIL;
     59 }
     60