source: trunk/minix/test/test16.c@ 15

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

Minix 3.1.2a

File size: 6.4 KB
RevLine 
[9]1/* test 16 */
2
3#include <sys/types.h>
4#include <sys/stat.h>
5#include <errno.h>
6#include <fcntl.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <utime.h>
10#include <stdio.h>
11
12#define MAX_ERROR 4
13
14int errct, subtest, passes;
15
16_PROTOTYPE(int main, (int argc, char *argv []));
17_PROTOTYPE(void test16a, (void));
18_PROTOTYPE(void get_times, (char *name, time_t *a, time_t *c, time_t *m));
19_PROTOTYPE(void e, (int n));
20_PROTOTYPE(void quit, (void));
21
22int main(argc, argv)
23int argc;
24char *argv[];
25{
26 int i, m;
27
28 m = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
29
30 system("rm -rf DIR_16; mkdir DIR_16");
31 chdir("DIR_16");
32
33 printf("Test 16 ");
34 fflush(stdout);
35 for (i = 0; i < 4; i++) {
36 if (m & 0001) test16a();
37 passes++;
38 }
39 quit();
40 return(-1); /* impossible */
41}
42
43void test16a()
44{
45/* Test atime, ctime, and mtime. */
46
47 int fd, fd1, fd2, fd3, fd4;
48 time_t a, c, m, pa, pc, pm, xa, xc, xm, ya, yc, ym, za, zc, zm, ta, tc, tm;
49 time_t wa, wc, wm;
50 char buf[1024];
51 struct stat s;
52
53 subtest = 1;
54 if (passes > 0) return; /* takes too long to repeat this test */
55
56 if ( (fd = creat("T16.a", 0666)) < 0) e(1);
57 if (write(fd, buf, 1024) != 1024) e(2);
58 if (close(fd) < 0) e(3);
59 sleep(1); /* wait 1 sec before continuing */
60 if ( (fd = open("T16.a", O_RDONLY)) < 0) e(4);
61 if (read(fd, buf, 3) != 3) e(5);
62 if (close(fd) != 0) e(6);
63 if (stat("T16.a", &s) != 0) e(7);
64 a = s.st_atime;
65 c = s.st_ctime;
66 m = s.st_mtime;
67 if (a == 0) {
68 /* Almost certainly means we are running a V1 file system. */
69 printf(" (atime = 0. Probably V1 file system. V2 tests skipped.) ");
70 return;
71 }
72
73 /* Many system calls affect atime, ctime, and mtime. Test them. They
74 * fall into several groups. The members of each group can be tested
75 * together. Start with creat(), mkdir(), and mkfifo, all of which
76 * set all 3 times on the created object, and ctime and mtime of the dir.
77 */
78 if ( (fd = creat("T16.b", 0666)) < 0) e(8);
79 if (close(fd) != 0) e(9);
80 get_times("T16.b", &a, &c, &m);
81 get_times(".", &pa, &pc, &pm);
82 if (a != c) e(10);
83 if (a != m) e(11);
84 if (a != pc) e(12);
85 if (a != pm) e(13);
86 if (unlink("T16.b") < 0) e(14);
87
88 /* Test the times for mkfifo. */
89 if ( (fd = mkfifo("T16.c", 0666)) != 0) e(15);
90 if (access("T16.c", R_OK | W_OK) != 0) e(16);
91 get_times("T16.c", &a, &c, &m);
92 get_times(".", &pa, &pc, &pm);
93 if (a != c) e(17);
94 if (a != m) e(18);
95 if (a != pc) e(19);
96 if (a != pm) e(20);
97 if (unlink("T16.c") < 0) e(21);
98
99 /* Test the times for mkdir. */
100 if (mkdir("T16.d", 0666) < 0) e(22);
101 get_times("T16.d", &a, &c, &m);
102 get_times(".", &pa, &pc, &pm);
103 if (a != c) e(23);
104 if (a != m) e(24);
105 if (a != pc) e(25);
106 if (a != pm) e(26);
107 sleep(1);
108 if (rmdir("T16.d") < 0) e(27);
109 get_times(".", &xa, &xc, &xm);
110 if (c == xc) e(28);
111 if (m == xm) e(29);
112 if (xc != xm) e(30);
113
114 /* Test open(file, O_TRUNC). */
115 if ( (fd = open("T16.e", O_WRONLY|O_CREAT, 0666)) < 0) e(31);
116 if (write(fd, buf, 1024) != 1024) e(32);
117 if (close(fd) != 0) e(33);
118 get_times("T16.e", &a, &c, &m);
119 get_times(".", &pa, &pc, &pm);
120 sleep(1);
121 if ( (fd = open("T16.e", O_WRONLY|O_TRUNC)) < 0) e(34);
122 get_times("T16.e", &xa, &xc, &xm);
123 get_times(".", &ya, &yc, &ym);
124 if (c != m) e(35);
125 if (pc != pm) e(36);
126 if (c == xc) e(37);
127 if (m == xm) e(38);
128 if (yc != pc) e(39);
129 if (ym != pm) e(40);
130 if (close(fd) != 0) e(41);
131
132 /* Test the times for link/unlink. */
133 get_times("T16.e", &a, &c, &m);
134 get_times(".", &ya, &yc, &ym);
135 sleep(1);
136 if (link("T16.e", "T16.f") != 0) e(42); /* second link */
137 get_times("T16.e", &xa, &xc, &xm);
138 get_times(".", &pa, &pc, &pm);
139 if (a != xa) e(43);
140 if (m != xm) e(44);
141#ifndef V1_FILESYSTEM
142 if (c == xc) e(45);
143#endif
144 if (ya != pa) e(46);
145 if (yc == pc) e(47);
146 if (ym == pm) e(48);
147 if (yc != ym) e(49);
148 if (pc != pm) e(50);
149 sleep(1);
150 if (unlink("T16.f") != 0) e(46);
151 get_times("T16.e", &a, &c, &m);
152 get_times(".", &ya, &yc, &ym);
153 if (a != xa) e(51);
154 if (m != xm) e(52);
155#ifndef V1_FILESYSTEM
156 if (c == xc) e(53);
157#endif
158 if (pa != ya) e(54);
159 if (pc == yc) e(55);
160 if (pm == ym) e(56);
161 if (yc != ym) e(57);
162 if (unlink("T16.e") != 0) e(58);
163
164 /* Test rename, read, write, chmod, utime. */
165 get_times(".", &pa, &pc, &pm);
166 if ( (fd = open("T16.g", O_RDWR|O_CREAT)) < 0) e(59);
167 if ( (fd1 = open("T16.h", O_WRONLY|O_CREAT, 0666)) < 0) e(60);
168 if ( (fd2 = open("T16.i", O_WRONLY|O_CREAT, 0666)) < 0) e(61);
169 if ( (fd3 = open("T16.j", O_WRONLY|O_CREAT, 0666)) < 0) e(62);
170 if ( (fd4 = open("T16.k", O_RDWR|O_CREAT, 0666)) < 0) e(63);
171 if (write(fd, buf, 1024) != 1024) e(64);
172 get_times("T16.g", &a, &c, &m);
173 get_times("T16.h", &pa, &pc, &pm);
174 get_times("T16.i", &xa, &xc, &xm);
175 get_times("T16.j", &ya, &yc, &ym);
176 get_times("T16.k", &za, &zc, &zm);
177 get_times(".", &wa, &wc, &wm);
178 sleep(1);
179 lseek(fd, 0L, SEEK_SET);
180 if (read(fd, buf, 35) != 35) e(65);
181 get_times("T16.g", &ta, &tc, &tm);
182 if (a == ta || c != tc || m != tm) e(66);
183 if (write(fd1, buf, 35) != 35) e(67);
184 get_times("T16.h", &ta, &tc, &tm);
185 if (pa != ta || pc == tc || pm == tm) e(69);
186 if (rename("T16.i", "T16.i1") != 0) e(70);
187 get_times("T16.i1", &ta, &tc, &tm);
188 if (xa != ta || xc != tc || xm != tm) e(71);
189 get_times(".", &a, &c, &m);
190 if (a != wa || c == wc || m == wm || wc != wm) e(72);
191 if (chmod("T16.j", 0777) != 0) e(73);
192 get_times("T16.j", &ta, &tc, &tm);
193 if (ya != ta || yc == tc || ym != tm) e(74);
194 if (utime("T16.k", (void *) 0) != 0) e(75);
195 get_times("T16.k", &ta, &tc, &tm);
196 if (za == ta || zc == tc) e(76);
197 if (close(fd) != 0) e(77);
198 if (close(fd1) != 0) e(78);
199 if (close(fd2) != 0) e(79);
200 if (close(fd3) != 0) e(80);
201 if (close(fd4) != 0) e(81);
202 if (unlink("T16.g") != 0) e(82);
203 if (unlink("T16.h") != 0) e(83);
204 if (unlink("T16.i1") != 0) e(84);
205 if (unlink("T16.j") != 0) e(85);
206 if (unlink("T16.k") != 0) e(86);
207}
208
209void get_times(name, a, c, m)
210char *name;
211time_t *a, *c, *m;
212{
213 struct stat s;
214
215 if (stat(name, &s) != 0) e(500);
216 *a = s.st_atime;
217 *c = s.st_ctime;
218 *m = s.st_mtime;
219}
220
221void e(n)
222int n;
223{
224 int err_num = errno; /* save errno in case printf clobbers it */
225
226 printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
227 errno = err_num; /* restore errno, just in case */
228 perror("");
229 if (errct++ > MAX_ERROR) {
230 printf("Too many errors; test aborted\n");
231 chdir("..");
232 system("rm -rf DIR*");
233 exit(1);
234 }
235}
236
237void quit()
238{
239
240 chdir("..");
241 system("rm -rf DIR*");
242
243 if (errct == 0) {
244 printf("ok\n");
245 exit(0);
246 } else {
247 printf("%d errors\n", errct);
248 exit(1);
249 }
250}
251
Note: See TracBrowser for help on using the repository browser.