[LTP] [PATCH v4 9/9] [RFC] metaparse: Check {min, max}_kver validity

Petr Vorel <[email protected]>
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Check .max_kver and .min_kver validity. Exit generation with error when:
* .max_kver or .min_kver is invalid
* .min_kver > .max_kver

Suggested-by: Li Wang <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
---
New in v4.

 lib/tst_test.c       |  2 ++
 metadata/Makefile    |  6 ++++--
 metadata/metaparse.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 0d3714c709..11d233dcbd 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1496,6 +1496,8 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->max_kver)
 		check_max_kver(tst_test->max_kver, 1);
 
+	// TODO: Add runtime check tst_test->max_kver >= tst_test->min_kver.
+
 	if (tst_test->skip_in_lockdown && tst_lockdown_enabled() > 0)
 		tst_brk(TCONF, "Kernel is locked down, skipping test");
 
diff --git a/metadata/Makefile b/metadata/Makefile
index af194bcc94..9ee2441669 100644
--- a/metadata/Makefile
+++ b/metadata/Makefile
@@ -3,13 +3,15 @@
 
 top_srcdir		?= ..
 
-include $(top_srcdir)/include/mk/env_pre.mk
-include $(top_srcdir)/include/mk/functions.mk
+include $(top_srcdir)/include/mk/testcases.mk
 
 MAKE_TARGETS		:= ltp.json
 HOST_MAKE_TARGETS	:= metaparse metaparse-sh
 INSTALL_DIR		= metadata
 
+metaparse: HOST_CFLAGS		+= -I$(abs_srcdir)/../include -L$(abs_builddir)/../lib
+metaparse: HOST_LDLIBS		+= -lltp
+
 .PHONY: ltp.json
 
 ltp.json: metaparse metaparse-sh
diff --git a/metadata/metaparse.c b/metadata/metaparse.c
index cb141c3831..07a452a5a1 100644
--- a/metadata/metaparse.c
+++ b/metadata/metaparse.c
@@ -6,6 +6,7 @@
 
 #define _GNU_SOURCE
 
+#include <assert.h>
 #include <search.h>
 #include <stdio.h>
 #include <string.h>
@@ -15,6 +16,7 @@
 #include <errno.h>
 
 #include "data_storage.h"
+#include "tst_kvercmp.h"
 
 #define INCLUDE_PATH_MAX 5
 #define GROUPS_TAG "@groups"
@@ -1372,6 +1374,37 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	/* Check max_kver >= min_kver */
+	struct data_node *max_kver = data_node_hash_get(res, "max_kver");
+	struct data_node *min_kver = data_node_hash_get(res, "min_kver");
+	int a1, a2, a3, b1, b2, b3;
+
+	if (min_kver) {
+		assert(min_kver->type == DATA_STRING);
+		if (tst_parse_kver(min_kver->string.val, &b1, &b2, &b3)) {
+			fprintf(stderr, "%s: wrong min_kver: '%s'\n",
+				argv[optind], min_kver->string.val);
+			return 1;
+		}
+	}
+
+	if (max_kver) {
+		assert(max_kver->type == DATA_STRING);
+		if (tst_parse_kver(max_kver->string.val, &a1, &a2, &a3)) {
+			fprintf(stderr, "%s: wrong max_kver: '%s'\n",
+					argv[optind], max_kver->string.val);
+			return 1;
+		}
+	}
+
+	if (min_kver && max_kver) {
+		if (tst_kver_cmp(a1, a2, a3, b1, b2, b3) < 0) {
+			fprintf(stderr, "%s: min_kver (%s) > max_kver (%s)\n",
+					argv[optind], min_kver->string.val, max_kver->string.val);
+			return 1;
+		}
+	}
+
 	/* Normalize types */
 	check_normalize_types(res, "", tst_test_typemap);
 
-- 
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.