Minor fixes while getting rid of code duplication
cover Minor fixes while getting rid of code duplication
The series isn't well split, so patches remove the code duplication and fix bugs at the same time. [3/5] is s390x+powerpc specific, but has dependency on [4/5], which affects all architectures, just like [1,5/5]. [2/5] is unrelated, but was simple enough to include.
Radim Krčmář (5):
arch/run: simplify copy-paste of the command line
run_tests: add summary to powerpc and s390 s390+powerpc/run: improve output handling scripts/arch-run: fix qemu binary search failure path arch/run: unify accelerator detection
arm/run | 28 +++------------------ powerpc/run | 41 ++++-------------------------- s390x/run | 38 +++------------------------- scripts/arch-run.bash | 69 +++++++++++++++++++++++++++++++++++++++++++++++---- scripts/runtime.bash | 2 +- x86/run | 8 +++--- 6 files changed, 81 insertions(+), 105 deletions(-)
Signature · 1 line
2.13.2
PATCH 1/5 arch/run: simplify copy-paste of the command line
The major annoyance coming from errata was "-initrd mktemp" that had to be removed before running the copy-pasted command line. Move "-initrd ..." part at the end of the line and hide it behind "#" if the initird file is a temporary one.
This patch also brings s390 to use the same code as other architectures and eliminates code duplication.
---
Adding the arch/run command line might also be worth it (i.e. adding echo $0 $@ to arch/run).
--- arm/run | 5 +---- powerpc/run | 5 +---- s390x/run | 2 -- scripts/arch-run.bash | 18 ++++++++++++++++-- x86/run | 5 +---- 5 files changed, 19 insertions(+), 16 deletions(-)
arm/run +1 -4
@@ -71,12 +71,9 @@ if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then pci_testdev="-device pci-testdev" fi -initrd_create - M+=",accel=$ACCEL" command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev" -command+=" -display none -serial stdio $INITRD -kernel" +command+=" -display none -serial stdio -kernel" command="$(timeout_cmd) $command" -echo $command "$@" run_qemu $command "$@"
powerpc/run +1 -4
@@ -35,14 +35,11 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then exit 2 fi -initrd_create - M='-machine pseries' M+=",accel=$ACCEL" command="$qemu -nodefaults $M -bios $FIRMWARE" -command+=" -display none -serial stdio $INITRD -kernel" +command+=" -display none -serial stdio -kernel" command="$(migration_cmd) $(timeout_cmd) $command" -echo $command "$@" # powerpc tests currently exit with rtas-poweroff, which exits with 0. # run_qemu treats that as a failure exit and returns 1, so we need
s390x/run +0 -2
@@ -34,10 +34,8 @@ M='-machine s390-ccw-virtio' M+=",accel=$ACCEL" command="$qemu -nodefaults -nographic $M" command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0" -[ -f "$ENV" ] && command+=" -initrd $ENV" command+=" -kernel" command="$(timeout_cmd) $command" -echo $command "$@" # We return the exit code via stdout, not via the QEMU return code lines=$(run_qemu $command "$@")
scripts/arch-run.bash +16 -2
@@ -28,9 +28,14 @@ run_qemu () { local stdout errors ret sig + echo -n $@ + initrd_create && + echo -n " #" + echo " $INITRD" + # stdout to {stdout}, stderr to $errors and stderr exec {stdout}>&1 - errors=$("${@}" </dev/null 2> >(tee /dev/stderr) > /dev/fd/$stdout) + errors=$("${@}" $INITRD </dev/null 2> >(tee /dev/stderr) > /dev/fd/$stdout) ret=$? exec {stdout}>&-
@@ -158,14 +163,20 @@ search_qemu_binary () initrd_create () { + local ret + env_add_errata + ret=$? + unset INITRD [ -f "$ENV" ] && INITRD="-initrd $ENV" + + return $ret } env_add_errata () { - local line errata + local line errata ret=1 if [ -f "$ENV" ] && grep -q '^ERRATA_' <(env); then for line in $(grep '^ERRATA_' "$ENV"); do
@@ -183,7 +194,10 @@ env_add_errata () trap_exit_push 'rm -f $ENV; [ "$ENV_OLD" ] && export ENV="$ENV_OLD" || unset ENV; unset ENV_OLD' [ -f "$ENV_OLD" ] && grep -v '^ERRATA_' "$ENV_OLD" > $ENV grep '^ERRATA_' <(env) >> $ENV + ret=0 fi + + return $ret } env_generate_errata ()
x86/run +1 -4
@@ -33,11 +33,8 @@ else pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out" fi -initrd_create - command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev" -command+=" $INITRD -kernel" +command+=" -kernel" command="$(timeout_cmd) $command" -echo ${command} "$@" run_qemu ${command} "$@"
Signature · 1 line
2.13.2
PATCH 2/5 run_tests: add summary to powerpc and s390
In reply to Radim KrčmářLooking at the last line was not enough as these architectures have information about the exit on the last two lines. See the last 3 lines.
---
Sample output on powerpc:
PASS selftest-setup (2 tests)
PASS spapr_hcall (9 tests, 1 expected failures)
PASS rtas-get-time-of-day (10 tests)
PASS rtas-get-time-of-day-base (10 tests)
PASS rtas-set-time-of-day (5 tests)
PASS emulator (4 tests)
SKIP h_cede_tm (test marked as manual run only)
PASS sprs (46 tests)
and s390x:
FAIL selftest-setup (7 tests)
FAIL intercept (3 tests, 2 unexpected failures)
s390 selftest-setup is failing even though all tests passed, but there is also:
ABORT: selftest: Unexpected program interrupt: 5 at 0x12b7c, ilen 4
--- scripts/runtime.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/runtime.bash +1 -1
@@ -8,7 +8,7 @@ FAIL() { echo -ne "\e[31mFAIL\e[0m"; } extract_summary() { - tail -1 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/' + tail -3 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/' } # We assume that QEMU is going to work if it tried to load the kernel
Signature · 1 line
2.13.2
Re: [kvm-unit-tests PATCH 2/5] run_tests: add summary to powerpc and s390
Quoted 15 lines · Radim Krčmář
Looking at the last line was not enough as these architectures have information about the exit on the last two lines. See the last 3 lines.
Signed-off-by Radim Krčmář <[email protected]>---
Sample output on powerpc:
PASS selftest-setup (2 tests)
PASSspapr_hcall(9 tests, 1 expected failures)
PASS rtas-get-time-of-day (10 tests)
PASS rtas-get-time-of-day-base (10 tests)
PASS rtas-set-time-of-day (5 tests)
PASS emulator (4 tests)
SKIPh_cede_tm(test marked as manual run only)
PASS sprs (46 tests)
Quoted 7 lines
and s390x:
FAIL selftest-setup (7 tests)
FAIL intercept (3 tests, 2 unexpected failures)s390 selftest-setup is failing even though all tests passed, but there is also:
ABORT: selftest: Unexpected program interrupt: 5 at0x12b7c, ilen 4
Please use the latest and greatest QEMU from the master branch for s390x ... there have been quite a lot of fixes since v2.9 and some of them are required to get the kvm-unit-tests running properly.
Thomas
Re: [kvm-unit-tests PATCH 2/5] run_tests: add summary to powerpc and s390
2017-06-29 07:30+0200, Thomas Huth:
Quoted 11 lines · Radim Krčmář
Quoted 6 lines
FAIL selftest-setup (7 tests)
FAIL intercept (3 tests, 2 unexpected failures)s390 selftest-setup is failing even though all tests passed, but there is also:
ABORT: selftest: Unexpected program interrupt: 5 at0x12b7c, ilen 4Please use the latest and greatest QEMU from the master branch for s390x ... there have been quite a lot of fixes since v2.9 and some of them are required to get the kvm-unit-tests running properly.
Will do, thanks. In this case, I wanted to demonstrate that the summary gets printed and didn't care what it was. :)
PATCH 3/5 s390+powerpc/run: improve output handling
In reply to Radim KrčmářIf the test is hanging, then using arch/run would produce no output, because of caching in a temporary variable.
Use the tee trick to save the output while passing it through.
They were also using the very same code.
--- powerpc/run | 15 +-------------- s390x/run | 15 +-------------- scripts/arch-run.bash | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 28 deletions(-)
powerpc/run +1 -14
@@ -46,17 +46,4 @@ command="$(migration_cmd) $(timeout_cmd) $command" # to fixup the fixup below by parsing the true exit code from the output. # The second fixup is also a FIXME, because once we add chr-testdev # support for powerpc, we won't need the second fixup. -lines=$(run_qemu $command "$@") -ret=$? -echo "$lines" -if [ $ret -eq 1 ]; then - testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/') - if [ "$testret" ]; then - if [ $testret -eq 1 ]; then - ret=0 - else - ret=$testret - fi - fi -fi -exit $ret +run_qemu_status $command "$@"
s390x/run +1 -14
@@ -38,17 +38,4 @@ command+=" -kernel" command="$(timeout_cmd) $command" # We return the exit code via stdout, not via the QEMU return code -lines=$(run_qemu $command "$@") -ret=$? -echo "$lines" -if [ $ret -eq 1 ]; then - testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/') - if [ "$testret" ]; then - if [ $testret -eq 1 ]; then - ret=0 - else - ret=$testret - fi - fi -fi -exit $ret +run_qemu_status $command "$@"
scripts/arch-run.bash +23 -0
@@ -69,6 +69,29 @@ run_qemu () return $ret } +run_qemu_status () +{ + local stdout ret + + exec {stdout}>&1 + lines=$(run_qemu "$@" > >(tee /dev/fd/$stdout)) + ret=$? + exec {stdout}>&- + + if [ $ret -eq 1 ]; then + testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/') + if [ "$testret" ]; then + if [ $testret -eq 1 ]; then + ret=0 + else + ret=$testret + fi + fi + fi + + return $ret +} + timeout_cmd () { if [ "$TIMEOUT" ] && [ "$TIMEOUT" != "0" ]; then
Signature · 1 line
2.13.2
PATCH 4/5 scripts/arch-run: fix qemu binary search failure path
In reply to Radim KrčmářDoing exit from a subshell won't exit the main shell, so arch-run will try to continue without a working QEMU if search_qemu_binary() failed.
Also fix error message from search_qemu_binary().
---
I was thinking about using set -e instead, so the "return 2" from search_qemu_binary() would stop the script without the explicit exit. It required just four changes to make the script work (resulting in better diffstat), but would likely complicate future development.
The second alternative would be to call just "search_qemu_binary" and set the qemu variable from it. This would allow "exit 2" from search_qemu_binary() to also exit arch/run, but side-effects on variables seem worse than the first alternative ...
--- arm/run | 3 ++- powerpc/run | 3 ++- s390x/run | 3 ++- scripts/arch-run.bash | 6 +++--- x86/run | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-)
arm/run +2 -1
@@ -31,7 +31,8 @@ if [ -z "$ACCEL" ]; then fi fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 if ! $qemu -machine '?' 2>&1 | grep 'ARM Virtual Machine' > /dev/null; then echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
powerpc/run +2 -1
@@ -28,7 +28,8 @@ if [ -z "$ACCEL" ]; then fi fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then echo "$qemu doesn't support pSeries ('-machine pseries'). Exiting."
s390x/run +2 -1
@@ -28,7 +28,8 @@ if [ -z "$ACCEL" ]; then fi fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 M='-machine s390-ccw-virtio' M+=",accel=$ACCEL"
scripts/arch-run.bash +3 -3
@@ -176,9 +176,9 @@ search_qemu_binary () done if [ -z "$qemu" ]; then - echo "A QEMU binary was not found." - echo "You can set a custom location by using the QEMU=<path> environment variable." - exit 2 + echo "A QEMU binary was not found." >&2 + echo "You can set a custom location by using the QEMU=<path> environment variable." >&2 + return 2 fi command -v $qemu export PATH=$save_path
x86/run +2 -1
@@ -9,7 +9,8 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 if ! ${qemu} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null; then
Signature · 1 line
2.13.2
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 4/5] scripts/arch-run: fix qemu binary search failure path
Quoted 2 lines · Radim Krčmář
Doing exit from a subshell won't exit the main shell, so arch-run will try to continue without a working QEMU if
search_qemu_binary()failed.
Should it be "exit $?"?
Apart from this looks good. I can do the change.
Paolo
Quoted 14 lines
Also fix error message from
search_qemu_binary().Signed-off-by Radim Krčmář <[email protected]>---
I was thinking about usingset -einstead, so the "return 2" fromsearch_qemu_binary()would stop the script without the explicit exit. It required just four changes to make the script work (resulting in better diffstat), but would likely complicate future development.The second alternative would be to call just "
search_qemu_binary" and set the qemu variable from it. This would allow "exit 2" fromsearch_qemu_binary()to also exitarch/run, but side-effects on variables seem worse than the first alternative ...
---
Re: [kvm-unit-tests PATCH 4/5] scripts/arch-run: fix qemu binary search failure path
2017-06-28 22:46+0200, Paolo Bonzini:
Quoted 5 lines · Radim Krčmář
Quoted 2 lines
Doing exit from a subshell won't exit the main shell, so arch-run will try to continue without a working QEMU if
search_qemu_binary()failed.Should it be "exit $?"?
Makes sense. I was thinking about 'return 1' from search_qemu_binary(), but never actually went from it.
Quoted 1 line
Apart from this looks good. I can do the change.
Please do, thanks.
PATCH 5/5 arch/run: unify accelerator detection
In reply to Radim KrčmářUse the same mechanism as search_qemu_binary().
--- arm/run | 20 +------------------- powerpc/run | 18 +----------------- s390x/run | 18 +----------------- scripts/arch-run.bash | 22 ++++++++++++++++++++++ 4 files changed, 25 insertions(+), 53 deletions(-)
arm/run +1 -19
@@ -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
powerpc/run +1 -17
@@ -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
s390x/run +1 -17
@@ -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
scripts/arch-run.bash +22 -0
@@ -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 +}
Signature · 1 line
2.13.2
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 5/5] arch/run: unify accelerator detection
arm/run if [ -z "$STANDALONE" ]; then · line 14
Quoted 4 lines · Radim Krčmář
arm/run +1
-2-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
Re: [kvm-unit-tests PATCH 5/5] arch/run: unify accelerator detection
2017-06-28 22:48+0200, Paolo Bonzini:
Quoted 7 lines · Radim Krčmář
Review
Quoted 4 lines
(quoted diff) +1
-2-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 2Should x86 do the same as ARM (follow-up patch)?
Yeah, I'll prepare it when we've agreed on the format.
Quoted 2 lines
And maybe the test could move from an argument of
get_accelto a function "arch_kvm_available" that returns 0 if available and 1 if not?
Right, the arm condition needs to be fixed as
([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || ([ "$HOST" = "aarch64" ] && [ "$ARCH" = arm -o "$ARCH" = arm64 ])
and it would look even worse in the argument ...
Would it be ok like this?
arm/run +6 -1
@@ -10,7 +10,12 @@ if [ -z "$STANDALONE" ]; then fi processor="$PROCESSOR" -ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') || +arch_kvm_available () +{ + ([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ] +} + +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||
powerpc/run +6 -1
@@ -9,7 +9,12 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]') || +arch_kvm_available () +{ + [ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ] +} + +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||
s390x/run +6 -1
@@ -9,7 +9,12 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]') || +arch_kvm_available () +{ + [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ] +} + +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||
scripts/arch-run.bash +1 -1
@@ -277,7 +277,7 @@ get_accel () { local kvm_available - if [ -c /dev/kvm ] && eval "$@"; then + if [ -c /dev/kvm ] && arch_kvm_available; then kvm_available=yes fi
Re: [kvm-unit-tests PATCH 5/5] arch/run: unify accelerator detection
2017-06-29 14:45+0200, Radim Krčmář:
Quoted 14 lines
2017-06-28 22:48+0200, Paolo Bonzini:
Quoted 7 lines · Radim Krčmář
Review
Quoted 4 lines
(quoted diff) +1
-2-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 2Should x86 do the same as ARM (follow-up patch)?
Yeah, I'll prepare it when we've agreed on the format.
Quoted 2 lines
And maybe the test could move from an argument of
get_accelto a function "arch_kvm_available" that returns 0 if available and 1 if not?
Quoted 8 lines
Right, the arm condition needs to be fixed as
([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || ([ "$HOST" = "aarch64" ] && [ "$ARCH" = arm -o "$ARCH" = arm64 ])and it would look even worse in the argument ...
Would it be ok like this?
No, we can make a better use of the $HOST variable:
arm/run +1 -1
@@ -10,7 +10,7 @@ if [ -z "$STANDALONE" ]; then fi processor="$PROCESSOR" -ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||
powerpc/run +1 -1
@@ -9,7 +9,7 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||
s390x/run +1 -1
@@ -9,7 +9,7 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||
scripts/arch-run.bash +12 -8
@@ -273,22 +273,26 @@ trap_exit_push () trap -- "$1; $old_exit" EXIT } +kvm_available () +{ + [ -c /dev/kvm ] || + return 1 + + [ "$HOST" = "$ARCH_NAME" ] || + [ "$HOST" = aarch64 -a "$ARCH" = arm ] || + [ "$HOST" = x86_64 -a "$ARCH" = i386 ] +} + get_accel () { - local kvm_available - - if [ -c /dev/kvm ] && eval "$@"; then - kvm_available=yes - fi - - if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then + if [ "$ACCEL" = "kvm" ] && ! kvm_available; 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 + elif kvm_available; then echo kvm else echo tcg
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 5/5] arch/run: unify accelerator detection
Quoted 17 lines · Radim Krčmář
2017-06-29 14:45+0200, Radim Krčmář:
Quoted 16 lines
2017-06-28 22:48+0200, Paolo Bonzini:
Quoted 7 lines · Radim Krčmář
Review
Quoted 4 lines
(quoted diff) +1
-2-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 2Should x86 do the same as ARM (follow-up patch)?
Yeah, I'll prepare it when we've agreed on the format.
Quoted 2 lines
And maybe the test could move from an argument of
get_accelto a function "arch_kvm_available" that returns 0 if available and 1 if not?Right, the arm condition needs to be fixed as
Quoted 8 lines
Quoted 6 lines
([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || ([ "$HOST" = "aarch64" ] && [ "$ARCH" = arm -o "$ARCH" = arm64 ])and it would look even worse in the argument ...
Would it be ok like this?
No, we can make a better use of the $HOST variable:
Either is okay.
Paolo
Quoted 79 lines
arm/run +1
-1@@ -10,7 +10,7 @@ if [ -z "$STANDALONE" ]; then fi processor="$PROCESSOR" -ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||powerpc/run +1
-1@@ -9,7 +9,7 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||s390x/run +1
-1@@ -9,7 +9,7 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) ||scripts/arch-run.bash +12
-8@@ -273,22 +273,26 @@ trap_exit_push () trap -- "$1; $old_exit" EXIT } +kvm_available () +{ + [ -c /dev/kvm ] || + return 1 + + [ "$HOST" = "$ARCH_NAME" ] || + [ "$HOST" = aarch64 -a "$ARCH" = arm ] || + [ "$HOST" = x86_64 -a "$ARCH" = i386 ] +} + get_accel () { - local kvm_available - - if [ -c /dev/kvm ] && eval "$@"; then - kvm_available=yes - fi - - if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then + if [ "$ACCEL" = "kvm" ] && ! kvm_available; 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 + elif kvm_available; then echo kvm else echo tcg
PATCH v2 5/5 arch/run: unify accelerator detection
In reply to Radim KrčmářUse the same mechanism as search_qemu_binary().
The simplified [ "$HOST" = "$ARCH_NAME" ] check will mishandle a case if you compile for $arch on $arch then try to run it with $other_arch/run, but that isn't really worth checking.
--- arm/run | 22 ++-------------------- powerpc/run | 20 ++------------------ s390x/run | 20 ++------------------ scripts/arch-run.bash | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 56 deletions(-)
arm/run +2 -20
@@ -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" - exit 2 -fi - -if [ -z "$ACCEL" ]; then - if [ "$kvm_available" = "yes" ]; then - ACCEL="kvm" - else - ACCEL="tcg" - fi -fi +ACCEL=$(get_qemu_accelerator) || + exit $? qemu=$(search_qemu_binary) || exit $?
powerpc/run +2 -18
@@ -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" - exit 2 -fi - -if [ -z "$ACCEL" ]; then - if [ "$kvm_available" = "yes" ]; then - ACCEL="kvm" - else - ACCEL="tcg" - fi -fi +ACCEL=$(get_qemu_accelerator) || + exit $? qemu=$(search_qemu_binary) || exit $?
s390x/run +2 -18
@@ -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" - exit 2 -fi - -if [ -z "$ACCEL" ]; then - if [ "$kvm_available" = "yes" ]; then - ACCEL="kvm" - else - ACCEL="tcg" - fi -fi +ACCEL=$(get_qemu_accelerator) || + exit $? qemu=$(search_qemu_binary) || exit $?
scripts/arch-run.bash +26 -0
@@ -272,3 +272,29 @@ trap_exit_push () local old_exit=$(trap -p EXIT | sed "s/^[^']*'//;s/'[^']*$//") trap -- "$1; $old_exit" EXIT } + +kvm_available () +{ + [ -c /dev/kvm ] || + return 1 + + [ "$HOST" = "$ARCH_NAME" ] || + [ "$HOST" = aarch64 -a "$ARCH" = arm ] || + [ "$HOST" = x86_64 -a "$ARCH" = i386 ] +} + +get_qemu_accelerator () +{ + if [ "$ACCEL" = "kvm" ] && ! kvm_available; then + echo "KVM is needed, but not available on this host" >&2 + return 2 + fi + + if [ "$ACCEL" ]; then + echo $ACCEL + elif kvm_available; then + echo kvm + else + echo tcg + fi +}
Signature · 1 line
2.13.2
[kvm-unit-tests PATCH v2 6/5] x86/run: support accelerator controls
In reply to Radim KrčmářIt's easy to support and we do have the option for other architectures.
--- x86/run | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
x86/run +5 -2
@@ -9,6 +9,9 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi +ACCEL=$(get_qemu_accelerator) || + exit $? + qemu=$(search_qemu_binary) || exit $?
@@ -34,8 +37,8 @@ else pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out" fi -command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev" -command+=" -kernel" +command="${qemu} -nodefaults $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev" +command+=" -machine accel=$ACCEL -kernel" command="$(timeout_cmd) $command" run_qemu ${command} "$@"
Signature · 1 line
2.13.2
Re: [kvm-unit-tests PATCH v2 6/5] x86/run: support accelerator controls
Applied both, thanks.
Paolo
Quoted 33 lines · Radim Krčmář
It's easy to support and we do have the option for other architectures.
Signed-off-by Radim Krčmář <[email protected]>--- x86/run | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)x86/run +5
-2@@ -9,6 +9,9 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi +ACCEL=$(get_qemu_accelerator) || + exit $? + qemu=$(search_qemu_binary) || exit $?@@ -34,8 +37,8 @@ else pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out" fi -command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev" -command+=" -kernel" +command="${qemu} -nodefaults $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev" +command+=" -machine accel=$ACCEL -kernel" command="$(timeout_cmd) $command" run_qemu ${command} "$@"
Quoted 13 lines · Radim Krčmář
The series isn't well split, so patches remove the code duplication and fix bugs at the same time. [3/5] is s390x+powerpc specific, but has dependency on [4/5], which affects all architectures, just like [1,5/5]. [2/5] is unrelated, but was simple enough to include.
Radim Krčmář (5):
arch/run: simplify copy-paste of the command line
run_tests: add summary to powerpc and s390 s390+powerpc/run: improve output handlingscripts/arch-run: fix qemu binary search failure patharch/run: unify accelerator detection
Quoted 11 lines
arm/run | 28 +++------------------ powerpc/run | 41 ++++-------------------------- s390x/run | 38 +++------------------------- scripts/arch-run.bash | 69 +++++++++++++++++++++++++++++++++++++++++++++++---- scripts/runtime.bash | 2 +- x86/run | 8 +++--- 6 files changed, 81 insertions(+), 105 deletions(-)Signature · 1 line
2.13.2
With Paolo's fixups, the series looks good to me. For the series