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
27 int main(int argc
, char **argv
) {
31 /* Get subtest number */
33 printf("Usage: %s subtest_no\n", argv
[0]);
35 } else if(sscanf(argv
[1], "%d", &subtest
) != 1) {
36 printf("Usage: %s subtest_no\n", argv
[0]);
42 for(i
= 0; i
< OPEN_MAX
; i
++) {
43 if(FD_ISSET(i
, &fds
)) {
44 em(1, "fd set should be completely empty");
50 for(i
= 0; i
< OPEN_MAX
; i
++) FD_SET(i
, &fds
);
51 for(i
= 0; i
< OPEN_MAX
; i
++) {
52 if(!FD_ISSET(i
, &fds
)) {
53 em(2, "fd set should be completely filled");
58 /* Reset to empty set and verify it's really empty */
60 for(i
= 0; i
< OPEN_MAX
; i
++) {
61 if(FD_ISSET(i
, &fds
)) {
62 em(3, "fd set should be completely empty");
67 /* Let's try a variation on filling the set */
68 for(i
= 0; i
< OPEN_MAX
; i
+= 2) FD_SET(i
, &fds
);
69 for(i
= 0; i
< OPEN_MAX
- 1; i
+= 2 ) {
70 if(!(FD_ISSET(i
, &fds
) && !FD_ISSET(i
+1, &fds
))) {
71 em(4, "bit pattern does not match");
76 /* Reset to empty set and verify it's really empty */
78 for(i
= 0; i
< OPEN_MAX
; i
++) {
79 if(FD_ISSET(i
, &fds
)) {
80 em(5,"fd set should be completely empty");
85 /* Let's try another variation on filling the set */
86 for(i
= 0; i
< OPEN_MAX
- 1; i
+= 2) FD_SET(i
+1, &fds
);
87 for(i
= 0; i
< OPEN_MAX
- 1; i
+= 2 ) {
88 if(!(FD_ISSET(i
+1, &fds
) && !FD_ISSET(i
, &fds
))) {
89 em(6, "bit pattern does not match");
94 /* Reset to empty set and verify it's really empty */
96 for(i
= 0; i
< OPEN_MAX
; i
++) {
97 if(FD_ISSET(i
, &fds
)) {
98 em(7, "fd set should be completely empty");
104 for(i
= 0; i
< OPEN_MAX
; i
++) FD_SET(i
, &fds
); /* Set all bits */
105 for(i
= 0; i
< OPEN_MAX
; i
++) FD_CLR(i
, &fds
); /* Clear all bits */
106 for(i
= 0; i
< OPEN_MAX
; i
++) {
107 if(FD_ISSET(i
, &fds
)) {
108 em(8, "all bits in fd set should be cleared");
113 /* Reset to empty set and verify it's really empty */
115 for(i
= 0; i
< OPEN_MAX
; i
++) {
116 if(FD_ISSET(i
, &fds
)) {
117 em(9, "fd set should be completely empty");
122 for(i
= 0; i
< OPEN_MAX
; i
++) FD_SET(i
, &fds
); /* Set all bits */
123 for(i
= 0; i
< OPEN_MAX
; i
+= 2) FD_CLR(i
, &fds
); /* Clear all bits */
124 for(i
= 0; i
< OPEN_MAX
; i
+= 2) {
125 if(FD_ISSET(i
, &fds
)) {
126 em(10, "all even bits in fd set should be cleared");