diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-06-16 23:10:15 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:09:10 -0500 |
commit | 5b7ee5e7d69f73618d7cc7a4229b98c429506084 (patch) | |
tree | 90ed8e2fb16ebf33c86ad1f0710ce9be6fdf1e26 | |
parent | 324583b28f739a545c63af235b9185a2f9b0345f (diff) | |
download | samba-5b7ee5e7d69f73618d7cc7a4229b98c429506084.tar.gz samba-5b7ee5e7d69f73618d7cc7a4229b98c429506084.tar.bz2 samba-5b7ee5e7d69f73618d7cc7a4229b98c429506084.zip |
r16321: Add suite_start/suite_finish hooks, support --format=quiet
(This used to be commit 6da39533d77f686b26787bebfe9e3db4bb8c740d)
-rw-r--r-- | source4/torture/smbtorture.c | 21 | ||||
-rw-r--r-- | source4/torture/ui.c | 47 | ||||
-rw-r--r-- | source4/torture/ui.h | 3 |
3 files changed, 57 insertions, 14 deletions
diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c index bdd7f0ed84..ab462f1d08 100644 --- a/source4/torture/smbtorture.c +++ b/source4/torture/smbtorture.c @@ -234,17 +234,16 @@ static void max_runtime_handler(int sig) } static void simple_tcase_start (struct torture_context *ctx, - struct torture_tcase *tcase, - struct torture_test *test) + struct torture_tcase *tcase) { - printf("Testing %s...\n", tcase->name); + printf("Testing %s\n", tcase->name); } static void simple_test_start (struct torture_context *ctx, struct torture_tcase *tcase, struct torture_test *test) { - printf("Testing %s/%s...\n", tcase->name, test->name); + printf("Testing %s/%s\n", tcase->name, test->name); } static void simple_test_result (struct torture_context *context, @@ -354,6 +353,18 @@ const static struct torture_ui_ops harness_ui_ops = { .test_result = harness_test_result }; +static void quiet_test_start (struct torture_context *ctx, + struct torture_tcase *tcase, + struct torture_test *test) +{ + putchar('.'); +} + +const static struct torture_ui_ops quiet_ui_ops = { + .test_start = quiet_test_start, +}; + + /**************************************************************************** main program ****************************************************************************/ @@ -509,6 +520,8 @@ const static struct torture_ui_ops harness_ui_ops = { torture->ui_ops = &subunit_ui_ops; } else if (!strcmp(ui_ops_name, "harness")) { torture->ui_ops = &harness_ui_ops; + } else if (!strcmp(ui_ops_name, "quiet")) { + torture->ui_ops = &quiet_ui_ops; } else { printf("Unknown output format '%s'\n", ui_ops_name); exit(1); diff --git a/source4/torture/ui.c b/source4/torture/ui.c index a4fa5eb525..7ceb4ec428 100644 --- a/source4/torture/ui.c +++ b/source4/torture/ui.c @@ -27,6 +27,10 @@ void torture_comment(struct torture_context *context, const char *comment, ...) { va_list ap; char *tmp; + + if (!context->ui_ops->comment) + return; + va_start(ap, comment); tmp = talloc_vasprintf(context, comment, ap); @@ -35,36 +39,46 @@ void torture_comment(struct torture_context *context, const char *comment, ...) talloc_free(tmp); } - void torture_ok(struct torture_context *context) { - context->ui_ops->test_result(context, TORTURE_OK, NULL); context->success++; + + if (!context->ui_ops->test_result) + return; + + context->ui_ops->test_result(context, TORTURE_OK, NULL); } void torture_fail(struct torture_context *context, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3) { va_list ap; char *reason; + context->failed++; + + if (!context->ui_ops->test_result) + return; + va_start(ap, fmt); reason = talloc_vasprintf(context, fmt, ap); va_end(ap); context->ui_ops->test_result(context, TORTURE_FAIL, reason); talloc_free(reason); - - context->failed++; } void torture_skip(struct torture_context *context, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3) { va_list ap; char *reason; + context->skipped++; + + if (!context->ui_ops->test_result) + return; + va_start(ap, fmt); reason = talloc_vasprintf(context, fmt, ap); va_end(ap); context->ui_ops->test_result(context, TORTURE_SKIP, reason); talloc_free(reason); - context->skipped++; } void torture_register_suite(struct torture_suite *suite) @@ -133,9 +147,15 @@ BOOL torture_run_suite(struct torture_context *context, BOOL ret = True; struct torture_tcase *tcase; + if (context->ui_ops->suite_start) + context->ui_ops->suite_start(context, suite); + for (tcase = suite->testcases; tcase; tcase = tcase->next) { ret &= torture_run_tcase(context, tcase); } + + if (context->ui_ops->suite_finish) + context->ui_ops->suite_finish(context, suite); return ret; } @@ -143,7 +163,7 @@ BOOL torture_run_suite(struct torture_context *context, static BOOL internal_torture_run_test(struct torture_context *context, struct torture_tcase *tcase, struct torture_test *test, - void *tcase_data) + const void *tcase_data) { BOOL ret; void *data = NULL; @@ -159,7 +179,8 @@ static BOOL internal_torture_run_test(struct torture_context *context, context->active_tcase = tcase; context->active_test = test; - context->ui_ops->test_start(context, tcase, test); + if (context->ui_ops->test_start) + context->ui_ops->test_start(context, tcase, test); ret = test->run(context, tcase->setup?data:tcase->data, test->data); context->active_test = NULL; @@ -183,8 +204,10 @@ BOOL torture_run_tcase(struct torture_context *context, context->ui_ops->tcase_start(context, tcase); if (tcase->fixture_persistent && tcase->setup - && !tcase->setup(context, &data)) - return False; + && !tcase->setup(context, &data)) { + ret = False; + goto done; + } for (test = tcase->tests; test; test = test->next) { ret &= internal_torture_run_test(context, tcase, test, @@ -193,10 +216,14 @@ BOOL torture_run_tcase(struct torture_context *context, if (tcase->fixture_persistent && tcase->teardown && !tcase->teardown(context, data)) - return False; + ret = False; +done: context->active_tcase = NULL; + if (context->ui_ops->tcase_finish) + context->ui_ops->tcase_finish(context, tcase); + return ret; } diff --git a/source4/torture/ui.h b/source4/torture/ui.h index b5417cfa9b..1dfe89e82f 100644 --- a/source4/torture/ui.h +++ b/source4/torture/ui.h @@ -24,6 +24,7 @@ struct torture_test; struct torture_context; +struct torture_suite; struct torture_tcase; enum torture_result { @@ -36,6 +37,8 @@ enum torture_result { struct torture_ui_ops { void (*comment) (struct torture_context *, const char *); + void (*suite_start) (struct torture_context *, struct torture_suite *); + void (*suite_finish) (struct torture_context *, struct torture_suite *); void (*tcase_start) (struct torture_context *, struct torture_tcase *); void (*tcase_finish) (struct torture_context *, struct torture_tcase *); void (*test_start) (struct torture_context *, |