Home | History | Annotate | Download | only in semop
      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  *	semop03.c
     23  *
     24  * DESCRIPTION
     25  *	semop03 - test for EFBIG error
     26  *
     27  * ALGORITHM
     28  *	create a semaphore set with read and alter permissions
     29  *	loop if that option was specified
     30  *	call semop() using two different invalid cases
     31  *	check the errno value
     32  *	  issue a PASS message if we get EFBIG
     33  *	otherwise, the tests fails
     34  *	  issue a FAIL message
     35  *	call cleanup
     36  *
     37  * USAGE:  <for command-line>
     38  *  semop03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
     39  *     where,  -c n : Run n copies concurrently.
     40  *             -e   : Turn on errno logging.
     41  *	       -i n : Execute test n times.
     42  *	       -I x : Execute test for x seconds.
     43  *	       -P x : Pause for x seconds between iterations.
     44  *	       -t   : Turn on syscall timing.
     45  *
     46  * HISTORY
     47  *	03/2001 - Written by Wayne Boyer
     48  *
     49  * RESTRICTIONS
     50  *	none
     51  */
     52 
     53 #include "ipcsem.h"
     54 
     55 char *TCID = "semop03";
     56 int TST_TOTAL = 2;
     57 
     58 int sem_id_1 = -1;
     59 
     60 struct sembuf s_buf;
     61 
     62 int TC[] = { -1, PSEMS + 1 };	/* negative and too many "primitive" semas */
     63 
     64 int main(int ac, char **av)
     65 {
     66 	int lc;
     67 	int i;
     68 
     69 	tst_parse_opts(ac, av, NULL, NULL);
     70 
     71 	setup();		/* global setup */
     72 
     73 	/* initialize two fields in the sembuf structure here */
     74 	s_buf.sem_op = 1;	/* add this value to struct sem.semval */
     75 	s_buf.sem_flg = SEM_UNDO;	/* undo when process exits */
     76 
     77 	/* The following loop checks looping state if -i option given */
     78 
     79 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     80 		/* reset tst_count in case we are looping */
     81 		tst_count = 0;
     82 
     83 		for (i = 0; i < TST_TOTAL; i++) {
     84 
     85 			/* initialize the last field in the sembuf */
     86 			/* structure to the test dependent value   */
     87 			s_buf.sem_num = TC[i];
     88 
     89 			/*
     90 			 * use the TEST macro to make the call
     91 			 */
     92 
     93 			TEST(semop(sem_id_1, &s_buf, 1));
     94 
     95 			if (TEST_RETURN != -1) {
     96 				tst_resm(TFAIL, "call succeeded unexpectedly");
     97 				continue;
     98 			}
     99 
    100 			switch (TEST_ERRNO) {
    101 			case EFBIG:
    102 				tst_resm(TPASS, "expected failure - errno = "
    103 					 "%d : %s", TEST_ERRNO,
    104 					 strerror(TEST_ERRNO));
    105 				break;
    106 			default:
    107 				tst_resm(TFAIL, "unexpected error - "
    108 					 "%d : %s", TEST_ERRNO,
    109 					 strerror(TEST_ERRNO));
    110 				break;
    111 			}
    112 		}
    113 	}
    114 
    115 	cleanup();
    116 
    117 	tst_exit();
    118 }
    119 
    120 /*
    121  * setup() - performs all the ONE TIME setup for this test.
    122  */
    123 void setup(void)
    124 {
    125 
    126 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    127 
    128 	TEST_PAUSE;
    129 
    130 	/*
    131 	 * Create a temporary directory and cd into it.
    132 	 * This helps to ensure that a unique msgkey is created.
    133 	 * See ../lib/libipc.c for more information.
    134 	 */
    135 	tst_tmpdir();
    136 
    137 	/* get an IPC resource key */
    138 	semkey = getipckey();
    139 
    140 	/* create a semaphore with read and alter permissions */
    141 	if ((sem_id_1 =
    142 	     semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
    143 		tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
    144 	}
    145 }
    146 
    147 /*
    148  * cleanup() - performs all the ONE TIME cleanup for this test at completion
    149  * 	       or premature exit.
    150  */
    151 void cleanup(void)
    152 {
    153 	/* if it exists, remove the semaphore resource */
    154 	rm_sema(sem_id_1);
    155 
    156 	tst_rmdir();
    157 
    158 }
    159