source: trunk/minix/test/test3.c@ 22

Last change on this file since 22 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 6.6 KB
Line 
1/* test 3 - library routines rather than system calls */
2
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>
13
14#define ITERATIONS 10
15#define MAX_ERROR 4
16#define SIZE 64
17
18int errct, subtest;
19char el_weirdo[] = "\n\t\\\e@@!!##\e\e\n\n";
20
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));
29
30int main(argc, argv)
31int argc;
32char *argv[];
33{
34 int i, m = 0xFFFF;
35
36 sync();
37 if (geteuid() == 0 || getuid() == 0) {
38 printf("Test 3 cannot run as root; test aborted\n");
39 exit(1);
40 }
41
42 if (argc == 2) m = atoi(argv[1]);
43
44 printf("Test 3 ");
45 fflush(stdout); /* have to flush for child's benefit */
46
47 system("rm -rf DIR_03; mkdir DIR_03");
48 chdir("DIR_03");
49
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();
56 }
57 quit();
58 return(-1); /* impossible */
59
60}
61
62void test3a()
63{
64/* Signal set manipulation. */
65
66 sigset_t s, s1;
67
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);
85
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);
99
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);
113
114 if (s != s1) e(42);
115
116 if (sigaddset(&s, SIGILL) != 0) e(43);
117 if (s == s1) e(44);
118
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);
133
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);
141
142}
143
144void test3b()
145{
146/* Test uname. */
147
148 struct utsname u; /* contains all kinds of system ids */
149
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
157}
158
159void test3c()
160{
161/* Test getenv. Asume HOME, PATH, and LOGNAME exist (not strictly required).*/
162
163 char *p, name[SIZE];
164
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);
174
175 /* The following test could fail in a legal POSIX system. However, if it
176 * does, you deserve it to fail.
177 */
178 if (getenv(el_weirdo) != NULL) e(7);
179}
180
181void test3d()
182{
183/* Test ctermid, ttyname, and isatty. */
184
185 int fd;
186 char *p, name[L_ctermid];
187
188 subtest = 4;
189 errno = -4000; /* None of these calls set errno. */
190
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 */
195
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);
202
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);
208}
209
210void test3e()
211{
212/* Test ctermid, ttyname, and isatty. */
213
214 subtest = 5;
215 errno = -5000; /* None of these calls set errno. */
216
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);
221
222 /* The rest are MINIX specific */
223 if (sysconf(_SC_JOB_CONTROL) >= 0) e(5); /* no job control! */
224}
225
226void quit()
227{
228 chdir("..");
229 system("rm -rf DIR*");
230
231 if (errct == 0) {
232 printf("ok\n");
233 exit(0);
234 } else {
235 printf("%d errors\n", errct);
236 exit(4);
237 }
238}
239
240void e(n)
241int n;
242{
243 int err_num = errno; /* save errno in case printf clobbers it */
244
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);
253 }
254}
Note: See TracBrowser for help on using the repository browser.