qemu-test: add device-del test case
[qemu-test.git] / tests / device-del.sh
1 #!/bin/sh
2
3 canary="** waiting for hotplug **"
4 canary2="** waiting for remove **"
5
6 in_host() {
7 tmpdisk=$tmpdir/disk.img
8
9 # make sure to test various of -device, anonymous, and named
10 extra_arg=`choose "-device virtio-balloon-pci" "-device virtio-balloon-pci,id=balloon0" none`
11
12 if test "$extra_arg" = "none"; then
13 extra_arg=""
14 fi
15
16 qemu-img create -f qcow2 $tmpdisk 10G
17
18 start_qemu -nographic -enable-kvm $extra_arg
19
20 while qemu_is_okay; do
21 if grep "$canary" $tmplog >/dev/null; then
22 out=`hmp drive_add auto file=$tmpdisk,if=none,id=hd0`
23 if test $(echo "$out") != "OK"; then
24 echo "drive_add failed!"
25 echo "$out"
26 rm $tmpdisk
27 kill $pid
28 return 1
29 fi
30
31 qmp device_add --driver=virtio-blk-pci --drive=hd0 --id=hd0
32 rc=$?
33 if test $rc != 0; then
34 echo "device_add failed!"
35 rm $tmpdisk
36 kill $pid
37 return 1
38 fi
39
40 echo "** waiting for guest to see device **"
41
42 while qemu_is_okay; do
43 if grep "$canary2" $tmplog >/dev/null; then
44 qmp device_del --id=hd0
45 rc=$?
46 if test $rc != 0; then
47 echo "device_del failed!"
48 rm $tmpdisk
49 kill $pid
50 return 1
51 fi
52
53 while qemu_is_okay; do
54 sleep 1
55 done
56
57 break
58 fi
59 sleep 1
60 done
61
62 break
63 fi
64 sleep 1
65 done
66
67 get_qemu_status
68 rc=$?
69
70 rm -f $tmpdisk
71
72 return $rc
73 }
74
75 in_guest() {
76 echo
77 echo "$canary"
78 while ! grep vda /proc/partitions >/dev/null; do
79 sleep 1
80 done
81 echo "$canary2"
82 while grep vda /proc/partitions >/dev/null; do
83 sleep 1
84 done
85 }
86
87 if test $QEMU_TEST; then
88 in_host
89 else
90 in_guest
91 fi