diff options
-rw-r--r-- | lib/torture/torture.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/torture/torture.c b/lib/torture/torture.c index 71bd53bbf3..27b2bdcc93 100644 --- a/lib/torture/torture.c +++ b/lib/torture/torture.c @@ -343,6 +343,7 @@ static bool internal_torture_run_test(struct torture_context *context, context->active_testname = talloc_asprintf(context, "%s-%s", old_testname, test->name); } + context->active_tcase = tcase; context->active_test = test; @@ -401,43 +402,58 @@ bool torture_run_tcase(struct torture_context *context, bool ret = true; char *old_testname; struct torture_test *test; + bool setup_succeeded = true; + const char * setup_reason = "Setup failed"; context->active_tcase = tcase; if (context->results->ui_ops->tcase_start) context->results->ui_ops->tcase_start(context, tcase); - if (tcase->fixture_persistent && tcase->setup - && !tcase->setup(context, &tcase->data)) { - /* FIXME: Use torture ui ops for reporting this error */ - fprintf(stderr, "Setup failed: "); - if (context->last_reason != NULL) - fprintf(stderr, "%s", context->last_reason); - fprintf(stderr, "\n"); - ret = false; - goto done; + if (tcase->fixture_persistent && tcase->setup) { + setup_succeeded = tcase->setup(context, &tcase->data); + } + + if (!setup_succeeded) { + /* Uh-oh. The setup failed, so we can't run any of the tests + * in this testcase. The subunit format doesn't specify what + * to do here, so we keep the failure reason, and manually + * use it to fail every test. + */ + if (context->last_reason != NULL) { + setup_reason = talloc_asprintf(context, + "Setup failed: %s", context->last_reason); + } } old_testname = context->active_testname; context->active_testname = talloc_asprintf(context, "%s-%s", old_testname, tcase->name); for (test = tcase->tests; test; test = test->next) { - ret &= internal_torture_run_test(context, tcase, test, - tcase->fixture_persistent); + if (setup_succeeded) { + ret &= internal_torture_run_test(context, tcase, test, + tcase->fixture_persistent); + } else { + context->active_tcase = tcase; + context->active_test = test; + torture_ui_test_start(context, tcase, test); + torture_ui_test_result(context, TORTURE_FAIL, setup_reason); + } } talloc_free(context->active_testname); context->active_testname = old_testname; - if (tcase->fixture_persistent && tcase->teardown && - !tcase->teardown(context, tcase->data)) + if (setup_succeeded && tcase->fixture_persistent && tcase->teardown && + !tcase->teardown(context, tcase->data)) { ret = false; + } -done: context->active_tcase = NULL; + context->active_test = NULL; if (context->results->ui_ops->tcase_finish) context->results->ui_ops->tcase_finish(context, tcase); - return ret; + return (!setup_succeeded) ? false : ret; } bool torture_run_test(struct torture_context *context, |