use oxpcie only if enabled to avoid baud bottleneck of uart.
[minix.git] / test / t40a.c
blob8dcbc7befaa4acb880617560219f44ebc5c6cc6b
1 /* t40a.c
3 * Test FD_* macros
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-
9 * test it is.
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <sys/select.h>
16 #include <errno.h>
17 #include <limits.h>
19 #ifndef OPEN_MAX
20 # define OPEN_MAX 1024
21 #endif
23 #define MAX_ERROR 5
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");
32 exit(errct);
36 int main(int argc, char **argv) {
37 fd_set fds;
38 int i;
40 /* Get subtest number */
41 if(argc != 2) {
42 printf("Usage: %s subtest_no\n", argv[0]);
43 exit(-1);
44 } else if(sscanf(argv[1], "%d", &subtest) != 1) {
45 printf("Usage: %s subtest_no\n", argv[0]);
46 exit(-1);
49 /* FD_ZERO */
50 FD_ZERO(&fds);
51 for(i = 0; i < OPEN_MAX; i++) {
52 if(FD_ISSET(i, &fds)) {
53 e(1, "fd set should be completely empty");
54 break;
58 /* FD_SET */
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");
63 break;
67 /* Reset to empty set and verify it's really empty */
68 FD_ZERO(&fds);
69 for(i = 0; i < OPEN_MAX; i++) {
70 if(FD_ISSET(i, &fds)) {
71 e(3, "fd set should be completely empty");
72 break;
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");
81 break;
85 /* Reset to empty set and verify it's really empty */
86 FD_ZERO(&fds);
87 for(i = 0; i < OPEN_MAX; i++) {
88 if(FD_ISSET(i, &fds)) {
89 e(5,"fd set should be completely empty");
90 break;
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");
99 break;
103 /* Reset to empty set and verify it's really empty */
104 FD_ZERO(&fds);
105 for(i = 0; i < OPEN_MAX; i++) {
106 if(FD_ISSET(i, &fds)) {
107 e(7, "fd set should be completely empty");
108 break;
112 /* FD_CLR */
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");
118 break;
122 /* Reset to empty set and verify it's really empty */
123 FD_ZERO(&fds);
124 for(i = 0; i < OPEN_MAX; i++) {
125 if(FD_ISSET(i, &fds)) {
126 e(9, "fd set should be completely empty");
127 break;
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");
136 break;
140 exit(errct);