diff mbox

[kvm-unit-tests,5/5] arch/run: unify accelerator detection

Message ID 20170628200857.1718-6-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář June 28, 2017, 8:08 p.m. UTC
Use the same mechanism as search_qemu_binary().

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 arm/run               | 20 +-------------------
 powerpc/run           | 18 +-----------------
 s390x/run             | 18 +-----------------
 scripts/arch-run.bash | 22 ++++++++++++++++++++++
 4 files changed, 25 insertions(+), 53 deletions(-)

Comments

Paolo Bonzini June 28, 2017, 8:48 p.m. UTC | #1
On 28/06/2017 22:08, Radim Krčmář wrote:
> -if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
> -	echo "KVM is needed, but not available on this host"
> +ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') ||
>  	exit 2

Should x86 do the same as ARM (follow-up patch)?

And maybe the test could move from an argument of get_accel to a
function "arch_kvm_available" that returns 0 if available and 1 if not?

Paolo
diff mbox

Patch

diff --git a/arm/run b/arm/run
index d7d778fe1645..f2e71eca022d 100755
--- a/arm/run
+++ b/arm/run
@@ -10,26 +10,8 @@  if [ -z "$STANDALONE" ]; then
 fi
 processor="$PROCESSOR"
 
-if [ -c /dev/kvm ]; then
-	if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
-		kvm_available=yes
-	elif [ "$HOST" = "aarch64" ]; then
-		kvm_available=yes
-	fi
-fi
-
-if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "KVM is needed, but not available on this host"
+ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') ||
 	exit 2
-fi
-
-if [ -z "$ACCEL" ]; then
-	if [ "$kvm_available" = "yes" ]; then
-		ACCEL="kvm"
-	else
-		ACCEL="tcg"
-	fi
-fi
 
 qemu=$(search_qemu_binary) ||
 	exit 2
diff --git a/powerpc/run b/powerpc/run
index e43c9fd8063c..55b987c5efc5 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -9,24 +9,8 @@  if [ -z "$STANDALONE" ]; then
 	source scripts/arch-run.bash
 fi
 
-if [ -c /dev/kvm ]; then
-	if [ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]; then
-		kvm_available=yes
-	fi
-fi
-
-if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "KVM is needed, but not available on this host"
+ACCEL=$(get_accel '[ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]') ||
 	exit 2
-fi
-
-if [ -z "$ACCEL" ]; then
-	if [ "$kvm_available" = "yes" ]; then
-		ACCEL="kvm"
-	else
-		ACCEL="tcg"
-	fi
-fi
 
 qemu=$(search_qemu_binary) ||
 	exit 2
diff --git a/s390x/run b/s390x/run
index ce8d45c2c8fd..67d6e88ea7e4 100755
--- a/s390x/run
+++ b/s390x/run
@@ -9,24 +9,8 @@  if [ -z "$STANDALONE" ]; then
 	source scripts/arch-run.bash
 fi
 
-if [ -c /dev/kvm ]; then
-	if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
-		kvm_available=yes
-	fi
-fi
-
-if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "KVM is needed, but not available on this host"
+ACCEL=$(get_accel '[ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]') ||
 	exit 2
-fi
-
-if [ -z "$ACCEL" ]; then
-	if [ "$kvm_available" = "yes" ]; then
-		ACCEL="kvm"
-	else
-		ACCEL="tcg"
-	fi
-fi
 
 qemu=$(search_qemu_binary) ||
 	exit 2
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 994c1aa9c0cd..a696652c61b1 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -272,3 +272,25 @@  trap_exit_push ()
 	local old_exit=$(trap -p EXIT | sed "s/^[^']*'//;s/'[^']*$//")
 	trap -- "$1; $old_exit" EXIT
 }
+
+get_accel ()
+{
+	local kvm_available
+
+	if [ -c /dev/kvm ] && eval "$@"; then
+		kvm_available=yes
+	fi
+
+	if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
+		echo "KVM is needed, but not available on this host" >&2
+		return 2
+	fi
+
+	if [ "$ACCEL" ]; then
+		echo $ACCEL
+	elif [ "$kvm_available" = "yes" ]; then
+		echo kvm
+	else
+		echo tcg
+	fi
+}