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 /* "rm -rf dir" will not work unless all the subdirectories have suitable
84 * permissions. Minix chmod is not recursive so it is not easy to change
85 * all the permissions. I had to fix opendir() to stop the bash shell
86 * from hanging when it opendir()s fifos.
88 sprintf(buf
, "chmod 777 DIR_%02d DIR_%02d/* DIR_%02d/*/* >/dev/null 2>&1",
89 test_nr
, test_nr
, test_nr
);
90 (void) system(buf
); /* usually fails */
91 sprintf(buf
, "rm -rf DIR_%02d >/dev/null 2>&1", test_nr
);
92 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
95 void rm_rf_ppdir(test_nr
)
98 /* Attempt to remove everything in the test directory (== the current dir). */
102 sprintf(buf
, "chmod 777 ../DIR_%02d/* ../DIR_%02d/*/* >/dev/null 2>&1",
105 sprintf(buf
, "rm -rf ../DIR_%02d >/dev/null 2>&1", test_nr
);
106 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
113 err_number
= errno
; /* Store before printf can clobber it */
114 if (errct
== 0) printf("\n"); /* finish header */
115 printf("Subtest %d, error %d, errno %d: %s\n",
116 subtest
, n
, errno
, strerror(errno
));
117 if (errct
++ > MAX_ERROR
) {
118 printf("Too many errors; test aborted\n");
127 if (chdir("..") == 0 && common_test_nr
!= -1) rm_rf_dir(common_test_nr
);
137 printf("%d errors\n", errct
);