]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/nvme/hotplug.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / test / nvme / hotplug.sh
CommitLineData
7c673cae
FG
1#!/usr/bin/env bash
2
3set -xe
4
5testdir=$(readlink -f $(dirname $0))
11fdf7f2
TL
6rootdir=$(readlink -f $testdir/../..)
7source $rootdir/test/common/autotest_common.sh
8
9if [ -z "${DEPENDENCY_DIR}" ]; then
10 echo DEPENDENCY_DIR not defined!
11 exit 1
12fi
7c673cae
FG
13
14function 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
21function 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
31function get_online_devices_count() {
32 ssh_vm "lspci | grep -c NVM"
33}
34
35function 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
44function 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
57function 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
66function 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
73function 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
82password=$1
11fdf7f2
TL
83base_img=${DEPENDENCY_DIR}/fedora24.img
84test_img=${DEPENDENCY_DIR}/fedora24_test.img
85qemu_pidfile=${DEPENDENCY_DIR}/qemupid
7c673cae
FG
86
87if [ ! -e "$base_img" ]; then
88 echo "Hotplug VM image not found; skipping test"
89 exit 0
90fi
91
92timing_enter hotplug
93
94timing_enter start_qemu
95
96qemu-img create -b "$base_img" -f qcow2 "$test_img"
97
98qemu-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
110timing_exit start_qemu
111
112timing_enter wait_for_vm
113ssh_vm 'echo ready'
114timing_exit wait_for_vm
115
116timing_enter copy_repo
117(cd "$rootdir"; tar -cf - .) | (ssh_vm 'tar -xf -')
118timing_exit copy_repo
119
120devices_initialization
121insert_devices
122
123timing_enter hotplug_test
124
11fdf7f2 125ssh_vm "examples/nvme/hotplug/hotplug -i 0 -t 25 -n 4 -r 8" &
7c673cae
FG
126example_pid=$!
127
11fdf7f2 128sleep 4
7c673cae 129remove_devices
11fdf7f2 130sleep 4
7c673cae 131insert_devices
11fdf7f2 132sleep 4
7c673cae
FG
133remove_devices
134devices_delete
135
136timing_enter wait_for_example
137wait $example_pid
138timing_exit wait_for_example
139
140trap - SIGINT SIGTERM EXIT
141
142qemupid=`cat "$qemu_pidfile" | awk '{printf $0}'`
143kill -9 $qemupid
144rm "$qemu_pidfile"
145rm "$test_img"
146
11fdf7f2 147report_test_completion "nvme_hotplug"
7c673cae
FG
148timing_exit hotplug_test
149
150timing_exit hotplug