14 #include <sys/types.h> 18 static char testfile[1024];
19 static char testfile2[1024];
20 static char testdir[1024];
21 static char testdir2[1024];
22 static char subfile[1280];
24 static char testfile_r[1024];
25 static char testfile2_r[1024];
26 static char testdir_r[1024];
27 static char testdir2_r[1024];
28 static char subfile_r[1280];
30 static char testname[256];
31 static char testdata[] =
"abcdefghijklmnopqrstuvwxyz";
32 static char testdata2[] =
"1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./";
33 static const char *testdir_files[] = {
"f1",
"f2", NULL};
34 static long seekdir_offsets[4];
35 static char zerodata[4096];
36 static int testdatalen =
sizeof(testdata) - 1;
37 static int testdata2len =
sizeof(testdata2) - 1;
38 static unsigned int testnum = 1;
39 static unsigned int select_test = 0;
40 static unsigned int skip_test = 0;
42 #define MAX_ENTRIES 1024 44 static void test_perror(
const char *func,
const char *msg)
46 fprintf(stderr,
"%s %s() - %s: %s\n", testname, func, msg,
50 static void test_error(
const char *func,
const char *msg, ...)
51 __attribute__ ((format (printf, 2, 3)));
53 static
void __start_test(const
char *fmt, ...)
54 __attribute__ ((format (printf, 1, 2)));
56 static
void test_error(const
char *func, const
char *msg, ...)
59 fprintf(stderr,
"%s %s() - ", testname, func);
61 vfprintf(stderr, msg, ap);
63 fprintf(stderr,
"\n");
66 static void success(
void)
68 fprintf(stderr,
"%s OK\n", testname);
71 static void __start_test(
const char *fmt, ...)
75 n = sprintf(testname,
"%3i [", testnum++);
77 n += vsprintf(testname + n, fmt, ap);
79 sprintf(testname + n,
"]");
82 #define start_test(msg, args...) { \ 83 if ((select_test && testnum != select_test) || \ 84 (testnum == skip_test)) { \ 88 __start_test(msg, ##args); \ 91 #define PERROR(msg) test_perror(__FUNCTION__, msg) 92 #define ERROR(msg, args...) test_error(__FUNCTION__, msg, ##args) 94 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 96 static int check_size(
const char *path,
int len)
99 int res = stat(path, &stbuf);
104 if (stbuf.st_size != len) {
105 ERROR(
"length %u instead of %u", (
int) stbuf.st_size,
112 static int fcheck_size(
int fd,
int len)
115 int res = fstat(fd, &stbuf);
120 if (stbuf.st_size != len) {
121 ERROR(
"length %u instead of %u", (
int) stbuf.st_size,
128 static int check_type(
const char *path, mode_t type)
131 int res = lstat(path, &stbuf);
136 if ((stbuf.st_mode & S_IFMT) != type) {
137 ERROR(
"type 0%o instead of 0%o", stbuf.st_mode & S_IFMT, type);
143 static int fcheck_type(
int fd, mode_t type)
146 int res = fstat(fd, &stbuf);
151 if ((stbuf.st_mode & S_IFMT) != type) {
152 ERROR(
"type 0%o instead of 0%o", stbuf.st_mode & S_IFMT, type);
158 static int check_mode(
const char *path, mode_t mode)
161 int res = lstat(path, &stbuf);
166 if ((stbuf.st_mode & ALLPERMS) != mode) {
167 ERROR(
"mode 0%o instead of 0%o", stbuf.st_mode & ALLPERMS,
174 static int fcheck_mode(
int fd, mode_t mode)
177 int res = fstat(fd, &stbuf);
182 if ((stbuf.st_mode & ALLPERMS) != mode) {
183 ERROR(
"mode 0%o instead of 0%o", stbuf.st_mode & ALLPERMS,
190 static int check_times(
const char *path, time_t atime, time_t mtime)
194 int res = lstat(path, &stbuf);
199 if (stbuf.st_atime != atime) {
200 ERROR(
"atime %li instead of %li", stbuf.st_atime, atime);
203 if (stbuf.st_mtime != mtime) {
204 ERROR(
"mtime %li instead of %li", stbuf.st_mtime, mtime);
214 static int fcheck_times(
int fd, time_t atime, time_t mtime)
218 int res = fstat(fd, &stbuf);
223 if (stbuf.st_atime != atime) {
224 ERROR(
"atime %li instead of %li", stbuf.st_atime, atime);
227 if (stbuf.st_mtime != mtime) {
228 ERROR(
"mtime %li instead of %li", stbuf.st_mtime, mtime);
238 static int check_nlink(
const char *path, nlink_t nlink)
241 int res = lstat(path, &stbuf);
246 if (stbuf.st_nlink != nlink) {
247 ERROR(
"nlink %li instead of %li", (
long) stbuf.st_nlink,
254 static int fcheck_nlink(
int fd, nlink_t nlink)
257 int res = fstat(fd, &stbuf);
262 if (stbuf.st_nlink != nlink) {
263 ERROR(
"nlink %li instead of %li", (
long) stbuf.st_nlink,
270 static int check_nonexist(
const char *path)
273 int res = lstat(path, &stbuf);
275 ERROR(
"file should not exist");
278 if (errno != ENOENT) {
279 ERROR(
"file should not exist: %s", strerror(errno));
285 static int check_buffer(
const char *buf,
const char *data,
unsigned len)
287 if (memcmp(buf, data, len) != 0) {
288 ERROR(
"data mismatch");
294 static int check_data(
const char *path,
const char *data,
int offset,
299 int fd = open(path, O_RDONLY);
304 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
310 int rdlen = len <
sizeof(buf) ? len :
sizeof(buf);
311 res = read(fd, buf, rdlen);
318 ERROR(
"short read: %u instead of %u", res, rdlen);
322 if (check_buffer(buf, data, rdlen) != 0) {
337 static int fcheck_data(
int fd,
const char *data,
int offset,
342 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
347 int rdlen = len <
sizeof(buf) ? len :
sizeof(buf);
348 res = read(fd, buf, rdlen);
354 ERROR(
"short read: %u instead of %u", res, rdlen);
357 if (check_buffer(buf, data, rdlen) != 0) {
366 static int check_dir_contents(
const char *path,
const char **contents)
371 int found[MAX_ENTRIES];
372 const char *cont[MAX_ENTRIES];
375 for (i = 0; contents[i]; i++) {
376 assert(i < MAX_ENTRIES - 3);
378 cont[i] = contents[i];
391 memset(found, 0,
sizeof(found));
404 for (i = 0; cont[i] != NULL; i++) {
405 assert(i < MAX_ENTRIES);
406 if (strcmp(cont[i], de->d_name) == 0) {
408 ERROR(
"duplicate entry <%s>",
417 ERROR(
"unexpected entry <%s>", de->d_name);
421 for (i = 0; cont[i] != NULL; i++) {
423 ERROR(
"missing entry <%s>", cont[i]);
438 static int create_file(
const char *path,
const char *data,
int len)
444 fd = creat(path, 0644);
450 res = write(fd, data, len);
457 ERROR(
"write is short: %u instead of %u", res, len);
467 res = check_type(path, S_IFREG);
470 res = check_mode(path, 0644);
473 res = check_nlink(path, 1);
476 res = check_size(path, len);
481 res = check_data(path, data, 0, len);
489 static int cleanup_dir(
const char *path,
const char **dir_files,
int quiet)
494 for (i = 0; dir_files[i]; i++) {
497 sprintf(fpath,
"%s/%s", path, dir_files[i]);
499 if (res == -1 && !quiet) {
510 static int create_dir(
const char *path,
const char **dir_files)
516 res = mkdir(path, 0755);
521 res = check_type(path, S_IFDIR);
524 res = check_mode(path, 0755);
528 for (i = 0; dir_files[i]; i++) {
530 sprintf(fpath,
"%s/%s", path, dir_files[i]);
531 res = create_file(fpath,
"", 0);
533 cleanup_dir(path, dir_files, 1);
537 res = check_dir_contents(path, dir_files);
539 cleanup_dir(path, dir_files, 1);
546 static int test_truncate(
int len)
548 const char *data = testdata;
549 int datalen = testdatalen;
552 start_test(
"truncate(%u)", (
int) len);
553 res = create_file(testfile, data, datalen);
557 res = truncate(testfile, len);
562 res = check_size(testfile, len);
567 if (len <= datalen) {
568 res = check_data(testfile, data, 0, len);
572 res = check_data(testfile, data, 0, datalen);
575 res = check_data(testfile, zerodata, datalen,
581 res = unlink(testfile);
586 res = check_nonexist(testfile);
594 static int test_ftruncate(
int len,
int mode)
596 const char *data = testdata;
597 int datalen = testdatalen;
601 start_test(
"ftruncate(%u) mode: 0%03o", len, mode);
602 res = create_file(testfile, data, datalen);
606 fd = open(testfile, O_WRONLY);
612 res = fchmod(fd, mode);
618 res = check_mode(testfile, mode);
623 res = ftruncate(fd, len);
630 res = check_size(testfile, len);
635 if (len <= datalen) {
636 res = check_data(testfile, data, 0, len);
640 res = check_data(testfile, data, 0, datalen);
643 res = check_data(testfile, zerodata, datalen,
649 res = unlink(testfile);
654 res = check_nonexist(testfile);
662 static int test_seekdir(
void)
669 start_test(
"seekdir");
670 res = create_dir(testdir, testdir_files);
674 dp = opendir(testdir);
681 for (i = 0; i < ARRAY_SIZE(seekdir_offsets); i++) {
682 seekdir_offsets[i] = telldir(dp);
699 for (i--; i >= 0; i--) {
700 seekdir(dp, seekdir_offsets[i]);
703 ERROR(
"Unexpected end of directory after seekdir()");
709 res = cleanup_dir(testdir, testdir_files, 0);
715 cleanup_dir(testdir, testdir_files, 1);
719 #ifdef HAVE_COPY_FILE_RANGE 720 static int test_copy_file_range(
void)
722 const char *data = testdata;
723 int datalen = testdatalen;
727 off_t pos_in = 0, pos_out = 0;
729 start_test(
"copy_file_range");
731 fd_in = open(testfile, O_CREAT | O_RDWR, 0644);
736 res = write(fd_in, data, datalen);
742 if (res != datalen) {
743 ERROR(
"write is short: %u instead of %u", res, datalen);
749 fd_out = creat(testfile2, 0644);
755 res = copy_file_range(fd_in, &pos_in, fd_out, &pos_out, datalen, 0);
757 PERROR(
"copy_file_range");
762 if (res != datalen) {
763 ERROR(
"copy is short: %u instead of %u", res, datalen);
780 err = check_data(testfile2, data, 0, datalen);
782 res = unlink(testfile);
787 res = check_nonexist(testfile);
793 res = unlink(testfile2);
798 res = check_nonexist(testfile2);
808 static int test_copy_file_range(
void)
814 static int test_utime(
void)
817 time_t atime = 987631200;
818 time_t mtime = 123116400;
822 res = create_file(testfile, NULL, 0);
828 res = utime(testfile, &utm);
833 res = check_times(testfile, atime, mtime);
837 res = unlink(testfile);
842 res = check_nonexist(testfile);
850 static int test_create(
void)
852 const char *data = testdata;
853 int datalen = testdatalen;
858 start_test(
"create");
860 fd = creat(testfile, 0644);
865 res = write(fd, data, datalen);
871 if (res != datalen) {
872 ERROR(
"write is short: %u instead of %u", res, datalen);
881 res = check_type(testfile, S_IFREG);
884 err += check_mode(testfile, 0644);
885 err += check_nlink(testfile, 1);
886 err += check_size(testfile, datalen);
887 err += check_data(testfile, data, 0, datalen);
888 res = unlink(testfile);
893 res = check_nonexist(testfile);
903 static int test_create_unlink(
void)
905 const char *data = testdata;
906 int datalen = testdatalen;
911 start_test(
"create+unlink");
913 fd = open(testfile, O_CREAT | O_RDWR | O_TRUNC, 0644);
918 res = unlink(testfile);
924 res = check_nonexist(testfile);
927 res = write(fd, data, datalen);
933 if (res != datalen) {
934 ERROR(
"write is short: %u instead of %u", res, datalen);
938 err += fcheck_type(fd, S_IFREG);
939 err += fcheck_mode(fd, 0644);
940 err += fcheck_nlink(fd, 0);
941 err += fcheck_size(fd, datalen);
942 err += fcheck_data(fd, data, 0, datalen);
956 static int test_mknod(
void)
963 res = mknod(testfile, 0644, 0);
968 res = check_type(testfile, S_IFREG);
971 err += check_mode(testfile, 0644);
972 err += check_nlink(testfile, 1);
973 err += check_size(testfile, 0);
974 res = unlink(testfile);
979 res = check_nonexist(testfile);
990 #define test_open(exist, flags, mode) do_test_open(exist, flags, #flags, mode) 992 static int do_test_open(
int exist,
int flags,
const char *flags_str,
int mode)
995 const char *data = testdata;
996 int datalen = testdatalen;
997 unsigned currlen = 0;
1003 start_test(
"open(%s, %s, 0%03o)", exist ?
"+" :
"-", flags_str, mode);
1006 res = create_file(testfile_r, testdata2, testdata2len);
1010 currlen = testdata2len;
1013 fd = open(testfile, flags, mode);
1014 if ((flags & O_CREAT) && (flags & O_EXCL) && exist) {
1016 ERROR(
"open should have failed");
1019 }
else if (errno == EEXIST)
1022 if (!(flags & O_CREAT) && !exist) {
1024 ERROR(
"open should have failed");
1027 }
else if (errno == ENOENT)
1035 if (flags & O_TRUNC)
1038 err += check_type(testfile, S_IFREG);
1040 err += check_mode(testfile, 0644);
1042 err += check_mode(testfile, mode);
1043 err += check_nlink(testfile, 1);
1044 err += check_size(testfile, currlen);
1045 if (exist && !(flags & O_TRUNC) && (mode & S_IRUSR))
1046 err += check_data(testfile, testdata2, 0, testdata2len);
1048 res = write(fd, data, datalen);
1049 if ((flags & O_ACCMODE) != O_RDONLY) {
1053 }
else if (res != datalen) {
1054 ERROR(
"write is short: %u instead of %u", res, datalen);
1057 if (datalen > (
int) currlen)
1060 err += check_size(testfile, currlen);
1062 if (mode & S_IRUSR) {
1063 err += check_data(testfile, data, 0, datalen);
1064 if (exist && !(flags & O_TRUNC) &&
1065 testdata2len > datalen)
1066 err += check_data(testfile,
1067 testdata2 + datalen,
1069 testdata2len - datalen);
1074 ERROR(
"write should have failed");
1076 }
else if (errno != EBADF) {
1081 off = lseek(fd, SEEK_SET, 0);
1082 if (off == (off_t) -1) {
1085 }
else if (off != 0) {
1086 ERROR(
"offset should have returned 0");
1089 res = read(fd, buf,
sizeof(buf));
1090 if ((flags & O_ACCMODE) != O_WRONLY) {
1096 currlen <
sizeof(buf) ? currlen :
sizeof(buf);
1097 if (res != readsize) {
1098 ERROR(
"read is short: %i instead of %u",
1102 if ((flags & O_ACCMODE) != O_RDONLY) {
1103 err += check_buffer(buf, data, datalen);
1104 if (exist && !(flags & O_TRUNC) &&
1105 testdata2len > datalen)
1106 err += check_buffer(buf + datalen,
1107 testdata2 + datalen,
1108 testdata2len - datalen);
1110 err += check_buffer(buf, testdata2,
1116 ERROR(
"read should have failed");
1118 }
else if (errno != EBADF) {
1129 res = unlink(testfile);
1134 res = check_nonexist(testfile);
1137 res = check_nonexist(testfile_r);
1148 #define test_open_acc(flags, mode, err) \ 1149 do_test_open_acc(flags, #flags, mode, err) 1151 static int do_test_open_acc(
int flags,
const char *flags_str,
int mode,
int err)
1153 const char *data = testdata;
1154 int datalen = testdatalen;
1158 start_test(
"open_acc(%s) mode: 0%03o message: '%s'", flags_str, mode,
1161 res = create_file(testfile, data, datalen);
1165 res = chmod(testfile, mode);
1171 res = check_mode(testfile, mode);
1175 fd = open(testfile, flags);
1183 ERROR(
"open should have failed");
1193 static int test_symlink(
void)
1196 const char *data = testdata;
1197 int datalen = testdatalen;
1198 int linklen = strlen(testfile);
1202 start_test(
"symlink");
1203 res = create_file(testfile, data, datalen);
1208 res = symlink(testfile, testfile2);
1213 res = check_type(testfile2, S_IFLNK);
1216 err += check_mode(testfile2, 0777);
1217 err += check_nlink(testfile2, 1);
1218 res = readlink(testfile2, buf,
sizeof(buf));
1223 if (res != linklen) {
1224 ERROR(
"short readlink: %u instead of %u", res, linklen);
1227 if (memcmp(buf, testfile, linklen) != 0) {
1228 ERROR(
"link mismatch");
1231 err += check_size(testfile2, datalen);
1232 err += check_data(testfile2, data, 0, datalen);
1233 res = unlink(testfile2);
1238 res = check_nonexist(testfile2);
1248 static int test_link(
void)
1250 const char *data = testdata;
1251 int datalen = testdatalen;
1256 res = create_file(testfile, data, datalen);
1261 res = link(testfile, testfile2);
1266 res = check_type(testfile2, S_IFREG);
1269 err += check_mode(testfile2, 0644);
1270 err += check_nlink(testfile2, 2);
1271 err += check_size(testfile2, datalen);
1272 err += check_data(testfile2, data, 0, datalen);
1273 res = unlink(testfile);
1278 res = check_nonexist(testfile);
1282 err += check_nlink(testfile2, 1);
1283 res = unlink(testfile2);
1288 res = check_nonexist(testfile2);
1298 static int test_link2(
void)
1300 const char *data = testdata;
1301 int datalen = testdatalen;
1305 start_test(
"link-unlink-link");
1306 res = create_file(testfile, data, datalen);
1311 res = link(testfile, testfile2);
1316 res = unlink(testfile);
1321 res = check_nonexist(testfile);
1324 res = link(testfile2, testfile);
1328 res = check_type(testfile, S_IFREG);
1331 err += check_mode(testfile, 0644);
1332 err += check_nlink(testfile, 2);
1333 err += check_size(testfile, datalen);
1334 err += check_data(testfile, data, 0, datalen);
1336 res = unlink(testfile2);
1341 err += check_nlink(testfile, 1);
1342 res = unlink(testfile);
1347 res = check_nonexist(testfile);
1357 static int test_rename_file(
void)
1359 const char *data = testdata;
1360 int datalen = testdatalen;
1364 start_test(
"rename file");
1365 res = create_file(testfile, data, datalen);
1370 res = rename(testfile, testfile2);
1375 res = check_nonexist(testfile);
1378 res = check_type(testfile2, S_IFREG);
1381 err += check_mode(testfile2, 0644);
1382 err += check_nlink(testfile2, 1);
1383 err += check_size(testfile2, datalen);
1384 err += check_data(testfile2, data, 0, datalen);
1385 res = unlink(testfile2);
1390 res = check_nonexist(testfile2);
1400 static int test_rename_dir(
void)
1405 start_test(
"rename dir");
1406 res = create_dir(testdir, testdir_files);
1411 res = rename(testdir, testdir2);
1414 cleanup_dir(testdir, testdir_files, 1);
1417 res = check_nonexist(testdir);
1419 cleanup_dir(testdir, testdir_files, 1);
1422 res = check_type(testdir2, S_IFDIR);
1424 cleanup_dir(testdir2, testdir_files, 1);
1427 err += check_mode(testdir2, 0755);
1428 err += check_dir_contents(testdir2, testdir_files);
1429 err += cleanup_dir(testdir2, testdir_files, 0);
1430 res = rmdir(testdir2);
1435 res = check_nonexist(testdir2);
1445 static int test_rename_dir_loop(
void)
1447 #define PATH(p) (snprintf(path, sizeof path, "%s/%s", testdir, p), path) 1448 #define PATH2(p) (snprintf(path2, sizeof path2, "%s/%s", testdir, p), path2) 1450 char path[1280], path2[1280];
1454 start_test(
"rename dir loop");
1456 res = create_dir(testdir, testdir_files);
1460 res = mkdir(PATH(
"a"), 0755);
1466 res = rename(PATH(
"a"), PATH2(
"a"));
1473 res = rename(PATH(
"a"), PATH2(
"a/b"));
1474 if (res == 0 || errno != EINVAL) {
1479 res = mkdir(PATH(
"a/b"), 0755);
1485 res = mkdir(PATH(
"a/b/c"), 0755);
1492 res = rename(PATH(
"a"), PATH2(
"a/b/c"));
1493 if (res == 0 || errno != EINVAL) {
1499 res = rename(PATH(
"a"), PATH2(
"a/b/c/a"));
1500 if (res == 0 || errno != EINVAL) {
1506 res = rename(PATH(
"a/b/c"), PATH2(
"a"));
1507 if (res == 0 || errno != ENOTEMPTY) {
1512 res = open(PATH(
"a/foo"), O_CREAT, 0644);
1519 res = rename(PATH(
"a/foo"), PATH2(
"a/bar"));
1525 res = rename(PATH(
"a/bar"), PATH2(
"a/foo"));
1531 res = rename(PATH(
"a/foo"), PATH2(
"a/b/bar"));
1537 res = rename(PATH(
"a/b/bar"), PATH2(
"a/foo"));
1543 res = rename(PATH(
"a/foo"), PATH2(
"a/b/c/bar"));
1549 res = rename(PATH(
"a/b/c/bar"), PATH2(
"a/foo"));
1555 res = open(PATH(
"a/bar"), O_CREAT, 0644);
1562 res = rename(PATH(
"a/foo"), PATH2(
"a/bar"));
1568 unlink(PATH(
"a/bar"));
1570 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1576 res = rename(PATH(
"a/d"), PATH2(
"a/b"));
1582 res = mkdir(PATH(
"a/d"), 0755);
1588 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1594 res = rename(PATH(
"a/d"), PATH2(
"a/b"));
1600 res = mkdir(PATH(
"a/d"), 0755);
1606 res = mkdir(PATH(
"a/d/e"), 0755);
1613 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1614 if (res == 0 || errno != ENOTEMPTY) {
1619 rmdir(PATH(
"a/d/e"));
1622 rmdir(PATH(
"a/b/c"));
1626 err += cleanup_dir(testdir, testdir_files, 0);
1627 res = rmdir(testdir);
1632 res = check_nonexist(testdir);
1642 unlink(PATH(
"a/bar"));
1644 rmdir(PATH(
"a/d/e"));
1647 rmdir(PATH(
"a/b/c"));
1651 cleanup_dir(testdir, testdir_files, 1);
1661 static int test_mkfifo(
void)
1666 start_test(
"mkfifo");
1668 res = mkfifo(testfile, 0644);
1673 res = check_type(testfile, S_IFIFO);
1676 err += check_mode(testfile, 0644);
1677 err += check_nlink(testfile, 1);
1678 res = unlink(testfile);
1683 res = check_nonexist(testfile);
1694 static int test_mkdir(
void)
1698 const char *dir_contents[] = {NULL};
1700 start_test(
"mkdir");
1702 res = mkdir(testdir, 0755);
1707 res = check_type(testdir, S_IFDIR);
1710 err += check_mode(testdir, 0755);
1714 err += check_dir_contents(testdir, dir_contents);
1715 res = rmdir(testdir);
1720 res = check_nonexist(testdir);
1730 #define test_create_ro_dir(flags) \ 1731 do_test_create_ro_dir(flags, #flags) 1733 static int do_test_create_ro_dir(
int flags,
const char *flags_str)
1739 start_test(
"open(%s) in read-only directory", flags_str);
1741 res = mkdir(testdir, 0555);
1746 fd = open(subfile, flags, 0644);
1750 ERROR(
"open should have failed");
1753 res = check_nonexist(subfile);
1758 res = rmdir(testdir);
1763 res = check_nonexist(testdir);
1773 int main(
int argc,
char *argv[])
1775 const char *basepath;
1776 const char *realpath;
1782 if (argc < 2 || argc > 4) {
1783 fprintf(stderr,
"usage: %s testdir [:realdir] [[-]test#]\n", argv[0]);
1787 realpath = basepath;
1788 for (a = 2; a < argc; a++) {
1790 char *arg = argv[a];
1791 if (arg[0] ==
':') {
1794 if (arg[0] ==
'-') {
1796 skip_test = strtoul(arg, &endptr, 10);
1798 select_test = strtoul(arg, &endptr, 10);
1800 if (arg[0] ==
'\0' || *endptr !=
'\0') {
1801 fprintf(stderr,
"invalid number: '%s'\n", arg);
1806 assert(strlen(basepath) < 512);
1807 assert(strlen(realpath) < 512);
1808 if (basepath[0] !=
'/') {
1809 fprintf(stderr,
"testdir must be an absolute path\n");
1813 sprintf(testfile,
"%s/testfile", basepath);
1814 sprintf(testfile2,
"%s/testfile2", basepath);
1815 sprintf(testdir,
"%s/testdir", basepath);
1816 sprintf(testdir2,
"%s/testdir2", basepath);
1817 sprintf(subfile,
"%s/subfile", testdir2);
1819 sprintf(testfile_r,
"%s/testfile", realpath);
1820 sprintf(testfile2_r,
"%s/testfile2", realpath);
1821 sprintf(testdir_r,
"%s/testdir", realpath);
1822 sprintf(testdir2_r,
"%s/testdir2", realpath);
1823 sprintf(subfile_r,
"%s/subfile", testdir2_r);
1825 is_root = (geteuid() == 0);
1827 err += test_create();
1828 err += test_create_unlink();
1829 err += test_symlink();
1831 err += test_link2();
1833 err += test_mknod();
1834 err += test_mkfifo();
1836 err += test_mkdir();
1837 err += test_rename_file();
1838 err += test_rename_dir();
1839 err += test_rename_dir_loop();
1840 err += test_seekdir();
1841 err += test_utime();
1842 err += test_truncate(0);
1843 err += test_truncate(testdatalen / 2);
1844 err += test_truncate(testdatalen);
1845 err += test_truncate(testdatalen + 100);
1846 err += test_ftruncate(0, 0600);
1847 err += test_ftruncate(testdatalen / 2, 0600);
1848 err += test_ftruncate(testdatalen, 0600);
1849 err += test_ftruncate(testdatalen + 100, 0600);
1850 err += test_ftruncate(0, 0400);
1851 err += test_ftruncate(0, 0200);
1852 err += test_ftruncate(0, 0000);
1853 err += test_open(0, O_RDONLY, 0);
1854 err += test_open(1, O_RDONLY, 0);
1855 err += test_open(1, O_RDWR, 0);
1856 err += test_open(1, O_WRONLY, 0);
1857 err += test_open(0, O_RDWR | O_CREAT, 0600);
1858 err += test_open(1, O_RDWR | O_CREAT, 0600);
1859 err += test_open(0, O_RDWR | O_CREAT | O_TRUNC, 0600);
1860 err += test_open(1, O_RDWR | O_CREAT | O_TRUNC, 0600);
1861 err += test_open(0, O_RDONLY | O_CREAT, 0600);
1862 err += test_open(0, O_RDONLY | O_CREAT, 0400);
1863 err += test_open(0, O_RDONLY | O_CREAT, 0200);
1864 err += test_open(0, O_RDONLY | O_CREAT, 0000);
1865 err += test_open(0, O_WRONLY | O_CREAT, 0600);
1866 err += test_open(0, O_WRONLY | O_CREAT, 0400);
1867 err += test_open(0, O_WRONLY | O_CREAT, 0200);
1868 err += test_open(0, O_WRONLY | O_CREAT, 0000);
1869 err += test_open(0, O_RDWR | O_CREAT, 0400);
1870 err += test_open(0, O_RDWR | O_CREAT, 0200);
1871 err += test_open(0, O_RDWR | O_CREAT, 0000);
1872 err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0600);
1873 err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0600);
1874 err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0000);
1875 err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0000);
1876 err += test_open_acc(O_RDONLY, 0600, 0);
1877 err += test_open_acc(O_WRONLY, 0600, 0);
1878 err += test_open_acc(O_RDWR, 0600, 0);
1879 err += test_open_acc(O_RDONLY, 0400, 0);
1880 err += test_open_acc(O_WRONLY, 0200, 0);
1882 err += test_open_acc(O_RDONLY | O_TRUNC, 0400, EACCES);
1883 err += test_open_acc(O_WRONLY, 0400, EACCES);
1884 err += test_open_acc(O_RDWR, 0400, EACCES);
1885 err += test_open_acc(O_RDONLY, 0200, EACCES);
1886 err += test_open_acc(O_RDWR, 0200, EACCES);
1887 err += test_open_acc(O_RDONLY, 0000, EACCES);
1888 err += test_open_acc(O_WRONLY, 0000, EACCES);
1889 err += test_open_acc(O_RDWR, 0000, EACCES);
1891 err += test_create_ro_dir(O_CREAT);
1892 err += test_create_ro_dir(O_CREAT | O_EXCL);
1893 err += test_create_ro_dir(O_CREAT | O_WRONLY);
1894 err += test_create_ro_dir(O_CREAT | O_TRUNC);
1895 err += test_copy_file_range();
1903 fprintf(stderr,
"%i tests failed\n", -err);