Zeng Linggang | 9ac868c | 2014-06-27 10:02:52 +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; if not, write the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | /* |
| 18 | * DESCRIPTION |
| 19 | * Verify that, |
| 20 | * 1. The clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME, |
| 21 | * EINVAL would return. |
| 22 | * 2. flags is invalid, EINVAL would return. |
| 23 | */ |
| 24 | |
| 25 | #define _GNU_SOURCE |
| 26 | |
| 27 | #include <errno.h> |
| 28 | |
| 29 | #include "test.h" |
Zeng Linggang | 9ac868c | 2014-06-27 10:02:52 +0800 | [diff] [blame] | 30 | #include "lapi/timerfd.h" |
| 31 | |
| 32 | char *TCID = "timerfd_create01"; |
| 33 | |
| 34 | static struct test_case_t { |
| 35 | int clockid; |
| 36 | int flags; |
| 37 | int exp_errno; |
| 38 | } test_cases[] = { |
| 39 | {-1, 0, EINVAL}, |
| 40 | {0, -1, EINVAL}, |
| 41 | }; |
| 42 | |
| 43 | int TST_TOTAL = ARRAY_SIZE(test_cases); |
| 44 | static void setup(void); |
| 45 | static void timerfd_create_verify(const struct test_case_t *); |
| 46 | static void cleanup(void); |
Zeng Linggang | 9ac868c | 2014-06-27 10:02:52 +0800 | [diff] [blame] | 47 | |
| 48 | int main(int argc, char *argv[]) |
| 49 | { |
| 50 | int lc; |
| 51 | const char *msg; |
| 52 | int i; |
| 53 | |
| 54 | msg = parse_opts(argc, argv, NULL, NULL); |
| 55 | if (msg != NULL) |
| 56 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 57 | |
| 58 | setup(); |
| 59 | |
| 60 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 61 | tst_count = 0; |
| 62 | for (i = 0; i < TST_TOTAL; i++) |
| 63 | timerfd_create_verify(&test_cases[i]); |
| 64 | } |
| 65 | |
| 66 | cleanup(); |
| 67 | tst_exit(); |
| 68 | } |
| 69 | |
| 70 | static void setup(void) |
| 71 | { |
| 72 | if ((tst_kvercmp(2, 6, 25)) < 0) |
| 73 | tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer"); |
| 74 | |
| 75 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 76 | |
| 77 | TEST_PAUSE; |
Zeng Linggang | 9ac868c | 2014-06-27 10:02:52 +0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static void timerfd_create_verify(const struct test_case_t *test) |
| 81 | { |
| 82 | TEST(timerfd_create(test->clockid, test->flags)); |
| 83 | |
| 84 | if (TEST_RETURN != -1) { |
| 85 | tst_resm(TFAIL, "timerfd_create() succeeded unexpectedly"); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if (TEST_ERRNO == test->exp_errno) { |
| 90 | tst_resm(TPASS | TTERRNO, |
| 91 | "timerfd_create() failed as expected"); |
| 92 | } else { |
| 93 | tst_resm(TFAIL | TTERRNO, |
| 94 | "timerfd_create() failed unexpectedly; expected: " |
| 95 | "%d - %s", test->exp_errno, strerror(test->exp_errno)); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | static void cleanup(void) |
| 100 | { |
Zeng Linggang | 9ac868c | 2014-06-27 10:02:52 +0800 | [diff] [blame] | 101 | } |