summaryrefslogtreecommitdiff
path: root/lib/torture
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2020-07-03 15:40:31 +0200
committerStefan Metzmacher <metze@samba.org>2020-07-07 10:30:40 +0000
commit0e0d89b55cd3fa348af609fb33828a35d4affca1 (patch)
treee58bf6275ef39d708051b60c3ce84ebd8c9c56dd /lib/torture
parenta4a6c03bf8448923525a4997e4a7a3bd1f29c70f (diff)
downloadsamba-0e0d89b55cd3fa348af609fb33828a35d4affca1.tar.gz
lib/torture: fix subunit names of nested suites
E.g. passing 'smb2.multichannel.generic' to smbtorture results in - interface_info - num_channels While passing 'smb2.multichannel' to smbtorture results in: - generic.interface_info - genetic.num_channels - oplocks.test1 ... - leases.test1 ... Before we got this: - interface_info - num_channels - test1 ... - test1 That made it impossible to add knownfail entries for leases.test1 vs. oplocks.test1 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'lib/torture')
-rw-r--r--lib/torture/torture.c72
-rw-r--r--lib/torture/torture.h9
2 files changed, 79 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;
}
diff --git a/lib/torture/torture.h b/lib/torture/torture.h
index 3f1f19a29b0..c95103072d2 100644
--- a/lib/torture/torture.h
+++ b/lib/torture/torture.h
@@ -83,12 +83,19 @@ void torture_ui_report_time(struct torture_context *context);
* specified below.
*/
+struct torture_subunit_prefix {
+ const struct torture_subunit_prefix *parent;
+ char subunit_prefix[256];
+};
+
struct torture_context
{
struct torture_results *results;
struct torture_test *active_test;
struct torture_tcase *active_tcase;
+ struct torture_subunit_prefix _initial_prefix;
+ const struct torture_subunit_prefix *active_prefix;
enum torture_result last_result;
char *last_reason;
@@ -225,6 +232,8 @@ bool torture_suite_add_suite(struct torture_suite *suite,
char *torture_subunit_test_name(struct torture_context *ctx,
struct torture_tcase *tcase,
struct torture_test *test);
+void torture_subunit_prefix_reset(struct torture_context *ctx,
+ const char *name);
/* Run the specified testsuite recursively */
bool torture_run_suite(struct torture_context *context,