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" 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); 47 48 int main(int argc, char *argv[]) 49 { 50 int lc; 51 int i; 52 53 tst_parse_opts(argc, argv, NULL, NULL); 54 55 setup(); 56 57 for (lc = 0; TEST_LOOPING(lc); lc++) { 58 tst_count = 0; 59 for (i = 0; i < TST_TOTAL; i++) 60 timerfd_create_verify(&test_cases[i]); 61 } 62 63 cleanup(); 64 tst_exit(); 65 } 66 67 static void setup(void) 68 { 69 if ((tst_kvercmp(2, 6, 25)) < 0) 70 tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer"); 71 72 tst_sig(NOFORK, DEF_HANDLER, cleanup); 73 74 TEST_PAUSE; 75 } 76 77 static void timerfd_create_verify(const struct test_case_t *test) 78 { 79 TEST(timerfd_create(test->clockid, test->flags)); 80 81 if (TEST_RETURN != -1) { 82 tst_resm(TFAIL, "timerfd_create() succeeded unexpectedly"); 83 return; 84 } 85 86 if (TEST_ERRNO == test->exp_errno) { 87 tst_resm(TPASS | TTERRNO, 88 "timerfd_create() failed as expected"); 89 } else { 90 tst_resm(TFAIL | TTERRNO, 91 "timerfd_create() failed unexpectedly; expected: " 92 "%d - %s", test->exp_errno, strerror(test->exp_errno)); 93 } 94 } 95 96 static void cleanup(void) 97 { 98 } 99