summaryrefslogtreecommitdiffstats
path: root/lib/torture
diff options
context:
space:
mode:
Diffstat (limited to 'lib/torture')
-rw-r--r--lib/torture/simple.c85
-rw-r--r--lib/torture/subunit.c143
-rw-r--r--lib/torture/torture.c835
-rw-r--r--lib/torture/torture.h810
-rw-r--r--lib/torture/wscript_build8
5 files changed, 1881 insertions, 0 deletions
diff --git a/lib/torture/simple.c b/lib/torture/simple.c
new file mode 100644
index 0000000..d234776
--- /dev/null
+++ b/lib/torture/simple.c
@@ -0,0 +1,85 @@
+/*
+ Unix SMB/CIFS implementation.
+ SMB torture tester
+ Copyright (C) Andrew Tridgell 1997-2003
+ Copyright (C) Jelmer Vernooij 2006-2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/torture/torture.h"
+
+static struct timeval last_suite_started;
+
+static void simple_suite_start(struct torture_context *ctx,
+ struct torture_suite *suite)
+{
+ last_suite_started = timeval_current();
+ printf("Running %s\n", suite->name);
+}
+
+static void simple_suite_finish(struct torture_context *ctx,
+ struct torture_suite *suite)
+{
+
+ printf("%s took %g secs\n\n", suite->name,
+ timeval_elapsed(&last_suite_started));
+}
+
+static void simple_test_result(struct torture_context *context,
+ enum torture_result res, const char *reason)
+{
+ switch (res) {
+ case TORTURE_OK:
+ if (reason)
+ printf("OK: %s\n", reason);
+ break;
+ case TORTURE_FAIL:
+ printf("TEST %s FAILED! - %s\n", context->active_test->name, reason);
+ break;
+ case TORTURE_ERROR:
+ printf("ERROR IN TEST %s! - %s\n", context->active_test->name, reason);
+ break;
+ case TORTURE_SKIP:
+ printf("SKIP: %s - %s\n", context->active_test->name, reason);
+ break;
+ }
+}
+
+static void simple_comment(struct torture_context *test,
+ const char *comment)
+{
+ printf("%s", comment);
+}
+
+static void simple_warning(struct torture_context *test,
+ const char *comment)
+{
+ fprintf(stderr, "WARNING: %s\n", comment);
+}
+
+static void simple_progress(struct torture_context *test,
+ int offset, enum torture_progress_whence whence)
+{
+}
+
+const struct torture_ui_ops torture_simple_ui_ops = {
+ .comment = simple_comment,
+ .warning = simple_warning,
+ .suite_start = simple_suite_start,
+ .suite_finish = simple_suite_finish,
+ .test_result = simple_test_result,
+ .progress = simple_progress,
+};
diff --git a/lib/torture/subunit.c b/lib/torture/subunit.c
new file mode 100644
index 0000000..693d903
--- /dev/null
+++ b/lib/torture/subunit.c
@@ -0,0 +1,143 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/torture/torture.h"
+
+static void subunit_send_event(char const * const event,
+ char const * const name,
+ char const * const details)
+{
+ if (NULL == details) {
+ printf("%s: %s\n", event, name);
+ } else {
+ printf("%s: %s [\n", event, name);
+ printf("%s", details);
+ if (details[strlen(details) - 1] != '\n')
+ puts("");
+ puts("]");
+ }
+ fflush(stdout);
+}
+
+static void torture_subunit_suite_start(struct torture_context *ctx,
+ struct torture_suite *suite)
+{
+}
+
+static void torture_subunit_report_time(struct torture_context *tctx)
+{
+ struct timespec tp;
+ struct tm *tmp;
+ char timestr[200];
+ if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
+ perror("clock_gettime");
+ return;
+ }
+
+ tmp = gmtime(&tp.tv_sec);
+ if (!tmp) {
+ perror("gmtime");
+ return;
+ }
+
+ if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
+ perror("strftime");
+ return;
+ }
+
+ printf("time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
+}
+
+static void torture_subunit_test_start(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
+ subunit_send_event("test", fullname, NULL);
+ torture_subunit_report_time(context);
+ talloc_free(fullname);
+}
+
+static void torture_subunit_test_result(struct torture_context *context,
+ enum torture_result res, const char *reason)
+{
+ char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
+ const char *result_str = "unknown";
+ torture_subunit_report_time(context);
+ switch (res) {
+ case TORTURE_OK:
+ result_str = "success";
+ break;
+ case TORTURE_FAIL:
+ result_str = "failure";
+ break;
+ case TORTURE_ERROR:
+ result_str = "error";
+ break;
+ case TORTURE_SKIP:
+ result_str = "skip";
+ break;
+ }
+ subunit_send_event(result_str, fullname, reason);
+ talloc_free(fullname);
+}
+
+static void torture_subunit_comment(struct torture_context *test,
+ const char *comment)
+{
+ fprintf(stderr, "%s", comment);
+}
+
+static void torture_subunit_warning(struct torture_context *test,
+ const char *comment)
+{
+ fprintf(stderr, "WARNING!: %s\n", comment);
+}
+
+static void torture_subunit_progress(struct torture_context *tctx, int offset, enum torture_progress_whence whence)
+{
+ switch (whence) {
+ case TORTURE_PROGRESS_SET:
+ printf("progress: %d\n", offset);
+ break;
+ case TORTURE_PROGRESS_CUR:
+ printf("progress: %+-d\n", offset);
+ break;
+ case TORTURE_PROGRESS_POP:
+ printf("progress: pop\n");
+ break;
+ case TORTURE_PROGRESS_PUSH:
+ printf("progress: push\n");
+ break;
+ default:
+ fprintf(stderr, "Invalid call to progress()\n");
+ break;
+ }
+}
+
+const struct torture_ui_ops torture_subunit_ui_ops = {
+ .comment = torture_subunit_comment,
+ .warning = torture_subunit_warning,
+ .test_start = torture_subunit_test_start,
+ .test_result = torture_subunit_test_result,
+ .suite_start = torture_subunit_suite_start,
+ .progress = torture_subunit_progress,
+ .report_time = torture_subunit_report_time,
+};
diff --git a/lib/torture/torture.c b/lib/torture/torture.c
new file mode 100644
index 0000000..b8fb28f
--- /dev/null
+++ b/lib/torture/torture.c
@@ -0,0 +1,835 @@
+/*
+ Unix SMB/CIFS implementation.
+ SMB torture UI functions
+
+ Copyright (C) Jelmer Vernooij 2006-2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "source4/include/includes.h"
+#include "../torture/torture.h"
+#include "../lib/util/dlinklist.h"
+#include "param/param.h"
+#include "system/filesys.h"
+#include "system/dir.h"
+
+
+struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops)
+{
+ struct torture_results *results = talloc_zero(mem_ctx, struct torture_results);
+
+ results->ui_ops = ui_ops;
+ results->returncode = true;
+
+ if (ui_ops->init)
+ ui_ops->init(results);
+
+ return results;
+}
+
+/**
+ * Initialize a torture context
+ */
+struct torture_context *torture_context_init(struct tevent_context *event_ctx,
+ struct torture_results *results)
+{
+ struct torture_context *torture = talloc_zero(event_ctx,
+ struct torture_context);
+
+ if (torture == NULL)
+ return NULL;
+
+ torture->ev = event_ctx;
+ torture->results = talloc_reference(torture, results);
+
+ /*
+ * We start with an empty subunit prefix
+ */
+ torture_subunit_prefix_reset(torture, NULL);
+
+ return torture;
+}
+
+/**
+ * Create a sub torture context
+ */
+struct torture_context *torture_context_child(struct torture_context *parent)
+{
+ struct torture_context *subtorture = talloc_zero(parent, struct torture_context);
+
+ if (subtorture == NULL)
+ return NULL;
+
+ subtorture->ev = talloc_reference(subtorture, parent->ev);
+ subtorture->lp_ctx = talloc_reference(subtorture, parent->lp_ctx);
+ subtorture->outputdir = talloc_reference(subtorture, parent->outputdir);
+ subtorture->results = talloc_reference(subtorture, parent->results);
+
+ return subtorture;
+}
+
+/**
+ create a temporary directory under the output dir
+*/
+_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_common(errno);
+ }
+
+ return NT_STATUS_OK;
+}
+
+static int local_deltree(const char *path)
+{
+ int ret = 0;
+ struct dirent *dirent;
+ DIR *dir = opendir(path);
+ if (!dir) {
+ char *error = talloc_asprintf(NULL, "Could not open directory %s", path);
+ perror(error);
+ talloc_free(error);
+ return -1;
+ }
+ while ((dirent = readdir(dir))) {
+ char *name;
+ if ((strcmp(dirent->d_name, ".") == 0) || (strcmp(dirent->d_name, "..") == 0)) {
+ continue;
+ }
+ name = talloc_asprintf(NULL, "%s/%s", path,
+ dirent->d_name);
+ if (name == NULL) {
+ closedir(dir);
+ return -1;
+ }
+ DEBUG(0, ("About to remove %s\n", name));
+ ret = remove(name);
+ if (ret == 0) {
+ talloc_free(name);
+ continue;
+ }
+
+ if (errno == ENOTEMPTY) {
+ ret = local_deltree(name);
+ if (ret == 0) {
+ ret = remove(name);
+ }
+ }
+ talloc_free(name);
+ if (ret != 0) {
+ char *error = talloc_asprintf(NULL, "Could not remove %s", path);
+ perror(error);
+ talloc_free(error);
+ break;
+ }
+ }
+ closedir(dir);
+ rmdir(path);
+ return ret;
+}
+
+_PUBLIC_ NTSTATUS torture_deltree_outputdir(struct torture_context *tctx)
+{
+ if (tctx->outputdir == NULL) {
+ return NT_STATUS_OK;
+ }
+ if ((strcmp(tctx->outputdir, "/") == 0)
+ || (strcmp(tctx->outputdir, "") == 0)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (local_deltree(tctx->outputdir) == -1) {
+ if (errno != 0) {
+ return map_nt_error_from_unix_common(errno);
+ }
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ return NT_STATUS_OK;
+}
+
+/**
+ * Comment on the status/progress of a test
+ */
+void torture_comment(struct torture_context *context, const char *comment, ...)
+{
+ va_list ap;
+ char *tmp;
+
+ if (!context->results->ui_ops->comment)
+ return;
+
+ va_start(ap, comment);
+ tmp = talloc_vasprintf(context, comment, ap);
+ va_end(ap);
+
+ context->results->ui_ops->comment(context, tmp);
+
+ talloc_free(tmp);
+}
+
+/**
+ * Print a warning about the current test
+ */
+void torture_warning(struct torture_context *context, const char *comment, ...)
+{
+ va_list ap;
+ char *tmp;
+
+ if (!context->results->ui_ops->warning)
+ return;
+
+ va_start(ap, comment);
+ tmp = talloc_vasprintf(context, comment, ap);
+ va_end(ap);
+
+ context->results->ui_ops->warning(context, tmp);
+
+ talloc_free(tmp);
+}
+
+/**
+ * Store the result of a torture test.
+ */
+void torture_result(struct torture_context *context,
+ enum torture_result result, const char *fmt, ...)
+{
+ va_list ap;
+
+ 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);
+}
+
+/**
+ * Create a new torture suite
+ */
+struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name)
+{
+ struct torture_suite *suite = talloc_zero(ctx, struct torture_suite);
+
+ suite->name = talloc_strdup(suite, name);
+ suite->testcases = NULL;
+ suite->children = NULL;
+
+ return suite;
+}
+
+/**
+ * Set the setup() and teardown() functions for a testcase.
+ */
+void torture_tcase_set_fixture(struct torture_tcase *tcase,
+ bool (*setup) (struct torture_context *, void **),
+ bool (*teardown) (struct torture_context *, void *))
+{
+ tcase->setup = setup;
+ tcase->teardown = teardown;
+}
+
+static bool wrap_test_with_testcase_const(struct torture_context *torture_ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*fn) (struct torture_context *,
+ const void *tcase_data,
+ const void *test_data);
+
+ fn = test->fn;
+
+ return fn(torture_ctx, tcase->data, test->data);
+}
+
+/**
+ * Add a test that uses const data to a testcase
+ */
+struct torture_test *torture_tcase_add_test_const(struct torture_tcase *tcase,
+ const char *name,
+ bool (*run) (struct torture_context *, const void *tcase_data,
+ const void *test_data),
+ const void *data)
+{
+ struct torture_test *test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_test_with_testcase_const;
+ test->fn = run;
+ test->dangerous = false;
+ test->data = data;
+
+ DLIST_ADD_END(tcase->tests, test);
+
+ return test;
+}
+
+/**
+ * Add a new testcase
+ */
+bool torture_suite_init_tcase(struct torture_suite *suite,
+ struct torture_tcase *tcase,
+ const char *name)
+{
+ tcase->name = talloc_strdup(tcase, name);
+ tcase->description = NULL;
+ tcase->setup = NULL;
+ tcase->teardown = NULL;
+ tcase->fixture_persistent = true;
+ tcase->tests = NULL;
+
+ DLIST_ADD_END(suite->testcases, tcase);
+ tcase->suite = suite;
+
+ return true;
+}
+
+
+struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
+ const char *name)
+{
+ struct torture_tcase *tcase = talloc(suite, struct torture_tcase);
+
+ if (!torture_suite_init_tcase(suite, tcase, name))
+ return NULL;
+
+ return tcase;
+}
+
+char *torture_subunit_test_name(struct torture_context *ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ if (!strcmp(tcase->name, test->name)) {
+ return talloc_asprintf(ctx, "%s%s",
+ ctx->active_prefix->subunit_prefix,
+ test->name);
+ } else {
+ return talloc_asprintf(ctx, "%s%s.%s",
+ ctx->active_prefix->subunit_prefix,
+ tcase->name, test->name);
+ }
+}
+
+void torture_subunit_prefix_reset(struct torture_context *ctx,
+ const char *name)
+{
+ struct torture_subunit_prefix *prefix = &ctx->_initial_prefix;
+
+ ZERO_STRUCTP(prefix);
+
+ if (name != NULL) {
+ int ret;
+
+ ret = snprintf(prefix->subunit_prefix,
+ sizeof(prefix->subunit_prefix),
+ "%s.", name);
+ if (ret < 0) {
+ abort();
+ }
+ }
+
+ ctx->active_prefix = prefix;
+}
+
+static void torture_subunit_prefix_push(struct torture_context *ctx,
+ struct torture_subunit_prefix *prefix,
+ const char *name)
+{
+ *prefix = (struct torture_subunit_prefix) {
+ .parent = ctx->active_prefix,
+ };
+
+ if (ctx->active_prefix->parent != NULL ||
+ ctx->active_prefix->subunit_prefix[0] != '\0') {
+ /*
+ * We need a new component for the prefix.
+ */
+ int ret;
+
+ ret = snprintf(prefix->subunit_prefix,
+ sizeof(prefix->subunit_prefix),
+ "%s%s.",
+ ctx->active_prefix->subunit_prefix,
+ name);
+ if (ret < 0) {
+ abort();
+ }
+ }
+
+ ctx->active_prefix = prefix;
+}
+
+static void torture_subunit_prefix_pop(struct torture_context *ctx)
+{
+ ctx->active_prefix = ctx->active_prefix->parent;
+}
+
+int torture_suite_children_count(const struct torture_suite *suite)
+{
+ int ret = 0;
+ struct torture_tcase *tcase;
+ struct torture_test *test;
+ struct torture_suite *tsuite;
+ for (tcase = suite->testcases; tcase; tcase = tcase->next) {
+ for (test = tcase->tests; test; test = test->next) {
+ ret++;
+ }
+ }
+ for (tsuite = suite->children; tsuite; tsuite = tsuite->next) {
+ ret ++;
+ }
+ return ret;
+}
+
+/**
+ * Run a torture test suite.
+ */
+bool torture_run_suite(struct torture_context *context,
+ struct torture_suite *suite)
+{
+ return torture_run_suite_restricted(context, suite, NULL);
+}
+
+bool torture_run_suite_restricted(struct torture_context *context,
+ struct torture_suite *suite, const char **restricted)
+{
+ struct torture_subunit_prefix _prefix_stack;
+ bool ret = true;
+ struct torture_tcase *tcase;
+ struct torture_suite *tsuite;
+
+ torture_subunit_prefix_push(context, &_prefix_stack, suite->name);
+
+ if (context->results->ui_ops->suite_start)
+ context->results->ui_ops->suite_start(context, suite);
+
+ /* FIXME: Adjust torture_suite_children_count if restricted != NULL */
+ context->results->ui_ops->progress(context,
+ torture_suite_children_count(suite), TORTURE_PROGRESS_SET);
+
+ for (tcase = suite->testcases; tcase; tcase = tcase->next) {
+ ret &= torture_run_tcase_restricted(context, tcase, restricted);
+ }
+
+ for (tsuite = suite->children; tsuite; tsuite = tsuite->next) {
+ context->results->ui_ops->progress(context, 0, TORTURE_PROGRESS_PUSH);
+ ret &= torture_run_suite_restricted(context, tsuite, restricted);
+ context->results->ui_ops->progress(context, 0, TORTURE_PROGRESS_POP);
+ }
+
+ if (context->results->ui_ops->suite_finish)
+ context->results->ui_ops->suite_finish(context, suite);
+
+ torture_subunit_prefix_pop(context);
+
+ return ret;
+}
+
+void torture_ui_test_start(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ if (context->results->ui_ops->test_start)
+ context->results->ui_ops->test_start(context, tcase, test);
+}
+
+void torture_ui_test_result(struct torture_context *context,
+ enum torture_result result,
+ const char *comment)
+{
+ if (context->results->ui_ops->test_result)
+ context->results->ui_ops->test_result(context, result, comment);
+
+ if (result == TORTURE_ERROR || result == TORTURE_FAIL)
+ context->results->returncode = false;
+}
+
+static bool test_needs_running(const char *name, const char **restricted)
+{
+ int i;
+ if (restricted == NULL)
+ return true;
+ for (i = 0; restricted[i]; i++) {
+ if (!strcmp(name, restricted[i]))
+ return true;
+ }
+ return false;
+}
+
+static bool internal_torture_run_test(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test,
+ bool already_setup,
+ const char **restricted)
+{
+ bool success;
+ char *subunit_testname = torture_subunit_test_name(context, tcase, test);
+
+ if (!test_needs_running(subunit_testname, restricted))
+ return true;
+
+ context->active_tcase = tcase;
+ context->active_test = test;
+
+ torture_ui_test_start(context, tcase, test);
+
+ context->last_reason = NULL;
+ context->last_result = TORTURE_OK;
+
+ 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. Missing torture_fail() or torture_assert_*() call?");
+ 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);
+
+ talloc_free(context->last_reason);
+ context->last_reason = NULL;
+
+ context->active_test = NULL;
+ context->active_tcase = NULL;
+
+ return success;
+}
+
+bool torture_run_tcase(struct torture_context *context,
+ struct torture_tcase *tcase)
+{
+ return torture_run_tcase_restricted(context, tcase, NULL);
+}
+
+bool torture_run_tcase_restricted(struct torture_context *context,
+ struct torture_tcase *tcase, const char **restricted)
+{
+ bool ret = true;
+ 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) {
+ 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);
+ }
+ }
+
+ for (test = tcase->tests; test; test = test->next) {
+ if (setup_succeeded) {
+ ret &= internal_torture_run_test(context, tcase, test,
+ tcase->fixture_persistent, restricted);
+ } 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);
+ }
+ }
+
+ if (setup_succeeded && tcase->fixture_persistent && tcase->teardown &&
+ !tcase->teardown(context, tcase->data)) {
+ ret = false;
+ }
+
+ context->active_tcase = NULL;
+ context->active_test = NULL;
+
+ if (context->results->ui_ops->tcase_finish)
+ context->results->ui_ops->tcase_finish(context, tcase);
+
+ return (!setup_succeeded) ? false : ret;
+}
+
+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, NULL);
+}
+
+bool torture_run_test_restricted(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test,
+ const char **restricted)
+{
+ return internal_torture_run_test(context, tcase, test, false, restricted);
+}
+
+int torture_setting_int(struct torture_context *test, const char *name,
+ int default_value)
+{
+ return lpcfg_parm_int(test->lp_ctx, NULL, "torture", name, default_value);
+}
+
+unsigned long torture_setting_ulong(struct torture_context *test,
+ const char *name,
+ unsigned long default_value)
+{
+ return lpcfg_parm_ulong(test->lp_ctx, NULL, "torture", name,
+ default_value);
+}
+
+double torture_setting_double(struct torture_context *test, const char *name,
+ double default_value)
+{
+ return lpcfg_parm_double(test->lp_ctx, NULL, "torture", name, default_value);
+}
+
+bool torture_setting_bool(struct torture_context *test, const char *name,
+ bool default_value)
+{
+ return lpcfg_parm_bool(test->lp_ctx, NULL, "torture", name, default_value);
+}
+
+const char *torture_setting_string(struct torture_context *test,
+ const char *name,
+ const char *default_value)
+{
+ const char *ret;
+
+ SMB_ASSERT(test != NULL);
+ SMB_ASSERT(test->lp_ctx != NULL);
+
+ ret = lpcfg_parm_string(test->lp_ctx, NULL, "torture", name);
+
+ if (ret == NULL)
+ return default_value;
+
+ return ret;
+}
+
+static bool wrap_test_with_simple_tcase_const (
+ struct torture_context *torture_ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*fn) (struct torture_context *, const void *tcase_data);
+
+ fn = test->fn;
+
+ return fn(torture_ctx, test->data);
+}
+
+struct torture_tcase *torture_suite_add_simple_tcase_const(
+ struct torture_suite *suite, const char *name,
+ bool (*run) (struct torture_context *test, const void *),
+ const void *data)
+{
+ struct torture_tcase *tcase;
+ struct torture_test *test;
+
+ tcase = torture_suite_add_tcase(suite, name);
+
+ test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_test_with_simple_tcase_const;
+ test->fn = run;
+ test->data = data;
+ test->dangerous = false;
+
+ DLIST_ADD_END(tcase->tests, test);
+ test->tcase = tcase;
+
+ return tcase;
+}
+
+static bool wrap_simple_test(struct torture_context *torture_ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*fn) (struct torture_context *);
+
+ fn = test->fn;
+
+ return fn(torture_ctx);
+}
+
+struct torture_tcase *torture_suite_add_simple_test(
+ struct torture_suite *suite,
+ const char *name,
+ bool (*run) (struct torture_context *test))
+{
+ struct torture_test *test;
+ struct torture_tcase *tcase;
+
+ tcase = torture_suite_add_tcase(suite, name);
+
+ test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_simple_test;
+ test->fn = run;
+ test->dangerous = false;
+
+ DLIST_ADD_END(tcase->tests, test);
+
+ return tcase;
+}
+
+/**
+ * Add a child testsuite to a testsuite.
+ */
+bool torture_suite_add_suite(struct torture_suite *suite,
+ struct torture_suite *child)
+{
+ if (child == NULL)
+ return false;
+
+ DLIST_ADD_END(suite->children, child);
+ child->parent = suite;
+
+ /* FIXME: Check for duplicates and return false if the
+ * added suite already exists as a child */
+
+ return true;
+}
+
+/**
+ * Find the child testsuite with the specified name.
+ */
+struct torture_suite *torture_find_suite(struct torture_suite *parent,
+ const char *name)
+{
+ struct torture_suite *child;
+
+ for (child = parent->children; child; child = child->next)
+ if (!strcmp(child->name, name))
+ return child;
+
+ return NULL;
+}
+
+static bool wrap_test_with_simple_test_const(struct torture_context *torture_ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*fn) (struct torture_context *, const void *tcase_data);
+
+ fn = test->fn;
+
+ return fn(torture_ctx, tcase->data);
+}
+
+struct torture_test *torture_tcase_add_simple_test_const(
+ struct torture_tcase *tcase,
+ const char *name,
+ bool (*run) (struct torture_context *test,
+ const void *tcase_data))
+{
+ struct torture_test *test;
+
+ test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_test_with_simple_test_const;
+ test->fn = run;
+ test->data = NULL;
+ test->dangerous = false;
+
+ DLIST_ADD_END(tcase->tests, test);
+
+ return test;
+}
+
+static bool wrap_test_with_simple_test(struct torture_context *torture_ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*fn) (struct torture_context *, void *tcase_data);
+
+ fn = test->fn;
+
+ return fn(torture_ctx, tcase->data);
+}
+
+struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
+ const char *name,
+ bool (*run) (struct torture_context *test, void *tcase_data))
+{
+ struct torture_test *test;
+
+ test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_test_with_simple_test;
+ test->fn = run;
+ test->data = NULL;
+ test->dangerous = false;
+
+ DLIST_ADD_END(tcase->tests, test);
+
+ return test;
+}
+
+void torture_ui_report_time(struct torture_context *context)
+{
+ if (context->results->ui_ops->report_time)
+ context->results->ui_ops->report_time(context);
+}
diff --git a/lib/torture/torture.h b/lib/torture/torture.h
new file mode 100644
index 0000000..ea34c15
--- /dev/null
+++ b/lib/torture/torture.h
@@ -0,0 +1,810 @@
+/*
+ Unix SMB/CIFS implementation.
+ SMB torture UI functions
+
+ Copyright (C) Jelmer Vernooij 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __TORTURE_UI_H__
+#define __TORTURE_UI_H__
+
+struct torture_test;
+struct torture_context;
+struct torture_suite;
+struct torture_tcase;
+struct torture_results;
+
+enum torture_result {
+ TORTURE_OK=0,
+ TORTURE_FAIL=1,
+ TORTURE_ERROR=2,
+ TORTURE_SKIP=3
+};
+
+enum torture_progress_whence {
+ TORTURE_PROGRESS_SET,
+ TORTURE_PROGRESS_CUR,
+ TORTURE_PROGRESS_POP,
+ TORTURE_PROGRESS_PUSH,
+};
+
+/*
+ * These callbacks should be implemented by any backend that wishes
+ * to listen to reports from the torture tests.
+ */
+struct torture_ui_ops
+{
+ void (*init) (struct torture_results *);
+ void (*comment) (struct torture_context *, const char *);
+ void (*warning) (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 *,
+ struct torture_tcase *,
+ struct torture_test *);
+ void (*test_result) (struct torture_context *,
+ enum torture_result, const char *reason);
+ void (*progress) (struct torture_context *, int offset, enum torture_progress_whence whence);
+ void (*report_time) (struct torture_context *);
+};
+
+void torture_ui_test_start(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test);
+
+void torture_ui_test_result(struct torture_context *context,
+ enum torture_result result,
+ const char *comment);
+
+void torture_ui_report_time(struct torture_context *context);
+
+/*
+ * Holds information about a specific run of the testsuite.
+ * The data in this structure should be considered private to
+ * the torture tests and should only be used directly by the torture
+ * code and the ui backends.
+ *
+ * Torture tests should instead call the torture_*() macros and functions
+ * specified below.
+ */
+
+struct torture_subunit_prefix {
+ const struct torture_subunit_prefix *parent;
+ char subunit_prefix[256];
+};
+
+struct torture_context
+{
+ struct torture_results *results;
+
+ struct torture_test *active_test;
+ struct torture_tcase *active_tcase;
+ struct torture_subunit_prefix _initial_prefix;
+ const struct torture_subunit_prefix *active_prefix;
+
+ enum torture_result last_result;
+ char *last_reason;
+
+ /** Directory used for temporary test data */
+ const char *outputdir;
+
+ /** Event context */
+ struct tevent_context *ev;
+
+ /** Loadparm context (will go away in favor of torture_setting_ at some point) */
+ struct loadparm_context *lp_ctx;
+
+ int conn_index;
+};
+
+struct torture_results
+{
+ const struct torture_ui_ops *ui_ops;
+ void *ui_data;
+
+ /** Whether tests should avoid writing output to stdout */
+ bool quiet;
+
+ bool returncode;
+};
+
+/*
+ * Describes a particular torture test
+ */
+struct torture_test {
+ /** Short unique name for the test. */
+ const char *name;
+
+ /** Long description for the test. */
+ const char *description;
+
+ /** Whether this is a dangerous test
+ * (can corrupt the remote servers data or bring it down). */
+ bool dangerous;
+
+ /** Function to call to run this test */
+ bool (*run) (struct torture_context *torture_ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test);
+
+ struct torture_test *prev, *next;
+
+ /** Pointer to the actual test function. This is run by the
+ * run() function above. */
+ void *fn;
+
+ /** Use data for this test */
+ const void *data;
+
+ struct torture_tcase *tcase;
+};
+
+/*
+ * Describes a particular test case.
+ */
+struct torture_tcase {
+ const char *name;
+ const char *description;
+ bool (*setup) (struct torture_context *tcase, void **data);
+ bool (*teardown) (struct torture_context *tcase, void *data);
+ bool fixture_persistent;
+ void *data;
+ struct torture_test *tests;
+ struct torture_tcase *prev, *next;
+ const struct torture_suite *suite;
+};
+
+struct torture_suite
+{
+ const char *name;
+ const char *description;
+ struct torture_tcase *testcases;
+ struct torture_suite *children;
+ const struct torture_suite *parent;
+
+ /* Pointers to siblings of this torture suite */
+ struct torture_suite *prev, *next;
+};
+
+/** Create a new torture suite */
+struct torture_suite *torture_suite_create(TALLOC_CTX *mem_ctx,
+ const char *name);
+
+/** Change the setup and teardown functions for a testcase */
+void torture_tcase_set_fixture(struct torture_tcase *tcase,
+ bool (*setup) (struct torture_context *, void **),
+ bool (*teardown) (struct torture_context *, void *));
+
+/* Add another test to run for a particular testcase */
+struct torture_test *torture_tcase_add_test_const(struct torture_tcase *tcase,
+ const char *name,
+ bool (*run) (struct torture_context *test,
+ const void *tcase_data, const void *test_data),
+ const void *test_data);
+
+/* Add a testcase to a testsuite */
+struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
+ const char *name);
+
+/* Convenience wrapper that adds a testcase against only one
+ * test will be run */
+struct torture_tcase *torture_suite_add_simple_tcase_const(
+ struct torture_suite *suite,
+ const char *name,
+ bool (*run) (struct torture_context *test,
+ const void *test_data),
+ const void *data);
+
+/* Convenience function that adds a test which only
+ * gets the test case data */
+struct torture_test *torture_tcase_add_simple_test_const(
+ struct torture_tcase *tcase,
+ const char *name,
+ bool (*run) (struct torture_context *test,
+ const void *tcase_data));
+
+/* Convenience wrapper that adds a test that doesn't need any
+ * testcase data */
+struct torture_tcase *torture_suite_add_simple_test(
+ struct torture_suite *suite,
+ const char *name,
+ bool (*run) (struct torture_context *test));
+
+/* Add a child testsuite to an existing testsuite */
+bool torture_suite_add_suite(struct torture_suite *suite,
+ struct torture_suite *child);
+
+char *torture_subunit_test_name(struct torture_context *ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test);
+void torture_subunit_prefix_reset(struct torture_context *ctx,
+ const char *name);
+
+/* Run the specified testsuite recursively */
+bool torture_run_suite(struct torture_context *context,
+ struct torture_suite *suite);
+
+/* Run the specified testsuite recursively, but only the specified
+ * tests */
+bool torture_run_suite_restricted(struct torture_context *context,
+ struct torture_suite *suite, const char **restricted);
+
+/* Run the specified testcase */
+bool torture_run_tcase(struct torture_context *context,
+ struct torture_tcase *tcase);
+
+bool torture_run_tcase_restricted(struct torture_context *context,
+ struct torture_tcase *tcase, const char **restricted);
+
+/* Run the specified test */
+bool torture_run_test(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test);
+
+bool torture_run_test_restricted(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test,
+ const char **restricted);
+
+void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
+void torture_warning(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
+void torture_result(struct torture_context *test,
+ enum torture_result, const char *reason, ...) PRINTF_ATTRIBUTE(3,4);
+
+#define torture_assert(torture_ctx,expr,cmt) do { \
+ if (!(expr)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
+ return false; \
+ } \
+} while(0)
+
+#define torture_assertf(torture_ctx, expr, format, ...) do { \
+ if (!(expr)) { \
+ char *_msg = talloc_asprintf(torture_ctx, \
+ format, \
+ __VA_ARGS__); \
+ torture_result(torture_ctx, \
+ TORTURE_FAIL, \
+ __location__": Expression `%s' failed: %s", \
+ __STRING(expr), _msg); \
+ talloc_free(_msg); \
+ return false; \
+ } \
+} while(0)
+
+#define torture_assert_goto(torture_ctx,expr,ret,label,cmt) do { \
+ if (!(expr)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
+ ret = false; \
+ goto label; \
+ } \
+} while(0)
+
+#define torture_assert_werr_equal(torture_ctx, got, expected, cmt) \
+ do { WERROR __got = got, __expected = expected; \
+ if (!W_ERROR_EQUAL(__got, __expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", win_errstr(__got), win_errstr(__expected), cmt); \
+ return false; \
+ } \
+ } while (0)
+
+#define torture_assert_ntstatus_equal(torture_ctx,got,expected,cmt) \
+ do { NTSTATUS __got = got, __expected = expected; \
+ if (!NT_STATUS_EQUAL(__got, __expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_errstr(__got), nt_errstr(__expected), cmt); \
+ return false; \
+ }\
+ } while(0)
+
+#define torture_assert_ntstatus_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
+ do { NTSTATUS __got = got, __expected = expected; \
+ if (!NT_STATUS_EQUAL(__got, __expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_errstr(__got), nt_errstr(__expected), cmt); \
+ ret = false; \
+ goto label; \
+ }\
+ } while(0)
+
+#define torture_assert_ndr_err_equal(torture_ctx,got,expected,cmt) \
+ do { enum ndr_err_code __got = got, __expected = expected; \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
+ return false; \
+ }\
+ } while(0)
+
+#define torture_assert_ndr_err_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
+ do { enum ndr_err_code __got = got, __expected = expected; \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
+ ret = false; \
+ goto label; \
+ }\
+ } while(0)
+
+#define torture_assert_hresult_equal(torture_ctx, got, expected, cmt) \
+ do { HRESULT __got = got, __expected = expected; \
+ if (!HRES_IS_EQUAL(__got, __expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", hresult_errstr(__got), hresult_errstr(__expected), cmt); \
+ return false; \
+ } \
+ } while (0)
+
+#define torture_assert_krb5_error_equal(torture_ctx, got, expected, cmt) \
+ do { krb5_error_code __got = got, __expected = expected; \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, error_message(__got), __expected, error_message(__expected), cmt); \
+ return false; \
+ } \
+ } while (0)
+
+#define torture_assert_casestr_equal(torture_ctx,got,expected,cmt) \
+ do { const char *__got = (got), *__expected = (expected); \
+ if (!strequal(__got, __expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %s, expected %s: %s", \
+ __got, __expected == NULL ? "null" : __expected, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_str_equal(torture_ctx,got,expected,cmt)\
+ do { const char *__got = (got), *__expected = (expected); \
+ if (strcmp_safe(__got, __expected) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %s, expected %s: %s", \
+ __got, __expected == NULL ? "NULL" : __expected, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_strn_equal(torture_ctx,got,expected,len,cmt)\
+ do { const char *__got = (got), *__expected = (expected); \
+ if (strncmp(__got, __expected, len) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" %s of len %d did not match "#expected" %s: %s", \
+ __got, (int)len, __expected, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_str_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
+ do { const char *__got = (got), *__expected = (expected); \
+ if (strcmp_safe(__got, __expected) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %s, expected %s: %s", \
+ __got, __expected, cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_mem_equal(torture_ctx,got,expected,len,cmt)\
+ do { const void *__got = (got), *__expected = (expected); \
+ if (memcmp(__got, __expected, len) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" of len %d did not match "#expected": %s", (int)len, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_mem_equal_goto(torture_ctx,got,expected,len,ret,label,cmt) \
+ do { const void *__got = (got), *__expected = (expected); \
+ if (memcmp(__got, __expected, len) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" of len %d did not match "#expected": %s", (int)len, cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_mem_not_equal_goto(torture_ctx,got,expected,len,ret,label,cmt) \
+ do { const void *__got = (got), *__expected = (expected); \
+ if (memcmp(__got, __expected, len) == 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" of len %d unexpectedly matches "#expected": %s", (int)len, cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+static inline void torture_dump_data_str_cb(const char *buf, void *private_data)
+{
+ char **dump = (char **)private_data;
+ *dump = talloc_strdup_append_buffer(*dump, buf);
+}
+
+#define torture_assert_data_blob_equal(torture_ctx,got,expected,cmt)\
+ do { const DATA_BLOB __got = (got), __expected = (expected); \
+ if (__got.length != __expected.length) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got".len %d did not match "#expected" len %d: %s", \
+ (int)__got.length, (int)__expected.length, cmt); \
+ return false; \
+ } \
+ if (memcmp(__got.data, __expected.data, __got.length) != 0) { \
+ char *__dump = NULL; \
+ uint8_t __byte_a = 0x00;\
+ uint8_t __byte_b = 0x00;\
+ size_t __i;\
+ for (__i=0; __i < __expected.length; __i++) {\
+ __byte_a = __expected.data[__i];\
+ if (__i == __got.length) {\
+ __byte_b = 0x00;\
+ break;\
+ }\
+ __byte_b = __got.data[__i];\
+ if (__byte_a != __byte_b) {\
+ break;\
+ }\
+ }\
+ torture_warning(torture_ctx, "blobs differ at byte 0x%02X (%zu)", (unsigned int)__i, __i);\
+ torture_warning(torture_ctx, "expected byte[0x%02X] = 0x%02X got byte[0x%02X] = 0x%02X",\
+ (unsigned int)__i, __byte_a, (unsigned int)__i, __byte_b);\
+ __dump = talloc_strdup(torture_ctx, ""); \
+ dump_data_cb(__got.data, __got.length, true, \
+ torture_dump_data_str_cb, &__dump); \
+ torture_warning(torture_ctx, "got[0x%02X]: \n%s", \
+ (unsigned int)__got.length, __dump); \
+ TALLOC_FREE(__dump); \
+ __dump = talloc_strdup(torture_ctx, ""); \
+ dump_data_cb(__expected.data, __expected.length, true, \
+ torture_dump_data_str_cb, &__dump); \
+ torture_warning(torture_ctx, "expected[0x%02X]: \n%s", \
+ (int)__expected.length, __dump); \
+ TALLOC_FREE(__dump); \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" of len %d did not match "#expected": %s", (int)__got.length, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_file_contains_text(torture_ctx,filename,expected,cmt)\
+ do { \
+ char *__got; \
+ const char *__expected = (expected); \
+ size_t __size; \
+ __got = file_load(filename, &__size, 0, torture_ctx); \
+ if (__got == NULL) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": unable to open %s: %s\n", \
+ filename, cmt); \
+ return false; \
+ } \
+ \
+ if (strcmp_safe(__got, __expected) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": %s contained:\n%sExpected: %s%s\n", \
+ filename, __got, __expected, cmt); \
+ talloc_free(__got); \
+ return false; \
+ } \
+ talloc_free(__got); \
+ } while(0)
+
+#define torture_assert_file_contains(torture_ctx,filename,expected,cmt)\
+ do { const char *__got, *__expected = (expected); \
+ size_t __size; \
+ __got = file_load(filename, *size, 0, torture_ctx); \
+ if (strcmp_safe(__got, __expected) != 0) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": %s contained:\n%sExpected: %s%s\n", \
+ __got, __expected, cmt); \
+ talloc_free(__got); \
+ return false; \
+ } \
+ talloc_free(__got); \
+ } while(0)
+
+#define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
+ do { int __got = (got), __expected = (expected); \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
+ __got, __got, __expected, __expected, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_int_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
+ do { int __got = (got), __expected = (expected); \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
+ __got, __got, __expected, __expected, cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_int_not_equal(torture_ctx,got,not_expected,cmt)\
+ do { int __got = (got), __not_expected = (not_expected); \
+ if (__got == __not_expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %d (0x%X), expected a different number: %s", \
+ __got, __got, cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_int_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
+ do { int __got = (got), __not_expected = (not_expected); \
+ if (__got == __not_expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %d (0x%X), expected a different number: %s", \
+ __got, __got, cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_u32_equal(torture_ctx,got,expected,cmt)\
+ do { uint32_t __got = (got), __expected = (expected); \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %ju (0x%jX), expected %ju (0x%jX): %s", \
+ (uintmax_t)__got, (uintmax_t)__got, \
+ (uintmax_t)__expected, (uintmax_t)__expected, \
+ cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_u32_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
+ do { uint32_t __got = (got), __expected = (expected); \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %ju (0x%jX), expected %ju (0x%jX): %s", \
+ (uintmax_t)__got, (uintmax_t)__got, \
+ (uintmax_t)__expected, (uintmax_t)__expected, \
+ cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_u32_not_equal(torture_ctx,got,not_expected,cmt)\
+ do { uint32_t __got = (got), __not_expected = (not_expected); \
+ if (__got == __not_expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %ju (0x%jX), expected a different number: %s", \
+ (uintmax_t)__got, (uintmax_t)__got, \
+ cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_u32_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
+ do { uint32_t __got = (got), __not_expected = (not_expected); \
+ if (__got == __not_expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %ju (0x%jX), expected a different number: %s", \
+ (uintmax_t)__got, (uintmax_t)__got, \
+ cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_u64_equal(torture_ctx,got,expected,cmt)\
+ do { uint64_t __got = (got), __expected = (expected); \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %llu (0x%llX), expected %llu (0x%llX): %s", \
+ (unsigned long long)__got, (unsigned long long)__got, \
+ (unsigned long long)__expected, (unsigned long long)__expected, \
+ cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_u64_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
+ do { uint64_t __got = (got), __expected = (expected); \
+ if (__got != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %llu (0x%llX), expected %llu (0x%llX): %s", \
+ (unsigned long long)__got, (unsigned long long)__got, \
+ (unsigned long long)__expected, (unsigned long long)__expected, \
+ cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_u64_not_equal(torture_ctx,got,not_expected,cmt)\
+ do { uint64_t __got = (got), __not_expected = (not_expected); \
+ if (__got == __not_expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %llu (0x%llX), expected a different number: %s", \
+ (unsigned long long)__got, (unsigned long long)__got, \
+ cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_u64_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
+ do { uint64_t __got = (got), __not_expected = (not_expected); \
+ if (__got == __not_expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %llu (0x%llX), expected a different number: %s", \
+ (unsigned long long)__got, (unsigned long long)__got, \
+ cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_errno_equal(torture_ctx,expected,cmt)\
+ do { int __expected = (expected); \
+ if (errno != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": errno was %d (%s), expected %d: %s: %s", \
+ errno, strerror(errno), __expected, \
+ strerror(__expected), cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_errno_equal_goto(torture_ctx,expected,ret,label,cmt)\
+ do { int __expected = (expected); \
+ if (errno != __expected) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": errno was %d (%s), expected %d: %s: %s", \
+ errno, strerror(errno), __expected, \
+ strerror(__expected), cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_assert_guid_equal(torture_ctx,got,expected,cmt)\
+ do {const struct GUID __got = (got), __expected = (expected); \
+ if (!GUID_equal(&__got, &__expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %s, expected %s: %s", \
+ GUID_string(torture_ctx, &__got), GUID_string(torture_ctx, &__expected), cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_nttime_equal(torture_ctx,got,expected,cmt) \
+ do { NTTIME __got = got, __expected = expected; \
+ if (!nt_time_equal(&__got, &__expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_time_string(tctx, __got), nt_time_string(tctx, __expected), cmt); \
+ return false; \
+ }\
+ } while(0)
+
+#define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
+ do {const struct dom_sid *__got = (got), *__expected = (expected); \
+ if (!dom_sid_equal(__got, __expected)) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was %s, expected %s: %s", \
+ dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_not_null(torture_ctx,got,cmt)\
+ do {const void *__got = (got); \
+ if (__got == NULL) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was NULL, expected != NULL: %s", \
+ cmt); \
+ return false; \
+ } \
+ } while(0)
+
+#define torture_assert_not_null_goto(torture_ctx,got,ret,label,cmt)\
+ do {const void *__got = (got); \
+ if (__got == NULL) { \
+ torture_result(torture_ctx, TORTURE_FAIL, \
+ __location__": "#got" was NULL, expected != NULL: %s", \
+ cmt); \
+ ret = false; \
+ goto label; \
+ } \
+ } while(0)
+
+#define torture_skip(torture_ctx,cmt) do {\
+ torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
+ return true; \
+ } while(0)
+#define torture_skip_goto(torture_ctx,label,cmt) do {\
+ torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
+ goto label; \
+ } while(0)
+#define torture_fail(torture_ctx,cmt) do {\
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
+ return false; \
+ } while (0)
+#define torture_fail_goto(torture_ctx,label,cmt) do {\
+ torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
+ goto label; \
+ } while (0)
+
+#define torture_out stderr
+
+/* Convenience macros */
+#define torture_assert_ntstatus_ok(torture_ctx,expr,cmt) \
+ torture_assert_ntstatus_equal(torture_ctx,expr,NT_STATUS_OK,cmt)
+
+#define torture_assert_ntstatus_ok_goto(torture_ctx,expr,ret,label,cmt) \
+ torture_assert_ntstatus_equal_goto(torture_ctx,expr,NT_STATUS_OK,ret,label,cmt)
+
+#define torture_assert_werr_ok(torture_ctx,expr,cmt) \
+ torture_assert_werr_equal(torture_ctx,expr,WERR_OK,cmt)
+
+#define torture_assert_ndr_success(torture_ctx,expr,cmt) \
+ torture_assert_ndr_err_equal(torture_ctx,expr,NDR_ERR_SUCCESS,cmt)
+
+#define torture_assert_ndr_success_goto(torture_ctx,expr,ret,label,cmt) \
+ torture_assert_ndr_err_equal_goto(torture_ctx,expr,NDR_ERR_SUCCESS,ret,label,cmt)
+
+#define torture_assert_hresult_ok(torture_ctx,expr,cmt) \
+ torture_assert_hresult_equal(torture_ctx,expr,HRES_ERROR(0), cmt)
+
+/* Getting settings */
+const char *torture_setting_string(struct torture_context *test, \
+ const char *name,
+ const char *default_value);
+
+int torture_setting_int(struct torture_context *test,
+ const char *name,
+ int default_value);
+
+double torture_setting_double(struct torture_context *test,
+ const char *name,
+ double default_value);
+
+bool torture_setting_bool(struct torture_context *test,
+ const char *name,
+ bool default_value);
+
+struct torture_suite *torture_find_suite(struct torture_suite *parent,
+ const char *name);
+
+unsigned long torture_setting_ulong(struct torture_context *test,
+ const char *name,
+ unsigned long default_value);
+
+NTSTATUS torture_temp_dir(struct torture_context *tctx,
+ const char *prefix,
+ char **tempdir);
+NTSTATUS torture_deltree_outputdir(struct torture_context *tctx);
+
+struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
+ const char *name,
+ bool (*run) (struct torture_context *test, void *tcase_data));
+
+
+bool torture_suite_init_tcase(struct torture_suite *suite,
+ struct torture_tcase *tcase,
+ const char *name);
+int torture_suite_children_count(const struct torture_suite *suite);
+
+struct torture_context *torture_context_init(struct tevent_context *event_ctx, struct torture_results *results);
+
+struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops);
+
+struct torture_context *torture_context_child(struct torture_context *tctx);
+
+extern const struct torture_ui_ops torture_subunit_ui_ops;
+extern const struct torture_ui_ops torture_simple_ui_ops;
+
+#endif /* __TORTURE_UI_H__ */
diff --git a/lib/torture/wscript_build b/lib/torture/wscript_build
new file mode 100644
index 0000000..31c3862
--- /dev/null
+++ b/lib/torture/wscript_build
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+bld.SAMBA_LIBRARY('torture',
+ private_library=True,
+ source='torture.c subunit.c simple.c',
+ public_deps='samba-hostconfig samba-util samba-errors talloc tevent',
+ private_headers='torture.h'
+ )