14 int errct
, subtest
, passes
;
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));
28 m
= (argc
== 2 ? atoi(argv
[1]) : 0xFFFF);
30 system("rm -rf DIR_16; mkdir DIR_16");
35 for (i
= 0; i
< 4; i
++) {
36 if (m
& 0001) test16a();
40 return(-1); /* impossible */
45 /* Test atime, ctime, and mtime. */
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
;
54 if (passes
> 0) return; /* takes too long to repeat this test */
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);
68 /* Almost certainly means we are running a V1 file system. */
69 printf(" (atime = 0. Probably V1 file system. V2 tests skipped.) ");
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.
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
);
86 if (unlink("T16.b") < 0) e(14);
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
);
97 if (unlink("T16.c") < 0) e(21);
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
);
108 if (rmdir("T16.d") < 0) e(27);
109 get_times(".", &xa
, &xc
, &xm
);
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
);
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
);
130 if (close(fd
) != 0) e(41);
132 /* Test the times for link/unlink. */
133 get_times("T16.e", &a
, &c
, &m
);
134 get_times(".", &ya
, &yc
, &ym
);
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
);
141 #ifndef V1_FILESYSTEM
150 if (unlink("T16.f") != 0) e(46);
151 get_times("T16.e", &a
, &c
, &m
);
152 get_times(".", &ya
, &yc
, &ym
);
155 #ifndef V1_FILESYSTEM
162 if (unlink("T16.e") != 0) e(58);
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
);
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);
209 void get_times(name
, a
, c
, m
)
215 if (stat(name
, &s
) != 0) e(500);
224 int err_num
= errno
; /* save errno in case printf clobbers it */
226 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
227 errno
= err_num
; /* restore errno, just in case */
229 if (errct
++ > MAX_ERROR
) {
230 printf("Too many errors; test aborted\n");
232 system("rm -rf DIR*");
241 system("rm -rf DIR*");
247 printf("%d errors\n", errct
);