rcutorture: Honor explicit QEMU CPU selection
Subsystems (3)
PATCH 1/1 rcutorture: Honor explicit QEMU CPU selection
kvm-test-1-run.sh appends the default -cpu after the arguments from --qemu-args. QEMU uses the last -cpu, so the default can override an explicit selection such as -cpu host,pmu=on.
Emit the default -cpu before the user arguments and keep the other arguments in their original order.
Fixes a6fda6dab93c ("rcutorture: Tweak kvm options")
Fixes 67ad71ddbcae ("rcutorture: Add basic ARM64 support to run scripts")
Signed-off-by Kunwu Chan <[email protected]>
---
All 17 shell tests passed. On x86 KVM with QEMU 8.2.2, QMP reported kvm64 with pmu=false before the patch and host with pmu=true after it. Both runs passed -cpu host,pmu=on and started paused (-S).
.../rcutorture/bin/functions-test.sh | 94 +++++++++++++++++++ .../selftests/rcutorture/bin/functions.sh | 20 ++-- .../rcutorture/bin/kvm-test-1-run.sh | 4 +- 3 files changed, 108 insertions(+), 10 deletions(-) create mode 100755 tools/testing/selftests/rcutorture/bin/functions-test.sh
tools/testing/selftests/rcutorture/bin/functions-test.sh new file +94 -0
@@ -0,0 +1,94 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# +# Check the order of arguments emitted by identify_qemu_args(). +# Usage: functions-test.sh [functions.sh] +# +# Author: Kunwu Chan <[email protected]> + +set -efu + +scriptdir="$(cd -- "$(dirname -- "$0")" && pwd)" +. "${1:-$scriptdir/functions.sh}" + +TORTURE_QEMU_INTERACTIVE= +TORTURE_QEMU_MAC= +console=/tmp/functions-test-console.log +serial="-serial file:$console" +nchecks=0 +nerrors=0 + +check_qemu_args () { + local label="$1" + local qemu="$2" + local expected="$3" + local args + + shift 3 + args=$(identify_qemu_args "$qemu" "$console" "$@") + # Normalize whitespace as when the harness writes qemu-cmd. + set -- $args + nchecks=$((nchecks + 1)) + if test "$*" = "$expected" + then + echo "ok $nchecks - $label" + else + echo "not ok $nchecks - $label" + printf '# expected: %s\n# got: %s\n' "$expected" "$*" + nerrors=$((nerrors + 1)) + fi +} + +for arch in x86_64 i386 aarch64 +do + case "$arch" in + x86_64) + cpu=kvm64 + machine=q35,accel=kvm + ;; + i386) + cpu=kvm32 + machine=q35,accel=kvm + ;; + aarch64) + cpu=host + machine=virt,gic-version=host + ;; + esac + tail="-machine $machine $serial" + check_qemu_args "$arch default CPU" "qemu-system-$arch" "-cpu $cpu $tail" + args="-smp 4 -net none -nodefaults" + check_qemu_args "$arch unrelated options" \ + "qemu-system-$arch" "-cpu $cpu $args $tail" "$args" + args="-smp 4 -cpu host,pmu=on -nodefaults" + check_qemu_args "$arch explicit CPU" \ + "qemu-system-$arch" "-cpu $cpu $args $tail" "$args" +done + +tail="-machine q35,accel=kvm $serial" +check_qemu_args "CPU token as guest name" qemu-system-x86_64 \ + "-cpu kvm64 -name -cpu $tail" "-name -cpu" +check_qemu_args "guest name and tab-separated --cpu" qemu-system-x86_64 \ + "-cpu kvm64 -name -cpu --cpu host,pmu=on $tail" $'-name -cpu\t--cpu\thost,pmu=on' +args="-cpu host,pmu=off --cpu host,pmu=on" +check_qemu_args "multiple explicit CPU options" qemu-system-x86_64 \ + "-cpu kvm64 $args $tail" "$args" +args="-machine q35,usb=off -serial none" +check_qemu_args "machine and serial ordering" qemu-system-x86_64 \ + "-cpu kvm64 $args $tail" "$args" +check_qemu_args "custom QEMU command" /opt/qemu/bin/qemu-system-x86_64 \ + "-name test $serial" "-name test" +ppc="-M pseries -nodefaults -device spapr-vscsi" +check_qemu_args "ppc64 defaults" qemu-system-ppc64 "$ppc $serial" + +TORTURE_QEMU_INTERACTIVE=1 +serial="-monitor stdio -serial pty -S" +check_qemu_args "x86_64 interactive" qemu-system-x86_64 \ + "-cpu kvm64 -cpu host,pmu=on -machine q35,accel=kvm $serial" "-cpu host,pmu=on" +TORTURE_QEMU_MAC=02:00:00:00:00:01 +ppc="$ppc -device spapr-vlan,netdev=net0,mac=$TORTURE_QEMU_MAC" +check_qemu_args "ppc64 interactive with MAC" qemu-system-ppc64 \ + "$ppc -netdev bridge,br=br0,id=net0 $serial" + +echo "1..$nchecks" +test "$nerrors" -eq 0
tools/testing/selftests/rcutorture/bin/functions.sh +12 -8
@@ -227,27 +227,31 @@ identify_qemu_append () { fi } -# identify_qemu_args qemu-cmd serial-file +# identify_qemu_args qemu-cmd serial-file [qemu-args] # -# Output arguments for qemu arguments based on the TORTURE_QEMU_MAC -# and TORTURE_QEMU_INTERACTIVE environment variables. +# QEMU uses the last -cpu option, so emit the default before qemu-args. identify_qemu_args () { - local KVM_CPU="" case "$1" in qemu-system-x86_64) - KVM_CPU=kvm64 + echo -cpu kvm64 ;; qemu-system-i386) - KVM_CPU=kvm32 + echo -cpu kvm32 + ;; + qemu-system-aarch64) + echo -cpu host ;; esac + if test -n "${3-}" + then + printf '%s\n' "$3" + fi case "$1" in qemu-system-x86_64|qemu-system-i386) echo -machine q35,accel=kvm - echo -cpu ${KVM_CPU} ;; qemu-system-aarch64) - echo -machine virt,gic-version=host -cpu host + echo -machine virt,gic-version=host ;; qemu-system-ppc64) echo -M pseries -nodefaults
tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh +2 -2
@@ -153,8 +153,8 @@ fi qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`" qemu_args="`specify_qemu_net "$qemu_args"`" -# Generate architecture-specific and interaction-specific qemu arguments -qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`" +# Place the default CPU before existing arguments and append the other defaults. +qemu_args="`identify_qemu_args "$QEMU" "$resdir/console.log" "$qemu_args"`" # Generate qemu -append arguments qemu_append="`identify_qemu_append "$QEMU"`"
base-commit: 68dcfb0e34ee3a9628f6b5ce7e06931b5248bb9e
Signature · 1 line
2.43.0