Skip to content

Commit

Permalink
KVM: selftests: Avoid assuming "sudo" exists in NX hugepage test
Browse files Browse the repository at this point in the history
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 <jackmanb@google.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20240415-kvm-selftests-no-sudo-v1-1-95153ad5f470@google.com
[sean: name the helper do_sudo() instead of maybe_sudo(), massage changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
bjackman authored and sean-jc committed Apr 29, 2024
1 parent 72cd4de commit 0540193
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ NX_HUGE_PAGES_RECOVERY_RATIO=$(cat /sys/module/kvm/parameters/nx_huge_pages_reco
NX_HUGE_PAGES_RECOVERY_PERIOD=$(cat /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms)
HUGE_PAGES=$(cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages)

# If we're already root, the host might not have sudo.
if [ $(whoami) == "root" ]; then
function do_sudo () {
"$@"
}
else
function do_sudo () {
sudo "$@"
}
fi

set +e

function sudo_echo () {
echo "$1" | sudo tee -a "$2" > /dev/null
echo "$1" | do_sudo tee -a "$2" > /dev/null
}

NXECUTABLE="$(dirname $0)/nx_huge_pages_test"
Expand Down

0 comments on commit 0540193

Please sign in to comment.