Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * Copyright (c) Crackerjack Project., 2007 * |
| 3 | * Porting from Crackerjack to LTP is done by: * |
| 4 | * Manas Kumar Nayak <maknayak@in.ibm.com> * |
| 5 | * Copyright (c) 2013 Cyril Hrubis <chrubis@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 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 23 | #include <time.h> |
| 24 | #include <signal.h> |
| 25 | #include <syscall.h> |
| 26 | #include <stdio.h> |
| 27 | #include <errno.h> |
| 28 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 29 | #include "test.h" |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 30 | #include "linux_syscall_numbers.h" |
| 31 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 32 | char *TCID = "timer_gettime01"; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 33 | int TST_TOTAL = 3; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 34 | |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 35 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 36 | { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 37 | tst_rmdir(); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 40 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 41 | { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 42 | TEST_PAUSE; |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 43 | tst_tmpdir(); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 46 | int main(int ac, char **av) |
| 47 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 48 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 49 | const char *msg; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 50 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 51 | struct sigevent ev; |
| 52 | struct itimerspec spec; |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 53 | int timer; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 54 | |
Garrett Cooper | e1f008e | 2010-12-14 00:21:59 -0800 | [diff] [blame] | 55 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 56 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 57 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 58 | setup(); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 59 | |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 60 | ev.sigev_value = (sigval_t) 0; |
| 61 | ev.sigev_signo = SIGALRM; |
| 62 | ev.sigev_notify = SIGEV_SIGNAL; |
| 63 | TEST(ltp_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer)); |
| 64 | |
| 65 | if (TEST_RETURN != 0) |
| 66 | tst_brkm(TBROK | TERRNO, cleanup, "Failed to create timer"); |
| 67 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 68 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 69 | tst_count = 0; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 70 | |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 71 | TEST(ltp_syscall(__NR_timer_gettime, timer, &spec)); |
| 72 | if (TEST_RETURN == 0) { |
| 73 | tst_resm(TPASS, "timer_gettime(CLOCK_REALTIME) Passed"); |
| 74 | } else { |
| 75 | tst_resm(TFAIL | TERRNO, |
| 76 | "timer_gettime(CLOCK_REALTIME) Failed"); |
| 77 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 78 | |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 79 | TEST(ltp_syscall(__NR_timer_gettime, -1, &spec)); |
| 80 | if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) { |
| 81 | tst_resm(TPASS, "timer_gettime(-1) Failed: EINVAL"); |
| 82 | } else { |
| 83 | tst_resm(TFAIL | TERRNO, |
| 84 | "timer_gettime(-1) = %li", TEST_RETURN); |
| 85 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 86 | |
Cyril Hrubis | d21b958 | 2013-09-04 16:29:35 +0200 | [diff] [blame] | 87 | TEST(ltp_syscall(__NR_timer_gettime, timer, NULL)); |
| 88 | if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT) { |
| 89 | tst_resm(TPASS, "timer_gettime(NULL) Failed: EFAULT"); |
| 90 | } else { |
| 91 | tst_resm(TFAIL | TERRNO, |
| 92 | "timer_gettime(-1) = %li", TEST_RETURN); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 93 | } |
| 94 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 95 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 96 | cleanup(); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 97 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 98 | } |