kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Avoid assuming "sudo" exists
@ 2024-04-15 14:43 Brendan Jackman
  2024-04-15 18:46 ` Muhammad Usama Anjum
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Brendan Jackman @ 2024-04-15 14:43 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Shuah Khan
  Cc: kvm, linux-kselftest, linux-kernel, Brendan Jackman

I ran into a failure running this test on a minimal rootfs.

Can be fixed by just skipping the "sudo" in case we are already root.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
index 7cbb409801eea..0e56822e8e0bf 100755
--- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
+++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
@@ -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 maybe_sudo () {
+		"$@"
+	}
+else
+	function maybe_sudo () {
+		sudo "$@"
+	}
+fi
+
 set +e
 
 function sudo_echo () {
-	echo "$1" | sudo tee -a "$2" > /dev/null
+	echo "$1" | maybe_sudo tee -a "$2" > /dev/null
 }
 
 NXECUTABLE="$(dirname $0)/nx_huge_pages_test"

---
base-commit: 2c71fdf02a95b3dd425b42f28fd47fb2b1d22702
change-id: 20240415-kvm-selftests-no-sudo-1a55f831f882

Best regards,
-- 
Brendan Jackman <jackmanb@google.com>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: Avoid assuming "sudo" exists
  2024-04-15 14:43 [PATCH] KVM: selftests: Avoid assuming "sudo" exists Brendan Jackman
@ 2024-04-15 18:46 ` Muhammad Usama Anjum
  2024-04-25 23:10 ` Sean Christopherson
  2024-04-29 20:45 ` Sean Christopherson
  2 siblings, 0 replies; 5+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-15 18:46 UTC (permalink / raw)
  To: Brendan Jackman, Sean Christopherson, Paolo Bonzini, Shuah Khan
  Cc: Muhammad Usama Anjum, kvm, linux-kselftest, linux-kernel

On 4/15/24 7:43 PM, Brendan Jackman wrote:
> I ran into a failure running this test on a minimal rootfs.
I've ran into similar issue before for another test. Its clever solution.

> 
> Can be fixed by just skipping the "sudo" in case we are already root.
> 
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> index 7cbb409801eea..0e56822e8e0bf 100755
> --- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> @@ -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 maybe_sudo () {
> +		"$@"
> +	}
> +else
> +	function maybe_sudo () {
> +		sudo "$@"
> +	}
> +fi
> +
>  set +e
>  
>  function sudo_echo () {
> -	echo "$1" | sudo tee -a "$2" > /dev/null
> +	echo "$1" | maybe_sudo tee -a "$2" > /dev/null
>  }
>  
>  NXECUTABLE="$(dirname $0)/nx_huge_pages_test"
> 
> ---
> base-commit: 2c71fdf02a95b3dd425b42f28fd47fb2b1d22702
> change-id: 20240415-kvm-selftests-no-sudo-1a55f831f882
> 
> Best regards,

-- 
BR,
Muhammad Usama Anjum

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: Avoid assuming "sudo" exists
  2024-04-15 14:43 [PATCH] KVM: selftests: Avoid assuming "sudo" exists Brendan Jackman
  2024-04-15 18:46 ` Muhammad Usama Anjum
@ 2024-04-25 23:10 ` Sean Christopherson
  2024-04-26 10:13   ` Brendan Jackman
  2024-04-29 20:45 ` Sean Christopherson
  2 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2024-04-25 23:10 UTC (permalink / raw)
  To: Brendan Jackman
  Cc: Paolo Bonzini, Shuah Khan, kvm, linux-kselftest, linux-kernel

On Mon, Apr 15, 2024, Brendan Jackman wrote:
> I ran into a failure running this test on a minimal rootfs.
> 
> Can be fixed by just skipping the "sudo" in case we are already root.
> 
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> ---
>  tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> index 7cbb409801eea..0e56822e8e0bf 100755
> --- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> @@ -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 maybe_sudo () {

Any objection to do_sudo instead of maybe_sudo?  I can fixup when applying if
that works for you.

> +		"$@"
> +	}
> +else
> +	function maybe_sudo () {
> +		sudo "$@"
> +	}
> +fi
> +
>  set +e
>  
>  function sudo_echo () {
> -	echo "$1" | sudo tee -a "$2" > /dev/null
> +	echo "$1" | maybe_sudo tee -a "$2" > /dev/null
>  }
>  
>  NXECUTABLE="$(dirname $0)/nx_huge_pages_test"
> 
> ---
> base-commit: 2c71fdf02a95b3dd425b42f28fd47fb2b1d22702
> change-id: 20240415-kvm-selftests-no-sudo-1a55f831f882
> 
> Best regards,
> -- 
> Brendan Jackman <jackmanb@google.com>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: Avoid assuming "sudo" exists
  2024-04-25 23:10 ` Sean Christopherson
@ 2024-04-26 10:13   ` Brendan Jackman
  0 siblings, 0 replies; 5+ messages in thread
From: Brendan Jackman @ 2024-04-26 10:13 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Shuah Khan, kvm, linux-kselftest, linux-kernel

On Fri, 26 Apr 2024 at 01:10, Sean Christopherson <seanjc@google.com> wrote:
>
> On Mon, Apr 15, 2024, Brendan Jackman wrote:
[...]
> > +     function maybe_sudo () {
>
> Any objection to do_sudo instead of maybe_sudo?  I can fixup when applying if
> that works for you.

Sounds good to me :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: Avoid assuming "sudo" exists
  2024-04-15 14:43 [PATCH] KVM: selftests: Avoid assuming "sudo" exists Brendan Jackman
  2024-04-15 18:46 ` Muhammad Usama Anjum
  2024-04-25 23:10 ` Sean Christopherson
@ 2024-04-29 20:45 ` Sean Christopherson
  2 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2024-04-29 20:45 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Shuah Khan, Brendan Jackman
  Cc: kvm, linux-kselftest, linux-kernel

On Mon, 15 Apr 2024 14:43:54 +0000, Brendan Jackman wrote:
> I ran into a failure running this test on a minimal rootfs.
> 
> Can be fixed by just skipping the "sudo" in case we are already root.

Applied to kvm-x86 selftests, thanks!

[1/1] KVM: selftests: Avoid assuming "sudo" exists
      https://github.com/kvm-x86/linux/commit/0540193614eb

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-29 20:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 14:43 [PATCH] KVM: selftests: Avoid assuming "sudo" exists Brendan Jackman
2024-04-15 18:46 ` Muhammad Usama Anjum
2024-04-25 23:10 ` Sean Christopherson
2024-04-26 10:13   ` Brendan Jackman
2024-04-29 20:45 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).