1 /****************************************************************************** 2 * Copyright (c) Crackerjack Project., 2007 * 3 * Porting from Crackerjack to LTP is done by: * 4 * Manas Kumar Nayak <maknayak (at) in.ibm.com> * 5 * Copyright (c) 2013 Cyril Hrubis <chrubis (at) suse.cz> * 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 Foundation, * 19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 20 * * 21 ******************************************************************************/ 22 23 #include <time.h> 24 #include <signal.h> 25 #include <sys/syscall.h> 26 #include <stdio.h> 27 #include <errno.h> 28 29 #include "test.h" 30 #include "lapi/syscalls.h" 31 32 char *TCID = "timer_gettime01"; 33 int TST_TOTAL = 3; 34 35 static void cleanup(void) 36 { 37 tst_rmdir(); 38 } 39 40 static void setup(void) 41 { 42 TEST_PAUSE; 43 tst_tmpdir(); 44 } 45 46 int main(int ac, char **av) 47 { 48 int lc; 49 50 struct sigevent ev; 51 struct itimerspec spec; 52 int timer; 53 54 tst_parse_opts(ac, av, NULL, NULL); 55 56 setup(); 57 58 ev.sigev_value = (union sigval) 0; 59 ev.sigev_signo = SIGALRM; 60 ev.sigev_notify = SIGEV_SIGNAL; 61 TEST(ltp_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer)); 62 63 if (TEST_RETURN != 0) 64 tst_brkm(TBROK | TERRNO, cleanup, "Failed to create timer"); 65 66 for (lc = 0; TEST_LOOPING(lc); ++lc) { 67 tst_count = 0; 68 69 TEST(ltp_syscall(__NR_timer_gettime, timer, &spec)); 70 if (TEST_RETURN == 0) { 71 tst_resm(TPASS, "timer_gettime(CLOCK_REALTIME) Passed"); 72 } else { 73 tst_resm(TFAIL | TERRNO, 74 "timer_gettime(CLOCK_REALTIME) Failed"); 75 } 76 77 TEST(ltp_syscall(__NR_timer_gettime, -1, &spec)); 78 if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) { 79 tst_resm(TPASS, "timer_gettime(-1) Failed: EINVAL"); 80 } else { 81 tst_resm(TFAIL | TERRNO, 82 "timer_gettime(-1) = %li", TEST_RETURN); 83 } 84 85 TEST(ltp_syscall(__NR_timer_gettime, timer, NULL)); 86 if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT) { 87 tst_resm(TPASS, "timer_gettime(NULL) Failed: EFAULT"); 88 } else { 89 tst_resm(TFAIL | TERRNO, 90 "timer_gettime(-1) = %li", TEST_RETURN); 91 } 92 } 93 94 cleanup(); 95 tst_exit(); 96 } 97