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 | * 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" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 55 | #include "ipcmsg.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
| 57 | void cleanup(void); |
| 58 | void setup(void); |
| 59 | |
| 60 | char *TCID = "msgrcv03"; |
| 61 | int TST_TOTAL = 2; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | { |
| 74 | &bad_q, MSGSIZE, EINVAL}, |
| 75 | /* EINVAL - the message size is less than 0 */ |
| 76 | { |
| 77 | &msg_q_1, -1, EINVAL} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 80 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 82 | int lc; |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 83 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | int i; |
| 85 | |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 86 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 87 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | |
| 91 | /* The following loop checks looping state if -i option given */ |
| 92 | |
| 93 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 94 | /* reset tst_count in case we are looping */ |
| 95 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | for (i = 0; i < TST_TOTAL; i++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Use the TEST macro to make the call |
| 101 | */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 102 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | TEST(msgrcv(*(TC[i].queue_id), &rcv_buf, TC[i].msize, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | 1, 0)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 105 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | if (TEST_RETURN != -1) { |
| 107 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
| 108 | continue; |
| 109 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 110 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | if (TEST_ERRNO == TC[i].error) { |
| 112 | tst_resm(TPASS, "expected failure - errno = " |
| 113 | "%d : %s", TEST_ERRNO, |
| 114 | strerror(TEST_ERRNO)); |
| 115 | } else { |
| 116 | tst_resm(TFAIL, "call failed with an " |
| 117 | "unexpected error - %d : %s", |
| 118 | TEST_ERRNO, strerror(TEST_ERRNO)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | cleanup(); |
| 124 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 125 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* |
| 129 | * setup() - performs all the ONE TIME setup for this test. |
| 130 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 132 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 133 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 134 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 135 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 136 | TEST_PAUSE; |
| 137 | |
| 138 | /* |
| 139 | * Create a temporary directory and cd into it. |
| 140 | * This helps to ensure that a unique msgkey is created. |
| 141 | * See ../lib/libipc.c for more information. |
| 142 | */ |
| 143 | tst_tmpdir(); |
| 144 | |
| 145 | msgkey = getipckey(); |
| 146 | |
| 147 | /* create a message queue with read/write permission */ |
| 148 | if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { |
| 149 | tst_brkm(TBROK, cleanup, "Can't create message queue"); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 155 | * or premature exit. |
| 156 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 157 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 158 | { |
| 159 | /* if it exists, remove the message queue that was created */ |
| 160 | rm_queue(msg_q_1); |
| 161 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | tst_rmdir(); |
| 163 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 164 | } |