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 * msgctl01.c 00023 * 00024 * DESCRIPTION 00025 * msgctl01 - create a message queue, then issue the IPC_STAT command 00026 * and RMID commands to test the functionality 00027 * 00028 * ALGORITHM 00029 * create a message queue 00030 * loop if that option was specified 00031 * call msgctl() with the IPC_STAT command 00032 * check the return code 00033 * if failure, issue a FAIL message and break remaining tests 00034 * otherwise, 00035 * if doing functionality testing 00036 * if the max number of bytes on the queue is > 0, 00037 * issue a PASS message 00038 * otherwise 00039 * issue a FAIL message 00040 * else issue a PASS message 00041 * call cleanup 00042 * 00043 * USAGE: <for command-line> 00044 * msgctl01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] 00045 * where, -c n : Run n copies concurrently. 00046 * -f : Turn off functionality Testing. 00047 * -i n : Execute test n times. 00048 * -I x : Execute test for x seconds. 00049 * -P x : Pause for x seconds between iterations. 00050 * -t : Turn on syscall timing. 00051 * 00052 * HISTORY 00053 * 03/2001 - Written by Wayne Boyer 00054 * 00055 * RESTRICTIONS 00056 * none 00057 */ 00058 00059 #include "test.h" 00060 #include "usctest.h" 00061 00062 #include "ipcmsg.h" 00063 00064 char *TCID = "msgctl01"; 00065 int TST_TOTAL = 1; 00066 extern int Tst_count; 00067 00068 int msg_q_1 = -1; /* to hold the message queue id */ 00069 00070 struct msqid_ds qs_buf; 00071 00072 int main(int ac, char **av) 00073 { 00074 int lc; /* loop counter */ 00075 char *msg; /* message returned from parse_opts */ 00076 00077 /* parse standard options */ 00078 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ 00079 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); 00080 } 00081 00082 setup(); /* global setup */ 00083 00084 /* The following loop checks looping state if -i option given */ 00085 00086 for (lc = 0; TEST_LOOPING(lc); lc++) { 00087 /* reset Tst_count in case we are looping */ 00088 Tst_count = 0; 00089 00090 /* 00091 * Get the msqid_ds structure values for the queue 00092 */ 00093 00094 TEST(msgctl(msg_q_1, IPC_STAT, &qs_buf)); 00095 00096 if (TEST_RETURN == -1) { 00097 tst_resm(TFAIL, "%s call failed - errno = %d" 00098 " : %s", TCID, TEST_ERRNO, 00099 strerror(TEST_ERRNO)); 00100 } else { 00101 if (STD_FUNCTIONAL_TEST) { 00102 if (qs_buf.msg_qbytes > 0) { 00103 tst_resm(TPASS, "qs_buf.msg_qbytes is" 00104 " a positive value"); 00105 } else { 00106 tst_resm(TFAIL, "qs_buf.msg_qbytes did" 00107 " not change"); 00108 } 00109 } else { 00110 tst_resm(TPASS, "msgctl() call succeeded"); 00111 } 00112 } 00113 00114 /* 00115 * clean up things in case we are looping 00116 */ 00117 qs_buf.msg_qbytes = 0x0000; 00118 } 00119 00120 cleanup(); 00121 00122 /*NOTREACHED*/ 00123 return(0); 00124 } 00125 00126 /* 00127 * setup() - performs all the ONE TIME setup for this test. 00128 */ 00129 void 00130 setup(void) 00131 { 00132 /* capture signals */ 00133 tst_sig(NOFORK, DEF_HANDLER, cleanup); 00134 00135 /* Pause if that option was specified */ 00136 TEST_PAUSE; 00137 00138 /* 00139 * Create a temporary directory and cd into it. 00140 * This helps to ensure that a unique msgkey is created. 00141 * See ../lib/libipc.c for more information. 00142 */ 00143 tst_tmpdir(); 00144 00145 /* get a message key */ 00146 msgkey = getipckey(); 00147 00148 /* make sure the initial # of bytes is 0 in our buffer */ 00149 qs_buf.msg_qbytes = 0x0000; 00150 00151 /* now we have a key, so let's create a message queue */ 00152 if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { 00153 tst_brkm(TBROK, cleanup, "Can't create message queue"); 00154 } 00155 } 00156 00157 /* 00158 * cleanup() - performs all the ONE TIME cleanup for this test at completion 00159 * or premature exit. 00160 */ 00161 void 00162 cleanup(void) 00163 { 00164 /* if it exists, remove the message queue */ 00165 rm_queue(msg_q_1); 00166 00167 /* Remove the temporary directory */ 00168 tst_rmdir(); 00169 00170 /* 00171 * print timing stats if that option was specified. 00172 * print errno log if that option was specified. 00173 */ 00174 TEST_CLEANUP; 00175 00176 /* exit with return code appropriate for results */ 00177 tst_exit(); 00178 } 00179
1.5.8