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[1024];
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[1024];
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 & 07777) != mode) {
167 ERROR(
"mode 0%o instead of 0%o", stbuf.st_mode & 07777, mode);
173 static int fcheck_mode(
int fd, mode_t mode)
176 int res = fstat(fd, &stbuf);
181 if ((stbuf.st_mode & 07777) != mode) {
182 ERROR(
"mode 0%o instead of 0%o", stbuf.st_mode & 07777, mode);
188 static int check_times(
const char *path, time_t atime, time_t mtime)
192 int res = lstat(path, &stbuf);
197 if (stbuf.st_atime != atime) {
198 ERROR(
"atime %li instead of %li", stbuf.st_atime, atime);
201 if (stbuf.st_mtime != mtime) {
202 ERROR(
"mtime %li instead of %li", stbuf.st_mtime, mtime);
212 static int fcheck_times(
int fd, time_t atime, time_t mtime)
216 int res = fstat(fd, &stbuf);
221 if (stbuf.st_atime != atime) {
222 ERROR(
"atime %li instead of %li", stbuf.st_atime, atime);
225 if (stbuf.st_mtime != mtime) {
226 ERROR(
"mtime %li instead of %li", stbuf.st_mtime, mtime);
236 static int check_nlink(
const char *path, nlink_t nlink)
239 int res = lstat(path, &stbuf);
244 if (stbuf.st_nlink != nlink) {
245 ERROR(
"nlink %li instead of %li", (
long) stbuf.st_nlink,
252 static int fcheck_nlink(
int fd, nlink_t nlink)
255 int res = fstat(fd, &stbuf);
260 if (stbuf.st_nlink != nlink) {
261 ERROR(
"nlink %li instead of %li", (
long) stbuf.st_nlink,
268 static int check_nonexist(
const char *path)
271 int res = lstat(path, &stbuf);
273 ERROR(
"file should not exist");
276 if (errno != ENOENT) {
277 ERROR(
"file should not exist: %s", strerror(errno));
283 static int check_buffer(
const char *buf,
const char *data,
unsigned len)
285 if (memcmp(buf, data, len) != 0) {
286 ERROR(
"data mismatch");
292 static int check_data(
const char *path,
const char *data,
int offset,
297 int fd = open(path, O_RDONLY);
302 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
308 int rdlen = len <
sizeof(buf) ? len :
sizeof(buf);
309 res = read(fd, buf, rdlen);
316 ERROR(
"short read: %u instead of %u", res, rdlen);
320 if (check_buffer(buf, data, rdlen) != 0) {
335 static int fcheck_data(
int fd,
const char *data,
int offset,
340 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
345 int rdlen = len <
sizeof(buf) ? len :
sizeof(buf);
346 res = read(fd, buf, rdlen);
352 ERROR(
"short read: %u instead of %u", res, rdlen);
355 if (check_buffer(buf, data, rdlen) != 0) {
364 static int check_dir_contents(
const char *path,
const char **contents)
369 int found[MAX_ENTRIES];
370 const char *cont[MAX_ENTRIES];
373 for (i = 0; contents[i]; i++) {
374 assert(i < MAX_ENTRIES - 3);
376 cont[i] = contents[i];
389 memset(found, 0,
sizeof(found));
402 for (i = 0; cont[i] != NULL; i++) {
403 assert(i < MAX_ENTRIES);
404 if (strcmp(cont[i], de->d_name) == 0) {
406 ERROR(
"duplicate entry <%s>",
415 ERROR(
"unexpected entry <%s>", de->d_name);
419 for (i = 0; cont[i] != NULL; i++) {
421 ERROR(
"missing entry <%s>", cont[i]);
436 static int create_file(
const char *path,
const char *data,
int len)
442 fd = creat(path, 0644);
448 res = write(fd, data, len);
455 ERROR(
"write is short: %u instead of %u", res, len);
465 res = check_type(path, S_IFREG);
468 res = check_mode(path, 0644);
471 res = check_nlink(path, 1);
474 res = check_size(path, len);
479 res = check_data(path, data, 0, len);
487 static int cleanup_dir(
const char *path,
const char **dir_files,
int quiet)
492 for (i = 0; dir_files[i]; i++) {
495 sprintf(fpath,
"%s/%s", path, dir_files[i]);
497 if (res == -1 && !quiet) {
508 static int create_dir(
const char *path,
const char **dir_files)
514 res = mkdir(path, 0755);
519 res = check_type(path, S_IFDIR);
522 res = check_mode(path, 0755);
526 for (i = 0; dir_files[i]; i++) {
528 sprintf(fpath,
"%s/%s", path, dir_files[i]);
529 res = create_file(fpath,
"", 0);
531 cleanup_dir(path, dir_files, 1);
535 res = check_dir_contents(path, dir_files);
537 cleanup_dir(path, dir_files, 1);
544 static int test_truncate(
int len)
546 const char *data = testdata;
547 int datalen = testdatalen;
550 start_test(
"truncate(%u)", (
int) len);
551 res = create_file(testfile, data, datalen);
555 res = truncate(testfile, len);
560 res = check_size(testfile, len);
565 if (len <= datalen) {
566 res = check_data(testfile, data, 0, len);
570 res = check_data(testfile, data, 0, datalen);
573 res = check_data(testfile, zerodata, datalen,
579 res = unlink(testfile);
584 res = check_nonexist(testfile);
592 static int test_ftruncate(
int len,
int mode)
594 const char *data = testdata;
595 int datalen = testdatalen;
599 start_test(
"ftruncate(%u) mode: 0%03o", len, mode);
600 res = create_file(testfile, data, datalen);
604 fd = open(testfile, O_WRONLY);
610 res = fchmod(fd, mode);
616 res = check_mode(testfile, mode);
621 res = ftruncate(fd, len);
628 res = check_size(testfile, len);
633 if (len <= datalen) {
634 res = check_data(testfile, data, 0, len);
638 res = check_data(testfile, data, 0, datalen);
641 res = check_data(testfile, zerodata, datalen,
647 res = unlink(testfile);
652 res = check_nonexist(testfile);
660 static int test_seekdir(
void)
667 start_test(
"seekdir");
668 res = create_dir(testdir, testdir_files);
672 dp = opendir(testdir);
679 for (i = 0; i < ARRAY_SIZE(seekdir_offsets); i++) {
680 seekdir_offsets[i] = telldir(dp);
697 for (i--; i >= 0; i--) {
698 seekdir(dp, seekdir_offsets[i]);
701 ERROR(
"Unexpected end of directory after seekdir()");
707 res = cleanup_dir(testdir, testdir_files, 0);
713 cleanup_dir(testdir, testdir_files, 1);
717 #ifdef HAVE_COPY_FILE_RANGE 718 static int test_copy_file_range(
void)
720 const char *data = testdata;
721 int datalen = testdatalen;
725 off_t pos_in = 0, pos_out = 0;
727 start_test(
"copy_file_range");
729 fd_in = open(testfile, O_CREAT | O_RDWR, 0644);
734 res = write(fd_in, data, datalen);
740 if (res != datalen) {
741 ERROR(
"write is short: %u instead of %u", res, datalen);
747 fd_out = creat(testfile2, 0644);
753 res = copy_file_range(fd_in, &pos_in, fd_out, &pos_out, datalen, 0);
755 PERROR(
"copy_file_range");
760 if (res != datalen) {
761 ERROR(
"copy is short: %u instead of %u", res, datalen);
778 err = check_data(testfile2, data, 0, datalen);
780 res = unlink(testfile);
785 res = check_nonexist(testfile);
791 res = unlink(testfile2);
796 res = check_nonexist(testfile2);
806 static int test_copy_file_range(
void)
812 static int test_utime(
void)
815 time_t atime = 987631200;
816 time_t mtime = 123116400;
820 res = create_file(testfile, NULL, 0);
826 res = utime(testfile, &utm);
831 res = check_times(testfile, atime, mtime);
835 res = unlink(testfile);
840 res = check_nonexist(testfile);
848 static int test_create(
void)
850 const char *data = testdata;
851 int datalen = testdatalen;
856 start_test(
"create");
858 fd = creat(testfile, 0644);
863 res = write(fd, data, datalen);
869 if (res != datalen) {
870 ERROR(
"write is short: %u instead of %u", res, datalen);
879 res = check_type(testfile, S_IFREG);
882 err += check_mode(testfile, 0644);
883 err += check_nlink(testfile, 1);
884 err += check_size(testfile, datalen);
885 err += check_data(testfile, data, 0, datalen);
886 res = unlink(testfile);
891 res = check_nonexist(testfile);
901 static int test_create_unlink(
void)
903 const char *data = testdata;
904 int datalen = testdatalen;
909 start_test(
"create+unlink");
911 fd = open(testfile, O_CREAT | O_RDWR | O_TRUNC, 0644);
916 res = unlink(testfile);
922 res = check_nonexist(testfile);
925 res = write(fd, data, datalen);
931 if (res != datalen) {
932 ERROR(
"write is short: %u instead of %u", res, datalen);
936 err += fcheck_type(fd, S_IFREG);
937 err += fcheck_mode(fd, 0644);
938 err += fcheck_nlink(fd, 0);
939 err += fcheck_size(fd, datalen);
940 err += fcheck_data(fd, data, 0, datalen);
954 static int test_mknod(
void)
961 res = mknod(testfile, 0644, 0);
966 res = check_type(testfile, S_IFREG);
969 err += check_mode(testfile, 0644);
970 err += check_nlink(testfile, 1);
971 err += check_size(testfile, 0);
972 res = unlink(testfile);
977 res = check_nonexist(testfile);
988 #define test_open(exist, flags, mode) do_test_open(exist, flags, #flags, mode) 990 static int do_test_open(
int exist,
int flags,
const char *flags_str,
int mode)
993 const char *data = testdata;
994 int datalen = testdatalen;
995 unsigned currlen = 0;
1001 start_test(
"open(%s, %s, 0%03o)", exist ?
"+" :
"-", flags_str, mode);
1004 res = create_file(testfile_r, testdata2, testdata2len);
1008 currlen = testdata2len;
1011 fd = open(testfile, flags, mode);
1012 if ((flags & O_CREAT) && (flags & O_EXCL) && exist) {
1014 ERROR(
"open should have failed");
1017 }
else if (errno == EEXIST)
1020 if (!(flags & O_CREAT) && !exist) {
1022 ERROR(
"open should have failed");
1025 }
else if (errno == ENOENT)
1033 if (flags & O_TRUNC)
1036 err += check_type(testfile, S_IFREG);
1038 err += check_mode(testfile, 0644);
1040 err += check_mode(testfile, mode);
1041 err += check_nlink(testfile, 1);
1042 err += check_size(testfile, currlen);
1043 if (exist && !(flags & O_TRUNC) && (mode & 0400))
1044 err += check_data(testfile, testdata2, 0, testdata2len);
1046 res = write(fd, data, datalen);
1047 if ((flags & O_ACCMODE) != O_RDONLY) {
1051 }
else if (res != datalen) {
1052 ERROR(
"write is short: %u instead of %u", res, datalen);
1055 if (datalen > (
int) currlen)
1058 err += check_size(testfile, currlen);
1061 err += check_data(testfile, data, 0, datalen);
1062 if (exist && !(flags & O_TRUNC) &&
1063 testdata2len > datalen)
1064 err += check_data(testfile,
1065 testdata2 + datalen,
1067 testdata2len - datalen);
1072 ERROR(
"write should have failed");
1074 }
else if (errno != EBADF) {
1079 off = lseek(fd, SEEK_SET, 0);
1080 if (off == (off_t) -1) {
1083 }
else if (off != 0) {
1084 ERROR(
"offset should have returned 0");
1087 res = read(fd, buf,
sizeof(buf));
1088 if ((flags & O_ACCMODE) != O_WRONLY) {
1094 currlen <
sizeof(buf) ? currlen :
sizeof(buf);
1095 if (res != readsize) {
1096 ERROR(
"read is short: %i instead of %u",
1100 if ((flags & O_ACCMODE) != O_RDONLY) {
1101 err += check_buffer(buf, data, datalen);
1102 if (exist && !(flags & O_TRUNC) &&
1103 testdata2len > datalen)
1104 err += check_buffer(buf + datalen,
1105 testdata2 + datalen,
1106 testdata2len - datalen);
1108 err += check_buffer(buf, testdata2,
1114 ERROR(
"read should have failed");
1116 }
else if (errno != EBADF) {
1127 res = unlink(testfile);
1132 res = check_nonexist(testfile);
1135 res = check_nonexist(testfile_r);
1146 #define test_open_acc(flags, mode, err) \ 1147 do_test_open_acc(flags, #flags, mode, err) 1149 static int do_test_open_acc(
int flags,
const char *flags_str,
int mode,
int err)
1151 const char *data = testdata;
1152 int datalen = testdatalen;
1156 start_test(
"open_acc(%s) mode: 0%03o message: '%s'", flags_str, mode,
1159 res = create_file(testfile, data, datalen);
1163 res = chmod(testfile, mode);
1169 res = check_mode(testfile, mode);
1173 fd = open(testfile, flags);
1181 ERROR(
"open should have failed");
1191 static int test_symlink(
void)
1194 const char *data = testdata;
1195 int datalen = testdatalen;
1196 int linklen = strlen(testfile);
1200 start_test(
"symlink");
1201 res = create_file(testfile, data, datalen);
1206 res = symlink(testfile, testfile2);
1211 res = check_type(testfile2, S_IFLNK);
1214 err += check_mode(testfile2, 0777);
1215 err += check_nlink(testfile2, 1);
1216 res = readlink(testfile2, buf,
sizeof(buf));
1221 if (res != linklen) {
1222 ERROR(
"short readlink: %u instead of %u", res, linklen);
1225 if (memcmp(buf, testfile, linklen) != 0) {
1226 ERROR(
"link mismatch");
1229 err += check_size(testfile2, datalen);
1230 err += check_data(testfile2, data, 0, datalen);
1231 res = unlink(testfile2);
1236 res = check_nonexist(testfile2);
1246 static int test_link(
void)
1248 const char *data = testdata;
1249 int datalen = testdatalen;
1254 res = create_file(testfile, data, datalen);
1259 res = link(testfile, testfile2);
1264 res = check_type(testfile2, S_IFREG);
1267 err += check_mode(testfile2, 0644);
1268 err += check_nlink(testfile2, 2);
1269 err += check_size(testfile2, datalen);
1270 err += check_data(testfile2, data, 0, datalen);
1271 res = unlink(testfile);
1276 res = check_nonexist(testfile);
1280 err += check_nlink(testfile2, 1);
1281 res = unlink(testfile2);
1286 res = check_nonexist(testfile2);
1296 static int test_link2(
void)
1298 const char *data = testdata;
1299 int datalen = testdatalen;
1303 start_test(
"link-unlink-link");
1304 res = create_file(testfile, data, datalen);
1309 res = link(testfile, testfile2);
1314 res = unlink(testfile);
1319 res = check_nonexist(testfile);
1322 res = link(testfile2, testfile);
1326 res = check_type(testfile, S_IFREG);
1329 err += check_mode(testfile, 0644);
1330 err += check_nlink(testfile, 2);
1331 err += check_size(testfile, datalen);
1332 err += check_data(testfile, data, 0, datalen);
1334 res = unlink(testfile2);
1339 err += check_nlink(testfile, 1);
1340 res = unlink(testfile);
1345 res = check_nonexist(testfile);
1355 static int test_rename_file(
void)
1357 const char *data = testdata;
1358 int datalen = testdatalen;
1362 start_test(
"rename file");
1363 res = create_file(testfile, data, datalen);
1368 res = rename(testfile, testfile2);
1373 res = check_nonexist(testfile);
1376 res = check_type(testfile2, S_IFREG);
1379 err += check_mode(testfile2, 0644);
1380 err += check_nlink(testfile2, 1);
1381 err += check_size(testfile2, datalen);
1382 err += check_data(testfile2, data, 0, datalen);
1383 res = unlink(testfile2);
1388 res = check_nonexist(testfile2);
1398 static int test_rename_dir(
void)
1403 start_test(
"rename dir");
1404 res = create_dir(testdir, testdir_files);
1409 res = rename(testdir, testdir2);
1412 cleanup_dir(testdir, testdir_files, 1);
1415 res = check_nonexist(testdir);
1417 cleanup_dir(testdir, testdir_files, 1);
1420 res = check_type(testdir2, S_IFDIR);
1422 cleanup_dir(testdir2, testdir_files, 1);
1425 err += check_mode(testdir2, 0755);
1426 err += check_dir_contents(testdir2, testdir_files);
1427 err += cleanup_dir(testdir2, testdir_files, 0);
1428 res = rmdir(testdir2);
1433 res = check_nonexist(testdir2);
1443 static int test_rename_dir_loop(
void)
1445 #define PATH(p) (snprintf(path, sizeof path, "%s/%s", testdir, p), path) 1446 #define PATH2(p) (snprintf(path2, sizeof path2, "%s/%s", testdir, p), path2) 1448 char path[1024], path2[1024];
1452 start_test(
"rename dir loop");
1454 res = create_dir(testdir, testdir_files);
1458 res = mkdir(PATH(
"a"), 0755);
1464 res = rename(PATH(
"a"), PATH2(
"a"));
1471 res = rename(PATH(
"a"), PATH2(
"a/b"));
1472 if (res == 0 || errno != EINVAL) {
1477 res = mkdir(PATH(
"a/b"), 0755);
1483 res = mkdir(PATH(
"a/b/c"), 0755);
1490 res = rename(PATH(
"a"), PATH2(
"a/b/c"));
1491 if (res == 0 || errno != EINVAL) {
1497 res = rename(PATH(
"a"), PATH2(
"a/b/c/a"));
1498 if (res == 0 || errno != EINVAL) {
1504 res = rename(PATH(
"a/b/c"), PATH2(
"a"));
1505 if (res == 0 || errno != ENOTEMPTY) {
1510 res = open(PATH(
"a/foo"), O_CREAT, 0644);
1517 res = rename(PATH(
"a/foo"), PATH2(
"a/bar"));
1523 res = rename(PATH(
"a/bar"), PATH2(
"a/foo"));
1529 res = rename(PATH(
"a/foo"), PATH2(
"a/b/bar"));
1535 res = rename(PATH(
"a/b/bar"), PATH2(
"a/foo"));
1541 res = rename(PATH(
"a/foo"), PATH2(
"a/b/c/bar"));
1547 res = rename(PATH(
"a/b/c/bar"), PATH2(
"a/foo"));
1553 res = open(PATH(
"a/bar"), O_CREAT, 0644);
1560 res = rename(PATH(
"a/foo"), PATH2(
"a/bar"));
1566 unlink(PATH(
"a/bar"));
1568 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1574 res = rename(PATH(
"a/d"), PATH2(
"a/b"));
1580 res = mkdir(PATH(
"a/d"), 0755);
1586 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1592 res = rename(PATH(
"a/d"), PATH2(
"a/b"));
1598 res = mkdir(PATH(
"a/d"), 0755);
1604 res = mkdir(PATH(
"a/d/e"), 0755);
1611 res = rename(PATH(
"a/b"), PATH2(
"a/d"));
1612 if (res == 0 || errno != ENOTEMPTY) {
1617 rmdir(PATH(
"a/d/e"));
1620 rmdir(PATH(
"a/b/c"));
1624 err += cleanup_dir(testdir, testdir_files, 0);
1625 res = rmdir(testdir);
1630 res = check_nonexist(testdir);
1640 unlink(PATH(
"a/bar"));
1642 rmdir(PATH(
"a/d/e"));
1645 rmdir(PATH(
"a/b/c"));
1649 cleanup_dir(testdir, testdir_files, 1);
1659 static int test_mkfifo(
void)
1664 start_test(
"mkfifo");
1666 res = mkfifo(testfile, 0644);
1671 res = check_type(testfile, S_IFIFO);
1674 err += check_mode(testfile, 0644);
1675 err += check_nlink(testfile, 1);
1676 res = unlink(testfile);
1681 res = check_nonexist(testfile);
1692 static int test_mkdir(
void)
1696 const char *dir_contents[] = {NULL};
1698 start_test(
"mkdir");
1700 res = mkdir(testdir, 0755);
1705 res = check_type(testdir, S_IFDIR);
1708 err += check_mode(testdir, 0755);
1712 err += check_dir_contents(testdir, dir_contents);
1713 res = rmdir(testdir);
1718 res = check_nonexist(testdir);
1728 #define test_create_ro_dir(flags) \ 1729 do_test_create_ro_dir(flags, #flags) 1731 static int do_test_create_ro_dir(
int flags,
const char *flags_str)
1737 start_test(
"open(%s) in read-only directory", flags_str);
1739 res = mkdir(testdir, 0555);
1744 fd = open(subfile, flags, 0644);
1748 ERROR(
"open should have failed");
1751 res = check_nonexist(subfile);
1756 res = rmdir(testdir);
1761 res = check_nonexist(testdir);
1771 int main(
int argc,
char *argv[])
1773 const char *basepath;
1774 const char *realpath;
1780 if (argc < 2 || argc > 4) {
1781 fprintf(stderr,
"usage: %s testdir [:realdir] [[-]test#]\n", argv[0]);
1785 realpath = basepath;
1786 for (a = 2; a < argc; a++) {
1788 char *arg = argv[a];
1789 if (arg[0] ==
':') {
1792 if (arg[0] ==
'-') {
1794 skip_test = strtoul(arg, &endptr, 10);
1796 select_test = strtoul(arg, &endptr, 10);
1798 if (arg[0] ==
'\0' || *endptr !=
'\0') {
1799 fprintf(stderr,
"invalid number: '%s'\n", arg);
1804 assert(strlen(basepath) < 512);
1805 assert(strlen(realpath) < 512);
1806 if (basepath[0] !=
'/') {
1807 fprintf(stderr,
"testdir must be an absolute path\n");
1811 sprintf(testfile,
"%s/testfile", basepath);
1812 sprintf(testfile2,
"%s/testfile2", basepath);
1813 sprintf(testdir,
"%s/testdir", basepath);
1814 sprintf(testdir2,
"%s/testdir2", basepath);
1815 sprintf(subfile,
"%s/subfile", testdir2);
1817 sprintf(testfile_r,
"%s/testfile", realpath);
1818 sprintf(testfile2_r,
"%s/testfile2", realpath);
1819 sprintf(testdir_r,
"%s/testdir", realpath);
1820 sprintf(testdir2_r,
"%s/testdir2", realpath);
1821 sprintf(subfile_r,
"%s/subfile", testdir2_r);
1823 is_root = (geteuid() == 0);
1825 err += test_create();
1826 err += test_create_unlink();
1827 err += test_symlink();
1829 err += test_link2();
1831 err += test_mknod();
1832 err += test_mkfifo();
1834 err += test_mkdir();
1835 err += test_rename_file();
1836 err += test_rename_dir();
1837 err += test_rename_dir_loop();
1838 err += test_seekdir();
1839 err += test_utime();
1840 err += test_truncate(0);
1841 err += test_truncate(testdatalen / 2);
1842 err += test_truncate(testdatalen);
1843 err += test_truncate(testdatalen + 100);
1844 err += test_ftruncate(0, 0600);
1845 err += test_ftruncate(testdatalen / 2, 0600);
1846 err += test_ftruncate(testdatalen, 0600);
1847 err += test_ftruncate(testdatalen + 100, 0600);
1848 err += test_ftruncate(0, 0400);
1849 err += test_ftruncate(0, 0200);
1850 err += test_ftruncate(0, 0000);
1851 err += test_open(0, O_RDONLY, 0);
1852 err += test_open(1, O_RDONLY, 0);
1853 err += test_open(1, O_RDWR, 0);
1854 err += test_open(1, O_WRONLY, 0);
1855 err += test_open(0, O_RDWR | O_CREAT, 0600);
1856 err += test_open(1, O_RDWR | O_CREAT, 0600);
1857 err += test_open(0, O_RDWR | O_CREAT | O_TRUNC, 0600);
1858 err += test_open(1, O_RDWR | O_CREAT | O_TRUNC, 0600);
1859 err += test_open(0, O_RDONLY | O_CREAT, 0600);
1860 err += test_open(0, O_RDONLY | O_CREAT, 0400);
1861 err += test_open(0, O_RDONLY | O_CREAT, 0200);
1862 err += test_open(0, O_RDONLY | O_CREAT, 0000);
1863 err += test_open(0, O_WRONLY | O_CREAT, 0600);
1864 err += test_open(0, O_WRONLY | O_CREAT, 0400);
1865 err += test_open(0, O_WRONLY | O_CREAT, 0200);
1866 err += test_open(0, O_WRONLY | O_CREAT, 0000);
1867 err += test_open(0, O_RDWR | O_CREAT, 0400);
1868 err += test_open(0, O_RDWR | O_CREAT, 0200);
1869 err += test_open(0, O_RDWR | O_CREAT, 0000);
1870 err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0600);
1871 err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0600);
1872 err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0000);
1873 err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0000);
1874 err += test_open_acc(O_RDONLY, 0600, 0);
1875 err += test_open_acc(O_WRONLY, 0600, 0);
1876 err += test_open_acc(O_RDWR, 0600, 0);
1877 err += test_open_acc(O_RDONLY, 0400, 0);
1878 err += test_open_acc(O_WRONLY, 0200, 0);
1880 err += test_open_acc(O_RDONLY | O_TRUNC, 0400, EACCES);
1881 err += test_open_acc(O_WRONLY, 0400, EACCES);
1882 err += test_open_acc(O_RDWR, 0400, EACCES);
1883 err += test_open_acc(O_RDONLY, 0200, EACCES);
1884 err += test_open_acc(O_RDWR, 0200, EACCES);
1885 err += test_open_acc(O_RDONLY, 0000, EACCES);
1886 err += test_open_acc(O_WRONLY, 0000, EACCES);
1887 err += test_open_acc(O_RDWR, 0000, EACCES);
1889 err += test_create_ro_dir(O_CREAT);
1890 err += test_create_ro_dir(O_CREAT | O_EXCL);
1891 err += test_create_ro_dir(O_CREAT | O_WRONLY);
1892 err += test_create_ro_dir(O_CREAT | O_TRUNC);
1893 err += test_copy_file_range();
1901 fprintf(stderr,
"%i tests failed\n", -err);