5 * Select works on regular files, (pseudo) terminal devices, streams-based
6 * files, FIFOs, pipes, and sockets. This test verifies the FD_* macros.
8 * This test is part of a bigger select test. It expects as argument which sub-
15 #include <sys/select.h>
20 # define OPEN_MAX 1024
25 int errct
= 0, subtest
= -1;
27 void e(int n
, char *s
) {
28 printf("Subtest %d, error %d, %s\n", subtest
, n
, s
);
30 if (errct
++ > MAX_ERROR
) {
31 printf("Too many errors; test aborted\n");
36 int main(int argc
, char **argv
) {
40 /* Get subtest number */
42 printf("Usage: %s subtest_no\n", argv
[0]);
44 } else if(sscanf(argv
[1], "%d", &subtest
) != 1) {
45 printf("Usage: %s subtest_no\n", argv
[0]);
51 for(i
= 0; i
< OPEN_MAX
; i
++) {
52 if(FD_ISSET(i
, &fds
)) {
53 e(1, "fd set should be completely empty");
59 for(i
= 0; i
< OPEN_MAX
; i
++) FD_SET(i
, &fds
);
60 for(i
= 0; i
< OPEN_MAX
; i
++) {
61 if(!FD_ISSET(i
, &fds
)) {
62 e(2, "fd set should be completely filled");
67 /* Reset to empty set and verify it's really empty */
69 for(i
= 0; i
< OPEN_MAX
; i
++) {
70 if(FD_ISSET(i
, &fds
)) {
71 e(3, "fd set should be completely empty");
76 /* Let's try a variation on filling the set */
77 for(i
= 0; i
< OPEN_MAX
; i
+= 2) FD_SET(i
, &fds
);
78 for(i
= 0; i
< OPEN_MAX
- 1; i
+= 2 ) {
79 if(!(FD_ISSET(i
, &fds
) && !FD_ISSET(i
+1, &fds
))) {
80 e(4, "bit pattern does not match");
85 /* Reset to empty set and verify it's really empty */
87 for(i
= 0; i
< OPEN_MAX
; i
++) {
88 if(FD_ISSET(i
, &fds
)) {
89 e(5,"fd set should be completely empty");
94 /* Let's try another variation on filling the set */
95 for(i
= 0; i
< OPEN_MAX
- 1; i
+= 2) FD_SET(i
+1, &fds
);
96 for(i
= 0; i
< OPEN_MAX
- 1; i
+= 2 ) {
97 if(!(FD_ISSET(i
+1, &fds
) && !FD_ISSET(i
, &fds
))) {
98 e(6, "bit pattern does not match");
103 /* Reset to empty set and verify it's really empty */
105 for(i
= 0; i
< OPEN_MAX
; i
++) {
106 if(FD_ISSET(i
, &fds
)) {
107 e(7, "fd set should be completely empty");
113 for(i
= 0; i
< OPEN_MAX
; i
++) FD_SET(i
, &fds
); /* Set all bits */
114 for(i
= 0; i
< OPEN_MAX
; i
++) FD_CLR(i
, &fds
); /* Clear all bits */
115 for(i
= 0; i
< OPEN_MAX
; i
++) {
116 if(FD_ISSET(i
, &fds
)) {
117 e(8, "all bits in fd set should be cleared");
122 /* Reset to empty set and verify it's really empty */
124 for(i
= 0; i
< OPEN_MAX
; i
++) {
125 if(FD_ISSET(i
, &fds
)) {
126 e(9, "fd set should be completely empty");
131 for(i
= 0; i
< OPEN_MAX
; i
++) FD_SET(i
, &fds
); /* Set all bits */
132 for(i
= 0; i
< OPEN_MAX
; i
+= 2) FD_CLR(i
, &fds
); /* Clear all bits */
133 for(i
= 0; i
< OPEN_MAX
; i
+= 2) {
134 if(FD_ISSET(i
, &fds
)) {
135 e(10, "all even bits in fd set should be cleared");