blob: 76ec56dac15f0eb61992e8a46d8d00343867566c [file] [log] [blame]
subrata_modak07168752009-05-21 18:41:36 +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_modak07168752009-05-21 18:41:36 +000017/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: timer_getoverrun01.c */
22/* */
23/* Description: This tests the timer_getoverrun() syscall */
24/* */
25/* Usage: <for command-line> */
26/* timer_getoverrun01 [-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_getoverrun01 */
37/* History: Porting from Crackerjack to LTP is done by */
38/* Manas Kumar Nayak maknayak@in.ibm.com> */
39/******************************************************************************/
40
41#include <stdio.h>
42#include <errno.h>
43#include <time.h>
44#include <signal.h>
45#include <syscall.h>
46
47/* Harness Specific Include Files. */
48#include "test.h"
49#include "usctest.h"
50#include "linux_syscall_numbers.h"
51
Subrata Modak4e947652010-05-28 12:50:38 +053052/* timer_t in kernel(int) is different from Glibc definition(void*).
53 * Use the kernel definition.
54 */
55typedef int kernel_timer_t;
56
subrata_modak07168752009-05-21 18:41:36 +000057/* Extern Global Variables */
subrata_modak07168752009-05-21 18:41:36 +000058
59/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080060char *TCID = "timer_getoverrun01"; /* Test program identifier. */
61int testno;
62int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modak07168752009-05-21 18:41:36 +000063
64/* Extern Global Functions */
65/******************************************************************************/
66/* */
67/* Function: cleanup */
68/* */
69/* Description: Performs all one time clean up for this test on successful */
70/* completion, premature exit or failure. Closes all temporary */
71/* files, removes all temporary directories exits the test with */
72/* appropriate return code by calling tst_exit() function. */
73/* */
74/* Input: None. */
75/* */
76/* Output: None. */
77/* */
78/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
79/* On success - Exits calling tst_exit(). With '0' return code. */
80/* */
81/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080082extern void cleanup()
83{
Garrett Cooper2c282152010-12-16 00:55:50 -080084
Wanlong Gao354ebb42012-12-07 10:10:04 +080085 TEST_CLEANUP;
86 tst_rmdir();
subrata_modak07168752009-05-21 18:41:36 +000087
Wanlong Gao354ebb42012-12-07 10:10:04 +080088 tst_exit();
subrata_modak07168752009-05-21 18:41:36 +000089}
90
91/* Local Functions */
92/******************************************************************************/
93/* */
94/* Function: setup */
95/* */
96/* Description: Performs all one time setup for this test. This function is */
97/* typically used to capture signals, create temporary dirs */
98/* and temporary files that may be used in the course of this */
99/* test. */
100/* */
101/* Input: None. */
102/* */
103/* Output: None. */
104/* */
105/* Return: On failure - Exits by calling cleanup(). */
106/* On success - returns 0. */
107/* */
108/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800109void setup()
110{
111 /* Capture signals if any */
112 /* Create temporary directories */
113 TEST_PAUSE;
114 tst_tmpdir();
subrata_modak07168752009-05-21 18:41:36 +0000115}
116
117char tmpname[40];
118int parent;
119int block = 1;
120
121#define ENTER(normal) tst_resm(TINFO, "Enter block %d: test %d (%s)", \
122 block, Tst_count, normal?"NORMAL":"ERROR");
123
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124int main(int ac, char **av)
125{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200126 int lc;
127 char *msg;
Subrata Modak4e947652010-05-28 12:50:38 +0530128 kernel_timer_t created_timer_id;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 struct sigevent ev;
Garrett Cooper2c282152010-12-16 00:55:50 -0800130
Wanlong Gao354ebb42012-12-07 10:10:04 +0800131 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
132 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
133 tst_exit();
134 }
subrata_modak07168752009-05-21 18:41:36 +0000135
Wanlong Gao354ebb42012-12-07 10:10:04 +0800136 setup();
subrata_modak07168752009-05-21 18:41:36 +0000137
Wanlong Gao354ebb42012-12-07 10:10:04 +0800138 for (lc = 0; TEST_LOOPING(lc); ++lc) {
139 Tst_count = 0;
140 for (testno = 0; testno < TST_TOTAL; ++testno) {
Garrett Cooper2c282152010-12-16 00:55:50 -0800141
Wanlong Gao354ebb42012-12-07 10:10:04 +0800142 ev.sigev_value = (sigval_t) 0;
143 ev.sigev_signo = SIGALRM;
144 ev.sigev_notify = SIGEV_SIGNAL;
subrata_modak07168752009-05-21 18:41:36 +0000145
Jan Stancek359980f2013-02-15 10:16:05 +0100146 TEST(ltp_syscall
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 (__NR_timer_create, CLOCK_REALTIME, &ev,
148 &created_timer_id));
Garrett Cooper2c282152010-12-16 00:55:50 -0800149
Wanlong Gao354ebb42012-12-07 10:10:04 +0800150 ENTER(1);
Jan Stancek359980f2013-02-15 10:16:05 +0100151 TEST(ltp_syscall(__NR_timer_getoverrun,
152 created_timer_id));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800153 if (TEST_RETURN == 0) {
154 tst_resm(TPASS, "Block %d: test %d PASSED",
155 block, Tst_count);
156 } else {
157 tst_resm(TFAIL,
158 "Block %d: test %d FAILED... errno = %d : %s",
159 block, Tst_count, TEST_ERRNO,
160 strerror(TEST_ERRNO));
161 cleanup();
162 tst_exit();
163 }
subrata_modak07168752009-05-21 18:41:36 +0000164
Wanlong Gao354ebb42012-12-07 10:10:04 +0800165 ENTER(0);
Jan Stancek359980f2013-02-15 10:16:05 +0100166 TEST(ltp_syscall(__NR_timer_getoverrun, -1));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800167 if (TEST_RETURN < 0 && TEST_ERRNO == EINVAL) {
168 tst_resm(TPASS, "Block %d: test %d PASSED",
169 block, Tst_count);
170 } else {
171 tst_resm(TFAIL,
172 "Block %d: test %d FAILED... errno = %d : %s",
173 block, Tst_count, TEST_ERRNO,
174 strerror(TEST_ERRNO));
175 cleanup();
176 tst_exit();
177 }
subrata_modak07168752009-05-21 18:41:36 +0000178
Wanlong Gao354ebb42012-12-07 10:10:04 +0800179 }
180 }
subrata_modak07168752009-05-21 18:41:36 +0000181 cleanup();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800182 tst_exit();
subrata_modak07168752009-05-21 18:41:36 +0000183}
184
subrata_modak07168752009-05-21 18:41:36 +0000185/*
186
187NAME
188 timer_getoverrun
189SYNOPSIS
190 #include <time.h>
191
192 int timer_getoverrun(timer_t timerid);
193
194 Only a single signal shall be queued to the process for a given timer
195 at any point in time. When a timer for which a signal is still pending
196 expires, no signal shall be queued, and a timer overrun shall occur.
197 When a timer expiration signal is delivered to or accepted by a pro-
198 cess, if the implementation supports the Realtime Signals Extension,
199 the timer_getoverrun() function shall return the timer expiration
200 overrun count for the specified timer. The overrun count returned con-
201 tains the number of extra timer expirations that occurred between the
202 time the signal was generated (queued) and when it was delivered or
203 accepted, up to but not including an implementation-defined maximum of
204 {DELAYTIMER_MAX}. If the number of such extra expirations is greater
205 than or equal to {DELAYTIMER_MAX}, then the overrun count shall be set
206 to {DELAYTIMER_MAX}. The value returned by timer_getoverrun() shall
207 apply to the most recent expiration signal delivery or acceptance for
208 the timer. If no expiration signal has been delivered for the timer,
209 or if the Realtime Signals Extension is not supported, the return
210 value of timer_getoverrun() is unspecified.
211
212RETURN VALUE
213 If the timer_getoverrun() function succeeds, it shall return the timer
214 expiration overrun count as explained above.
Chris Dearmanec6edca2012-10-17 19:54:01 -0700215*/