Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
arm/run: use ACCEL to choose between kvm and tcg
Inspired by a patch by Alex Bennée. This version uses a new
unittests.cfg variable and includes support for DRYRUN.

Signed-off-by: Andrew Jones <drjones@redhat.com>
  • Loading branch information
Andrew Jones committed Aug 7, 2015
1 parent c238c29 commit 85e084c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
43 changes: 37 additions & 6 deletions arm/run
Expand Up @@ -7,6 +7,42 @@ fi
source config.mak
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" ] &&
[ "$DRYRUN" != "yes" ]; then
printf "skip $TESTNAME (kvm only)\n\n"
exit 2
fi

if [ -z "$ACCEL" ]; then
if [ "$DRYRUN" = "yes" ]; then
# Output kvm with tcg fallback for dryrun (when both are
# allowed), since the command line we output may get used
# elsewhere.
ACCEL="kvm:tcg"
elif [ "$kvm_available" = "yes" ]; then
ACCEL="kvm"
else
ACCEL="tcg"
fi
fi

if [ "$ARCH" = "arm64" ]; then
if [[ $ACCEL =~ kvm ]]; then
# arm64 must use '-cpu host' with kvm, and we can't use
# '-cpu host' with tcg, so we force kvm-only (no fallback)
ACCEL="kvm"
processor="host"
fi
fi

qemu="${QEMU:-qemu-system-$ARCH_NAME}"
qpath=$(which $qemu 2>/dev/null)

Expand All @@ -33,15 +69,10 @@ if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \
exit 2
fi

M='-machine virt,accel=kvm:tcg'
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
processor="host"
fi

M+=",accel=$ACCEL"
command="$qemu $M -cpu $processor $chr_testdev"
command+=" -display none -serial stdio -kernel"
echo $command "$@"
Expand Down
4 changes: 3 additions & 1 deletion arm/unittests.cfg
Expand Up @@ -3,8 +3,10 @@
# file = foo.flat # Name of the flat file to be used
# smp = 2 # Number of processors the VM will use during this test
# extra_params = -append <params...> # Additional parameters used
# arch = arm/arm64 # Only if test case is specific to one
# arch = arm|arm64 # Only if test case is specific to one
# groups = group1 group2 # Used to identify test cases with run_tests -g ...
# accel = kvm|tcg # Optionally specify if test must run with kvm or tcg.
# # If not specified, then kvm will be used when available.

#
# Test that the configured number of processors (smp = <num>), and
Expand Down
3 changes: 2 additions & 1 deletion run_tests.sh
Expand Up @@ -20,6 +20,7 @@ function run()
local opts="$5"
local arch="$6"
local check="$7"
local accel="$8"

if [ -z "$testname" ]; then
return
Expand All @@ -46,7 +47,7 @@ function run()
fi
done

cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts"
cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts"
if [ $verbose != 0 ]; then
echo $cmdline
fi
Expand Down
8 changes: 6 additions & 2 deletions scripts/functions.bash
Expand Up @@ -10,19 +10,21 @@ function for_each_unittest()
local groups
local arch
local check
local accel

exec {fd}<"$unittests"

while read -u $fd line; do
if [[ "$line" =~ ^\[(.*)\]$ ]]; then
"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel"
testname=${BASH_REMATCH[1]}
smp=1
kernel=""
opts=""
groups=""
arch=""
check=""
accel=""
elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
kernel=$TEST_DIR/${BASH_REMATCH[1]}
elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
Expand All @@ -35,8 +37,10 @@ function for_each_unittest()
arch=${BASH_REMATCH[1]}
elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
check=${BASH_REMATCH[1]}
elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
accel=${BASH_REMATCH[1]}
fi
done
"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel"
exec {fd}<&-
}
15 changes: 11 additions & 4 deletions scripts/mkstandalone.sh
Expand Up @@ -29,6 +29,7 @@ function mkstandalone()
local opts="$5"
local arch="$6"
local check="$7"
local accel="$8"

if [ -z "$testname" ]; then
return 1
Expand All @@ -39,7 +40,7 @@ function mkstandalone()
fi

standalone=tests/$testname
cmdline=$(DRYRUN=yes ./$TEST_DIR-run $kernel)
cmdline=$(DRYRUN=yes ACCEL=$accel ./$TEST_DIR-run $kernel)
if [ $? -ne 0 ]; then
echo $cmdline
exit 1
Expand Down Expand Up @@ -94,10 +95,16 @@ qemu="$qemu"
if [ "\$QEMU" ]; then
qemu="\$QEMU"
fi
cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
echo \$qemu $cmdline -smp $smp $opts
\$qemu \$cmdline -smp $smp $opts
ret=\$?
cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`"
if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then
ret=2
else
cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
\$qemu \$cmdline -smp $smp $opts
ret=\$?
fi
echo Return value from qemu: \$ret
if [ \$ret -le 1 ]; then
echo PASS $testname 1>&2
Expand Down

0 comments on commit 85e084c

Please sign in to comment.