[LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables

Yang Xu xuyang2018.jy@fujitsu.com
Thu Jan 6 10:25:19 CET 2022


This environment variables is designed to add kernel config check functionality
switch. So we can disable kconfig check completely and it is useful especially
for the  embedded platforms that they don't have kernel config.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/user-guide.txt |  3 +++
 lib/tst_kconfig.c  | 31 +++++++++++++++++++++++++++++++
 lib/tst_test.c     |  1 +
 3 files changed, 35 insertions(+)

diff --git a/doc/user-guide.txt b/doc/user-guide.txt
index 494652618..8d4435a28 100644
--- a/doc/user-guide.txt
+++ b/doc/user-guide.txt
@@ -18,6 +18,9 @@ For running LTP network tests see `testcases/network/README.md`.
 | 'LTP_SINGLE_FS_TYPE'  | Testing only - specifies filesystem instead all
                           supported (for tests with '.all_filesystems').
 | 'LTP_DEV_FS_TYPE'     | Filesystem used for testing (default: 'ext2').
+| 'LTP_KCONFIG_DISABLE' | Switch for kernel config check functionality.
+                          'y' or '1': disable kconfig check,
+                          'n' or '0': enable kconfig check.
 | 'LTP_TIMEOUT_MUL'     | Multiply timeout, must be number >= 1 (> 1 is useful for
                           slow machines to avoid unexpected timeout).
                           Variable is also used in shell tests, but ceiled to int.
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index dc7decff9..c37afd8c8 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -478,6 +478,27 @@ static void dump_vars(const struct tst_expr *expr)
 	}
 }
 
+static int tst_kconfig_disabled(void)
+{
+	static int check;
+
+	if (check)
+		return check - 1;
+
+	char *env = getenv("LTP_KCONFIG_DISABLE");
+
+	if (env) {
+		if (!strcmp(env, "n") || !strcmp(env, "0"))
+			check = 1;
+		if (!strcmp(env, "y") || !strcmp(env, "1"))
+			check = 2;
+		return check - 1;
+	}
+
+	check = 1;
+	return 0;
+}
+
 int tst_kconfig_check(const char *const kconfigs[])
 {
 	size_t expr_cnt = array_len(kconfigs);
@@ -485,6 +506,11 @@ int tst_kconfig_check(const char *const kconfigs[])
 	unsigned int i, var_cnt;
 	int ret = 0;
 
+	if (tst_kconfig_disabled()) {
+		tst_res(TINFO, "Kernel config check functionality has been disabled.");
+		return 0;
+	}
+
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
 
@@ -530,6 +556,11 @@ char tst_kconfig_get(const char *confname)
 {
 	struct tst_kconfig_var var;
 
+	if (tst_kconfig_disabled()) {
+		tst_res(TINFO, "Kernel config check functionality has been disabled.");
+		return 0;
+	}
+
 	var.id_len = strlen(confname);
 
 	if (var.id_len >= sizeof(var.id))
diff --git a/lib/tst_test.c b/lib/tst_test.c
index d5cefadaa..3e6f2ee1f 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -483,6 +483,7 @@ static void print_help(void)
 	fprintf(stderr, "LTP_COLORIZE_OUTPUT  Force colorized output behaviour (y/1 always, n/0: never)\n");
 	fprintf(stderr, "LTP_DEV              Path to the block device to be used (for .needs_device)\n");
 	fprintf(stderr, "LTP_DEV_FS_TYPE      Filesystem used for testing (default: %s)\n", DEFAULT_FS_TYPE);
+	fprintf(stderr, "LTP_KCONFIG_DISABLE  Switch for kernel config check functionality (y/1: disable, n/0: enable)\n");
 	fprintf(stderr, "LTP_SINGLE_FS_TYPE   Testing only - specifies filesystem instead all supported (for .all_filesystems)\n");
 	fprintf(stderr, "LTP_TIMEOUT_MUL      Timeout multiplier (must be a number >=1)\n");
 	fprintf(stderr, "LTP_VIRT_OVERRIDE    Overrides virtual machine detection (values: \"\"|kvm|microsoft|xen|zvm)\n");
-- 
2.23.0



More information about the ltp mailing list