1 /* test 3 - library routines rather than system calls */
4 #include <sys/utsname.h>
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
));
37 if (geteuid() == 0 || getuid() == 0) {
38 printf("Test 3 cannot run as root; test aborted\n");
42 if (argc
== 2) m
= atoi(argv
[1]);
45 fflush(stdout
); /* have to flush for child's benefit */
47 system("rm -rf DIR_03; mkdir 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();
58 return(-1); /* impossible */
64 /* Signal set manipulation. */
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);
116 if (sigaddset(&s
, SIGILL
) != 0) e(43);
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);
148 struct utsname u
; /* contains all kinds of system ids */
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 */
161 /* Test getenv. Asume HOME, PATH, and LOGNAME exist (not strictly required).*/
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 */
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);
183 /* Test ctermid, ttyname, and isatty. */
186 char *p
, name
[L_ctermid
];
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);
212 /* Test ctermid, ttyname, and isatty. */
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! */
229 system("rm -rf DIR*");
235 printf("%d errors\n", errct
);
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 */
248 if (errct
++ > MAX_ERROR
) {
249 printf("Test aborted. Too many errors: ");
251 system("rm -rf DIR*");