2009-10-08 18:34:22 +04:00
#!/bin/sh
2011-09-28 11:43:39 +04:00
#
# virt-aa-helper needs a working locale system. If testing this in a chroot
# system, need to make sure these are setup properly. On Debian-based systems
# this can be done with something like (as root):
# locale-gen en_US.UTF-8
2009-10-08 18:34:22 +04:00
set -e
test_hostdev="no"
if [ "$1" = "test_hostdev" ]; then
test_hostdev="yes"
shift
fi
output="/dev/null"
use_valgrind=""
ld_library_path="../src/.libs/"
if [ ! -z "$1" ] && [ "$1" = "-d" ]; then
output="/dev/stdout"
shift
fi
exe="../src/virt-aa-helper"
if [ ! -z "$1" ]; then
if [ "$1" = "-v" ]; then
use_valgrind="yes"
shift
fi
if [ -n "$1" ]; then
exe="$1"
shift
fi
fi
if [ ! -x "$exe" ]; then
echo "Could not find '$exe'"
exit 1
fi
echo "testing `basename $exe`" >$output
if [ "$use_valgrind" = "yes" ]; then
exe="valgrind --error-exitcode=2 --track-origins=yes $exe"
fi
extra_args="--dryrun"
errors=0
tmpdir=`mktemp -d`
trap "rm -rf $tmpdir" EXIT HUP INT QUIT TERM
template_xml="$tmpdir/template.xml"
test_xml="$tmpdir/test.xml"
uuid="00000000-0000-0000-0000-0123456789ab"
disk1="$tmpdir/1.img"
disk2="$tmpdir/2.img"
relative_disk1="$tmpdir/./../`basename $tmpdir`//./1.img"
2014-04-21 00:07:46 +04:00
nonexistent="$tmpdir/nonexistent.img"
2009-10-08 18:34:22 +04:00
bad_disk="/etc/passwd"
valid_uuid="libvirt-$uuid"
nonexistent_uuid="libvirt-00000000-0000-0000-0000-000000000001"
cat > "$template_xml" <<EOM
<domain type='kvm'>
<name>virt-aa-helper-test</name>
<uuid>###UUID###</uuid>
<memory>524288</memory>
<currentMemory>524288</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
2017-04-06 19:19:48 +03:00
<emulator>/usr/bin/qemu-system-x86_64</emulator>
2009-10-08 18:34:22 +04:00
<disk type='file' device='disk'>
2010-07-23 20:43:37 +04:00
<driver name='qemu' type='raw'/>
2009-10-08 18:34:22 +04:00
<source file='###DISK###'/>
<target dev='hda' bus='ide'/>
</disk>
<interface type='network'>
<mac address='52:54:00:50:4b:26'/>
<source network='default'/>
<model type='virtio'/>
</interface>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'/>
<video>
2014-11-24 13:58:53 +03:00
<model type='cirrus' vram='16384' heads='1'/>
2009-10-08 18:34:22 +04:00
</video>
</devices>
</domain>
EOM
touch "$disk1" "$disk2"
testme() {
expected="$1"
outstr="$2"
args="$3"
input=""
2018-03-21 14:28:39 +03:00
checkrule="$5"
tmpout="$tmpdir/checkrule.out"
2009-10-08 18:34:22 +04:00
if [ -n "$4" ]; then
input="$4"
if [ ! -e "$input" ]; then
echo "FAIL: could not find $input" >$output
echo "FAIL: could not find $input"
echo " '$extra_args $args': "
errors=$(($errors + 1))
fi
fi
2010-04-14 19:51:45 +04:00
printf %s " $outstr: " >$output
printf %s " '$extra_args $args" >$output
2009-10-08 18:34:22 +04:00
if [ -n "$input" ]; then
2010-04-14 19:51:45 +04:00
printf %s " < $input" >$output
2009-10-08 18:34:22 +04:00
fi
echo "': " >$output
set +e
if [ -n "$input" ]; then
2018-03-21 14:28:39 +03:00
LD_LIBRARY_PATH="$ld_library_path" $exe $extra_args $args < $input >"$tmpout" 2>&1
2009-10-08 18:34:22 +04:00
else
2018-03-21 14:28:39 +03:00
LD_LIBRARY_PATH="$ld_library_path" $exe $extra_args $args >"$tmpout" 2>&1
2009-10-08 18:34:22 +04:00
fi
rc="$?"
2018-03-21 14:28:39 +03:00
cat "$tmpout" >"$output"
rule_missing=0
if [ -n "$checkrule" ]; then
if ! grep -q "$checkrule" "$tmpout"; then
echo "FAIL: missing rule '$checkrule'" >"$output"
rule_missing=1
fi
fi
2009-10-08 18:34:22 +04:00
set -e
2018-03-21 14:28:39 +03:00
if [ "$rc" = "$expected" ] && [ $rule_missing -eq 0 ]; then
2009-10-08 18:34:22 +04:00
echo "pass" >$output
else
echo "FAIL: exited with '$rc'" >$output
echo "FAIL: exited with '$rc'"
2010-04-14 19:51:45 +04:00
printf %s " $outstr: "
2009-10-08 18:34:22 +04:00
echo " '$extra_args $args': "
errors=$(($errors + 1))
#exit $rc
fi
}
2017-05-23 19:22:40 +03:00
testfw() {
title="$1"
fwpath="$2"
if [ -f "$fwpath" ]; then
2017-11-03 15:09:47 +03:00
sed -e "s,###UUID###,$uuid,g" \
2017-05-23 19:22:40 +03:00
-e "s,###DISK###,$disk1,g" \
-e "s,</os>,<loader readonly='yes' type='pflash'>$fwpath</loader></os>,g" "$template_xml" > "$test_xml"
testme "0" "$title" "-r -u $valid_uuid" "$test_xml"
else
2017-10-26 16:22:11 +03:00
echo "Skipping FW $title test. Could not find $fwpath" >$output
2017-05-23 19:22:40 +03:00
fi
}
2009-10-08 18:34:22 +04:00
# Expected failures
echo "Expected failures:" >$output
testme "1" "invalid arg" "-z"
testme "1" "invalid case" "-A"
testme "1" "not enough args" "-c"
2010-09-23 21:16:24 +04:00
testme "1" "not enough args" "-p"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "1" "no -u with -c" "-c" "$test_xml"
testme "1" "bad uuid (bad digit)" "-c -u libvirt-00000000-0000-0000-0000-00000000000g" "$test_xml"
testme "1" "bad uuid (too long)" "-c -u ${valid_uuid}abcdef" "$test_xml"
testme "1" "bad uuid (too short)" "-c -u libvirt-00000000-0000-0000-0000-0123456789a" "$test_xml"
testme "1" "non-matching uuid" "-c -u libvirt-00000000-0000-0000-0000-00000000000a" "$test_xml"
testme "1" "missing uuid" "-c -u" "$test_xml"
testme "1" "no -u with -R" "-R"
testme "1" "non-existent uuid" "-R -u $nonexistent_uuid"
testme "1" "no -u with -r" "-r"
testme "1" "old '-n' option" "-c -n foo -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$bad_disk,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "1" "bad disk" "-c -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$bad_disk,g" -e "s,</devices>,<disk type='file' device='disk'><driver name='qemu' type='raw'/><source file='$disk2'/><target dev='hda' bus='ide'/></disk></devices>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "1" "bad disk2" "-c -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<devices>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "1" "malformed xml" "-c -u $valid_uuid" "$test_xml"
2010-09-23 21:16:24 +04:00
initrd=`ls -1 /boot/initrd* | head -1`
if [ -z "$initrd" ]; then
echo "Skipping /boot/initrd* tests. Could not find /boot/initrd*"
else
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$initrd,g" "$template_xml" > "$test_xml"
2010-09-23 21:16:24 +04:00
testme "1" "disk in /boot without probing" "-p 0 -r -u $valid_uuid" "$test_xml"
testme "1" "disk in /boot with probing" "-p 1 -r -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,/boot/initrd,g" "$template_xml" > "$test_xml"
2010-09-23 21:16:24 +04:00
testme "1" "-r with invalid -f with probing" "-p 1 -r -u $valid_uuid -f $bad_disk" "$test_xml"
testme "1" "-r with invalid -f without probing" "-p 0 -r -u $valid_uuid -f $bad_disk" "$test_xml"
2010-10-01 00:54:56 +04:00
testme "1" "-r with invalid -F with probing" "-p 1 -r -u $valid_uuid -F $bad_disk" "$test_xml"
testme "1" "-r with invalid -F without probing" "-p 0 -r -u $valid_uuid -F $bad_disk" "$test_xml"
2010-09-23 21:16:24 +04:00
fi
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1</disk>,g" "$template_xml" > "$test_xml"
2009-11-13 13:04:23 +03:00
testme "1" "-c with malformed xml" "-c -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<type arch='x86_64' machine='pc'>hvm</type>,,g" "$template_xml" > "$test_xml"
2009-11-13 13:04:23 +03:00
testme "1" "-c with no os.type" "-c -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,hvm</type>,hvm_invalid</type>,g" "$template_xml" > "$test_xml"
2009-11-13 13:04:23 +03:00
testme "1" "-c with invalid hvm" "-c -u $valid_uuid" "$test_xml"
2017-10-26 16:22:10 +03:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-/,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char /" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-[,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char [" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-],g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char ]" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-{,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char {" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-},g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char }" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-?,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char ?" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-^,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char ^" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-\,,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char ," "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-\",g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char \"" "-c -u $valid_uuid" "$test_xml"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-aa-helper-test,virt-aa-helper-test-*,g" "$template_xml" > "$test_xml"
testme "1" "-c with invalid domain name char *" "-c -u $valid_uuid" "$test_xml"
2009-10-08 18:34:22 +04:00
echo "Expected pass:" >$output
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create (x86_64)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rwk,$"
2009-11-13 13:04:23 +03:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,arch='x86_64',arch='i686',g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create (i686)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rwk,$"
2009-11-13 13:04:23 +03:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,arch='x86_64',arch='ppc',g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create (ppc)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</disk>,</disk><disk type='file' device='disk'><driver name='qemu' type='raw'/><source file='$disk2'/><target dev='hdb' bus='ide'/></disk>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create multiple disks" "-c -u $valid_uuid" "$test_xml" "$disk1.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###',${disk1}'/><readonly,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create (readonly)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rk,$"
2009-10-08 18:34:22 +04:00
if [ "$test_hostdev" = "yes" ]; then
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</disk>,</disk><hostdev mode='subsystem' type='usb'><source><address bus='002' device='004'/></source></hostdev>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "0" "create hostdev (USB)" "-c -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</disk>,</disk><hostdev mode='subsystem' type='pci'><source><address bus='0x00' slot='0x19' function='0x0'/></source></hostdev>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "0" "create hostdev (PCI)" "-c -u $valid_uuid" "$test_xml"
fi
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$nonexistent,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create (non-existent disk)" "-c -u $valid_uuid" "$test_xml" "$nonexistent.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$relative_disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "create (relative path)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk2,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "replace" "-r -u $valid_uuid" "$test_xml" "$disk2.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$nonexistent,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "replace (non-existent disk)" "-r -u $valid_uuid" "$test_xml" "$nonexistent.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "replace (adding disk)" "-r -u $valid_uuid -f $disk2" "$test_xml" "$disk2.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "replace (adding non-existent disk)" "-r -u $valid_uuid -f $nonexistent" "$test_xml" "$nonexistent.*rwk,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "replace (appending disk)" "-r -u $valid_uuid -F $disk2" "$test_xml" "$disk2.*rwk,$"
2010-10-01 00:54:56 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "replace (appending non-existent disk)" "-r -u $valid_uuid -F $nonexistent" "$test_xml" "$nonexistent.*rwk,$"
2010-10-01 00:54:56 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<disk type='block' device='cdrom'><target dev='hdc' bus='ide'/><readonly/></disk></devices>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "0" "disk (empty cdrom)" "-r -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='file'><source path='$tmpdir/serial.log'/><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "serial" "-r -u $valid_uuid" "$test_xml" "$tmpdir/serial.log.*rw,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='pty'><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "0" "serial (pty)" "-r -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='dev'><source path='/dev/ttyS0'/><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "serial (dev)" "-r -u $valid_uuid" "$test_xml" "/dev/ttyS0.*rw,$"
2010-09-23 21:22:44 +04:00
2011-09-28 11:43:39 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='pipe'><source path='$tmpdir/serial.pipe'/><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
mkfifo "$tmpdir/serial.pipe.in" "$tmpdir/serial.pipe.out" "$tmpdir/serial.pipe.in.*rw,$"
2011-09-28 11:43:39 +04:00
testme "0" "serial (pipe)" "-r -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<console type='file'><source path='$tmpdir/console.log'/><target port='0'/></console></devices>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
touch "$tmpdir/console.log"
2018-03-21 14:28:39 +03:00
testme "0" "console" "-r -u $valid_uuid" "$test_xml" "$tmpdir/console.log.*rw,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<console type='pty'><target port='0'/></console></devices>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
testme "0" "console (pty)" "-r -u $valid_uuid" "$test_xml"
2011-09-28 11:43:39 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<console type='pipe'><source path='$tmpdir/console.pipe'/><target port='0'/></console></devices>,g" "$template_xml" > "$test_xml"
mkfifo "$tmpdir/console.pipe.in" "$tmpdir/console.pipe.out"
2018-03-21 14:28:39 +03:00
testme "0" "console (pipe)" "-r -u $valid_uuid" "$test_xml" "$tmpdir/console.pipe.out.*rw,$"
2011-09-28 11:43:39 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<parallel type='pty'><source path='/dev/pts/0'/><target port='0'/></parallel></devices>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "parallel (pty)" "-r -u $valid_uuid" "$test_xml" "/dev/pts/0.*rw,$"
2010-09-23 21:22:44 +04:00
2011-09-28 11:43:39 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<parallel type='pipe'><source path='$tmpdir/parallel.pipe'/><target port='0'/></parallel></devices>,g" "$template_xml" > "$test_xml"
mkfifo "$tmpdir/parallel.pipe.in" "$tmpdir/parallel.pipe.out"
2018-03-21 14:28:39 +03:00
testme "0" "parallel (pipe)" "-r -u $valid_uuid" "$test_xml" "$tmpdir/parallel.pipe.in.*rw,$"
2011-09-28 11:43:39 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<channel type='unix'><source mode='bind' path='$tmpdir/guestfwd'/><target type='guestfwd' address='10.0.2.1' port='4600'/></channel></devices>,g" "$template_xml" > "$test_xml"
2010-09-23 21:22:44 +04:00
touch "$tmpdir/guestfwd"
2018-03-21 14:28:39 +03:00
testme "0" "channel (unix)" "-r -u $valid_uuid" "$test_xml" "$tmpdir/guestfwd.*rw,$"
2010-09-23 21:22:44 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<channel type='pty'><target type='virtio'/></channel></devices>,g" "$template_xml" > "$test_xml"
2010-09-23 21:22:44 +04:00
testme "0" "channel (pty)" "-r -u $valid_uuid" "$test_xml"
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<kernel>$tmpdir/kernel</kernel></os>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
touch "$tmpdir/kernel"
2018-03-21 14:28:39 +03:00
testme "0" "kernel" "-r -u $valid_uuid" "$test_xml" "$tmpdir/kernel.*r,$"
2009-10-08 18:34:22 +04:00
2017-05-23 19:22:40 +03:00
testfw "ovmf (old path)" "/usr/share/ovmf/OVMF.fd"
testfw "OVMF (new path)" "/usr/share/OVMF/OVMF_CODE.fd"
2017-05-23 19:22:41 +03:00
testfw "AAVMF" "/usr/share/AAVMF/AAVMF_CODE.fd"
2017-07-20 22:56:56 +03:00
testfw "AAVMF32" "/usr/share/AAVMF/AAVMF32_CODE.fd"
2017-05-23 19:22:41 +03:00
testfw "qemu-efi" "/usr/share/qemu-efi/QEMU_EFI.fd"
2015-08-21 11:52:52 +03:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>$tmpdir/initrd</initrd></os>,g" "$template_xml" > "$test_xml"
2009-10-08 18:34:22 +04:00
touch "$tmpdir/initrd"
2018-03-21 14:28:39 +03:00
testme "0" "initrd" "-r -u $valid_uuid" "$test_xml" "$tmpdir/initrd.*r,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<kernel>/boot/kernel</kernel></os>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "kernel in /boot" "-r -u $valid_uuid" "$test_xml" "/boot/kernel.*r,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>/boot/initrd</initrd></os>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "initrd in /boot" "-r -u $valid_uuid" "$test_xml" "/boot/initrd.*r,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<kernel>/vmlinuz</kernel></os>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "kernel is /vmlinuz" "-r -u $valid_uuid" "$test_xml" "/vmlinuz.*r,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>/initrd/ramdisk</initrd></os>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "initrd is /initrd/ramdisk" "-r -u $valid_uuid" "$test_xml" "/initrd/ramdisk.*r,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>/initrd.img</initrd></os>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "initrd is /initrd.img" "-r -u $valid_uuid" "$test_xml" "/initrd.img.*r,$"
2009-10-08 18:34:22 +04:00
2010-10-01 01:01:36 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<graphics*,<graphics type='sdl' display=':0.0' xauth='/home/myself/.Xauthority'/>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "sdl Xauthority" "-r -u $valid_uuid" "$test_xml" "/home/myself/.Xauthority.*r,$"
2010-04-07 00:59:31 +04:00
2012-12-12 00:20:29 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "hugepages" "-r -u $valid_uuid -F /run/hugepages/kvm/\*\*" "$test_xml" "/run/hugepages/kvm/.*rwk,$"
2012-12-12 00:20:29 +04:00
2012-12-12 00:20:30 +04:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<graphics.*>,<graphics type='vnc' socket='/var/lib/libvirt/qemu/myself.vnc'><listen type='address' address='0.0.0.0'/></graphics>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "vnc socket" "-r -u $valid_uuid" "$test_xml" "/var/lib/libvirt/qemu/myself.vnc.*rw,$"
2012-12-12 00:20:30 +04:00
2018-03-20 13:11:13 +03:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<input type='passthrough' bus='virtio'><source evdev='$disk2' /></input></devices>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "input dev passthrough" "-r -u $valid_uuid" "$test_xml" "$disk2.*rw,$"
2018-03-20 13:11:13 +03:00
2018-03-20 13:13:54 +03:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<memory>524288</memory>,<memory>1048576</memory>,g" -e "s,</devices>,<memory model='nvdimm'><source><path>$disk2</path></source><target><size unit='KiB'>524288</size><node>0</node></target></memory></devices>,g" "$template_xml" > "$test_xml"
2018-03-21 14:28:39 +03:00
testme "0" "nvdimm" "-r -u $valid_uuid" "$test_xml" "$disk2.*rw,$"
2018-03-20 13:13:54 +03:00
2019-01-14 16:15:06 +03:00
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<graphics type='egl-headless'><gl rendernode='/dev/dri/testegl1'/></graphics></devices>,g" "$template_xml" > "$test_xml"
testme "0" "dri egl" "-r -u $valid_uuid" "$test_xml" "/dev/dri/testegl1.*rw,$"
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<graphics type='spice'><gl enable='yes' rendernode='/dev/dri/testegl2'/></graphics></devices>,g" "$template_xml" > "$test_xml"
testme "0" "dri spice" "-r -u $valid_uuid" "$test_xml" "/dev/dri/testegl2.*rw,$"
2009-10-08 18:34:22 +04:00
testme "0" "help" "-h"
echo "" >$output
if [ "$errors" != "0" ]; then
echo "FAIL: $errors error(s)" >$output
exit 1
fi
echo PASS >$output