Home | History | Annotate | Download | only in signal
      1 /*
      2  *
      3  *   Copyright (c) International Business Machines  Corp., 2001
      4  *
      5  *   This program is free software;  you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 2 of the License, or
      8  *   (at your option) any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  *   the GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program;  if not, write to the Free Software
     17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * NAME
     22  *	signal02.c
     23  *
     24  * DESCRIPTION
     25  *	signal02 - Test that we get an error using illegal signals
     26  *
     27  * ALGORITHM
     28  *	loop if that option was specified
     29  *	issue the system call
     30  *	check the return value
     31  *	  if return value != -1
     32  *	    issue a FAIL message, break remaining tests and cleanup
     33  *	  if we get an EINVAL
     34  *	    issue a PASS message
     35  *	  else
     36  *	    issue a FAIL message, break remaining tests and cleanup
     37  *	call cleanup
     38  *
     39  * USAGE:  <for command-line>
     40  *  signal02 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
     41  *	where,  -c n : Run n copies concurrently.
     42  *		-e   : Turn on error logging.
     43  *		-i n : Execute test n times.
     44  *		-I x : Execute test for x seconds.
     45  *		-P x : Pause for x seconds between iterations.
     46  *		-t   : Turn on syscall timing.
     47  *
     48  * History
     49  *	07/2001 John George
     50  *		-Ported
     51  *
     52  * Restrictions
     53  *	none
     54  */
     55 
     56 #include "test.h"
     57 
     58 #include <errno.h>
     59 #include <signal.h>
     60 
     61 void cleanup(void);
     62 void setup(void);
     63 
     64 char *TCID = "signal02";
     65 int TST_TOTAL = 3;
     66 
     67 typedef void (*sighandler_t) (int);
     68 
     69 sighandler_t Tret;
     70 int sigs[] = { _NSIG + 1, SIGKILL, SIGSTOP };
     71 
     72 int main(int ac, char **av)
     73 {
     74 	int lc;
     75 	int i;
     76 
     77 	tst_parse_opts(ac, av, NULL, NULL);
     78 
     79 	setup();		/* global setup */
     80 
     81 	/* The following loop checks looping state if -i option given */
     82 
     83 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     84 		/* reset tst_count in case we are looping */
     85 		tst_count = 0;
     86 
     87 		/*
     88 		 * There are three cases where we should get an EINVAL
     89 		 */
     90 		for (i = 0; i < TST_TOTAL; i++) {
     91 
     92 			errno = 0;
     93 			Tret = signal(sigs[i], SIG_IGN);
     94 			TEST_ERRNO = errno;
     95 
     96 			if (Tret != SIG_ERR) {
     97 				tst_brkm(TFAIL, cleanup, "%s call failed - "
     98 					 "errno = %d : %s", TCID, TEST_ERRNO,
     99 					 strerror(TEST_ERRNO));
    100 			}
    101 
    102 			switch (TEST_ERRNO) {
    103 			case EINVAL:
    104 				tst_resm(TPASS, "expected failure - errno = "
    105 					 "%d - %s", TEST_ERRNO,
    106 					 strerror(TEST_ERRNO));
    107 				break;
    108 			default:
    109 				tst_resm(TFAIL, "call failed to produce "
    110 					 "expected error - errno = %d "
    111 					 "- %s", TEST_ERRNO,
    112 					 strerror(TEST_ERRNO));
    113 			}
    114 		}
    115 		tst_count++;	/* incr. TEST_LOOP counter */
    116 	}
    117 
    118 	cleanup();
    119 
    120 	tst_exit();
    121 
    122 }
    123 
    124 /*
    125  * setup() - performs all the ONE TIME setup for this test.
    126  */
    127 void setup(void)
    128 {
    129 
    130 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    131 
    132 	TEST_PAUSE;
    133 }
    134 
    135 /*
    136  * cleanup() - performs all the ONE TIME cleanup for this test at completion
    137  * 	       or premature exit.
    138  */
    139 void cleanup(void)
    140 {
    141 
    142 }
    143