All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1 1/3] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
@ 2022-01-04  6:57 Yang Xu
  2022-01-04  6:57 ` [LTP] [PATCH v1 2/3] shell: add kconfig parse api Yang Xu
  2022-01-04  6:57 ` [LTP] [PATCH v1 3/3] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
  0 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-04  6:57 UTC (permalink / raw)
  To: ltp

So this function can be used to detect whether the function succeeded in shell
api by its return value.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/tst_kconfig.h |  2 +-
 lib/tst_kconfig.c     | 21 ++++++++++++---------
 lib/tst_test.c        |  4 ++--
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/include/tst_kconfig.h b/include/tst_kconfig.h
index 1bb21fea8..050687c69 100644
--- a/include/tst_kconfig.h
+++ b/include/tst_kconfig.h
@@ -53,6 +53,6 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
  *
  * @param kconfigs NULL-terminated array of config strings needed for the testrun.
  */
-void tst_kconfig_check(const char *const kconfigs[]);
+int tst_kconfig_check(const char *const kconfigs[]);
 
 #endif	/* TST_KCONFIG_H__ */
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index d433b8cf6..dc7decff9 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -478,22 +478,26 @@ static void dump_vars(const struct tst_expr *expr)
 	}
 }
 
-void tst_kconfig_check(const char *const kconfigs[])
+int tst_kconfig_check(const char *const kconfigs[])
 {
 	size_t expr_cnt = array_len(kconfigs);
 	struct tst_expr *exprs[expr_cnt];
 	unsigned int i, var_cnt;
-	int abort_test = 0;
+	int ret = 0;
 
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
 
-		if (!exprs[i])
-			tst_brk(TBROK, "Invalid kconfig expression!");
+		if (!exprs[i]) {
+			tst_res(TWARN, "Invalid kconfig expression!");
+			return 1;
+		}
 	}
 
-	if (validate_vars(exprs, expr_cnt))
-		tst_brk(TBROK, "Invalid kconfig variables!");
+	if (validate_vars(exprs, expr_cnt)) {
+		tst_res(TWARN, "Invalid kconfig variables!");
+		return 1;
+	}
 
 	var_cnt = get_var_cnt(exprs, expr_cnt);
 	struct tst_kconfig_var vars[var_cnt];
@@ -506,7 +510,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 		int val = tst_bool_expr_eval(exprs[i], map);
 
 		if (val != 1) {
-			abort_test = 1;
+			ret = 1;
 			tst_res(TINFO, "Constraint '%s' not satisfied!", kconfigs[i]);
 			dump_vars(exprs[i]);
 		}
@@ -519,8 +523,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 			free(vars[i].val);
 	}
 
-	if (abort_test)
-		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+	return ret;
 }
 
 char tst_kconfig_get(const char *confname)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 23fc0ebf4..f0bf97743 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1016,8 +1016,8 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->tconf_msg)
 		tst_brk(TCONF, "%s", tst_test->tconf_msg);
 
-	if (tst_test->needs_kconfigs)
-		tst_kconfig_check(tst_test->needs_kconfigs);
+	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
+		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
 	assert_test_fn();
 
-- 
2.23.0


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

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

* [LTP] [PATCH v1 2/3] shell: add kconfig parse api
  2022-01-04  6:57 [LTP] [PATCH v1 1/3] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
@ 2022-01-04  6:57 ` Yang Xu
  2022-01-04 11:04   ` Petr Vorel
  2022-01-04  6:57 ` [LTP] [PATCH v1 3/3] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
  1 sibling, 1 reply; 74+ messages in thread
From: Yang Xu @ 2022-01-04  6:57 UTC (permalink / raw)
  To: ltp

Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
It introduces three variables in tst_test.sh
TST_NEEDS_KCONFIGS
TST_NEEDS_KCONFIG_IFS (default value is comma)
TST_TCONF_IF_KCONFIG (default value is 1, 0 means to use TWRAN and case continue)

Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
case instead the whole test.

ps:Don't use array in tst_require_kconfigs because dash doesn't support shell array.

Fixes:#891
Suggested-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/shell-test-api.txt                        | 57 +++++++++++++------
 lib/newlib_tests/runtest.sh                   |  4 +-
 lib/newlib_tests/shell/tst_check_kconfig01.sh | 26 +++++++++
 lib/newlib_tests/shell/tst_check_kconfig02.sh | 16 ++++++
 lib/newlib_tests/shell/tst_check_kconfig03.sh | 15 +++++
 lib/newlib_tests/shell/tst_check_kconfig04.sh | 16 ++++++
 lib/newlib_tests/shell/tst_check_kconfig05.sh | 26 +++++++++
 lib/newlib_tests/shell/tst_check_kconfig06.sh | 17 ++++++
 testcases/lib/.gitignore                      |  1 +
 testcases/lib/Makefile                        |  4 +-
 testcases/lib/tst_check_kconfigs.c            | 17 ++++++
 testcases/lib/tst_test.sh                     | 41 +++++++++++++
 12 files changed, 221 insertions(+), 19 deletions(-)
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig04.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig05.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig06.sh
 create mode 100644 testcases/lib/tst_check_kconfigs.c

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index b993a9e1e..c742fff39 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -193,22 +193,23 @@ simply by setting right '$TST_NEEDS_FOO'.
 
 [options="header"]
 |=============================================================================
-| Variable name      | Action done
-| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
-|                    | Alternatively the 'tst_require_root' command can be used.
-| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
-| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
-                       device is stored in '$TST_DEVICE' variable.
-                       The option implies 'TST_NEEDS_TMPDIR'.
-| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
-                       the test (see below).
-| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
-| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
-| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
-                       or -1 (special value to disable timeout), default is 300.
-                       Variable is meant be set in tests, not by user.
-                       It's an equivalent of `tst_test.timeout` in C, can be set
-                       via 'tst_set_timeout(timeout)' after test has started.
+| Variable name       | Action done
+| 'TST_NEEDS_ROOT'    | Exit the test with 'TCONF' unless executed under root.
+|                     | Alternatively the 'tst_require_root' command can be used.
+| 'TST_NEEDS_TMPDIR'  | Create test temporary directory and cd into it.
+| 'TST_NEEDS_DEVICE'  | Prepare test temporary device, the path to testing
+                        device is stored in '$TST_DEVICE' variable.
+                        The option implies 'TST_NEEDS_TMPDIR'.
+| 'TST_NEEDS_CMDS'    | String with command names that has to be present for
+                        the test (see below).
+| 'TST_NEEDS_MODULE'  | Test module name needed for the test (see below).
+| 'TST_NEEDS_DRIVERS' | Checks kernel drivers support for the test.
+| 'TST_NEEDS_KCONFIGS'| Checks kernel kconfigs support for the test (see below).
+| 'TST_TIMEOUT'       | Maximum timeout set for the test in sec. Must be int >= 1,
+                        or -1 (special value to disable timeout), default is 300.
+                        Variable is meant be set in tests, not by user.
+                        It's an equivalent of `tst_test.timeout` in C, can be set
+                        via 'tst_set_timeout(timeout)' after test has started.
 |=============================================================================
 
 [options="header"]
@@ -742,3 +743,27 @@ TST_NEEDS_CHECKPOINTS=1
 Since both the implementations are compatible, it's also possible to start
 a child binary process from a shell test and synchronize with it. This process
 must have checkpoints initialized by calling 'tst_reinit()'.
+
+1.7 Parsing kernel .config
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The shell library provides an implementation of the kconfig parsing interface
+compatible with the C version.
+
+It's possible to pass kernel kconfig list for tst_require_kconfigs api with
+'$TST_NEEDS_KCONFIGS'.
+Optional '$TST_NEEDS_KCONFIG_IFS' is used for splitting, default value is comma.
+Optional '$TST_TCONF_IF_KCONFIG' is used for deciding how to exit the test if kernel
+.config doesn't meet test's requirement, default value is 1(TCONF). Otherwise, just
+use TWRAN and continue to run test.
+
+Now, we support the length of kconfig list is 10.
+
+-------------------------------------------------------------------------------
+#!/bin/sh
+TST_NEEDS_KCONFIGS="CONFIG_FS_EXT4 , CONFIG_QUOTACTL=y"
+TST_NEEDS_KCONFIG_IFS=","
+TST_TCONF_IF_KCONFIG=1
+
+. tst_test.sh
+-------------------------------------------------------------------------------
diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index 8b2fe347a..1fb9e7f21 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -6,7 +6,9 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
 tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
 tst_fuzzy_sync03 test_zero_hugepage.sh}"
 
-LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
+LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
+shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
+
 
 cd $(dirname $0)
 PATH="$PWD/../../testcases/lib/:$PATH"
diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
new file mode 100755
index 000000000..dc09b6092
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_GENERIC_IRQ_PROBE=y,
+CONFIG_GENERIC_IRQ_SHOW=y,
+CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y,
+CONFIG_GENERIC_PENDING_IRQ=y,
+CONFIG_GENERIC_IRQ_MIGRATION=y,
+CONFIG_IRQ_DOMAIN=y,
+CONFIG_IRQ_DOMAIN_HIERARCHY=y,
+CONFIG_GENERIC_MSI_IRQ=y,
+CONFIG_GENERIC_MSI_IRQ_DOMAIN=y,
+CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y,
+CONFIG_GENERIC_IRQ_RESERVATION_MODE=y"
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "Kconfig api only supports 10 kernel kconfigs!"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
new file mode 100755
index 000000000..d79f96ff2
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4"
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "Kernel .config doesn't have CONFIG_EXT4!"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
new file mode 100755
index 000000000..c70f378f8
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS: CONFIG_XFS_FS"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "Invalid kconfig delimter!"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
new file mode 100755
index 000000000..42b07d287
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+TST_NEEDS_KCONFIG_IFS=":"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TPASS "Valid kconfig delimter!"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig05.sh b/lib/newlib_tests/shell/tst_check_kconfig05.sh
new file mode 100755
index 000000000..6e5d5368b
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+. tst_test.sh
+
+do_test()
+{
+	tst_check_kconfigs "CONFIG_EXT4_FS"
+	if [ $? -eq 0 ]; then
+		tst_res TPASS "kernel .config has CONFIG_EXT4_fs."
+	else
+		tst_res TFAIL "kerenl .config doesn't have CONFIG_EXT4_FS."
+	fi
+
+	tst_check_kconfigs "CONFIG_EXT4"
+	if [ $? -eq 0 ]; then
+		tst_res TFAIL "kernel .config has CONFIG_EXT4."
+	else
+		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4."
+	fi
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig06.sh b/lib/newlib_tests/shell/tst_check_kconfig06.sh
new file mode 100755
index 000000000..6a6d68fd7
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig06.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4"
+TST_TCONF_IF_KCONFIG=0
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TPASS "Kernel .config doesn't have CONFIG_EXT4!"
+}
+
+tst_run
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 9625d9043..c0d4dc851 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,4 +1,5 @@
 /tst_check_drivers
+/tst_check_kconfigs
 /tst_checkpoint
 /tst_device
 /tst_getconf
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index d6b4c7a91..0e40cc7e3 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -11,6 +11,6 @@ INSTALL_TARGETS		:= *.sh
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
-			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
-
+			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
+			   tst_check_kconfigs
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
new file mode 100644
index 000000000..fda322746
--- /dev/null
+++ b/testcases/lib/tst_check_kconfigs.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/
+
+#include <stdio.h>
+#include "tst_kconfig.h"
+
+int main(int argc, const char *argv[])
+{
+	if (argc < 2) {
+		fprintf(stderr, "Please provide kernel kconfig list\n");
+		return 1;
+	}
+
+	if (tst_kconfig_check(argv+1))
+		return 1;
+	return 0;
+}
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 2556b28f5..c8134692e 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -412,6 +412,41 @@ tst_require_drivers()
 	return 0
 }
 
+tst_require_kconfigs()
+{
+	[ $# -eq 0 ] && return 0
+
+	local kconfigs
+	local kconfig_i
+	local kconfig_max
+
+	kconfigs=$@
+	[ -z "$kconfigs" ] && return 0
+
+	tst_check_cmds cut tr wc
+	kconfig_max=$(( $(echo "$kconfigs" | tr -cd "$TST_NEEDS_KCONFIG_IFS" | wc -c) +1))
+	if [ $kconfig_max -gt 10 ]; then
+		tst_brk TCONF "The max number of kconfig is 10!"
+	fi
+
+	for kconfig_i in $(seq $kconfig_max); do
+		eval "local kconfig$kconfig_i"
+		eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIG_IFS" -f$kconfig_i)'"
+	done
+
+	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
+			$kconfig7 $kconfig8 $kconfig9 $kconfig10
+	if [ $? -ne 0 ]; then
+		if [ $TST_TCONF_IF_KCONFIG -eq 1 ]; then
+			tst_brk TCONF "kconfig not available"
+		else
+			tst_res TWARN "kconfig not available"
+		fi
+	fi
+
+	return 0
+}
+
 tst_is_int()
 {
 	[ "$1" -eq "$1" ] 2>/dev/null
@@ -586,6 +621,7 @@ tst_run()
 			OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
 			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
 			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
+			NEEDS_KCONFIGS|NEEDS_KCONFIG_IFS|TCONF_IF_KCONFIG);;
 			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
 			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
 			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
@@ -626,6 +662,7 @@ tst_run()
 	[ "$TST_DISABLE_APPARMOR" = 1 ] && tst_disable_apparmor
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
 
+	tst_require_kconfigs $TST_NEEDS_KCONFIGS
 	tst_require_cmds $TST_NEEDS_CMDS
 	tst_require_drivers $TST_NEEDS_DRIVERS
 
@@ -748,6 +785,10 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
 
 	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
 
+	TST_NEEDS_KCONFIG_IFS="${TST_NEEDS_KCONFIG_IFS:-,}"
+
+	TST_TCONF_IF_KCONFIG="${TST_TCONF_IF_KCONFIG:-1}"
+
 	if [ -n "$TST_CNT" ]; then
 		if ! tst_is_int "$TST_CNT"; then
 			tst_brk TBROK "TST_CNT must be integer"
-- 
2.23.0


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

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

* [LTP] [PATCH v1 3/3] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-04  6:57 [LTP] [PATCH v1 1/3] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-04  6:57 ` [LTP] [PATCH v1 2/3] shell: add kconfig parse api Yang Xu
@ 2022-01-04  6:57 ` Yang Xu
  1 sibling, 0 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-04  6:57 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/commands/sysctl/sysctl02.sh | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/testcases/commands/sysctl/sysctl02.sh b/testcases/commands/sysctl/sysctl02.sh
index 3964a9829..1c444268a 100755
--- a/testcases/commands/sysctl/sysctl02.sh
+++ b/testcases/commands/sysctl/sysctl02.sh
@@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
 TST_CNT=4
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl"
+TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
 sys_name="fs.file-max"
 sys_file="/proc/sys/fs/file-max"
-syms_file="/proc/kallsyms"
 
 . tst_test.sh
 
 setup()
 {
-	[ ! -f "$sys_file" ] && tst_brk TCONF "$sys_file not enabled"
 	orig_value=$(cat "$sys_file")
 }
 
@@ -61,17 +60,15 @@ sysctl_test_overflow()
 
 sysctl_test_zero()
 {
-	[ ! -f "$syms_file" ] && tst_brk TCONF "$syms_file not enabled"
+	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
+		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
+
 	ROD sysctl -w -q $sys_name=0
 
-	if grep -q kasan_report $syms_file; then
-		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
-			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
-		else
-			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
-		fi
+	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
+		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
 	else
-		tst_res TCONF "kernel doesn't support KASAN"
+		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
 	fi
 }
 
-- 
2.23.0


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

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

* Re: [LTP] [PATCH v1 2/3] shell: add kconfig parse api
  2022-01-04  6:57 ` [LTP] [PATCH v1 2/3] shell: add kconfig parse api Yang Xu
@ 2022-01-04 11:04   ` Petr Vorel
  2022-01-05  7:15     ` xuyang2018.jy
  0 siblings, 1 reply; 74+ messages in thread
From: Petr Vorel @ 2022-01-04 11:04 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

> Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
> It introduces three variables in tst_test.sh
> TST_NEEDS_KCONFIGS
> TST_NEEDS_KCONFIG_IFS (default value is comma)
> TST_TCONF_IF_KCONFIG (default value is 1, 0 means to use TWRAN and case continue)

> Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
> case instead the whole test.

> ps:Don't use array in tst_require_kconfigs because dash doesn't support shell array.
IFS instead of array is has been used since tst_test.sh creation, maybe we can
omit this info.

> Fixes:#891
> Suggested-by: Petr Vorel <pvorel@suse.cz>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>

> +++ b/doc/shell-test-api.txt
> @@ -193,22 +193,23 @@ simply by setting right '$TST_NEEDS_FOO'.

>  [options="header"]
>  |=============================================================================
> -| Variable name      | Action done
> -| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
> -|                    | Alternatively the 'tst_require_root' command can be used.
> -| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
> -| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
> -                       device is stored in '$TST_DEVICE' variable.
> -                       The option implies 'TST_NEEDS_TMPDIR'.
> -| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
> -                       the test (see below).
> -| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
> -| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
> -| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
> -                       or -1 (special value to disable timeout), default is 300.
> -                       Variable is meant be set in tests, not by user.
> -                       It's an equivalent of `tst_test.timeout` in C, can be set
> -                       via 'tst_set_timeout(timeout)' after test has started.
> +| Variable name       | Action done
> +| 'TST_NEEDS_ROOT'    | Exit the test with 'TCONF' unless executed under root.
> +|                     | Alternatively the 'tst_require_root' command can be used.
> +| 'TST_NEEDS_TMPDIR'  | Create test temporary directory and cd into it.
> +| 'TST_NEEDS_DEVICE'  | Prepare test temporary device, the path to testing
> +                        device is stored in '$TST_DEVICE' variable.
> +                        The option implies 'TST_NEEDS_TMPDIR'.
> +| 'TST_NEEDS_CMDS'    | String with command names that has to be present for
> +                        the test (see below).
> +| 'TST_NEEDS_MODULE'  | Test module name needed for the test (see below).
> +| 'TST_NEEDS_DRIVERS' | Checks kernel drivers support for the test.
> +| 'TST_NEEDS_KCONFIGS'| Checks kernel kconfigs support for the test (see below).
+1 for adding TST_NEEDS_KCONFIG_IFS, it's needed e.g. for: CONFIG_LSM="integrity,apparmor"
Could you please mention TST_NEEDS_KCONFIG_IFS and TST_TCONF_IF_KCONFIG here in docs?

> +| 'TST_TIMEOUT'       | Maximum timeout set for the test in sec. Must be int >= 1,
> +                        or -1 (special value to disable timeout), default is 300.
> +                        Variable is meant be set in tests, not by user.
> +                        It's an equivalent of `tst_test.timeout` in C, can be set
> +                        via 'tst_set_timeout(timeout)' after test has started.
>  |=============================================================================

