annotate tests/test-poll.c @ 30157:27e770162c3f

add sockets wrappers 2008-09-23 Paolo Bonzini <bonzini@gnu.org> * lib/sys_socket.in.h: Do not implement rpl_setsockopt here, instead define prototypes for a full set of wrappers. Ensure that Cygwin does not use the compatibility code, which is only for MinGW. * lib/winsock.c: New. * m4/sys_socket_h.m4: Compile lib/winsock.c if WinSock is being used. * modules/sys_socket: Add lib/winsock.c. * modules/poll-tests: Add errno and perror. * tests/test-poll.c: Use ioctl, not ioctlsocket.
author Paolo Bonzini <bonzini@gnu.org>
date Fri, 12 Sep 2008 08:43:03 +0200
parents c47a6f165a9a
children ebbb50a36a9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
1 /* Test of poll() function.
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
2 Copyright (C) 2008 Free Software Foundation, Inc.
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
3
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3, or (at your option)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
7 any later version.
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
8
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
12 GNU General Public License for more details.
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
13
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
17
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
18 /* Written by Paolo Bonzini. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
19
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
20 #include <config.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
21
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
22 #include <stdio.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
23 #include <string.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
24 #include <sys/socket.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
25 #include <netinet/in.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
26 #include <arpa/inet.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
27 #include <poll.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
28 #include <fcntl.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
29 #include <stdlib.h>
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
30 #include <stdbool.h>
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
31 #include <errno.h>
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
32 #include "sockets.h"
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
33
30115
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
34 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
35 # define WIN32_NATIVE
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
36 #endif
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
37
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
38 #ifdef WIN32_NATIVE
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
39 #include <io.h>
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
40 #define pipe(x) _pipe(x, 256, O_BINARY)
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
41 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
42 #ifdef HAVE_UNISTD_H
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
43 #include <unistd.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
44 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
45 #ifdef HAVE_SYS_WAIT_H
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
46 #include <sys/wait.h>
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
47 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
48
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
49 #ifndef SO_REUSEPORT
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
50 #define SO_REUSEPORT SO_REUSEADDR
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
51 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
52
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
53 #define TEST_PORT 12345
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
54
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
55
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
56 /* Minimal testing infrastructure. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
57
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
58 static int failures;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
59
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
60 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
61 failed (const char *reason)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
62 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
63 if (++failures > 1)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
64 printf (" ");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
65 printf ("failed (%s)\n", reason);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
66 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
67
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
68 static int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
69 test (void (*fn) (void), const char *msg)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
70 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
71 failures = 0;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
72 printf ("%s... ", msg);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
73 fflush (stdout);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
74 fn ();
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
75
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
76 if (!failures)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
77 printf ("passed\n");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
78
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
79 return failures;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
80 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
81
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
82
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
83 /* Funny socket code. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
84
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
85 static int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
86 open_server_socket ()
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
87 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
88 int s, x;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
89 struct sockaddr_in ia;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
90
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
91 s = socket (AF_INET, SOCK_STREAM, 0);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
92
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
93 memset (&ia, 0, sizeof (ia));
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
94 ia.sin_family = AF_INET;
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
95 inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
96 ia.sin_port = htons (TEST_PORT);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
97 if (bind (s, (struct sockaddr *) &ia, sizeof (ia)) < 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
98 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
99 perror ("bind");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
100 exit (77);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
101 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
102
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
103 x = 1;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
104 setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
105
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
106 if (listen (s, 1) < 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
107 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
108 perror ("listen");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
109 exit (77);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
110 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
111
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
112 return s;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
113 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
114
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
115 static int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
116 connect_to_socket (int blocking)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
117 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
118 int s;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
119 struct sockaddr_in ia;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
120
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
121 s = socket (AF_INET, SOCK_STREAM, 0);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
122
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
123 memset (&ia, 0, sizeof (ia));
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
124 ia.sin_family = AF_INET;
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
125 inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
126 ia.sin_port = htons (TEST_PORT);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
127
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
128 if (!blocking)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
129 {
30115
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
130 #ifdef WIN32_NATIVE
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
131 unsigned long iMode = 1;
30157
27e770162c3f add sockets wrappers
Paolo Bonzini <bonzini@gnu.org>
parents: 30156
diff changeset
132 ioctl (s, FIONBIO, (char *) &iMode);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
133
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
134 #elif defined F_GETFL
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
135 int oldflags = fcntl (s, F_GETFL, NULL);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
136
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
137 if (!(oldflags & O_NONBLOCK))
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
138 fcntl (s, F_SETFL, oldflags | O_NONBLOCK);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
139 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
140 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
141
30136
344142aabdce allow non-blocking connect to succeed, as it does on OpenBSD
Paolo Bonzini <bonzini@gnu.org>
parents: 30115
diff changeset
142 if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0
344142aabdce allow non-blocking connect to succeed, as it does on OpenBSD
Paolo Bonzini <bonzini@gnu.org>
parents: 30115
diff changeset
143 && (blocking || errno != EINPROGRESS))
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
144 {
30136
344142aabdce allow non-blocking connect to succeed, as it does on OpenBSD
Paolo Bonzini <bonzini@gnu.org>
parents: 30115
diff changeset
145 perror ("connect");
344142aabdce allow non-blocking connect to succeed, as it does on OpenBSD
Paolo Bonzini <bonzini@gnu.org>
parents: 30115
diff changeset
146 exit (77);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
147 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
148
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
149 return s;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
150 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
151
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
152
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
153 /* A slightly more convenient interface to poll(2). */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
154
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
155 static int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
156 poll1 (int fd, int ev, int time)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
157 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
158 struct pollfd pfd;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
159 int r;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
160
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
161 pfd.fd = fd;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
162 pfd.events = ev;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
163 pfd.revents = 0;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
164 r = poll (&pfd, 1, time);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
165 if (r < 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
166 return r;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
167
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
168 if (pfd.revents & ~(POLLHUP | POLLERR | POLLNVAL | ev))
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
169 failed ("invalid flag combination (unrequested events)");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
170
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
171 return pfd.revents;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
172 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
173
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
174 static int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
175 poll1_nowait (int fd, int ev)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
176 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
177 return poll1 (fd, ev, 0);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
178 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
179
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
180 static int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
181 poll1_wait (int fd, int ev)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
182 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
183 return poll1 (fd, ev, -1);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
184 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
185
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
186
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
187 /* Test poll(2) for TTYs. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
188
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
189 #ifdef INTERACTIVE
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
190 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
191 test_tty (void)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
192 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
193 if (poll1_nowait (0, POLLIN | POLLRDNORM) != 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
194 failed ("can read");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
195 if (poll1_nowait (0, POLLOUT) == 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
196 failed ("cannot write");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
197
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
198 if (poll1_wait (0, POLLIN | POLLRDNORM) == 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
199 failed ("return with infinite timeout");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
200
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
201 getchar ();
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
202 if (poll1_nowait (0, POLLIN | POLLRDNORM) != 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
203 failed ("can read after getc");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
204 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
205 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
206
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
207
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
208 /* Test poll(2) for unconnected nonblocking sockets. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
209
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
210 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
211 test_connect_first (void)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
212 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
213 int s = open_server_socket ();
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
214 struct sockaddr_in ia;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
215 socklen_t addrlen;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
216
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
217 int c1, c2;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
218
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
219 if (poll1_nowait (s, POLLIN | POLLRDNORM | POLLRDBAND) != 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
220 failed ("can read, socket not connected");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
221
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
222 c1 = connect_to_socket (false);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
223
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
224 if (poll1_wait (s, POLLIN | POLLRDNORM | POLLRDBAND) != (POLLIN | POLLRDNORM))
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
225 failed ("expecting POLLIN | POLLRDNORM on passive socket");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
226 if (poll1_nowait (s, POLLIN | POLLRDBAND) != POLLIN)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
227 failed ("expecting POLLIN on passive socket");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
228 if (poll1_nowait (s, POLLRDNORM | POLLRDBAND) != POLLRDNORM)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
229 failed ("expecting POLLRDNORM on passive socket");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
230
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
231 addrlen = sizeof (ia);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
232 c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
233 close (s);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
234 close (c1);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
235 close (c2);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
236 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
237
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
238
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
239 /* Test poll(2) for unconnected blocking sockets. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
240
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
241 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
242 test_accept_first (void)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
243 {
30115
182fde192679 Change the test for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 30112
diff changeset
244 #ifndef WIN32_NATIVE
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
245 int s = open_server_socket ();
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
246 struct sockaddr_in ia;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
247 socklen_t addrlen;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
248 char buf[3];
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
249 int c, pid;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
250
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
251 pid = fork ();
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
252 if (pid < 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
253 return;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
254
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
255 if (pid == 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
256 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
257 addrlen = sizeof (ia);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
258 c = accept (s, (struct sockaddr *) &ia, &addrlen);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
259 close (s);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
260 write (c, "foo", 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
261 read (c, buf, 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
262 shutdown (c, SHUT_RD);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
263 close (c);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
264 exit (0);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
265 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
266 else
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
267 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
268 close (s);
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
269 c = connect_to_socket (true);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
270 if (poll1_nowait (c, POLLOUT | POLLWRNORM | POLLRDBAND)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
271 != (POLLOUT | POLLWRNORM))
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
272 failed ("cannot write after blocking connect");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
273 write (c, "foo", 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
274 wait (&pid);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
275 if (poll1_wait (c, POLLIN) != POLLIN)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
276 failed ("cannot read data left in the socket by closed process");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
277 read (c, buf, 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
278 write (c, "foo", 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
279 if ((poll1_wait (c, POLLIN | POLLOUT) & (POLLHUP | POLLERR)) == 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
280 failed ("expecting POLLHUP after shutdown");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
281 close (c);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
282 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
283 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
284 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
285
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
286
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
287 /* Common code for pipes and connected sockets. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
288
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
289 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
290 test_pair (int rd, int wd)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
291 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
292 char buf[3];
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
293 if (poll1_wait (wd, POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
294 != (POLLOUT | POLLWRNORM))
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
295 failed ("expecting POLLOUT | POLLWRNORM before writing");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
296 if (poll1_nowait (wd, POLLIN | POLLRDNORM | POLLOUT | POLLRDBAND) != POLLOUT)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
297 failed ("expecting POLLOUT before writing");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
298 if (poll1_nowait (wd, POLLIN | POLLRDNORM | POLLWRNORM | POLLRDBAND)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
299 != POLLWRNORM)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
300 failed ("expecting POLLWRNORM before writing");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
301
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
302 write (wd, "foo", 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
303 if (poll1_wait (rd, POLLIN | POLLRDNORM) != (POLLIN | POLLRDNORM))
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
304 failed ("expecting POLLIN | POLLRDNORM after writing");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
305 if (poll1_nowait (rd, POLLIN) != POLLIN)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
306 failed ("expecting POLLIN after writing");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
307 if (poll1_nowait (rd, POLLRDNORM) != POLLRDNORM)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
308 failed ("expecting POLLRDNORM after writing");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
309
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
310 read (rd, buf, 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
311 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
312
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
313
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
314 /* Test poll(2) on connected sockets. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
315
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
316 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
317 test_socket_pair (void)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
318 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
319 struct sockaddr_in ia;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
320
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
321 socklen_t addrlen = sizeof (ia);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
322 int s = open_server_socket ();
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
323 int c1 = connect_to_socket (false);
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
324 int c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
325
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
326 close (s);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
327
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
328 test_pair (c1, c2);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
329 close (c1);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
330 write (c2, "foo", 3);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
331 if ((poll1_nowait (c2, POLLIN | POLLOUT) & (POLLHUP | POLLERR)) == 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
332 failed ("expecting POLLHUP after shutdown");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
333
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
334 close (c2);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
335 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
336
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
337
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
338 /* Test poll(2) on pipes. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
339
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
340 static void
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
341 test_pipe (void)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
342 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
343 int fd[2];
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
344
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
345 pipe (fd);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
346 test_pair (fd[0], fd[1]);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
347 close (fd[0]);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
348 if ((poll1_wait (fd[1], POLLIN | POLLOUT) & (POLLHUP | POLLERR)) == 0)
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
349 failed ("expecting POLLHUP after shutdown");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
350
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
351 close (fd[1]);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
352 }
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
353
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
354
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
355 /* Do them all. */
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
356
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
357 int
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
358 main ()
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
359 {
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
360 int result;
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
361
30156
c47a6f165a9a downgrade minimum needed Winsock version for test-poll.c
Paolo Bonzini <bonzini@gnu.org>
parents: 30136
diff changeset
362 gl_sockets_startup (SOCKETS_1_1);
30111
e65b7d186878 port poll tests to Windows
Paolo Bonzini <bonzini@gnu.org>
parents: 30110
diff changeset
363
30110
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
364 #ifdef INTERACTIVE
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
365 printf ("Please press Enter\n");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
366 test (test_tty, "TTY");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
367 #endif
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
368
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
369 result = test (test_connect_first, "Unconnected socket test");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
370 result += test (test_socket_pair, "Connected sockets test");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
371 result += test (test_accept_first, "General socket test with fork");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
372 result += test (test_pipe, "Pipe test");
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
373
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
374 exit (result);
56b93720bc7f add a minimal testsuite for the poll module
Paolo Bonzini <bonzini@gnu.org>
parents:
diff changeset
375 }