20 int main(int argc
, char *argv
[]);
21 void test16init(void);
30 void get_times(char *name
, time_t *a
, time_t *c
, time_t *m
);
40 m
= (argc
== 2 ? atoi(argv
[1]) : 0xFFFF);
43 for (i
= 0; i
< 4; i
++) {
45 if (m
& 0001) test16a();
46 if (m
& 0002) test16b();
47 if (m
& 0004) test16c();
48 if (m
& 0010) test16d();
49 if (m
& 0020) test16e();
50 if (m
& 0040) test16f();
51 if (m
& 0100) test16g();
52 if (m
& 0200) test16h();
56 return(-1); /* impossible */
61 /* Test atime, ctime, and mtime. */
68 if (passes
> 0) return; /* takes too long to repeat this test */
69 if (V1filesystem
) return; /* no need to spend time testing lacking features */
71 if ( (fd
= creat("T16.a", 0666)) < 0) e(1);
72 if (write(fd
, buf
, 1024) != 1024) e(2);
73 if (close(fd
) < 0) e(3);
74 sleep(1); /* wait 1 sec before continuing */
75 if ( (fd
= open("T16.a", O_RDONLY
)) < 0) e(4);
76 if (read(fd
, buf
, 3) != 3) e(5);
77 if (close(fd
) != 0) e(6);
78 if (stat("T16.a", &s
) != 0) e(7);
79 if (s
.st_atime
== 0) {
80 /* Almost certainly means we are running a V1 file system. */
81 printf(" (atime = 0. Probably V1 file system. V2+ tests skipped.) ");
86 /* Many system calls affect atime, ctime, and mtime. Test them. They
87 * fall into several groups. The members of each group can be tested
88 * together. Start with creat(), mkdir(), and mkfifo, all of which
89 * set all 3 times on the created object, and ctime and mtime of the dir.
97 time_t a
, c
, m
, pa
, pc
, pm
;
100 if (passes
> 0) return; /* takes too long to repeat this test */
101 if (V1filesystem
) return; /* no need to spend time testing lacking features */
103 if ( (fd
= creat("T16.b", 0666)) < 0) e(8);
104 if (close(fd
) != 0) e(9);
105 get_times("T16.b", &a
, &c
, &m
);
106 get_times(".", &pa
, &pc
, &pm
);
111 if (unlink("T16.b") < 0) e(14);
116 /* Test the times for mkfifo. */
118 time_t a
, c
, m
, pa
, pc
, pm
;
121 if (passes
> 0) return; /* takes too long to repeat this test */
122 if (V1filesystem
) return; /* no need to spend time testing lacking features */
124 if ( (fd
= mkfifo("T16.c", 0666)) != 0) e(15);
125 if (access("T16.c", R_OK
| W_OK
) != 0) e(16);
126 get_times("T16.c", &a
, &c
, &m
);
127 get_times(".", &pa
, &pc
, &pm
);
132 if (unlink("T16.c") < 0) e(21);
137 /* Test the times for mkdir. */
138 time_t a
, c
, m
, pa
, pc
, pm
, xa
, xc
, xm
;
141 if (passes
> 0) return; /* takes too long to repeat this test */
142 if (V1filesystem
) return; /* no need to spend time testing lacking features */
144 if (mkdir("T16.d", 0666) < 0) e(22);
145 get_times("T16.d", &a
, &c
, &m
);
146 get_times(".", &pa
, &pc
, &pm
);
152 if (rmdir("T16.d") < 0) e(27);
153 get_times(".", &xa
, &xc
, &xm
);
161 /* Test open(file, O_TRUNC). */
163 time_t a
, c
, m
, pa
, pc
, pm
, xa
, xc
, xm
, ya
, yc
, ym
;
167 if (passes
> 0) return; /* takes too long to repeat this test */
168 if (V1filesystem
) return; /* no need to spend time testing lacking features */
170 if ( (fd
= open("T16.e", O_WRONLY
|O_CREAT
, 0666)) < 0) e(31);
171 if (write(fd
, buf
, 1024) != 1024) e(32);
172 if (close(fd
) != 0) e(33);
173 get_times("T16.e", &a
, &c
, &m
);
174 get_times(".", &pa
, &pc
, &pm
);
176 if ( (fd
= open("T16.e", O_WRONLY
|O_TRUNC
)) < 0) e(34);
177 get_times("T16.e", &xa
, &xc
, &xm
);
178 get_times(".", &ya
, &yc
, &ym
);
185 if (close(fd
) != 0) e(41);
186 /* Try once more, now without changing the file size. */
188 if ( (fd
= open("T16.e", O_WRONLY
|O_TRUNC
)) < 0) e(89);
189 get_times("T16.e", &a
, &c
, &m
);
193 if (close(fd
) != 0) e(93);
198 /* Test the times for link/unlink. */
199 time_t a
, c
, m
, pa
, pc
, pm
, xa
, xc
, xm
, ya
, yc
, ym
;
202 if (passes
> 0) return; /* takes too long to repeat this test */
203 if (V1filesystem
) return; /* no need to spend time testing lacking features */
205 get_times("T16.e", &a
, &c
, &m
);
206 get_times(".", &ya
, &yc
, &ym
);
208 if (link("T16.e", "T16.f") != 0) e(42); /* second link */
209 get_times("T16.e", &xa
, &xc
, &xm
);
210 get_times(".", &pa
, &pc
, &pm
);
213 #ifndef V1_FILESYSTEM
222 if (unlink("T16.f") != 0) e(46);
223 get_times("T16.e", &a
, &c
, &m
);
224 get_times(".", &ya
, &yc
, &ym
);
227 #ifndef V1_FILESYSTEM
234 if (unlink("T16.e") != 0) e(58);
239 /* Test rename, read, write, chmod, utime. */
240 int fd
, fd1
, fd2
, fd3
, fd4
;
241 time_t a
, c
, m
, pa
, pc
, pm
, xa
, xc
, xm
, ya
, yc
, ym
, za
, zc
, zm
, ta
, tc
, tm
;
246 if (passes
> 0) return; /* takes too long to repeat this test */
247 if (V1filesystem
) return; /* no need to spend time testing lacking features */
249 get_times(".", &pa
, &pc
, &pm
);
250 if ( (fd
= open("T16.g", O_RDWR
|O_CREAT
)) < 0) e(59);
251 if ( (fd1
= open("T16.h", O_WRONLY
|O_CREAT
, 0666)) < 0) e(60);
252 if ( (fd2
= open("T16.i", O_WRONLY
|O_CREAT
, 0666)) < 0) e(61);
253 if ( (fd3
= open("T16.j", O_WRONLY
|O_CREAT
, 0666)) < 0) e(62);
254 if ( (fd4
= open("T16.k", O_RDWR
|O_CREAT
, 0666)) < 0) e(63);
255 if (write(fd
, buf
, 1024) != 1024) e(64);
256 get_times("T16.g", &a
, &c
, &m
);
257 get_times("T16.h", &pa
, &pc
, &pm
);
258 get_times("T16.i", &xa
, &xc
, &xm
);
259 get_times("T16.j", &ya
, &yc
, &ym
);
260 get_times("T16.k", &za
, &zc
, &zm
);
261 get_times(".", &wa
, &wc
, &wm
);
263 lseek(fd
, 0L, SEEK_SET
);
264 if (read(fd
, buf
, 35) != 35) e(65);
265 get_times("T16.g", &ta
, &tc
, &tm
);
266 if (a
== ta
|| c
!= tc
|| m
!= tm
) e(66);
267 if (write(fd1
, buf
, 35) != 35) e(67);
268 get_times("T16.h", &ta
, &tc
, &tm
);
269 if (pa
!= ta
|| pc
== tc
|| pm
== tm
) e(69);
270 if (rename("T16.i", "T16.i1") != 0) e(70);
271 get_times("T16.i1", &ta
, &tc
, &tm
);
272 if (xa
!= ta
|| xc
!= tc
|| xm
!= tm
) e(71);
273 get_times(".", &a
, &c
, &m
);
274 if (a
!= wa
|| c
== wc
|| m
== wm
|| wc
!= wm
) e(72);
275 if (chmod("T16.j", 0777) != 0) e(73);
276 get_times("T16.j", &ta
, &tc
, &tm
);
277 if (ya
!= ta
|| yc
== tc
|| ym
!= tm
) e(74);
278 if (utime("T16.k", (void *) 0) != 0) e(75);
279 get_times("T16.k", &ta
, &tc
, &tm
);
280 if (za
== ta
|| zc
== tc
) e(76);
281 if (close(fd
) != 0) e(77);
282 if (close(fd1
) != 0) e(78);
283 if (close(fd2
) != 0) e(79);
284 if (close(fd3
) != 0) e(80);
285 if (close(fd4
) != 0) e(81);
286 if (unlink("T16.g") != 0) e(82);
287 if (unlink("T16.h") != 0) e(83);
288 if (unlink("T16.i1") != 0) e(84);
289 if (unlink("T16.j") != 0) e(85);
290 if (unlink("T16.k") != 0) e(86);
295 /* Test the times for truncate. */
296 time_t a
, c
, m
, ta
, tc
, tm
;
300 if (passes
> 0) return; /* takes too long to repeat this test */
301 if (V1filesystem
) return; /* no need to spend time testing lacking features */
303 if (system("echo 1 > T16.l") != 0) e(87);
305 get_times("T16.l", &a
, &c
, &m
);
307 truncate("T16.l", s
.st_size
);
308 get_times("T16.l", &ta
, &tc
, &tm
);
309 if (a
!= ta
|| c
!= tc
|| m
!= tm
) e(88);
315 /* Test utimes, futimes, lutimes, futimens, utimensat. */
316 int fd
, fd1
, fd2
, fd3
, fd4
;
317 time_t a
, c
, m
, pa
, pc
, pm
;
318 time_t ta
, tc
, tm
, wa
, wc
, wm
, xa
, xc
, xm
, ya
, yc
, ym
, za
, zc
, zm
;
321 if (passes
> 0) return; /* takes too long to repeat this test */
322 if (V1filesystem
) return; /* no need to spend time testing lacking features */
324 get_times(".", &pa
, &pc
, &pm
);
325 if ( (fd
= open("T16.m", O_RDWR
|O_CREAT
, 0666)) < 0) e(89);
326 if ( (fd1
= open("T16.n", O_RDWR
|O_CREAT
, 0666)) < 0) e(90);
327 if ( (fd2
= open("T16.o", O_RDWR
|O_CREAT
, 0666)) < 0) e(91);
328 if ( (fd3
= open("T16.p", O_RDWR
|O_CREAT
, 0666)) < 0) e(92);
329 if ( (fd4
= open("T16.q", O_RDWR
|O_CREAT
, 0666)) < 0) e(93);
330 get_times("T16.m", &ta
, &tc
, &tm
);
331 get_times("T16.n", &wa
, &wc
, &wm
);
332 get_times("T16.o", &xa
, &xc
, &xm
);
333 get_times("T16.p", &ya
, &yc
, &ym
);
334 get_times("T16.q", &za
, &zc
, &zm
);
335 get_times(".", &pa
, &pc
, &pm
);
337 if (utimes("T16.m", (void *) 0) != 0) e(94);
338 get_times("T16.m", &a
, &c
, &m
);
339 if (a
== ta
|| c
== tc
) e(95);
340 if (futimes(fd1
, (void *) 0) != 0) e(96);
341 get_times("T16.n", &a
, &c
, &m
);
342 if (a
== wa
|| c
== wc
) e(97);
343 if (lutimes("T16.o", (void *) 0) != 0) e(98);
344 get_times("T16.o", &a
, &c
, &m
);
345 if (a
== xa
|| c
== xc
) e(99);
346 if (utimensat(AT_FDCWD
, "T16.p", (void *) 0, 0) != 0) e(100);
347 get_times("T16.p", &a
, &c
, &m
);
348 if (a
== ya
|| c
== yc
) e(101);
349 if (futimens(fd4
, (void *) 0) != 0) e(102);
350 get_times("T16.q", &a
, &c
, &m
);
351 if (a
== za
|| c
== zc
) e(103);
352 if (close(fd
) != 0) e(104);
353 if (close(fd1
) != 0) e(105);
354 if (close(fd2
) != 0) e(106);
355 if (close(fd3
) != 0) e(107);
356 if (close(fd4
) != 0) e(108);
357 if (unlink("T16.m") != 0) e(109);
358 if (unlink("T16.n") != 0) e(110);
359 if (unlink("T16.o") != 0) e(111);
360 if (unlink("T16.p") != 0) e(112);
361 if (unlink("T16.q") != 0) e(113);
364 void get_times(name
, a
, c
, m
)
370 if (stat(name
, &s
) != 0) e(500);