Skip to content

Commit 0540193

Browse files
bjackmansean-jc
authored andcommitted
KVM: selftests: Avoid assuming "sudo" exists in NX hugepage test
Writing various root-only files, omit "sudo" when already running as root to allow running the NX hugepage test on systems with a minimal rootfs, i.e. without sudo. Signed-off-by: Brendan Jackman <[email protected]> Reviewed-by: Muhammad Usama Anjum <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: name the helper do_sudo() instead of maybe_sudo(), massage changelog] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 72cd4de commit 0540193

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ NX_HUGE_PAGES_RECOVERY_RATIO=$(cat /sys/module/kvm/parameters/nx_huge_pages_reco
1313
NX_HUGE_PAGES_RECOVERY_PERIOD=$(cat /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms)
1414
HUGE_PAGES=$(cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages)
1515

16+
# If we're already root, the host might not have sudo.
17+
if [ $(whoami) == "root" ]; then
18+
function do_sudo () {
19+
"$@"
20+
}
21+
else
22+
function do_sudo () {
23+
sudo "$@"
24+
}
25+
fi
26+
1627
set +e
1728

1829
function sudo_echo () {
19-
echo "$1" | sudo tee -a "$2" > /dev/null
30+
echo "$1" | do_sudo tee -a "$2" > /dev/null
2031
}
2132

2233
NXECUTABLE="$(dirname $0)/nx_huge_pages_test"

0 commit comments

Comments
 (0)