blob: 238447278b9820e663c404f1ebff558b282a4bd7 [file] [log] [blame]
Cyril Hrubisd21b9582013-09-04 16:29:35 +02001/******************************************************************************
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_modak1f2aeea2009-05-21 18:43:48 +000023#include <time.h>
24#include <signal.h>
25#include <syscall.h>
26#include <stdio.h>
27#include <errno.h>
28
subrata_modak1f2aeea2009-05-21 18:43:48 +000029#include "test.h"
subrata_modak1f2aeea2009-05-21 18:43:48 +000030#include "linux_syscall_numbers.h"
31
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020032char *TCID = "timer_gettime01";
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020033int TST_TOTAL = 3;
subrata_modak1f2aeea2009-05-21 18:43:48 +000034
Cyril Hrubisd21b9582013-09-04 16:29:35 +020035static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080036{
Garrett Cooper43088e12010-12-13 23:30:59 -080037 tst_rmdir();
subrata_modak1f2aeea2009-05-21 18:43:48 +000038}
39
Cyril Hrubisd21b9582013-09-04 16:29:35 +020040static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080041{
Garrett Cooper43088e12010-12-13 23:30:59 -080042 TEST_PAUSE;
Garrett Cooper43088e12010-12-13 23:30:59 -080043 tst_tmpdir();
subrata_modak1f2aeea2009-05-21 18:43:48 +000044}
45
Wanlong Gao354ebb42012-12-07 10:10:04 +080046int main(int ac, char **av)
47{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020048 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020049 const char *msg;
subrata_modak1f2aeea2009-05-21 18:43:48 +000050
Garrett Cooper43088e12010-12-13 23:30:59 -080051 struct sigevent ev;
52 struct itimerspec spec;
Cyril Hrubisd21b9582013-09-04 16:29:35 +020053 int timer;
subrata_modak1f2aeea2009-05-21 18:43:48 +000054
Garrett Coopere1f008e2010-12-14 00:21:59 -080055 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper43088e12010-12-13 23:30:59 -080056 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak1f2aeea2009-05-21 18:43:48 +000057
Garrett Cooper43088e12010-12-13 23:30:59 -080058 setup();
subrata_modak1f2aeea2009-05-21 18:43:48 +000059
Cyril Hrubisd21b9582013-09-04 16:29:35 +020060 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 Cooper43088e12010-12-13 23:30:59 -080068 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080069 tst_count = 0;
subrata_modak1f2aeea2009-05-21 18:43:48 +000070
Cyril Hrubisd21b9582013-09-04 16:29:35 +020071 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_modak1f2aeea2009-05-21 18:43:48 +000078
Cyril Hrubisd21b9582013-09-04 16:29:35 +020079 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_modak1f2aeea2009-05-21 18:43:48 +000086
Cyril Hrubisd21b9582013-09-04 16:29:35 +020087 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 Cooper43088e12010-12-13 23:30:59 -080093 }
94 }
subrata_modak1f2aeea2009-05-21 18:43:48 +000095
subrata_modak1f2aeea2009-05-21 18:43:48 +000096 cleanup();
Garrett Cooper43088e12010-12-13 23:30:59 -080097 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -070098}