Skip to contentSkip to conversation

selftests/filesystems: Fix run_fat_tests hang

PATCH New Shuah Khan 1 participant 1 message Oct 21

Subsystems (2)
lore
Share & tools
lore

Shuah Khan

author maintainer
#0 lore raw

PATCH 1/1 selftests/filesystems: Fix run_fat_tests hang

run_fat_tests script hangs waiting at sudo prompt preventing the kselftest default test to complete when a non-privileged user runs the test. This is incorrect test behavior. Fix it to test for root and skip the test.

---
 .../selftests/filesystems/fat/run_fat_tests.sh     | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tools/testing/selftests/filesystems/fat/run_fat_tests.sh +14 -0
index d61264d4795d..0712c8d23fd7 100755
@@ -15,6 +15,8 @@ BASE_DIR="$(dirname $0)"
 TMP_DIR="$(mktemp -d /tmp/fat_tests_tmp.XXXXXX)"
 IMG_PATH="${TMP_DIR}/fat.img"
 MNT_PATH="${TMP_DIR}/mnt"
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
 
 cleanup()
 {
@@ -23,6 +25,17 @@ cleanup()
 }
 trap cleanup SIGINT SIGTERM EXIT
 
+check_prereqs()
+{
+        local msg="skip all tests:"
+        local uid=$(id -u)
+
+        if [ $uid -ne 0 ]; then
+                echo $msg must be run as root >&2
+                exit $ksft_skip
+        fi
+}
+
 create_loopback()
 {
     touch "${IMG_PATH}"
@@ -73,6 +86,7 @@ unmount_image()
     sudo umount "${MNT_PATH}" &> /dev/null
 }
 
+check_prereqs
 create_loopback
 mount_image
 rename_exchange_test
Signature · 1 line
2.48.1