Skip to content

Commit 534222c

Browse files
committed
metadata: automatically detect groups via tags
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. Reviewed-by: Cyril Hrubis <chrubis@suse.cz> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
1 parent b2184c0 commit 534222c

5 files changed

Lines changed: 95 additions & 5 deletions

File tree

metadata/metaparse.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ static char *eat_asterisk_space(char *c)
5252
}
5353

5454
/*
55-
* Add a group to the groups array, skipping 'kernel' as it's too generic.
56-
* Returns 0 if no group was added, 1 otherwise.
55+
* Add a group to the groups array, skipping path components that are too
56+
* generic ('kernel') or assigned from a more reliable source ('cve', which
57+
* is derived from the CVE tag instead). Returns 0 if no group was added,
58+
* 1 otherwise.
5759
*/
5860
static int add_group(struct data_node *groups, const char *name)
5961
{
60-
if (name && strcmp(name, "kernel")) {
62+
if (name && strcmp(name, "kernel") && strcmp(name, "cve")) {
6163
data_node_array_add(groups, data_node_string(name));
6264
return 1;
6365
}
@@ -971,11 +973,11 @@ static void load_internal_macros(void)
971973
* Add groups derived from the source file path.
972974
*
973975
* Groups are the two nearest parent directories (immediate parent
974-
* first), skipping 'kernel' as it's too generic:
976+
* first), skipping 'kernel' (too generic) and 'cve' (assigned from the
977+
* CVE tag instead, see add_tag_groups()):
975978
*
976979
* testcases/kernel/syscalls/clone/clone01.c -> clone, syscalls
977980
* testcases/kernel/kvm/kvm_pagefault01.c -> kvm
978-
* testcases/cve/cve-2017-16939.c -> cve
979981
*/
980982
static void add_path_groups(struct data_node *groups, const char *fname)
981983
{
@@ -1010,6 +1012,38 @@ static void add_path_groups(struct data_node *groups, const char *fname)
10101012
free(buf);
10111013
}
10121014

1015+
/*
1016+
* Add group to specific test tags.
1017+
*/
1018+
static void add_tag_groups(struct data_node *groups, struct data_node *res)
1019+
{
1020+
struct data_node *tags = data_node_hash_get(res, "tags");
1021+
int has_cve = 0, has_regression = 0;
1022+
1023+
if (!tags || tags->type != DATA_ARRAY)
1024+
return;
1025+
1026+
for (unsigned int i = 0; i < data_node_array_len(tags); i++) {
1027+
struct data_node *tag = tags->array.array[i];
1028+
struct data_node *name;
1029+
1030+
if (tag->type != DATA_ARRAY || !data_node_array_len(tag))
1031+
continue;
1032+
1033+
name = tag->array.array[0];
1034+
if (name->type != DATA_STRING)
1035+
continue;
1036+
1037+
if (!has_cve && !strcmp(name->string.val, "CVE")) {
1038+
data_node_array_add(groups, data_node_string("cve"));
1039+
has_cve = 1;
1040+
} else if (!has_regression && !strcmp(name->string.val, "linux-git")) {
1041+
data_node_array_add(groups, data_node_string("regression"));
1042+
has_regression = 1;
1043+
}
1044+
}
1045+
}
1046+
10131047
static struct data_node *parse_file(const char *fname)
10141048
{
10151049
int state = 0, found = 0;
@@ -1064,6 +1098,8 @@ static struct data_node *parse_file(const char *fname)
10641098
data_node_free(doc);
10651099
}
10661100

1101+
add_tag_groups(groups, res);
1102+
10671103
/*
10681104
* Always emit groups, even when empty: tests outside testcases/
10691105
* and files whose only parent dir is 'kernel' produce no groups.

metadata/tests/cve.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
/*\
4+
* Test for cve group derived from the CVE tag.
5+
*/
6+
7+
static struct tst_test test = {
8+
.tags = (const struct tst_tag[]) {
9+
{"CVE", "2017-16939"},
10+
{}
11+
}
12+
};

metadata/tests/cve.c.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"cve": {
2+
"tags": [
3+
[
4+
"CVE",
5+
"2017-16939"
6+
]
7+
],
8+
"doc": [
9+
"Test for cve group derived from the CVE tag."
10+
],
11+
"groups": [
12+
"cve"
13+
],
14+
"fname": "cve.c"
15+
}

metadata/tests/regression.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
/*\
4+
* Test for regression group derived from the linux-git tag.
5+
*/
6+
7+
static struct tst_test test = {
8+
.tags = (const struct tst_tag[]) {
9+
{"linux-git", "1137b5e2529a"},
10+
{}
11+
}
12+
};

metadata/tests/regression.c.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"regression": {
2+
"tags": [
3+
[
4+
"linux-git",
5+
"1137b5e2529a"
6+
]
7+
],
8+
"doc": [
9+
"Test for regression group derived from the linux-git tag."
10+
],
11+
"groups": [
12+
"regression"
13+
],
14+
"fname": "regression.c"
15+
}

0 commit comments

Comments
 (0)