Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] metadata: automatically detect groups via tags
@ 2026-06-22 13:44 Andrea Cervesato
  2026-06-22 14:02 ` Cyril Hrubis
  2026-06-22 14:11 ` Andrea Cervesato via ltp
  0 siblings, 2 replies; 3+ messages in thread
From: Andrea Cervesato @ 2026-06-22 13:44 UTC (permalink / raw)
  To: Linux Test Project

From: Andrea Cervesato <andrea.cervesato@suse.com>

Automatically assign a 'cve' group to test metadata when we are tagging
it with a CVE number and assign a 'regression' group to test metadata
when we are tagging it with a linux git commit.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v2:
- add linux-git to tags
- Link to v1: https://lore.kernel.org/r/20260622-metadata_cve-v1-1-c8d43e0db19e@suse.com
---
 metadata/metaparse.c             | 46 +++++++++++++++++++++++++++++++++++-----
 metadata/tests/cve.c             | 12 +++++++++++
 metadata/tests/cve.c.json        | 15 +++++++++++++
 metadata/tests/regression.c      | 12 +++++++++++
 metadata/tests/regression.c.json | 15 +++++++++++++
 5 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/metadata/metaparse.c b/metadata/metaparse.c
index a0f94511db36e42e6174774dfa8340cb4dce113a..cb141c383142142491f802e51afd29bc014f0e6e 100644
--- a/metadata/metaparse.c
+++ b/metadata/metaparse.c
@@ -52,12 +52,14 @@ static char *eat_asterisk_space(char *c)
 }
 
 /*
- * Add a group to the groups array, skipping 'kernel' as it's too generic.
- * Returns 0 if no group was added, 1 otherwise.
+ * Add a group to the groups array, skipping path components that are too
+ * generic ('kernel') or assigned from a more reliable source ('cve', which
+ * is derived from the CVE tag instead). Returns 0 if no group was added,
+ * 1 otherwise.
  */
 static int add_group(struct data_node *groups, const char *name)
 {
-	if (name && strcmp(name, "kernel")) {
+	if (name && strcmp(name, "kernel") && strcmp(name, "cve")) {
 		data_node_array_add(groups, data_node_string(name));
 		return 1;
 	}
@@ -971,11 +973,11 @@ static void load_internal_macros(void)
  * Add groups derived from the source file path.
  *
  * Groups are the two nearest parent directories (immediate parent
- * first), skipping 'kernel' as it's too generic:
+ * first), skipping 'kernel' (too generic) and 'cve' (assigned from the
+ * CVE tag instead, see add_tag_groups()):
  *
  *   testcases/kernel/syscalls/clone/clone01.c  -> clone, syscalls
  *   testcases/kernel/kvm/kvm_pagefault01.c     -> kvm
- *   testcases/cve/cve-2017-16939.c             -> cve
  */
 static void add_path_groups(struct data_node *groups, const char *fname)
 {
@@ -1010,6 +1012,38 @@ static void add_path_groups(struct data_node *groups, const char *fname)
 	free(buf);
 }
 
+/*
+ * Add group to specific test tags.
+ */
+static void add_tag_groups(struct data_node *groups, struct data_node *res)
+{
+	struct data_node *tags = data_node_hash_get(res, "tags");
+	int has_cve = 0, has_regression = 0;
+
+	if (!tags || tags->type != DATA_ARRAY)
+		return;
+
+	for (unsigned int i = 0; i < data_node_array_len(tags); i++) {
+		struct data_node *tag = tags->array.array[i];
+		struct data_node *name;
+
+		if (tag->type != DATA_ARRAY || !data_node_array_len(tag))
+			continue;
+
+		name = tag->array.array[0];
+		if (name->type != DATA_STRING)
+			continue;
+
+		if (!has_cve && !strcmp(name->string.val, "CVE")) {
+			data_node_array_add(groups, data_node_string("cve"));
+			has_cve = 1;
+		} else if (!has_regression && !strcmp(name->string.val, "linux-git")) {
+			data_node_array_add(groups, data_node_string("regression"));
+			has_regression = 1;
+		}
+	}
+}
+
 static struct data_node *parse_file(const char *fname)
 {
 	int state = 0, found = 0;
@@ -1064,6 +1098,8 @@ static struct data_node *parse_file(const char *fname)
 		data_node_free(doc);
 	}
 
+	add_tag_groups(groups, res);
+
 	/*
 	 * Always emit groups, even when empty: tests outside testcases/
 	 * and files whose only parent dir is 'kernel' produce no groups.
diff --git a/metadata/tests/cve.c b/metadata/tests/cve.c
new file mode 100644
index 0000000000000000000000000000000000000000..c2b0e551f111ae87f3c6dcb50ef25c66967443f4
--- /dev/null
+++ b/metadata/tests/cve.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*\
+ * Test for cve group derived from the CVE tag.
+ */
+
+static struct tst_test test = {
+	.tags = (const struct tst_tag[]) {
+		{"CVE", "2017-16939"},
+		{}
+	}
+};
diff --git a/metadata/tests/cve.c.json b/metadata/tests/cve.c.json
new file mode 100644
index 0000000000000000000000000000000000000000..543d9e58a3e78d296cc4247659d1b26f2a103245
--- /dev/null
+++ b/metadata/tests/cve.c.json
@@ -0,0 +1,15 @@
+  "cve": {
+   "tags": [
+    [
+     "CVE",
+     "2017-16939"
+    ]
+   ],
+   "doc": [
+    "Test for cve group derived from the CVE tag."
+   ],
+   "groups": [
+    "cve"
+   ],
+   "fname": "cve.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/regression.c b/metadata/tests/regression.c
new file mode 100644
index 0000000000000000000000000000000000000000..e02683dedce13b7579ec874c64476f09f34707de
--- /dev/null
+++ b/metadata/tests/regression.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*\
+ * Test for regression group derived from the linux-git tag.
+ */
+
+static struct tst_test test = {
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "1137b5e2529a"},
+		{}
+	}
+};
diff --git a/metadata/tests/regression.c.json b/metadata/tests/regression.c.json
new file mode 100644
index 0000000000000000000000000000000000000000..21f818888301cd982ca9e52861f7ea0fc2e570be
--- /dev/null
+++ b/metadata/tests/regression.c.json
@@ -0,0 +1,15 @@
+  "regression": {
+   "tags": [
+    [
+     "linux-git",
+     "1137b5e2529a"
+    ]
+   ],
+   "doc": [
+    "Test for regression group derived from the linux-git tag."
+   ],
+   "groups": [
+    "regression"
+   ],
+   "fname": "regression.c"
+  }
\ No newline at end of file

---
base-commit: b2184c0f2debb976414b294b8527298bdac0a877
change-id: 20260622-metadata_cve-25cf42b4f38d

Best regards,
-- 
Andrea Cervesato <andrea.cervesato@suse.com>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-22 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 13:44 [LTP] [PATCH v2] metadata: automatically detect groups via tags Andrea Cervesato
2026-06-22 14:02 ` Cyril Hrubis
2026-06-22 14:11 ` Andrea Cervesato via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox