Zeng Linggang | 0feb2d7 | 2014-02-21 16:33:39 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Fujitsu Ltd. |
| 3 | * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program. |
| 15 | */ |
| 16 | /* |
| 17 | * ALGORITHM |
| 18 | * test 1: |
| 19 | * sevp->sigev_notify = -1, EINVAL should be returned. |
| 20 | * test 2: |
| 21 | * sevp->sigev_notify = SIGEV_SIGNAL and sevp->sigev_signo > _NSG, |
| 22 | * EINVAL should be returned. |
| 23 | */ |
| 24 | |
| 25 | #include <errno.h> |
| 26 | #include <mqueue.h> |
| 27 | #include "test.h" |
Zeng Linggang | 0feb2d7 | 2014-02-21 16:33:39 +0800 | [diff] [blame] | 28 | |
| 29 | char *TCID = "mq_notify02"; |
| 30 | static void setup(void); |
| 31 | static void cleanup(void); |
| 32 | |
| 33 | static struct test_case_t { |
| 34 | struct sigevent sevp; |
| 35 | int exp_errno; |
| 36 | } test_cases[] = { |
| 37 | {{.sigev_notify = -1}, EINVAL}, |
| 38 | {{.sigev_notify = SIGEV_SIGNAL, .sigev_signo = _NSIG+1}, EINVAL}, |
| 39 | }; |
| 40 | |
| 41 | int TST_TOTAL = ARRAY_SIZE(test_cases); |
| 42 | static void mq_notify_verify(struct test_case_t *); |
Zeng Linggang | 0feb2d7 | 2014-02-21 16:33:39 +0800 | [diff] [blame] | 43 | |
| 44 | int main(int argc, char **argv) |
| 45 | { |
| 46 | int lc; |
| 47 | int i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 48 | const char *msg; |
Zeng Linggang | 0feb2d7 | 2014-02-21 16:33:39 +0800 | [diff] [blame] | 49 | |
| 50 | msg = parse_opts(argc, argv, NULL, NULL); |
| 51 | if (msg != NULL) |
| 52 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 53 | |
| 54 | setup(); |
| 55 | |
Zeng Linggang | 0feb2d7 | 2014-02-21 16:33:39 +0800 | [diff] [blame] | 56 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 57 | tst_count = 0; |
| 58 | for (i = 0; i < TST_TOTAL; i++) |
| 59 | mq_notify_verify(&test_cases[i]); |
| 60 | } |
| 61 | cleanup(); |
| 62 | tst_exit(); |
| 63 | } |
| 64 | |
| 65 | static void setup(void) |
| 66 | { |
| 67 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 68 | |
| 69 | TEST_PAUSE; |
| 70 | } |
| 71 | |
| 72 | static void mq_notify_verify(struct test_case_t *test) |
| 73 | { |
| 74 | TEST(mq_notify(0, &(test->sevp))); |
| 75 | |
| 76 | if (TEST_RETURN != -1) { |
| 77 | tst_resm(TFAIL, "mq_notify() succeeded unexpectedly"); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if (TEST_ERRNO == test->exp_errno) { |
| 82 | tst_resm(TPASS | TTERRNO, "mq_notify failed as expected"); |
| 83 | } else { |
| 84 | tst_resm(TFAIL | TTERRNO, |
| 85 | "mq_notify failed unexpectedly; expected: %d - %s", |
| 86 | test->exp_errno, strerror(test->exp_errno)); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | static void cleanup(void) |
| 91 | { |
Zeng Linggang | 0feb2d7 | 2014-02-21 16:33:39 +0800 | [diff] [blame] | 92 | } |