diff options
Diffstat (limited to 'source4/torture/ui.c')
-rw-r--r-- | source4/torture/ui.c | 137 |
1 files changed, 88 insertions, 49 deletions
diff --git a/source4/torture/ui.c b/source4/torture/ui.c index 92e03fff19..5d00b664f4 100644 --- a/source4/torture/ui.c +++ b/source4/torture/ui.c @@ -22,6 +22,27 @@ #include "torture/ui.h" #include "torture/torture.h" #include "lib/util/dlinklist.h" +#include "param/param.h" +#include "system/filesys.h" + +/** + create a temporary directory. +*/ +_PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx, + const char *prefix, + char **tempdir) +{ + SMB_ASSERT(tctx->outputdir != NULL); + + *tempdir = talloc_asprintf(tctx, "%s/%s.XXXXXX", tctx->outputdir, prefix); + NT_STATUS_HAVE_NO_MEMORY(*tempdir); + + if (mkdtemp(*tempdir) == NULL) { + return map_nt_error_from_unix(errno); + } + + return NT_STATUS_OK; +} void torture_comment(struct torture_context *context, const char *comment, ...) { @@ -62,6 +83,11 @@ void torture_result(struct torture_context *context, va_start(ap, fmt); + if (context->last_reason) { + torture_warning(context, "%s", context->last_reason); + talloc_free(context->last_reason); + } + context->last_result = result; context->last_reason = talloc_vasprintf(context, fmt, ap); va_end(ap); @@ -79,20 +105,20 @@ struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name) } void torture_tcase_set_fixture(struct torture_tcase *tcase, - BOOL (*setup) (struct torture_context *, void **), - BOOL (*teardown) (struct torture_context *, void *)) + bool (*setup) (struct torture_context *, void **), + bool (*teardown) (struct torture_context *, void *)) { tcase->setup = setup; tcase->teardown = teardown; } static bool wrap_test_with_testcase(struct torture_context *torture_ctx, - struct torture_tcase *tcase, - struct torture_test *test) + struct torture_tcase *tcase, + struct torture_test *test) { bool (*fn) (struct torture_context *, - const void *tcase_data, - const void *test_data); + const void *tcase_data, + const void *test_data); fn = test->fn; @@ -112,7 +138,7 @@ struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase, test->description = NULL; test->run = wrap_test_with_testcase; test->fn = run; - test->dangerous = False; + test->dangerous = false; test->data = data; DLIST_ADD_END(tcase->tests, test, struct torture_test *); @@ -129,7 +155,7 @@ bool torture_suite_init_tcase(struct torture_suite *suite, tcase->description = NULL; tcase->setup = NULL; tcase->teardown = NULL; - tcase->fixture_persistent = True; + tcase->fixture_persistent = true; tcase->tests = NULL; DLIST_ADD_END(suite->testcases, tcase, struct torture_tcase *); @@ -149,10 +175,10 @@ struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite, return tcase; } -BOOL torture_run_suite(struct torture_context *context, +bool torture_run_suite(struct torture_context *context, struct torture_suite *suite) { - BOOL ret = True; + bool ret = true; struct torture_tcase *tcase; struct torture_suite *tsuite; char *old_testname; @@ -164,7 +190,7 @@ BOOL torture_run_suite(struct torture_context *context, old_testname = context->active_testname; if (old_testname != NULL) context->active_testname = talloc_asprintf(context, "%s-%s", - old_testname, suite->name); + old_testname, suite->name); else context->active_testname = talloc_strdup(context, suite->name); @@ -219,46 +245,58 @@ void torture_ui_test_result(struct torture_context *context, context->returncode = false; } -static BOOL internal_torture_run_test(struct torture_context *context, +static bool internal_torture_run_test(struct torture_context *context, struct torture_tcase *tcase, struct torture_test *test, - BOOL already_setup) + bool already_setup) { - BOOL ret; + bool success; char *old_testname; - if (test->dangerous && !torture_setting_bool(context, "dangerous", False)) { - torture_result(context, TORTURE_SKIP, - "disabled %s - enable dangerous tests to use", test->name); - return True; - } - - if (!already_setup && tcase->setup && - !tcase->setup(context, &(tcase->data))) - return False; - if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { old_testname = context->active_testname; - context->active_testname = talloc_asprintf(context, "%s-%s", - old_testname, test->name); + context->active_testname = talloc_asprintf(context, "%s-%s", old_testname, test->name); } + context->active_tcase = tcase; context->active_test = test; torture_ui_test_start(context, tcase, test); - context->last_reason = NULL; context->last_result = TORTURE_OK; - ret = test->run(context, tcase, test); - if (!ret && context->last_result == TORTURE_OK) { - if (context->last_reason == NULL) - context->last_reason = talloc_strdup(context, "Unknown error/failure"); + if (!already_setup && tcase->setup && + !tcase->setup(context, &(tcase->data))) { + if (context->last_reason == NULL) + context->last_reason = talloc_strdup(context, "Setup failure"); context->last_result = TORTURE_ERROR; + success = false; + } else if (test->dangerous && + !torture_setting_bool(context, "dangerous", false)) { + context->last_result = TORTURE_SKIP; + context->last_reason = talloc_asprintf(context, + "disabled %s - enable dangerous tests to use", test->name); + success = true; + } else { + success = test->run(context, tcase, test); + + if (!success && context->last_result == TORTURE_OK) { + if (context->last_reason == NULL) + context->last_reason = talloc_strdup(context, "Unknown error/failure"); + context->last_result = TORTURE_ERROR; + } + } + + if (!already_setup && tcase->teardown && !tcase->teardown(context, tcase->data)) { + if (context->last_reason == NULL) + context->last_reason = talloc_strdup(context, "Setup failure"); + context->last_result = TORTURE_ERROR; + success = false; } - torture_ui_test_result(context, context->last_result, context->last_reason); + torture_ui_test_result(context, context->last_result, + context->last_reason); talloc_free(context->last_reason); @@ -269,34 +307,35 @@ static BOOL internal_torture_run_test(struct torture_context *context, context->active_test = NULL; context->active_tcase = NULL; - if (!already_setup && tcase->teardown && !tcase->teardown(context, tcase->data)) - return False; - - return ret; + return success; } -BOOL torture_run_tcase(struct torture_context *context, +bool torture_run_tcase(struct torture_context *context, struct torture_tcase *tcase) { - BOOL ret = True; + bool ret = true; char *old_testname; struct torture_test *test; context->level++; context->active_tcase = tcase; - if (context->ui_ops->tcase_start) + if (context->ui_ops->tcase_start) context->ui_ops->tcase_start(context, tcase); if (tcase->fixture_persistent && tcase->setup && !tcase->setup(context, &tcase->data)) { - ret = False; + /* 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; } old_testname = context->active_testname; - context->active_testname = talloc_asprintf(context, "%s-%s", - old_testname, tcase->name); + 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); @@ -306,7 +345,7 @@ BOOL torture_run_tcase(struct torture_context *context, if (tcase->fixture_persistent && tcase->teardown && !tcase->teardown(context, tcase->data)) - ret = False; + ret = false; done: context->active_tcase = NULL; @@ -319,35 +358,35 @@ done: return ret; } -BOOL torture_run_test(struct torture_context *context, +bool torture_run_test(struct torture_context *context, struct torture_tcase *tcase, struct torture_test *test) { - return internal_torture_run_test(context, tcase, test, False); + return internal_torture_run_test(context, tcase, test, false); } int torture_setting_int(struct torture_context *test, const char *name, int default_value) { - return lp_parm_int(-1, "torture", name, default_value); + return lp_parm_int(global_loadparm, NULL, "torture", name, default_value); } double torture_setting_double(struct torture_context *test, const char *name, double default_value) { - return lp_parm_double(-1, "torture", name, default_value); + return lp_parm_double(global_loadparm, NULL, "torture", name, default_value); } bool torture_setting_bool(struct torture_context *test, const char *name, bool default_value) { - return lp_parm_bool(-1, "torture", name, default_value); + return lp_parm_bool(global_loadparm, NULL, "torture", name, default_value); } const char *torture_setting_string(struct torture_context *test, const char *name, const char *default_value) { - const char *ret = lp_parm_string(-1, "torture", name); + const char *ret = lp_parm_string(global_loadparm, NULL, "torture", name); if (ret == NULL) return default_value; |