Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 1 | /********************************************************************************/ |
| 2 | /* Copyright (c) Crackerjack Project., 2007-2008 ,Hitachi, Ltd */ |
| 3 | /* Author(s): Takahiro Yasui <takahiro.yasui.mp@hitachi.com>, */ |
| 4 | /* Yumiko Sugita <yumiko.sugita.yf@hitachi.com>, */ |
| 5 | /* Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp> */ |
| 6 | /* */ |
| 7 | /* This program is free software; you can redistribute it and/or modify */ |
| 8 | /* it under the terms of the GNU General Public License as published by */ |
| 9 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 10 | /* (at your option) any later version. */ |
| 11 | /* */ |
| 12 | /* This program is distributed in the hope that it will be useful, */ |
| 13 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 14 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 15 | /* the GNU General Public License for more details. */ |
| 16 | /* */ |
| 17 | /* You should have received a copy of the GNU General Public License */ |
| 18 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 19 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 20 | /* USA */ |
| 21 | /********************************************************************************/ |
| 22 | /************************************************************************/ |
| 23 | /* */ |
| 24 | /* File: mq_timedsend01.c */ |
| 25 | /* */ |
| 26 | /* Description: This tests the mq_timedsend() syscall */ |
| 27 | /* */ |
| 28 | /* */ |
| 29 | /* */ |
| 30 | /* */ |
| 31 | /* */ |
| 32 | /* */ |
| 33 | /* Usage: <for command-line> */ |
| 34 | /* mq_timedsend01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 35 | /* where, -c n : Run n copies concurrently. */ |
| 36 | /* -e : Turn on errno logging. */ |
| 37 | /* -i n : Execute test n times. */ |
| 38 | /* -I x : Execute test for x seconds. */ |
| 39 | /* -P x : Pause for x seconds between iterations. */ |
| 40 | /* -t : Turn on syscall timing. */ |
| 41 | /* */ |
| 42 | /* Total Tests: 1 */ |
| 43 | /* */ |
| 44 | /* Test Name: mq_timedsend01 */ |
| 45 | /* History: Porting from Crackerjack to LTP is done by */ |
| 46 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 47 | /************************************************************************/ |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 48 | #include <sys/syscall.h> |
| 49 | #include <sys/types.h> |
| 50 | #include <sys/stat.h> |
| 51 | #include <sys/wait.h> |
| 52 | #include <getopt.h> |
| 53 | #include <stdlib.h> |
| 54 | #include <errno.h> |
| 55 | #include <stdio.h> |
| 56 | #include <unistd.h> |
| 57 | #include <string.h> |
| 58 | #include <mqueue.h> |
| 59 | #include <time.h> |
| 60 | #include <signal.h> |
| 61 | #include <limits.h> |
| 62 | |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 63 | #include "../utils/include_j_h.h" |
| 64 | #include "../utils/common_j_h.c" |
| 65 | |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 66 | #include "test.h" |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 67 | #include "linux_syscall_numbers.h" |
| 68 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 69 | char *TCID = "mq_timedsend01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 70 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 71 | int TST_TOTAL = 1; |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 72 | struct sigaction act; |
| 73 | |
| 74 | /* |
| 75 | * sighandler() |
| 76 | */ |
| 77 | void sighandler(int sig) |
| 78 | { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 79 | if (sig == SIGINT) |
| 80 | return; |
| 81 | return; |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 82 | } |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 83 | |
| 84 | /* Extern Global Functions */ |
| 85 | /******************************************************************************/ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 86 | /* */ |
| 87 | /* Function: cleanup */ |
| 88 | /* */ |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 89 | /* Description: Performs all one time clean up for this test on successful */ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 90 | /* completion, premature exit or failure. Closes all temporary */ |
| 91 | /* files, removes all temporary directories exits the test with */ |
| 92 | /* appropriate return code by calling tst_exit() function. */ |
| 93 | /* */ |
| 94 | /* Input: None. */ |
| 95 | /* */ |
| 96 | /* Output: None. */ |
| 97 | /* */ |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 98 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 99 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 100 | /* */ |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 101 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 102 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 104 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 105 | tst_rmdir(); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* Local Functions */ |
| 109 | /******************************************************************************/ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 110 | /* */ |
| 111 | /* Function: setup */ |
| 112 | /* */ |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 113 | /* Description: Performs all one time setup for this test. This function is */ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 114 | /* typically used to capture signals, create temporary dirs */ |
| 115 | /* and temporary files that may be used in the course of this */ |
| 116 | /* test. */ |
| 117 | /* */ |
| 118 | /* Input: None. */ |
| 119 | /* */ |
| 120 | /* Output: None. */ |
| 121 | /* */ |
| 122 | /* Return: On failure - Exits by calling cleanup(). */ |
| 123 | /* On success - returns 0. */ |
| 124 | /* */ |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 125 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 126 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 128 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 129 | /* Capture signals if any */ |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 130 | act.sa_handler = sighandler; |
| 131 | sigfillset(&act.sa_mask); |
| 132 | |
| 133 | sigaction(SIGINT, &act, NULL); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 134 | /* Create temporary directories */ |
| 135 | TEST_PAUSE; |
| 136 | tst_tmpdir(); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 137 | } |
| 138 | |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 139 | /* |
| 140 | * Macros |
| 141 | */ |
| 142 | #define SYSCALL_NAME "mq_timedsend" |
| 143 | |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 144 | enum test_type { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | NORMAL, |
| 146 | FD_NONE, |
| 147 | FD_NOT_EXIST, |
| 148 | FD_FILE, |
| 149 | FULL_QUEUE, |
| 150 | SEND_SIGINT, |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | /* |
| 154 | * Data Structure |
| 155 | */ |
| 156 | struct test_case { |
| 157 | int ttype; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 158 | int non_block; |
| 159 | int len; |
| 160 | unsigned prio; |
| 161 | time_t sec; |
| 162 | long nsec; |
| 163 | int ret; |
| 164 | int err; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 167 | #define MAX_MSG 10 |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 168 | #define MAX_MSGSIZE 8192 |
| 169 | |
| 170 | /* Test cases |
| 171 | * |
| 172 | * test status of errors on man page |
| 173 | * |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 174 | * EAGAIN v (would block) |
| 175 | * EBADF v (not a valid descriptor) |
| 176 | * EINTR v (interrupted by a signal) |
| 177 | * EINVAL v (1. invalid 'msg_prio' or |
| 178 | * 2. would block but timeout exists) |
| 179 | * EMSGSIZE v ('msg_len' exceeds the message size of the queue) |
| 180 | * ETIMEDOUT v (not block and timeout occured) |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 181 | */ |
| 182 | |
| 183 | static struct test_case tcase[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 184 | { // case00 |
| 185 | .ttype = NORMAL, |
| 186 | .len = 0, // also success when size equals zero |
| 187 | .ret = 0, |
| 188 | .err = 0, |
| 189 | }, |
| 190 | { // case01 |
| 191 | .ttype = NORMAL, |
| 192 | .len = 1, |
| 193 | .ret = 0, |
| 194 | .err = 0, |
| 195 | }, |
| 196 | { // case02 |
| 197 | .ttype = NORMAL, |
| 198 | .len = MAX_MSGSIZE, |
| 199 | .ret = 0, |
| 200 | .err = 0, |
| 201 | }, |
| 202 | { // case03 |
| 203 | .ttype = NORMAL, |
| 204 | .len = 1, |
| 205 | .prio = 32767, // max priority |
| 206 | .ret = 0, |
| 207 | .err = 0, |
| 208 | }, |
| 209 | { // case04 |
| 210 | .ttype = NORMAL, |
| 211 | .len = MAX_MSGSIZE + 1, |
| 212 | .ret = -1, |
| 213 | .err = EMSGSIZE, |
| 214 | }, |
| 215 | { // case05 |
| 216 | .ttype = FD_NONE, |
| 217 | .len = 0, |
| 218 | .ret = -1, |
| 219 | .err = EBADF, |
| 220 | }, |
| 221 | { // case06 |
| 222 | .ttype = FD_NOT_EXIST, |
| 223 | .len = 0, |
| 224 | .ret = -1, |
| 225 | .err = EBADF, |
| 226 | }, |
| 227 | { // case07 |
| 228 | .ttype = FD_FILE, |
| 229 | .len = 0, |
| 230 | .ret = -1, |
| 231 | .err = EBADF, |
| 232 | }, |
| 233 | { // case08 |
| 234 | .ttype = FULL_QUEUE, |
| 235 | .non_block = 1, |
| 236 | .len = 16, |
| 237 | .ret = -1, |
| 238 | .err = EAGAIN, |
| 239 | }, |
| 240 | { // case09 |
| 241 | .ttype = NORMAL, |
| 242 | .len = 1, |
| 243 | .prio = 32768, // max priority + 1 |
| 244 | .ret = -1, |
| 245 | .err = EINVAL, |
| 246 | }, |
| 247 | { // case10 |
| 248 | .ttype = FULL_QUEUE, |
| 249 | .len = 16, |
| 250 | .sec = -1, |
| 251 | .nsec = 0, |
| 252 | .ret = -1, |
| 253 | .err = EINVAL, |
| 254 | }, |
| 255 | { // case11 |
| 256 | .ttype = FULL_QUEUE, |
| 257 | .len = 16, |
| 258 | .sec = 0, |
| 259 | .nsec = -1, |
| 260 | .ret = -1, |
| 261 | .err = EINVAL, |
| 262 | }, |
| 263 | { // case12 |
| 264 | .ttype = FULL_QUEUE, |
| 265 | .len = 16, |
| 266 | .sec = 0, |
| 267 | .nsec = 1000000000, |
| 268 | .ret = -1, |
| 269 | .err = EINVAL, |
| 270 | }, |
| 271 | { // case13 |
| 272 | .ttype = FULL_QUEUE, |
| 273 | .len = 16, |
| 274 | .sec = 0, |
| 275 | .nsec = 999999999, |
| 276 | .ret = -1, |
| 277 | .err = ETIMEDOUT, |
| 278 | }, |
| 279 | { // case14 |
| 280 | .ttype = SEND_SIGINT, |
| 281 | .len = 16, |
| 282 | .ret = -1, |
| 283 | .sec = 3, |
| 284 | .nsec = 0, |
| 285 | .err = EINTR, |
| 286 | }, |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 287 | }; |
| 288 | |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 289 | /* |
| 290 | * do_test() |
| 291 | * |
| 292 | * Input : TestCase Data |
| 293 | * Return : RESULT_OK(0), RESULT_NG(1) |
| 294 | * |
| 295 | */ |
| 296 | |
| 297 | static int do_test(struct test_case *tc) |
| 298 | { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 299 | int sys_ret; |
| 300 | int sys_errno; |
| 301 | int result = RESULT_OK; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 302 | int oflag; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 303 | int i, rc, cmp_ok = 1, fd = -1; |
| 304 | char smsg[MAX_MSGSIZE], rmsg[MAX_MSGSIZE]; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 305 | struct timespec ts = { 0, 0 }; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 306 | pid_t pid = 0; |
| 307 | unsigned prio; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 308 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 309 | /* |
| 310 | * When test ended with SIGTERM etc, mq discriptor is left remains. |
| 311 | * So we delete it first. |
| 312 | */ |
| 313 | TEST(mq_unlink(QUEUE_NAME)); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 314 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 315 | switch (tc->ttype) { |
| 316 | case FD_NOT_EXIST: |
| 317 | fd = INT_MAX - 1; |
| 318 | /* fallthrough */ |
| 319 | case FD_NONE: |
| 320 | break; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 321 | case FD_FILE: |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 322 | TEST(fd = open("/", O_RDONLY)); |
| 323 | if (fd < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 324 | tst_resm(TFAIL, "can't open \"/\".- errno = %d : %s\n", |
| 325 | TEST_ERRNO, strerror(TEST_ERRNO)); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 326 | result = 1; |
| 327 | goto EXIT; |
| 328 | } |
| 329 | break; |
| 330 | default: |
| 331 | /* |
| 332 | * Open message queue |
| 333 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 334 | oflag = O_CREAT | O_EXCL | O_RDWR; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 335 | if (tc->non_block) |
| 336 | oflag |= O_NONBLOCK; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 337 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 338 | TEST(fd = mq_open(QUEUE_NAME, oflag, S_IRWXU, NULL)); |
| 339 | if (TEST_RETURN < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 340 | tst_resm(TFAIL, "mq_open failed - errno = %d : %s\n", |
| 341 | TEST_ERRNO, strerror(TEST_ERRNO)); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 342 | result = 1; |
| 343 | goto EXIT; |
| 344 | } |
| 345 | if (tc->ttype == FULL_QUEUE || tc->ttype == SEND_SIGINT) { |
| 346 | for (i = 0; i < MAX_MSG; i++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 347 | TEST(rc = |
| 348 | mq_timedsend(fd, smsg, tc->len, 0, &ts)); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 349 | if (rc < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 350 | tst_resm(TFAIL, |
| 351 | "mq_timedsend failed - errno = %d : %s\n", |
| 352 | TEST_ERRNO, |
| 353 | strerror(TEST_ERRNO)); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 354 | result = 1; |
| 355 | goto EXIT; |
| 356 | } |
| 357 | } |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 358 | if (tc->ttype == SEND_SIGINT) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 359 | pid = create_sig_proc(200000, SIGINT, UINT_MAX); |
| 360 | if (pid < 0) { |
| 361 | result = 1; |
| 362 | goto EXIT; |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | break; |
| 367 | } |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 368 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 369 | /* |
| 370 | * Prepare send message |
| 371 | */ |
Carmelo AMOROSO | 3f3baa2 | 2011-07-05 16:24:12 +0200 | [diff] [blame] | 372 | for (i = 0; i < tc->len && i < sizeof(smsg); i++) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 373 | smsg[i] = i; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 374 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 375 | /* |
| 376 | * Set the timeout value |
| 377 | */ |
| 378 | ts.tv_sec = tc->sec; |
| 379 | ts.tv_nsec = tc->nsec; |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 380 | if (tc->sec >= 0 || tc->nsec != 0) |
| 381 | ts.tv_sec += time(NULL); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 382 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 383 | /* |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 384 | * Execut test system call |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 385 | */ |
| 386 | errno = 0; |
| 387 | TEST(sys_ret = mq_timedsend(fd, smsg, tc->len, tc->prio, &ts)); |
| 388 | sys_errno = errno; |
| 389 | if (sys_ret < 0) |
| 390 | goto TEST_END; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 391 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 392 | /* |
| 393 | * Receive echoed message and compare |
| 394 | */ |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 395 | ts.tv_sec = 0; |
| 396 | ts.tv_nsec = 0; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 397 | TEST(rc = mq_timedreceive(fd, rmsg, MAX_MSGSIZE, &prio, &ts)); |
| 398 | if (rc < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 399 | tst_resm(TFAIL, "mq_timedreceive failed - errno = %d : %s\n", |
| 400 | TEST_ERRNO, strerror(TEST_ERRNO)); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 401 | result = 1; |
| 402 | goto EXIT; |
| 403 | } |
| 404 | if (rc != tc->len || tc->prio != prio) |
| 405 | cmp_ok = 0; |
| 406 | else { |
| 407 | for (i = 0; i < tc->len; i++) |
| 408 | if (rmsg[i] != smsg[i]) { |
| 409 | cmp_ok = 0; |
| 410 | break; |
| 411 | } |
| 412 | } |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 413 | TEST_END: |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 414 | /* |
| 415 | * Check results |
| 416 | */ |
| 417 | result |= (sys_errno != tc->err) || !cmp_ok; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 418 | PRINT_RESULT_CMP(sys_ret >= 0, tc->ret, tc->err, sys_ret, sys_errno, |
| 419 | cmp_ok); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 420 | |
| 421 | EXIT: |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 422 | if (fd >= 0) { |
| 423 | TEST(close(fd)); |
| 424 | TEST(mq_unlink(QUEUE_NAME)); |
| 425 | } |
| 426 | if (pid > 0) { |
| 427 | int st; |
| 428 | kill(pid, SIGTERM); |
| 429 | wait(&st); |
| 430 | } |
| 431 | return result; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 432 | } |
| 433 | |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 434 | /* |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 435 | * main() |
| 436 | */ |
| 437 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 438 | int main(int ac, char **av) |
| 439 | { |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 440 | int result = RESULT_OK; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 441 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 442 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 443 | const char *msg; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 444 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 445 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
| 446 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 447 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 448 | setup(); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 449 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 450 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 451 | tst_count = 0; |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 452 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 453 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 454 | /* |
| 455 | * Execute test |
| 456 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 457 | for (i = 0; i < (int)(sizeof(tcase) / sizeof(tcase[0])); |
| 458 | i++) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 459 | int ret; |
| 460 | tst_resm(TINFO, "(case%02d) START", i); |
| 461 | ret = do_test(&tcase[i]); |
| 462 | tst_resm(TINFO, "(case%02d) END => %s", i, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 463 | (ret == 0) ? "OK" : "NG"); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 464 | result |= ret; |
| 465 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 466 | /* |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 467 | * Check results |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 468 | */ |
| 469 | switch (result) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 470 | case RESULT_OK: |
| 471 | tst_resm(TPASS, "mq_timedsend call succeeded"); |
| 472 | break; |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 473 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 474 | default: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 475 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 476 | "mq_timedsend failed"); |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 477 | } |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 478 | |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 479 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 480 | } |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 481 | cleanup(); |
subrata_modak | fc114ed | 2009-05-29 12:29:55 +0000 | [diff] [blame] | 482 | tst_exit(); |
Garrett Cooper | cd324c5 | 2010-12-19 10:05:13 -0800 | [diff] [blame] | 483 | } |