From: Brendan Jackman <jackmanb@google.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Brendan Jackman <jackmanb@google.com>
Subject: [PATCH v2 2/9] selftests/mm: Fix assumption that sudo is present
Date: Fri, 21 Feb 2025 18:25:41 +0000 [thread overview]
Message-ID: <20250221-mm-selftests-v2-2-28c4d66383c5@google.com> (raw)
In-Reply-To: <20250221-mm-selftests-v2-0-28c4d66383c5@google.com>
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.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/run_vmtests.sh | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
index da7e266681031d2772fb0c4139648904a18e0bf9..9c963f50927ab2b10c3f942cedd087087d4d0def 100755
--- a/tools/testing/selftests/mm/run_vmtests.sh
+++ b/tools/testing/selftests/mm/run_vmtests.sh
@@ -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 ;;
@@ -384,10 +395,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
--
2.48.1.601.g30ceb7b040-goog
next prev parent reply other threads:[~2025-02-21 18:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 1/9] selftests/mm: Report errno when things fail in gup_longterm Brendan Jackman
2025-02-21 18:25 ` Brendan Jackman [this message]
2025-02-21 18:25 ` [PATCH v2 3/9] selftests/mm: Skip uffd-stress if userfaultfd not available Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 4/9] selftests/mm: Skip uffd-wp-mremap " Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 5/9] selftests/mm/uffd: Rename nr_cpus -> nr_threads Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 6/9] selftests/mm: Print some details when uffd-stress gets bad params Brendan Jackman
2025-02-28 12:47 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 7/9] selftests/mm: Don't fail uffd-stress if too many CPUs Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems Brendan Jackman
2025-02-24 10:25 ` Brendan Jackman
2025-02-27 12:58 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 9/9] selftests/mm: Skip gup_longerm tests " Brendan Jackman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250221-mm-selftests-v2-2-28c4d66383c5@google.com \
--to=jackmanb@google.com \
--cc=akpm@linux-foundation.org \
--cc=dev.jain@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox