summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/torture/subunit.c2
-rw-r--r--source4/lib/torture/torture.c78
-rw-r--r--source4/lib/torture/torture.h51
-rw-r--r--source4/torture/smbtorture.c9
4 files changed, 101 insertions, 39 deletions
diff --git a/source4/lib/torture/subunit.c b/source4/lib/torture/subunit.c
index 40d9b9731d..d5ee344596 100644
--- a/source4/lib/torture/subunit.c
+++ b/source4/lib/torture/subunit.c
@@ -20,7 +20,7 @@
#include "includes.h"
#include "lib/torture/torture.h"
-static void subunit_init(struct torture_context *ctx)
+static void subunit_init(struct torture_results *results)
{
/* FIXME: register segv and bus handler */
}
diff --git a/source4/lib/torture/torture.c b/source4/lib/torture/torture.c
index 54ddc79be7..e465529f6b 100644
--- a/source4/lib/torture/torture.c
+++ b/source4/lib/torture/torture.c
@@ -24,25 +24,57 @@
#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,
- const struct torture_ui_ops *ui_ops)
+ struct torture_results *results)
{
struct torture_context *torture = talloc_zero(event_ctx,
struct torture_context);
- torture->ui_ops = ui_ops;
- torture->returncode = true;
- torture->ev = event_ctx;
- if (ui_ops->init)
- ui_ops->init(torture);
+ 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,
@@ -70,13 +102,13 @@ void torture_comment(struct torture_context *context, const char *comment, ...)
va_list ap;
char *tmp;
- if (!context->ui_ops->comment)
+ if (!context->results->ui_ops->comment)
return;
va_start(ap, comment);
tmp = talloc_vasprintf(context, comment, ap);
- context->ui_ops->comment(context, tmp);
+ context->results->ui_ops->comment(context, tmp);
talloc_free(tmp);
}
@@ -89,13 +121,13 @@ void torture_warning(struct torture_context *context, const char *comment, ...)
va_list ap;
char *tmp;
- if (!context->ui_ops->warning)
+ if (!context->results->ui_ops->warning)
return;
va_start(ap, comment);
tmp = talloc_vasprintf(context, comment, ap);
- context->ui_ops->warning(context, tmp);
+ context->results->ui_ops->warning(context, tmp);
talloc_free(tmp);
}
@@ -224,8 +256,8 @@ bool torture_run_suite(struct torture_context *context,
char *old_testname;
context->level++;
- if (context->ui_ops->suite_start)
- context->ui_ops->suite_start(context, suite);
+ if (context->results->ui_ops->suite_start)
+ context->results->ui_ops->suite_start(context, suite);
old_testname = context->active_testname;
if (old_testname != NULL)
@@ -245,8 +277,8 @@ bool torture_run_suite(struct torture_context *context,
talloc_free(context->active_testname);
context->active_testname = old_testname;
- if (context->ui_ops->suite_finish)
- context->ui_ops->suite_finish(context, suite);
+ if (context->results->ui_ops->suite_finish)
+ context->results->ui_ops->suite_finish(context, suite);
context->level--;
@@ -257,19 +289,19 @@ void torture_ui_test_start(struct torture_context *context,
struct torture_tcase *tcase,
struct torture_test *test)
{
- if (context->ui_ops->test_start)
- context->ui_ops->test_start(context, tcase, 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->ui_ops->test_result)
- context->ui_ops->test_result(context, result, 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->returncode = false;
+ context->results->returncode = false;
}
static bool internal_torture_run_test(struct torture_context *context,
@@ -347,8 +379,8 @@ bool torture_run_tcase(struct torture_context *context,
context->level++;
context->active_tcase = tcase;
- if (context->ui_ops->tcase_start)
- context->ui_ops->tcase_start(context, 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)) {
@@ -378,8 +410,8 @@ bool torture_run_tcase(struct torture_context *context,
done:
context->active_tcase = NULL;
- if (context->ui_ops->tcase_finish)
- context->ui_ops->tcase_finish(context, tcase);
+ if (context->results->ui_ops->tcase_finish)
+ context->results->ui_ops->tcase_finish(context, tcase);
context->level--;
diff --git a/source4/lib/torture/torture.h b/source4/lib/torture/torture.h
index ea5cd70961..f06ffe012b 100644
--- a/source4/lib/torture/torture.h
+++ b/source4/lib/torture/torture.h
@@ -25,6 +25,7 @@ struct torture_test;
struct torture_context;
struct torture_suite;
struct torture_tcase;
+struct torture_results;
enum torture_result {
TORTURE_OK=0,
@@ -39,7 +40,7 @@ enum torture_result {
*/
struct torture_ui_ops
{
- void (*init) (struct torture_context *);
+ 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 *);
@@ -73,44 +74,67 @@ void torture_ui_test_result(struct torture_context *context,
struct torture_context
{
- const struct torture_ui_ops *ui_ops;
- void *ui_data;
+ struct torture_results *results;
char *active_testname;
struct torture_test *active_test;
struct torture_tcase *active_tcase;
- bool quiet; /* Whether tests should avoid writing output to stdout */
-
enum torture_result last_result;
char *last_reason;
- bool returncode;
-
+ /** Directory used for temporary test data */
const char *outputdir;
+
+ /** Indentation level */
int level;
+
+ /** Event context */
struct event_context *ev;
+ /** Loadparm context (will go away in favor of torture_setting_ at some point) */
struct loadparm_context *lp_ctx;
};
+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 */
+
+ /** 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. */
+ /** Pointer to the actual test function. This is run by the
+ * run() function above. */
void *fn;
+
+ /** Use data for this test */
const void *data;
};
@@ -390,8 +414,11 @@ bool torture_suite_init_tcase(struct torture_suite *suite,
struct torture_tcase *tcase,
const char *name);
-struct torture_context *torture_context_init(struct event_context *event_ctx,
- const struct torture_ui_ops *ui_ops);
+struct torture_context *torture_context_init(struct event_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;
diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c
index 19f1d1ae35..bfe6d0503d 100644
--- a/source4/torture/smbtorture.c
+++ b/source4/torture/smbtorture.c
@@ -370,7 +370,7 @@ static void quiet_suite_start(struct torture_context *ctx,
struct torture_suite *suite)
{
int i;
- ctx->quiet = true;
+ ctx->results->quiet = true;
for (i = 1; i < ctx->level; i++) putchar('\t');
printf("%s: ", suite->name);
fflush(stdout);
@@ -456,6 +456,7 @@ int main(int argc,char *argv[])
int max_runtime=0;
int argc_new;
struct torture_context *torture;
+ struct torture_results *results;
const struct torture_ui_ops *ui_ops;
char **argv_new;
poptContext pc;
@@ -627,7 +628,9 @@ int main(int argc,char *argv[])
exit(1);
}
- torture = torture_context_init(s4_event_context_init(NULL), ui_ops);
+ results = torture_results_init(talloc_autofree_context(), ui_ops);
+
+ torture = torture_context_init(s4_event_context_init(NULL), results);
if (basedir != NULL) {
if (basedir[0] != '/') {
fprintf(stderr, "Please specify an absolute path to --basedir\n");
@@ -657,7 +660,7 @@ int main(int argc,char *argv[])
}
}
- if (torture->returncode && correct) {
+ if (torture->results->returncode && correct) {
return(0);
} else {
return(1);