[LTP] [PATCH 1/2] lib: shell: Add tst_lockdown_enabled.c

Petr Vorel pvorel@suse.cz
Wed Mar 8 10:32:18 CET 2023


Detection is needed for insmod01.sh.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 doc/test-writing-guidelines.txt      |  2 +-
 testcases/lib/.gitignore             |  1 +
 testcases/lib/Makefile               |  2 +-
 testcases/lib/tst_lockdown_enabled.c | 12 ++++++++++++
 testcases/lib/tst_test.sh            |  6 +++++-
 5 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 testcases/lib/tst_lockdown_enabled.c

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index b83a6fdb6..875c20eae 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -392,7 +392,7 @@ https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API].
 | '.setup' | 'TST_SETUP'
 | '.skip_filesystems' | 'TST_SKIP_FILESYSTEMS'
 | '.skip_in_compat' | –
-| '.skip_in_lockdown' | –
+| '.skip_in_lockdown' | 'TST_SKIP_IN_LOCKDOWN'
 | '.supported_archs' | not applicable
 | '.tags' | –
 | '.taint_check' | –
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 34dea272d..61cf05226 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -8,6 +8,7 @@
 /tst_get_median
 /tst_get_unused_port
 /tst_kvcmp
+/tst_lockdown_enabled
 /tst_net_iface_prefix
 /tst_net_ip_prefix
 /tst_net_vars
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index f4f8c8524..6fd58b3ab 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -12,6 +12,6 @@ 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_check_kconfigs tst_cgctl
+			   tst_check_kconfigs tst_cgctl tst_lockdown_enabled
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_lockdown_enabled.c b/testcases/lib/tst_lockdown_enabled.c
new file mode 100644
index 000000000..0e40c428c
--- /dev/null
+++ b/testcases/lib/tst_lockdown_enabled.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Petr Vorel <pvorel@suse.cz>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+int main(void)
+{
+	return !tst_lockdown_enabled();
+}
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index c817eec77..50939d4e4 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -678,7 +678,7 @@ tst_run()
 			CHECKPOINT_WAIT|CHECKPOINT_WAKE);;
 			CHECKPOINT_WAKE2|CHECKPOINT_WAKE_AND_WAIT);;
 			DEV_EXTRA_OPTS|DEV_FS_OPTS|FORMAT_DEVICE|MOUNT_DEVICE);;
-			SKIP_FILESYSTEMS);;
+			SKIP_FILESYSTEMS|SKIP_IN_LOCKDOWN);;
 			*) tst_res TWARN "Reserved variable TST_$_tst_i used!";;
 			esac
 		done
@@ -698,6 +698,10 @@ tst_run()
 
 	[ "$TST_NEEDS_ROOT" = 1 ] && tst_require_root
 
+	if [ "$TST_SKIP_IN_LOCKDOWN" = 1 ] && tst_lockdown_enabled; then
+		tst_brk TCONF "Kernel is locked down, skipping test"
+	fi
+
 	[ "$TST_DISABLE_APPARMOR" = 1 ] && tst_disable_apparmor
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
 
-- 
2.39.2



More information about the ltp mailing list