summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/test/main.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2007-06-13 03:30:46 +0000
committerkientzle <kientzle@FreeBSD.org>2007-06-13 03:30:46 +0000
commit4abc2f2f474d5ddbdaffb4265fc7b06abba70c46 (patch)
tree8cd1e3afc6f0107d35e1bc8f36edef36ac783640 /lib/libarchive/test/main.c
parent2e23f02e8bfbeb0495434eb050f733e6d7aa22d6 (diff)
downloadFreeBSD-src-4abc2f2f474d5ddbdaffb4265fc7b06abba70c46.zip
FreeBSD-src-4abc2f2f474d5ddbdaffb4265fc7b06abba70c46.tar.gz
Add some options to libarchive_test:
-k: like make -k, try to keep going after errors. -q: quiet
Diffstat (limited to 'lib/libarchive/test/main.c')
-rw-r--r--lib/libarchive/test/main.c62
1 files changed, 50 insertions, 12 deletions
diff --git a/lib/libarchive/test/main.c b/lib/libarchive/test/main.c
index ade4993..1e95f89 100644
--- a/lib/libarchive/test/main.c
+++ b/lib/libarchive/test/main.c
@@ -34,6 +34,13 @@
#include "test.h"
__FBSDID("$FreeBSD$");
+/* Default is to crash and try to force a core dump on failure. */
+static int dump_on_failure = 1;
+/* Default is to print some basic information about each test. */
+static int quiet_flag = 0;
+/* Cumulative count of failures. */
+static int failures = 0;
+
/*
* My own implementation of the standard assert() macro emits the
* message in the same format as GCC (file:line: message).
@@ -51,10 +58,13 @@ __FBSDID("$FreeBSD$");
*/
static char msg[4096];
+
/* Common handling of failed tests. */
static void
test_failed(struct archive *a)
{
+ failures ++;
+
if (msg[0] != '\0') {
fprintf(stderr, " Description: %s\n", msg);
msg[0] = '\0';
@@ -63,9 +73,11 @@ test_failed(struct archive *a)
fprintf(stderr, " archive error: %s\n", archive_error_string(a));
}
- fprintf(stderr, " *** forcing core dump so failure can be debugged ***\n");
- *(char *)(NULL) = 0;
- exit(1);
+ if (dump_on_failure) {
+ fprintf(stderr, " *** forcing core dump so failure can be debugged ***\n");
+ *(char *)(NULL) = 0;
+ exit(1);
+ }
}
/* Set up a message to display only after a test fails. */
@@ -160,9 +172,12 @@ struct { void (*func)(void); const char *name; } tests[] = {
#include "list.h"
};
-static void test_run(int i, const char *tmpdir)
+static int test_run(int i, const char *tmpdir)
{
- printf("%d: %s\n", i, tests[i].name);
+ int failures_before = failures;
+
+ if (!quiet_flag)
+ printf("%d: %s\n", i, tests[i].name);
/*
* Always explicitly chdir() in case the last test moved us to
* a strange place.
@@ -187,6 +202,7 @@ static void test_run(int i, const char *tmpdir)
exit(1);
}
(*tests[i].func)();
+ return (failures - failures_before);
}
static void usage(void)
@@ -194,9 +210,13 @@ static void usage(void)
static const int limit = sizeof(tests) / sizeof(tests[0]);
int i;
- printf("Usage: libarchive_test <test> <test> ...\n");
+ printf("Usage: libarchive_test [options] <test> <test> ...\n");
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(" -q Quiet.\n");
printf("Available tests:\n");
for (i = 0; i < limit; i++)
printf(" %d: %s\n", i, tests[i].name);
@@ -206,10 +226,26 @@ static void usage(void)
int main(int argc, char **argv)
{
static const int limit = sizeof(tests) / sizeof(tests[0]);
- int i, tests_run = 0;
+ int i, tests_run = 0, tests_succeeded = 0, opt;
time_t now;
char tmpdir[256];
+ while ((opt = getopt(argc, argv, "kq")) != -1) {
+ switch (opt) {
+ case 'k':
+ dump_on_failure = 0;
+ break;
+ case 'q':
+ quiet_flag = 1;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
/*
* Create a temp directory for the following tests.
* Include the time the tests started as part of the name,
@@ -232,10 +268,11 @@ int main(int argc, char **argv)
printf("Running libarchive tests in: %s\n", tmpdir);
- if (argc == 1) {
+ if (argc == 0) {
/* Default: Run all tests. */
for (i = 0; i < limit; i++) {
- test_run(i, tmpdir);
+ if (test_run(i, tmpdir) == 0)
+ tests_succeeded++;
tests_run++;
}
} else {
@@ -245,12 +282,13 @@ int main(int argc, char **argv)
printf("*** INVALID Test %s\n", *argv);
usage();
} else {
- test_run(i, tmpdir);
+ if (test_run(i, tmpdir) == 0)
+ tests_succeeded++;
tests_run++;
}
}
}
- printf("%d tests succeeded.\n", tests_run);
- return (0);
+ printf("%d of %d tests succeeded.\n", tests_succeeded, tests_run);
+ return (tests_succeeded == tests_run ? 0 : 1);
}
OpenPOWER on IntegriCloud