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 | * msgctl03.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * msgctl03 - create a message queue, then issue the IPC_RMID command |
| 26 | * |
| 27 | * ALGORITHM |
| 28 | * create a message queue |
| 29 | * loop if that option was specified |
| 30 | * call msgctl() with the IPC_RMID command |
| 31 | * check the return code |
| 32 | * if failure, issue a FAIL message and break remaining tests |
| 33 | * otherwise, |
| 34 | * if doing functionality testing |
| 35 | * issue an IPC_STAT on the queue that was just removed |
| 36 | * if the call fails |
| 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 | * msgctl03 [-c n] [-f] [-I x] [-P x] [-t] |
| 45 | * where, -c n : Run n copies concurrently. |
| 46 | * -f : Turn off functionality Testing. |
| 47 | * -I x : Execute test for x seconds. |
| 48 | * -P x : Pause for x seconds between iterations. |
| 49 | * -t : Turn on syscall timing. |
| 50 | * |
| 51 | * HISTORY |
| 52 | * 03/2001 - Written by Wayne Boyer |
| 53 | * |
| 54 | * RESTRICTIONS |
| 55 | * This test does not support looping. |
| 56 | */ |
| 57 | |
| 58 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 60 | #include "ipcmsg.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | |
| 62 | char *TCID = "msgctl03"; |
| 63 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | int msg_q_1 = -1; /* to hold the message queue id */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | |
| 67 | struct msqid_ds qs_buf; |
| 68 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 69 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | { |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 71 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 73 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 74 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Remove the queue that was created in setup() |
| 80 | */ |
| 81 | |
| 82 | TEST(msgctl(msg_q_1, IPC_RMID, NULL)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 83 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | tst_brkm(TFAIL | TTERRNO, cleanup, "msgctl() call failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 87 | /* |
| 88 | * if the queue is gone, then an IPC_STAT msgctl() |
| 89 | * call should generate an EINVAL error. |
| 90 | */ |
| 91 | if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)) { |
| 92 | if (errno == EINVAL) { |
| 93 | tst_resm(TPASS, "The queue is gone"); |
| 94 | } else { |
| 95 | tst_resm(TFAIL, "IPC_RMID succeeded ," |
| 96 | " but functional test did not" |
| 97 | " get expected EINVAL error"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | msg_q_1 = -1; |
| 103 | |
| 104 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 105 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* |
| 109 | * setup() - performs all the ONE TIME setup for this test. |
| 110 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 113 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 115 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | TEST_PAUSE; |
| 117 | |
| 118 | /* |
| 119 | * Create a temporary directory and cd into it. |
| 120 | * This helps to ensure that a unique msgkey is created. |
| 121 | * See ../lib/libipc.c for more information. |
| 122 | */ |
| 123 | tst_tmpdir(); |
| 124 | |
| 125 | /* get a message key */ |
| 126 | msgkey = getipckey(); |
| 127 | |
| 128 | /* now we have a key, so let's create a message queue */ |
| 129 | if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { |
| 130 | tst_brkm(TBROK, cleanup, "Can't create message queue"); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 136 | * or premature exit. |
| 137 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | { |
| 140 | /* if it exists, remove the message queue */ |
| 141 | rm_queue(msg_q_1); |
| 142 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | tst_rmdir(); |
| 144 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 145 | } |