>  [options="header"]
> @@ -742,3 +743,27 @@ TST_NEEDS_CHECKPOINTS=1
>  Since both the implementations are compatible, it's also possible to start
>  a child binary process from a shell test and synchronize with it. This process
>  must have checkpoints initialized by calling 'tst_reinit()'.
> +
> +1.7 Parsing kernel .config
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +The shell library provides an implementation of the kconfig parsing interface
> +compatible with the C version.
> +
> +It's possible to pass kernel kconfig list for tst_require_kconfigs api with
nit: s/api/API/ (it's an abbreviation). Also before merge please update git commit message.

> +'$TST_NEEDS_KCONFIGS'.
> +Optional '$TST_NEEDS_KCONFIG_IFS' is used for splitting, default value is comma.
> +Optional '$TST_TCONF_IF_KCONFIG' is used for deciding how to exit the test if kernel
> +.config doesn't meet test's requirement, default value is 1(TCONF). Otherwise, just
I wonder if we need TST_TCONF_IF_KCONFIG functionality in the test or if it's an
user request (i.e. user like variable LTP_TCONF_IF_KCONFIG doc/user-guide.txt).
Because I'm not sure whether test would need it, but I can imagine user want to
have test running even kernel config is not available (e.g. embedded platforms).
Or maybe we need both user variable and test variable.

Also not sure about TST_TCONF_IF_KCONFIG name, IMHO "IF" should be replaced to
something which describes what it does.

Also this patchset is about syncing C API functionality with shell API. But you
introduce TST_TCONF_IF_KCONFIG only for shell. Shouldn't it be functionality for
both parts?

More notes about this variable also below.

BTW github actions have probably kernel config on expected place, which means
that most of the new tests TCONF, but tst_check_kconfig05.sh TFAIL.

tst_rhost_run 1 TCONF: veth(null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.dep does not exist or not a file
320
(null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.builtin does not exist or not a file driver not available

> +use TWRAN and continue to run test.
> +
> +Now, we support the length of kconfig list is 10.
Why 10? Cyril suggested that in PR, where he suggested to use separated
variables:
https://github.com/linux-test-project/ltp/issues/891#issuecomment-989712350

But for string used like array there is no performance limitation, thus I'd use
something like 50 or 100. Because for certain IMA tests there are at least 6
kconfig requirements, thus > 10 could be hit.

...
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
> new file mode 100755
> index 000000000..dc09b6092
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_GENERIC_IRQ_PROBE=y,
> +CONFIG_GENERIC_IRQ_SHOW=y,
> +CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y,
> +CONFIG_GENERIC_PENDING_IRQ=y,
> +CONFIG_GENERIC_IRQ_MIGRATION=y,
> +CONFIG_IRQ_DOMAIN=y,
> +CONFIG_IRQ_DOMAIN_HIERARCHY=y,
> +CONFIG_GENERIC_MSI_IRQ=y,
> +CONFIG_GENERIC_MSI_IRQ_DOMAIN=y,
> +CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y,
> +CONFIG_GENERIC_IRQ_RESERVATION_MODE=y"
> +
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TFAIL "Kconfig api only supports 10 kernel kconfigs!"
s/api/API

...
> +++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_check_kconfigs "CONFIG_EXT4_FS"
> +	if [ $? -eq 0 ]; then
> +		tst_res TPASS "kernel .config has CONFIG_EXT4_fs."
nit: I'd also remove dot at the end (we don't use it in tests).

> +	else
> +		tst_res TFAIL "kerenl .config doesn't have CONFIG_EXT4_FS."
s/kerenl/kernel/
> +	fi
> +
> +	tst_check_kconfigs "CONFIG_EXT4"
> +	if [ $? -eq 0 ]; then
> +		tst_res TFAIL "kernel .config has CONFIG_EXT4."
> +	else
> +		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4."
> +	fi
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig06.sh b/lib/newlib_tests/shell/tst_check_kconfig06.sh
> new file mode 100755
> index 000000000..6a6d68fd7
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig06.sh
> @@ -0,0 +1,17 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4"
> +TST_TCONF_IF_KCONFIG=0
IMHO in shell is better to have empty value for "false", not zero.
Also, we use it that way for shell variables.

But that would mean you'd have to allow to be empty, i.e. use : instead of :-:
+TST_TCONF_IF_KCONFIG="${TST_TCONF_IF_KCONFIG:-1}"
-TST_TCONF_IF_KCONFIG="${TST_TCONF_IF_KCONFIG:1}"

But maybe it'd be better to have variable which is off by default (thus variable
with reverse meaning).

...
> +++ b/testcases/lib/tst_check_kconfigs.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/
> +
> +#include <stdio.h>
> +#include "tst_kconfig.h"
> +
> +int main(int argc, const char *argv[])
> +{
> +	if (argc < 2) {
> +		fprintf(stderr, "Please provide kernel kconfig list\n");
> +		return 1;
> +	}
> +
> +	if (tst_kconfig_check(argv+1))
> +		return 1;
nit: I'd add space here (readability).
> +	return 0;
> +}
> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 2556b28f5..c8134692e 100644
...

> --- a/testcases/lib/tst_test.sh
> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
> +	if [ $? -ne 0 ]; then
> +		if [ $TST_TCONF_IF_KCONFIG -eq 1 ]; then
> +			tst_brk TCONF "kconfig not available"

> +		else
> +			tst_res TWARN "kconfig not available"
This is quite strong: either test "fails" due TWARN non-zero exit code or it's
skipped. I'd prefer to have user variable for systems which are properly
configured (user will make sure all kconfig options are set), but it's just
missing kconfig due system configuration.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v1 2/3] shell: add kconfig parse api
  2022-01-04 11:04   ` Petr Vorel
@ 2022-01-05  7:15     ` xuyang2018.jy
  2022-01-05 14:34       ` Petr Vorel
  0 siblings, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-05  7:15 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi Petr
> Hi Xu,
>
>> Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
>> It introduces three variables in tst_test.sh
>> TST_NEEDS_KCONFIGS
>> TST_NEEDS_KCONFIG_IFS (default value is comma)
>> TST_TCONF_IF_KCONFIG (default value is 1, 0 means to use TWRAN and case continue)
>
>> Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
>> case instead the whole test.
>
>> ps:Don't use array in tst_require_kconfigs because dash doesn't support shell array.
> IFS instead of array is has been used since tst_test.sh creation, maybe we can
> omit this info.
Now, I know. Will remove this info.
>
>> Fixes:#891
>> Suggested-by: Petr Vorel<pvorel@suse.cz>
>> Suggested-by: Cyril Hrubis<chrubis@suse.cz>
>> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
>
>> +++ b/doc/shell-test-api.txt
>> @@ -193,22 +193,23 @@ simply by setting right '$TST_NEEDS_FOO'.
>
>>   [options="header"]
>>   |=============================================================================
>> -| Variable name      | Action done
>> -| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
>> -|                    | Alternatively the 'tst_require_root' command can be used.
>> -| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
>> -| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
>> -                       device is stored in '$TST_DEVICE' variable.
>> -                       The option implies 'TST_NEEDS_TMPDIR'.
>> -| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
>> -                       the test (see below).
>> -| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
>> -| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
>> -| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int>= 1,
>> -                       or -1 (special value to disable timeout), default is 300.
>> -                       Variable is meant be set in tests, not by user.
>> -                       It's an equivalent of `tst_test.timeout` in C, can be set
>> -                       via 'tst_set_timeout(timeout)' after test has started.
>> +| Variable name       | Action done
>> +| 'TST_NEEDS_ROOT'    | Exit the test with 'TCONF' unless executed under root.
>> +|                     | Alternatively the 'tst_require_root' command can be used.
>> +| 'TST_NEEDS_TMPDIR'  | Create test temporary directory and cd into it.
>> +| 'TST_NEEDS_DEVICE'  | Prepare test temporary device, the path to testing
>> +                        device is stored in '$TST_DEVICE' variable.
>> +                        The option implies 'TST_NEEDS_TMPDIR'.
>> +| 'TST_NEEDS_CMDS'    | String with command names that has to be present for
>> +                        the test (see below).
>> +| 'TST_NEEDS_MODULE'  | Test module name needed for the test (see below).
>> +| 'TST_NEEDS_DRIVERS' | Checks kernel drivers support for the test.
>> +| 'TST_NEEDS_KCONFIGS'| Checks kernel kconfigs support for the test (see below).
> +1 for adding TST_NEEDS_KCONFIG_IFS, it's needed e.g. for: CONFIG_LSM="integrity,apparmor"
> Could you please mention TST_NEEDS_KCONFIG_IFS and TST_TCONF_IF_KCONFIG here in docs?
of course.
>
>> +| 'TST_TIMEOUT'       | Maximum timeout set for the test in sec. Must be int>= 1,
>> +                        or -1 (special value to disable timeout), default is 300.
>> +                        Variable is meant be set in tests, not by user.
>> +                        It's an equivalent of `tst_test.timeout` in C, can be set
>> +                        via 'tst_set_timeout(timeout)' after test has started.
>>   |=============================================================================
>
>>   [options="header"]
>> @@ -742,3 +743,27 @@ TST_NEEDS_CHECKPOINTS=1
>>   Since both the implementations are compatible, it's also possible to start
>>   a child binary process from a shell test and synchronize with it. This process
>>   must have checkpoints initialized by calling 'tst_reinit()'.
>> +
>> +1.7 Parsing kernel .config
>> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> +
>> +The shell library provides an implementation of the kconfig parsing interface
>> +compatible with the C version.
>> +
>> +It's possible to pass kernel kconfig list for tst_require_kconfigs api with
> nit: s/api/API/ (it's an abbreviation). Also before merge please update git commit message.
>
>> +'$TST_NEEDS_KCONFIGS'.
>> +Optional '$TST_NEEDS_KCONFIG_IFS' is used for splitting, default value is comma.
>> +Optional '$TST_TCONF_IF_KCONFIG' is used for deciding how to exit the test if kernel
>> +.config doesn't meet test's requirement, default value is 1(TCONF). Otherwise, just
> I wonder if we need TST_TCONF_IF_KCONFIG functionality in the test or if it's an
> user request (i.e. user like variable LTP_TCONF_IF_KCONFIG doc/user-guide.txt).
> Because I'm not sure whether test would need it, but I can imagine user want to
> have test running even kernel config is not available (e.g. embedded platforms).
> Or maybe we need both user variable and test variable.
Oh, I misunderstand the usage.

I should use TST_TCONF_IF_KCONFIG for non-found kconfig file instead of 
non-found kconfig list.

I think one variable is enough.

>
> Also not sure about TST_TCONF_IF_KCONFIG name, IMHO "IF" should be replaced to
> something which describes what it does.
Thinking a good name isn't a easy thing.

how about TCONF_IF_NO_KCONFIG?

>
> Also this patchset is about syncing C API functionality with shell API. But you
> introduce TST_TCONF_IF_KCONFIG only for shell. Shouldn't it be functionality for
> both parts?
Yes, code maybe as below:

void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len)
+static char kconfig_flag;
+
+int tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len)
  {
         char line[128];
         unsigned int vars_found = 0;
+       const char *flag = getenv("TWARN_IF_NO_KCONFIG");
+
+       if (flag && !strcmp(flag,"y"))
+               kconfig_flag = 'y';

         FILE *fp = open_kconfig();
-       if (!fp)
+       if (!fp) {
+               if (kconfig_flag == 'y') {
+                       tst_res(TWARN, "Cannot parse kernel .config");
+                       return 1;
+               }
                 tst_brk(TBROK, "Cannot parse kernel .config");
-
+       }
         while (fgets(line, sizeof(line), fp)) {
                 if (kconfig_parse_line(line, vars, vars_len))
                         vars_found++;
@@ -198,6 +210,7 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], 
size_t vars_len)

  exit:
         close_kconfig(fp);
+       return 0;
  }

  static size_t array_len(const char *const kconfigs[])
@@ -504,7 +517,9 @@ int tst_kconfig_check(const char *const kconfigs[])

         var_cnt = populate_vars(exprs, expr_cnt, vars);

-       tst_kconfig_read(vars, var_cnt);
+       ret = tst_kconfig_read(vars, var_cnt);
+       if (ret)
+               return kconfig_flag == 'y' ? 0 : 1;



>
> More notes about this variable also below.
>
> BTW github actions have probably kernel config on expected place, which means
> that most of the new tests TCONF, but tst_check_kconfig05.sh TFAIL.
I guess we can export the  KCONFIG_PATH to solve this problem. But I 
don't know the expected place on github actions.
>
> tst_rhost_run 1 TCONF: veth(null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.dep does not exist or not a file
> 320
> (null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.builtin does not exist or not a file driver not available
>
>> +use TWRAN and continue to run test.
>> +
>> +Now, we support the length of kconfig list is 10.
> Why 10? Cyril suggested that in PR, where he suggested to use separated
> variables:
> https://github.com/linux-test-project/ltp/issues/891#issuecomment-989712350
>
> But for string used like array there is no performance limitation, thus I'd use
> something like 50 or 100. Because for certain IMA tests there are at least 6
> kconfig requirements, thus>  10 could be hit.
If case needs more than 10 kconfigs, we can use & ie
"CONFIG_EX4_FS & CONFIG_XFS_FS & CONFIG_QUOTAL_FS, CONFIG_PROC_FS..."
>
> ...
>> diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
>> new file mode 100755
>> index 000000000..dc09b6092
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
>> @@ -0,0 +1,26 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>> +TST_NEEDS_KCONFIGS="CONFIG_GENERIC_IRQ_PROBE=y,
>> +CONFIG_GENERIC_IRQ_SHOW=y,
>> +CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y,
>> +CONFIG_GENERIC_PENDING_IRQ=y,
>> +CONFIG_GENERIC_IRQ_MIGRATION=y,
>> +CONFIG_IRQ_DOMAIN=y,
>> +CONFIG_IRQ_DOMAIN_HIERARCHY=y,
>> +CONFIG_GENERIC_MSI_IRQ=y,
>> +CONFIG_GENERIC_MSI_IRQ_DOMAIN=y,
>> +CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y,
>> +CONFIG_GENERIC_IRQ_RESERVATION_MODE=y"
>> +
>> +. tst_test.sh
>> +
>> +do_test()
>> +{
>> +	tst_res TFAIL "Kconfig api only supports 10 kernel kconfigs!"
> s/api/API
OK
>
> ...
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
>> @@ -0,0 +1,26 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>> +. tst_test.sh
>> +
>> +do_test()
>> +{
>> +	tst_check_kconfigs "CONFIG_EXT4_FS"
>> +	if [ $? -eq 0 ]; then
>> +		tst_res TPASS "kernel .config has CONFIG_EXT4_fs."
> nit: I'd also remove dot at the end (we don't use it in tests).
OK
>
>> +	else
>> +		tst_res TFAIL "kerenl .config doesn't have CONFIG_EXT4_FS."
> s/kerenl/kernel/
Sorry.
>> +	fi
>> +
>> +	tst_check_kconfigs "CONFIG_EXT4"
>> +	if [ $? -eq 0 ]; then
>> +		tst_res TFAIL "kernel .config has CONFIG_EXT4."
>> +	else
>> +		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4."
>> +	fi
>> +}
>> +
>> +tst_run
>> diff --git a/lib/newlib_tests/shell/tst_check_kconfig06.sh b/lib/newlib_tests/shell/tst_check_kconfig06.sh
>> new file mode 100755
>> index 000000000..6a6d68fd7
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig06.sh
>> @@ -0,0 +1,17 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>> +TST_NEEDS_KCONFIGS="CONFIG_EXT4"
>> +TST_TCONF_IF_KCONFIG=0
> IMHO in shell is better to have empty value for "false", not zero.
> Also, we use it that way for shell variables.
>
OK
> But that would mean you'd have to allow to be empty, i.e. use : instead of :-:
> +TST_TCONF_IF_KCONFIG="${TST_TCONF_IF_KCONFIG:-1}"
> -TST_TCONF_IF_KCONFIG="${TST_TCONF_IF_KCONFIG:1}"
>
> But maybe it'd be better to have variable which is off by default (thus variable
> with reverse meaning).
OK
>
> ...
>> +++ b/testcases/lib/tst_check_kconfigs.c
>> @@ -0,0 +1,17 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/
>> +
>> +#include<stdio.h>
>> +#include "tst_kconfig.h"
>> +
>> +int main(int argc, const char *argv[])
>> +{
>> +	if (argc<  2) {
>> +		fprintf(stderr, "Please provide kernel kconfig list\n");
>> +		return 1;
>> +	}
>> +
>> +	if (tst_kconfig_check(argv+1))
>> +		return 1;
> nit: I'd add space here (readability).
>> +	return 0;
>> +}
>> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
>> index 2556b28f5..c8134692e 100644
> ...
>
>> --- a/testcases/lib/tst_test.sh
>> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
>> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
>> +	if [ $? -ne 0 ]; then
>> +		if [ $TST_TCONF_IF_KCONFIG -eq 1 ]; then
>> +			tst_brk TCONF "kconfig not available"
>
>> +		else
>> +			tst_res TWARN "kconfig not available"
> This is quite strong: either test "fails" due TWARN non-zero exit code or it's
> skipped. I'd prefer to have user variable for systems which are properly
> configured (user will make sure all kconfig options are set), but it's just
> missing kconfig due system configuration.
I plan to fix the variable usage for non-found kconfig path/file instead 
of kconfig list.

Best Regards
Yang Xu
>
> Kind regards,
> Petr

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

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

* Re: [LTP] [PATCH v1 2/3] shell: add kconfig parse api
  2022-01-05  7:15     ` xuyang2018.jy
@ 2022-01-05 14:34       ` Petr Vorel
  2022-01-06  5:59         ` xuyang2018.jy
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  0 siblings, 2 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-05 14:34 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi Xu,

> >> +'$TST_NEEDS_KCONFIGS'.
> >> +Optional '$TST_NEEDS_KCONFIG_IFS' is used for splitting, default value is comma.
> >> +Optional '$TST_TCONF_IF_KCONFIG' is used for deciding how to exit the test if kernel
> >> +.config doesn't meet test's requirement, default value is 1(TCONF). Otherwise, just
> > I wonder if we need TST_TCONF_IF_KCONFIG functionality in the test or if it's an
> > user request (i.e. user like variable LTP_TCONF_IF_KCONFIG doc/user-guide.txt).
> > Because I'm not sure whether test would need it, but I can imagine user want to
> > have test running even kernel config is not available (e.g. embedded platforms).
> > Or maybe we need both user variable and test variable.
> Oh, I misunderstand the usage.

> I should use TST_TCONF_IF_KCONFIG for non-found kconfig file instead of 
> non-found kconfig list.

> I think one variable is enough.

OK, but I'd like to know others' opinion what's needed.
Cyril, Li?

> > Also not sure about TST_TCONF_IF_KCONFIG name, IMHO "IF" should be replaced to
> > something which describes what it does.
> Thinking a good name isn't a easy thing.

> how about TCONF_IF_NO_KCONFIG?

Well, I was not sure about "IF" part. For use in test code it should have "TST_"
prefix, for users to set it should have "LTP_" prefix.

> > Also this patchset is about syncing C API functionality with shell API. But you
> > introduce TST_TCONF_IF_KCONFIG only for shell. Shouldn't it be functionality for
> > both parts?
> Yes, code maybe as below:

> void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len)
> +static char kconfig_flag;
> +
> +int tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len)
>   {
>          char line[128];
>          unsigned int vars_found = 0;
> +       const char *flag = getenv("TWARN_IF_NO_KCONFIG");
> +
> +       if (flag && !strcmp(flag,"y"))
> +               kconfig_flag = 'y';

>          FILE *fp = open_kconfig();
> -       if (!fp)
> +       if (!fp) {
> +               if (kconfig_flag == 'y') {
> +                       tst_res(TWARN, "Cannot parse kernel .config");
> +                       return 1;
> +               }
>                  tst_brk(TBROK, "Cannot parse kernel .config");
> -
> +       }
>          while (fgets(line, sizeof(line), fp)) {
>                  if (kconfig_parse_line(line, vars, vars_len))
>                          vars_found++;
> @@ -198,6 +210,7 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], 
> size_t vars_len)

>   exit:
>          close_kconfig(fp);
> +       return 0;
>   }

Sure, once we agree what should be implemented.

>   static size_t array_len(const char *const kconfigs[])
> @@ -504,7 +517,9 @@ int tst_kconfig_check(const char *const kconfigs[])

>          var_cnt = populate_vars(exprs, expr_cnt, vars);

> -       tst_kconfig_read(vars, var_cnt);
> +       ret = tst_kconfig_read(vars, var_cnt);
> +       if (ret)
> +               return kconfig_flag == 'y' ? 0 : 1;




> > More notes about this variable also below.

> > BTW github actions have probably kernel config on expected place, which means
> > that most of the new tests TCONF, but tst_check_kconfig05.sh TFAIL.
> I guess we can export the  KCONFIG_PATH to solve this problem. But I 
> don't know the expected place on github actions.

Sure, for github we can find config place.
But this can happen to user who runs the test. IMHO test should not fail if
user's system is without config. That's why I'd like to have a variable making
errors non-fatal.

> > tst_rhost_run 1 TCONF: veth(null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.dep does not exist or not a file
> > 320
> > (null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.builtin does not exist or not a file driver not available

> >> +use TWRAN and continue to run test.
> >> +
> >> +Now, we support the length of kconfig list is 10.
> > Why 10? Cyril suggested that in PR, where he suggested to use separated
> > variables:
> > https://github.com/linux-test-project/ltp/issues/891#issuecomment-989712350

> > But for string used like array there is no performance limitation, thus I'd use
> > something like 50 or 100. Because for certain IMA tests there are at least 6
> > kconfig requirements, thus>  10 could be hit.
> If case needs more than 10 kconfigs, we can use & ie
> "CONFIG_EX4_FS & CONFIG_XFS_FS & CONFIG_QUOTAL_FS, CONFIG_PROC_FS..."
Sure. I just meant there is no reason to put low number and then workaround it.

> >> --- a/testcases/lib/tst_test.sh
> >> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
> >> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
> >> +	if [ $? -ne 0 ]; then
> >> +		if [ $TST_TCONF_IF_KCONFIG -eq 1 ]; then
> >> +			tst_brk TCONF "kconfig not available"

> >> +		else
> >> +			tst_res TWARN "kconfig not available"
> > This is quite strong: either test "fails" due TWARN non-zero exit code or it's
> > skipped. I'd prefer to have user variable for systems which are properly
> > configured (user will make sure all kconfig options are set), but it's just
> > missing kconfig due system configuration.
> I plan to fix the variable usage for non-found kconfig path/file instead 
> of kconfig list.

> Best Regards
> Yang Xu

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v1 2/3] shell: add kconfig parse api
  2022-01-05 14:34       ` Petr Vorel
@ 2022-01-06  5:59         ` xuyang2018.jy
  2022-01-06  8:16           ` xuyang2018.jy
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  1 sibling, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-06  5:59 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi Petr
> Hi Xu,
>
>>>> +'$TST_NEEDS_KCONFIGS'.
>>>> +Optional '$TST_NEEDS_KCONFIG_IFS' is used for splitting, default value is comma.
>>>> +Optional '$TST_TCONF_IF_KCONFIG' is used for deciding how to exit the test if kernel
>>>> +.config doesn't meet test's requirement, default value is 1(TCONF). Otherwise, just
>>> I wonder if we need TST_TCONF_IF_KCONFIG functionality in the test or if it's an
>>> user request (i.e. user like variable LTP_TCONF_IF_KCONFIG doc/user-guide.txt).
>>> Because I'm not sure whether test would need it, but I can imagine user want to
>>> have test running even kernel config is not available (e.g. embedded platforms).
>>> Or maybe we need both user variable and test variable.
>> Oh, I misunderstand the usage.
>
>> I should use TST_TCONF_IF_KCONFIG for non-found kconfig file instead of
>> non-found kconfig list.
>
>> I think one variable is enough.
>
> OK, but I'd like to know others' opinion what's needed.
> Cyril, Li?
>
>>> Also not sure about TST_TCONF_IF_KCONFIG name, IMHO "IF" should be replaced to
>>> something which describes what it does.
>> Thinking a good name isn't a easy thing.
>
>> how about TCONF_IF_NO_KCONFIG?
>
> Well, I was not sure about "IF" part. For use in test code it should have "TST_"
> prefix, for users to set it should have "LTP_" prefix.
When I write this v2 patch, I think we may introuce a 
LTP_KCONFIG_DISABLE macro that can disable kconfig parser function whole 
for the situation that some embedded platforms doesn't have config. So 
we don't need to distinguish whether kconfig file doesn't exist or perms 
leak or invalid config expression.

code may below
static int tst_kconfig_disable()
{
         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);
         struct tst_expr *exprs[expr_cnt];
         unsigned int i, var_cnt;
         int ret = 0;

	if (tst_kconfig_disable())
		return 0
	...
}

Also, this macro is easy to understand and we don't need macro ie 
CONF_IF_NO_KCONFIG or TWARN_NO_IF_KCONFIG. Any idea?

Best Regards
Yang Xu
>
>>> Also this patchset is about syncing C API functionality with shell API. But you
>>> introduce TST_TCONF_IF_KCONFIG only for shell. Shouldn't it be functionality for
>>> both parts?
>> Yes, code maybe as below:
>
>> void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len)
>> +static char kconfig_flag;
>> +
>> +int tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len)
>>    {
>>           char line[128];
>>           unsigned int vars_found = 0;
>> +       const char *flag = getenv("TWARN_IF_NO_KCONFIG");
>> +
>> +       if (flag&&  !strcmp(flag,"y"))
>> +               kconfig_flag = 'y';
>
>>           FILE *fp = open_kconfig();
>> -       if (!fp)
>> +       if (!fp) {
>> +               if (kconfig_flag == 'y') {
>> +                       tst_res(TWARN, "Cannot parse kernel .config");
>> +                       return 1;
>> +               }
>>                   tst_brk(TBROK, "Cannot parse kernel .config");
>> -
>> +       }
>>           while (fgets(line, sizeof(line), fp)) {
>>                   if (kconfig_parse_line(line, vars, vars_len))
>>                           vars_found++;
>> @@ -198,6 +210,7 @@ void tst_kconfig_read(struct tst_kconfig_var vars[],
>> size_t vars_len)
>
>>    exit:
>>           close_kconfig(fp);
>> +       return 0;
>>    }
>
> Sure, once we agree what should be implemented.
>
>>    static size_t array_len(const char *const kconfigs[])
>> @@ -504,7 +517,9 @@ int tst_kconfig_check(const char *const kconfigs[])
>
>>           var_cnt = populate_vars(exprs, expr_cnt, vars);
>
>> -       tst_kconfig_read(vars, var_cnt);
>> +       ret = tst_kconfig_read(vars, var_cnt);
>> +       if (ret)
>> +               return kconfig_flag == 'y' ? 0 : 1;
>
>
>
>
>>> More notes about this variable also below.
>
>>> BTW github actions have probably kernel config on expected place, which means
>>> that most of the new tests TCONF, but tst_check_kconfig05.sh TFAIL.
>> I guess we can export the  KCONFIG_PATH to solve this problem. But I
>> don't know the expected place on github actions.
>
> Sure, for github we can find config place.
> But this can happen to user who runs the test. IMHO test should not fail if
> user's system is without config. That's why I'd like to have a variable making
> errors non-fatal.
>
>>> tst_rhost_run 1 TCONF: veth(null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.dep does not exist or not a file
>>> 320
>>> (null)      0  TWARN  :  /__w/ltp/ltp/lib/tst_kernel.c:110: expected file /lib/modules/5.11.0-1022-azure/modules.builtin does not exist or not a file driver not available
>
>>>> +use TWRAN and continue to run test.
>>>> +
>>>> +Now, we support the length of kconfig list is 10.
>>> Why 10? Cyril suggested that in PR, where he suggested to use separated
>>> variables:
>>> https://github.com/linux-test-project/ltp/issues/891#issuecomment-989712350
>
>>> But for string used like array there is no performance limitation, thus I'd use
>>> something like 50 or 100. Because for certain IMA tests there are at least 6
>>> kconfig requirements, thus>   10 could be hit.
>> If case needs more than 10 kconfigs, we can use&  ie
>> "CONFIG_EX4_FS&  CONFIG_XFS_FS&  CONFIG_QUOTAL_FS, CONFIG_PROC_FS..."
> Sure. I just meant there is no reason to put low number and then workaround it.
>
>>>> --- a/testcases/lib/tst_test.sh
>>>> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
>>>> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
>>>> +	if [ $? -ne 0 ]; then
>>>> +		if [ $TST_TCONF_IF_KCONFIG -eq 1 ]; then
>>>> +			tst_brk TCONF "kconfig not available"
>
>>>> +		else
>>>> +			tst_res TWARN "kconfig not available"
>>> This is quite strong: either test "fails" due TWARN non-zero exit code or it's
>>> skipped. I'd prefer to have user variable for systems which are properly
>>> configured (user will make sure all kconfig options are set), but it's just
>>> missing kconfig due system configuration.
>> I plan to fix the variable usage for non-found kconfig path/file instead
>> of kconfig list.
>
>> Best Regards
>> Yang Xu
>
> Kind regards,
> Petr

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

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

* Re: [LTP] [PATCH v1 2/3] shell: add kconfig parse api
  2022-01-06  5:59         ` xuyang2018.jy
@ 2022-01-06  8:16           ` xuyang2018.jy
  0 siblings, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-06  8:16 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi Petr

>>>>> +
>>>>> +Now, we support the length of kconfig list is 10.
>>>> Why 10? Cyril suggested that in PR, where he suggested to use separated
>>>> variables:
>>>> https://github.com/linux-test-project/ltp/issues/891#issuecomment-989712350
>>
>>>> But for string used like array there is no performance limitation, thus I'd use
>>>> something like 50 or 100. Because for certain IMA tests there are at least 6
>>>> kconfig requirements, thus>    10 could be hit.
>>> If case needs more than 10 kconfigs, we can use&   ie
>>> "CONFIG_EX4_FS&   CONFIG_XFS_FS&   CONFIG_QUOTAL_FS, CONFIG_PROC_FS..."
>> Sure. I just meant there is no reason to put low number and then workaround it.
 From my understanding, we split kconfig list for kconfig1,2... variables.

Then I need to call tst_check_kconfigs with pass fixed number paremeters 
one ie 10). code ie
tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 
$kconfig6\
$kconfig7 $kconfig8 $kconfig9 $kconfig10

So do you have simple code to replace them or you just want to increase 
the number to 20?

ps: In fact, I am not good at writting shell script. So if wrong or have 
better way, please tell me.

Best Regards
Yang Xu

>

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

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

* [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-05 14:34       ` Petr Vorel
  2022-01-06  5:59         ` xuyang2018.jy
@ 2022-01-06  9:25         ` Yang Xu
  2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
                             ` (4 more replies)
  1 sibling, 5 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-06  9:25 UTC (permalink / raw)
  To: ltp

So this function can be used to detect whether the function succeeded in shell
api by its return value.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/tst_kconfig.h |  5 +++--
 lib/tst_kconfig.c     | 21 ++++++++++++---------
 lib/tst_test.c        |  4 ++--
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/include/tst_kconfig.h b/include/tst_kconfig.h
index 1bb21fea8..cc0908ea8 100644
--- a/include/tst_kconfig.h
+++ b/include/tst_kconfig.h
@@ -44,7 +44,8 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
 
 /**
  * Checks if required kernel configuration options are set in the kernel
- * config and exits the test with TCONF if at least one is missing.
+ * config. Return 0 if every config is satisfied and return 1 if at least
+ * one is missing.
  *
  * The config options can be passed in two different formats, either
  * "CONFIG_FOO" in which case the option has to be set in order to continue the
@@ -53,6 +54,6 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
  *
  * @param kconfigs NULL-terminated array of config strings needed for the testrun.
  */
-void tst_kconfig_check(const char *const kconfigs[]);
+int tst_kconfig_check(const char *const kconfigs[]);
 
 #endif	/* TST_KCONFIG_H__ */
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index d433b8cf6..dc7decff9 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -478,22 +478,26 @@ static void dump_vars(const struct tst_expr *expr)
 	}
 }
 
-void tst_kconfig_check(const char *const kconfigs[])
+int tst_kconfig_check(const char *const kconfigs[])
 {
 	size_t expr_cnt = array_len(kconfigs);
 	struct tst_expr *exprs[expr_cnt];
 	unsigned int i, var_cnt;
-	int abort_test = 0;
+	int ret = 0;
 
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
 
-		if (!exprs[i])
-			tst_brk(TBROK, "Invalid kconfig expression!");
+		if (!exprs[i]) {
+			tst_res(TWARN, "Invalid kconfig expression!");
+			return 1;
+		}
 	}
 
-	if (validate_vars(exprs, expr_cnt))
-		tst_brk(TBROK, "Invalid kconfig variables!");
+	if (validate_vars(exprs, expr_cnt)) {
+		tst_res(TWARN, "Invalid kconfig variables!");
+		return 1;
+	}
 
 	var_cnt = get_var_cnt(exprs, expr_cnt);
 	struct tst_kconfig_var vars[var_cnt];
@@ -506,7 +510,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 		int val = tst_bool_expr_eval(exprs[i], map);
 
 		if (val != 1) {
-			abort_test = 1;
+			ret = 1;
 			tst_res(TINFO, "Constraint '%s' not satisfied!", kconfigs[i]);
 			dump_vars(exprs[i]);
 		}
@@ -519,8 +523,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 			free(vars[i].val);
 	}
 
-	if (abort_test)
-		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+	return ret;
 }
 
 char tst_kconfig_get(const char *confname)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9fea7263a..d5cefadaa 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1025,8 +1025,8 @@ static void do_setup(int argc, char *argv[])
 
 	parse_opts(argc, argv);
 
-	if (tst_test->needs_kconfigs)
-		tst_kconfig_check(tst_test->needs_kconfigs);
+	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
+		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
 	if (tst_test->needs_root && geteuid() != 0)
 		tst_brk(TCONF, "Test needs to be run as root");
-- 
2.23.0


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

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

* [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
@ 2022-01-06  9:25           ` Yang Xu
  2022-01-06  9:49             ` Petr Vorel
                               ` (2 more replies)
  2022-01-06  9:25           ` [LTP] [PATCH v2 3/4] shell: add kconfig parse api Yang Xu
                             ` (3 subsequent siblings)
  4 siblings, 3 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-06  9:25 UTC (permalink / raw)
  To: ltp

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


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

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

* [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
@ 2022-01-06  9:25           ` Yang Xu
  2022-01-06 10:40             ` Petr Vorel
  2022-01-06 11:19             ` Cyril Hrubis
  2022-01-06  9:25           ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
                             ` (2 subsequent siblings)
  4 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-06  9:25 UTC (permalink / raw)
  To: ltp

Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
It introduces two variables in tst_test.sh
TST_NEEDS_KCONFIGS
TST_NEEDS_KCONFIGS_IFS (default value is comma)

Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
case instead the whole test.

Fixes:#891
Suggested-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/shell-test-api.txt                        | 54 +++++++++++++------
 lib/newlib_tests/runtest.sh                   |  3 +-
 lib/newlib_tests/shell/tst_check_kconfig01.sh | 26 +++++++++
 lib/newlib_tests/shell/tst_check_kconfig02.sh | 16 ++++++
 lib/newlib_tests/shell/tst_check_kconfig03.sh | 15 ++++++
 lib/newlib_tests/shell/tst_check_kconfig04.sh | 16 ++++++
 lib/newlib_tests/shell/tst_check_kconfig05.sh | 26 +++++++++
 testcases/lib/.gitignore                      |  1 +
 testcases/lib/Makefile                        |  3 +-
 testcases/lib/tst_check_kconfigs.c            | 18 +++++++
 testcases/lib/tst_test.sh                     | 35 ++++++++++++
 11 files changed, 195 insertions(+), 18 deletions(-)
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig04.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig05.sh
 create mode 100644 testcases/lib/tst_check_kconfigs.c

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index b993a9e1e..a1ec6ba2a 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -193,22 +193,25 @@ simply by setting right '$TST_NEEDS_FOO'.
 
 [options="header"]
 |=============================================================================
-| Variable name      | Action done
-| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
-|                    | Alternatively the 'tst_require_root' command can be used.
-| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
-| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
-                       device is stored in '$TST_DEVICE' variable.
-                       The option implies 'TST_NEEDS_TMPDIR'.
-| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
-                       the test (see below).
-| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
-| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
-| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
-                       or -1 (special value to disable timeout), default is 300.
-                       Variable is meant be set in tests, not by user.
-                       It's an equivalent of `tst_test.timeout` in C, can be set
-                       via 'tst_set_timeout(timeout)' after test has started.
+| Variable name            | Action done
+| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
+|                          | Alternatively the 'tst_require_root' command can be used.
+| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
+| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
+                             device is stored in '$TST_DEVICE' variable.
+                             The option implies 'TST_NEEDS_TMPDIR'.
+| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
+                             the test (see below).
+| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
+| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
+| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
+| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
+                             default value is comma.
+| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int >= 1,
+                             or -1 (special value to disable timeout), default is 300.
+                             Variable is meant be set in tests, not by user.
+                             It's an equivalent of `tst_test.timeout` in C, can be set
+                             via 'tst_set_timeout(timeout)' after test has started.
 |=============================================================================
 
 [options="header"]
@@ -742,3 +745,22 @@ TST_NEEDS_CHECKPOINTS=1
 Since both the implementations are compatible, it's also possible to start
 a child binary process from a shell test and synchronize with it. This process
 must have checkpoints initialized by calling 'tst_reinit()'.
+
+1.7 Parsing kernel .config
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The shell library provides an implementation of the kconfig parsing interface
+compatible with the C version.
+
+It's possible to pass kernel kconfig list for tst_require_kconfigs API with
+'$TST_NEEDS_KCONFIGS'.
+Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
+
+Now, we support the length of kconfig list is 10.
+
+-------------------------------------------------------------------------------
+#!/bin/sh
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
+
+. tst_test.sh
+-------------------------------------------------------------------------------
diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index 8b2fe347a..b34a582b7 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -6,7 +6,8 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
 tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
 tst_fuzzy_sync03 test_zero_hugepage.sh}"
 
-LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
+LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
+shell/tst_check_kconfig0[1-4].sh shell/net/*.sh}"
 
 cd $(dirname $0)
 PATH="$PWD/../../testcases/lib/:$PATH"
diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
new file mode 100755
index 000000000..90e76360e
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_GENERIC_IRQ_PROBE=y,
+CONFIG_GENERIC_IRQ_SHOW=y,
+CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y,
+CONFIG_GENERIC_PENDING_IRQ=y,
+CONFIG_GENERIC_IRQ_MIGRATION=y,
+CONFIG_IRQ_DOMAIN=y,
+CONFIG_IRQ_DOMAIN_HIERARCHY=y,
+CONFIG_GENERIC_MSI_IRQ=y,
+CONFIG_GENERIC_MSI_IRQ_DOMAIN=y,
+CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y,
+CONFIG_GENERIC_IRQ_RESERVATION_MODE=y"
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "kernel config check functionality only supports 10 kernel kconfigs"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
new file mode 100755
index 000000000..065a20fd2
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4"
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
new file mode 100755
index 000000000..ebdec70f8
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS: CONFIG_XFS_FS"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "invalid kconfig delimter"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
new file mode 100755
index 000000000..c5f046b79
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+TST_NEEDS_KCONFIGS_IFS=":"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TPASS "valid kconfig delimter"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig05.sh b/lib/newlib_tests/shell/tst_check_kconfig05.sh
new file mode 100755
index 000000000..1a214016a
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+. tst_test.sh
+
+do_test()
+{
+	tst_check_kconfigs "CONFIG_EXT4_FS"
+	if [ $? -eq 0 ]; then
+		tst_res TPASS "kernel .config has CONFIG_EXT4_fs"
+	else
+		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
+	fi
+
+	tst_check_kconfigs "CONFIG_EXT4"
+	if [ $? -eq 0 ]; then
+		tst_res TFAIL "kernel .config has CONFIG_EXT4"
+	else
+		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
+	fi
+}
+
+tst_run
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 9625d9043..c0d4dc851 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,4 +1,5 @@
 /tst_check_drivers
+/tst_check_kconfigs
 /tst_checkpoint
 /tst_device
 /tst_getconf
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index d6b4c7a91..f2de0c832 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -11,6 +11,7 @@ INSTALL_TARGETS		:= *.sh
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
-			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
+			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
+			   tst_check_kconfigs
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
new file mode 100644
index 000000000..5c387a62d
--- /dev/null
+++ b/testcases/lib/tst_check_kconfigs.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. */
+
+#include <stdio.h>
+#include "tst_kconfig.h"
+
+int main(int argc, const char *argv[])
+{
+	if (argc < 2) {
+		fprintf(stderr, "Please provide kernel kconfig list\n");
+		return 1;
+	}
+
+	if (tst_kconfig_check(argv+1))
+		return 1;
+
+	return 0;
+}
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 2556b28f5..0097c8d43 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -412,6 +412,37 @@ tst_require_drivers()
 	return 0
 }
 
