[kvm-unit-tests,v2,3/4] arm/run: introduce usingkvm var and use it
diff mbox

Message ID 1436252613-1540-4-git-send-email-alex.bennee@linaro.org
State New
Headers show

Commit Message

Alex Bennée July 7, 2015, 7:03 a.m. UTC
This makes the script a little cleaner by only checking for KVM support
in one place.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 arm/run | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Andrew Jones July 7, 2015, 11:36 a.m. UTC | #1
On Tue, Jul 07, 2015 at 08:03:32AM +0100, Alex Bennée wrote:
> This makes the script a little cleaner by only checking for KVM support
> in one place.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  arm/run | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/arm/run b/arm/run
> index 6b42a2e..493ce0d 100755
> --- a/arm/run
> +++ b/arm/run
> @@ -8,6 +8,16 @@ fi
>  source config.mak
>  processor="$PROCESSOR"
>  
> +# Default to using KVM if available and on the right ARM host
> +usingkvm=0

I actually prefer

usingkvm=no # or to just not declare it at all, or to do just usingkvm=

if [ should-use-kvm ]; then
	usingkvm=yes
fi

if [ "$usingkvm" = "yes" ]; then
...
fi

The reason is because '=' is a string comparison operator, so
you're using the string "0" and the string "1", but without
quotes. To use integers 0 and 1, the operator '-eq' is necessary.

Sorry, I should have mentioned that yesterday.

Thanks,
drew

> +if [ -c /dev/kvm ]; then
> +	if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
> +		usingkvm=1
> +	elif [ "$HOST" = "aarch64" ]; then
> +		usingkvm=1
> +	fi
> +fi
> +
>  qemu="${QEMU:-qemu-system-$ARCH_NAME}"
>  qpath=$(which $qemu 2>/dev/null)
>  
> @@ -39,7 +49,7 @@ chr_testdev='-device virtio-serial-device'
>  chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
>  
>  # arm64 must use '-cpu host' with kvm
> -if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then
> +if [ $usingkvm = 1 ] && [ "$ARCH" = "arm64" ]; then
>  	processor="host"
>  fi
>  
> -- 
> 2.4.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/arm/run b/arm/run
index 6b42a2e..493ce0d 100755
--- a/arm/run
+++ b/arm/run
@@ -8,6 +8,16 @@  fi
 source config.mak
 processor="$PROCESSOR"
 
+# Default to using KVM if available and on the right ARM host
+usingkvm=0
+if [ -c /dev/kvm ]; then
+	if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
+		usingkvm=1
+	elif [ "$HOST" = "aarch64" ]; then
+		usingkvm=1
+	fi
+fi
+
 qemu="${QEMU:-qemu-system-$ARCH_NAME}"
 qpath=$(which $qemu 2>/dev/null)
 
@@ -39,7 +49,7 @@  chr_testdev='-device virtio-serial-device'
 chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
 
 # arm64 must use '-cpu host' with kvm
-if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then
+if [ $usingkvm = 1 ] && [ "$ARCH" = "arm64" ]; then
 	processor="host"
 fi