diff options
author | James Peach <jpeach@samba.org> | 2010-08-12 12:36:24 -0700 |
---|---|---|
committer | James Peach <jpeach@samba.org> | 2010-08-17 20:19:27 -0700 |
commit | b7ad0c6e394b09a8933080e966ba1c77575d9f31 (patch) | |
tree | 25606c309fd26b26d27b3bfb8dd24582c22cf6dc /lib/torture | |
parent | 21fe7533032168222a32bc12e2ade1169d41b763 (diff) | |
download | samba-b7ad0c6e394b09a8933080e966ba1c77575d9f31.tar.gz samba-b7ad0c6e394b09a8933080e966ba1c77575d9f31.tar.bz2 samba-b7ad0c6e394b09a8933080e966ba1c77575d9f31.zip |
smbtorture: Emit correct test results if setup fails.
If the test setup fails, we still need to format the test result for the
UI. At leas in the subunit case, the format doesn't specify what to do
here, so we fail every test manually with the setup failure message.
Diffstat (limited to 'lib/torture')
-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, |