blob: ab2249d00b816de0683cc6196d8df66c24fdbfaf [file] [log] [blame]
subrata_modak1f2aeea2009-05-21 18:43:48 +00001/******************************************************************************/
2/* Copyright (c) Crackerjack Project., 2007 */
3/* */
4/* This program is free software; you can redistribute it and/or modify */
5/* it under the terms of the GNU General Public License as published by */
6/* the Free Software Foundation; either version 2 of the License, or */
7/* (at your option) any later version. */
8/* */
9/* This program is distributed in the hope that it will be useful, */
10/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
12/* the GNU General Public License for more details. */
13/* */
14/* You should have received a copy of the GNU General Public License */
15/* along with this program; if not, write to the Free Software */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modak1f2aeea2009-05-21 18:43:48 +000017/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: timer_gettime01.c */
22/* */
23/* Description: This tests the timer_gettime() syscall */
24/* */
25/* Usage: <for command-line> */
26/* timer_gettime01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
27/* where, -c n : Run n copies concurrently. */
28/* -e : Turn on errno logging. */
29/* -i n : Execute test n times. */
30/* -I x : Execute test for x seconds. */
31/* -P x : Pause for x seconds between iterations. */
32/* -t : Turn on syscall timing. */
33/* */
34/* Total Tests: 1 */
35/* */
36/* Test Name: timer_gettime01 */
37/* History: Porting from Crackerjack to LTP is done by */
38/* Manas Kumar Nayak maknayak@in.ibm.com> */
39/******************************************************************************/
40#include <time.h>
41#include <signal.h>
42#include <syscall.h>
43#include <stdio.h>
44#include <errno.h>
45
46/* Harness Specific Include Files. */
47#include "test.h"
48#include "usctest.h"
49#include "linux_syscall_numbers.h"
50
Subrata Modak4e947652010-05-28 12:50:38 +053051/* timer_t in kernel(int) is different from Glibc definition(void*).
52 * Use the kernel definition.
53 */
54typedef int kernel_timer_t;
55
subrata_modak1f2aeea2009-05-21 18:43:48 +000056/* Extern Global Variables */
subrata_modak1f2aeea2009-05-21 18:43:48 +000057
58/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080059char *TCID = "timer_gettime01"; /* Test program identifier. */
60int testno;
61int TST_TOTAL = 3; /* total number of tests in this file. */
subrata_modak1f2aeea2009-05-21 18:43:48 +000062
63/* Extern Global Functions */
64/******************************************************************************/
65/* */
66/* Function: cleanup */
67/* */
68/* Description: Performs all one time clean up for this test on successful */
69/* completion, premature exit or failure. Closes all temporary */
70/* files, removes all temporary directories exits the test with */
71/* appropriate return code by calling tst_exit() function. */
72/* */
73/* Input: None. */
74/* */
75/* Output: None. */
76/* */
77/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
78/* On success - Exits calling tst_exit(). With '0' return code. */
79/* */
80/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080081extern void cleanup()
82{
Garrett Cooper2c282152010-12-16 00:55:50 -080083
Garrett Cooper43088e12010-12-13 23:30:59 -080084 TEST_CLEANUP;
85 tst_rmdir();
Garrett Cooper2c282152010-12-16 00:55:50 -080086
subrata_modak1f2aeea2009-05-21 18:43:48 +000087}
88
89/* Local Functions */
90/******************************************************************************/
91/* */
92/* Function: setup */
93/* */
94/* Description: Performs all one time setup for this test. This function is */
95/* typically used to capture signals, create temporary dirs */
96/* and temporary files that may be used in the course of this */
97/* test. */
98/* */
99/* Input: None. */
100/* */
101/* Output: None. */
102/* */
103/* Return: On failure - Exits by calling cleanup(). */
104/* On success - returns 0. */
105/* */
106/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107void setup()
108{
Garrett Cooper43088e12010-12-13 23:30:59 -0800109 /* Capture signals if any */
110 /* Create temporary directories */
111 TEST_PAUSE;
subrata_modak1f2aeea2009-05-21 18:43:48 +0000112
Garrett Cooper43088e12010-12-13 23:30:59 -0800113 tst_tmpdir();
subrata_modak1f2aeea2009-05-21 18:43:48 +0000114}
115
116#define ENTER(normal) tst_resm(TINFO, "Enter block %d: test %d (%s)", \
Garrett Cooper43088e12010-12-13 23:30:59 -0800117 block, Tst_count, normal?"NORMAL":"ERROR");
subrata_modak1f2aeea2009-05-21 18:43:48 +0000118
119char tmpname[40];
120int parent;
121int block = 1;
122
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123int main(int ac, char **av)
124{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200125 int lc;
126 char *msg;
subrata_modak1f2aeea2009-05-21 18:43:48 +0000127
Garrett Cooper43088e12010-12-13 23:30:59 -0800128 kernel_timer_t created_timer_id;
129 struct sigevent ev;
130 struct itimerspec spec;
subrata_modak1f2aeea2009-05-21 18:43:48 +0000131
Garrett Coopere1f008e2010-12-14 00:21:59 -0800132 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper43088e12010-12-13 23:30:59 -0800133 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak1f2aeea2009-05-21 18:43:48 +0000134
Garrett Cooper43088e12010-12-13 23:30:59 -0800135 setup();
subrata_modak1f2aeea2009-05-21 18:43:48 +0000136
Garrett Cooper43088e12010-12-13 23:30:59 -0800137 for (lc = 0; TEST_LOOPING(lc); ++lc) {
138 Tst_count = 0;
139 for (testno = 0; testno < TST_TOTAL; ++testno) {
140 ENTER(1);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800141 ev.sigev_value = (sigval_t) 0;
Garrett Cooper43088e12010-12-13 23:30:59 -0800142 ev.sigev_signo = SIGALRM;
143 ev.sigev_notify = SIGEV_SIGNAL;
Jan Stancek359980f2013-02-15 10:16:05 +0100144 TEST(ltp_syscall(__NR_timer_create, CLOCK_REALTIME, &ev,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 &created_timer_id));
Jan Stancek359980f2013-02-15 10:16:05 +0100146 TEST(ltp_syscall(__NR_timer_gettime, created_timer_id,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 &spec));
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800148 if (TEST_RETURN == 0) {
Garrett Cooper43088e12010-12-13 23:30:59 -0800149 tst_resm(TPASS, "Block %d: test %d PASSED",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800150 block, Tst_count);
Garrett Cooper43088e12010-12-13 23:30:59 -0800151 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800152 tst_brkm(TFAIL | TERRNO, cleanup,
153 "Block %d: test %d FAILED",
154 block, Tst_count);
Garrett Cooper43088e12010-12-13 23:30:59 -0800155 }
subrata_modak1f2aeea2009-05-21 18:43:48 +0000156
subrata_modak1f2aeea2009-05-21 18:43:48 +0000157/*
158
159ERRORS
160 -EINVAL
Garrett Cooper43088e12010-12-13 23:30:59 -0800161 An invalid timer_id value was specified.
subrata_modak1f2aeea2009-05-21 18:43:48 +0000162*/
Garrett Cooper43088e12010-12-13 23:30:59 -0800163 ENTER(0);
Jan Stancek359980f2013-02-15 10:16:05 +0100164 TEST(ltp_syscall(__NR_timer_gettime, -1, &spec));
Garrett Cooper43088e12010-12-13 23:30:59 -0800165 if (TEST_RETURN < 0 && TEST_ERRNO == EINVAL) {
166 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800167 "Block %d: test %d PASSED",
168 block, Tst_count);
Garrett Cooper43088e12010-12-13 23:30:59 -0800169 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800170 tst_brkm(TFAIL | TERRNO, cleanup,
171 "Block %d: test %d FAILED",
172 block, Tst_count);
Garrett Cooper43088e12010-12-13 23:30:59 -0800173 }
subrata_modak1f2aeea2009-05-21 18:43:48 +0000174
175/*
176
177 -EFAULT
Garrett Cooper43088e12010-12-13 23:30:59 -0800178 An invalid address of setting was specified.
subrata_modak1f2aeea2009-05-21 18:43:48 +0000179*/
180
Garrett Cooper43088e12010-12-13 23:30:59 -0800181 ENTER(0);
Jan Stancek359980f2013-02-15 10:16:05 +0100182 TEST(ltp_syscall(__NR_timer_gettime, created_timer_id,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800183 NULL));
184 if (TEST_RETURN < 0 && TEST_ERRNO == EFAULT) {
Garrett Cooper43088e12010-12-13 23:30:59 -0800185 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800186 "Block %d: test %d PASSED",
187 block, Tst_count);
Garrett Cooper43088e12010-12-13 23:30:59 -0800188 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800189 tst_brkm(TFAIL | TERRNO, cleanup,
190 "Block %d: test %d FAILED",
191 block, Tst_count);
Garrett Cooper43088e12010-12-13 23:30:59 -0800192 }
subrata_modak1f2aeea2009-05-21 18:43:48 +0000193
Garrett Cooper43088e12010-12-13 23:30:59 -0800194 }
195 }
subrata_modak1f2aeea2009-05-21 18:43:48 +0000196
subrata_modak1f2aeea2009-05-21 18:43:48 +0000197 cleanup();
Garrett Cooper43088e12010-12-13 23:30:59 -0800198 tst_exit();
subrata_modak1f2aeea2009-05-21 18:43:48 +0000199
Chris Dearmanec6edca2012-10-17 19:54:01 -0700200}