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_02.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=e7d476dfdf0bcfed478a207aecfdc84f81efecaf */
28 /* which says: */
29 /* This patch adds support for the EFD_NONBLOCK flag to eventfd2. The */
30 /* additional changes needed are minimal. The following test must be adjusted */
31 /* or architectures other than x86 and x86-64 and in case the syscall numbers */
32 /* changed. */
33 /* */
34 /* Usage: <for command-line> */
35 /* eventfd2_02 [-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: eventfd2_02 */
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 <unistd.h>
56 #include <sys/syscall.h>
57 #include <errno.h>
58
59 #include "test.h"
60 #include "lapi/fcntl.h"
61 #include "lapi/syscalls.h"
62
63 #define EFD_NONBLOCK O_NONBLOCK
64
65 char *TCID = "eventfd2_02";
66 int testno;
67 int TST_TOTAL = 1;
68
cleanup(void)69 void cleanup(void)
70 {
71 tst_rmdir();
72 }
73
setup(void)74 void setup(void)
75 {
76 TEST_PAUSE;
77 tst_tmpdir();
78 }
79
main(int argc,char * argv[])80 int main(int argc, char *argv[])
81 {
82 int fd, fl;
83
84 tst_parse_opts(argc, argv, NULL, NULL);
85
86 if ((tst_kvercmp(2, 6, 27)) < 0) {
87 tst_brkm(TCONF, NULL,
88 "This test can only run on kernels that are 2.6.27 and higher");
89 }
90 setup();
91
92 tst_count = 0;
93 fd = ltp_syscall(__NR_eventfd2, 1, 0);
94 if (fd == -1) {
95 tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
96 }
97 fl = fcntl(fd, F_GETFL);
98 if (fl == -1) {
99 tst_brkm(TBROK, cleanup, "fcntl failed");
100 }
101 if (fl & O_NONBLOCK) {
102 tst_brkm(TFAIL, cleanup, "eventfd2(0) sets non-blocking mode");
103 }
104 close(fd);
105
106 fd = ltp_syscall(__NR_eventfd2, 1, EFD_NONBLOCK);
107 if (fd == -1) {
108 tst_brkm(TFAIL, cleanup, "eventfd2(EFD_NONBLOCK) failed");
109 }
110 fl = fcntl(fd, F_GETFL);
111 if (fl == -1) {
112 tst_brkm(TBROK, cleanup, "fcntl failed");
113 }
114 if ((fl & O_NONBLOCK) == 0) {
115 tst_brkm(TFAIL, cleanup,
116 "eventfd2(EFD_NONBLOCK) didn't set non-blocking mode");
117 }
118 close(fd);
119 tst_resm(TPASS, "eventfd2(EFD_NONBLOCK) PASSED");
120
121 cleanup();
122 tst_exit();
123 }
124