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
;
15 #define e(errn) e_f(__FILE__, __LINE__, (errn))
18 int does_fs_truncate(void);
19 void e_f(char *file
, int lineno
, int n
);
20 int name_max(char *path
);
22 void rm_rf_dir(int test_nr
);
23 void rm_rf_ppdir(int test_nr
);
24 void start(int test_nr
);
32 common_test_nr
= test_nr
;
33 printf("Test %2d ", test_nr
);
34 fflush(stdout
); /* since stdout is probably line buffered */
37 sprintf(buf
, "mkdir DIR_%02d", test_nr
);
38 if (system(buf
) != 0) {
42 sprintf(buf
, "DIR_%02d", test_nr
);
43 if (chdir(buf
) != 0) {
48 for (i
= 3; i
< OPEN_MAX
; ++i
) {
49 /* Close all files except stdin, stdout, and stderr */
54 int does_fs_truncate(void)
57 int does_truncate
= 0;
58 char cwd
[PATH_MAX
]; /* Storage for path to current working dir */
60 if (realpath(".", cwd
) == NULL
) e(7777); /* Get current working dir */
61 if (statvfs(cwd
, &stvfs
) != 0) e(7778); /* Get FS information */
62 /* Depending on how an FS handles too long file names, we have to adjust our
63 * error checking. If an FS does not truncate file names, it should generate
64 * an ENAMETOOLONG error when we provide too long a file name.
66 if (!(stvfs
.f_flag
& ST_NOTRUNC
)) does_truncate
= 1;
68 return(does_truncate
);
71 int name_max(char *path
)
75 if (statvfs(path
, &stvfs
) != 0) e(7779);
76 return(stvfs
.f_namemax
);
80 void rm_rf_dir(test_nr
)
85 sprintf(buf
, "rm -rf DIR_%02d >/dev/null 2>&1", test_nr
);
86 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
89 void rm_rf_ppdir(test_nr
)
92 /* Attempt to remove everything in the test directory (== the current dir). */
96 sprintf(buf
, "chmod 777 ../DIR_%02d/* ../DIR_%02d/*/* >/dev/null 2>&1",
99 sprintf(buf
, "rm -rf ../DIR_%02d >/dev/null 2>&1", test_nr
);
100 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
103 void e_f(char *file
, int line
, int n
)
106 err_number
= errno
; /* Store before printf can clobber it */
107 if (errct
== 0) printf("\n"); /* finish header */
108 printf("%s:%d: Subtest %d, error %d, errno %d: %s\n",
109 file
, line
, subtest
, n
, errno
, strerror(errno
));
110 if (++errct
> MAX_ERROR
) {
111 printf("Too many errors; test aborted\n");
120 if (chdir("..") == 0 && common_test_nr
!= -1) rm_rf_dir(common_test_nr
);
130 printf("%d errors\n", errct
);