summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/cpio/test/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'archivers/libarchive/files/cpio/test/main.c')
-rw-r--r--archivers/libarchive/files/cpio/test/main.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/archivers/libarchive/files/cpio/test/main.c b/archivers/libarchive/files/cpio/test/main.c
index f06f75a918c..c88dd2ac341 100644
--- a/archivers/libarchive/files/cpio/test/main.c
+++ b/archivers/libarchive/files/cpio/test/main.c
@@ -64,10 +64,14 @@ extern char *optarg;
extern int optind;
#endif
-/* Default is to crash and try to force a core dump on failure. */
-static int dump_on_failure = 1;
+/* Enable core dump on failure. */
+static int dump_on_failure = 0;
+/* Default is to remove temp dirs for successful tests. */
+static int keep_temp_files = 0;
/* Default is to print some basic information about each test. */
static int quiet_flag = 0;
+/* Default is to summarize repeated failures. */
+static int verbose = 0;
/* Cumulative count of component failures. */
static int failures = 0;
/* Cumulative count of skipped component tests. */
@@ -243,7 +247,7 @@ test_assert(const char *file, int line, int value, const char *condition, void *
return (value);
}
failures ++;
- if (previous_failures(file, line))
+ if (!verbose && previous_failures(file, line))
return (value);
fprintf(stderr, "%s:%d: Assertion failed\n", file, line);
fprintf(stderr, " Condition: %s\n", condition);
@@ -262,7 +266,7 @@ test_assert_equal_int(const char *file, int line,
return (1);
}
failures ++;
- if (previous_failures(file, line))
+ if (!verbose && previous_failures(file, line))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
file, line);
@@ -314,16 +318,16 @@ test_assert_equal_string(const char *file, int line,
return (1);
}
failures ++;
- if (previous_failures(file, line))
+ if (!verbose && previous_failures(file, line))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
file, line);
fprintf(stderr, " %s = ", e1);
strdump(v1);
- fprintf(stderr, "\n");
+ fprintf(stderr, " (length %d)\n", v1 == NULL ? 0 : strlen(v1));
fprintf(stderr, " %s = ", e2);
strdump(v2);
- fprintf(stderr, "\n");
+ fprintf(stderr, " (length %d)\n", v2 == NULL ? 0 : strlen(v2));
report_failure(extra);
return (0);
}
@@ -372,7 +376,7 @@ test_assert_equal_wstring(const char *file, int line,
return (1);
}
failures ++;
- if (previous_failures(file, line))
+ if (!verbose && previous_failures(file, line))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
file, line);
@@ -442,7 +446,7 @@ test_assert_equal_mem(const char *file, int line,
return (1);
}
failures ++;
- if (previous_failures(file, line))
+ if (!verbose && previous_failures(file, line))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
file, line);
@@ -474,12 +478,13 @@ test_assert_empty_file(const char *f1fmt, ...)
if (stat(f1, &st) != 0) {
fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1);
report_failure(NULL);
+ return (0);
}
if (st.st_size == 0)
return (1);
failures ++;
- if (previous_failures(test_filename, test_line))
+ if (!verbose && previous_failures(test_filename, test_line))
return (0);
fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
@@ -526,7 +531,7 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...)
break;
}
failures ++;
- if (previous_failures(test_filename, test_line))
+ if (!verbose && previous_failures(test_filename, test_line))
return (0);
fprintf(stderr, "%s:%d: Files are not identical\n",
test_filename, test_line);
@@ -697,6 +702,12 @@ static int test_run(int i, const char *tmpdir)
(*tests[i].func)();
/* Summarize the results of this test. */
summarize();
+ /* If there were no failures, we can remove the work dir. */
+ if (failures == failures_before) {
+ if (!keep_temp_files && chdir(tmpdir) == 0) {
+ systemf("rm -rf %s", tests[i].name);
+ }
+ }
/* Return appropriate status. */
return (failures == failures_before ? 0 : 1);
}
@@ -710,8 +721,9 @@ static void usage(const char *program)
printf("Default is to run all tests.\n");
printf("Otherwise, specify the numbers of the tests you wish to run.\n");
printf("Options:\n");
- printf(" -k Keep running after failures.\n");
- printf(" Default: Core dump after any failure.\n");
+ printf(" -d Dump core after any failure, for debugging.\n");
+ printf(" -k Keep all temp files.\n");
+ printf(" Default: temp files for successful tests deleted.\n");
#ifdef PROGRAM
printf(" -p <path> Path to executable to be tested.\n");
printf(" Default: path taken from " ENVBASE " environment variable.\n");
@@ -719,6 +731,7 @@ static void usage(const char *program)
printf(" -q Quiet.\n");
printf(" -r <dir> Path to dir containing reference files.\n");
printf(" Default: Current directory.\n");
+ printf(" -v Verbose.\n");
printf("Available tests:\n");
for (i = 0; i < limit; i++)
printf(" %d: %s\n", i, tests[i].name);
@@ -811,9 +824,9 @@ int main(int argc, char **argv)
testprog = getenv(ENVBASE);
#endif
- /* Allow -k to be controlled through the environment. */
- if (getenv(ENVBASE "_KEEP_GOING") != NULL)
- dump_on_failure = 0;
+ /* Allow -d to be controlled through the environment. */
+ if (getenv(ENVBASE "_DEBUG") != NULL)
+ dump_on_failure = 1;
/* Get the directory holding test files from environment. */
refdir = getenv(ENVBASE "_TEST_FILES");
@@ -821,10 +834,13 @@ int main(int argc, char **argv)
/*
* Parse options.
*/
- while ((opt = getopt(argc, argv, "kp:qr:")) != -1) {
+ while ((opt = getopt(argc, argv, "dkp:qr:v")) != -1) {
switch (opt) {
+ case 'd':
+ dump_on_failure = 1;
+ break;
case 'k':
- dump_on_failure = 0;
+ keep_temp_files = 1;
break;
case 'p':
#ifdef PROGRAM
@@ -839,6 +855,9 @@ int main(int argc, char **argv)
case 'r':
refdir = optarg;
break;
+ case 'v':
+ verbose = 1;
+ break;
case '?':
default:
usage(progname);
@@ -887,6 +906,7 @@ int main(int argc, char **argv)
--p;
*p = '\0';
}
+ systemf("rm %s/refdir", tmpdir);
}
/*
@@ -942,5 +962,9 @@ int main(int argc, char **argv)
free(refdir_alloc);
+ /* If the final tmpdir is empty, we can remove it. */
+ /* This should be the usual case when all tests succeed. */
+ rmdir(tmpdir);
+
return (tests_failed);
}