1 /* Utility routines for Minix tests.
2 * This is designed to be #includ'ed near the top of test programs. It is
3 * self-contained except for MAX_ERRORS.
11 #include <sys/statvfs.h>
13 int common_test_nr
= -1, errct
= 0, subtest
;
16 int does_fs_truncate(void);
18 int name_max(char *path
);
20 void rm_rf_dir(int test_nr
);
21 void rm_rf_ppdir(int test_nr
);
22 void start(int test_nr
);
30 common_test_nr
= test_nr
;
31 printf("Test %2d ", test_nr
);
32 fflush(stdout
); /* since stdout is probably line buffered */
35 sprintf(buf
, "mkdir DIR_%02d", test_nr
);
36 if (system(buf
) != 0) {
40 sprintf(buf
, "DIR_%02d", test_nr
);
41 if (chdir(buf
) != 0) {
46 for (i
= 3; i
< OPEN_MAX
; ++i
) {
47 /* Close all files except stdin, stdout, and stderr */
52 int does_fs_truncate(void)
55 int does_truncate
= 0;
56 char cwd
[PATH_MAX
]; /* Storage for path to current working dir */
58 if (realpath(".", cwd
) == NULL
) e(7777); /* Get current working dir */
59 if (statvfs(cwd
, &stvfs
) != 0) e(7778); /* Get FS information */
60 /* Depending on how an FS handles too long file names, we have to adjust our
61 * error checking. If an FS does not truncate file names, it should generate
62 * an ENAMETOOLONG error when we provide too long a file name.
64 if (!(stvfs
.f_flag
& ST_NOTRUNC
)) does_truncate
= 1;
66 return(does_truncate
);
69 int name_max(char *path
)
73 if (statvfs(path
, &stvfs
) != 0) e(7779);
74 return(stvfs
.f_namemax
);
78 void rm_rf_dir(test_nr
)
83 sprintf(buf
, "rm -rf DIR_%02d >/dev/null 2>&1", test_nr
);
84 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
87 void rm_rf_ppdir(test_nr
)
90 /* Attempt to remove everything in the test directory (== the current dir). */
94 sprintf(buf
, "chmod 777 ../DIR_%02d/* ../DIR_%02d/*/* >/dev/null 2>&1",
97 sprintf(buf
, "rm -rf ../DIR_%02d >/dev/null 2>&1", test_nr
);
98 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
105 err_number
= errno
; /* Store before printf can clobber it */
106 if (errct
== 0) printf("\n"); /* finish header */
107 printf("Subtest %d, error %d, errno %d: %s\n",
108 subtest
, n
, errno
, strerror(errno
));
109 if (++errct
> MAX_ERROR
) {
110 printf("Too many errors; test aborted\n");
119 if (chdir("..") == 0 && common_test_nr
!= -1) rm_rf_dir(common_test_nr
);
129 printf("%d errors\n", errct
);