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.
12 int common_test_nr
= -1, errct
= 0, subtest
;
14 _PROTOTYPE(void cleanup
, (void));
15 _PROTOTYPE(void e
, (int n
));
16 _PROTOTYPE(void quit
, (void));
17 _PROTOTYPE(void rm_rf_dir
, (int test_nr
));
18 _PROTOTYPE(void rm_rf_ppdir
, (int test_nr
));
19 _PROTOTYPE(void start
, (int test_nr
));
26 common_test_nr
= test_nr
;
27 printf("Test %2d ", test_nr
);
28 fflush(stdout
); /* since stdout is probably line buffered */
31 sprintf(buf
, "mkdir DIR_%02d", test_nr
);
32 if (system(buf
) != 0) {
36 sprintf(buf
, "DIR_%02d", test_nr
);
37 if (chdir(buf
) != 0) {
43 void rm_rf_dir(test_nr
)
48 /* "rm -rf dir" will not work unless all the subdirectories have suitable
49 * permissions. Minix chmod is not recursive so it is not easy to change
50 * all the permissions. I had to fix opendir() to stop the bash shell
51 * from hanging when it opendir()s fifos.
53 sprintf(buf
, "chmod 777 DIR_%02d DIR_%02d/* DIR_%02d/*/* >/dev/null 2>&1",
54 test_nr
, test_nr
, test_nr
);
55 (void) system(buf
); /* usually fails */
56 sprintf(buf
, "rm -rf DIR_%02d >/dev/null 2>&1", test_nr
);
57 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
60 void rm_rf_ppdir(test_nr
)
63 /* Attempt to remove everything in the test directory (== the current dir). */
67 sprintf(buf
, "chmod 777 ../DIR_%02d/* ../DIR_%02d/*/* >/dev/null 2>&1",
70 sprintf(buf
, "rm -rf ../DIR_%02d >/dev/null 2>&1", test_nr
);
71 if (system(buf
) != 0) printf("Warning: system(\"%s\") failed\n", buf
);
77 if (errct
== 0) printf("\n"); /* finish header */
78 printf("Subtest %d, error %d, errno %d: %s\n",
79 subtest
, n
, errno
, strerror(errno
));
80 if (errct
++ > MAX_ERROR
) {
81 printf("Too many errors; test aborted\n");
85 errno
= 0; /* don't leave it around to confuse next e() */
90 if (chdir("..") == 0 && common_test_nr
!= -1) rm_rf_dir(common_test_nr
);
100 printf("%d errors\n", errct
);