source: trunk/minix/test/test6.c@ 20

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

Minix 3.1.2a

File size: 4.3 KB
Line 
1/* test 6 */
2
3#include <sys/types.h>
4#include <sys/stat.h>
5#include <errno.h>
6#include <fcntl.h>
7#include <limits.h>
8#include <signal.h>
9#include <stdlib.h>
10#include <unistd.h>
11#include <stdio.h>
12
13#define MAX_ERROR 4
14
15int errct;
16int subtest = 1;
17int zilch[5000];
18char curdir[PATH_MAX];
19
20_PROTOTYPE(int main, (int argc, char *argv []));
21_PROTOTYPE(void test6a, (void));
22_PROTOTYPE(void test6b, (void));
23_PROTOTYPE(void test6c, (void));
24_PROTOTYPE(void e, (int n));
25_PROTOTYPE(void quit, (void));
26
27int main(argc, argv)
28int argc;
29char *argv[];
30{
31 int i, m = 0xFFFF;
32
33 sync();
34 if (geteuid() == 0 || getuid() == 0) {
35 printf("Test 6 cannot run as root; test aborted\n");
36 exit(1);
37 }
38
39 if (argc == 2) m = atoi(argv[1]);
40
41 printf("Test 6 ");
42 fflush(stdout);
43
44 getcwd(curdir, PATH_MAX);
45 system("rm -rf DIR_06; mkdir DIR_06");
46 chdir("DIR_06");
47
48 for (i = 0; i < 70; i++) {
49 if (m & 00001) test6a();
50 if (m & 00002) test6b();
51 if (m & 00004) test6c();
52 }
53
54 quit();
55 return(-1); /* impossible */
56}
57
58void test6a()
59{
60/* Test sbrk() and brk(). */
61
62 char *addr, *addr2, *addr3;
63 int i, del, click, click2;
64
65 subtest = 1;
66 addr = sbrk(0);
67 addr = sbrk(0); /* force break to a click boundary */
68 for (i = 0; i < 10; i++) sbrk(7 * i);
69 for (i = 0; i < 10; i++) sbrk(-7 * i);
70 if (sbrk(0) != addr) e(1);
71 sbrk(30);
72 if (brk(addr) != 0) e(2);
73 if (sbrk(0) != addr) e(3);
74
75 del = 0;
76 do {
77 del++;
78 brk(addr + del);
79 addr2 = sbrk(0);
80 } while (addr2 == addr);
81 click = addr2 - addr;
82 sbrk(-1);
83 if (sbrk(0) != addr) e(4);
84 brk(addr);
85 if (sbrk(0) != addr) e(5);
86
87 del = 0;
88 do {
89 del++;
90 brk(addr - del);
91 addr3 = sbrk(0);
92 } while (addr3 == addr);
93 click2 = addr - addr3;
94 sbrk(1);
95 if (sbrk(0) != addr) e(6);
96 brk(addr);
97 if (sbrk(0) != addr) e(8);
98 if (click != click2) e(9);
99
100 brk(addr + 2 * click);
101 if (sbrk(0) != addr + 2 * click) e(10);
102 sbrk(3 * click);
103 if (sbrk(0) != addr + 5 * click) e(11);
104 sbrk(-5 * click);
105 if (sbrk(0) != addr) e(12);
106}
107
108void test6b()
109{
110 int i, err;
111
112 subtest = 2;
113 signal(SIGQUIT, SIG_IGN);
114 err = 0;
115 for (i = 0; i < 5000; i++)
116 if (zilch[i] != 0) err++;
117 if (err > 0) e(1);
118 kill(getpid(), SIGQUIT);
119}
120
121void test6c()
122{
123/* Test mknod, chdir, chmod, chown, access. */
124
125 int i, j;
126 struct stat s;
127
128 subtest = 3;
129 if (getuid() != 0) return;
130 for (j = 0; j < 2; j++) {
131 umask(0);
132
133 if (chdir("/") < 0) e(1);
134 if (mknod("dir", 040700, 0) < 0) e(2);
135 if (link("/", "/dir/..") < 0) e(3);
136 if (mknod("T3a", 0777, 0) < 0) e(4);
137 if (mknod("/dir/T3b", 0777, 0) < 0) e(5);
138 if (mknod("dir/T3c", 0777, 0) < 0) e(6);
139 if ((i = open("/dir/T3b", 0)) < 0) e(7);
140 if (close(i) < 0) e(8);
141 if ((i = open("dir/T3c", O_RDONLY)) < 0) e(9);
142 if (close(i) < 0) e(10);
143 if (chdir("dir") < 0) e(11);
144 if ((i = open("T3b", 0)) < 0) e(12);
145 if (close(i) < 0) e(13);
146 if ((i = open("../T3a", O_RDONLY)) < 0) e(14);
147 if (close(i) < 0) e(15);
148 if ((i = open("../dir/../dir/../dir/../dir/../dir/T3c", O_RDONLY)) < 0)
149 e(16);
150 if (close(i) < 0) e(17);
151
152 if (chmod("../dir/../dir/../dir/../dir/../T3a", 0123) < 0) e(18);
153 if (stat("../dir/../dir/../dir/../T3a", &s) < 0) e(19);
154 if ((s.st_mode & 077777) != 0123) e(20);
155 if (chmod("../dir/../dir/../T3a", 0456) < 0) e(21);
156 if (stat("../T3a", &s) < 0) e(22);
157 if ((s.st_mode & 077777) != 0456) e(23);
158 if (chown("../dir/../dir/../T3a", 20, 30) < 0) e(24);
159 if (stat("../T3a", &s) < 0) e(25);
160 if (s.st_uid != 20) e(26);
161 if (s.st_gid != 30) e(27);
162
163 if ((i = open("/T3c", O_RDONLY)) >= 0) e(28);
164 if ((i = open("/T3a", O_RDONLY)) < 0) e(29);
165 if (close(i) < 0) e(30);
166
167 if (access("/T3a", 4) < 0) e(31);
168 if (access("/dir/T3b", 4) < 0) e(32);
169 if (access("/dir/T3d", 4) >= 0) e(33);
170
171 if (unlink("T3b") < 0) e(34);
172 if (unlink("T3c") < 0) e(35);
173 if (unlink("..") < 0) e(36);
174 if (chdir("/") < 0) e(37);
175 if (unlink("dir") < 0) e(38);
176 if (unlink("/T3a") < 0) e(39);
177 }
178
179}
180
181void e(n)
182int n;
183{
184
185 int err_num = errno; /* save errno in case printf clobbers it */
186
187 printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
188 errno = err_num; /* restore errno, just in case */
189 perror("");
190 if (errct++ > MAX_ERROR) {
191 printf("Too many errors; test aborted\n");
192 chdir("..");
193 system("rm -rf DIR*");
194 exit(1);
195 }
196}
197
198void quit()
199{
200
201 chdir("..");
202 system("rm -rf DIR*");
203
204 chdir(curdir);
205 system("rm -rf DIR*");
206 if (errct == 0) {
207 printf("ok\n");
208 exit(0);
209 } else {
210 printf("%d errors\n", errct);
211 exit(1);
212 }
213}
Note: See TracBrowser for help on using the repository browser.