1 /* $NetBSD: h_client.c,v 1.8 2012/04/20 05:15:11 jruoho Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
32 #include <sys/select.h>
43 main(int argc
, char *argv
[])
47 errx(1, "need testname as param");
50 if (strcmp(argv
[1], "select_timeout") == 0) {
59 if (pipe(pipefd
) == -1)
60 err(EXIT_FAILURE
, "pipe");
62 FD_SET(pipefd
[0], &rfds
);
64 rv
= select(pipefd
[0]+1, &rfds
, NULL
, NULL
, &tv
);
66 err(EXIT_FAILURE
, "select");
68 errx(EXIT_FAILURE
, "select succesful");
70 if (FD_ISSET(pipefd
[0], &rfds
))
71 errx(EXIT_FAILURE
, "stdin fileno is still set");
73 } else if (strcmp(argv
[1], "select_allunset") == 0) {
83 rv
= select(100, &fds
, &fds
, &fds
, &tv
);
85 err(EXIT_FAILURE
, "select");
87 errx(EXIT_FAILURE
, "select succesful");
89 rv
= select(0, NULL
, NULL
, NULL
, &tv
);
91 err(EXIT_FAILURE
, "select2");
93 errx(EXIT_FAILURE
, "select2 succesful");
96 } else if (strcmp(argv
[1], "invafd") == 0) {
100 fd
= open("/rump/dev/null", O_RDWR
);
102 err(EXIT_FAILURE
, "open");
105 pfd
[0].fd
= STDIN_FILENO
;
106 pfd
[0].events
= POLLIN
;
108 pfd
[1].events
= POLLIN
;
110 if ((rv
= poll(pfd
, 2, INFTIM
)) != 1)
111 errx(EXIT_FAILURE
, "poll unexpected rv %d (%d)",
113 if (pfd
[1].revents
!= POLLNVAL
|| pfd
[0].revents
!= 0)
114 errx(EXIT_FAILURE
, "poll unexpected revents");
117 } else if (strcmp(argv
[1], "fdoff8") == 0) {
124 if ((fd
= open("/dev/null", O_RDWR
)) == -1)
125 err(EXIT_FAILURE
, "open1");
127 fd
= open("/dev/null", O_RDWR
);
128 if (fd
!= -1 || errno
!= ENFILE
)
129 errx(EXIT_FAILURE
, "unexpected fd8 %d %d", fd
, errno
);
130 if (fcntl(0, F_MAXFD
) != 7)
131 errx(EXIT_FAILURE
, "fd leak?");
132 if ((fd
= open("/rump/dev/null", O_RDWR
)) != 8)
133 errx(EXIT_FAILURE
, "rump open %d %d", fd
, errno
);