blob: 0bf234abbc3936133117d73111e691047ba1de47 [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
subrata_modaka9ba2142009-01-16 10:33:26 +000060#include "test.h"
Cyril Hrubis98f87472014-01-08 13:32:41 +010061#include "lapi/fcntl.h"
subrata_modak115006c2009-02-04 06:16:40 +000062#include "linux_syscall_numbers.h"
subrata_modaka9ba2142009-01-16 10:33:26 +000063
subrata_modaka9ba2142009-01-16 10:33:26 +000064#define TFD_NONBLOCK O_NONBLOCK
65
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020066char *TCID = "timerfd03";
subrata_modak56207ce2009-03-23 13:35:39 +000067int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020068int TST_TOTAL = 1;
subrata_modaka9ba2142009-01-16 10:33:26 +000069
70/* Extern Global Functions */
71/******************************************************************************/
72/* */
73/* Function: cleanup */
74/* */
75/* Description: Performs all one time clean up for this test on successful */
76/* completion, premature exit or failure. Closes all temporary */
77/* files, removes all temporary directories exits the test with */
78/* appropriate return code by calling tst_exit() function. */
79/* */
80/* Input: None. */
81/* */
82/* Output: None. */
83/* */
84/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
85/* On success - Exits calling tst_exit(). With '0' return code. */
86/* */
87/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040088void cleanup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000089{
Garrett Cooper2c282152010-12-16 00:55:50 -080090
subrata_modak56207ce2009-03-23 13:35:39 +000091 tst_rmdir();
subrata_modaka9ba2142009-01-16 10:33:26 +000092
subrata_modaka9ba2142009-01-16 10:33:26 +000093}
94
95/* Local Functions */
96/******************************************************************************/
97/* */
98/* Function: setup */
99/* */
100/* Description: Performs all one time setup for this test. This function is */
101/* typically used to capture signals, create temporary dirs */
102/* and temporary files that may be used in the course of this */
103/* test. */
104/* */
105/* Input: None. */
106/* */
107/* Output: None. */
108/* */
109/* Return: On failure - Exits by calling cleanup(). */
110/* On success - returns 0. */
111/* */
112/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400113void setup(void)
subrata_modak56207ce2009-03-23 13:35:39 +0000114{
115 /* Capture signals if any */
116 /* Create temporary directories */
117 TEST_PAUSE;
118 tst_tmpdir();
subrata_modaka9ba2142009-01-16 10:33:26 +0000119}
120
subrata_modak56207ce2009-03-23 13:35:39 +0000121int main(int argc, char *argv[])
122{
123 int fd, fl;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200124 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200125 const char *msg;
subrata_modaka9ba2142009-01-16 10:33:26 +0000126
Garrett Cooper45e285d2010-11-22 12:19:25 -0800127 msg = parse_opts(argc, argv, NULL, NULL);
128 if (msg != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000129 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000130 }
131 if ((tst_kvercmp(2, 6, 27)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100132 tst_brkm(TCONF,
133 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000134 "This test can only run on kernels that are 2.6.27 and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000135 }
136 setup();
subrata_modaka9ba2142009-01-16 10:33:26 +0000137
subrata_modak56207ce2009-03-23 13:35:39 +0000138 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800139 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000140 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100141 fd = ltp_syscall(__NR_timerfd_create,
142 CLOCK_REALTIME, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000143 if (fd == -1) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100144 tst_brkm(TFAIL, cleanup,
145 "timerfd_create(0) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000146 }
147 fl = fcntl(fd, F_GETFL);
148 if (fl == -1) {
149 tst_brkm(TBROK, cleanup, "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000150 }
151 if (fl & O_NONBLOCK) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100152 tst_brkm(TFAIL,
153 cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000154 "timerfd_create(0) set non-blocking mode");
subrata_modak56207ce2009-03-23 13:35:39 +0000155 }
156 close(fd);
subrata_modaka9ba2142009-01-16 10:33:26 +0000157
Jan Stancek359980f2013-02-15 10:16:05 +0100158 fd = ltp_syscall(__NR_timerfd_create, CLOCK_REALTIME,
subrata_modak56207ce2009-03-23 13:35:39 +0000159 TFD_NONBLOCK);
160 if (fd == -1) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100161 tst_brkm(TFAIL,
162 cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000163 "timerfd_create(TFD_NONBLOCK) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000164 }
165 fl = fcntl(fd, F_GETFL);
166 if (fl == -1) {
167 tst_brkm(TBROK, cleanup, "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000168 }
169 if ((fl & O_NONBLOCK) == 0) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100170 tst_brkm(TFAIL,
171 cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000172 "timerfd_create(TFD_NONBLOCK) set non-blocking mode");
subrata_modak56207ce2009-03-23 13:35:39 +0000173 }
174 close(fd);
175 tst_resm(TPASS, "timerfd_create(TFD_NONBLOCK) PASSED");
176 cleanup();
177 }
178 }
179 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700180}