summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-11-01 00:24:55 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-11-01 00:24:55 +0100
commit59206674521065e041a6020f9ba793fac47b1d7d (patch)
tree7f693ab5a6d19f3b5f853e12e1f8beb77e2aa6af
parentc7cedd3a67b08be933a3101162bd5745284c8bf8 (diff)
downloadsamba-59206674521065e041a6020f9ba793fac47b1d7d.tar.gz
samba-59206674521065e041a6020f9ba793fac47b1d7d.tar.bz2
samba-59206674521065e041a6020f9ba793fac47b1d7d.zip
Split out torture results from torture context.
-rw-r--r--source4/lib/torture/subunit.c2
-rw-r--r--source4/lib/torture/torture.c58
-rw-r--r--source4/lib/torture/torture.h29
-rw-r--r--source4/torture/smbtorture.c9
4 files changed, 59 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 15e5198fc9..e465529f6b 100644
--- a/source4/lib/torture/torture.c
+++ b/source4/lib/torture/torture.c
@@ -24,11 +24,24 @@
#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);
@@ -36,12 +49,8 @@ struct torture_context *torture_context_init(struct event_context *event_ctx,
if (torture == NULL)
return NULL;
- torture->ui_ops = ui_ops;
- torture->returncode = true;
torture->ev = event_ctx;
-
- if (ui_ops->init)
- ui_ops->init(torture);
+ torture->results = talloc_reference(torture, results);
return torture;
}
@@ -56,12 +65,11 @@ struct torture_context *torture_context_child(struct torture_context *parent)
if (subtorture == NULL)
return NULL;
- subtorture->ui_ops = parent->ui_ops;
subtorture->level = parent->level+1;
subtorture->ev = talloc_reference(subtorture, parent->ev);
subtorture->lp_ctx = talloc_reference(subtorture, parent->lp_ctx);
- subtorture->ui_data = parent->ui_data;
subtorture->outputdir = talloc_reference(subtorture, parent->outputdir);
+ subtorture->results = talloc_reference(subtorture, parent->results);
return subtorture;
}
@@ -94,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);
}
@@ -113,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);
}
@@ -248,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)
@@ -269,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--;
@@ -281,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,
@@ -371,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)) {
@@ -402,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 0a84cef84a..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,21 +74,15 @@ 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;
- /** Whether tests should avoid writing output to stdout */
- bool quiet;
-
enum torture_result last_result;
char *last_reason;
- bool returncode;
-
/** Directory used for temporary test data */
const char *outputdir;
@@ -101,6 +96,19 @@ struct torture_context
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
*/
@@ -406,8 +414,9 @@ 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);
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);