[LTP] [PATCH 2/4] lib: shell: Add TST_SKIP_IN_SECUREBOOT=1

Petr Vorel pvorel@suse.cz
Fri Jul 28 15:21:15 CEST 2023


And tst_secureboot_enabled.c helper.
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_secureboot_enabled.c | 12 ++++++++++++
 testcases/lib/tst_test.sh              |  6 +++++-
 5 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 testcases/lib/tst_secureboot_enabled.c

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 367fa780b..4ee9199ab 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -393,7 +393,7 @@ https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API].
 | '.skip_filesystems' | 'TST_SKIP_FILESYSTEMS'
 | '.skip_in_compat' | –
 | '.skip_in_lockdown' | 'TST_SKIP_IN_LOCKDOWN'
-| '.skip_in_secureboot' | –
+| '.skip_in_secureboot' | 'TST_SKIP_IN_SECUREBOOT'
 | '.supported_archs' | not applicable
 | '.tags' | –
 | '.taint_check' | –
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index b824767f7..e8afd06f3 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -19,6 +19,7 @@
 /tst_ns_ifmove
 /tst_random
 /tst_rod
+/tst_secureboot_enabled
 /tst_sleep
 /tst_supported_fs
 /tst_timeout_kill
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index 3094aa463..990b46089 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -13,6 +13,6 @@ MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   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_fsfreeze tst_ns_create tst_ns_exec\
-			   tst_ns_ifmove tst_lockdown_enabled
+			   tst_ns_ifmove tst_lockdown_enabled tst_secureboot_enabled
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_secureboot_enabled.c b/testcases/lib/tst_secureboot_enabled.c
new file mode 100644
index 000000000..7c26fb118
--- /dev/null
+++ b/testcases/lib/tst_secureboot_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_secureboot_enabled();
+}
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index afcf66b20..b5b38f524 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_IN_LOCKDOWN);;
+			SKIP_FILESYSTEMS|SKIP_IN_LOCKDOWN|SKIP_IN_SECUREBOOT);;
 			*) 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_SECUREBOOT" = 1 ] && tst_secureboot_enabled; then
+		tst_brk TCONF "SecureBoot enabled, skipping test"
+	fi
+
 	if [ "$TST_SKIP_IN_LOCKDOWN" = 1 ] && tst_lockdown_enabled; then
 		tst_brk TCONF "Kernel is locked down, skipping test"
 	fi
-- 
2.41.0



More information about the ltp mailing list