14 #include <sys/types.h> 18 # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) 22 static char testfile[1024];
23 static char testfile2[1024];
24 static char testdir[1024];
25 static char testdir2[1024];
26 static char subfile[1280];
28 static char testfile_r[1024];
29 static char testfile2_r[1024];
30 static char testdir_r[1024];
31 static char testdir2_r[1024];
32 static char subfile_r[1280];
34 static char testname[256];
35 static char testdata[] =
"abcdefghijklmnopqrstuvwxyz";
36 static char testdata2[] =
"1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./";
37 static const char *testdir_files[] = {
"f1",
"f2", NULL};
38 static long seekdir_offsets[4];
39 static char zerodata[4096];
40 static int testdatalen =
sizeof(testdata) - 1;
41 static int testdata2len =
sizeof(testdata2) - 1;
42 static unsigned int testnum = 1;
43 static unsigned int select_test = 0;
44 static unsigned int skip_test = 0;
46 #define MAX_ENTRIES 1024 48 static void test_perror(
const char *func,
const char *msg)
50 fprintf(stderr,
"%s %s() - %s: %s\n", testname, func, msg,
54 static void test_error(
const char *func,
const char *msg, ...)
55 __attribute__ ((format (printf, 2, 3)));
57 static
void __start_test(const
char *fmt, ...)
58 __attribute__ ((format (printf, 1, 2)));
60 static
void test_error(const
char *func, const
char *msg, ...)
63 fprintf(stderr,
"%s %s() - ", testname, func);
65 vfprintf(stderr, msg, ap);
67 fprintf(stderr,
"\n");
70 static void success(
void)
72 fprintf(stderr,
"%s OK\n", testname);
75 static void __start_test(
const char *fmt, ...)
79 n = sprintf(testname,
"%3i [", testnum++);
81 n += vsprintf(testname + n, fmt, ap);
83 sprintf(testname + n,
"]");
86 #define start_test(msg, args...) { \ 87 if ((select_test && testnum != select_test) || \ 88 (testnum == skip_test)) { \ 92 __start_test(msg, ##args); \ 95 #define PERROR(msg) test_perror(__FUNCTION__, msg) 96 #define ERROR(msg, args...) test_error(__FUNCTION__, msg, ##args) 98 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 100 static int check_size(
const char *path,
int len)
103 int res = stat(path, &stbuf);
108 if (stbuf.st_size != len) {
109 ERROR(
"length %u instead of %u", (
int) stbuf.st_size,
116 static int fcheck_size(
int fd,
int len)
119 int res = fstat(fd, &stbuf);
124 if (stbuf.st_size != len) {
125 ERROR(
"length %u instead of %u", (
int) stbuf.st_size,
132 static int check_type(
const char *path, mode_t type)
135 int res = lstat(path, &stbuf);
140 if ((stbuf.st_mode & S_IFMT) != type) {
141 ERROR(
"type 0%o instead of 0%o", stbuf.st_mode & S_IFMT, type);
147 static int fcheck_type(
int fd, mode_t type)
150 int res = fstat(fd, &stbuf);
155 if ((stbuf.st_mode & S_IFMT) != type) {
156 ERROR(
"type 0%o instead of 0%o", stbuf.st_mode & S_IFMT, type);
162 static int check_mode(
const char *path, mode_t mode)
165 int res = lstat(path, &stbuf);
170 if ((stbuf.st_mode & ALLPERMS) != mode) {
171 ERROR(
"mode 0%o instead of 0%o", stbuf.st_mode & ALLPERMS,
178 static int fcheck_mode(
int fd, mode_t mode)
181 int res = fstat(fd, &stbuf);
186 if ((stbuf.st_mode & ALLPERMS) != mode) {
187 ERROR(
"mode 0%o instead of 0%o", stbuf.st_mode & ALLPERMS,
194 static int check_times(
const char *path, time_t atime, time_t mtime)
198 int res = lstat(path, &stbuf);
203 if (stbuf.st_atime != atime) {
204 ERROR(
"atime %li instead of %li", stbuf.st_atime, atime);
207 if (stbuf.st_mtime != mtime) {
208 ERROR(
"mtime %li instead of %li", stbuf.st_mtime, mtime);
218 static int fcheck_times(
int fd, time_t atime, time_t mtime)
222 int res = fstat(fd, &stbuf);
227 if (stbuf.st_atime != atime) {
228 ERROR(
"atime %li instead of %li", stbuf.st_atime, atime);
231 if (stbuf.st_mtime != mtime) {
232 ERROR(
"mtime %li instead of %li", stbuf.st_mtime, mtime);
242 static int check_nlink(
const char *path, nlink_t nlink)
245 int res = lstat(path, &stbuf);
250 if (stbuf.st_nlink != nlink) {
251 ERROR(
"nlink %li instead of %li", (
long) stbuf.st_nlink,
258 static int fcheck_nlink(
int fd, nlink_t nlink)
261 int res = fstat(fd, &stbuf);
266 if (stbuf.st_nlink != nlink) {
267 ERROR(
"nlink %li instead of %li", (
long) stbuf.st_nlink,
274 static int check_nonexist(
const char *path)
277 int res = lstat(path, &stbuf);
279 ERROR(
"file should not exist");
282 if (errno != ENOENT) {
283 ERROR(
"file should not exist: %s", strerror(errno));
289 static int check_buffer(
const char *buf,
const char *data,
unsigned len)
291 if (memcmp(buf, data, len) != 0) {
292 ERROR(
"data mismatch");
298 static int check_data(
const char *path,
const char *data,
int offset,
303 int fd = open(path, O_RDONLY);
308 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
314 int rdlen = len <
sizeof(buf) ? len :
sizeof(buf);
315 res = read(fd, buf, rdlen);
322 ERROR(
"short read: %u instead of %u", res, rdlen);
326 if (check_buffer(buf, data, rdlen) != 0) {
341 static int fcheck_data(
int fd,
const char *data,
int offset,
346 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
351 int rdlen = len <
sizeof(buf) ? len :
sizeof(buf);
352 res = read(fd, buf, rdlen);
358 ERROR(
"short read: %u instead of %u", res, rdlen);
361 if (check_buffer(buf, data, rdlen) != 0) {
370 static int check_dir_contents(
const char *path,
const char **contents)
375 int found[MAX_ENTRIES];
376 const char *cont[MAX_ENTRIES];
379 for (i = 0; contents[i]; i++) {
380 assert(i < MAX_ENTRIES - 3);
382 cont[i] = contents[i];
395 memset(found, 0,
sizeof(found));
408 for (i = 0; cont[i] != NULL; i++) {
409 assert(i < MAX_ENTRIES);
410 if (strcmp(cont[i], de->d_name) == 0) {
412 ERROR(
"duplicate entry <%s>",
421 ERROR(
"unexpected entry <%s>", de->d_name);
425 for (i = 0; cont[i] != NULL; i++) {
427 ERROR(
"missing entry <%s>", cont[i]);
442 static int create_file(
const char *path,
const char *data,
int len)
448 fd = creat(path, 0644);
454 res = write(fd, data, len);
461 ERROR(
"write is short: %u instead of %u", res, len);
471 res = check_type(path, S_IFREG);
474 res = check_mode(path, 0644);
477 res = check_nlink(path, 1);
480 res = check_size(path, len);
485 res = check_data(path, data, 0, len);
493 static int cleanup_dir(
const char *path,
const char **dir_files,
int quiet)
498 for (i = 0; dir_files[i]; i++) {
501 sprintf(fpath,
"%s/%s", path, dir_files[i]);
503 if (res == -1 && !quiet) {
514 static int create_dir(
const char *path,
const char **dir_files)
520 res = mkdir(path, 0755);
525 res = check_type(path, S_IFDIR);
528 res = check_mode(path, 0755);
532 for (i = 0; dir_files[i]; i++) {
534 sprintf(fpath,
"%s/%s", path, dir_files[i]);
535 res = create_file(fpath,
"", 0);
537 cleanup_dir(path, dir_files, 1);
541 res = check_dir_contents(path, dir_files);
543 cleanup_dir(path, dir_files, 1);
550 static int test_truncate(
int len)
552 const char *data = testdata;
553 int datalen = testdatalen;
556 start_test(
"truncate(%u)", (
int) len);
557 res = create_file(testfile, data, datalen);
561 res = truncate(testfile, len);
566 res = check_size(testfile, len);
571 if (len <= datalen) {
572 res = check_data(testfile, data, 0, len);
576 res = check_data(testfile, data, 0, datalen);
579 res = check_data(testfile, zerodata, datalen,
585 res = unlink(testfile);
590 res = check_nonexist(testfile);
598 static int test_ftruncate(
int len,
int mode)
600 const char *data = testdata;
601 int datalen = testdatalen;
605 start_test(
"ftruncate(%u) mode: 0%03o", len, mode);
606 res = create_file(testfile, data, datalen);
610 fd = open(testfile, O_WRONLY);
616 res = fchmod(fd, mode);
622 res = check_mode(testfile, mode);
627 res = ftruncate(fd, len);
634 res = check_size(testfile, len);
639 if (len <= datalen) {
640 res = check_data(testfile, data, 0, len);
644 res = check_data(testfile, data, 0, datalen);
647 res = check_data(testfile, zerodata, datalen,
653 res = unlink(testfile);
658 res = check_nonexist(testfile);
666 static int test_seekdir(
void)
673 start_test(
"seekdir");
674 res = create_dir(testdir, testdir_files);
678 dp = opendir(testdir);
685 for (i = 0; i < ARRAY_SIZE(seekdir_offsets); i++) {
686 seekdir_offsets[i] = telldir(dp);
703 for (i--; i >= 0; i--) {
704 seekdir(dp, seekdir_offsets[i]);
707 ERROR(
"Unexpected end of directory after seekdir()");
713 res = cleanup_dir(testdir, testdir_files, 0);
719 cleanup_dir(testdir, testdir_files, 1);
723 #ifdef HAVE_COPY_FILE_RANGE 724 static int test_copy_file_range(
void)
726 const char *data = testdata;
727 int datalen = testdatalen;
731 off_t pos_in = 0, pos_out = 0;
733 start_test(
"copy_file_range");
735 fd_in = open(testfile, O_CREAT | O_RDWR, 0644);
740 res = write(fd_in, data, datalen);
746 if (res != datalen) {
747 ERROR(
"write is short: %u instead of %u", res, datalen);
753 fd_out = creat(testfile2, 0644);
759 res = copy_file_range(fd_in, &pos_in, fd_out, &pos_out, datalen, 0);
761 PERROR(
"copy_file_range");
766 if (res != datalen) {
767 ERROR(
"copy is short: %u instead of %u", res, datalen);
784 err = check_data(testfile2, data, 0, datalen);
786 res = unlink(testfile);
791 res = check_nonexist(testfile);
797 res = unlink(testfile2);
802 res = check_nonexist(testfile2);
812 static int test_copy_file_range(
void)
818 static int test_utime(
void)
821 time_t atime = 987631200;
822 time_t mtime = 123116400;
826 res = create_file(testfile, NULL, 0);
832 res = utime(testfile, &utm);
837 res = check_times(testfile, atime, mtime);
841 res = unlink(testfile);
846 res = check_nonexist(testfile);
854 static int test_create(
void)
856 const char *data = testdata;
857 int datalen = testdatalen;
862 start_test(
"create");
864 fd = creat(testfile, 0644);
869 res = write(fd, data, datalen);
875 if (res != datalen) {
876 ERROR(
"write is short: %u instead of %u", res, datalen);
885 res = check_type(testfile, S_IFREG);
888 err += check_mode(testfile, 0644);
889 err += check_nlink(testfile, 1);
890 err += check_size(testfile, datalen);
891 err += check_data(testfile, data, 0, datalen);
892 res = unlink(testfile);
897 res = check_nonexist(testfile);
907 static int test_create_unlink(
void)
909 const char *data = testdata;
910 int datalen = testdatalen;
915 start_test(
"create+unlink");
917 fd = open(testfile, O_CREAT | O_RDWR | O_TRUNC, 0644);
922 res = unlink(testfile);
928 res = check_nonexist(testfile);
931 res = write(fd, data, datalen);
937 if (res != datalen) {
938 ERROR(
"write is short: %u instead of %u", res, datalen);
942 err += fcheck_type(fd, S_IFREG);
943 err += fcheck_mode(fd, 0644);
944 err += fcheck_nlink(fd, 0);
945 err += fcheck_size(fd, datalen);
946 err += fcheck_data(fd, data, 0, datalen);
960 static int test_mknod(
void)
967 res = mknod(testfile, 0644, 0);
972 res = check_type(testfile, S_IFREG);
975 err += check_mode(testfile, 0644);
976 err += check_nlink(testfile, 1);
977 err += check_size(testfile, 0);
978 res = unlink(testfile);
983 res = check_nonexist(testfile);
994 #define test_open(exist, flags, mode) do_test_open(exist, flags, #flags, mode) 996 static int do_test_open(
int exist,
int flags,
const char *flags_str,
int mode)
999 const char *data = testdata;
1000 int datalen = testdatalen;
1001 unsigned currlen = 0;
1007 start_test(
"open(%s, %s, 0%03o)", exist ?
"+" :
"-", flags_str, mode);
1010 res = create_file(testfile_r, testdata2, testdata2len);
1014 currlen = testdata2len;
1017 fd = open(testfile, flags, mode);
1018 if ((flags & O_CREAT) && (flags & O_EXCL) && exist) {
1020 ERROR(
"open should have failed");
1023 }
else if (errno == EEXIST)
1026 if (!(flags & O_CREAT) && !exist) {
1028 ERROR(
"open should have failed");
1031 }
else if (errno == ENOENT)
1039 if (flags & O_TRUNC)
1042 err += check_type(testfile, S_IFREG);
1044 err += check_mode(testfile, 0644);
1046 err += check_mode(testfile, mode);
1047 err += check_nlink(testfile, 1);
1048 err += check_size(testfile, currlen);
1049 if (exist && !(flags & O_TRUNC) && (mode & S_IRUSR))
1050 err += check_data(testfile, testdata2, 0, testdata2len);
1052 res = write(fd, data, datalen);
1053 if ((flags & O_ACCMODE) != O_RDONLY) {
1057 }
else if (res != datalen) {
1058 ERROR(
"write is short: %u instead of %u", res, datalen);
1061 if (datalen > (
int) currlen)
1064 err += check_size(testfile, currlen);
1066 if (mode & S_IRUSR) {
1067 err += check_data(testfile, data, 0, datalen);
1068 if (exist && !(flags & O_TRUNC) &&
1069 testdata2len > datalen)
1070 err += check_data(testfile,
1071 testdata2 + datalen,
1073 testdata2len - datalen);
1078 ERROR(
"write should have failed");
1080 }
else if (errno != EBADF) {
1085 off = lseek(fd, SEEK_SET, 0);
1086 if (off == (off_t) -1) {
1089 }
else if (off != 0) {
1090 ERROR(
"offset should have returned 0");
1093 res = read(fd, buf,
sizeof(buf));
1094 if ((flags & O_ACCMODE) != O_WRONLY) {
1100 currlen <
sizeof(buf) ? currlen :
sizeof(buf);
1101 if (res != readsize) {
1102 ERROR(
"read is short: %i instead of %u",
1106 if ((flags & O_ACCMODE) != O_RDONLY) {
1107 err += check_buffer(buf, data, datalen);
1108 if (exist && !(flags & O_TRUNC) &&
1109 testdata2len > datalen)
1110 err += check_buffer(buf + datalen,
1111 testdata2 + datalen,
1112 testdata2len - datalen);
1114 err += check_buffer(buf, testdata2,
1120 ERROR(
"read should have failed");
1122 }
else if (errno != EBADF) {
1133 res = unlink(testfile);
1138 res = check_nonexist(testfile);
1141 res = check_nonexist(testfile_r);
1152 #define test_open_acc(flags, mode, err) \ 1153 do_test_open_acc(flags, #flags, mode, err) 1155 static int do_test_open_acc(
int flags,
const char *flags_str,
int mode,
int err)
1157 const char *data = testdata;
1158 int datalen = testdatalen;
1162 start_test(
"open_acc(%s) mode: 0%03o message: '%s'", flags_str, mode,
1165 res = create_file(testfile, data, datalen);
1169 res = chmod(testfile, mode);
1175 res = check_mode(testfile, mode);
1179 fd = open(testfile, flags);
1187 ERROR(
"open should have failed");
1197 static int test_symlink(
void)
1200 const char *data = testdata;
1201 int datalen = testdatalen;
1202 int linklen = strlen(testfile);
1206 start_test(
"symlink");
1207 res = create_file(testfile, data, datalen);
1212 res = symlink(testfile, testfile2);
1217 res = check_type(testfile2, S_IFLNK);
1220 err += check_mode(testfile2, 0777);
1221 err += check_nlink(testfile2, 1);
1222 res = readlink(testfile2, buf,
sizeof(buf));
1227 if (res != linklen) {
1228 ERROR(
"short readlink: %u instead of %u", res, linklen);
1231 if (memcmp(buf, testfile, linklen) != 0) {
1232 ERROR(
"link mismatch");
1235 err += check_size(testfile2, datalen);
1236 err += check_data(testfile2, data, 0, datalen);
1237 res = unlink(testfile2);
1242 res = check_nonexist(testfile2);
1252 static int test_link(
void)
1254 const char *data = testdata;
1255 int datalen = testdatalen;
1260 res = create_file(testfile, data, datalen);
1265 res = link(testfile, testfile2);
1270 res = check_type(testfile2, S_IFREG);
1273 err += check_mode(testfile2, 0644);
1274 err += check_nlink(testfile2, 2);
1275 err += check_size(testfile2, datalen);
1276 err += check_data(testfile2, data, 0, datalen);
1277 res = unlink(testfile);
1282 res = check_nonexist(testfile);
1286 err += check_nlink(testfile2, 1);
1287 res = unlink(testfile2);
1292 res = check_nonexist(testfile2);
1302 static int test_link2(
void)
1304 const char *data = testdata;
1305 int datalen = testdatalen;
1309 start_test(
"link-unlink-link");
1310 res = create_file(testfile, data, datalen);
1315 res = link(testfile, testfile2);
1320 res = unlink(testfile);
1325 res = check_nonexist(testfile);
1328 res = link(testfile2, testfile);
1332 res = check_type(testfile, S_IFREG);
1335 err += check_mode(testfile, 0644);
1336 err += check_nlink(testfile, 2);
1337 err += check_size(testfile, datalen);
1338 err += check_data(testfile, data, 0, datalen);
1340 res = unlink(testfile2);
1345 err += check_nlink(testfile, 1);
1346 res = unlink(testfile);
1351 res = check_nonexist(testfile);
1361 static int test_rename_file(
void)
1363 const char *data = testdata;
1364 int datalen = testdatalen;
1368 start_test(
"rename file");
1369 res = create_file(testfile, data, datalen);
1374 res = rename(testfile, testfile2);
1379 res = check_nonexist(testfile);
1382 res = check_type(testfile2, S_IFREG);
1385 err += check_mode(testfile2, 0644);
1386 err += check_nlink(testfile2, 1);
1387 err += check_size(testfile2, datalen);
1388 err += check_data(testfile2, data, 0, datalen);
1389 res = unlink(testfile2);
1394 res = check_nonexist(testfile2);
1404 static int test_rename_dir(
void)
1409 start_test(
"rename dir");
1410 res = create_dir(testdir, testdir_files);
1415 res = rename(testdir, testdir2);
1418 cleanup_dir(testdir, testdir_files, 1);
1421 res = check_nonexist(testdir);
1423 cleanup_dir(testdir, testdir_files, 1);
1426 res = check_type(testdir2, S_IFDIR);
1428 cleanup_dir(testdir2, testdir_files, 1);
1431 err += check_mode(testdir2, 0755);
1432 err += check_dir_contents(testdir2, testdir_files);
1433 err += cleanup_dir(testdir2, testdir_files, 0);
1434 res = rmdir(testdir2);
1439 res = check_nonexist(testdir2);
1449 static int test_rename_dir_loop(
void)
1451 #define PATH(p) (snprintf(path, sizeof path, "%s/%s", testdir, p), path) 1452 #define PATH2(p) (snprintf(path2, sizeof path2, "%s/%s", testdir, p), path2) 1454 char path[1280], path2[1280];
1458 start_test(
"rename dir loop");
1460 res = create_dir(testdir, testdir_files);
1464 res = mkdir(PATH(
"a"), 0755);
1470 res = rename(PATH(
"a"), PATH2(
"a"));
1477 res = rename(PATH(
"a"), PATH2(
"a/b"));
1478 if (res == 0 || errno != EINVAL) {
1483 res = mkdir(PATH(
"a/b"), 0755);
1489 res = mkdir(PATH(
"a/b/c"), 0755);
1496 res = rename(PATH(
"a"), PATH2(
"a/b/c"));
1497 if (res == 0 || errno != EINVAL) {
1503 res = rename(PATH(
"a"), PATH2(
"a/b/c/a"));
1504 if (res == 0 || errno != EINVAL) {
1510 res = rename(PATH(
"a/b/c"), PATH2(
"a"));
1511 if (res == 0 || errno != ENOTEMPTY) {
1516 res = open(PATH(
"a/foo"), O_CREAT, 0644);
1523 res = rename(PATH(
"a/foo"), PATH2(
"a/bar"));
1529 res = rename(PATH(
"a/bar"), PATH2(
"a/foo"));
1535 res = rename(PATH(
"a/foo"), PATH2(
"a/b/bar"));
1541 res = rename(PATH(
"a/b/bar"), PATH2(
"a/foo"));
1547 res = rename(PATH(
"a/foo"), PATH2(
"a/b/c/bar"));
1553 res = rename(PATH(
"a/b/c/bar"), PATH2(
"a/foo"));
1559 res = open(PATH(
"a/bar"), O_CREAT, 0644);
1566 res = rename(PATH(
"a/foo"), PATH2(
"a/bar"));
1572 unlink(PATH(
"a/bar"));
1574 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1580 res = rename(PATH(
"a/d"), PATH2(
"a/b"));
1586 res = mkdir(PATH(
"a/d"), 0755);
1592 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1598 res = rename(PATH(
"a/d"), PATH2(
"a/b"));
1604 res = mkdir(PATH(
"a/d"), 0755);
1610 res = mkdir(PATH(
"a/d/e"), 0755);
1617 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1618 if (res == 0 || errno != ENOTEMPTY) {
1623 rmdir(PATH(
"a/d/e"));
1626 rmdir(PATH(
"a/b/c"));
1630 err += cleanup_dir(testdir, testdir_files, 0);
1631 res = rmdir(testdir);
1636 res = check_nonexist(testdir);
1646 unlink(PATH(
"a/bar"));
1648 rmdir(PATH(
"a/d/e"));
1651 rmdir(PATH(
"a/b/c"));
1655 cleanup_dir(testdir, testdir_files, 1);
1665 static int test_mkfifo(
void)
1670 start_test(
"mkfifo");
1672 res = mkfifo(testfile, 0644);
1677 res = check_type(testfile, S_IFIFO);
1680 err += check_mode(testfile, 0644);
1681 err += check_nlink(testfile, 1);
1682 res = unlink(testfile);
1687 res = check_nonexist(testfile);
1698 static int test_mkdir(
void)
1702 const char *dir_contents[] = {NULL};
1704 start_test(
"mkdir");
1706 res = mkdir(testdir, 0755);
1711 res = check_type(testdir, S_IFDIR);
1714 err += check_mode(testdir, 0755);
1718 err += check_dir_contents(testdir, dir_contents);
1719 res = rmdir(testdir);
1724 res = check_nonexist(testdir);
1734 #define test_create_ro_dir(flags) \ 1735 do_test_create_ro_dir(flags, #flags) 1737 static int do_test_create_ro_dir(
int flags,
const char *flags_str)
1743 start_test(
"open(%s) in read-only directory", flags_str);
1745 res = mkdir(testdir, 0555);
1750 fd = open(subfile, flags, 0644);
1754 ERROR(
"open should have failed");
1757 res = check_nonexist(subfile);
1762 res = rmdir(testdir);
1767 res = check_nonexist(testdir);
1777 int main(
int argc,
char *argv[])
1779 const char *basepath;
1780 const char *realpath;
1786 if (argc < 2 || argc > 4) {
1787 fprintf(stderr,
"usage: %s testdir [:realdir] [[-]test#]\n", argv[0]);
1791 realpath = basepath;
1792 for (a = 2; a < argc; a++) {
1794 char *arg = argv[a];
1795 if (arg[0] ==
':') {
1798 if (arg[0] ==
'-') {
1800 skip_test = strtoul(arg, &endptr, 10);
1802 select_test = strtoul(arg, &endptr, 10);
1804 if (arg[0] ==
'\0' || *endptr !=
'\0') {
1805 fprintf(stderr,
"invalid number: '%s'\n", arg);
1810 assert(strlen(basepath) < 512);
1811 assert(strlen(realpath) < 512);
1812 if (basepath[0] !=
'/') {
1813 fprintf(stderr,
"testdir must be an absolute path\n");
1817 sprintf(testfile,
"%s/testfile", basepath);
1818 sprintf(testfile2,
"%s/testfile2", basepath);
1819 sprintf(testdir,
"%s/testdir", basepath);
1820 sprintf(testdir2,
"%s/testdir2", basepath);
1821 sprintf(subfile,
"%s/subfile", testdir2);
1823 sprintf(testfile_r,
"%s/testfile", realpath);
1824 sprintf(testfile2_r,
"%s/testfile2", realpath);
1825 sprintf(testdir_r,
"%s/testdir", realpath);
1826 sprintf(testdir2_r,
"%s/testdir2", realpath);
1827 sprintf(subfile_r,
"%s/subfile", testdir2_r);
1829 is_root = (geteuid() == 0);
1831 err += test_create();
1832 err += test_create_unlink();
1833 err += test_symlink();
1835 err += test_link2();
1837 err += test_mknod();
1838 err += test_mkfifo();
1840 err += test_mkdir();
1841 err += test_rename_file();
1842 err += test_rename_dir();
1843 err += test_rename_dir_loop();
1844 err += test_seekdir();
1845 err += test_utime();
1846 err += test_truncate(0);
1847 err += test_truncate(testdatalen / 2);
1848 err += test_truncate(testdatalen);
1849 err += test_truncate(testdatalen + 100);
1850 err += test_ftruncate(0, 0600);
1851 err += test_ftruncate(testdatalen / 2, 0600);
1852 err += test_ftruncate(testdatalen, 0600);
1853 err += test_ftruncate(testdatalen + 100, 0600);
1854 err += test_ftruncate(0, 0400);
1855 err += test_ftruncate(0, 0200);
1856 err += test_ftruncate(0, 0000);
1857 err += test_open(0, O_RDONLY, 0);
1858 err += test_open(1, O_RDONLY, 0);
1859 err += test_open(1, O_RDWR, 0);
1860 err += test_open(1, O_WRONLY, 0);
1861 err += test_open(0, O_RDWR | O_CREAT, 0600);
1862 err += test_open(1, O_RDWR | O_CREAT, 0600);
1863 err += test_open(0, O_RDWR | O_CREAT | O_TRUNC, 0600);
1864 err += test_open(1, O_RDWR | O_CREAT | O_TRUNC, 0600);
1865 err += test_open(0, O_RDONLY | O_CREAT, 0600);
1866 err += test_open(0, O_RDONLY | O_CREAT, 0400);
1867 err += test_open(0, O_RDONLY | O_CREAT, 0200);
1868 err += test_open(0, O_RDONLY | O_CREAT, 0000);
1869 err += test_open(0, O_WRONLY | O_CREAT, 0600);
1870 err += test_open(0, O_WRONLY | O_CREAT, 0400);
1871 err += test_open(0, O_WRONLY | O_CREAT, 0200);
1872 err += test_open(0, O_WRONLY | O_CREAT, 0000);
1873 err += test_open(0, O_RDWR | O_CREAT, 0400);
1874 err += test_open(0, O_RDWR | O_CREAT, 0200);
1875 err += test_open(0, O_RDWR | O_CREAT, 0000);
1876 err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0600);
1877 err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0600);
1878 err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0000);
1879 err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0000);
1880 err += test_open_acc(O_RDONLY, 0600, 0);
1881 err += test_open_acc(O_WRONLY, 0600, 0);
1882 err += test_open_acc(O_RDWR, 0600, 0);
1883 err += test_open_acc(O_RDONLY, 0400, 0);
1884 err += test_open_acc(O_WRONLY, 0200, 0);
1886 err += test_open_acc(O_RDONLY | O_TRUNC, 0400, EACCES);
1887 err += test_open_acc(O_WRONLY, 0400, EACCES);
1888 err += test_open_acc(O_RDWR, 0400, EACCES);
1889 err += test_open_acc(O_RDONLY, 0200, EACCES);
1890 err += test_open_acc(O_RDWR, 0200, EACCES);
1891 err += test_open_acc(O_RDONLY, 0000, EACCES);
1892 err += test_open_acc(O_WRONLY, 0000, EACCES);
1893 err += test_open_acc(O_RDWR, 0000, EACCES);
1895 err += test_create_ro_dir(O_CREAT);
1896 err += test_create_ro_dir(O_CREAT | O_EXCL);
1897 err += test_create_ro_dir(O_CREAT | O_WRONLY);
1898 err += test_create_ro_dir(O_CREAT | O_TRUNC);
1899 err += test_copy_file_range();
1907 fprintf(stderr,
"%i tests failed\n", -err);