Home | History | Annotate | Download | only in msgrcv
      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  *	msgrcv03.c
     23  *
     24  * DESCRIPTION
     25  *	msgrcv03 - test for EINVAL error
     26  *
     27  * ALGORITHM
     28  *	create a message queue with read/write permissions
     29  *	loop if that option was specified
     30  *	call msgrcv() using two different invalid cases
     31  *	check the errno value
     32  *	  issue a PASS message if we get EINVAL
     33  *	otherwise, the tests fails
     34  *	  issue a FAIL message
     35  *	call cleanup
     36  *
     37  * USAGE:  <for command-line>
     38  *  msgrcv03 [-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 "test.h"
     54 
     55 #include "ipcmsg.h"
     56 
     57 void cleanup(void);
     58 void setup(void);
     59 
     60 char *TCID = "msgrcv03";
     61 int TST_TOTAL = 2;
     62 
     63 int msg_q_1 = -1;		/* The message queue id created in setup */
     64 int bad_q = -1;			/* a value to use as a bad queue ID */
     65 MSGBUF rcv_buf;
     66 
     67 struct test_case_t {
     68 	int *queue_id;
     69 	int msize;
     70 	int error;
     71 } TC[] = {
     72 	/* EINVAL - the queue ID is invalid */
     73 	{
     74 	&bad_q, MSGSIZE, EINVAL},
     75 	    /* EINVAL - the message size is less than 0 */
     76 	{
     77 	&msg_q_1, -1, EINVAL}
     78 };
     79 
     80 int main(int ac, char **av)
     81 {
     82 	int lc;
     83 	int i;
     84 
     85 	tst_parse_opts(ac, av, NULL, NULL);
     86 
     87 	setup();		/* global setup */
     88 
     89 	/* The following loop checks looping state if -i option given */
     90 
     91 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     92 		/* reset tst_count in case we are looping */
     93 		tst_count = 0;
     94 
     95 		for (i = 0; i < TST_TOTAL; i++) {
     96 
     97 			/*
     98 			 * Use the TEST macro to make the call
     99 			 */
    100 
    101 			TEST(msgrcv(*(TC[i].queue_id), &rcv_buf, TC[i].msize,
    102 				    1, 0));
    103 
    104 			if (TEST_RETURN != -1) {
    105 				tst_resm(TFAIL, "call succeeded unexpectedly");
    106 				continue;
    107 			}
    108 
    109 			if (TEST_ERRNO == TC[i].error) {
    110 				tst_resm(TPASS, "expected failure - errno = "
    111 					 "%d : %s", TEST_ERRNO,
    112 					 strerror(TEST_ERRNO));
    113 			} else {
    114 				tst_resm(TFAIL, "call failed with an "
    115 					 "unexpected error - %d : %s",
    116 					 TEST_ERRNO, strerror(TEST_ERRNO));
    117 			}
    118 		}
    119 	}
    120 
    121 	cleanup();
    122 
    123 	tst_exit();
    124 }
    125 
    126 /*
    127  * setup() - performs all the ONE TIME setup for this test.
    128  */
    129 void setup(void)
    130 {
    131 
    132 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    133 
    134 	TEST_PAUSE;
    135 
    136 	/*
    137 	 * Create a temporary directory and cd into it.
    138 	 * This helps to ensure that a unique msgkey is created.
    139 	 * See ../lib/libipc.c for more information.
    140 	 */
    141 	tst_tmpdir();
    142 
    143 	msgkey = getipckey();
    144 
    145 	/* create a message queue with read/write permission */
    146 	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
    147 		tst_brkm(TBROK, cleanup, "Can't create message queue");
    148 	}
    149 }
    150 
    151 /*
    152  * cleanup() - performs all the ONE TIME cleanup for this test at completion
    153  * 	       or premature exit.
    154  */
    155 void cleanup(void)
    156 {
    157 	/* if it exists, remove the message queue that was created */
    158 	rm_queue(msg_q_1);
    159 
    160 	tst_rmdir();
    161 
    162 }
    163