diff options
Diffstat (limited to 'lib/torture/torture.c')
-rw-r--r-- | lib/torture/torture.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/lib/torture/torture.c b/lib/torture/torture.c index d808b788481..b8fb28f669f 100644 --- a/lib/torture/torture.c +++ b/lib/torture/torture.c @@ -54,6 +54,11 @@ struct torture_context *torture_context_init(struct tevent_context *event_ctx, 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; } @@ -319,10 +324,68 @@ char *torture_subunit_test_name(struct torture_context *ctx, struct torture_test *test) { if (!strcmp(tcase->name, test->name)) { - return talloc_strdup(ctx, test->name); + return talloc_asprintf(ctx, "%s%s", + ctx->active_prefix->subunit_prefix, + test->name); } else { - return talloc_asprintf(ctx, "%s.%s", tcase->name, test->name); + 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) @@ -354,10 +417,13 @@ bool torture_run_suite(struct torture_context *context, 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); @@ -378,6 +444,8 @@ bool torture_run_suite_restricted(struct torture_context *context, if (context->results->ui_ops->suite_finish) context->results->ui_ops->suite_finish(context, suite); + torture_subunit_prefix_pop(context); + return ret; } |