+tst_require_kconfigs()
+{
+	[ $# -eq 0 ] && return 0
+
+	local kconfigs
+	local kconfig_i
+	local kconfig_max
+
+	kconfigs=$@
+	[ -z "$kconfigs" ] && return 0
+
+	tst_check_cmds cut tr wc
+	kconfig_max=$(( $(echo "$kconfigs" | tr -cd "$TST_NEEDS_KCONFIGS_IFS" | wc -c) +1))
+	if [ $kconfig_max -gt 10 ]; then
+		tst_brk TCONF "The max number of kconfig is 10!"
+	fi
+
+	for kconfig_i in $(seq $kconfig_max); do
+		eval "local kconfig$kconfig_i"
+		eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
+	done
+
+	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
+			$kconfig7 $kconfig8 $kconfig9 $kconfig10
+	if [ $? -ne 0 ]; then
+		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
+	fi
+
+	return 0
+}
+
 tst_is_int()
 {
 	[ "$1" -eq "$1" ] 2>/dev/null
@@ -587,6 +618,7 @@ tst_run()
 			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
 			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
 			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
+			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
 			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
 			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
 			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
@@ -627,6 +659,7 @@ tst_run()
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
 
 	tst_require_cmds $TST_NEEDS_CMDS
+	tst_require_kconfigs $TST_NEEDS_KCONFIGS
 	tst_require_drivers $TST_NEEDS_DRIVERS
 
 	if [ -n "$TST_MIN_KVER" ]; then
@@ -748,6 +781,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
 
 	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
 
+	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
+
 	if [ -n "$TST_CNT" ]; then
 		if ! tst_is_int "$TST_CNT"; then
 			tst_brk TBROK "TST_CNT must be integer"
-- 
2.23.0


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

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

* [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
  2022-01-06  9:25           ` [LTP] [PATCH v2 3/4] shell: add kconfig parse api Yang Xu
@ 2022-01-06  9:25           ` Yang Xu
  2022-01-06 11:20             ` Cyril Hrubis
  2022-01-06  9:54           ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Petr Vorel
  2022-01-06 10:57           ` Cyril Hrubis
  4 siblings, 1 reply; 74+ messages in thread
From: Yang Xu @ 2022-01-06  9:25 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/commands/sysctl/sysctl02.sh | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/testcases/commands/sysctl/sysctl02.sh b/testcases/commands/sysctl/sysctl02.sh
index 3964a9829..1c444268a 100755
--- a/testcases/commands/sysctl/sysctl02.sh
+++ b/testcases/commands/sysctl/sysctl02.sh
@@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
 TST_CNT=4
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl"
+TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
 sys_name="fs.file-max"
 sys_file="/proc/sys/fs/file-max"
-syms_file="/proc/kallsyms"
 
 . tst_test.sh
 
 setup()
 {
-	[ ! -f "$sys_file" ] && tst_brk TCONF "$sys_file not enabled"
 	orig_value=$(cat "$sys_file")
 }
 
@@ -61,17 +60,15 @@ sysctl_test_overflow()
 
 sysctl_test_zero()
 {
-	[ ! -f "$syms_file" ] && tst_brk TCONF "$syms_file not enabled"
+	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
+		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
+
 	ROD sysctl -w -q $sys_name=0
 
-	if grep -q kasan_report $syms_file; then
-		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
-			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
-		else
-			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
-		fi
+	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
+		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
 	else
-		tst_res TCONF "kernel doesn't support KASAN"
+		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
 	fi
 }
 
-- 
2.23.0


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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
@ 2022-01-06  9:49             ` Petr Vorel
  2022-01-06  9:52             ` Petr Vorel
  2022-01-06 11:07             ` Cyril Hrubis
  2 siblings, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-06  9:49 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

> diff --git a/doc/user-guide.txt b/doc/user-guide.txt
...
> +| 'LTP_KCONFIG_DISABLE' | Switch for kernel config check functionality.
> +                          'y' or '1': disable kconfig check,
> +                          'n' or '0': enable kconfig check.
Not sure if you got inspired by LTP_COLORIZE_OUTPUT, which also uses y/1 or n/0
input, but I'd really stick just to LTP_KCONFIG_DISABLE=1 to disable kconfig check.
By default kconfig check would be kept.

LTP_COLORIZE_OUTPUT has more complicated the default value, because it's on by
default when print to stderr, but off when redirected (we should document it in
doc/user-guide.txt). But there is no reason have way to configure the default
value.

But maybe others see it differently.

And writing it today I'd have probably chosen for LTP_KCONFIG_DISABLE only one:
y/n or 1/0.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
  2022-01-06  9:49             ` Petr Vorel
@ 2022-01-06  9:52             ` Petr Vorel
  2022-01-06 11:07             ` Cyril Hrubis
  2 siblings, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-06  9:52 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

> +| 'LTP_KCONFIG_DISABLE' | Switch for kernel config check functionality.
> +                          'y' or '1': disable kconfig check,
> +                          'n' or '0': enable kconfig check.
Also, regardless if we keep it this way,  it's worth to mention the default
value.

>  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.");
nit: please avoid the dot :).

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
                             ` (2 preceding siblings ...)
  2022-01-06  9:25           ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
@ 2022-01-06  9:54           ` Petr Vorel
  2022-01-06 10:57           ` Cyril Hrubis
  4 siblings, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-06  9:54 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Obviously OK.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-06  9:25           ` [LTP] [PATCH v2 3/4] shell: add kconfig parse api Yang Xu
@ 2022-01-06 10:40             ` Petr Vorel
  2022-01-06 11:19             ` Cyril Hrubis
  1 sibling, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-06 10:40 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

> +tst_require_kconfigs()
> +{
> +	[ $# -eq 0 ] && return 0
> +
> +	local kconfigs
> +	local kconfig_i
> +	local kconfig_max
> +
> +	kconfigs=$@

> +	[ -z "$kconfigs" ] && return 0
> +
> +	tst_check_cmds cut tr wc
> +	kconfig_max=$(( $(echo "$kconfigs" | tr -cd "$TST_NEEDS_KCONFIGS_IFS" | wc -c) +1))
> +	if [ $kconfig_max -gt 10 ]; then
> +		tst_brk TCONF "The max number of kconfig is 10!"
> +	fi
> +
> +	for kconfig_i in $(seq $kconfig_max); do
> +		eval "local kconfig$kconfig_i"
> +		eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
Well, we use 2x eval and cut in order to have easy C code. How about move
splitting string to C (using e.g. strtok_r()? Although using this code is
probably safe for any shell (we use similar cut like delimiter in tst_test.sh),
I've had enough of fixing obscure shell bugs. And C code with strtok_r() is more
portable across libc than any shell code.

> +	done
> +
> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
Now I see the need for the need to limit. First, you need to quote parameters:

	tst_check_kconfigs "$kconfig1" "$kconfig2" "$kconfig3" "$kconfig4" "$kconfig5" "$kconfig6" \
			"$kconfig7" "$kconfig8" "$kconfig9" "$kconfig10"

Because there might be config value with space. I found only one which is not
going to be used:
CONFIG_CC_VERSION_TEXT="gcc (SUSE Linux) 11.2.1 20211124 [revision 7510c23c1ec53aa4a62705f0384079661342ff7b]"
but we cannot rely on that.

Kind regards,
Petr

> +	if [ $? -ne 0 ]; then
> +		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
> +	fi
> +
> +	return 0
> +}

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

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

* Re: [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
                             ` (3 preceding siblings ...)
  2022-01-06  9:54           ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Petr Vorel
@ 2022-01-06 10:57           ` Cyril Hrubis
  2022-01-07  1:25             ` xuyang2018.jy
  4 siblings, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-06 10:57 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
> index d433b8cf6..dc7decff9 100644
> --- a/lib/tst_kconfig.c
> +++ b/lib/tst_kconfig.c
> @@ -478,22 +478,26 @@ static void dump_vars(const struct tst_expr *expr)
>  	}
>  }
>  
> -void tst_kconfig_check(const char *const kconfigs[])
> +int tst_kconfig_check(const char *const kconfigs[])
>  {
>  	size_t expr_cnt = array_len(kconfigs);
>  	struct tst_expr *exprs[expr_cnt];
>  	unsigned int i, var_cnt;
> -	int abort_test = 0;
> +	int ret = 0;
>  
>  	for (i = 0; i < expr_cnt; i++) {
>  		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
>  
> -		if (!exprs[i])
> -			tst_brk(TBROK, "Invalid kconfig expression!");
> +		if (!exprs[i]) {
> +			tst_res(TWARN, "Invalid kconfig expression!");
> +			return 1;
> +		}
>  	}
>  
> -	if (validate_vars(exprs, expr_cnt))
> -		tst_brk(TBROK, "Invalid kconfig variables!");
> +	if (validate_vars(exprs, expr_cnt)) {
> +		tst_res(TWARN, "Invalid kconfig variables!");
> +		return 1;
> +	}

I think that it would be actually better to keep the TBROK in these two
checks because neither of these two will trigger unless there is a typo
in the expressions and it makes sense to abort everything and stop in
these cases.

Other than that it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
  2022-01-06  9:49             ` Petr Vorel
  2022-01-06  9:52             ` Petr Vorel
@ 2022-01-06 11:07             ` Cyril Hrubis
  2022-01-06 11:50               ` Petr Vorel
  2 siblings, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-06 11:07 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> 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.

Maybe it would be better named LTP_KCONFIG_SKIP or even
KCONFIG_SKIP_CHECK we do have KCONFIG_PATH so it would make sense to
keep the kernel config related variables prefixed with just KCONFIG_

I think that the point made by Tim Bird was that the KCONFIG_PATH should
be standartized variable among testsuites, so it makes sense to have
KCONFIG_SKIP_CHECK as a standartized variable as well.

[CC: Tim should we start tracking common env variables like this somewhere?]

>  | '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;
> +}

As pointed out by Peter, can we please keep it simple? I.e. just branch
on variable defined/undefined?

>  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.");

I would try to make more clear what has happened here, something as:

"Skipping kernel config check as requested"

Or something along these lines.

> +		return 0;
> +	}
> +
>  	for (i = 0; i < expr_cnt; i++) {
>  		exprs[i] = tst_bool_expr_parse(kconfigs[i]);

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-06  9:25           ` [LTP] [PATCH v2 3/4] shell: add kconfig parse api Yang Xu
  2022-01-06 10:40             ` Petr Vorel
@ 2022-01-06 11:19             ` Cyril Hrubis
  2022-01-07  3:54               ` Li Wang
  1 sibling, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-06 11:19 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
> It introduces two variables in tst_test.sh
> TST_NEEDS_KCONFIGS
> TST_NEEDS_KCONFIGS_IFS (default value is comma)
> 
> Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
> case instead the whole test.
> 
> Fixes:#891
> Suggested-by: Petr Vorel <pvorel@suse.cz>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  doc/shell-test-api.txt                        | 54 +++++++++++++------
>  lib/newlib_tests/runtest.sh                   |  3 +-
>  lib/newlib_tests/shell/tst_check_kconfig01.sh | 26 +++++++++
>  lib/newlib_tests/shell/tst_check_kconfig02.sh | 16 ++++++
>  lib/newlib_tests/shell/tst_check_kconfig03.sh | 15 ++++++
>  lib/newlib_tests/shell/tst_check_kconfig04.sh | 16 ++++++
>  lib/newlib_tests/shell/tst_check_kconfig05.sh | 26 +++++++++
>  testcases/lib/.gitignore                      |  1 +
>  testcases/lib/Makefile                        |  3 +-
>  testcases/lib/tst_check_kconfigs.c            | 18 +++++++
>  testcases/lib/tst_test.sh                     | 35 ++++++++++++
>  11 files changed, 195 insertions(+), 18 deletions(-)
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig04.sh
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig05.sh
>  create mode 100644 testcases/lib/tst_check_kconfigs.c
> 
> diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
> index b993a9e1e..a1ec6ba2a 100644
> --- a/doc/shell-test-api.txt
> +++ b/doc/shell-test-api.txt
> @@ -193,22 +193,25 @@ simply by setting right '$TST_NEEDS_FOO'.
>  
>  [options="header"]
>  |=============================================================================
> -| Variable name      | Action done
> -| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
> -|                    | Alternatively the 'tst_require_root' command can be used.
> -| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
> -| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
> -                       device is stored in '$TST_DEVICE' variable.
> -                       The option implies 'TST_NEEDS_TMPDIR'.
> -| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
> -                       the test (see below).
> -| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
> -| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
> -| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
> -                       or -1 (special value to disable timeout), default is 300.
> -                       Variable is meant be set in tests, not by user.
> -                       It's an equivalent of `tst_test.timeout` in C, can be set
> -                       via 'tst_set_timeout(timeout)' after test has started.
> +| Variable name            | Action done
> +| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
> +|                          | Alternatively the 'tst_require_root' command can be used.
> +| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
> +| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
> +                             device is stored in '$TST_DEVICE' variable.
> +                             The option implies 'TST_NEEDS_TMPDIR'.
> +| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
> +                             the test (see below).
> +| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
> +| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
> +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
> +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
> +                             default value is comma.
> +| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int >= 1,
> +                             or -1 (special value to disable timeout), default is 300.
> +                             Variable is meant be set in tests, not by user.
> +                             It's an equivalent of `tst_test.timeout` in C, can be set
> +                             via 'tst_set_timeout(timeout)' after test has started.
>  |=============================================================================
>  
>  [options="header"]
> @@ -742,3 +745,22 @@ TST_NEEDS_CHECKPOINTS=1
>  Since both the implementations are compatible, it's also possible to start
>  a child binary process from a shell test and synchronize with it. This process
>  must have checkpoints initialized by calling 'tst_reinit()'.
> +
> +1.7 Parsing kernel .config
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +The shell library provides an implementation of the kconfig parsing interface
> +compatible with the C version.
> +
> +It's possible to pass kernel kconfig list for tst_require_kconfigs API with
> +'$TST_NEEDS_KCONFIGS'.
> +Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
> +
> +Now, we support the length of kconfig list is 10.
> +
> +-------------------------------------------------------------------------------
> +#!/bin/sh
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
> +
> +. tst_test.sh
> +-------------------------------------------------------------------------------
> diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
> index 8b2fe347a..b34a582b7 100755
> --- a/lib/newlib_tests/runtest.sh
> +++ b/lib/newlib_tests/runtest.sh
> @@ -6,7 +6,8 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
>  tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
>  tst_fuzzy_sync03 test_zero_hugepage.sh}"
>  
> -LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
> +LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
> +shell/tst_check_kconfig0[1-4].sh shell/net/*.sh}"
>  
>  cd $(dirname $0)
>  PATH="$PWD/../../testcases/lib/:$PATH"
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
> new file mode 100755
> index 000000000..90e76360e
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_GENERIC_IRQ_PROBE=y,
> +CONFIG_GENERIC_IRQ_SHOW=y,
> +CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y,
> +CONFIG_GENERIC_PENDING_IRQ=y,
> +CONFIG_GENERIC_IRQ_MIGRATION=y,
> +CONFIG_IRQ_DOMAIN=y,
> +CONFIG_IRQ_DOMAIN_HIERARCHY=y,
> +CONFIG_GENERIC_MSI_IRQ=y,
> +CONFIG_GENERIC_MSI_IRQ_DOMAIN=y,
> +CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y,
> +CONFIG_GENERIC_IRQ_RESERVATION_MODE=y"
> +
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TFAIL "kernel config check functionality only supports 10 kernel kconfigs"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
> new file mode 100755
> index 000000000..065a20fd2
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4"
> +
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
> new file mode 100755
> index 000000000..ebdec70f8
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS: CONFIG_XFS_FS"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TFAIL "invalid kconfig delimter"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
> new file mode 100755
> index 000000000..c5f046b79
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
> +TST_NEEDS_KCONFIGS_IFS=":"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TPASS "valid kconfig delimter"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig05.sh b/lib/newlib_tests/shell/tst_check_kconfig05.sh
> new file mode 100755
> index 000000000..1a214016a
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_check_kconfigs "CONFIG_EXT4_FS"
> +	if [ $? -eq 0 ]; then
> +		tst_res TPASS "kernel .config has CONFIG_EXT4_fs"
> +	else
> +		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
> +	fi
> +
> +	tst_check_kconfigs "CONFIG_EXT4"
> +	if [ $? -eq 0 ]; then
> +		tst_res TFAIL "kernel .config has CONFIG_EXT4"
> +	else
> +		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
> +	fi
> +}
> +
> +tst_run
> diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
> index 9625d9043..c0d4dc851 100644
> --- a/testcases/lib/.gitignore
> +++ b/testcases/lib/.gitignore
> @@ -1,4 +1,5 @@
>  /tst_check_drivers
> +/tst_check_kconfigs
>  /tst_checkpoint
>  /tst_device
>  /tst_getconf
> diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
> index d6b4c7a91..f2de0c832 100644
> --- a/testcases/lib/Makefile
> +++ b/testcases/lib/Makefile
> @@ -11,6 +11,7 @@ INSTALL_TARGETS		:= *.sh
>  MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
>  			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
>  			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
> -			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
> +			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
> +			   tst_check_kconfigs
>  
>  include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
> new file mode 100644
> index 000000000..5c387a62d
> --- /dev/null
> +++ b/testcases/lib/tst_check_kconfigs.c
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. */
> +
> +#include <stdio.h>
> +#include "tst_kconfig.h"
> +
> +int main(int argc, const char *argv[])
> +{
> +	if (argc < 2) {
> +		fprintf(stderr, "Please provide kernel kconfig list\n");
> +		return 1;
> +	}
> +
> +	if (tst_kconfig_check(argv+1))
> +		return 1;
> +
> +	return 0;
> +}
> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 2556b28f5..0097c8d43 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -412,6 +412,37 @@ tst_require_drivers()
>  	return 0
>  }
>  
> +tst_require_kconfigs()
> +{
> +	[ $# -eq 0 ] && return 0
> +
> +	local kconfigs
> +	local kconfig_i
> +	local kconfig_max
> +
> +	kconfigs=$@
> +	[ -z "$kconfigs" ] && return 0
> +
> +	tst_check_cmds cut tr wc
> +	kconfig_max=$(( $(echo "$kconfigs" | tr -cd "$TST_NEEDS_KCONFIGS_IFS" | wc -c) +1))
> +	if [ $kconfig_max -gt 10 ]; then
> +		tst_brk TCONF "The max number of kconfig is 10!"
> +	fi

There is really no reason to have this artificial limit if we are not
passing the configs in a set of variables.

> +	for kconfig_i in $(seq $kconfig_max); do
> +		eval "local kconfig$kconfig_i"
> +		eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
> +	done

This part is a bit ugly, I guess that it may as well be easier to
process in C. A long as we pass it as:

tst_check_kconfigs "$TST_NEEDS_KCONFIGS_IFS" "$TST_NEEDS_KCONFIGS"

We can easily split the TST_NEEDS_KCONFIGS with strchr() and single
loop.

> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
> +	if [ $? -ne 0 ]; then
> +		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
> +	fi
> +
> +	return 0
> +}
> +
>  tst_is_int()
>  {
>  	[ "$1" -eq "$1" ] 2>/dev/null
> @@ -587,6 +618,7 @@ tst_run()
>  			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
>  			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
>  			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
> +			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
>  			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
>  			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
>  			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
> @@ -627,6 +659,7 @@ tst_run()
>  	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
>  
>  	tst_require_cmds $TST_NEEDS_CMDS
> +	tst_require_kconfigs $TST_NEEDS_KCONFIGS
>  	tst_require_drivers $TST_NEEDS_DRIVERS
>  
>  	if [ -n "$TST_MIN_KVER" ]; then
> @@ -748,6 +781,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
>  
>  	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
>  
> +	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
> +
>  	if [ -n "$TST_CNT" ]; then
>  		if ! tst_is_int "$TST_CNT"; then
>  			tst_brk TBROK "TST_CNT must be integer"
> -- 
> 2.23.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-06  9:25           ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
@ 2022-01-06 11:20             ` Cyril Hrubis
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-10  5:45               ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api xuyang2018.jy
  0 siblings, 2 replies; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-06 11:20 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> @@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
>  TST_CNT=4
>  TST_NEEDS_ROOT=1
>  TST_NEEDS_CMDS="sysctl"
> +TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"

Is there a good reason to check for PROC_FS? I doubt that modern system
without CONFIG_PROC_FS will even boot.

>  sys_name="fs.file-max"
>  sys_file="/proc/sys/fs/file-max"
> -syms_file="/proc/kallsyms"
>  
>  . tst_test.sh
>  
>  setup()
>  {
> -	[ ! -f "$sys_file" ] && tst_brk TCONF "$sys_file not enabled"
>  	orig_value=$(cat "$sys_file")
>  }
>  
> @@ -61,17 +60,15 @@ sysctl_test_overflow()
>  
>  sysctl_test_zero()
>  {
> -	[ ! -f "$syms_file" ] && tst_brk TCONF "$syms_file not enabled"
> +	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
> +		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
> +
>  	ROD sysctl -w -q $sys_name=0
>  
> -	if grep -q kasan_report $syms_file; then
> -		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
> -			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
> -		else
> -			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
> -		fi
> +	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
> +		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
>  	else
> -		tst_res TCONF "kernel doesn't support KASAN"
> +		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
>  	fi
>  }
>  
> -- 
> 2.23.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06 11:07             ` Cyril Hrubis
@ 2022-01-06 11:50               ` Petr Vorel
  2022-01-06 13:59                 ` Cyril Hrubis
  0 siblings, 1 reply; 74+ messages in thread
From: Petr Vorel @ 2022-01-06 11:50 UTC (permalink / raw)
  To: Yang Xu, Cyril Hrubis; +Cc: ltp

Hi Xu, Cyril,

> Hi!
> > 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.

> Maybe it would be better named LTP_KCONFIG_SKIP or even
> KCONFIG_SKIP_CHECK we do have KCONFIG_PATH so it would make sense to
> keep the kernel config related variables prefixed with just KCONFIG_

> I think that the point made by Tim Bird was that the KCONFIG_PATH should
> be standartized variable among testsuites, so it makes sense to have
> KCONFIG_SKIP_CHECK as a standartized variable as well.

Is it too bad to have LTP_KCONFIG_SKIP_CHECK and LTP_KCONFIG_PATH ?
Maybe we could change it even now.

OK, we have few exceptions to LTP_ prefix LTPROOT (I'd keep it for historical
reasons), TMPDIR (IMHO make sense), TST_NO_CLEANUP (IMHO should be changed to
LTP_NO_CLEANUP).

> [CC: Tim should we start tracking common env variables like this somewhere?]
+1

> > +	if (tst_kconfig_disabled()) {
> > +		tst_res(TINFO, "Kernel config check functionality has been disabled.");

> I would try to make more clear what has happened here, something as:

> "Skipping kernel config check as requested"
+1

> Or something along these lines.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06 11:50               ` Petr Vorel
@ 2022-01-06 13:59                 ` Cyril Hrubis
  2022-01-06 17:41                   ` Petr Vorel
  2022-01-07  2:00                   ` xuyang2018.jy
  0 siblings, 2 replies; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-06 13:59 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> > > 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.
> 
> > Maybe it would be better named LTP_KCONFIG_SKIP or even
> > KCONFIG_SKIP_CHECK we do have KCONFIG_PATH so it would make sense to
> > keep the kernel config related variables prefixed with just KCONFIG_
> 
> > I think that the point made by Tim Bird was that the KCONFIG_PATH should
> > be standartized variable among testsuites, so it makes sense to have
> > KCONFIG_SKIP_CHECK as a standartized variable as well.
> 
> Is it too bad to have LTP_KCONFIG_SKIP_CHECK and LTP_KCONFIG_PATH ?
> Maybe we could change it even now.

Yes, the whole reason not to prefix it with LTP_ is to have a standard
among all the testsuites. The more variables are standartized the
better.

> TST_NO_CLEANUP (IMHO should be changed to LTP_NO_CLEANUP).

Unless we want to have a standard for that one as well. Really all we
need to is to create a page with the description of these variables and
agree on a common subset. It's that simple, but someone has to actually
do it.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06 13:59                 ` Cyril Hrubis
@ 2022-01-06 17:41                   ` Petr Vorel
  2022-01-07  2:00                   ` xuyang2018.jy
  1 sibling, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-06 17:41 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi all,

> Hi!
> > > > 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.

> > > Maybe it would be better named LTP_KCONFIG_SKIP or even
> > > KCONFIG_SKIP_CHECK we do have KCONFIG_PATH so it would make sense to
> > > keep the kernel config related variables prefixed with just KCONFIG_

> > > I think that the point made by Tim Bird was that the KCONFIG_PATH should
> > > be standartized variable among testsuites, so it makes sense to have
> > > KCONFIG_SKIP_CHECK as a standartized variable as well.

> > Is it too bad to have LTP_KCONFIG_SKIP_CHECK and LTP_KCONFIG_PATH ?
> > Maybe we could change it even now.

> Yes, the whole reason not to prefix it with LTP_ is to have a standard
> among all the testsuites. The more variables are standartized the
> better.

Ah, thanks, I wasn't aware of this agreement.

> > TST_NO_CLEANUP (IMHO should be changed to LTP_NO_CLEANUP).

> Unless we want to have a standard for that one as well. Really all we
> need to is to create a page with the description of these variables and
> agree on a common subset. It's that simple, but someone has to actually
> do it.

I thought this is the page for user defined variables:
https://github.com/linux-test-project/ltp/wiki/User-Guidelines

But we should explain there the exceptions.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-06 10:57           ` Cyril Hrubis
@ 2022-01-07  1:25             ` xuyang2018.jy
  0 siblings, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-07  1:25 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
>> index d433b8cf6..dc7decff9 100644
>> --- a/lib/tst_kconfig.c
>> +++ b/lib/tst_kconfig.c
>> @@ -478,22 +478,26 @@ static void dump_vars(const struct tst_expr *expr)
>>   	}
>>   }
>>
>> -void tst_kconfig_check(const char *const kconfigs[])
>> +int tst_kconfig_check(const char *const kconfigs[])
>>   {
>>   	size_t expr_cnt = array_len(kconfigs);
>>   	struct tst_expr *exprs[expr_cnt];
>>   	unsigned int i, var_cnt;
>> -	int abort_test = 0;
>> +	int ret = 0;
>>
>>   	for (i = 0; i<  expr_cnt; i++) {
>>   		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
>>
>> -		if (!exprs[i])
>> -			tst_brk(TBROK, "Invalid kconfig expression!");
>> +		if (!exprs[i]) {
>> +			tst_res(TWARN, "Invalid kconfig expression!");
>> +			return 1;
>> +		}
>>   	}
>>
>> -	if (validate_vars(exprs, expr_cnt))
>> -		tst_brk(TBROK, "Invalid kconfig variables!");
>> +	if (validate_vars(exprs, expr_cnt)) {
>> +		tst_res(TWARN, "Invalid kconfig variables!");
>> +		return 1;
>> +	}
>
> I think that it would be actually better to keep the TBROK in these two
> checks because neither of these two will trigger unless there is a typo
> in the expressions and it makes sense to abort everything and stop in
> these cases.
Sounds reasonable, will do it.

Best Regards
Yang Xu
>
> Other than that it looks good.
>

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

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

* Re: [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables
  2022-01-06 13:59                 ` Cyril Hrubis
  2022-01-06 17:41                   ` Petr Vorel
@ 2022-01-07  2:00                   ` xuyang2018.jy
  1 sibling, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-07  2:00 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>>>> 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.
>>
>>> Maybe it would be better named LTP_KCONFIG_SKIP or even
>>> KCONFIG_SKIP_CHECK we do have KCONFIG_PATH so it would make sense to
>>> keep the kernel config related variables prefixed with just KCONFIG_
>>
>>> I think that the point made by Tim Bird was that the KCONFIG_PATH should
>>> be standartized variable among testsuites, so it makes sense to have
>>> KCONFIG_SKIP_CHECK as a standartized variable as well.
>>
>> Is it too bad to have LTP_KCONFIG_SKIP_CHECK and LTP_KCONFIG_PATH ?
>> Maybe we could change it even now.
>
> Yes, the whole reason not to prefix it with LTP_ is to have a standard
> among all the testsuites. The more variables are standartized the
> better.
This make me remember xfstests  testsuite also has KCONFIG_PATH 
environment variable.

I will use KCONFIG_SKIP_CHECK name firstly, Unless Tim objects(may know 
  other testsuite has used KCONFIG_ environment variable ) or has a 
better naming method.

Best Regards
Yang Xu
>
>> TST_NO_CLEANUP (IMHO should be changed to LTP_NO_CLEANUP).
>
> Unless we want to have a standard for that one as well. Really all we
> need to is to create a page with the description of these variables and
> agree on a common subset. It's that simple, but someone has to actually
> do it.
>

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-06 11:19             ` Cyril Hrubis
@ 2022-01-07  3:54               ` Li Wang
  2022-01-07  4:08                 ` xuyang2018.jy
  2022-01-07  7:33                 ` Petr Vorel
  0 siblings, 2 replies; 74+ messages in thread
From: Li Wang @ 2022-01-07  3:54 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: LTP List

Hi all,

On Thu, Jan 6, 2022 at 7:17 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> > +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).

> > +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
> > +                             default value is comma.


> > +     for kconfig_i in $(seq $kconfig_max); do
> > +             eval "local kconfig$kconfig_i"
> > +             eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
> > +     done
>
> This part is a bit ugly, I guess that it may as well be easier to
> process in C. A long as we pass it as:
>
> tst_check_kconfigs "$TST_NEEDS_KCONFIGS_IFS" "$TST_NEEDS_KCONFIGS"
>
> We can easily split the TST_NEEDS_KCONFIGS with strchr() and single
> loop.

+1

I even don't think we need that 'TST_NEEDS_KCONFIGS_IFS'
variable for users. More flexible means more complicated to some
degree, if achieve a C process,  we can handle that by accepting
whatever the delimiter.

But strictly usage with a comma is enough for current kernel configs
parsing I guess.

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  3:54               ` Li Wang
@ 2022-01-07  4:08                 ` xuyang2018.jy
  2022-01-07  7:04                   ` Li Wang
  2022-01-07  7:33                 ` Petr Vorel
  1 sibling, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-07  4:08 UTC (permalink / raw)
  To: Li Wang, Cyril Hrubis, Petr Vorel; +Cc: LTP List

Hi Li, Cyril, Petr
> Hi all,
>
> On Thu, Jan 6, 2022 at 7:17 PM Cyril Hrubis<chrubis@suse.cz>  wrote:
>
>>> +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
>
>>> +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
>>> +                             default value is comma.
>
>
>>> +     for kconfig_i in $(seq $kconfig_max); do
>>> +             eval "local kconfig$kconfig_i"
>>> +             eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
>>> +     done
>>
>> This part is a bit ugly, I guess that it may as well be easier to
>> process in C. A long as we pass it as:
>>
>> tst_check_kconfigs "$TST_NEEDS_KCONFIGS_IFS" "$TST_NEEDS_KCONFIGS"
>>
>> We can easily split the TST_NEEDS_KCONFIGS with strchr() and single
>> loop.
>
> +1
>
In fact, I used the c code(use strtok_r) in the beginning when I wrote 
this patch
code as below:

// SPDX-License-Identifier: GPL-2.0-or-later
/* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/

#include <stdio.h>
#include <string.h>
#include "tst_kconfig.h"


int main(int argc, const char *argv[])
{
         char delims[] = ",";
         char kconfig[PATH_MAX];
         char str[PATH_MAX];
         char *result = NULL;
         char *next = NULL;
         int i = 0;

         if (argc < 2) {
                 fprintf(stderr, "Please provide kernel kconfig list\n");
                 return 1;
         }

         strcpy(str, argv[1]);
         result = strtok_r(str, delims, &next);

         while (result != NULL) {
                 strcpy(kconfig, result);
                 printf("%s %s %d\n", kconfig,result, i);
                 const char *const kconfigs[] = {
                         kconfig,
                         NULL
                 };
                 if (tst_kconfig_check(kconfigs)) {
                          fprintf(stderr, "Kernel config doesn't meet 
test's requirement!\n");
                          return 1;
                 }

                 i++;
                 result = strtok_r(NULL, delims, &next);
         }

         return 0;
}

But it must call tst_kconfig_check for every kconfig expression and 
print many info "Parsing kernel config ..." because we need to create a 
NULL terminated array for  tst_kconfig_check.

It seems also increase calculated complexity...

That is why I switch to filter them in shell.

If you want to use C, I will swich to use C for filter strings.
> I even don't think we need that 'TST_NEEDS_KCONFIGS_IFS'
> variable for users. More flexible means more complicated to some
> degree, if achieve a C process,  we can handle that by accepting
> whatever the delimiter.
>
> But strictly usage with a comma is enough for current kernel configs
> parsing I guess.
+1

Best Regards
Yang Xu
>

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  4:08                 ` xuyang2018.jy
@ 2022-01-07  7:04                   ` Li Wang
  2022-01-07  8:28                     ` xuyang2018.jy
  0 siblings, 1 reply; 74+ messages in thread
From: Li Wang @ 2022-01-07  7:04 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: LTP List

xuyang2018.jy@fujitsu.com <xuyang2018.jy@fujitsu.com> wrote:

> // SPDX-License-Identifier: GPL-2.0-or-later
> /* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/
>
> #include <stdio.h>
> #include <string.h>
> #include "tst_kconfig.h"
>
>
> int main(int argc, const char *argv[])
> {
>          char delims[] = ",";
>          char kconfig[PATH_MAX];
>          char str[PATH_MAX];
>          char *result = NULL;
>          char *next = NULL;
>          int i = 0;
>
>          if (argc < 2) {
>                  fprintf(stderr, "Please provide kernel kconfig list\n");
>                  return 1;
>          }
>
>          strcpy(str, argv[1]);
>          result = strtok_r(str, delims, &next);
>
>          while (result != NULL) {
>                  strcpy(kconfig, result);
>                  printf("%s %s %d\n", kconfig,result, i);
>                  const char *const kconfigs[] = {
>                          kconfig,
>                          NULL
>                  };
>                  if (tst_kconfig_check(kconfigs)) {
>                           fprintf(stderr, "Kernel config doesn't meet
> test's requirement!\n");
>                           return 1;
>                  }
>
>                  i++;
>                  result = strtok_r(NULL, delims, &next);
>          }
>
>          return 0;
> }
>
> But it must call tst_kconfig_check for every kconfig expression and
> print many info "Parsing kernel config ..." because we need to create a
> NULL terminated array for  tst_kconfig_check.

Maybe we can combine the arguments into one kconfigs struct and
just do once check? something like:

---------------------------
        strcpy(str, argv[1]);
        result = strtok_r(str, delims, &next);

        const char *kconfigs[64];

        for (i = 0; result != NULL; i++) {
                kconfigs[i] = result;
                result = strtok_r(NULL, delims, &next);
        }

        kconfigs[++i] = NULL;

        if (tst_kconfig_check(kconfigs)) {
                fprintf(stderr, "Kernel config doesn't meet test's
requirement!\n");
                return 1;
        }
        ...



-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  3:54               ` Li Wang
  2022-01-07  4:08                 ` xuyang2018.jy
@ 2022-01-07  7:33                 ` Petr Vorel
  1 sibling, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-07  7:33 UTC (permalink / raw)
  To: Li Wang; +Cc: LTP List

> Hi all,

> On Thu, Jan 6, 2022 at 7:17 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> > > +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).

> > > +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
> > > +                             default value is comma.


> > > +     for kconfig_i in $(seq $kconfig_max); do
> > > +             eval "local kconfig$kconfig_i"
> > > +             eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
> > > +     done

> > This part is a bit ugly, I guess that it may as well be easier to
> > process in C. A long as we pass it as:

> > tst_check_kconfigs "$TST_NEEDS_KCONFIGS_IFS" "$TST_NEEDS_KCONFIGS"

> > We can easily split the TST_NEEDS_KCONFIGS with strchr() and single
> > loop.

> +1

> I even don't think we need that 'TST_NEEDS_KCONFIGS_IFS'
> variable for users. More flexible means more complicated to some
> degree, if achieve a C process,  we can handle that by accepting
> whatever the delimiter.
I suppose any string can be part of kconfig, thus it'd be safer to be able to
redefine delimiter. But yes, TST_NEEDS_KCONFIGS_IFS should be for using in tests
(thus TST_ prefix).

Kind regards,
Petr

> But strictly usage with a comma is enough for current kernel configs
> parsing I guess.

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  7:04                   ` Li Wang
@ 2022-01-07  8:28                     ` xuyang2018.jy
  2022-01-07  8:41                       ` Li Wang
  2022-01-07  9:05                       ` Petr Vorel
  0 siblings, 2 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-07  8:28 UTC (permalink / raw)
  To: Li Wang; +Cc: LTP List

Hi Li
> xuyang2018.jy@fujitsu.com<xuyang2018.jy@fujitsu.com>  wrote:
>
>> // SPDX-License-Identifier: GPL-2.0-or-later
>> /* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/
>>
>> #include<stdio.h>
>> #include<string.h>
>> #include "tst_kconfig.h"
>>
>>
>> int main(int argc, const char *argv[])
>> {
>>           char delims[] = ",";
>>           char kconfig[PATH_MAX];
>>           char str[PATH_MAX];
>>           char *result = NULL;
>>           char *next = NULL;
>>           int i = 0;
>>
>>           if (argc<  2) {
>>                   fprintf(stderr, "Please provide kernel kconfig list\n");
>>                   return 1;
>>           }
>>
>>           strcpy(str, argv[1]);
>>           result = strtok_r(str, delims,&next);
>>
>>           while (result != NULL) {
>>                   strcpy(kconfig, result);
>>                   printf("%s %s %d\n", kconfig,result, i);
>>                   const char *const kconfigs[] = {
>>                           kconfig,
>>                           NULL
>>                   };
>>                   if (tst_kconfig_check(kconfigs)) {
>>                            fprintf(stderr, "Kernel config doesn't meet
>> test's requirement!\n");
>>                            return 1;
>>                   }
>>
>>                   i++;
>>                   result = strtok_r(NULL, delims,&next);
>>           }
>>
>>           return 0;
>> }
>>
>> But it must call tst_kconfig_check for every kconfig expression and
>> print many info "Parsing kernel config ..." because we need to create a
>> NULL terminated array for  tst_kconfig_check.
>
> Maybe we can combine the arguments into one kconfigs struct and
> just do once check? something like:
Yes, it works well. Thanks.

I checked the kernel config, it seems comma can not meet the CONFIG_LSM 
situation (Petr mention it but I don't notice before).
CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"

so I think we may TST_NEEDS_KCONFIGS_IFS variable and default value is 
comma.

Best Regards
Yang Xu
>
> ---------------------------
>          strcpy(str, argv[1]);
>          result = strtok_r(str, delims,&next);
>
>          const char *kconfigs[64];
>
>          for (i = 0; result != NULL; i++) {
>                  kconfigs[i] = result;
>                  result = strtok_r(NULL, delims,&next);
>          }
>
>          kconfigs[++i] = NULL;
>
>          if (tst_kconfig_check(kconfigs)) {
>                  fprintf(stderr, "Kernel config doesn't meet test's
> requirement!\n");
>                  return 1;
>          }
>          ...
>
>
>

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  8:28                     ` xuyang2018.jy
@ 2022-01-07  8:41                       ` Li Wang
  2022-01-07  9:46                         ` Cyril Hrubis
  2022-01-07  9:05                       ` Petr Vorel
  1 sibling, 1 reply; 74+ messages in thread
From: Li Wang @ 2022-01-07  8:41 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: LTP List

Hi Petr, Xu,

> > Maybe we can combine the arguments into one kconfigs struct and
> > just do once check? something like:
> Yes, it works well. Thanks.

Btw, seems const char *kconfigs[64] is not enough for a long
string combination, you can dynamically allocate memory
according to arguments size. Or, just raise to a big number.

>
> I checked the kernel config, it seems comma can not meet the CONFIG_LSM
> situation (Petr mention it but I don't notice before).
> CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"
>
> so I think we may TST_NEEDS_KCONFIGS_IFS variable and default value is
> comma.

Ok, I'm fine to keep that, and thanks for the instance.

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  8:28                     ` xuyang2018.jy
  2022-01-07  8:41                       ` Li Wang
@ 2022-01-07  9:05                       ` Petr Vorel
  2022-01-07  9:22                         ` xuyang2018.jy
  1 sibling, 1 reply; 74+ messages in thread
From: Petr Vorel @ 2022-01-07  9:05 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: LTP List

Hi all,

> >> int main(int argc, const char *argv[])
> >> {
> >>           char delims[] = ",";
> >>           char kconfig[PATH_MAX];
> >>           char str[PATH_MAX];
> >>           char *result = NULL;
> >>           char *next = NULL;
> >>           int i = 0;

> >>           if (argc<  2) {
> >>                   fprintf(stderr, "Please provide kernel kconfig list\n");
> >>                   return 1;
> >>           }

> >>           strcpy(str, argv[1]);
> >>           result = strtok_r(str, delims,&next);

> >>           while (result != NULL) {
> >>                   strcpy(kconfig, result);
> >>                   printf("%s %s %d\n", kconfig,result, i);
> >>                   const char *const kconfigs[] = {
> >>                           kconfig,
> >>                           NULL
> >>                   };
> >>                   if (tst_kconfig_check(kconfigs)) {
> >>                            fprintf(stderr, "Kernel config doesn't meet
> >> test's requirement!\n");
> >>                            return 1;
> >>                   }

> >>                   i++;
> >>                   result = strtok_r(NULL, delims,&next);
> >>           }

> >>           return 0;
> >> }

> >> But it must call tst_kconfig_check for every kconfig expression and
> >> print many info "Parsing kernel config ..." because we need to create a
> >> NULL terminated array for  tst_kconfig_check.

> > Maybe we can combine the arguments into one kconfigs struct and
> > just do once check? something like:
> Yes, it works well. Thanks.

LGTM. NOTE: Cyril suggested strchr() with loop, maybe he thought about even
simpler solution.

> I checked the kernel config, it seems comma can not meet the CONFIG_LSM 
> situation (Petr mention it but I don't notice before).
> CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"

> so I think we may TST_NEEDS_KCONFIGS_IFS variable and default value is 
> comma.
Maybe use '|' as the default? That's very unlikely to be used
(but I'd still have TST_NEEDS_KCONFIGS_IFS).

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  9:05                       ` Petr Vorel
@ 2022-01-07  9:22                         ` xuyang2018.jy
  2022-01-07 12:07                           ` Petr Vorel
  0 siblings, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-07  9:22 UTC (permalink / raw)
  To: Petr Vorel; +Cc: LTP List

Hi Petr
> Hi all,
>
>>>> int main(int argc, const char *argv[])
>>>> {
>>>>            char delims[] = ",";
>>>>            char kconfig[PATH_MAX];
>>>>            char str[PATH_MAX];
>>>>            char *result = NULL;
>>>>            char *next = NULL;
>>>>            int i = 0;
>
>>>>            if (argc<   2) {
>>>>                    fprintf(stderr, "Please provide kernel kconfig list\n");
>>>>                    return 1;
>>>>            }
>
>>>>            strcpy(str, argv[1]);
>>>>            result = strtok_r(str, delims,&next);
>
>>>>            while (result != NULL) {
>>>>                    strcpy(kconfig, result);
>>>>                    printf("%s %s %d\n", kconfig,result, i);
>>>>                    const char *const kconfigs[] = {
>>>>                            kconfig,
>>>>                            NULL
>>>>                    };
>>>>                    if (tst_kconfig_check(kconfigs)) {
>>>>                             fprintf(stderr, "Kernel config doesn't meet
>>>> test's requirement!\n");
>>>>                             return 1;
>>>>                    }
>
>>>>                    i++;
>>>>                    result = strtok_r(NULL, delims,&next);
>>>>            }
>
>>>>            return 0;
>>>> }
>
>>>> But it must call tst_kconfig_check for every kconfig expression and
>>>> print many info "Parsing kernel config ..." because we need to create a
>>>> NULL terminated array for  tst_kconfig_check.
>
>>> Maybe we can combine the arguments into one kconfigs struct and
>>> just do once check? something like:
>> Yes, it works well. Thanks.
>
> LGTM. NOTE: Cyril suggested strchr() with loop, maybe he thought about even
> simpler solution.
>
>> I checked the kernel config, it seems comma can not meet the CONFIG_LSM
>> situation (Petr mention it but I don't notice before).
>> CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"
>
>> so I think we may TST_NEEDS_KCONFIGS_IFS variable and default value is
>> comma.
> Maybe use '|' as the default? That's very unlikely to be used
> (but I'd still have TST_NEEDS_KCONFIGS_IFS).
No, look test_kconfig01.c, we use '|' for a valid or operation.

Best Rgards
Yang Xu
>
> Kind regards,
> Petr

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  8:41                       ` Li Wang
@ 2022-01-07  9:46                         ` Cyril Hrubis
  2022-01-07  9:56                           ` xuyang2018.jy
  0 siblings, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-07  9:46 UTC (permalink / raw)
  To: Li Wang; +Cc: LTP List

Hi!
> > > Maybe we can combine the arguments into one kconfigs struct and
> > > just do once check? something like:
> > Yes, it works well. Thanks.
> 
> Btw, seems const char *kconfigs[64] is not enough for a long
> string combination, you can dynamically allocate memory
> according to arguments size. Or, just raise to a big number.

Just loop over the string twice and count the occurencens of IFS
character in the first loop.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  9:46                         ` Cyril Hrubis
@ 2022-01-07  9:56                           ` xuyang2018.jy
  0 siblings, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-07  9:56 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: LTP List

Hi!
> Hi!
>>>> Maybe we can combine the arguments into one kconfigs struct and
>>>> just do once check? something like:
>>> Yes, it works well. Thanks.
>>
>> Btw, seems const char *kconfigs[64] is not enough for a long
>> string combination, you can dynamically allocate memory
>> according to arguments size. Or, just raise to a big number.
>
> Just loop over the string twice and count the occurencens of IFS
> character in the first loop.
Yes.

All,  I have rewrited this patchset, I will send a v3 on next Monday.

Best Regards
Yang Xu
>

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

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

* Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
  2022-01-07  9:22                         ` xuyang2018.jy
@ 2022-01-07 12:07                           ` Petr Vorel
  0 siblings, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-07 12:07 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: LTP List

Hi all,

...
> >> so I think we may TST_NEEDS_KCONFIGS_IFS variable and default value is
> >> comma.
> > Maybe use '|' as the default? That's very unlikely to be used
> > (but I'd still have TST_NEEDS_KCONFIGS_IFS).
> No, look test_kconfig01.c, we use '|' for a valid or operation.
Ah, correct. Then comma as the default is probably the best.

Kind regards,
Petr

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

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

* [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-06 11:20             ` Cyril Hrubis
@ 2022-01-10  1:49               ` Yang Xu
  2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
                                   ` (4 more replies)
  2022-01-10  5:45               ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api xuyang2018.jy
  1 sibling, 5 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-10  1:49 UTC (permalink / raw)
  To: ltp

So this function can be used to detect whether the function succeeded in shell
api by its return value.

Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/tst_kconfig.h | 5 +++--
 lib/tst_kconfig.c     | 9 ++++-----
 lib/tst_test.c        | 4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/tst_kconfig.h b/include/tst_kconfig.h
index 1bb21fea8..cc0908ea8 100644
--- a/include/tst_kconfig.h
+++ b/include/tst_kconfig.h
@@ -44,7 +44,8 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
 
 /**
  * Checks if required kernel configuration options are set in the kernel
- * config and exits the test with TCONF if at least one is missing.
+ * config. Return 0 if every config is satisfied and return 1 if at least
+ * one is missing.
  *
  * The config options can be passed in two different formats, either
  * "CONFIG_FOO" in which case the option has to be set in order to continue the
@@ -53,6 +54,6 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
  *
  * @param kconfigs NULL-terminated array of config strings needed for the testrun.
  */
-void tst_kconfig_check(const char *const kconfigs[]);
+int tst_kconfig_check(const char *const kconfigs[]);
 
 #endif	/* TST_KCONFIG_H__ */
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index d433b8cf6..7d7aecfc1 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -478,12 +478,12 @@ static void dump_vars(const struct tst_expr *expr)
 	}
 }
 
-void tst_kconfig_check(const char *const kconfigs[])
+int tst_kconfig_check(const char *const kconfigs[])
 {
 	size_t expr_cnt = array_len(kconfigs);
 	struct tst_expr *exprs[expr_cnt];
 	unsigned int i, var_cnt;
-	int abort_test = 0;
+	int ret = 0;
 
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
@@ -506,7 +506,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 		int val = tst_bool_expr_eval(exprs[i], map);
 
 		if (val != 1) {
-			abort_test = 1;
+			ret = 1;
 			tst_res(TINFO, "Constraint '%s' not satisfied!", kconfigs[i]);
 			dump_vars(exprs[i]);
 		}
@@ -519,8 +519,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 			free(vars[i].val);
 	}
 
-	if (abort_test)
-		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+	return ret;
 }
 
 char tst_kconfig_get(const char *confname)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9fea7263a..d5cefadaa 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1025,8 +1025,8 @@ static void do_setup(int argc, char *argv[])
 
 	parse_opts(argc, argv);
 
-	if (tst_test->needs_kconfigs)
-		tst_kconfig_check(tst_test->needs_kconfigs);
+	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
+		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
 	if (tst_test->needs_root && geteuid() != 0)
 		tst_brk(TCONF, "Test needs to be run as root");
-- 
2.23.0


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

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

* [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
@ 2022-01-10  1:49                 ` Yang Xu
  2022-01-10  8:14                   ` Li Wang
  2022-01-10 12:20                   ` Cyril Hrubis
  2022-01-10  1:49                 ` [LTP] [PATCH v3 3/4] shell: add kconfig parse api Yang Xu
                                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-10  1:49 UTC (permalink / raw)
  To: ltp

This environment variable is designed to add kernel config check functionality
switch. So we can skip 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 |  1 +
 lib/tst_kconfig.c  | 20 ++++++++++++++++++++
 lib/tst_test.c     |  1 +
 3 files changed, 22 insertions(+)

diff --git a/doc/user-guide.txt b/doc/user-guide.txt
index 494652618..864467f60 100644
--- a/doc/user-guide.txt
+++ b/doc/user-guide.txt
@@ -10,6 +10,7 @@ For running LTP network tests see `testcases/network/README.md`.
 |==============================================================================
 | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
                           the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
+| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check, the default is empty(don't skip).
 | 'LTPROOT'             | Prefix for installed LTP, the default is '/opt/ltp'.
 | 'LTP_COLORIZE_OUTPUT' | Force colorized output behaviour. 'y' or '1': always colorize
                           'n' or '0': never colorize.
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index 7d7aecfc1..e4264101d 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -15,6 +15,16 @@
 #include "tst_kconfig.h"
 #include "tst_bool_expr.h"
 
+static int kconfig_check_skipped(void)
+{
+	char *skipped = getenv("KCONFIG_SKIP_CHECK");
+
+	if (skipped)
+		return 1;
+
+	return 0;
+}
+
 static const char *kconfig_path(char *path_buf, size_t path_buf_len)
 {
 	const char *path = getenv("KCONFIG_PATH");
@@ -485,6 +495,11 @@ int tst_kconfig_check(const char *const kconfigs[])
 	unsigned int i, var_cnt;
 	int ret = 0;
 
+	if (kconfig_check_skipped()) {
+		tst_res(TINFO, "Skipping kernel config check as requested");
+		return 0;
+	}
+
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
 
@@ -526,6 +541,11 @@ char tst_kconfig_get(const char *confname)
 {
 	struct tst_kconfig_var var;
 
+	if (kconfig_check_skipped()) {
+		tst_res(TINFO, "Skipping kernel config check as requested");
+		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..8ac3cdc5c 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -479,6 +479,7 @@ static void print_help(void)
 	fprintf(stderr, "Environment Variables\n");
 	fprintf(stderr, "---------------------\n");
 	fprintf(stderr, "KCONFIG_PATH         Specify kernel config file\n");
+	fprintf(stderr, "KCONFIG_SKIP_CHECK   Skip kernel config check (the default is empty means don't skip)\n");
 	fprintf(stderr, "LTPROOT              Prefix for installed LTP (default: /opt/ltp)\n");
 	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");
-- 
2.23.0


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

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

* [LTP] [PATCH v3 3/4] shell: add kconfig parse api
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
@ 2022-01-10  1:49                 ` Yang Xu
  2022-01-10  8:26                   ` Li Wang
  2022-01-10 13:43                   ` Cyril Hrubis
  2022-01-10  1:49                 ` [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
                                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-10  1:49 UTC (permalink / raw)
  To: ltp

Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
It introduces two variables in tst_test.sh
TST_NEEDS_KCONFIGS
TST_NEEDS_KCONFIGS_IFS (default value is comma)

Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
case instead the whole test.

Fixes:#891
Suggested-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/shell-test-api.txt                        | 51 ++++++++++++------
 lib/newlib_tests/runtest.sh                   |  3 +-
 lib/newlib_tests/shell/tst_check_kconfig01.sh | 16 ++++++
 lib/newlib_tests/shell/tst_check_kconfig02.sh | 15 ++++++
 lib/newlib_tests/shell/tst_check_kconfig03.sh | 16 ++++++
 lib/newlib_tests/shell/tst_check_kconfig04.sh | 25 +++++++++
 testcases/lib/.gitignore                      |  1 +
 testcases/lib/Makefile                        |  3 +-
 testcases/lib/tst_check_kconfigs.c            | 54 +++++++++++++++++++
 testcases/lib/tst_test.sh                     | 15 ++++++
 10 files changed, 181 insertions(+), 18 deletions(-)
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
 create mode 100644 lib/newlib_tests/shell/tst_check_kconfig04.sh
 create mode 100644 testcases/lib/tst_check_kconfigs.c

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index b993a9e1e..e082808f7 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -193,22 +193,25 @@ simply by setting right '$TST_NEEDS_FOO'.
 
 [options="header"]
 |=============================================================================
-| Variable name      | Action done
-| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
-|                    | Alternatively the 'tst_require_root' command can be used.
-| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
-| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
-                       device is stored in '$TST_DEVICE' variable.
-                       The option implies 'TST_NEEDS_TMPDIR'.
-| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
-                       the test (see below).
-| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
-| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
-| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
-                       or -1 (special value to disable timeout), default is 300.
-                       Variable is meant be set in tests, not by user.
-                       It's an equivalent of `tst_test.timeout` in C, can be set
-                       via 'tst_set_timeout(timeout)' after test has started.
+| Variable name            | Action done
+| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
+|                          | Alternatively the 'tst_require_root' command can be used.
+| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
+| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
+                             device is stored in '$TST_DEVICE' variable.
+                             The option implies 'TST_NEEDS_TMPDIR'.
+| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
+                             the test (see below).
+| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
+| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
+| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
+| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
+                             default value is comma, it only supports single character.
+| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int >= 1,
+                             or -1 (special value to disable timeout), default is 300.
+                             Variable is meant be set in tests, not by user.
+                             It's an equivalent of `tst_test.timeout` in C, can be set
+                             via 'tst_set_timeout(timeout)' after test has started.
 |=============================================================================
 
 [options="header"]
@@ -742,3 +745,19 @@ TST_NEEDS_CHECKPOINTS=1
 Since both the implementations are compatible, it's also possible to start
 a child binary process from a shell test and synchronize with it. This process
 must have checkpoints initialized by calling 'tst_reinit()'.
+
+1.7 Parsing kernel .config
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The shell library provides an implementation of the kconfig parsing interface
+compatible with the C version.
+
+It's possible to pass kernel kconfig list for tst_require_kconfigs API with
+'$TST_NEEDS_KCONFIGS'.
+Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
+
+-------------------------------------------------------------------------------
+#!/bin/sh
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
+
+. tst_test.sh
+-------------------------------------------------------------------------------
diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index 8b2fe347a..b34a582b7 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -6,7 +6,8 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
 tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
 tst_fuzzy_sync03 test_zero_hugepage.sh}"
 
-LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
+LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
+shell/tst_check_kconfig0[1-4].sh shell/net/*.sh}"
 
 cd $(dirname $0)
 PATH="$PWD/../../testcases/lib/:$PATH"
diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
new file mode 100755
index 000000000..065a20fd2
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4"
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
new file mode 100755
index 000000000..3a0f05847
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "invalid kconfig delimter"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
new file mode 100755
index 000000000..c5f046b79
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+TST_NEEDS_KCONFIGS_IFS=":"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TPASS "valid kconfig delimter"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
new file mode 100644
index 000000000..ad5e8ac21
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_CMDS="tst_check_kconfigs"
+. tst_test.sh
+
+do_test()
+{
+	tst_check_kconfigs "CONFIG_EXT4_FS"
+	if [ $? -eq 0 ]; then
+		tst_res TPASS "kernel .config has CONFIG_EXT4_fs"
+	else
+		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
+	fi
+
+	tst_check_kconfigs "CONFIG_EXT4"
+	if [ $? -eq 0 ]; then
+		tst_res TFAIL "kernel .config has CONFIG_EXT4"
+	else
+		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
+	fi
+}
+tst_run
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 9625d9043..c0d4dc851 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,4 +1,5 @@
 /tst_check_drivers
+/tst_check_kconfigs
 /tst_checkpoint
 /tst_device
 /tst_getconf
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index d6b4c7a91..f2de0c832 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -11,6 +11,7 @@ INSTALL_TARGETS		:= *.sh
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
-			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
+			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
+			   tst_check_kconfigs
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
new file mode 100644
index 000000000..dd0c72768
--- /dev/null
+++ b/testcases/lib/tst_check_kconfigs.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
+
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include "tst_kconfig.h"
+
+int main(int argc, const char *argv[])
+{
+	char delim[2];
+	char str[PATH_MAX];
+	char *result = NULL;
+	char *next = NULL;
+	int i = 0, j = 0, ret = 0;
+
+	if (argc < 3) {
+		fprintf(stderr, "Please provide kernel kconfig list and delims\n");
+		return 1;
+	}
+
+	if (strlen(argv[2]) != 1) {
+		fprintf(stderr, "The delim must be a single character\n");
+		return 1;
+	}
+
+	strcpy(str, argv[1]);
+	strcpy(delim, argv[2]);
+
+	result = strtok_r(str, delim, &next);
+	for (i = 0; result != NULL; i++)
+		result = strtok_r(NULL, delim, &next);
+
+	strcpy(str, argv[1]);
+	char **kconfigs = (char **)malloc(++i * sizeof(char *));
+
+	result = strtok_r(str, delim, &next);
+	for (i = 0; result != NULL; i++) {
+		kconfigs[i] = (char *)malloc(sizeof(char) * strlen(result));
+		strcpy(kconfigs[i], result);
+		result = strtok_r(NULL, delim, &next);
+	}
+
+	kconfigs[i] = NULL;
+	if (tst_kconfig_check((const char * const*)kconfigs))
+		ret = 1;
+
+	for (j = 0; j <= i; j++)
+		free(kconfigs[i]);
+
+	free(kconfigs);
+	return ret;
+}
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 2556b28f5..9c4e4dd3b 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -412,6 +412,17 @@ tst_require_drivers()
 	return 0
 }
 
+tst_require_kconfigs()
+{
+	[ $# -ne 2  ] && return 0
+
+	tst_check_kconfigs "$1" $2 > /dev/null
+	if [ $? -ne 0 ]; then
+		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
+	fi
+	return 0
+}
+
 tst_is_int()
 {
 	[ "$1" -eq "$1" ] 2>/dev/null
@@ -587,6 +598,7 @@ tst_run()
 			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
 			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
 			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
+			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
 			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
 			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
 			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
@@ -627,6 +639,7 @@ tst_run()
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
 
 	tst_require_cmds $TST_NEEDS_CMDS
+	tst_require_kconfigs "$TST_NEEDS_KCONFIGS" $TST_NEEDS_KCONFIGS_IFS
 	tst_require_drivers $TST_NEEDS_DRIVERS
 
 	if [ -n "$TST_MIN_KVER" ]; then
@@ -748,6 +761,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
 
 	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
 
+	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
+
 	if [ -n "$TST_CNT" ]; then
 		if ! tst_is_int "$TST_CNT"; then
 			tst_brk TBROK "TST_CNT must be integer"
-- 
2.23.0


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

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

* [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
  2022-01-10  1:49                 ` [LTP] [PATCH v3 3/4] shell: add kconfig parse api Yang Xu
@ 2022-01-10  1:49                 ` Yang Xu
  2022-01-10  8:30                   ` Li Wang
  2022-01-10 14:15                   ` Cyril Hrubis
  2022-01-10  8:10                 ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Li Wang
  2022-01-10 12:18                 ` Cyril Hrubis
  4 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-10  1:49 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/commands/sysctl/sysctl02.sh | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/testcases/commands/sysctl/sysctl02.sh b/testcases/commands/sysctl/sysctl02.sh
index 3964a9829..1c444268a 100755
--- a/testcases/commands/sysctl/sysctl02.sh
+++ b/testcases/commands/sysctl/sysctl02.sh
@@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
 TST_CNT=4
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl"
+TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
 sys_name="fs.file-max"
 sys_file="/proc/sys/fs/file-max"
-syms_file="/proc/kallsyms"
 
 . tst_test.sh
 
 setup()
 {
-	[ ! -f "$sys_file" ] && tst_brk TCONF "$sys_file not enabled"
 	orig_value=$(cat "$sys_file")
 }
 
@@ -61,17 +60,15 @@ sysctl_test_overflow()
 
 sysctl_test_zero()
 {
-	[ ! -f "$syms_file" ] && tst_brk TCONF "$syms_file not enabled"
+	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
+		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
+
 	ROD sysctl -w -q $sys_name=0
 
-	if grep -q kasan_report $syms_file; then
-		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
-			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
-		else
-			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
-		fi
+	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
+		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
 	else
-		tst_res TCONF "kernel doesn't support KASAN"
+		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
 	fi
 }
 
-- 
2.23.0


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

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

* Re: [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-06 11:20             ` Cyril Hrubis
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
@ 2022-01-10  5:45               ` xuyang2018.jy
  1 sibling, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-10  5:45 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> @@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
>>   TST_CNT=4
>>   TST_NEEDS_ROOT=1
>>   TST_NEEDS_CMDS="sysctl"
>> +TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
>
> Is there a good reason to check for PROC_FS? I doubt that modern system
> without CONFIG_PROC_FS will even boot.
I just think some autotest framework ie lkp will start kernel with 
random config (to find compile bug), so I add PROC_FS to it.

Best Regards
Yang Xu

  >
>>   sys_name="fs.file-max"
>>   sys_file="/proc/sys/fs/file-max"
>> -syms_file="/proc/kallsyms"
>>
>>   . tst_test.sh
>>
>>   setup()
>>   {
>> -	[ ! -f "$sys_file" ]&&  tst_brk TCONF "$sys_file not enabled"
>>   	orig_value=$(cat "$sys_file")
>>   }
>>
>> @@ -61,17 +60,15 @@ sysctl_test_overflow()
>>
>>   sysctl_test_zero()
>>   {
>> -	[ ! -f "$syms_file" ]&&  tst_brk TCONF "$syms_file not enabled"
>> +	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
>> +		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
>> +
>>   	ROD sysctl -w -q $sys_name=0
>>
>> -	if grep -q kasan_report $syms_file; then
>> -		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
>> -			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
>> -		else
>> -			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
>> -		fi
>> +	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
>> +		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
>>   	else
>> -		tst_res TCONF "kernel doesn't support KASAN"
>> +		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
>>   	fi
>>   }
>>
>> --
>> 2.23.0
>>
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
>

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

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

* Re: [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
                                   ` (2 preceding siblings ...)
  2022-01-10  1:49                 ` [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
@ 2022-01-10  8:10                 ` Li Wang
  2022-01-10 12:18                 ` Cyril Hrubis
  4 siblings, 0 replies; 74+ messages in thread
From: Li Wang @ 2022-01-10  8:10 UTC (permalink / raw)
  To: Yang Xu; +Cc: LTP List

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
@ 2022-01-10  8:14                   ` Li Wang
  2022-01-10 12:20                   ` Cyril Hrubis
  1 sibling, 0 replies; 74+ messages in thread
From: Li Wang @ 2022-01-10  8:14 UTC (permalink / raw)
  To: Yang Xu; +Cc: LTP List

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v3 3/4] shell: add kconfig parse api
  2022-01-10  1:49                 ` [LTP] [PATCH v3 3/4] shell: add kconfig parse api Yang Xu
@ 2022-01-10  8:26                   ` Li Wang
  2022-01-10  8:46                     ` xuyang2018.jy
  2022-01-10 13:43                   ` Cyril Hrubis
  1 sibling, 1 reply; 74+ messages in thread
From: Li Wang @ 2022-01-10  8:26 UTC (permalink / raw)
  To: Yang Xu; +Cc: LTP List

On Mon, Jan 10, 2022 at 2:26 PM Yang Xu <xuyang2018.jy@fujitsu.com> wrote:

> +1.7 Parsing kernel .config
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +The shell library provides an implementation of the kconfig parsing interface
> +compatible with the C version.

 ^ consistent with the C version.

> +++ b/testcases/lib/tst_check_kconfigs.c
> @@ -0,0 +1,54 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
> +
> +#include <stdio.h>
> +#include <string.h>
> +#include <limits.h>
> +#include <stdlib.h>
> +#include "tst_kconfig.h"
> +
> +int main(int argc, const char *argv[])
> +{
> +       char delim[2];
> +       char str[PATH_MAX];
> +       char *result = NULL;
> +       char *next = NULL;
> +       int i = 0, j = 0, ret = 0;
> +
> +       if (argc < 3) {
> +               fprintf(stderr, "Please provide kernel kconfig list and delims\n");
> +               return 1;
> +       }
> +
> +       if (strlen(argv[2]) != 1) {
> +               fprintf(stderr, "The delim must be a single character\n");
> +               return 1;
> +       }
> +
> +       strcpy(str, argv[1]);
> +       strcpy(delim, argv[2]);
> +
> +       result = strtok_r(str, delim, &next);
> +       for (i = 0; result != NULL; i++)
> +               result = strtok_r(NULL, delim, &next);
> +
> +       strcpy(str, argv[1]);
> +       char **kconfigs = (char **)malloc(++i * sizeof(char *));
> +
> +       result = strtok_r(str, delim, &next);
> +       for (i = 0; result != NULL; i++) {
> +               kconfigs[i] = (char *)malloc(sizeof(char) * strlen(result));
> +               strcpy(kconfigs[i], result);

I guess there is no need to allocate additional memory to do strcpy.
As the kconfigs[i] is just a pointer, we can assign the 'result' to it directly.

i.e.

       for (i = 0; result != NULL; i++) {
               kconfigs[i] = result;
               result = strtok_r(NULL, delim, &next);
       }

Otherwise looks good.
Reviewed-by: Li Wang <liwang@redhat.com>

--
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-10  1:49                 ` [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
@ 2022-01-10  8:30                   ` Li Wang
  2022-01-10 14:15                   ` Cyril Hrubis
  1 sibling, 0 replies; 74+ messages in thread
From: Li Wang @ 2022-01-10  8:30 UTC (permalink / raw)
  To: Yang Xu; +Cc: LTP List

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v3 3/4] shell: add kconfig parse api
  2022-01-10  8:26                   ` Li Wang
@ 2022-01-10  8:46                     ` xuyang2018.jy
  2022-01-10  9:13                       ` Li Wang
  0 siblings, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-10  8:46 UTC (permalink / raw)
  To: Li Wang; +Cc: LTP List

Hi Li
> On Mon, Jan 10, 2022 at 2:26 PM Yang Xu<xuyang2018.jy@fujitsu.com>  wrote:
>
>> +1.7 Parsing kernel .config
>> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> +The shell library provides an implementation of the kconfig parsing interface
>> +compatible with the C version.
>
>   ^ consistent with the C version.
Yes.
>
>> +++ b/testcases/lib/tst_check_kconfigs.c
>> @@ -0,0 +1,54 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
>> +
>> +#include<stdio.h>
>> +#include<string.h>
>> +#include<limits.h>
>> +#include<stdlib.h>
>> +#include "tst_kconfig.h"
>> +
>> +int main(int argc, const char *argv[])
>> +{
>> +       char delim[2];
>> +       char str[PATH_MAX];
>> +       char *result = NULL;
>> +       char *next = NULL;
>> +       int i = 0, j = 0, ret = 0;
>> +
>> +       if (argc<  3) {
>> +               fprintf(stderr, "Please provide kernel kconfig list and delims\n");
>> +               return 1;
>> +       }
>> +
>> +       if (strlen(argv[2]) != 1) {
>> +               fprintf(stderr, "The delim must be a single character\n");
>> +               return 1;
>> +       }
>> +
>> +       strcpy(str, argv[1]);
>> +       strcpy(delim, argv[2]);
>> +
>> +       result = strtok_r(str, delim,&next);
>> +       for (i = 0; result != NULL; i++)
>> +               result = strtok_r(NULL, delim,&next);
>> +
>> +       strcpy(str, argv[1]);
>> +       char **kconfigs = (char **)malloc(++i * sizeof(char *));
>> +
>> +       result = strtok_r(str, delim,&next);
>> +       for (i = 0; result != NULL; i++) {
>> +               kconfigs[i] = (char *)malloc(sizeof(char) * strlen(result));
>> +               strcpy(kconfigs[i], result);
>
> I guess there is no need to allocate additional memory to do strcpy.
> As the kconfigs[i] is just a pointer, we can assign the 'result' to it directly.
>
> i.e.
>
>         for (i = 0; result != NULL; i++) {
>                 kconfigs[i] = result;
>                 result = strtok_r(NULL, delim,&next);
>         }
>
Yes, thanks for your review.

We can modify those when maintainer merges it.

Best Regard
Yang Xu
> Otherwise looks good.
> Reviewed-by: Li Wang<liwang@redhat.com>
>
> --
> Regards,
> Li Wang
>

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

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

* Re: [LTP] [PATCH v3 3/4] shell: add kconfig parse api
  2022-01-10  8:46                     ` xuyang2018.jy
@ 2022-01-10  9:13                       ` Li Wang
  0 siblings, 0 replies; 74+ messages in thread
From: Li Wang @ 2022-01-10  9:13 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: LTP List

On Mon, Jan 10, 2022 at 4:48 PM xuyang2018.jy@fujitsu.com
<xuyang2018.jy@fujitsu.com> wrote:
>
> Hi Li
> > On Mon, Jan 10, 2022 at 2:26 PM Yang Xu<xuyang2018.jy@fujitsu.com>  wrote:
> >
> >> +1.7 Parsing kernel .config
> >> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> +The shell library provides an implementation of the kconfig parsing interface
> >> +compatible with the C version.
> >
> >   ^ consistent with the C version.
> Yes.
> >
> >> +++ b/testcases/lib/tst_check_kconfigs.c
> >> @@ -0,0 +1,54 @@
> >> +// SPDX-License-Identifier: GPL-2.0-or-later
> >> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
> >> +
> >> +#include<stdio.h>
> >> +#include<string.h>
> >> +#include<limits.h>
> >> +#include<stdlib.h>
> >> +#include "tst_kconfig.h"
> >> +
> >> +int main(int argc, const char *argv[])
> >> +{
> >> +       char delim[2];
> >> +       char str[PATH_MAX];
> >> +       char *result = NULL;
> >> +       char *next = NULL;
> >> +       int i = 0, j = 0, ret = 0;
> >> +
> >> +       if (argc<  3) {
> >> +               fprintf(stderr, "Please provide kernel kconfig list and delims\n");
> >> +               return 1;
> >> +       }
> >> +
> >> +       if (strlen(argv[2]) != 1) {
> >> +               fprintf(stderr, "The delim must be a single character\n");
> >> +               return 1;
> >> +       }
> >> +
> >> +       strcpy(str, argv[1]);
> >> +       strcpy(delim, argv[2]);
> >> +
> >> +       result = strtok_r(str, delim,&next);
> >> +       for (i = 0; result != NULL; i++)
> >> +               result = strtok_r(NULL, delim,&next);
> >> +
> >> +       strcpy(str, argv[1]);
> >> +       char **kconfigs = (char **)malloc(++i * sizeof(char *));

And, I also think that if traverse the number of delim, then
we will avoid doing strcpy twice here. But that's not important,
I have no strong insist on this way.

i.e.

       strcpy(str, argv[1]);
       strcpy(delim, argv[2]);

       for (next = str, i = 1; next[j] != '\0'; j++)
               if (next[j] == delim[0])
                       i++;
       char **kconfigs = (char **)malloc(++i * sizeof(char *));


> We can modify those when maintainer merges it.

Sure.

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
                                   ` (3 preceding siblings ...)
  2022-01-10  8:10                 ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Li Wang
@ 2022-01-10 12:18                 ` Cyril Hrubis
  4 siblings, 0 replies; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-10 12:18 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
  2022-01-10  8:14                   ` Li Wang
@ 2022-01-10 12:20                   ` Cyril Hrubis
  2022-01-11  1:38                     ` xuyang2018.jy
  1 sibling, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-10 12:20 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> This environment variable is designed to add kernel config check functionality
> switch. So we can skip 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 |  1 +
>  lib/tst_kconfig.c  | 20 ++++++++++++++++++++
>  lib/tst_test.c     |  1 +
>  3 files changed, 22 insertions(+)
> 
> diff --git a/doc/user-guide.txt b/doc/user-guide.txt
> index 494652618..864467f60 100644
> --- a/doc/user-guide.txt
> +++ b/doc/user-guide.txt
> @@ -10,6 +10,7 @@ For running LTP network tests see `testcases/network/README.md`.
>  |==============================================================================
>  | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
>                            the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
> +| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check, the default is empty(don't skip).
                                                                           ^
									   Space
									   here
									   please
>  | 'LTPROOT'             | Prefix for installed LTP, the default is '/opt/ltp'.
>  | 'LTP_COLORIZE_OUTPUT' | Force colorized output behaviour. 'y' or '1': always colorize
>                            'n' or '0': never colorize.
> diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
> index 7d7aecfc1..e4264101d 100644
> --- a/lib/tst_kconfig.c
> +++ b/lib/tst_kconfig.c
> @@ -15,6 +15,16 @@
>  #include "tst_kconfig.h"
>  #include "tst_bool_expr.h"
>  
> +static int kconfig_check_skipped(void)
                       ^
		       I would have named this same as the variable,
		       i.e. kconfig_skip_check()

Other that these two minor things:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v3 3/4] shell: add kconfig parse api
  2022-01-10  1:49                 ` [LTP] [PATCH v3 3/4] shell: add kconfig parse api Yang Xu
  2022-01-10  8:26                   ` Li Wang
@ 2022-01-10 13:43                   ` Cyril Hrubis
  2022-01-11  5:29                     ` xuyang2018.jy
  2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  1 sibling, 2 replies; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-10 13:43 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
> It introduces two variables in tst_test.sh
> TST_NEEDS_KCONFIGS
> TST_NEEDS_KCONFIGS_IFS (default value is comma)
> 
> Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
> case instead the whole test.
> 
> Fixes:#891
> Suggested-by: Petr Vorel <pvorel@suse.cz>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  doc/shell-test-api.txt                        | 51 ++++++++++++------
>  lib/newlib_tests/runtest.sh                   |  3 +-
>  lib/newlib_tests/shell/tst_check_kconfig01.sh | 16 ++++++
>  lib/newlib_tests/shell/tst_check_kconfig02.sh | 15 ++++++
>  lib/newlib_tests/shell/tst_check_kconfig03.sh | 16 ++++++
>  lib/newlib_tests/shell/tst_check_kconfig04.sh | 25 +++++++++
>  testcases/lib/.gitignore                      |  1 +
>  testcases/lib/Makefile                        |  3 +-
>  testcases/lib/tst_check_kconfigs.c            | 54 +++++++++++++++++++
>  testcases/lib/tst_test.sh                     | 15 ++++++
>  10 files changed, 181 insertions(+), 18 deletions(-)
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
>  create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
>  create mode 100644 lib/newlib_tests/shell/tst_check_kconfig04.sh
>  create mode 100644 testcases/lib/tst_check_kconfigs.c
> 
> diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
> index b993a9e1e..e082808f7 100644
> --- a/doc/shell-test-api.txt
> +++ b/doc/shell-test-api.txt
> @@ -193,22 +193,25 @@ simply by setting right '$TST_NEEDS_FOO'.
>  
>  [options="header"]
>  |=============================================================================
> -| Variable name      | Action done
> -| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
> -|                    | Alternatively the 'tst_require_root' command can be used.
> -| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
> -| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
> -                       device is stored in '$TST_DEVICE' variable.
> -                       The option implies 'TST_NEEDS_TMPDIR'.
> -| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
> -                       the test (see below).
> -| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
> -| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
> -| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
> -                       or -1 (special value to disable timeout), default is 300.
> -                       Variable is meant be set in tests, not by user.
> -                       It's an equivalent of `tst_test.timeout` in C, can be set
> -                       via 'tst_set_timeout(timeout)' after test has started.
> +| Variable name            | Action done
> +| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
> +|                          | Alternatively the 'tst_require_root' command can be used.
> +| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
> +| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
> +                             device is stored in '$TST_DEVICE' variable.
> +                             The option implies 'TST_NEEDS_TMPDIR'.
> +| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
> +                             the test (see below).
> +| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
> +| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
> +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
> +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
> +                             default value is comma, it only supports single character.
> +| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int >= 1,
> +                             or -1 (special value to disable timeout), default is 300.
> +                             Variable is meant be set in tests, not by user.
> +                             It's an equivalent of `tst_test.timeout` in C, can be set
> +                             via 'tst_set_timeout(timeout)' after test has started.
>  |=============================================================================
>  
>  [options="header"]
> @@ -742,3 +745,19 @@ TST_NEEDS_CHECKPOINTS=1
>  Since both the implementations are compatible, it's also possible to start
>  a child binary process from a shell test and synchronize with it. This process
>  must have checkpoints initialized by calling 'tst_reinit()'.
> +
> +1.7 Parsing kernel .config
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +The shell library provides an implementation of the kconfig parsing interface
> +compatible with the C version.
> +
> +It's possible to pass kernel kconfig list for tst_require_kconfigs API with
> +'$TST_NEEDS_KCONFIGS'.
> +Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
> +
> +-------------------------------------------------------------------------------
> +#!/bin/sh
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
> +
> +. tst_test.sh
> +-------------------------------------------------------------------------------
> diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
> index 8b2fe347a..b34a582b7 100755
> --- a/lib/newlib_tests/runtest.sh
> +++ b/lib/newlib_tests/runtest.sh
> @@ -6,7 +6,8 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
>  tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
>  tst_fuzzy_sync03 test_zero_hugepage.sh}"
>  
> -LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
> +LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
> +shell/tst_check_kconfig0[1-4].sh shell/net/*.sh}"

It would be slightly safter to actually export the KCONFIG_PATH pointing
to one of the config files created for the C tests (config02) if we are goind to
run this in CI.

It's very unlikely that anyone who runs these tests wouldn't have
CONFIG_EXT4_FS in but it may actually happen.

>  cd $(dirname $0)
>  PATH="$PWD/../../testcases/lib/:$PATH"
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
> new file mode 100755
> index 000000000..065a20fd2
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"

I wouldn't bother with checking for this, it's part of the LTP it's not
an external tool that could be missing.

> +TST_NEEDS_KCONFIGS="CONFIG_EXT4"
> +
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
> new file mode 100755
> index 000000000..3a0f05847
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TFAIL "invalid kconfig delimter"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
> new file mode 100755
> index 000000000..c5f046b79
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
> +TST_NEEDS_KCONFIGS_IFS=":"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_res TPASS "valid kconfig delimter"
> +}
> +
> +tst_run
> diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
> new file mode 100644
> index 000000000..ad5e8ac21
> --- /dev/null
> +++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
> @@ -0,0 +1,25 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +
> +TST_TESTFUNC=do_test
> +TST_NEEDS_CMDS="tst_check_kconfigs"
> +. tst_test.sh
> +
> +do_test()
> +{
> +	tst_check_kconfigs "CONFIG_EXT4_FS"
> +	if [ $? -eq 0 ]; then
> +		tst_res TPASS "kernel .config has CONFIG_EXT4_fs"
                                                              ^
							      FS
> +	else
> +		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
> +	fi
> +
> +	tst_check_kconfigs "CONFIG_EXT4"
> +	if [ $? -eq 0 ]; then
> +		tst_res TFAIL "kernel .config has CONFIG_EXT4"
> +	else
> +		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
> +	fi
> +}
> +tst_run
> diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
> index 9625d9043..c0d4dc851 100644
> --- a/testcases/lib/.gitignore
> +++ b/testcases/lib/.gitignore
> @@ -1,4 +1,5 @@
>  /tst_check_drivers
> +/tst_check_kconfigs
>  /tst_checkpoint
>  /tst_device
>  /tst_getconf
> diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
> index d6b4c7a91..f2de0c832 100644
> --- a/testcases/lib/Makefile
> +++ b/testcases/lib/Makefile
> @@ -11,6 +11,7 @@ INSTALL_TARGETS		:= *.sh
>  MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
>  			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
>  			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
> -			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
> +			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
> +			   tst_check_kconfigs
>  
>  include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
> new file mode 100644
> index 000000000..dd0c72768
> --- /dev/null
> +++ b/testcases/lib/tst_check_kconfigs.c
> @@ -0,0 +1,54 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
> +
> +#include <stdio.h>
> +#include <string.h>
> +#include <limits.h>
> +#include <stdlib.h>
> +#include "tst_kconfig.h"
> +
> +int main(int argc, const char *argv[])
> +{
> +	char delim[2];
> +	char str[PATH_MAX];
> +	char *result = NULL;
> +	char *next = NULL;
> +	int i = 0, j = 0, ret = 0;
> +
> +	if (argc < 3) {
> +		fprintf(stderr, "Please provide kernel kconfig list and delims\n");
> +		return 1;
> +	}
> +
> +	if (strlen(argv[2]) != 1) {
> +		fprintf(stderr, "The delim must be a single character\n");
> +		return 1;
> +	}
> +
> +	strcpy(str, argv[1]);
> +	strcpy(delim, argv[2]);
> +
> +	result = strtok_r(str, delim, &next);
> +	for (i = 0; result != NULL; i++)
> +		result = strtok_r(NULL, delim, &next);

There is no reason to parse the string like this here we can just do:

	char *str = argv[1];
	char *delim = argv[2];
	unsigned int cnt = 1;

	for (i = 0; str[i]; i++) {
		if (str[i] == delim[0])
			cnt++;
	}

> +	strcpy(str, argv[1]);
> +	char **kconfigs = (char **)malloc(++i * sizeof(char *));
                            ^
			    useless cast

> +	result = strtok_r(str, delim, &next);
> +	for (i = 0; result != NULL; i++) {
> +		kconfigs[i] = (char *)malloc(sizeof(char) * strlen(result));
> +		strcpy(kconfigs[i], result);
> +		result = strtok_r(NULL, delim, &next);
> +	}

Also no reason to allocate anything here, we can in fact modify the
argv[1] there is no reason not to, so we can do:

	for (i = 0; i < cnt; i++)
		kconfigs[i] = strtok_r(str, delim, &str);

	kconfigs[i] = NULL;


> +	kconfigs[i] = NULL;
> +	if (tst_kconfig_check((const char * const*)kconfigs))
> +		ret = 1;
> +
> +	for (j = 0; j <= i; j++)
> +		free(kconfigs[i]);
> +
> +	free(kconfigs);
> +	return ret;
> +}
> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 2556b28f5..9c4e4dd3b 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -412,6 +412,17 @@ tst_require_drivers()
>  	return 0
>  }
>  
> +tst_require_kconfigs()
> +{
> +	[ $# -ne 2  ] && return 0
> +
> +	tst_check_kconfigs "$1" $2 > /dev/null
> +	if [ $? -ne 0 ]; then
> +		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
> +	fi
> +	return 0
> +}
> +
>  tst_is_int()
>  {
>  	[ "$1" -eq "$1" ] 2>/dev/null
> @@ -587,6 +598,7 @@ tst_run()
>  			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
>  			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
>  			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
> +			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
>  			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
>  			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
>  			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
> @@ -627,6 +639,7 @@ tst_run()
>  	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
>  
>  	tst_require_cmds $TST_NEEDS_CMDS
> +	tst_require_kconfigs "$TST_NEEDS_KCONFIGS" $TST_NEEDS_KCONFIGS_IFS
>  	tst_require_drivers $TST_NEEDS_DRIVERS
>  
>  	if [ -n "$TST_MIN_KVER" ]; then
> @@ -748,6 +761,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
>  
>  	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
>  
> +	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
> +
>  	if [ -n "$TST_CNT" ]; then
>  		if ! tst_is_int "$TST_CNT"; then
>  			tst_brk TBROK "TST_CNT must be integer"
> -- 
> 2.23.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-10  1:49                 ` [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
  2022-01-10  8:30                   ` Li Wang
@ 2022-01-10 14:15                   ` Cyril Hrubis
  2022-01-11  5:34                     ` xuyang2018.jy
  1 sibling, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-10 14:15 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> +	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
                               ^
			       This should be a single string now,
			       right?

			       Also we should pass the delimiter unless
			       we change the tst_check_kconfigs default
			       to ',' if no delimiter was passed (which
			       sounds reasonable).

> +		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
> +
>  	ROD sysctl -w -q $sys_name=0
>  
> -	if grep -q kasan_report $syms_file; then
> -		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
> -			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
> -		else
> -			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
> -		fi
> +	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
> +		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
>  	else
> -		tst_res TCONF "kernel doesn't support KASAN"
> +		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
>  	fi
>  }
>  
> -- 
> 2.23.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-10 12:20                   ` Cyril Hrubis
@ 2022-01-11  1:38                     ` xuyang2018.jy
  0 siblings, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-11  1:38 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> This environment variable is designed to add kernel config check functionality
>> switch. So we can skip 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 |  1 +
>>   lib/tst_kconfig.c  | 20 ++++++++++++++++++++
>>   lib/tst_test.c     |  1 +
>>   3 files changed, 22 insertions(+)
>>
>> diff --git a/doc/user-guide.txt b/doc/user-guide.txt
>> index 494652618..864467f60 100644
>> --- a/doc/user-guide.txt
>> +++ b/doc/user-guide.txt
>> @@ -10,6 +10,7 @@ For running LTP network tests see `testcases/network/README.md`.
>>   |==============================================================================
>>   | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
>>                             the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
>> +| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check, the default is empty(don't skip).
>                                                                             ^
> 									   Space
> 									   here
> 									   please
>>   | 'LTPROOT'             | Prefix for installed LTP, the default is '/opt/ltp'.
>>   | 'LTP_COLORIZE_OUTPUT' | Force colorized output behaviour. 'y' or '1': always colorize
>>                             'n' or '0': never colorize.
>> diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
>> index 7d7aecfc1..e4264101d 100644
>> --- a/lib/tst_kconfig.c
>> +++ b/lib/tst_kconfig.c
>> @@ -15,6 +15,16 @@
>>   #include "tst_kconfig.h"
>>   #include "tst_bool_expr.h"
>>
>> +static int kconfig_check_skipped(void)
>                         ^
> 		       I would have named this same as the variable,
> 		       i.e. kconfig_skip_check()

Will fix these two comments in v5, thanks for your review.

Best Regards
Yang Xu
>
> Other that these two minor things:
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>

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

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

* Re: [LTP] [PATCH v3 3/4] shell: add kconfig parse api
  2022-01-10 13:43                   ` Cyril Hrubis
@ 2022-01-11  5:29                     ` xuyang2018.jy
  2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  1 sibling, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-11  5:29 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
>> It introduces two variables in tst_test.sh
>> TST_NEEDS_KCONFIGS
>> TST_NEEDS_KCONFIGS_IFS (default value is comma)
>>
>> Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
>> case instead the whole test.
>>
>> Fixes:#891
>> Suggested-by: Petr Vorel<pvorel@suse.cz>
>> Suggested-by: Cyril Hrubis<chrubis@suse.cz>
>> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
>> ---
>>   doc/shell-test-api.txt                        | 51 ++++++++++++------
>>   lib/newlib_tests/runtest.sh                   |  3 +-
>>   lib/newlib_tests/shell/tst_check_kconfig01.sh | 16 ++++++
>>   lib/newlib_tests/shell/tst_check_kconfig02.sh | 15 ++++++
>>   lib/newlib_tests/shell/tst_check_kconfig03.sh | 16 ++++++
>>   lib/newlib_tests/shell/tst_check_kconfig04.sh | 25 +++++++++
>>   testcases/lib/.gitignore                      |  1 +
>>   testcases/lib/Makefile                        |  3 +-
>>   testcases/lib/tst_check_kconfigs.c            | 54 +++++++++++++++++++
>>   testcases/lib/tst_test.sh                     | 15 ++++++
>>   10 files changed, 181 insertions(+), 18 deletions(-)
>>   create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
>>   create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
>>   create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
>>   create mode 100644 lib/newlib_tests/shell/tst_check_kconfig04.sh
>>   create mode 100644 testcases/lib/tst_check_kconfigs.c
>>
>> diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
>> index b993a9e1e..e082808f7 100644
>> --- a/doc/shell-test-api.txt
>> +++ b/doc/shell-test-api.txt
>> @@ -193,22 +193,25 @@ simply by setting right '$TST_NEEDS_FOO'.
>>
>>   [options="header"]
>>   |=============================================================================
>> -| Variable name      | Action done
>> -| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
>> -|                    | Alternatively the 'tst_require_root' command can be used.
>> -| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
>> -| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
>> -                       device is stored in '$TST_DEVICE' variable.
>> -                       The option implies 'TST_NEEDS_TMPDIR'.
>> -| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
>> -                       the test (see below).
>> -| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
>> -| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
>> -| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int>= 1,
>> -                       or -1 (special value to disable timeout), default is 300.
>> -                       Variable is meant be set in tests, not by user.
>> -                       It's an equivalent of `tst_test.timeout` in C, can be set
>> -                       via 'tst_set_timeout(timeout)' after test has started.
>> +| Variable name            | Action done
>> +| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
>> +|                          | Alternatively the 'tst_require_root' command can be used.
>> +| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
>> +| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
>> +                             device is stored in '$TST_DEVICE' variable.
>> +                             The option implies 'TST_NEEDS_TMPDIR'.
>> +| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
>> +                             the test (see below).
>> +| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
>> +| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
>> +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
>> +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
>> +                             default value is comma, it only supports single character.
>> +| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int>= 1,
>> +                             or -1 (special value to disable timeout), default is 300.
>> +                             Variable is meant be set in tests, not by user.
>> +                             It's an equivalent of `tst_test.timeout` in C, can be set
>> +                             via 'tst_set_timeout(timeout)' after test has started.
>>   |=============================================================================
>>
>>   [options="header"]
>> @@ -742,3 +745,19 @@ TST_NEEDS_CHECKPOINTS=1
>>   Since both the implementations are compatible, it's also possible to start
>>   a child binary process from a shell test and synchronize with it. This process
>>   must have checkpoints initialized by calling 'tst_reinit()'.
>> +
>> +1.7 Parsing kernel .config
>> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> +The shell library provides an implementation of the kconfig parsing interface
>> +compatible with the C version.
>> +
>> +It's possible to pass kernel kconfig list for tst_require_kconfigs API with
>> +'$TST_NEEDS_KCONFIGS'.
>> +Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
>> +
>> +-------------------------------------------------------------------------------
>> +#!/bin/sh
>> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
>> +
>> +. tst_test.sh
>> +-------------------------------------------------------------------------------
>> diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
>> index 8b2fe347a..b34a582b7 100755
>> --- a/lib/newlib_tests/runtest.sh
>> +++ b/lib/newlib_tests/runtest.sh
>> @@ -6,7 +6,8 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
>>   tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
>>   tst_fuzzy_sync03 test_zero_hugepage.sh}"
>>
>> -LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
>> +LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
>> +shell/tst_check_kconfig0[1-4].sh shell/net/*.sh}"
>
> It would be slightly safter to actually export the KCONFIG_PATH pointing
> to one of the config files created for the C tests (config02) if we are goind to
> run this in CI.
>
> It's very unlikely that anyone who runs these tests wouldn't have
> CONFIG_EXT4_FS in but it may actually happen.
Good suggestion.
>
>>   cd $(dirname $0)
>>   PATH="$PWD/../../testcases/lib/:$PATH"
>> diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
>> new file mode 100755
>> index 000000000..065a20fd2
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
>> @@ -0,0 +1,16 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>
> I wouldn't bother with checking for this, it's part of the LTP it's not
> an external tool that could be missing.
Agree.
>
>> +TST_NEEDS_KCONFIGS="CONFIG_EXT4"
>> +
>> +. tst_test.sh
>> +
>> +do_test()
>> +{
>> +	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
>> +}
>> +
>> +tst_run
>> diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
>> new file mode 100755
>> index 000000000..3a0f05847
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
>> @@ -0,0 +1,15 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
>> +. tst_test.sh
>> +
>> +do_test()
>> +{
>> +	tst_res TFAIL "invalid kconfig delimter"
>> +}
>> +
>> +tst_run
>> diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
>> new file mode 100755
>> index 000000000..c5f046b79
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
>> @@ -0,0 +1,16 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>> +TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
>> +TST_NEEDS_KCONFIGS_IFS=":"
>> +. tst_test.sh
>> +
>> +do_test()
>> +{
>> +	tst_res TPASS "valid kconfig delimter"
>> +}
>> +
>> +tst_run
>> diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
>> new file mode 100644
>> index 000000000..ad5e8ac21
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
>> @@ -0,0 +1,25 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> +
>> +TST_TESTFUNC=do_test
>> +TST_NEEDS_CMDS="tst_check_kconfigs"
>> +. tst_test.sh
>> +
>> +do_test()
>> +{
>> +	tst_check_kconfigs "CONFIG_EXT4_FS"
>> +	if [ $? -eq 0 ]; then
>> +		tst_res TPASS "kernel .config has CONFIG_EXT4_fs"
>                                                                ^
> 							      FS
Will fix.
>> +	else
>> +		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
>> +	fi
>> +
>> +	tst_check_kconfigs "CONFIG_EXT4"
>> +	if [ $? -eq 0 ]; then
>> +		tst_res TFAIL "kernel .config has CONFIG_EXT4"
>> +	else
>> +		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
>> +	fi
>> +}
>> +tst_run
>> diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
>> index 9625d9043..c0d4dc851 100644
>> --- a/testcases/lib/.gitignore
>> +++ b/testcases/lib/.gitignore
>> @@ -1,4 +1,5 @@
>>   /tst_check_drivers
>> +/tst_check_kconfigs
>>   /tst_checkpoint
>>   /tst_device
>>   /tst_getconf
>> diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
>> index d6b4c7a91..f2de0c832 100644
>> --- a/testcases/lib/Makefile
>> +++ b/testcases/lib/Makefile
>> @@ -11,6 +11,7 @@ INSTALL_TARGETS		:= *.sh
>>   MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
>>   			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
>>   			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
>> -			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
>> +			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
>> +			   tst_check_kconfigs
>>
>>   include $(top_srcdir)/include/mk/generic_leaf_target.mk
>> diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
>> new file mode 100644
>> index 000000000..dd0c72768
>> --- /dev/null
>> +++ b/testcases/lib/tst_check_kconfigs.c
>> @@ -0,0 +1,54 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
>> +
>> +#include<stdio.h>
>> +#include<string.h>
>> +#include<limits.h>
>> +#include<stdlib.h>
>> +#include "tst_kconfig.h"
>> +
>> +int main(int argc, const char *argv[])
>> +{
>> +	char delim[2];
>> +	char str[PATH_MAX];
>> +	char *result = NULL;
>> +	char *next = NULL;
>> +	int i = 0, j = 0, ret = 0;
>> +
>> +	if (argc<  3) {
>> +		fprintf(stderr, "Please provide kernel kconfig list and delims\n");
>> +		return 1;
>> +	}
>> +
>> +	if (strlen(argv[2]) != 1) {
>> +		fprintf(stderr, "The delim must be a single character\n");
>> +		return 1;
>> +	}
>> +
>> +	strcpy(str, argv[1]);
>> +	strcpy(delim, argv[2]);
>> +
>> +	result = strtok_r(str, delim,&next);
>> +	for (i = 0; result != NULL; i++)
>> +		result = strtok_r(NULL, delim,&next);
>
> There is no reason to parse the string like this here we can just do:
>
> 	char *str = argv[1];
> 	char *delim = argv[2];
> 	unsigned int cnt = 1;
>
> 	for (i = 0; str[i]; i++) {
> 		if (str[i] == delim[0])
> 			cnt++;
> 	}
>
>> +	strcpy(str, argv[1]);
>> +	char **kconfigs = (char **)malloc(++i * sizeof(char *));
>                              ^
> 			    useless cast
>
>> +	result = strtok_r(str, delim,&next);
>> +	for (i = 0; result != NULL; i++) {
>> +		kconfigs[i] = (char *)malloc(sizeof(char) * strlen(result));
>> +		strcpy(kconfigs[i], result);
>> +		result = strtok_r(NULL, delim,&next);
>> +	}
>
> Also no reason to allocate anything here, we can in fact modify the
> argv[1] there is no reason not to, so we can do:
>
> 	for (i = 0; i<  cnt; i++)
> 		kconfigs[i] = strtok_r(str, delim,&str);
>
> 	kconfigs[i] = NULL;
>
>
Will do it in v5.


Best Regards
Yang Xu
>> +	kconfigs[i] = NULL;
>> +	if (tst_kconfig_check((const char * const*)kconfigs))
>> +		ret = 1;
>> +
>> +	for (j = 0; j<= i; j++)
>> +		free(kconfigs[i]);
>> +
>> +	free(kconfigs);
>> +	return ret;
>> +}
>> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
>> index 2556b28f5..9c4e4dd3b 100644
>> --- a/testcases/lib/tst_test.sh
>> +++ b/testcases/lib/tst_test.sh
>> @@ -412,6 +412,17 @@ tst_require_drivers()
>>   	return 0
>>   }
>>
>> +tst_require_kconfigs()
>> +{
>> +	[ $# -ne 2  ]&&  return 0
>> +
>> +	tst_check_kconfigs "$1" $2>  /dev/null
>> +	if [ $? -ne 0 ]; then
>> +		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
>> +	fi
>> +	return 0
>> +}
>> +
>>   tst_is_int()
>>   {
>>   	[ "$1" -eq "$1" ] 2>/dev/null
>> @@ -587,6 +598,7 @@ tst_run()
>>   			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
>>   			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
>>   			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
>> +			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
>>   			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
>>   			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
>>   			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
>> @@ -627,6 +639,7 @@ tst_run()
>>   	[ "$TST_DISABLE_SELINUX" = 1 ]&&  tst_disable_selinux
>>
>>   	tst_require_cmds $TST_NEEDS_CMDS
>> +	tst_require_kconfigs "$TST_NEEDS_KCONFIGS" $TST_NEEDS_KCONFIGS_IFS
>>   	tst_require_drivers $TST_NEEDS_DRIVERS
>>
>>   	if [ -n "$TST_MIN_KVER" ]; then
>> @@ -748,6 +761,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
>>
>>   	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
>>
>> +	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
>> +
>>   	if [ -n "$TST_CNT" ]; then
>>   		if ! tst_is_int "$TST_CNT"; then
>>   			tst_brk TBROK "TST_CNT must be integer"
>> --
>> 2.23.0
>>
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
>

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

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

* Re: [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-10 14:15                   ` Cyril Hrubis
@ 2022-01-11  5:34                     ` xuyang2018.jy
  0 siblings, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-11  5:34 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> +	tst_check_kconfigs "CONFIG_KALLSYMS=y" "CONFIG_KALLSYMS_ALL=y" "CONFIG_KASAN=y" \
>                                 ^
> 			       This should be a single string now,
> 			       right?
Yes.
>
> 			       Also we should pass the delimiter unless
> 			       we change the tst_check_kconfigs default
> 			       to ',' if no delimiter was passed (which
> 			       sounds reasonable).
Yes, I have modified tst_check_kconfigs and tst_require_kconfigs api, so 
if no delimiters was passed, tst_require_kconfigs will use 
$TST_NEEDS_KCONFIGS_IFS, tst_check_kconfigs will use comma.

Best Regards
Yang Xu
>
>> +		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
>> +
>>   	ROD sysctl -w -q $sys_name=0
>>
>> -	if grep -q kasan_report $syms_file; then
>> -		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
>> -			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
>> -		else
>> -			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
>> -		fi
>> +	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
>> +		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
>>   	else
>> -		tst_res TCONF "kernel doesn't support KASAN"
>> +		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
>>   	fi
>>   }
>>
>> --
>> 2.23.0
>>
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
>

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

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

* [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function
  2022-01-10 13:43                   ` Cyril Hrubis
  2022-01-11  5:29                     ` xuyang2018.jy
@ 2022-01-11  6:10                     ` Yang Xu
  2022-01-11  6:10                       ` [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
                                         ` (3 more replies)
  1 sibling, 4 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-11  6:10 UTC (permalink / raw)
  To: ltp

So this function can be used to detect whether the function succeeded in shell
api by its return value.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/tst_kconfig.h | 5 +++--
 lib/tst_kconfig.c     | 9 ++++-----
 lib/tst_test.c        | 4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/tst_kconfig.h b/include/tst_kconfig.h
index 1bb21fea8..cc0908ea8 100644
--- a/include/tst_kconfig.h
+++ b/include/tst_kconfig.h
@@ -44,7 +44,8 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
 
 /**
  * Checks if required kernel configuration options are set in the kernel
- * config and exits the test with TCONF if at least one is missing.
+ * config. Return 0 if every config is satisfied and return 1 if at least
+ * one is missing.
  *
  * The config options can be passed in two different formats, either
  * "CONFIG_FOO" in which case the option has to be set in order to continue the
@@ -53,6 +54,6 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);
  *
  * @param kconfigs NULL-terminated array of config strings needed for the testrun.
  */
-void tst_kconfig_check(const char *const kconfigs[]);
+int tst_kconfig_check(const char *const kconfigs[]);
 
 #endif	/* TST_KCONFIG_H__ */
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index d433b8cf6..7d7aecfc1 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -478,12 +478,12 @@ static void dump_vars(const struct tst_expr *expr)
 	}
 }
 
-void tst_kconfig_check(const char *const kconfigs[])
+int tst_kconfig_check(const char *const kconfigs[])
 {
 	size_t expr_cnt = array_len(kconfigs);
 	struct tst_expr *exprs[expr_cnt];
 	unsigned int i, var_cnt;
-	int abort_test = 0;
+	int ret = 0;
 
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
@@ -506,7 +506,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 		int val = tst_bool_expr_eval(exprs[i], map);
 
 		if (val != 1) {
-			abort_test = 1;
+			ret = 1;
 			tst_res(TINFO, "Constraint '%s' not satisfied!", kconfigs[i]);
 			dump_vars(exprs[i]);
 		}
@@ -519,8 +519,7 @@ void tst_kconfig_check(const char *const kconfigs[])
 			free(vars[i].val);
 	}
 
-	if (abort_test)
-		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+	return ret;
 }
 
 char tst_kconfig_get(const char *confname)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9fea7263a..d5cefadaa 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1025,8 +1025,8 @@ static void do_setup(int argc, char *argv[])
 
 	parse_opts(argc, argv);
 
-	if (tst_test->needs_kconfigs)
-		tst_kconfig_check(tst_test->needs_kconfigs);
+	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
+		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
 	if (tst_test->needs_root && geteuid() != 0)
 		tst_brk(TCONF, "Test needs to be run as root");
-- 
2.23.0


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

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

* [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
@ 2022-01-11  6:10                       ` Yang Xu
  2022-01-13 11:09                         ` Petr Vorel
  2022-01-11  6:10                       ` [LTP] [PATCH v4 3/5] shell: add kconfig parse api Yang Xu
                                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 74+ messages in thread
From: Yang Xu @ 2022-01-11  6:10 UTC (permalink / raw)
  To: ltp

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

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/user-guide.txt |  1 +
 lib/tst_kconfig.c  | 20 ++++++++++++++++++++
 lib/tst_test.c     |  1 +
 3 files changed, 22 insertions(+)

diff --git a/doc/user-guide.txt b/doc/user-guide.txt
index 494652618..6b80bb699 100644
--- a/doc/user-guide.txt
+++ b/doc/user-guide.txt
@@ -10,6 +10,7 @@ For running LTP network tests see `testcases/network/README.md`.
 |==============================================================================
 | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
                           the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
+| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check, the default is empty (don't skip).
 | 'LTPROOT'             | Prefix for installed LTP, the default is '/opt/ltp'.
 | 'LTP_COLORIZE_OUTPUT' | Force colorized output behaviour. 'y' or '1': always colorize
                           'n' or '0': never colorize.
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index 7d7aecfc1..d0c9b24c2 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -15,6 +15,16 @@
 #include "tst_kconfig.h"
 #include "tst_bool_expr.h"
 
+static int kconfig_skip_check(void)
+{
+	char *skipped = getenv("KCONFIG_SKIP_CHECK");
+
+	if (skipped)
+		return 1;
+
+	return 0;
+}
+
 static const char *kconfig_path(char *path_buf, size_t path_buf_len)
 {
 	const char *path = getenv("KCONFIG_PATH");
@@ -485,6 +495,11 @@ int tst_kconfig_check(const char *const kconfigs[])
 	unsigned int i, var_cnt;
 	int ret = 0;
 
+	if (kconfig_skip_check()) {
+		tst_res(TINFO, "Skipping kernel config check as requested");
+		return 0;
+	}
+
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
 
@@ -526,6 +541,11 @@ char tst_kconfig_get(const char *confname)
 {
 	struct tst_kconfig_var var;
 
+	if (kconfig_skip_check()) {
+		tst_res(TINFO, "Skipping kernel config check as requested");
+		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..db19d0d68 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -479,6 +479,7 @@ static void print_help(void)
 	fprintf(stderr, "Environment Variables\n");
 	fprintf(stderr, "---------------------\n");
 	fprintf(stderr, "KCONFIG_PATH         Specify kernel config file\n");
+	fprintf(stderr, "KCONFIG_SKIP_CHECK   Skip kernel config check (the default is empty means don't skip)\n");
 	fprintf(stderr, "LTPROOT              Prefix for installed LTP (default: /opt/ltp)\n");
 	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");
-- 
2.23.0


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

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

* [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-11  6:10                       ` [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
@ 2022-01-11  6:10                       ` Yang Xu
  2022-01-11  7:52                         ` Li Wang
  2022-01-11  6:10                       ` [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
  2022-01-11  6:10                       ` [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target Yang Xu
  3 siblings, 1 reply; 74+ messages in thread
From: Yang Xu @ 2022-01-11  6:10 UTC (permalink / raw)
  To: ltp

Use tst_check_kconfigs command to call tst_kconfig_check function in internal.
It introduces two variables in tst_test.sh
TST_NEEDS_KCONFIGS
TST_NEEDS_KCONFIGS_IFS (default value is comma)

Also, we can use tst_check_kconfigs in your shell case if you want to skip subtest
case instead the whole test. Of course, ltp shell test library can use
tst_require_kconfigs in the future if needs. The delim parameter is optional for
tst_require_kconfigs or tst_check_kconfigs api because they have default value for
themselves.

Fixes:#891
Reviewed-by: Li Wang <liwang@redhat.com>
Suggested-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/shell-test-api.txt                        | 51 +++++++++++++------
 lib/newlib_tests/runtest.sh                   |  5 +-
 lib/newlib_tests/shell/tst_check_kconfig01.sh | 15 ++++++
 lib/newlib_tests/shell/tst_check_kconfig02.sh | 14 +++++
 lib/newlib_tests/shell/tst_check_kconfig03.sh | 15 ++++++
 lib/newlib_tests/shell/tst_check_kconfig04.sh | 24 +++++++++
 lib/newlib_tests/shell/tst_check_kconfig05.sh | 16 ++++++
 testcases/lib/.gitignore                      |  1 +
 testcases/lib/Makefile                        |  3 +-
 testcases/lib/tst_check_kconfigs.c            | 46 +++++++++++++++++
 testcases/lib/tst_test.sh                     | 24 +++++++++
 11 files changed, 196 insertions(+), 18 deletions(-)
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig01.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig02.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig03.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig04.sh
 create mode 100755 lib/newlib_tests/shell/tst_check_kconfig05.sh
 create mode 100644 testcases/lib/tst_check_kconfigs.c

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index b993a9e1e..e082808f7 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -193,22 +193,25 @@ simply by setting right '$TST_NEEDS_FOO'.
 
 [options="header"]
 |=============================================================================
-| Variable name      | Action done
-| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
-|                    | Alternatively the 'tst_require_root' command can be used.
-| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
-| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
-                       device is stored in '$TST_DEVICE' variable.
-                       The option implies 'TST_NEEDS_TMPDIR'.
-| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
-                       the test (see below).
-| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
-| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
-| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
-                       or -1 (special value to disable timeout), default is 300.
-                       Variable is meant be set in tests, not by user.
-                       It's an equivalent of `tst_test.timeout` in C, can be set
-                       via 'tst_set_timeout(timeout)' after test has started.
+| Variable name            | Action done
+| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
+|                          | Alternatively the 'tst_require_root' command can be used.
+| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
+| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
+                             device is stored in '$TST_DEVICE' variable.
+                             The option implies 'TST_NEEDS_TMPDIR'.
+| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
+                             the test (see below).
+| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
+| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
+| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
+| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
+                             default value is comma, it only supports single character.
+| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int >= 1,
+                             or -1 (special value to disable timeout), default is 300.
+                             Variable is meant be set in tests, not by user.
+                             It's an equivalent of `tst_test.timeout` in C, can be set
+                             via 'tst_set_timeout(timeout)' after test has started.
 |=============================================================================
 
 [options="header"]
@@ -742,3 +745,19 @@ TST_NEEDS_CHECKPOINTS=1
 Since both the implementations are compatible, it's also possible to start
 a child binary process from a shell test and synchronize with it. This process
 must have checkpoints initialized by calling 'tst_reinit()'.
+
+1.7 Parsing kernel .config
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The shell library provides an implementation of the kconfig parsing interface
+compatible with the C version.
+
+It's possible to pass kernel kconfig list for tst_require_kconfigs API with
+'$TST_NEEDS_KCONFIGS'.
+Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
+
+-------------------------------------------------------------------------------
+#!/bin/sh
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
+
+. tst_test.sh
+-------------------------------------------------------------------------------
diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index 8b2fe347a..ad213eef6 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -6,7 +6,8 @@ tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
 tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
 tst_fuzzy_sync03 test_zero_hugepage.sh}"
 
-LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh shell/net/*.sh}"
+LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
+shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
 
 cd $(dirname $0)
 PATH="$PWD/../../testcases/lib/:$PATH"
@@ -179,6 +180,8 @@ if [ -z "$run" -o "$run" = "c" ]; then
 fi
 
 if [ -z "$run" -o "$run" = "s" ]; then
+	export KCONFIG_PATH=config02
+	runtest_res TINFO "KCONFIG_PATH='$KCONFIG_PATH'"
 	run_shell_tests
 	shell_fail=$?
 fi
diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
new file mode 100755
index 000000000..03f86266d
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_KCONFIGS="CONFIG_EXT4"
+
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
new file mode 100755
index 000000000..6a20cfc3d
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TFAIL "invalid kconfig delimter"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
new file mode 100755
index 000000000..361b6bf0b
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+TST_NEEDS_KCONFIGS_IFS=":"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TPASS "valid kconfig delimter"
+}
+
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
new file mode 100755
index 000000000..21cd998dd
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+. tst_test.sh
+
+do_test()
+{
+	tst_check_kconfigs "CONFIG_EXT4_FS"
+	if [ $? -eq 0 ]; then
+		tst_res TPASS "kernel .config has CONFIG_EXT4_FS"
+	else
+		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
+	fi
+
+	tst_check_kconfigs "CONFIG_EXT4"
+	if [ $? -eq 0 ]; then
+		tst_res TFAIL "kernel .config has CONFIG_EXT4"
+	else
+		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
+	fi
+}
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig05.sh b/lib/newlib_tests/shell/tst_check_kconfig05.sh
new file mode 100755
index 000000000..f118f27a5
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+. tst_test.sh
+
+do_test()
+{
+	tst_require_kconfigs "CONFIG_EXT4_FS"
+	tst_res TPASS "kernel .config has CONFIG_EXT4_FS"
+
+	tst_require_kconfigs "CONFIG_EXT4"
+	tst_res TFAIL "kernel .config has CONFIG_EXT4"
+}
+tst_run
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 9625d9043..c0d4dc851 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,4 +1,5 @@
 /tst_check_drivers
+/tst_check_kconfigs
 /tst_checkpoint
 /tst_device
 /tst_getconf
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index d6b4c7a91..f2de0c832 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -11,6 +11,7 @@ INSTALL_TARGETS		:= *.sh
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
-			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill
+			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
+			   tst_check_kconfigs
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
new file mode 100644
index 000000000..b0f1f201a
--- /dev/null
+++ b/testcases/lib/tst_check_kconfigs.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "tst_kconfig.h"
+
+int main(int argc, char *argv[])
+{
+	char *str = argv[1];
+	char *delim = argv[2];
+	unsigned int i, cnt = 1;
+	int ret = 0;
+
+	if (argc == 2 || strlen(delim) == 0) {
+		delim = ",";
+	} else if (argc == 3) {
+		if (strlen(delim) > 1) {
+			fprintf(stderr, "The delim must be a single character\n");
+			return 1;
+		}
+	} else {
+		fprintf(stderr, "Please provide kernel kconfig list and delim "
+				"(optinal, default value is ',')\n");
+		return 1;
+	}
+
+	for (i = 0; str[i]; i++) {
+		if (str[i] == delim[0])
+			cnt++;
+	}
+
+	char **kconfigs = malloc(++i * sizeof(char *));
+
+	for (i = 0; i < cnt; i++)
+		kconfigs[i] = strtok_r(str, delim, &str);
+
+	kconfigs[i] = NULL;
+
+	if (tst_kconfig_check((const char * const*)kconfigs))
+		ret = 1;
+
+	free(kconfigs);
+	return ret;
+}
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 2556b28f5..30614974c 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -412,6 +412,26 @@ tst_require_drivers()
 	return 0
 }
 
+tst_require_kconfigs()
+{
+	local delim
+
+	if [ $# -gt 2 ]; then
+		return 0
+	elif [ $# -eq 1 ]; then
+		delim="$TST_NEEDS_KCONFIGS_IFS"
+	else
+		delim="$2"
+	fi
+
+	[ -z "$1" ] && return 0
+
+	tst_check_kconfigs "$1" "$delim" > /dev/null
+
+	[ $? -ne 0 ] && tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
+	return 0
+}
+
 tst_is_int()
 {
 	[ "$1" -eq "$1" ] 2>/dev/null
@@ -587,6 +607,7 @@ tst_run()
 			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
 			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
 			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
+			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
 			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
 			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
 			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
@@ -627,6 +648,7 @@ tst_run()
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
 
 	tst_require_cmds $TST_NEEDS_CMDS
+	tst_require_kconfigs "$TST_NEEDS_KCONFIGS"
 	tst_require_drivers $TST_NEEDS_DRIVERS
 
 	if [ -n "$TST_MIN_KVER" ]; then
@@ -748,6 +770,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
 
 	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
 
+	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
+
 	if [ -n "$TST_CNT" ]; then
 		if ! tst_is_int "$TST_CNT"; then
 			tst_brk TBROK "TST_CNT must be integer"
-- 
2.23.0


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

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

* [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
  2022-01-11  6:10                       ` [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
  2022-01-11  6:10                       ` [LTP] [PATCH v4 3/5] shell: add kconfig parse api Yang Xu
@ 2022-01-11  6:10                       ` Yang Xu
  2022-01-13 10:53                         ` Petr Vorel
  2022-01-13 15:54                         ` Cyril Hrubis
  2022-01-11  6:10                       ` [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target Yang Xu
  3 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-11  6:10 UTC (permalink / raw)
  To: ltp

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/commands/sysctl/sysctl02.sh | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/testcases/commands/sysctl/sysctl02.sh b/testcases/commands/sysctl/sysctl02.sh
index 3964a9829..367cd5743 100755
--- a/testcases/commands/sysctl/sysctl02.sh
+++ b/testcases/commands/sysctl/sysctl02.sh
@@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
 TST_CNT=4
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl"
+TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
 sys_name="fs.file-max"
 sys_file="/proc/sys/fs/file-max"
-syms_file="/proc/kallsyms"
 
 . tst_test.sh
 
 setup()
 {
-	[ ! -f "$sys_file" ] && tst_brk TCONF "$sys_file not enabled"
 	orig_value=$(cat "$sys_file")
 }
 
@@ -61,17 +60,15 @@ sysctl_test_overflow()
 
 sysctl_test_zero()
 {
-	[ ! -f "$syms_file" ] && tst_brk TCONF "$syms_file not enabled"
+	tst_check_kconfigs "CONFIG_KALLSYMS=y,CONFIG_KALLSYMS_ALL=y,CONFIG_KASAN=y" \
+		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
+
 	ROD sysctl -w -q $sys_name=0
 
-	if grep -q kasan_report $syms_file; then
-		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
-			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
-		else
-			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
-		fi
+	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
+		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
 	else
-		tst_res TCONF "kernel doesn't support KASAN"
+		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
 	fi
 }
 
-- 
2.23.0


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

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

* [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target
  2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
                                         ` (2 preceding siblings ...)
  2022-01-11  6:10                       ` [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
@ 2022-01-11  6:10                       ` Yang Xu
  2022-01-13 11:25                         ` Petr Vorel
  2022-01-13 15:54                         ` Cyril Hrubis
  3 siblings, 2 replies; 74+ messages in thread
From: Yang Xu @ 2022-01-11  6:10 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 lib/newlib_tests/runtest.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index ad213eef6..92fd3860e 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -4,7 +4,7 @@
 LTP_C_API_TESTS="${LTP_C_API_TESTS:-test05 test07 test09 test12 test15 test18
 tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
 tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
-tst_fuzzy_sync03 test_zero_hugepage.sh}"
+tst_fuzzy_sync03 test_zero_hugepage.sh test_kconfig.sh}"
 
 LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
 shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
-- 
2.23.0


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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-11  6:10                       ` [LTP] [PATCH v4 3/5] shell: add kconfig parse api Yang Xu
@ 2022-01-11  7:52                         ` Li Wang
  2022-01-11  8:37                           ` xuyang2018.jy
  0 siblings, 1 reply; 74+ messages in thread
From: Li Wang @ 2022-01-11  7:52 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

On Tue, Jan 11, 2022 at 2:10 PM Yang Xu <xuyang2018.jy@fujitsu.com> wrote:

> +++ b/testcases/lib/tst_check_kconfigs.c
> @@ -0,0 +1,46 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
> +
> +#include <stdio.h>
> +#include <string.h>
> +#include <stdlib.h>
> +#include "tst_kconfig.h"
> +
> +int main(int argc, char *argv[])
> +{
> +       char *str = argv[1];
> +       char *delim = argv[2];
> +       unsigned int i, cnt = 1;
> +       int ret = 0;
> +
> +       if (argc == 2 || strlen(delim) == 0) {

I doubt that this syntax really works here.

How can we get the strlen(delim) equal to 0? if the argc is
not 2, why the length of delimi is zero? but if we change ||
to &&, then get a segment fault. I don't understand this.

> +               delim = ",";
> +       } else if (argc == 3) {
> +               if (strlen(delim) > 1) {
> +                       fprintf(stderr, "The delim must be a single character\n");
> +                       return 1;
> +               }
> +       } else {
> +               fprintf(stderr, "Please provide kernel kconfig list and delim "
> +                               "(optinal, default value is ',')\n");
> +               return 1;
> +       }
> +
> +       for (i = 0; str[i]; i++) {
> +               if (str[i] == delim[0])
> +                       cnt++;
> +       }
> +
> +       char **kconfigs = malloc(++i * sizeof(char *));

Shouldn't this be malloc(++cnt * sizeof(char*)) ?

> +
> +       for (i = j0; i < cnt; i++)
> +               kconfigs[i] = strtok_r(str, delim, &str);
> +
> +       kconfigs[i] = NULL;
> +
> +       if (tst_kconfig_check((const char * const*)kconfigs))
> +               ret = 1;
> +
> +       free(kconfigs);
> +       return ret;
> +}

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-11  7:52                         ` Li Wang
@ 2022-01-11  8:37                           ` xuyang2018.jy
  2022-01-13  9:15                             ` xuyang2018.jy
  2022-01-13 15:51                             ` Cyril Hrubis
  0 siblings, 2 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-11  8:37 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi Li
> On Tue, Jan 11, 2022 at 2:10 PM Yang Xu<xuyang2018.jy@fujitsu.com>  wrote:
>
>> +++ b/testcases/lib/tst_check_kconfigs.c
>> @@ -0,0 +1,46 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
>> +
>> +#include<stdio.h>
>> +#include<string.h>
>> +#include<stdlib.h>
>> +#include "tst_kconfig.h"
>> +
>> +int main(int argc, char *argv[])
>> +{
>> +       char *str = argv[1];
>> +       char *delim = argv[2];
>> +       unsigned int i, cnt = 1;
>> +       int ret = 0;
>> +
>> +       if (argc == 2 || strlen(delim) == 0) {
>
> I doubt that this syntax really works here.
>
> How can we get the strlen(delim) equal to 0? if the argc is
> not 2, why the length of delimi is zero? but if we change ||
> to&&, then get a segment fault. I don't understand this.

Sorry, this is ugly code. please see the lastest code.
>
>> +               delim = ",";
>> +       } else if (argc == 3) {
>> +               if (strlen(delim)>  1) {
>> +                       fprintf(stderr, "The delim must be a single character\n");
>> +                       return 1;
>> +               }
>> +       } else {
>> +               fprintf(stderr, "Please provide kernel kconfig list and delim "
>> +                               "(optinal, default value is ',')\n");
>> +               return 1;
>> +       }
>> +
>> +       for (i = 0; str[i]; i++) {
>> +               if (str[i] == delim[0])
>> +                       cnt++;
>> +       }
>> +
>> +       char **kconfigs = malloc(++i * sizeof(char *));
>
> Shouldn't this be malloc(++cnt * sizeof(char*)) ?
Oh, yes. Sorry for this typo.
>
>> +
>> +       for (i = j0; i<  cnt; i++)
>> +               kconfigs[i] = strtok_r(str, delim,&str);
>> +
>> +       kconfigs[i] = NULL;
This is also useless.

The lastest code should be as below:

int main(int argc, char *argv[])
{
         char *str = argv[1];
         char *delim = argv[2];
         unsigned int i, cnt = 1;
         int ret = 0;

         if (argc == 2) {
                 delim = ",";
         } else if (argc == 3) {
                 if (strlen(delim) > 1) {
                         fprintf(stderr, "The delim must be a single 
character\n");
                         return 1;
                 }
         } else {
                 fprintf(stderr, "Please provide kernel kconfig list and 
delim "
                                 "(optinal, default value is ',')\n");
                 return 1;
         }

         for (i = 0; str[i]; i++) {
                 if (str[i] == delim[0])
                         cnt++;
         }

         char **kconfigs = malloc(++cnt * sizeof(char *));

         for (i = 0; i < cnt; i++)
                 kconfigs[i] = strtok_r(str, delim, &str);

         if (tst_kconfig_check((const char * const*)kconfigs))
                 ret = 1;

         free(kconfigs);
         return ret;
}


Best Regards
Yang Xu
>> +
>> +       if (tst_kconfig_check((const char * const*)kconfigs))
>> +               ret = 1;
>> +
>> +       free(kconfigs);
>> +       return ret;
>> +}
>

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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-11  8:37                           ` xuyang2018.jy
@ 2022-01-13  9:15                             ` xuyang2018.jy
  2022-01-13  9:42                               ` Li Wang
  2022-01-13 15:51                             ` Cyril Hrubis
  1 sibling, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-13  9:15 UTC (permalink / raw)
  To: Li Wang, Cyril Hrubis, Petr Vorel; +Cc: ltp

Hi Li, Cyril, Petr

Any comment for this patchset?

Best Regards
Yang Xu
> Hi Li
>> On Tue, Jan 11, 2022 at 2:10 PM Yang Xu<xuyang2018.jy@fujitsu.com>   wrote:
>>
>>> +++ b/testcases/lib/tst_check_kconfigs.c
>>> @@ -0,0 +1,46 @@
>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
>>> +
>>> +#include<stdio.h>
>>> +#include<string.h>
>>> +#include<stdlib.h>
>>> +#include "tst_kconfig.h"
>>> +
>>> +int main(int argc, char *argv[])
>>> +{
>>> +       char *str = argv[1];
>>> +       char *delim = argv[2];
>>> +       unsigned int i, cnt = 1;
>>> +       int ret = 0;
>>> +
>>> +       if (argc == 2 || strlen(delim) == 0) {
>>
>> I doubt that this syntax really works here.
>>
>> How can we get the strlen(delim) equal to 0? if the argc is
>> not 2, why the length of delimi is zero? but if we change ||
>> to&&, then get a segment fault. I don't understand this.
>
> Sorry, this is ugly code. please see the lastest code.
>>
>>> +               delim = ",";
>>> +       } else if (argc == 3) {
>>> +               if (strlen(delim)>   1) {
>>> +                       fprintf(stderr, "The delim must be a single character\n");
>>> +                       return 1;
>>> +               }
>>> +       } else {
>>> +               fprintf(stderr, "Please provide kernel kconfig list and delim "
>>> +                               "(optinal, default value is ',')\n");
>>> +               return 1;
>>> +       }
>>> +
>>> +       for (i = 0; str[i]; i++) {
>>> +               if (str[i] == delim[0])
>>> +                       cnt++;
>>> +       }
>>> +
>>> +       char **kconfigs = malloc(++i * sizeof(char *));
>>
>> Shouldn't this be malloc(++cnt * sizeof(char*)) ?
> Oh, yes. Sorry for this typo.
>>
>>> +
>>> +       for (i = j0; i<   cnt; i++)
>>> +               kconfigs[i] = strtok_r(str, delim,&str);
>>> +
>>> +       kconfigs[i] = NULL;
> This is also useless.
>
> The lastest code should be as below:
>
> int main(int argc, char *argv[])
> {
>           char *str = argv[1];
>           char *delim = argv[2];
>           unsigned int i, cnt = 1;
>           int ret = 0;
>
>           if (argc == 2) {
>                   delim = ",";
>           } else if (argc == 3) {
>                   if (strlen(delim)>  1) {
>                           fprintf(stderr, "The delim must be a single
> character\n");
>                           return 1;
>                   }
>           } else {
>                   fprintf(stderr, "Please provide kernel kconfig list and
> delim "
>                                   "(optinal, default value is ',')\n");
>                   return 1;
>           }
>
>           for (i = 0; str[i]; i++) {
>                   if (str[i] == delim[0])
>                           cnt++;
>           }
>
>           char **kconfigs = malloc(++cnt * sizeof(char *));
>
>           for (i = 0; i<  cnt; i++)
>                   kconfigs[i] = strtok_r(str, delim,&str);
>
>           if (tst_kconfig_check((const char * const*)kconfigs))
>                   ret = 1;
>
>           free(kconfigs);
>           return ret;
> }
>
>
> Best Regards
> Yang Xu
>>> +
>>> +       if (tst_kconfig_check((const char * const*)kconfigs))
>>> +               ret = 1;
>>> +
>>> +       free(kconfigs);
>>> +       return ret;
>>> +}
>>
>

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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-13  9:15                             ` xuyang2018.jy
@ 2022-01-13  9:42                               ` Li Wang
  0 siblings, 0 replies; 74+ messages in thread
From: Li Wang @ 2022-01-13  9:42 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

> > The lastest code should be as below:
> >
> > int main(int argc, char *argv[])
> > {
> >           char *str = argv[1];
> >           char *delim = argv[2];
> >           unsigned int i, cnt = 1;
> >           int ret = 0;

The statement of ‘ret‘ can move up to unsigned int as well.
Otherwise, this version LGTM.

> >
> >           if (argc == 2) {
> >                   delim = ",";
> >           } else if (argc == 3) {
> >                   if (strlen(delim)>  1) {
> >                           fprintf(stderr, "The delim must be a single
> > character\n");
> >                           return 1;
> >                   }
> >           } else {
> >                   fprintf(stderr, "Please provide kernel kconfig list and
> > delim "
> >                                   "(optinal, default value is ',')\n");
> >                   return 1;
> >           }
> >
> >           for (i = 0; str[i]; i++) {
> >                   if (str[i] == delim[0])
> >                           cnt++;
> >           }
> >
> >           char **kconfigs = malloc(++cnt * sizeof(char *));
> >
> >           for (i = 0; i<  cnt; i++)
> >                   kconfigs[i] = strtok_r(str, delim,&str);
> >
> >           if (tst_kconfig_check((const char * const*)kconfigs))
> >                   ret = 1;
> >
> >           free(kconfigs);
> >           return ret;
> > }


-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-11  6:10                       ` [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
@ 2022-01-13 10:53                         ` Petr Vorel
  2022-01-13 16:06                           ` Petr Vorel
  2022-01-13 15:54                         ` Cyril Hrubis
  1 sibling, 1 reply; 74+ messages in thread
From: Petr Vorel @ 2022-01-13 10:53 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu, all,

subject: "sysctl/sysctl02.sh: Use kconfig shell api"
nit: s/api/API/

Maybe to explain why it's better thatn simple [ -f /proc/kallsyms ] ?
Isn't it more reliable to use /proc/kallsyms file instead of requiring kconfig?

kconfig is sort of documentation, but only if used as TST_NEEDS_KCONFIGS
(I'm going to work on enabling docparse for shell), which is not this case.

If we agree TST_NEEDS_KCONFIGS is better in this case how about to put
sysctl_test_zero into separate file? It could then define things required setup
in TST_NEEDS_KCONFIGS.

> +++ b/testcases/commands/sysctl/sysctl02.sh
> @@ -20,15 +20,14 @@ TST_CLEANUP=cleanup
>  TST_CNT=4
>  TST_NEEDS_ROOT=1
>  TST_NEEDS_CMDS="sysctl"
> +TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
As Cyril mentioned previously CONFIG_PROC_FS can be dropped
(IMHO mandatory for today's linux).

OK, looking into sources it's disabled in:

arch/h8300/configs/edosk2674_defconfig, the other two are GDB simulators.
=> only this one relevant (Renesas EDOSK2674R)
arch/h8300/configs/h8300h-sim_defconfig
arch/h8300/configs/h8s-sim_defconfig

arch/sh/configs/edosk7705_defconfig
arch/sh/configs/sh7724_generic_defconfig
arch/sh/configs/sh7770_generic_defconfig

=> sh and h8300 are certainly not mainstream :).
I can ask the maintainers whether they really use kernel without CONFIG_PROC_FS.

But I'd still consider to safe to expect CONFIG_PROC_FS=y.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-11  6:10                       ` [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
@ 2022-01-13 11:09                         ` Petr Vorel
  2022-01-14  5:36                           ` xuyang2018.jy
  0 siblings, 1 reply; 74+ messages in thread
From: Petr Vorel @ 2022-01-13 11:09 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

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

very nit: I'd write it a bit simpler. Maybe:
Add environment variable to disable kernel config check functionality.
It is useful for embedded platforms which don't have kernel config installed.

> +++ b/doc/user-guide.txt
> @@ -10,6 +10,7 @@ For running LTP network tests see `testcases/network/README.md`.
>  |==============================================================================
>  | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
>                            the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
> +| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check, the default is empty (don't skip).
s/empty/not set/ ?
maybe: Skip kernel config check if variable set (not set by default).

...

> +static int kconfig_skip_check(void)
> +{
> +	char *skipped = getenv("KCONFIG_SKIP_CHECK");
> +
> +	if (skipped)
> +		return 1;
> +
> +	return 0;
> +}
> +
>  static const char *kconfig_path(char *path_buf, size_t path_buf_len)
>  {
>  	const char *path = getenv("KCONFIG_PATH");
> @@ -485,6 +495,11 @@ int tst_kconfig_check(const char *const kconfigs[])
>  	unsigned int i, var_cnt;
>  	int ret = 0;

> +	if (kconfig_skip_check()) {
> +		tst_res(TINFO, "Skipping kernel config check as requested");
I suppose you expect tests / library use kconfig_skip_check() in the future for
some detection. If not I'd move tst_res(TINFO, ...) into kconfig_skip_check().

Otherwise LGTM.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target
  2022-01-11  6:10                       ` [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target Yang Xu
@ 2022-01-13 11:25                         ` Petr Vorel
  2022-01-13 15:54                         ` Cyril Hrubis
  1 sibling, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-13 11:25 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu,

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks!

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-11  8:37                           ` xuyang2018.jy
  2022-01-13  9:15                             ` xuyang2018.jy
@ 2022-01-13 15:51                             ` Cyril Hrubis
  2022-01-14  6:26                               ` xuyang2018.jy
  1 sibling, 1 reply; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-13 15:51 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi!
> int main(int argc, char *argv[])
> {
>          char *str = argv[1];
>          char *delim = argv[2];
>          unsigned int i, cnt = 1;
>          int ret = 0;
> 
>          if (argc == 2) {
>                  delim = ",";
>          } else if (argc == 3) {
>                  if (strlen(delim) > 1) {
>                          fprintf(stderr, "The delim must be a single 
> character\n");
>                          return 1;
>                  }
>          } else {
>                  fprintf(stderr, "Please provide kernel kconfig list and 
> delim "
>                                  "(optinal, default value is ',')\n");
>                  return 1;
>          }

We can make the code a bit easier to read with a switch()

	switch (argc) {
	case 2:
		delim = ",";
	break;
	case 3:
		if (strlen(delim) > 1) {
			fprintf(stderr, "...");
			return 1;
		}
	break;
	default:
		fprintf(stderr, "...");
		return 1;
	}


>          for (i = 0; str[i]; i++) {
>                  if (str[i] == delim[0])
>                          cnt++;
>          }
> 
>          char **kconfigs = malloc(++cnt * sizeof(char *));

It's unlikely that this will fail the allocation, but for the sake of
correctness we should also do:

	if (!kconfigs) {
		fprintf(stderr, "malloc failed");
		return 1;
	}

>          for (i = 0; i < cnt; i++)
>                  kconfigs[i] = strtok_r(str, delim, &str);
> 
>          if (tst_kconfig_check((const char * const*)kconfigs))
>                  ret = 1;
> 
>          free(kconfigs);
>          return ret;
> }

Other than the two minor issues this version looks good to me:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-11  6:10                       ` [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
  2022-01-13 10:53                         ` Petr Vorel
@ 2022-01-13 15:54                         ` Cyril Hrubis
  1 sibling, 0 replies; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-13 15:54 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target
  2022-01-11  6:10                       ` [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target Yang Xu
  2022-01-13 11:25                         ` Petr Vorel
@ 2022-01-13 15:54                         ` Cyril Hrubis
  1 sibling, 0 replies; 74+ messages in thread
From: Cyril Hrubis @ 2022-01-13 15:54 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api
  2022-01-13 10:53                         ` Petr Vorel
@ 2022-01-13 16:06                           ` Petr Vorel
  0 siblings, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-13 16:06 UTC (permalink / raw)
  To: Yang Xu, ltp

Hi Xu, all,

> If we agree TST_NEEDS_KCONFIGS is better in this case how about to put
> sysctl_test_zero into separate file? It could then define things required setup
> in TST_NEEDS_KCONFIGS.
I'm sorry, I overlook config for CONFIG_KASAN.
Splitting into separate file can be done in separate effort.
Thus let's not block this:
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable
  2022-01-13 11:09                         ` Petr Vorel
@ 2022-01-14  5:36                           ` xuyang2018.jy
  0 siblings, 0 replies; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-14  5:36 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi Petr
> Hi Xu,
>
>> This environment variable is designed to add kernel config check functionality
>> switch. So we can skip kconfig check completely and it is useful especially
>> for the embedded platforms that they don't have kernel config.
>
> very nit: I'd write it a bit simpler. Maybe:
> Add environment variable to disable kernel config check functionality.
> It is useful for embedded platforms which don't have kernel config installed.
>
>> +++ b/doc/user-guide.txt
>> @@ -10,6 +10,7 @@ For running LTP network tests see `testcases/network/README.md`.
>>   |==============================================================================
>>   | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
>>                             the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
>> +| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check, the default is empty (don't skip).
> s/empty/not set/ ?
> maybe: Skip kernel config check if variable set (not set by default).
>
Sounds reasonable.
> ...
>
>> +static int kconfig_skip_check(void)
>> +{
>> +	char *skipped = getenv("KCONFIG_SKIP_CHECK");
>> +
>> +	if (skipped)
>> +		return 1;
>> +
>> +	return 0;
>> +}
>> +
>>   static const char *kconfig_path(char *path_buf, size_t path_buf_len)
>>   {
>>   	const char *path = getenv("KCONFIG_PATH");
>> @@ -485,6 +495,11 @@ int tst_kconfig_check(const char *const kconfigs[])
>>   	unsigned int i, var_cnt;
>>   	int ret = 0;
>
>> +	if (kconfig_skip_check()) {
>> +		tst_res(TINFO, "Skipping kernel config check as requested");
> I suppose you expect tests / library use kconfig_skip_check() in the future for
> some detection. If not I'd move tst_res(TINFO, ...) into kconfig_skip_check().
I don't have this plan. So move it into kconfig_skip_check().

Best Regards
Yang Xu
>
> Otherwise LGTM.
>
> Reviewed-by: Petr Vorel<pvorel@suse.cz>
>
> Kind regards,
> Petr

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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-13 15:51                             ` Cyril Hrubis
@ 2022-01-14  6:26                               ` xuyang2018.jy
  2022-01-14  9:19                                 ` xuyang2018.jy
  0 siblings, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-14  6:26 UTC (permalink / raw)
  To: Cyril Hrubis, Li Wang, Petr Vorel; +Cc: ltp

Hi Cyril, Li, Petr

> Hi!
>> int main(int argc, char *argv[])
>> {
>>           char *str = argv[1];
>>           char *delim = argv[2];
>>           unsigned int i, cnt = 1;
>>           int ret = 0;
>>
>>           if (argc == 2) {
>>                   delim = ",";
>>           } else if (argc == 3) {
>>                   if (strlen(delim)>  1) {
>>                           fprintf(stderr, "The delim must be a single
>> character\n");
>>                           return 1;
>>                   }
>>           } else {
>>                   fprintf(stderr, "Please provide kernel kconfig list and
>> delim "
>>                                   "(optinal, default value is ',')\n");
>>                   return 1;
>>           }
>
> We can make the code a bit easier to read with a switch()
>
> 	switch (argc) {
> 	case 2:
> 		delim = ",";
> 	break;
> 	case 3:
> 		if (strlen(delim)>  1) {
> 			fprintf(stderr, "...");
> 			return 1;
> 		}
> 	break;
> 	default:
> 		fprintf(stderr, "...");
> 		return 1;
> 	}
>
>
>>           for (i = 0; str[i]; i++) {
>>                   if (str[i] == delim[0])
>>                           cnt++;
>>           }
>>
>>           char **kconfigs = malloc(++cnt * sizeof(char *));
>
> It's unlikely that this will fail the allocation, but for the sake of
> correctness we should also do:
>
> 	if (!kconfigs) {
> 		fprintf(stderr, "malloc failed");
> 		return 1;
> 	}
>
>>           for (i = 0; i<  cnt; i++)
>>                   kconfigs[i] = strtok_r(str, delim,&str);
>>
>>           if (tst_kconfig_check((const char * const*)kconfigs))
>>                   ret = 1;
>>
>>           free(kconfigs);
>>           return ret;
>> }
>
> Other than the two minor issues this version looks good to me:

I modify this patch with the above comment and also move tst_res into
kconfig_skip_check in the 2nd patch. Then I pushed this patchset.

Thanks for your patient review.

Best Regards
Yang Xu
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>

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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-14  6:26                               ` xuyang2018.jy
@ 2022-01-14  9:19                                 ` xuyang2018.jy
  2022-01-14  9:49                                   ` Petr Vorel
  0 siblings, 1 reply; 74+ messages in thread
From: xuyang2018.jy @ 2022-01-14  9:19 UTC (permalink / raw)
  To: Cyril Hrubis, Li Wang, Petr Vorel; +Cc: ltp

Hi Petr

I find  ltp doesn't update wiki automatically. Or I miss something?

This occurs the last patch doesn't update doc when we merged a patchset.

Best Regards
Yang Xu
> Hi Cyril, Li, Petr
>
>> Hi!
>>> int main(int argc, char *argv[])
>>> {
>>>            char *str = argv[1];
>>>            char *delim = argv[2];
>>>            unsigned int i, cnt = 1;
>>>            int ret = 0;
>>>
>>>            if (argc == 2) {
>>>                    delim = ",";
>>>            } else if (argc == 3) {
>>>                    if (strlen(delim)>   1) {
>>>                            fprintf(stderr, "The delim must be a single
>>> character\n");
>>>                            return 1;
>>>                    }
>>>            } else {
>>>                    fprintf(stderr, "Please provide kernel kconfig list and
>>> delim "
>>>                                    "(optinal, default value is ',')\n");
>>>                    return 1;
>>>            }
>>
>> We can make the code a bit easier to read with a switch()
>>
>> 	switch (argc) {
>> 	case 2:
>> 		delim = ",";
>> 	break;
>> 	case 3:
>> 		if (strlen(delim)>   1) {
>> 			fprintf(stderr, "...");
>> 			return 1;
>> 		}
>> 	break;
>> 	default:
>> 		fprintf(stderr, "...");
>> 		return 1;
>> 	}
>>
>>
>>>            for (i = 0; str[i]; i++) {
>>>                    if (str[i] == delim[0])
>>>                            cnt++;
>>>            }
>>>
>>>            char **kconfigs = malloc(++cnt * sizeof(char *));
>>
>> It's unlikely that this will fail the allocation, but for the sake of
>> correctness we should also do:
>>
>> 	if (!kconfigs) {
>> 		fprintf(stderr, "malloc failed");
>> 		return 1;
>> 	}
>>
>>>            for (i = 0; i<   cnt; i++)
>>>                    kconfigs[i] = strtok_r(str, delim,&str);
>>>
>>>            if (tst_kconfig_check((const char * const*)kconfigs))
>>>                    ret = 1;
>>>
>>>            free(kconfigs);
>>>            return ret;
>>> }
>>
>> Other than the two minor issues this version looks good to me:
>
> I modify this patch with the above comment and also move tst_res into
> kconfig_skip_check in the 2nd patch. Then I pushed this patchset.
>
> Thanks for your patient review.
>
> Best Regards
> Yang Xu
>>
>> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>>
>

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

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

* Re: [LTP] [PATCH v4 3/5] shell: add kconfig parse api
  2022-01-14  9:19                                 ` xuyang2018.jy
@ 2022-01-14  9:49                                   ` Petr Vorel
  0 siblings, 0 replies; 74+ messages in thread
From: Petr Vorel @ 2022-01-14  9:49 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi Xu,

> Hi Petr

> I find  ltp doesn't update wiki automatically. Or I miss something?

> This occurs the last patch doesn't update doc when we merged a patchset.
Hm, I need to look into it.
Thx for info.

Kind regards,
Petr

> Best Regards
> Yang Xu

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

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

end of thread, other threads:[~2022-01-14  9:49 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04  6:57 [LTP] [PATCH v1 1/3] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-04  6:57 ` [LTP] [PATCH v1 2/3] shell: add kconfig parse api Yang Xu
2022-01-04 11:04   ` Petr Vorel
2022-01-05  7:15     ` xuyang2018.jy
2022-01-05 14:34       ` Petr Vorel
2022-01-06  5:59         ` xuyang2018.jy
2022-01-06  8:16           ` xuyang2018.jy
2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
2022-01-06  9:49             ` Petr Vorel
2022-01-06  9:52             ` Petr Vorel
2022-01-06 11:07             ` Cyril Hrubis
2022-01-06 11:50               ` Petr Vorel
2022-01-06 13:59                 ` Cyril Hrubis
2022-01-06 17:41                   ` Petr Vorel
2022-01-07  2:00                   ` xuyang2018.jy
2022-01-06  9:25           ` [LTP] [PATCH v2 3/4] shell: add kconfig parse api Yang Xu
2022-01-06 10:40             ` Petr Vorel
2022-01-06 11:19             ` Cyril Hrubis
2022-01-07  3:54               ` Li Wang
2022-01-07  4:08                 ` xuyang2018.jy
2022-01-07  7:04                   ` Li Wang
2022-01-07  8:28                     ` xuyang2018.jy
2022-01-07  8:41                       ` Li Wang
2022-01-07  9:46                         ` Cyril Hrubis
2022-01-07  9:56                           ` xuyang2018.jy
2022-01-07  9:05                       ` Petr Vorel
2022-01-07  9:22                         ` xuyang2018.jy
2022-01-07 12:07                           ` Petr Vorel
2022-01-07  7:33                 ` Petr Vorel
2022-01-06  9:25           ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
2022-01-06 11:20             ` Cyril Hrubis
2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
2022-01-10  8:14                   ` Li Wang
2022-01-10 12:20                   ` Cyril Hrubis
2022-01-11  1:38                     ` xuyang2018.jy
2022-01-10  1:49                 ` [LTP] [PATCH v3 3/4] shell: add kconfig parse api Yang Xu
2022-01-10  8:26                   ` Li Wang
2022-01-10  8:46                     ` xuyang2018.jy
2022-01-10  9:13                       ` Li Wang
2022-01-10 13:43                   ` Cyril Hrubis
2022-01-11  5:29                     ` xuyang2018.jy
2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-11  6:10                       ` [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
2022-01-13 11:09                         ` Petr Vorel
2022-01-14  5:36                           ` xuyang2018.jy
2022-01-11  6:10                       ` [LTP] [PATCH v4 3/5] shell: add kconfig parse api Yang Xu
2022-01-11  7:52                         ` Li Wang
2022-01-11  8:37                           ` xuyang2018.jy
2022-01-13  9:15                             ` xuyang2018.jy
2022-01-13  9:42                               ` Li Wang
2022-01-13 15:51                             ` Cyril Hrubis
2022-01-14  6:26                               ` xuyang2018.jy
2022-01-14  9:19                                 ` xuyang2018.jy
2022-01-14  9:49                                   ` Petr Vorel
2022-01-11  6:10                       ` [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
2022-01-13 10:53                         ` Petr Vorel
2022-01-13 16:06                           ` Petr Vorel
2022-01-13 15:54                         ` Cyril Hrubis
2022-01-11  6:10                       ` [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target Yang Xu
2022-01-13 11:25                         ` Petr Vorel
2022-01-13 15:54                         ` Cyril Hrubis
2022-01-10  1:49                 ` [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
2022-01-10  8:30                   ` Li Wang
2022-01-10 14:15                   ` Cyril Hrubis
2022-01-11  5:34                     ` xuyang2018.jy
2022-01-10  8:10                 ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Li Wang
2022-01-10 12:18                 ` Cyril Hrubis
2022-01-10  5:45               ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api xuyang2018.jy
2022-01-06  9:54           ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Petr Vorel
2022-01-06 10:57           ` Cyril Hrubis
2022-01-07  1:25             ` xuyang2018.jy
2022-01-04  6:57 ` [LTP] [PATCH v1 3/3] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.