blob: 89686d18da39ed13f5afeab7dea4319e72407a1c [file] [log] [blame]
subrata_modaka9ba2142009-01-16 10:33:26 +00001/******************************************************************************/
2/* */
3/* Copyright (c) Ulrich Drepper <drepper@redhat.com> */
4/* Copyright (c) International Business Machines Corp., 2009 */
5/* */
6/* This program is free software; you can redistribute it and/or modify */
7/* it under the terms of the GNU General Public License as published by */
8/* the Free Software Foundation; either version 2 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* This program is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
14/* the GNU General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU General Public License */
17/* along with this program; if not, write to the Free Software */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modaka9ba2142009-01-16 10:33:26 +000019/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: timerfd03.c */
24/* */
25/* Description: This Program tests the new system call introduced in 2.6.27. */
26/* Ulrich´s comment as in: */
27/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=6b1ef0e60d42f2fdaec26baee8327eb156347b4f */
28/* which says: */
29/* This patch adds support for the TFD_NONBLOCK flag to timerfd_create. The */
30/* additional changes needed are minimal. The following test must be adjusted */
31/* for architectures other than x86 and x86-64 and in case the syscall numbers*/
32/* changed. */
33/* */
34/* Usage: <for command-line> */
35/* timerfd03 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
36/* where, -c n : Run n copies concurrently. */
37/* -e : Turn on errno logging. */
38/* -i n : Execute test n times. */
39/* -I x : Execute test for x seconds. */
40/* -P x : Pause for x seconds between iterations. */
41/* -t : Turn on syscall timing. */
42/* */
43/* Total Tests: 1 */
44/* */
45/* Test Name: timerfd03 */
46/* */
47/* Author: Ulrich Drepper <drepper@redhat.com> */
48/* */
49/* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */
50/* Ported to LTP */
51/* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */
52/******************************************************************************/
53#include <fcntl.h>
54#include <stdio.h>
55#include <time.h>
56#include <unistd.h>
57#include <sys/syscall.h>
subrata_modakc488f902009-02-23 07:17:33 +000058#include <errno.h>
subrata_modaka9ba2142009-01-16 10:33:26 +000059
60/* Harness Specific Include Files. */
61#include "test.h"
62#include "usctest.h"
subrata_modak115006c2009-02-04 06:16:40 +000063#include "linux_syscall_numbers.h"
subrata_modaka9ba2142009-01-16 10:33:26 +000064
65#ifndef O_CLOEXEC
Wanlong Gao354ebb42012-12-07 10:10:04 +080066#define O_CLOEXEC 02000000
subrata_modaka9ba2142009-01-16 10:33:26 +000067#endif
68
subrata_modaka9ba2142009-01-16 10:33:26 +000069#define TFD_NONBLOCK O_NONBLOCK
70
71/* Extern Global Variables */
subrata_modaka9ba2142009-01-16 10:33:26 +000072
73/* Global Variables */
subrata_modak56207ce2009-03-23 13:35:39 +000074char *TCID = "timerfd03"; /* test program identifier. */
75int testno;
76int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modaka9ba2142009-01-16 10:33:26 +000077
78/* Extern Global Functions */
79/******************************************************************************/
80/* */
81/* Function: cleanup */
82/* */
83/* Description: Performs all one time clean up for this test on successful */
84/* completion, premature exit or failure. Closes all temporary */
85/* files, removes all temporary directories exits the test with */
86/* appropriate return code by calling tst_exit() function. */
87/* */
88/* Input: None. */
89/* */
90/* Output: None. */
91/* */
92/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
93/* On success - Exits calling tst_exit(). With '0' return code. */
94/* */
95/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +000096extern void cleanup()
97{
Garrett Cooper2c282152010-12-16 00:55:50 -080098
subrata_modak56207ce2009-03-23 13:35:39 +000099 TEST_CLEANUP;
100 tst_rmdir();
subrata_modaka9ba2142009-01-16 10:33:26 +0000101
subrata_modaka9ba2142009-01-16 10:33:26 +0000102}
103
104/* Local Functions */
105/******************************************************************************/
106/* */
107/* Function: setup */
108/* */
109/* Description: Performs all one time setup for this test. This function is */
110/* typically used to capture signals, create temporary dirs */
111/* and temporary files that may be used in the course of this */
112/* test. */
113/* */
114/* Input: None. */
115/* */
116/* Output: None. */
117/* */
118/* Return: On failure - Exits by calling cleanup(). */
119/* On success - returns 0. */
120/* */
121/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000122void setup()
123{
124 /* Capture signals if any */
125 /* Create temporary directories */
126 TEST_PAUSE;
127 tst_tmpdir();
subrata_modaka9ba2142009-01-16 10:33:26 +0000128}
129
subrata_modak56207ce2009-03-23 13:35:39 +0000130int main(int argc, char *argv[])
131{
132 int fd, fl;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200133 int lc;
134 char *msg;
subrata_modaka9ba2142009-01-16 10:33:26 +0000135
subrata_modak56207ce2009-03-23 13:35:39 +0000136 /* Parse standard options given to run the test. */
Garrett Cooper45e285d2010-11-22 12:19:25 -0800137 msg = parse_opts(argc, argv, NULL, NULL);
138 if (msg != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000139 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
140 tst_exit();
141 }
142 if ((tst_kvercmp(2, 6, 27)) < 0) {
143 tst_resm(TCONF,
144 "This test can only run on kernels that are 2.6.27 and higher");
145 tst_exit();
146 }
147 setup();
subrata_modaka9ba2142009-01-16 10:33:26 +0000148
subrata_modak56207ce2009-03-23 13:35:39 +0000149 for (lc = 0; TEST_LOOPING(lc); ++lc) {
150 Tst_count = 0;
151 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100152 fd = ltp_syscall(__NR_timerfd_create,
153 CLOCK_REALTIME, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000154 if (fd == -1) {
155 tst_resm(TFAIL, "timerfd_create(0) failed");
156 cleanup();
157 tst_exit();
158 }
159 fl = fcntl(fd, F_GETFL);
160 if (fl == -1) {
161 tst_brkm(TBROK, cleanup, "fcntl failed");
162 tst_exit();
163 }
164 if (fl & O_NONBLOCK) {
165 tst_resm(TFAIL,
166 "timerfd_create(0) set non-blocking mode");
167 cleanup();
168 tst_exit();
169 }
170 close(fd);
subrata_modaka9ba2142009-01-16 10:33:26 +0000171
Jan Stancek359980f2013-02-15 10:16:05 +0100172 fd = ltp_syscall(__NR_timerfd_create, CLOCK_REALTIME,
subrata_modak56207ce2009-03-23 13:35:39 +0000173 TFD_NONBLOCK);
174 if (fd == -1) {
175 tst_resm(TFAIL,
176 "timerfd_create(TFD_NONBLOCK) failed");
177 cleanup();
178 tst_exit();
179 }
180 fl = fcntl(fd, F_GETFL);
181 if (fl == -1) {
182 tst_brkm(TBROK, cleanup, "fcntl failed");
183 tst_exit();
184 }
185 if ((fl & O_NONBLOCK) == 0) {
186 tst_resm(TFAIL,
187 "timerfd_create(TFD_NONBLOCK) set non-blocking mode");
188 cleanup();
189 tst_exit();
190 }
191 close(fd);
192 tst_resm(TPASS, "timerfd_create(TFD_NONBLOCK) PASSED");
193 cleanup();
194 }
195 }
196 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700197}