subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007-2008 ,Hitachi, Ltd */ |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 3 | /* Author(s): Takahiro Yasui <takahiro.yasui.mp@hitachi.com>, */ |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 4 | /* Yumiko Sugita <yumiko.sugita.yf@hitachi.com>, */ |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 5 | /* Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp> */ |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 6 | /* Porting from Crackerjack to LTP is done by */ |
| 7 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 8 | /* */ |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 9 | /* This program is free software; you can redistribute it and/or modify */ |
| 10 | /* it under the terms of the GNU General Public License as published by */ |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 11 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 12 | /* (at your option) any later version. */ |
| 13 | /* */ |
| 14 | /* This program is distributed in the hope that it will be useful, */ |
| 15 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 16 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 17 | /* the GNU General Public License for more details. */ |
| 18 | /* */ |
| 19 | /* You should have received a copy of the GNU General Public License */ |
| 20 | /* along with this program; if not, write to the Free Software Foundation, */ |
| 21 | /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 22 | /* */ |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 23 | /******************************************************************************/ |
| 24 | /******************************************************************************/ |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 25 | /* */ |
| 26 | /* Description: This tests the mq_notify() syscall */ |
| 27 | /* */ |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 28 | /******************************************************************************/ |
Garrett Cooper | 09cbd9c | 2010-02-18 21:24:03 -0800 | [diff] [blame] | 29 | #define _XOPEN_SOURCE 600 |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 30 | #include <sys/syscall.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <sys/uio.h> |
| 34 | #include <getopt.h> |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 35 | #include <libgen.h> |
| 36 | #include <limits.h> |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 37 | #include <errno.h> |
| 38 | #include <stdio.h> |
| 39 | #include <unistd.h> |
| 40 | #include <string.h> |
| 41 | #include <mqueue.h> |
| 42 | #include <signal.h> |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 43 | #include <stdlib.h> |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 44 | |
| 45 | #include "../utils/include_j_h.h" |
| 46 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 47 | #include "test.h" |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 48 | #include "linux_syscall_numbers.h" |
| 49 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 50 | char *TCID = "mq_notify01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 51 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 52 | int TST_TOTAL = 1; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 53 | |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 54 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 55 | { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 56 | tst_rmdir(); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Cyril Hrubis | be8b878 | 2014-03-18 17:55:52 +0100 | [diff] [blame] | 59 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 61 | TEST_PAUSE; |
| 62 | tst_tmpdir(); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 63 | } |
| 64 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 65 | #define SYSCALL_NAME "mq_notify" |
| 66 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 67 | static int opt_debug; |
| 68 | static char *progname; |
| 69 | static int notified; |
| 70 | static int cmp_ok; |
| 71 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 72 | enum test_type { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 73 | NORMAL, |
| 74 | FD_NONE, |
| 75 | FD_NOT_EXIST, |
| 76 | FD_FILE, |
| 77 | ALREADY_REGISTERED, |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 80 | struct test_case { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 81 | int notify; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 82 | int ttype; |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 83 | int ret; |
| 84 | int err; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #define MAX_MSGSIZE 8192 |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 88 | #define MSG_SIZE 16 |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 89 | #define USER_DATA 0x12345678 |
| 90 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 91 | static struct test_case tcase[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | { // case00 |
| 93 | .ttype = NORMAL, |
| 94 | .notify = SIGEV_NONE, |
| 95 | .ret = 0, |
| 96 | .err = 0, |
| 97 | }, |
| 98 | { // case01 |
| 99 | .ttype = NORMAL, |
| 100 | .notify = SIGEV_SIGNAL, |
| 101 | .ret = 0, |
| 102 | .err = 0, |
| 103 | }, |
| 104 | { // case02 |
| 105 | .ttype = NORMAL, |
| 106 | .notify = SIGEV_THREAD, |
| 107 | .ret = 0, |
| 108 | .err = 0, |
| 109 | }, |
| 110 | { // case03 |
| 111 | .ttype = FD_NONE, |
| 112 | .notify = SIGEV_NONE, |
| 113 | .ret = -1, |
| 114 | .err = EBADF, |
| 115 | }, |
| 116 | { // case04 |
| 117 | .ttype = FD_NOT_EXIST, |
| 118 | .notify = SIGEV_NONE, |
| 119 | .ret = -1, |
| 120 | .err = EBADF, |
| 121 | }, |
| 122 | { // case05 |
| 123 | .ttype = FD_FILE, |
| 124 | .notify = SIGEV_NONE, |
| 125 | .ret = -1, |
| 126 | .err = EBADF, |
| 127 | }, |
| 128 | { // case06 |
| 129 | .ttype = ALREADY_REGISTERED, |
| 130 | .notify = SIGEV_NONE, |
| 131 | .ret = -1, |
| 132 | .err = EBUSY, |
| 133 | }, |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 136 | static void sigfunc(int signo, siginfo_t * info, void *data) |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 137 | { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 138 | if (opt_debug) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | tst_resm(TINFO, "si_code E:%d,\tR:%d", info->si_code, |
| 140 | SI_MESGQ); |
| 141 | tst_resm(TINFO, "si_signo E:%d,\tR:%d", info->si_signo, |
| 142 | SIGUSR1); |
| 143 | tst_resm(TINFO, "si_value E:0x%x,\tR:0x%x", |
| 144 | info->si_value.sival_int, USER_DATA); |
| 145 | tst_resm(TINFO, "si_pid E:%d,\tR:%d", info->si_pid, getpid()); |
| 146 | tst_resm(TINFO, "si_uid E:%d,\tR:%d", info->si_uid, getuid()); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 147 | } |
| 148 | cmp_ok = info->si_code == SI_MESGQ && |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | info->si_signo == SIGUSR1 && |
| 150 | info->si_value.sival_int == USER_DATA && |
| 151 | info->si_pid == getpid() && info->si_uid == getuid(); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 152 | notified = 1; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static void tfunc(union sigval sv) |
| 156 | { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 157 | cmp_ok = sv.sival_int == USER_DATA; |
| 158 | notified = 1; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 159 | } |
| 160 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 161 | static int do_test(struct test_case *tc) |
| 162 | { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 163 | int sys_ret; |
| 164 | int sys_errno; |
| 165 | int result = RESULT_OK; |
| 166 | int rc, i, fd = -1; |
| 167 | struct sigevent ev; |
| 168 | struct sigaction sigact; |
Garrett Cooper | 09cbd9c | 2010-02-18 21:24:03 -0800 | [diff] [blame] | 169 | struct timespec abs_timeout; |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 170 | char smsg[MAX_MSGSIZE]; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 171 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 172 | notified = cmp_ok = 1; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 173 | |
Garrett Cooper | 09cbd9c | 2010-02-18 21:24:03 -0800 | [diff] [blame] | 174 | /* Don't timeout. */ |
| 175 | abs_timeout.tv_sec = 0; |
| 176 | abs_timeout.tv_nsec = 0; |
| 177 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 178 | /* |
| 179 | * When test ended with SIGTERM etc, mq discriptor is left remains. |
| 180 | * So we delete it first. |
| 181 | */ |
| 182 | mq_unlink(QUEUE_NAME); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 183 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 184 | switch (tc->ttype) { |
| 185 | case FD_NOT_EXIST: |
| 186 | fd = INT_MAX - 1; |
| 187 | /* fallthrough */ |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 188 | case FD_NONE: |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 189 | break; |
| 190 | case FD_FILE: |
| 191 | TEST(fd = open("/", O_RDONLY)); |
| 192 | if (TEST_RETURN < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 193 | tst_resm(TFAIL, "can't open \"/\"."); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 194 | result = 1; |
| 195 | goto EXIT; |
| 196 | } |
| 197 | break; |
| 198 | default: |
| 199 | /* |
| 200 | * Open message queue |
| 201 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 202 | TEST(fd = |
| 203 | mq_open(QUEUE_NAME, O_CREAT | O_EXCL | O_RDWR, S_IRWXU, |
| 204 | NULL)); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 205 | if (TEST_RETURN < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 206 | tst_resm(TFAIL | TTERRNO, "mq_open failed"); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 207 | result = 1; |
| 208 | goto EXIT; |
| 209 | } |
| 210 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 211 | |
| 212 | /* |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 213 | * Set up struct sigevent |
| 214 | */ |
| 215 | ev.sigev_notify = tc->notify; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 216 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 217 | switch (tc->notify) { |
| 218 | case SIGEV_SIGNAL: |
| 219 | notified = cmp_ok = 0; |
| 220 | ev.sigev_signo = SIGUSR1; |
| 221 | ev.sigev_value.sival_int = USER_DATA; |
| 222 | |
| 223 | memset(&sigact, 0, sizeof(sigact)); |
| 224 | sigact.sa_sigaction = sigfunc; |
| 225 | sigact.sa_flags = SA_SIGINFO; |
| 226 | TEST(rc = sigaction(SIGUSR1, &sigact, NULL)); |
| 227 | break; |
| 228 | case SIGEV_THREAD: |
| 229 | notified = cmp_ok = 0; |
| 230 | ev.sigev_notify_function = tfunc; |
| 231 | ev.sigev_notify_attributes = NULL; |
| 232 | ev.sigev_value.sival_int = USER_DATA; |
| 233 | break; |
| 234 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 235 | |
| 236 | if (tc->ttype == ALREADY_REGISTERED) { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 237 | TEST(rc = mq_notify(fd, &ev)); |
| 238 | if (TEST_RETURN < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 239 | tst_resm(TFAIL | TTERRNO, "mq_notify failed"); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 240 | result = 1; |
| 241 | goto EXIT; |
| 242 | } |
| 243 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 244 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 245 | /* |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 246 | * Execute system call |
| 247 | */ |
| 248 | errno = 0; |
| 249 | sys_ret = mq_notify(fd, &ev); |
Garrett Cooper | 3fceccb | 2010-02-18 21:43:51 -0800 | [diff] [blame] | 250 | sys_errno = errno; |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 251 | if (sys_ret < 0) |
| 252 | goto TEST_END; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 253 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 254 | /* |
| 255 | * Prepare send message |
| 256 | */ |
| 257 | for (i = 0; i < MSG_SIZE; i++) |
| 258 | smsg[i] = i; |
| 259 | TEST(rc = mq_timedsend(fd, smsg, MSG_SIZE, 0, &abs_timeout)); |
| 260 | if (rc < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 261 | tst_resm(TFAIL | TTERRNO, "mq_timedsend failed"); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 262 | result = 1; |
| 263 | goto EXIT; |
| 264 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 265 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 266 | while (!notified) |
| 267 | usleep(10000); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 268 | |
| 269 | TEST_END: |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 270 | /* |
| 271 | * Check results |
| 272 | */ |
| 273 | result |= (sys_ret != 0 && sys_errno != tc->err) || !cmp_ok; |
| 274 | PRINT_RESULT_CMP(sys_ret >= 0, tc->ret, tc->err, sys_ret, sys_errno, |
| 275 | cmp_ok); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 276 | |
| 277 | EXIT: |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 278 | if (fd >= 0) { |
| 279 | close(fd); |
| 280 | mq_unlink(QUEUE_NAME); |
| 281 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 282 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 283 | return result; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 284 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 285 | |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 286 | static void usage(const char *progname) |
| 287 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 288 | tst_resm(TINFO, "usage: %s [options]", progname); |
| 289 | tst_resm(TINFO, "This is a regression test program of %s system call.", |
| 290 | SYSCALL_NAME); |
| 291 | tst_resm(TINFO, "options:"); |
| 292 | tst_resm(TINFO, " -d --debug Show debug messages"); |
| 293 | tst_resm(TINFO, " -h --help Show this message"); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 296 | int main(int ac, char **av) |
| 297 | { |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 298 | int result = RESULT_OK; |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 299 | int c; |
| 300 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 301 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 302 | const char *msg; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 303 | |
| 304 | struct option long_options[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 305 | {"debug", no_argument, 0, 'd'}, |
| 306 | {"help", no_argument, 0, 'h'}, |
| 307 | {NULL, 0, NULL, 0} |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 308 | }; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 309 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 310 | progname = basename(av[0]); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 311 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 312 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 313 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 314 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 315 | setup(); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 316 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 317 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 318 | tst_count = 0; |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 319 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 320 | TEST(c = getopt_long(ac, av, "dh", long_options, NULL)); |
| 321 | while (TEST_RETURN != -1) { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 322 | switch (c) { |
| 323 | case 'd': |
| 324 | opt_debug = 1; |
| 325 | break; |
| 326 | default: |
| 327 | usage(progname); |
| 328 | } |
| 329 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 330 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 331 | if (ac != optind) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 332 | tst_resm(TINFO, "Options are not match."); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 333 | usage(progname); |
| 334 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 335 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 336 | for (i = 0; i < (int)(sizeof(tcase) / sizeof(tcase[0])); |
| 337 | i++) { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 338 | int ret; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 339 | tst_resm(TINFO, "(case%02d) START", i); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 340 | ret = do_test(&tcase[i]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 341 | tst_resm(TINFO, "(case%02d) END => %s", |
| 342 | i, (ret == 0) ? "OK" : "NG"); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 343 | result |= ret; |
| 344 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 345 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 346 | switch (result) { |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 347 | case RESULT_OK: |
| 348 | tst_resm(TPASS, "mq_notify call succeeded"); |
| 349 | break; |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 350 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 351 | default: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 352 | tst_brkm(TFAIL, cleanup, "mq_notify failed"); |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 353 | break; |
| 354 | } |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 355 | |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 356 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 357 | } |
Garrett Cooper | 2384bd4 | 2010-11-22 14:53:11 -0800 | [diff] [blame] | 358 | cleanup(); |
subrata_modak | 812b850 | 2009-05-29 10:38:21 +0000 | [diff] [blame] | 359 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 360 | } |