diff mbox series

[ima-evm-utils,7/8] Adapt fsverity.test to work with UML kernel

Message ID 20230109165552.3409716-8-roberto.sassu@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series Support testing with UML kernel | expand

Commit Message

Roberto Sassu Jan. 9, 2023, 4:55 p.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com>

Adapt fsverity.test by adding calls to the UML kernel API in functions.sh.
If the UML_MODE environment variable is set to 1, run first the UML kernel
specified as first argument of _run_user_mode() and execute the tests in
the new environment. Otherwise, keep the current behavior.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 tests/fsverity.test | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tests/fsverity.test b/tests/fsverity.test
index 549c42a32608..84312aa08a30 100755
--- a/tests/fsverity.test
+++ b/tests/fsverity.test
@@ -49,7 +49,7 @@  _require dd mkfs blkid e2fsck tune2fs evmctl setfattr
 
 trap cleanup SIGINT SIGTERM EXIT
 
-cleanup() {
+_cleanup() {
         if [ -e $TST_MNT ]; then
 		if [ $LOOPBACK_MOUNTED -eq 1 ]; then
 			umount $TST_MNT
@@ -61,6 +61,11 @@  cleanup() {
 	_report_exit_and_cleanup
 }
 
+cleanup() {
+	_cleanup_user_mode _cleanup
+	_report_exit_and_cleanup
+}
+
 # Loopback mount a file
 mount_loopback_file() {
 	local ret
@@ -309,6 +314,15 @@  measure-ima() {
 	return "$error"
 }
 
+# Run in User Mode Linux.
+_run_user_mode ../linux $PWD/$(basename $0) "UML_MODE=$UML_MODE PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH VERBOSE=$VERBOSE"
+
+# Exit from the parent if UML was used.
+_exit_user_mode ../linux
+
+# Mount filesystems in UML environment.
+_init_user_mode
+
 # Dependency on being able to read and write the IMA policy file.
 # Requires both CONFIG_IMA_WRITE_POLICY, CONFIG_IMA_READ_POLICY be
 # enabled.