]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/mm: fix assumption that sudo is present
authorBrendan Jackman <jackmanb@google.com>
Fri, 21 Feb 2025 18:25:41 +0000 (18:25 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 28 Feb 2025 01:00:26 +0000 (17:00 -0800)
If we are root, sudo isn't needed.  If we are not root, we need sudo, so
skip the test if it isn't present.

We already do this for on-fault-limit, but this uses separate
infrastructure since that is specifically for sudo-ing to the nobody user.

Note this ptrace_skip configuration still fails if that file doesn't
exist, but in that case the test is still fine, so this just prints an
error but doesn't break anything.  I suspect that's probably deliberate.

Link: https://lkml.kernel.org/r/20250221-mm-selftests-v2-2-28c4d66383c5@google.com
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Shuah Khan (Samsung OSG) <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/run_vmtests.sh

index d3866b50a6e16a9ba08b6cf33d131edf2a9226be..fe3606de37f944d7a5110226485c63b440558490 100755 (executable)
@@ -89,6 +89,17 @@ RUN_ALL=false
 RUN_DESTRUCTIVE=false
 TAP_PREFIX="# "
 
+# We can do stuff as root either if we are already root, or if sudo exists.
+if [ "$(id -u)" == 0 ]; then
+       HAVE_SUDO_ROOT=true
+       SUDO_ROOT=
+elif command -v sudo >/dev/null 2>&1; then
+       HAVE_SUDO_ROOT=true
+       SUDO_ROOT=sudo
+else
+       HAVE_SUDO_ROOT=false
+fi
+
 while getopts "aht:n" OPT; do
        case ${OPT} in
                "a") RUN_ALL=true ;;
@@ -398,10 +409,13 @@ CATEGORY="madv_guard" run_test ./guard-pages
 # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
 CATEGORY="madv_populate" run_test ./madv_populate
 
-if [ -x ./memfd_secret ]
-then
-(echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix
-CATEGORY="memfd_secret" run_test ./memfd_secret
+if [ -x ./memfd_secret ]; then
+       if $HAVE_SUDO_ROOT; then
+               (echo 0 | $SUDO_ROOT tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix
+               CATEGORY="memfd_secret" run_test ./memfd_secret
+       else
+               echo "# SKIP ./memfd_secret"
+       fi
 fi
 
 # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100