[SCM] Samba Shared Repository - branch master updated -
0e553a06ced50bcb947c13a711f59db9e7203eea
Jelmer Vernooij
jelmer at samba.org
Sun Nov 16 00:37:49 GMT 2008
The branch, master has been updated
via 0e553a06ced50bcb947c13a711f59db9e7203eea (commit)
via 12f64285ee09954cac447cf9c9fa241fd4b1e59e (commit)
via 8beecd42f2789635891121be8e185e9acef0bcb5 (commit)
via badfac44128d64b9e1ba80603ac3835ef50f01f9 (commit)
from caf0c17e247b7c66051abc9ed239506a4be6aecc (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 0e553a06ced50bcb947c13a711f59db9e7203eea
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Nov 16 01:36:17 2008 +0100
Remove unused init function in subunit code.
commit 12f64285ee09954cac447cf9c9fa241fd4b1e59e
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Nov 16 01:35:46 2008 +0100
Fix merged build.
commit 8beecd42f2789635891121be8e185e9acef0bcb5
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Nov 16 00:58:08 2008 +0100
Move torture directory to top-level.
commit badfac44128d64b9e1ba80603ac3835ef50f01f9
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Nov 16 00:55:35 2008 +0100
Move libtorture to top-level.
-----------------------------------------------------------------------
Summary of changes:
lib/README | 1 +
lib/torture/config.mk | 14 +
lib/torture/subunit.c | 90 ++++++
lib/torture/torture.c | 627 +++++++++++++++++++++++++++++++++++++
lib/torture/torture.h | 423 +++++++++++++++++++++++++
lib/torture/torture.pc.in | 12 +
source3/samba4.m4 | 2 +-
source3/samba4.mk | 2 +-
source4/Makefile | 4 +-
source4/configure.ac | 2 +-
source4/lib/torture/config.mk | 14 -
source4/lib/torture/subunit.c | 96 ------
source4/lib/torture/torture.c | 627 -------------------------------------
source4/lib/torture/torture.h | 425 -------------------------
source4/lib/torture/torture.pc.in | 12 -
source4/main.mk | 2 +-
source4/torture/rpc/ntsvcs.c | 2 +-
source4/torture/rpc/rpc.h | 3 +-
source4/torture/smbtorture.h | 2 +-
source4/torture/util.h | 2 +-
20 files changed, 1177 insertions(+), 1185 deletions(-)
create mode 100644 lib/torture/config.mk
create mode 100644 lib/torture/subunit.c
create mode 100644 lib/torture/torture.c
create mode 100644 lib/torture/torture.h
create mode 100644 lib/torture/torture.pc.in
delete mode 100644 source4/lib/torture/config.mk
delete mode 100644 source4/lib/torture/subunit.c
delete mode 100644 source4/lib/torture/torture.c
delete mode 100644 source4/lib/torture/torture.h
delete mode 100644 source4/lib/torture/torture.pc.in
Changeset truncated at 500 lines:
diff --git a/lib/README b/lib/README
index b994447..acae62c 100644
--- a/lib/README
+++ b/lib/README
@@ -8,3 +8,4 @@ socket_wrapper - Wrapper library allowing TCP/IP traffic to be redirected
over Unix domain sockets.
talloc - Hierarchical pool based memory allocator
tdb - Simple but fast key/value database library, supporting multiple writers
+torture - Simple unit testing helper library
diff --git a/lib/torture/config.mk b/lib/torture/config.mk
new file mode 100644
index 0000000..8a7f2a3
--- /dev/null
+++ b/lib/torture/config.mk
@@ -0,0 +1,14 @@
+# TORTURE subsystem
+[LIBRARY::torture]
+PUBLIC_DEPENDENCIES = \
+ LIBSAMBA-HOSTCONFIG \
+ LIBSAMBA-UTIL \
+ LIBTALLOC
+
+torture_VERSION = 0.0.1
+torture_SOVERSION = 0
+
+PC_FILES += $(libtorturesrcdir)/torture.pc
+torture_OBJ_FILES = $(addprefix $(libtorturesrcdir)/, torture.o subunit.o)
+
+PUBLIC_HEADERS += $(libtorturesrcdir)/torture.h
diff --git a/lib/torture/subunit.c b/lib/torture/subunit.c
new file mode 100644
index 0000000..832f11f
--- /dev/null
+++ b/lib/torture/subunit.c
@@ -0,0 +1,90 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer at 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_suite_start(struct torture_context *ctx,
+ struct torture_suite *suite)
+{
+}
+
+static void subunit_print_testname(struct torture_context *ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ if (!strcmp(tcase->name, test->name)) {
+ printf("%s", test->name);
+ } else {
+ printf("%s.%s", tcase->name, test->name);
+ }
+}
+
+static void subunit_test_start(struct torture_context *ctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ printf("test: ");
+ subunit_print_testname(ctx, tcase, test);
+ printf("\n");
+}
+
+static void subunit_test_result(struct torture_context *context,
+ enum torture_result res, const char *reason)
+{
+ switch (res) {
+ case TORTURE_OK:
+ printf("success: ");
+ break;
+ case TORTURE_FAIL:
+ printf("failure: ");
+ break;
+ case TORTURE_ERROR:
+ printf("error: ");
+ break;
+ case TORTURE_SKIP:
+ printf("skip: ");
+ break;
+ }
+ subunit_print_testname(context, context->active_tcase, context->active_test);
+
+ if (reason)
+ printf(" [\n%s\n]", reason);
+ printf("\n");
+}
+
+static void subunit_comment(struct torture_context *test,
+ const char *comment)
+{
+ fprintf(stderr, "%s", comment);
+}
+
+static void subunit_warning(struct torture_context *test,
+ const char *comment)
+{
+ fprintf(stderr, "WARNING!: %s\n", comment);
+}
+
+const struct torture_ui_ops torture_subunit_ui_ops = {
+ .comment = subunit_comment,
+ .warning = subunit_warning,
+ .test_start = subunit_test_start,
+ .test_result = subunit_test_result,
+ .suite_start = subunit_suite_start
+};
diff --git a/lib/torture/torture.c b/lib/torture/torture.c
new file mode 100644
index 0000000..6b2a5b1
--- /dev/null
+++ b/lib/torture/torture.c
@@ -0,0 +1,627 @@
+/*
+ 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 "includes.h"
+#include "../torture/torture.h"
+#include "../lib/util/dlinklist.h"
+#include "param/param.h"
+#include "system/filesys.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 event_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);
+
+ 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->level = parent->level+1;
+ 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.
+*/
+_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;
+}
+
+/**
+ * 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);
+
+ 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);
+
+ 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, struct torture_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, struct torture_tcase *);
+
+ 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;
+}
+
+/**
+ * Run a torture test suite.
+ */
+bool torture_run_suite(struct torture_context *context,
+ struct torture_suite *suite)
+{
+ bool ret = true;
+ struct torture_tcase *tcase;
+ struct torture_suite *tsuite;
+ char *old_testname;
+
+ context->level++;
+ if (context->results->ui_ops->suite_start)
+ context->results->ui_ops->suite_start(context, suite);
+
+ old_testname = context->active_testname;
+ if (old_testname != NULL)
+ context->active_testname = talloc_asprintf(context, "%s-%s",
+ old_testname, suite->name);
+ else
+ context->active_testname = talloc_strdup(context, suite->name);
+
+ for (tcase = suite->testcases; tcase; tcase = tcase->next) {
+ ret &= torture_run_tcase(context, tcase);
+ }
+
+ for (tsuite = suite->children; tsuite; tsuite = tsuite->next) {
+ ret &= torture_run_suite(context, tsuite);
+ }
+
+ talloc_free(context->active_testname);
+ context->active_testname = old_testname;
+
+ if (context->results->ui_ops->suite_finish)
+ context->results->ui_ops->suite_finish(context, suite);
+
+ context->level--;
+
+ 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 internal_torture_run_test(struct torture_context *context,
+ struct torture_tcase *tcase,
+ struct torture_test *test,
+ bool already_setup)
+{
+ bool success;
+ char *old_testname;
+
+ 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_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");
+ 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);
+
+ if (tcase == NULL || strcmp(test->name, tcase->name) != 0) {
+ talloc_free(context->active_testname);
+ context->active_testname = old_testname;
+ }
+ context->active_test = NULL;
+ context->active_tcase = NULL;
+
+ return success;
--
Samba Shared Repository
More information about the samba-cvs
mailing list