Add comments in torture code, allow creating subcontexts.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 31 Oct 2008 15:37:02 +0000 (16:37 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 31 Oct 2008 15:37:02 +0000 (16:37 +0100)
source4/lib/torture/torture.c
source4/lib/torture/torture.h

index 54ddc79be7f0de9c0f1fc8183e8dd8615d4790ee..15e5198fc9e7664141f63ad06e582aeae147406d 100644 (file)
@@ -32,6 +32,10 @@ struct torture_context *torture_context_init(struct event_context *event_ctx,
 {
        struct torture_context *torture = talloc_zero(event_ctx, 
                                                      struct torture_context);
+
+       if (torture == NULL)
+               return NULL;
+
        torture->ui_ops = ui_ops;
        torture->returncode = true;
        torture->ev = event_ctx;
@@ -42,6 +46,26 @@ struct torture_context *torture_context_init(struct event_context *event_ctx,
        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->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);
+
+       return subtorture;
+}      
+
 /**
  create a temporary directory.
 */
index ea5cd709617c1d4f3611f2683d864cee0afee120..0a84cef84a2d33998709fccc1c28eec24ac08551 100644 (file)
@@ -80,17 +80,24 @@ struct torture_context
        struct torture_test *active_test;
        struct torture_tcase *active_tcase;
 
-       bool quiet; /* Whether tests should avoid writing output to stdout */
+       /** 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;
+       
+       /** 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;
 };
 
@@ -98,19 +105,28 @@ struct torture_context
  * 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;
 };
 
@@ -393,6 +409,8 @@ bool torture_suite_init_tcase(struct torture_suite *suite,
 struct torture_context *torture_context_init(struct event_context *event_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;
 
 #endif /* __TORTURE_UI_H__ */