unstack, sort: cleanup and improvement
[minix.git] / test / test3.c
blob311de9c452b16a1f4a21454012c3d877dc58d28d
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 3
16 #define SIZE 64
18 int subtest;
19 char el_weirdo[] = "\n\t\\\e@@!!##\e\e\n\n";
21 #include "common.c"
23 int main(int argc, char *argv []);
24 void test3a(void);
25 void test3c(void);
26 void test3d(void);
27 void test3e(void);
28 void e(int n);
30 int main(argc, argv)
31 int argc;
32 char *argv[];
34 int i, m = 0xFFFF;
36 start(3);
37 if (argc == 2) m = atoi(argv[1]);
39 for (i = 0; i < ITERATIONS; i++) {
40 if (m & 0001) test3a();
41 if (m & 0004) test3c();
42 if (m & 0010) test3d();
43 if (m & 0020) test3e();
45 quit();
46 return(-1); /* impossible */
50 void test3a()
52 /* Signal set manipulation. */
54 sigset_t s, s1;
56 subtest = 1;
57 errno = -1000; /* None of these calls set errno. */
58 if (sigemptyset(&s) != 0) e(1);
59 if (sigemptyset(&s1) != 0) e(2);
60 if (sigaddset(&s, SIGABRT) != 0) e(3);
61 if (sigaddset(&s, SIGALRM) != 0) e(4);
62 if (sigaddset(&s, SIGFPE ) != 0) e(5);
63 if (sigaddset(&s, SIGHUP ) != 0) e(6);
64 if (sigaddset(&s, SIGILL ) != 0) e(7);
65 if (sigaddset(&s, SIGINT ) != 0) e(8);
66 if (sigaddset(&s, SIGKILL) != 0) e(9);
67 if (sigaddset(&s, SIGPIPE) != 0) e(10);
68 if (sigaddset(&s, SIGQUIT) != 0) e(11);
69 if (sigaddset(&s, SIGSEGV) != 0) e(12);
70 if (sigaddset(&s, SIGTERM) != 0) e(13);
71 if (sigaddset(&s, SIGUSR1) != 0) e(14);
72 if (sigaddset(&s, SIGUSR2) != 0) e(15);
74 if (sigismember(&s, SIGABRT) != 1) e(16);
75 if (sigismember(&s, SIGALRM) != 1) e(17);
76 if (sigismember(&s, SIGFPE ) != 1) e(18);
77 if (sigismember(&s, SIGHUP ) != 1) e(19);
78 if (sigismember(&s, SIGILL ) != 1) e(20);
79 if (sigismember(&s, SIGINT ) != 1) e(21);
80 if (sigismember(&s, SIGKILL) != 1) e(22);
81 if (sigismember(&s, SIGPIPE) != 1) e(23);
82 if (sigismember(&s, SIGQUIT) != 1) e(24);
83 if (sigismember(&s, SIGSEGV) != 1) e(25);
84 if (sigismember(&s, SIGTERM) != 1) e(26);
85 if (sigismember(&s, SIGUSR1) != 1) e(27);
86 if (sigismember(&s, SIGUSR2) != 1) e(28);
88 if (sigdelset(&s, SIGABRT) != 0) e(29);
89 if (sigdelset(&s, SIGALRM) != 0) e(30);
90 if (sigdelset(&s, SIGFPE ) != 0) e(31);
91 if (sigdelset(&s, SIGHUP ) != 0) e(32);
92 if (sigdelset(&s, SIGILL ) != 0) e(33);
93 if (sigdelset(&s, SIGINT ) != 0) e(34);
94 if (sigdelset(&s, SIGKILL) != 0) e(35);
95 if (sigdelset(&s, SIGPIPE) != 0) e(36);
96 if (sigdelset(&s, SIGQUIT) != 0) e(37);
97 if (sigdelset(&s, SIGSEGV) != 0) e(38);
98 if (sigdelset(&s, SIGTERM) != 0) e(39);
99 if (sigdelset(&s, SIGUSR1) != 0) e(40);
100 if (sigdelset(&s, SIGUSR2) != 0) e(41);
102 if (s != s1) e(42);
104 if (sigaddset(&s, SIGILL) != 0) e(43);
105 if (s == s1) e(44);
107 if (sigfillset(&s) != 0) e(45);
108 if (sigismember(&s, SIGABRT) != 1) e(46);
109 if (sigismember(&s, SIGALRM) != 1) e(47);
110 if (sigismember(&s, SIGFPE ) != 1) e(48);
111 if (sigismember(&s, SIGHUP ) != 1) e(49);
112 if (sigismember(&s, SIGILL ) != 1) e(50);
113 if (sigismember(&s, SIGINT ) != 1) e(51);
114 if (sigismember(&s, SIGKILL) != 1) e(52);
115 if (sigismember(&s, SIGPIPE) != 1) e(53);
116 if (sigismember(&s, SIGQUIT) != 1) e(54);
117 if (sigismember(&s, SIGSEGV) != 1) e(55);
118 if (sigismember(&s, SIGTERM) != 1) e(56);
119 if (sigismember(&s, SIGUSR1) != 1) e(57);
120 if (sigismember(&s, SIGUSR2) != 1) e(58);
122 /* Test error returns. */
123 if (sigaddset(&s, -1) != -1) e(59);
124 if (sigaddset(&s, -1) != -1) e(60);
125 if (sigismember(&s, -1) != -1) e(61);
126 if (sigaddset(&s, 10000) != -1) e(62);
127 if (sigaddset(&s, 10000) != -1) e(63);
128 if (sigismember(&s, 10000) != -1) e(64);
132 void test3c()
134 /* Test getenv. Asume HOME, PATH, and LOGNAME exist (not strictly required).*/
136 char *p, name[SIZE];
138 subtest = 3;
139 errno = -3000; /* None of these calls set errno. */
140 if ( (p = getenv("HOME")) == NULL) { fprintf(stderr, "Please have $HOME set properly.\n"); e(1); }
141 if (*p != '/') { fprintf(stderr, "Please have $HOME point to an abolute path.\n"); e(2); } /* path must be absolute */
142 if ( (p = getenv("PATH")) == NULL) { fprintf(stderr, "Please have $PATH set properly.\n"); e(3); }
143 if ( (p = getenv("LOGNAME")) == NULL) { fprintf(stderr, "Please have $LOGNAME set properly.\n"); e(5); }
144 strcpy(name, p); /* save it, since getlogin might wipe it out */
145 p = getlogin();
146 if (strcmp(p, name) != 0) { fprintf(stderr, "Please have $LOGNAME set to your real username. (su - instead of su?)\n"); e(6); }
148 /* The following test could fail in a legal POSIX system. However, if it
149 * does, you deserve it to fail.
151 if (getenv(el_weirdo) != NULL) e(7);
154 void test3d()
156 /* Test ctermid, ttyname, and isatty. */
158 int fd;
159 char *p, name[L_ctermid];
161 subtest = 4;
162 errno = -4000; /* None of these calls set errno. */
164 /* Test ctermid first. */
165 if ( (p = ctermid(name)) == NULL) e(1);
166 if (strcmp(p, name) != 0) e(2);
167 if (strncmp(p, "/dev/tty", 8) != 0) e(3); /* MINIX convention */
169 if ( (p = ttyname(0)) == NULL) e(4);
170 if (strncmp(p, "/dev/tty", 8) != 0 && strcmp(p, "/dev/console") != 0) e(5);
171 if ( (p = ttyname(3)) != NULL) e(6);
172 if (ttyname(5000) != NULL) e(7);
173 if ( (fd = creat("T3a", 0777)) < 0) e(8);
174 if (ttyname(fd) != NULL) e(9);
176 if (isatty(0) != 1) e(10);
177 if (isatty(3) != 0) e(11);
178 if (isatty(fd) != 0) e(12);
179 if (close(fd) != 0) e(13);
180 if (ttyname(fd) != NULL) e(14);
183 void test3e()
185 /* Test ctermid, ttyname, and isatty. */
187 subtest = 5;
188 errno = -5000; /* None of these calls set errno. */
190 if (sysconf(_SC_ARG_MAX) < _POSIX_ARG_MAX) e(1);
191 if (sysconf(_SC_CHILD_MAX) < _POSIX_CHILD_MAX) e(2);
192 if (sysconf(_SC_NGROUPS_MAX) < 0) e(3);
193 if (sysconf(_SC_OPEN_MAX) < _POSIX_OPEN_MAX) e(4);
195 /* The rest are MINIX specific */
196 if (sysconf(_SC_JOB_CONTROL) >= 0) e(5); /* no job control! */