00001 /* 00002 * 00003 * Copyright (c) International Business Machines Corp., 2001 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00013 * the GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 /* 00021 * NAME 00022 * msgsnd03.c 00023 * 00024 * DESCRIPTION 00025 * msgsnd03 - test for EINVAL error 00026 * 00027 * ALGORITHM 00028 * create a message queue with read/write permissions 00029 * create a trivial message buffer 00030 * loop if that option was specified 00031 * call msgsnd() using four different invalid cases 00032 * check the errno value 00033 * issue a PASS message if we get EINVAL 00034 * otherwise, the tests fails 00035 * issue a FAIL message 00036 * call cleanup 00037 * 00038 * USAGE: <for command-line> 00039 * msgsnd03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 00040 * where, -c n : Run n copies concurrently. 00041 * -e : Turn on errno logging. 00042 * -i n : Execute test n times. 00043 * -I x : Execute test for x seconds. 00044 * -P x : Pause for x seconds between iterations. 00045 * -t : Turn on syscall timing. 00046 * 00047 * HISTORY 00048 * 03/2001 - Written by Wayne Boyer 00049 * 00050 * RESTRICTIONS 00051 * none 00052 */ 00053 00054 #include "test.h" 00055 #include "usctest.h" 00056 00057 #include "ipcmsg.h" 00058 00059 void cleanup(void); 00060 void setup(void); 00061 00062 char *TCID = "msgsnd03"; 00063 int TST_TOTAL = 4; 00064 extern int Tst_count; 00065 00066 00067 int exp_enos[] = {EINVAL, 0}; /* 0 terminated list of expected errnos */ 00068 00069 int msg_q_1 = -1; /* The message queue id created in setup */ 00070 MSGBUF msg_buf; /* a buffer for the message to queue */ 00071 int bad_q = -1; /* a value to use as a bad queue ID */ 00072 00073 struct test_case_t { 00074 int *queue_id; 00075 MSGBUF *buffer; 00076 long mtype; 00077 int msg_size; 00078 int error; 00079 } TC[] = { 00080 /* EINVAL - the queue ID is invalid */ 00081 {&bad_q, &msg_buf, 1, 1, EINVAL}, 00082 00083 /* EINVAL - the message type is not positive (0) */ 00084 {&msg_q_1, &msg_buf, 0, 1, EINVAL}, 00085 00086 /* EINVAL - the message type is not positive (>0) */ 00087 {&msg_q_1, &msg_buf, -1, 1, EINVAL}, 00088 00089 /* EINVAL - the message size is less than zero */ 00090 {&msg_q_1, &msg_buf, 1, -1, EINVAL} 00091 }; 00092 00093 int main(int ac, char **av) 00094 { 00095 int lc; /* loop counter */ 00096 char *msg; /* message returned from parse_opts */ 00097 int i; 00098 00099 /* parse standard options */ 00100 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ 00101 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); 00102 } 00103 00104 setup(); /* global setup */ 00105 00106 /* The following loop checks looping state if -i option given */ 00107 00108 for (lc = 0; TEST_LOOPING(lc); lc++) { 00109 /* reset Tst_count in case we are looping */ 00110 Tst_count = 0; 00111 00112 /* 00113 * loop through the test cases 00114 */ 00115 00116 for (i=0; i<TST_TOTAL; i++) { 00117 00118 /* set the message type */ 00119 msg_buf.mtype = TC[i].mtype; 00120 00121 /* make the call with the TEST macro */ 00122 TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer, 00123 TC[i].msg_size, 0)); 00124 00125 if (TEST_RETURN != -1) { 00126 tst_resm(TFAIL, "call succeeded unexpectedly"); 00127 continue; 00128 } 00129 00130 TEST_ERROR_LOG(TEST_ERRNO); 00131 00132 if (TEST_ERRNO == TC[i].error) { 00133 tst_resm(TPASS, "expected failure - " 00134 "errno = %d : %s", TEST_ERRNO, 00135 strerror(TEST_ERRNO)); 00136 } else { 00137 tst_resm(TFAIL, "unexpected error - %d : %s", 00138 TEST_ERRNO, strerror(TEST_ERRNO)); 00139 } 00140 } 00141 } 00142 00143 cleanup(); 00144 00145 /*NOTREACHED*/ 00146 return(0); 00147 } 00148 00149 /* 00150 * setup() - performs all the ONE TIME setup for this test. 00151 */ 00152 void 00153 setup(void) 00154 { 00155 /* capture signals */ 00156 tst_sig(NOFORK, DEF_HANDLER, cleanup); 00157 00158 /* Set up the expected error numbers for -e option */ 00159 TEST_EXP_ENOS(exp_enos); 00160 00161 /* Pause if that option was specified */ 00162 TEST_PAUSE; 00163 00164 /* 00165 * Create a temporary directory and cd into it. 00166 * This helps to ensure that a unique msgkey is created. 00167 * See ../lib/libipc.c for more information. 00168 */ 00169 tst_tmpdir(); 00170 00171 msgkey = getipckey(); 00172 00173 /* create a message queue with read/write permission */ 00174 if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { 00175 tst_brkm(TBROK, cleanup, "Can't create message queue"); 00176 } 00177 00178 /* initialize the message buffer with something trivial */ 00179 msg_buf.mtype = MSGTYPE; 00180 msg_buf.mtext[0] = 'a'; 00181 } 00182 00183 /* 00184 * cleanup() - performs all the ONE TIME cleanup for this test at completion 00185 * or premature exit. 00186 */ 00187 void 00188 cleanup(void) 00189 { 00190 /* if it exists, remove the message queue that was created */ 00191 rm_queue(msg_q_1); 00192 00193 /* Remove the temporary directory */ 00194 tst_rmdir(); 00195 00196 /* 00197 * print timing stats if that option was specified. 00198 * print errno log if that option was specified. 00199 */ 00200 TEST_CLEANUP; 00201 00202 /* exit with return code appropriate for results */ 00203 tst_exit(); 00204 } 00205
1.5.8