2 * Copyright (c) 2003-2007 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * Various utility routines useful for test programs.
28 * Each test program is linked against this file.
38 * This same file is used pretty much verbatim for all test harnesses.
40 * The next few lines are the only differences.
42 #define PROGRAM "bsdcpio" /* Name of program being tested. */
43 #define ENVBASE "BSDCPIO" /* Prefix for environment variables. */
44 #undef EXTRA_DUMP /* How to dump extra data */
45 /* How to generate extra version info. */
46 #define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "")
47 #define KNOWNREF "test_option_f.cpio.uu"
48 __FBSDID("$FreeBSD$");
51 * "list.h" is simply created by "grep DEFINE_TEST"; it has
53 * DEFINE_TEST(test_function)
55 * Include it here with a suitable DEFINE_TEST to declare all of the
59 #define DEFINE_TEST(name) void name(void);
62 /* Interix doesn't define these in a standard header. */
68 /* Enable core dump on failure. */
69 static int dump_on_failure = 0;
70 /* Default is to remove temp dirs for successful tests. */
71 static int keep_temp_files = 0;
72 /* Default is to print some basic information about each test. */
73 static int quiet_flag = 0;
74 /* Default is to summarize repeated failures. */
75 static int verbose = 0;
76 /* Cumulative count of component failures. */
77 static int failures = 0;
78 /* Cumulative count of skipped component tests. */
80 /* Cumulative count of assertions. */
81 static int assertions = 0;
83 /* Directory where uuencoded reference files can be found. */
84 static const char *refdir;
87 * My own implementation of the standard assert() macro emits the
88 * message in the same format as GCC (file:line: message).
89 * It also includes some additional useful information.
90 * This makes it a lot easier to skim through test failures in
93 * It also supports a few special features specifically to simplify
95 * failure(fmt, args) -- Stores a text string that gets
96 * printed if the following assertion fails, good for
97 * explaining subtle tests.
99 static char msg[4096];
102 * For each test source file, we remember how many times each
103 * failure was reported.
105 static const char *failed_filename = NULL;
109 } failed_lines[1000];
112 * Count this failure; return the number of previous failures.
115 previous_failures(const char *filename, int line)
120 if (failed_filename == NULL || strcmp(failed_filename, filename) != 0)
121 memset(failed_lines, 0, sizeof(failed_lines));
122 failed_filename = filename;
124 for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
125 if (failed_lines[i].line == line) {
126 count = failed_lines[i].count;
127 failed_lines[i].count++;
130 if (failed_lines[i].line == 0) {
131 failed_lines[i].line = line;
132 failed_lines[i].count = 1;
140 * Copy arguments into file-local variables.
142 static const char *test_filename;
143 static int test_line;
144 static void *test_extra;
145 void test_setup(const char *filename, int line)
147 test_filename = filename;
152 * Inform user that we're skipping a test.
155 test_skipping(const char *fmt, ...)
159 if (previous_failures(test_filename, test_line))
163 fprintf(stderr, " *** SKIPPING: ");
164 vfprintf(stderr, fmt, ap);
165 fprintf(stderr, "\n");
170 /* Common handling of failed tests. */
172 report_failure(void *extra)
174 if (msg[0] != '\0') {
175 fprintf(stderr, " Description: %s\n", msg);
181 fprintf(stderr, " detail: %s\n", EXTRA_DUMP(extra));
183 (void)extra; /* UNUSED */
186 if (dump_on_failure) {
188 " *** forcing core dump so failure can be debugged ***\n");
195 * Summarize repeated failures in the just-completed test file.
196 * The reports above suppress multiple failures from the same source
197 * line; this reports on any tests that did fail multiple times.
200 summarize_comparator(const void *a0, const void *b0)
202 const struct line *a = a0, *b = b0;
203 if (a->line == 0 && b->line == 0)
209 return (a->line - b->line);
217 qsort(failed_lines, sizeof(failed_lines)/sizeof(failed_lines[0]),
218 sizeof(failed_lines[0]), summarize_comparator);
219 for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
220 if (failed_lines[i].line == 0)
222 if (failed_lines[i].count > 1)
223 fprintf(stderr, "%s:%d: Failed %d times\n",
224 failed_filename, failed_lines[i].line,
225 failed_lines[i].count);
227 /* Clear the failure history for the next file. */
228 memset(failed_lines, 0, sizeof(failed_lines));
231 /* Set up a message to display only after a test fails. */
233 failure(const char *fmt, ...)
237 vsprintf(msg, fmt, ap);
241 /* Generic assert() just displays the failed condition. */
243 test_assert(const char *file, int line, int value, const char *condition, void *extra)
251 if (!verbose && previous_failures(file, line))
253 fprintf(stderr, "%s:%d: Assertion failed\n", file, line);
254 fprintf(stderr, " Condition: %s\n", condition);
255 report_failure(extra);
259 /* assertEqualInt() displays the values of the two integers. */
261 test_assert_equal_int(const char *file, int line,
262 int v1, const char *e1, int v2, const char *e2, void *extra)
270 if (!verbose && previous_failures(file, line))
272 fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
274 fprintf(stderr, " %s=%d\n", e1, v1);
275 fprintf(stderr, " %s=%d\n", e2, v2);
276 report_failure(extra);
280 static void strdump(const char *p)
283 fprintf(stderr, "(null)");
286 fprintf(stderr, "\"");
288 unsigned int c = 0xff & *p++;
290 case '\a': fprintf(stderr, "\a"); break;
291 case '\b': fprintf(stderr, "\b"); break;
292 case '\n': fprintf(stderr, "\n"); break;
293 case '\r': fprintf(stderr, "\r"); break;
295 if (c >= 32 && c < 127)
296 fprintf(stderr, "%c", c);
298 fprintf(stderr, "\\x%02X", c);
301 fprintf(stderr, "\"");
304 /* assertEqualString() displays the values of the two strings. */
306 test_assert_equal_string(const char *file, int line,
307 const char *v1, const char *e1,
308 const char *v2, const char *e2,
312 if (v1 == NULL || v2 == NULL) {
317 } else if (strcmp(v1, v2) == 0) {
322 if (!verbose && previous_failures(file, line))
324 fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
326 fprintf(stderr, " %s = ", e1);
328 fprintf(stderr, " (length %d)\n", v1 == NULL ? 0 : (int)strlen(v1));
329 fprintf(stderr, " %s = ", e2);
331 fprintf(stderr, " (length %d)\n", v2 == NULL ? 0 : (int)strlen(v2));
332 report_failure(extra);
336 static void wcsdump(const wchar_t *w)
339 fprintf(stderr, "(null)");
342 fprintf(stderr, "\"");
343 while (*w != L'\0') {
344 unsigned int c = *w++;
345 if (c >= 32 && c < 127)
346 fprintf(stderr, "%c", c);
348 fprintf(stderr, "\\x%02X", c);
349 else if (c < 0x10000)
350 fprintf(stderr, "\\u%04X", c);
352 fprintf(stderr, "\\U%08X", c);
354 fprintf(stderr, "\"");
357 /* assertEqualWString() displays the values of the two strings. */
359 test_assert_equal_wstring(const char *file, int line,
360 const wchar_t *v1, const char *e1,
361 const wchar_t *v2, const char *e2,
370 } else if (v2 == NULL) {
375 } else if (wcscmp(v1, v2) == 0) {
380 if (!verbose && previous_failures(file, line))
382 fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
384 fprintf(stderr, " %s = ", e1);
386 fprintf(stderr, "\n");
387 fprintf(stderr, " %s = ", e2);
389 fprintf(stderr, "\n");
390 report_failure(extra);
395 * Pretty standard hexdump routine. As a bonus, if ref != NULL, then
396 * any bytes in p that differ from ref will be highlighted with '_'
397 * before and after the hex value.
400 hexdump(const char *p, const char *ref, size_t l, size_t offset)
405 for(i=0; i < l; i+=16) {
406 fprintf(stderr, "%04x", (unsigned)(i + offset));
408 for (j = 0; j < 16 && i + j < l; j++) {
409 if (ref != NULL && p[i + j] != ref[i + j])
411 fprintf(stderr, "%c%02x", sep, 0xff & (int)p[i+j]);
412 if (ref != NULL && p[i + j] == ref[i + j])
415 for (; j < 16; j++) {
416 fprintf(stderr, "%c ", sep);
419 fprintf(stderr, "%c", sep);
420 for (j=0; j < 16 && i + j < l; j++) {
422 if (c >= ' ' && c <= 126)
423 fprintf(stderr, "%c", c);
425 fprintf(stderr, ".");
427 fprintf(stderr, "\n");
431 /* assertEqualMem() displays the values of the two memory blocks. */
432 /* TODO: For long blocks, hexdump the first bytes that actually differ. */
434 test_assert_equal_mem(const char *file, int line,
435 const char *v1, const char *e1,
436 const char *v2, const char *e2,
437 size_t l, const char *ld, void *extra)
440 if (v1 == NULL || v2 == NULL) {
445 } else if (memcmp(v1, v2, l) == 0) {
450 if (!verbose && previous_failures(file, line))
452 fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
454 fprintf(stderr, " size %s = %d\n", ld, (int)l);
455 fprintf(stderr, " Dump of %s\n", e1);
456 hexdump(v1, v2, l < 32 ? l : 32, 0);
457 fprintf(stderr, " Dump of %s\n", e2);
458 hexdump(v2, v1, l < 32 ? l : 32, 0);
459 fprintf(stderr, "\n");
460 report_failure(extra);
465 test_assert_empty_file(const char *f1fmt, ...)
476 vsprintf(f1, f1fmt, ap);
479 if (stat(f1, &st) != 0) {
480 fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1);
481 report_failure(NULL);
488 if (!verbose && previous_failures(test_filename, test_line))
491 fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
492 fprintf(stderr, " File size: %d\n", (int)st.st_size);
493 fprintf(stderr, " Contents:\n");
494 fd = open(f1, O_RDONLY);
496 fprintf(stderr, " Unable to open %s\n", f1);
498 s = sizeof(buff) < st.st_size ? sizeof(buff) : st.st_size;
499 s = read(fd, buff, s);
500 hexdump(buff, NULL, s, 0);
503 report_failure(NULL);
507 /* assertEqualFile() asserts that two files have the same contents. */
508 /* TODO: hexdump the first bytes that actually differ. */
510 test_assert_equal_file(const char *f1, const char *f2pattern, ...)
519 va_start(ap, f2pattern);
520 vsprintf(f2, f2pattern, ap);
523 fd1 = open(f1, O_RDONLY);
524 fd2 = open(f2, O_RDONLY);
526 n1 = read(fd1, buff1, sizeof(buff1));
527 n2 = read(fd2, buff2, sizeof(buff2));
530 if (n1 == 0 && n2 == 0) {
535 if (memcmp(buff1, buff2, n1) != 0)
541 if (!verbose && previous_failures(test_filename, test_line))
543 fprintf(stderr, "%s:%d: Files are not identical\n",
544 test_filename, test_line);
545 fprintf(stderr, " file1=\"%s\"\n", f1);
546 fprintf(stderr, " file2=\"%s\"\n", f2);
547 report_failure(test_extra);
552 test_assert_file_exists(const char *fpattern, ...)
557 va_start(ap, fpattern);
558 vsprintf(f, fpattern, ap);
561 if (!access(f, F_OK))
563 if (!previous_failures(test_filename, test_line)) {
564 fprintf(stderr, "%s:%d: File doesn't exist\n",
565 test_filename, test_line);
566 fprintf(stderr, " file=\"%s\"\n", f);
567 report_failure(test_extra);
573 test_assert_file_not_exists(const char *fpattern, ...)
578 va_start(ap, fpattern);
579 vsprintf(f, fpattern, ap);
584 if (!previous_failures(test_filename, test_line)) {
585 fprintf(stderr, "%s:%d: File exists and shouldn't\n",
586 test_filename, test_line);
587 fprintf(stderr, " file=\"%s\"\n", f);
588 report_failure(test_extra);
593 /* assertFileContents() asserts the contents of a file. */
595 test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
603 va_start(ap, fpattern);
604 vsprintf(f, fpattern, ap);
607 fd = open(f, O_RDONLY);
608 contents = malloc(s * 2 + 128);
609 n = read(fd, contents, s * 2 + 128);
611 if (n == s && memcmp(buff, contents, s) == 0) {
616 if (!previous_failures(test_filename, test_line)) {
617 fprintf(stderr, "%s:%d: File contents don't match\n",
618 test_filename, test_line);
619 fprintf(stderr, " file=\"%s\"\n", f);
621 hexdump(contents, buff, n, 0);
623 fprintf(stderr, " File empty, contents should be:\n");
624 hexdump(buff, NULL, s, 0);
626 report_failure(test_extra);
632 /* assertTextFileContents() asserts the contents of a text file. */
634 test_assert_text_file_contents(const char *buff, const char *f)
637 const char *btxt, *ftxt;
641 fd = open(f, O_RDONLY);
643 contents = malloc(s * 2 + 128);
644 n = read(fd, contents, s * 2 + 128 -1);
650 ftxt = (const char *)contents;
651 while (*btxt != '\0' && *ftxt != '\0') {
652 if (*btxt == *ftxt) {
657 if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') {
658 /* Pass over different new line characters. */
665 if (*btxt == '\0' && *ftxt == '\0') {
670 if (!previous_failures(test_filename, test_line)) {
671 fprintf(stderr, "%s:%d: File contents don't match\n",
672 test_filename, test_line);
673 fprintf(stderr, " file=\"%s\"\n", f);
675 hexdump(contents, buff, n, 0);
677 fprintf(stderr, " File empty, contents should be:\n");
678 hexdump(buff, NULL, s, 0);
680 report_failure(test_extra);
687 * Call standard system() call, but build up the command line using
688 * sprintf() conventions.
691 systemf(const char *fmt, ...)
698 vsprintf(buff, fmt, ap);
705 * Slurp a file into memory for ease of comparison and testing.
706 * Returns size of file in 'sizep' if non-NULL, null-terminates
707 * data in memory for ease of use.
710 slurpfile(size_t * sizep, const char *fmt, ...)
721 vsprintf(filename, fmt, ap);
724 fd = open(filename, O_RDONLY);
726 /* Note: No error; non-existent file is okay here. */
731 fprintf(stderr, "Can't stat file %s\n", filename);
735 p = malloc(st.st_size + 1);
737 fprintf(stderr, "Can't allocate %ld bytes of memory to read file %s\n", (long int)st.st_size, filename);
741 bytes_read = read(fd, p, st.st_size);
742 if (bytes_read < st.st_size) {
743 fprintf(stderr, "Can't read file %s\n", filename);
748 p[st.st_size] = '\0';
750 *sizep = (size_t)st.st_size;
756 * "list.h" is automatically generated; it just has a lot of lines like:
757 * DEFINE_TEST(function_name)
758 * It's used above to declare all of the test functions.
759 * We reuse it here to define a list of all tests (functions and names).
762 #define DEFINE_TEST(n) { n, #n },
763 struct { void (*func)(void); const char *name; } tests[] = {
768 * Each test is run in a private work dir. Those work dirs
769 * do have consistent and predictable names, in case a group
770 * of tests need to collaborate. However, there is no provision
771 * for requiring that tests run in a certain order.
773 static int test_run(int i, const char *tmpdir)
775 int failures_before = failures;
778 printf("%d: %s\n", i, tests[i].name);
783 * Always explicitly chdir() in case the last test moved us to
788 "ERROR: Couldn't chdir to temp dir %s\n",
792 /* Create a temp directory for this specific test. */
793 if (mkdir(tests[i].name, 0755)) {
795 "ERROR: Couldn't create temp dir ``%s''\n",
799 /* Chdir() to that work directory. */
800 if (chdir(tests[i].name)) {
802 "ERROR: Couldn't chdir to temp dir ``%s''\n",
806 /* Explicitly reset the locale before each test. */
807 setlocale(LC_ALL, "C");
808 /* Run the actual test. */
810 /* Summarize the results of this test. */
812 /* If there were no failures, we can remove the work dir. */
813 if (failures == failures_before) {
814 if (!keep_temp_files && chdir(tmpdir) == 0) {
815 #if defined(_WIN32) && !defined(__CYGWIN__)
816 systemf("rmdir /S /Q %s", tests[i].name);
818 systemf("rm -rf %s", tests[i].name);
822 /* Return appropriate status. */
823 return (failures == failures_before ? 0 : 1);
826 static void usage(const char *program)
828 static const int limit = sizeof(tests) / sizeof(tests[0]);
831 printf("Usage: %s [options] <test> <test> ...\n", program);
832 printf("Default is to run all tests.\n");
833 printf("Otherwise, specify the numbers of the tests you wish to run.\n");
834 printf("Options:\n");
835 printf(" -d Dump core after any failure, for debugging.\n");
836 printf(" -k Keep all temp files.\n");
837 printf(" Default: temp files for successful tests deleted.\n");
839 printf(" -p <path> Path to executable to be tested.\n");
840 printf(" Default: path taken from " ENVBASE " environment variable.\n");
842 printf(" -q Quiet.\n");
843 printf(" -r <dir> Path to dir containing reference files.\n");
844 printf(" Default: Current directory.\n");
845 printf(" -v Verbose.\n");
846 printf("Available tests:\n");
847 for (i = 0; i < limit; i++)
848 printf(" %d: %s\n", i, tests[i].name);
852 #define UUDECODE(c) (((c) - 0x20) & 0x3f)
855 extract_reference_file(const char *name)
860 sprintf(buff, "%s/%s.uu", refdir, name);
861 in = fopen(buff, "r");
862 failure("Couldn't open reference file %s", buff);
866 /* Read up to and including the 'begin' line. */
868 if (fgets(buff, sizeof(buff), in) == NULL) {
869 /* TODO: This is a failure. */
872 if (memcmp(buff, "begin ", 6) == 0)
875 /* Now, decode the rest and write it. */
876 /* Not a lot of error checking here; the input better be right. */
877 out = fopen(name, "w");
878 while (fgets(buff, sizeof(buff), in) != NULL) {
882 if (memcmp(buff, "end", 3) == 0)
885 bytes = UUDECODE(*p++);
888 /* Write out 1-3 bytes from that. */
890 n = UUDECODE(*p++) << 18;
891 n |= UUDECODE(*p++) << 12;
896 n |= UUDECODE(*p++) << 6;
897 fputc((n >> 8) & 0xFF, out);
902 fputc(n & 0xFF, out);
915 char tried[512] = { '\0' };
919 /* Get the current dir. */
920 pwd = getcwd(NULL, 0);
921 while (pwd[strlen(pwd) - 1] == '\n')
922 pwd[strlen(pwd) - 1] = '\0';
923 printf("PWD: %s\n", pwd);
925 /* Look for a known file. */
926 snprintf(buff, sizeof(buff), "%s", pwd);
927 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
928 if (p != NULL) goto success;
929 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
930 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
932 snprintf(buff, sizeof(buff), "%s/test", pwd);
933 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
934 if (p != NULL) goto success;
935 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
936 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
938 snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
939 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
940 if (p != NULL) goto success;
941 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
942 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
944 if (memcmp(pwd, "/usr/obj", 8) == 0) {
945 snprintf(buff, sizeof(buff), "%s", pwd + 8);
946 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
947 if (p != NULL) goto success;
948 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
949 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
951 snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
952 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
953 if (p != NULL) goto success;
954 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
955 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
958 #if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
961 printf("Unable to locate known reference file %s\n", KNOWNREF);
962 printf(" Checked following directories:\n%s\n", tried);
971 int main(int argc, char **argv)
973 static const int limit = sizeof(tests) / sizeof(tests[0]);
974 int i, tests_run = 0, tests_failed = 0, opt;
976 char *refdir_alloc = NULL;
977 #if defined(_WIN32) && !defined(__CYGWIN__)
980 const char *opt_arg, *progname, *p;
982 char tmpdir_timestamp[256];
984 (void)argc; /* UNUSED */
986 #if defined(_WIN32) && !defined(__CYGWIN__)
987 /* Make sure open() function will be used with a binary mode. */
988 /* on cygwin, we need something similar, but instead link against */
989 /* a special startup object, binmode.o */
990 _set_fmode(_O_BINARY);
993 * Name of this program, used to build root of our temp directory
996 progname = p = argv[0];
998 /* Support \ or / dir separators for Windows compat. */
999 if (*p == '/' || *p == '\\')
1005 /* Get the target program from environment, if available. */
1006 testprog = getenv(ENVBASE);
1009 /* Allow -d to be controlled through the environment. */
1010 if (getenv(ENVBASE "_DEBUG") != NULL)
1011 dump_on_failure = 1;
1013 /* Get the directory holding test files from environment. */
1014 refdir = getenv(ENVBASE "_TEST_FILES");
1017 * Parse options, without using getopt(), which isn't available
1020 ++argv; /* Skip program name */
1021 while (*argv != NULL) {
1026 while (*p != '\0') {
1029 /* If 'opt' takes an argument, parse that. */
1030 if (opt == 'p' || opt == 'r') {
1033 else if (*argv == NULL) {
1035 "Option -%c requires argument.\n",
1040 p = ""; /* End of this option word. */
1045 dump_on_failure = 1;
1048 keep_temp_files = 1;
1074 * Sanity-check that our options make sense.
1077 if (testprog == NULL)
1080 #if defined(_WIN32) && !defined(__CYGWIN__)
1082 * Command.exe cannot accept the command used '/' with drive
1083 * name such as c:/xxx/command.exe when use '|' pipe handling.
1085 testprg = strdup(testprog);
1086 for (i = 0; testprg[i] != '\0'; i++) {
1087 if (testprg[i] == '/')
1094 * Create a temp directory for the following tests.
1095 * Include the time the tests started as part of the name,
1096 * to make it easier to track the results of multiple tests.
1099 for (i = 0; i < 1000; i++) {
1100 strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
1101 "%Y-%m-%dT%H.%M.%S",
1103 sprintf(tmpdir, "/tmp/%s.%s-%03d", progname, tmpdir_timestamp, i);
1104 if (mkdir(tmpdir,0755) == 0)
1106 if (errno == EEXIST)
1108 fprintf(stderr, "ERROR: Unable to create temp directory %s\n",
1114 * If the user didn't specify a directory for locating
1115 * reference files, use the current directory for that.
1118 refdir = refdir_alloc = get_refdir();
1121 * Banner with basic information.
1124 printf("Running tests in: %s\n", tmpdir);
1125 printf("Reference files will be read from: %s\n", refdir);
1127 printf("Running tests on: %s\n", testprog);
1129 printf("Exercising: ");
1131 printf("%s\n", EXTRA_VERSION);
1135 * Run some or all of the individual tests.
1137 if (*argv == NULL) {
1138 /* Default: Run all tests. */
1139 for (i = 0; i < limit; i++) {
1140 if (test_run(i, tmpdir))
1145 while (*(argv) != NULL) {
1147 if (**argv < '0' || **argv > '9' || i < 0 || i >= limit) {
1148 printf("*** INVALID Test %s\n", *argv);
1151 if (test_run(i, tmpdir))
1160 * Report summary statistics.
1164 printf("%d of %d tests reported failures\n",
1165 tests_failed, tests_run);
1166 printf(" Total of %d assertions checked.\n", assertions);
1167 printf(" Total of %d assertions failed.\n", failures);
1168 printf(" Total of %d assertions skipped.\n", skips);
1173 /* If the final tmpdir is empty, we can remove it. */
1174 /* This should be the usual case when all tests succeed. */
1177 return (tests_failed);