qemu-test: add virtio-serial test
[qemu-test.git] / tests / virtio-serial.sh
1 #!/bin/sh
2
3 canary="** waiting for... **"
4
5 in_host() {
6 tmpchr=$tmpdir/chr.log
7
8 # Also test alias
9 devname=`choose virtio-serial virtio-serial-pci`
10
11 qemu -nographic -enable-kvm -device $devname \
12 -device virtserialport,name=org.qemu.test,chardev=chr0 \
13 -chardev file,path=$tmpchr,id=chr0
14 rc=$?
15
16 if test $rc = 0; then
17 if ! grep "$canary" $tmpchr >/dev/null; then
18 echo "Failed to see output from guest!"
19 rc=1
20 fi
21 fi
22
23 rm -f $tmpchr
24
25 return $rc
26 }
27
28 in_guest() {
29 sysfspath=/sys/bus/virtio/devices/virtio0/virtio-ports/vport0p1
30 if ! test -e $sysfspath/name; then
31 echo "Device not visible!"
32 return 1
33 fi
34
35 name=`cat $sysfspath/name`
36
37 if test "$name" != "org.qemu.test"; then
38 echo "Device has wrong name!"
39 echo "Expected 'org.qemu.test', got '$name'"
40 return 2
41 fi
42
43 echo "$canary" > /dev/vport0p1
44
45 return 0
46 }
47
48 if test $QEMU_TEST; then
49 in_host
50 else
51 in_guest
52 fi