plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * msgctl01.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * msgctl01 - create a message queue, then issue the IPC_STAT command |
| 26 | * and RMID commands to test the functionality |
| 27 | * |
| 28 | * ALGORITHM |
| 29 | * create a message queue |
| 30 | * loop if that option was specified |
| 31 | * call msgctl() with the IPC_STAT command |
| 32 | * check the return code |
| 33 | * if failure, issue a FAIL message and break remaining tests |
| 34 | * otherwise, |
| 35 | * if doing functionality testing |
| 36 | * if the max number of bytes on the queue is > 0, |
| 37 | * issue a PASS message |
| 38 | * otherwise |
| 39 | * issue a FAIL message |
| 40 | * else issue a PASS message |
| 41 | * call cleanup |
| 42 | * |
| 43 | * USAGE: <for command-line> |
| 44 | * msgctl01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] |
| 45 | * where, -c n : Run n copies concurrently. |
| 46 | * -f : Turn off functionality Testing. |
| 47 | * -i n : Execute test n times. |
| 48 | * -I x : Execute test for x seconds. |
| 49 | * -P x : Pause for x seconds between iterations. |
| 50 | * -t : Turn on syscall timing. |
| 51 | * |
| 52 | * HISTORY |
| 53 | * 03/2001 - Written by Wayne Boyer |
| 54 | * |
| 55 | * RESTRICTIONS |
| 56 | * none |
| 57 | */ |
| 58 | |
| 59 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 61 | #include "ipcmsg.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | |
| 63 | char *TCID = "msgctl01"; |
| 64 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 66 | int msg_q_1 = -1; /* to hold the message queue id */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
| 68 | struct msqid_ds qs_buf; |
| 69 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 70 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 72 | int lc; |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 73 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 75 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 76 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
| 80 | /* The following loop checks looping state if -i option given */ |
| 81 | |
| 82 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 83 | /* reset tst_count in case we are looping */ |
| 84 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * Get the msqid_ds structure values for the queue |
| 88 | */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 89 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | TEST(msgctl(msg_q_1, IPC_STAT, &qs_buf)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 91 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 93 | tst_resm(TFAIL | TTERRNO, "msgctl() call failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 95 | if (qs_buf.msg_qbytes > 0) { |
| 96 | tst_resm(TPASS, "qs_buf.msg_qbytes is" |
| 97 | " a positive value"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 99 | tst_resm(TFAIL, "qs_buf.msg_qbytes did" |
| 100 | " not change"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * clean up things in case we are looping |
| 106 | */ |
| 107 | qs_buf.msg_qbytes = 0x0000; |
| 108 | } |
| 109 | |
| 110 | cleanup(); |
| 111 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 112 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
| 116 | * setup() - performs all the ONE TIME setup for this test. |
| 117 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 120 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 122 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | TEST_PAUSE; |
| 124 | |
| 125 | /* |
| 126 | * Create a temporary directory and cd into it. |
| 127 | * This helps to ensure that a unique msgkey is created. |
| 128 | * See ../lib/libipc.c for more information. |
| 129 | */ |
| 130 | tst_tmpdir(); |
| 131 | |
| 132 | /* get a message key */ |
| 133 | msgkey = getipckey(); |
| 134 | |
| 135 | /* make sure the initial # of bytes is 0 in our buffer */ |
| 136 | qs_buf.msg_qbytes = 0x0000; |
| 137 | |
| 138 | /* now we have a key, so let's create a message queue */ |
| 139 | if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { |
| 140 | tst_brkm(TBROK, cleanup, "Can't create message queue"); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 146 | * or premature exit. |
| 147 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 149 | { |
| 150 | /* if it exists, remove the message queue */ |
| 151 | rm_queue(msg_q_1); |
| 152 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 153 | tst_rmdir(); |
| 154 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 155 | } |