• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************/
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               */
18 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
19 /*                                                                            */
20 /******************************************************************************/
21 /******************************************************************************/
22 /*                                                                            */
23 /* File:        eventfd2_01.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=b087498eb5605673b0f260a7620d91818cd72304 */
28 /*              says:                                                         */
29 /* This patch adds the new eventfd2 syscall.  It extends the old eventfd      */
30 /* syscall by one parameter which is meant to hold a flag value.  In this     */
31 /* patch the only flag support is EFD_CLOEXEC which causes the close-on-exec  */
32 /* flag for the returned file descriptor to be set. A new name EFD_CLOEXEC is */
33 /* introduced which in this implementation must have the same value as        */
34 /* O_CLOEXEC. The following test must be adjusted for architectures other than*/
35 /*  x86 and x86-64 and in case the syscall numbers changed.                   */
36 /*                                                                            */
37 /* Usage:  <for command-line>                                                 */
38 /* eventfd2_01 [-c n] [-e][-i n] [-I x] [-p x] [-t]                           */
39 /*      where,  -c n : Run n copies concurrently.                             */
40 /*              -e   : Turn on errno logging.                                 */
41 /*              -i n : Execute test n times.                                  */
42 /*              -I x : Execute test for x seconds.                            */
43 /*              -P x : Pause for x seconds between iterations.                */
44 /*              -t   : Turn on syscall timing.                                */
45 /*                                                                            */
46 /* Total Tests: 1                                                             */
47 /*                                                                            */
48 /* Test Name:   eventfd2_01                                                   */
49 /*                                                                            */
50 /* Author:      Ulrich Drepper <drepper@redhat.com>                           */
51 /*                                                                            */
52 /* History:     Created - Jan 08 2009 - Ulrich Drepper <drepper@redhat.com>   */
53 /*              Ported to LTP                                                 */
54 /*                      - Jan 08 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
55 /******************************************************************************/
56 #include <stdio.h>
57 #include <unistd.h>
58 #include <sys/syscall.h>
59 #include <errno.h>
60 
61 #include "test.h"
62 #include "lapi/fcntl.h"
63 #include "lapi/syscalls.h"
64 
65 #define EFD_CLOEXEC O_CLOEXEC
66 
67 char *TCID = "eventfd2_01";
68 int testno;
69 int TST_TOTAL = 1;
70 
cleanup(void)71 void cleanup(void)
72 {
73 	tst_rmdir();
74 }
75 
setup(void)76 void setup(void)
77 {
78 	TEST_PAUSE;
79 	tst_tmpdir();
80 }
81 
main(int argc,char * argv[])82 int main(int argc, char *argv[])
83 {
84 	int fd, coe;
85 
86 	tst_parse_opts(argc, argv, NULL, NULL);
87 
88 	if ((tst_kvercmp(2, 6, 27)) < 0) {
89 		tst_brkm(TCONF, NULL,
90 			 "This test can only run on kernels that are 2.6.27 and higher");
91 	}
92 	setup();
93 
94 	fd = ltp_syscall(__NR_eventfd2, 1, 0);
95 	if (fd == -1) {
96 		tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
97 	}
98 	coe = fcntl(fd, F_GETFD);
99 	if (coe == -1) {
100 		tst_brkm(TBROK, cleanup, "fcntl failed");
101 	}
102 	if (coe & FD_CLOEXEC) {
103 		tst_brkm(TFAIL, cleanup, "eventfd2(0) set close-on-exec flag");
104 	}
105 	close(fd);
106 
107 	fd = ltp_syscall(__NR_eventfd2, 1, EFD_CLOEXEC);
108 	if (fd == -1) {
109 		tst_brkm(TFAIL, cleanup, "eventfd2(EFD_CLOEXEC) failed");
110 	}
111 	coe = fcntl(fd, F_GETFD);
112 	if (coe == -1) {
113 		tst_brkm(TBROK, cleanup, "fcntl failed");
114 	}
115 	if ((coe & FD_CLOEXEC) == 0) {
116 		tst_brkm(TFAIL, cleanup,
117 			 "eventfd2(EFD_CLOEXEC) does not set close-on-exec flag");
118 	}
119 	close(fd);
120 	tst_resm(TPASS, "eventfd2(EFD_CLOEXEC) Passed");
121 	cleanup();
122 	tst_exit();
123 }
124