]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -xe | |
4 | ||
5 | testdir=$(readlink -f $(dirname $0)) | |
11fdf7f2 TL |
6 | rootdir=$(readlink -f $testdir/../..) |
7 | source $rootdir/test/common/autotest_common.sh | |
8 | ||
9 | if [ -z "${DEPENDENCY_DIR}" ]; then | |
10 | echo DEPENDENCY_DIR not defined! | |
11 | exit 1 | |
12 | fi | |
7c673cae FG |
13 | |
14 | function ssh_vm() { | |
9f95a23c TL |
15 | local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )" |
16 | set +x | |
11fdf7f2 | 17 | sshpass -p "$password" ssh -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -p 10022 root@localhost "$@" |
9f95a23c | 18 | $shell_restore_x |
7c673cae FG |
19 | } |
20 | ||
21 | function monitor_cmd() { | |
22 | rc=0 | |
23 | if ! (echo "$@" | nc localhost 4444 > mon.log); then | |
24 | rc=1 | |
25 | cat mon.log | |
26 | fi | |
27 | rm mon.log | |
28 | return $rc | |
29 | } | |
30 | ||
11fdf7f2 TL |
31 | function get_online_devices_count() { |
32 | ssh_vm "lspci | grep -c NVM" | |
33 | } | |
34 | ||
35 | function wait_for_devices_ready() { | |
36 | count=$(get_online_devices_count) | |
37 | ||
38 | while [ $count -ne 4 ]; do | |
39 | echo "waitting for all devices online" | |
40 | count=$(get_online_devices_count) | |
41 | done | |
42 | } | |
43 | ||
7c673cae FG |
44 | function devices_initialization() { |
45 | timing_enter devices_initialization | |
46 | dd if=/dev/zero of=/root/test0 bs=1M count=1024 | |
47 | dd if=/dev/zero of=/root/test1 bs=1M count=1024 | |
48 | dd if=/dev/zero of=/root/test2 bs=1M count=1024 | |
49 | dd if=/dev/zero of=/root/test3 bs=1M count=1024 | |
50 | monitor_cmd "drive_add 0 file=/root/test0,format=raw,id=drive0,if=none" | |
51 | monitor_cmd "drive_add 1 file=/root/test1,format=raw,id=drive1,if=none" | |
52 | monitor_cmd "drive_add 2 file=/root/test2,format=raw,id=drive2,if=none" | |
53 | monitor_cmd "drive_add 3 file=/root/test3,format=raw,id=drive3,if=none" | |
54 | timing_exit devices_initialization | |
55 | } | |
56 | ||
57 | function insert_devices() { | |
58 | monitor_cmd "device_add nvme,drive=drive0,id=nvme0,serial=nvme0" | |
59 | monitor_cmd "device_add nvme,drive=drive1,id=nvme1,serial=nvme1" | |
60 | monitor_cmd "device_add nvme,drive=drive2,id=nvme2,serial=nvme2" | |
61 | monitor_cmd "device_add nvme,drive=drive3,id=nvme3,serial=nvme3" | |
11fdf7f2 | 62 | wait_for_devices_ready |
7c673cae FG |
63 | ssh_vm "scripts/setup.sh" |
64 | } | |
65 | ||
66 | function remove_devices() { | |
67 | monitor_cmd "device_del nvme0" | |
68 | monitor_cmd "device_del nvme1" | |
69 | monitor_cmd "device_del nvme2" | |
70 | monitor_cmd "device_del nvme3" | |
71 | } | |
72 | ||
73 | function devices_delete() { | |
74 | timing_enter devices_delete | |
75 | rm /root/test0 | |
76 | rm /root/test1 | |
77 | rm /root/test2 | |
78 | rm /root/test3 | |
79 | timing_exit devices_delete | |
80 | } | |
81 | ||
82 | password=$1 | |
11fdf7f2 TL |
83 | base_img=${DEPENDENCY_DIR}/fedora24.img |
84 | test_img=${DEPENDENCY_DIR}/fedora24_test.img | |
85 | qemu_pidfile=${DEPENDENCY_DIR}/qemupid | |
7c673cae FG |
86 | |
87 | if [ ! -e "$base_img" ]; then | |
88 | echo "Hotplug VM image not found; skipping test" | |
89 | exit 0 | |
90 | fi | |
91 | ||
92 | timing_enter hotplug | |
93 | ||
94 | timing_enter start_qemu | |
95 | ||
96 | qemu-img create -b "$base_img" -f qcow2 "$test_img" | |
97 | ||
98 | qemu-system-x86_64 \ | |
11fdf7f2 | 99 | -daemonize -display none -m 8192 \ |
7c673cae FG |
100 | -pidfile "$qemu_pidfile" \ |
101 | -hda "$test_img" \ | |
102 | -net user,hostfwd=tcp::10022-:22 \ | |
103 | -net nic \ | |
104 | -cpu host \ | |
105 | -smp cores=16,sockets=1 \ | |
106 | --enable-kvm \ | |
107 | -chardev socket,id=mon0,host=localhost,port=4444,server,nowait \ | |
108 | -mon chardev=mon0,mode=readline | |
109 | ||
110 | timing_exit start_qemu | |
111 | ||
112 | timing_enter wait_for_vm | |
113 | ssh_vm 'echo ready' | |
114 | timing_exit wait_for_vm | |
115 | ||
116 | timing_enter copy_repo | |
117 | (cd "$rootdir"; tar -cf - .) | (ssh_vm 'tar -xf -') | |
118 | timing_exit copy_repo | |
119 | ||
120 | devices_initialization | |
121 | insert_devices | |
122 | ||
123 | timing_enter hotplug_test | |
124 | ||
11fdf7f2 | 125 | ssh_vm "examples/nvme/hotplug/hotplug -i 0 -t 25 -n 4 -r 8" & |
7c673cae FG |
126 | example_pid=$! |
127 | ||
11fdf7f2 | 128 | sleep 4 |
7c673cae | 129 | remove_devices |
11fdf7f2 | 130 | sleep 4 |
7c673cae | 131 | insert_devices |
11fdf7f2 | 132 | sleep 4 |
7c673cae FG |
133 | remove_devices |
134 | devices_delete | |
135 | ||
136 | timing_enter wait_for_example | |
137 | wait $example_pid | |
138 | timing_exit wait_for_example | |
139 | ||
140 | trap - SIGINT SIGTERM EXIT | |
141 | ||
142 | qemupid=`cat "$qemu_pidfile" | awk '{printf $0}'` | |
143 | kill -9 $qemupid | |
144 | rm "$qemu_pidfile" | |
145 | rm "$test_img" | |
146 | ||
11fdf7f2 | 147 | report_test_completion "nvme_hotplug" |
7c673cae FG |
148 | timing_exit hotplug_test |
149 | ||
150 | timing_exit hotplug |