[<prev] [next>] [day] [month] [year] [list]
Message-ID: <201911211052.90C65FD667@keescook>
Date:   Thu, 21 Nov 2019 10:53:20 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Shuah Khan <shuah@...nel.org>
Cc:     Matthieu Baerts <matthieu.baerts@...sares.net>,
        linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] selftests: Load settings from subdirs
If settings files are present in upper directories of a test directory,
load those first before the local settings. This allows a top-level
directory to define settings for subdirectories while still allowing the
subdirectories to override them on a per-directory basis.
Signed-off-by: Kees Cook <keescook@...omium.org>
---
Note that this depends on Matt's patch:
https://lore.kernel.org/lkml/20191022171223.27934-1-matthieu.baerts@tessares.net
---
 tools/testing/selftests/kselftest/runner.sh | 30 +++++++++++++++------
 1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index 84de7bc74f2c..666cfeaa8046 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -39,6 +39,27 @@ tap_timeout()
 	fi
 }
 
+load_settings()
+{
+	local fullpath="$1"
+	local upperpath=${fullpath%/*}
+
+	# Load upper path settings first.
+	if [ "$fullpath" != "$upperpath" ] ; then
+		load_settings "$upperpath"
+	fi
+
+	# Load per-test-directory kselftest "settings" file.
+	local settings="$BASE_DIR/$fullpath/settings"
+	if [ -r "$settings" ] ; then
+		while read line ; do
+			local field=$(echo "$line" | cut -d= -f1)
+			local value=$(echo "$line" | cut -d= -f2-)
+			eval "kselftest_$field"="$value"
+		done < "$settings"
+	fi
+}
+
 run_one()
 {
 	DIR="$1"
@@ -50,14 +71,7 @@ run_one()
 	# Reset any "settings"-file variables.
 	export kselftest_timeout="$kselftest_default_timeout"
 	# Load per-test-directory kselftest "settings" file.
-	settings="$BASE_DIR/$DIR/settings"
-	if [ -r "$settings" ] ; then
-		while read line ; do
-			field=$(echo "$line" | cut -d= -f1)
-			value=$(echo "$line" | cut -d= -f2-)
-			eval "kselftest_$field"="$value"
-		done < "$settings"
-	fi
+	load_settings "$DIR"
 
 	TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
 	echo "# $TEST_HDR_MSG"
-- 
2.17.1
-- 
Kees Cook
Powered by blists - more mailing lists