Home | History | Annotate | Download | only in shmdt
      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  *	shmdt02.c
     23  *
     24  * DESCRIPTION
     25  *	shmdt02 - check for EINVAL error
     26  *
     27  * ALGORITHM
     28  *	loop if that option was specified
     29  *	  call shmdt() using an invalid shared memory address
     30  *	  check the errno value
     31  *	    issue a PASS message if we get EINVAL
     32  *	  otherwise, the tests fails
     33  *	    issue a FAIL message
     34  *	call cleanup
     35  *
     36  * USAGE:  <for command-line>
     37  *  shmdt02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
     38  *     where,  -c n : Run n copies concurrently.
     39  *             -e   : Turn on errno logging.
     40  *	       -i n : Execute test n times.
     41  *	       -I x : Execute test for x seconds.
     42  *	       -P x : Pause for x seconds between iterations.
     43  *	       -t   : Turn on syscall timing.
     44  *
     45  * HISTORY
     46  *	03/2001 - Written by Wayne Boyer
     47  *
     48  * RESTRICTIONS
     49  *	none
     50  */
     51 
     52 #include "ipcshm.h"
     53 
     54 char *TCID = "shmdt02";
     55 int TST_TOTAL = 1;
     56 
     57 int main(int ac, char **av)
     58 {
     59 	int lc;
     60 	int unshared;		/* a local variable to use to produce *//* the error in the shmdt() call */
     61 
     62 	tst_parse_opts(ac, av, NULL, NULL);
     63 
     64 	setup();		/* global setup */
     65 
     66 	/* The following loop checks looping state if -i option given */
     67 
     68 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     69 		/* reset tst_count in case we are looping */
     70 		tst_count = 0;
     71 
     72 		/*
     73 		 * make the call using the TEST() macro - attempt to
     74 		 * remove an invalid shared memory address
     75 		 */
     76 
     77 		TEST(shmdt(&unshared));
     78 
     79 		if (TEST_RETURN != -1) {
     80 			tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
     81 		}
     82 
     83 		switch (TEST_ERRNO) {
     84 		case EINVAL:
     85 			tst_resm(TPASS, "expected failure - errno = %d : %s",
     86 				 TEST_ERRNO, strerror(TEST_ERRNO));
     87 			break;
     88 		default:
     89 			tst_resm(TFAIL, "call failed with an unexpected error "
     90 				 "- %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
     91 
     92 		}
     93 	}
     94 
     95 	cleanup();
     96 
     97 	tst_exit();
     98 }
     99 
    100 /*
    101  * setup() - performs all the ONE TIME setup for this test.
    102  */
    103 void setup(void)
    104 {
    105 
    106 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    107 
    108 	TEST_PAUSE;
    109 }
    110 
    111 /*
    112  * cleanup() - performs all the ONE TIME cleanup for this test at completion
    113  * 	       or premature exit.
    114  */
    115 void cleanup(void)
    116 {
    117 
    118 }
    119