Joren's proposed fix for a too-conservative split point selection.
[minix3.git] / test / test3.c
blob2aa2b55880ef4898d89eba9e47a0a900e6046c6d
1 /* test 3 - library routines rather than system calls */
3 #include <sys/types.h>
4 #include <sys/utsname.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <limits.h>
8 #include <signal.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <stdio.h>
14 #define ITERATIONS 10
15 #define MAX_ERROR 4
16 #define SIZE 64
18 int errct, subtest;
19 char el_weirdo[] = "\n\t\\\e@@!!##\e\e\n\n";
21 _PROTOTYPE(int main, (int argc, char *argv []));
22 _PROTOTYPE(void test3a, (void));
23 _PROTOTYPE(void test3b, (void));
24 _PROTOTYPE(void test3c, (void));
25 _PROTOTYPE(void test3d, (void));
26 _PROTOTYPE(void test3e, (void));
27 _PROTOTYPE(void quit, (void));
28 _PROTOTYPE(void e, (int n));
30 int main(argc, argv)
31 int argc;
32 char *argv[];
34 int i, m = 0xFFFF;
36 sync();
37 if (geteuid() == 0 || getuid() == 0) {
38 printf("Test 3 cannot run as root; test aborted\n");
39 exit(1);
42 if (argc == 2) m = atoi(argv[1]);
44 printf("Test 3 ");
45 fflush(stdout); /* have to flush for child's benefit */
47 system("rm -rf DIR_03; mkdir DIR_03");
48 chdir("DIR_03");
50 for (i = 0; i < ITERATIONS; i++) {
51 if (m & 0001) test3a();
52 if (m & 0002) test3b();
53 if (m & 0004) test3c();
54 if (m & 0010) test3d();
55 if (m & 0020) test3e();
57 quit();
58 return(-1); /* impossible */
62 void test3a()
64 /* Signal set manipulation. */
66 sigset_t s, s1;
68 subtest = 1;
69 errno = -1000; /* None of these calls set errno. */
70 if (sigemptyset(&s) != 0) e(1);
71 if (sigemptyset(&s1) != 0) e(2);
72 if (sigaddset(&s, SIGABRT) != 0) e(3);
73 if (sigaddset(&s, SIGALRM) != 0) e(4);
74 if (sigaddset(&s, SIGFPE ) != 0) e(5);
75 if (sigaddset(&s, SIGHUP ) != 0) e(6);
76 if (sigaddset(&s, SIGILL ) != 0) e(7);
77 if (sigaddset(&s, SIGINT ) != 0) e(8);
78 if (sigaddset(&s, SIGKILL) != 0) e(9);
79 if (sigaddset(&s, SIGPIPE) != 0) e(10);
80 if (sigaddset(&s, SIGQUIT) != 0) e(11);
81 if (sigaddset(&s, SIGSEGV) != 0) e(12);
82 if (sigaddset(&s, SIGTERM) != 0) e(13);
83 if (sigaddset(&s, SIGUSR1) != 0) e(14);
84 if (sigaddset(&s, SIGUSR2) != 0) e(15);
86 if (sigismember(&s, SIGABRT) != 1) e(16);
87 if (sigismember(&s, SIGALRM) != 1) e(17);
88 if (sigismember(&s, SIGFPE ) != 1) e(18);
89 if (sigismember(&s, SIGHUP ) != 1) e(19);
90 if (sigismember(&s, SIGILL ) != 1) e(20);
91 if (sigismember(&s, SIGINT ) != 1) e(21);
92 if (sigismember(&s, SIGKILL) != 1) e(22);
93 if (sigismember(&s, SIGPIPE) != 1) e(23);
94 if (sigismember(&s, SIGQUIT) != 1) e(24);
95 if (sigismember(&s, SIGSEGV) != 1) e(25);
96 if (sigismember(&s, SIGTERM) != 1) e(26);
97 if (sigismember(&s, SIGUSR1) != 1) e(27);
98 if (sigismember(&s, SIGUSR2) != 1) e(28);
100 if (sigdelset(&s, SIGABRT) != 0) e(29);
101 if (sigdelset(&s, SIGALRM) != 0) e(30);
102 if (sigdelset(&s, SIGFPE ) != 0) e(31);
103 if (sigdelset(&s, SIGHUP ) != 0) e(32);
104 if (sigdelset(&s, SIGILL ) != 0) e(33);
105 if (sigdelset(&s, SIGINT ) != 0) e(34);
106 if (sigdelset(&s, SIGKILL) != 0) e(35);
107 if (sigdelset(&s, SIGPIPE) != 0) e(36);
108 if (sigdelset(&s, SIGQUIT) != 0) e(37);
109 if (sigdelset(&s, SIGSEGV) != 0) e(38);
110 if (sigdelset(&s, SIGTERM) != 0) e(39);
111 if (sigdelset(&s, SIGUSR1) != 0) e(40);
112 if (sigdelset(&s, SIGUSR2) != 0) e(41);
114 if (s != s1) e(42);
116 if (sigaddset(&s, SIGILL) != 0) e(43);
117 if (s == s1) e(44);
119 if (sigfillset(&s) != 0) e(45);
120 if (sigismember(&s, SIGABRT) != 1) e(46);
121 if (sigismember(&s, SIGALRM) != 1) e(47);
122 if (sigismember(&s, SIGFPE ) != 1) e(48);
123 if (sigismember(&s, SIGHUP ) != 1) e(49);
124 if (sigismember(&s, SIGILL ) != 1) e(50);
125 if (sigismember(&s, SIGINT ) != 1) e(51);
126 if (sigismember(&s, SIGKILL) != 1) e(52);
127 if (sigismember(&s, SIGPIPE) != 1) e(53);
128 if (sigismember(&s, SIGQUIT) != 1) e(54);
129 if (sigismember(&s, SIGSEGV) != 1) e(55);
130 if (sigismember(&s, SIGTERM) != 1) e(56);
131 if (sigismember(&s, SIGUSR1) != 1) e(57);
132 if (sigismember(&s, SIGUSR2) != 1) e(58);
134 /* Test error returns. */
135 if (sigaddset(&s, -1) != -1) e(59);
136 if (sigaddset(&s, -1) != -1) e(60);
137 if (sigismember(&s, -1) != -1) e(61);
138 if (sigaddset(&s, 10000) != -1) e(62);
139 if (sigaddset(&s, 10000) != -1) e(63);
140 if (sigismember(&s, 10000) != -1) e(64);
144 void test3b()
146 /* Test uname. */
148 struct utsname u; /* contains all kinds of system ids */
150 subtest = 2;
151 #if 0
152 errno = -2000; /* None of these calls set errno. */
153 if (uname(&u) != 0) e(1);
154 if (strcmp(u.sysname, "MINIX") != 0
155 && strcmp(u.sysname, "Minix") != 0) e(2); /* only one defined */
156 #endif
159 void test3c()
161 /* Test getenv. Asume HOME, PATH, and LOGNAME exist (not strictly required).*/
163 char *p, name[SIZE];
165 subtest = 3;
166 errno = -3000; /* None of these calls set errno. */
167 if ( (p = getenv("HOME")) == NULL) e(1);
168 if (*p != '/') e(2); /* path must be absolute */
169 if ( (p = getenv("PATH")) == NULL) e(3);
170 if ( (p = getenv("LOGNAME")) == NULL) e(5);
171 strcpy(name, p); /* save it, since getlogin might wipe it out */
172 p = getlogin();
173 if (strcmp(p, name) != 0) e(6);
175 /* The following test could fail in a legal POSIX system. However, if it
176 * does, you deserve it to fail.
178 if (getenv(el_weirdo) != NULL) e(7);
181 void test3d()
183 /* Test ctermid, ttyname, and isatty. */
185 int fd;
186 char *p, name[L_ctermid];
188 subtest = 4;
189 errno = -4000; /* None of these calls set errno. */
191 /* Test ctermid first. */
192 if ( (p = ctermid(name)) == NULL) e(1);
193 if (strcmp(p, name) != 0) e(2);
194 if (strncmp(p, "/dev/tty", 8) != 0) e(3); /* MINIX convention */
196 if ( (p = ttyname(0)) == NULL) e(4);
197 if (strncmp(p, "/dev/tty", 8) != 0 && strcmp(p, "/dev/console") != 0) e(5);
198 if ( (p = ttyname(3)) != NULL) e(6);
199 if (ttyname(5000) != NULL) e(7);
200 if ( (fd = creat("T3a", 0777)) < 0) e(8);
201 if (ttyname(fd) != NULL) e(9);
203 if (isatty(0) != 1) e(10);
204 if (isatty(3) != 0) e(11);
205 if (isatty(fd) != 0) e(12);
206 if (close(fd) != 0) e(13);
207 if (ttyname(fd) != NULL) e(14);
210 void test3e()
212 /* Test ctermid, ttyname, and isatty. */
214 subtest = 5;
215 errno = -5000; /* None of these calls set errno. */
217 if (sysconf(_SC_ARG_MAX) < _POSIX_ARG_MAX) e(1);
218 if (sysconf(_SC_CHILD_MAX) < _POSIX_CHILD_MAX) e(2);
219 if (sysconf(_SC_NGROUPS_MAX) < 0) e(3);
220 if (sysconf(_SC_OPEN_MAX) < _POSIX_OPEN_MAX) e(4);
222 /* The rest are MINIX specific */
223 if (sysconf(_SC_JOB_CONTROL) >= 0) e(5); /* no job control! */
226 void quit()
228 chdir("..");
229 system("rm -rf DIR*");
231 if (errct == 0) {
232 printf("ok\n");
233 exit(0);
234 } else {
235 printf("%d errors\n", errct);
236 exit(4);
240 void e(n)
241 int n;
243 int err_num = errno; /* save errno in case printf clobbers it */
245 printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
246 errno = err_num; /* restore errno, just in case */
247 perror("");
248 if (errct++ > MAX_ERROR) {
249 printf("Test aborted. Too many errors: ");
250 chdir("..");
251 system("rm -rf DIR*");
252 exit(1);