test: Add autotest for hotplug.
Change-Id: I5822c36a7374b680a3b213b8768afd834daf59d9 Signed-off-by: Cunyin Chang <cunyin.chang@intel.com>
This commit is contained in:
parent
d77a04d148
commit
94cf5c00d2
@ -79,6 +79,7 @@ run_test test/lib/bdev/blockdev.sh
|
|||||||
run_test test/lib/event/event.sh
|
run_test test/lib/event/event.sh
|
||||||
run_test test/lib/nvme/nvme.sh
|
run_test test/lib/nvme/nvme.sh
|
||||||
if [ $RUN_NIGHTLY -eq 1 ]; then
|
if [ $RUN_NIGHTLY -eq 1 ]; then
|
||||||
|
run_test test/lib/nvme/hotplug.sh intel
|
||||||
run_test test/lib/nvme/nvmemp.sh
|
run_test test/lib/nvme/nvmemp.sh
|
||||||
fi
|
fi
|
||||||
run_test test/lib/nvmf/nvmf.sh
|
run_test test/lib/nvmf/nvmf.sh
|
||||||
|
@ -189,7 +189,7 @@ function run_test() {
|
|||||||
echo "START TEST $1"
|
echo "START TEST $1"
|
||||||
echo "************************************"
|
echo "************************************"
|
||||||
set -x
|
set -x
|
||||||
time $1
|
time "$@"
|
||||||
set +x
|
set +x
|
||||||
echo "************************************"
|
echo "************************************"
|
||||||
echo "END TEST $1"
|
echo "END TEST $1"
|
||||||
|
127
test/lib/nvme/hotplug.sh
Executable file
127
test/lib/nvme/hotplug.sh
Executable file
@ -0,0 +1,127 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
testdir=$(readlink -f $(dirname $0))
|
||||||
|
rootdir="$testdir/../../.."
|
||||||
|
source $rootdir/scripts/autotest_common.sh
|
||||||
|
|
||||||
|
function ssh_vm() {
|
||||||
|
sshpass -p "$password" ssh -o PubkeyAuthentication=no -p 10022 root@localhost "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function monitor_cmd() {
|
||||||
|
rc=0
|
||||||
|
if ! (echo "$@" | nc localhost 4444 > mon.log); then
|
||||||
|
rc=1
|
||||||
|
cat mon.log
|
||||||
|
fi
|
||||||
|
rm mon.log
|
||||||
|
return $rc
|
||||||
|
}
|
||||||
|
|
||||||
|
function devices_initialization() {
|
||||||
|
timing_enter devices_initialization
|
||||||
|
dd if=/dev/zero of=/root/test0 bs=1M count=1024
|
||||||
|
dd if=/dev/zero of=/root/test1 bs=1M count=1024
|
||||||
|
dd if=/dev/zero of=/root/test2 bs=1M count=1024
|
||||||
|
dd if=/dev/zero of=/root/test3 bs=1M count=1024
|
||||||
|
monitor_cmd "drive_add 0 file=/root/test0,format=raw,id=drive0,if=none"
|
||||||
|
monitor_cmd "drive_add 1 file=/root/test1,format=raw,id=drive1,if=none"
|
||||||
|
monitor_cmd "drive_add 2 file=/root/test2,format=raw,id=drive2,if=none"
|
||||||
|
monitor_cmd "drive_add 3 file=/root/test3,format=raw,id=drive3,if=none"
|
||||||
|
timing_exit devices_initialization
|
||||||
|
}
|
||||||
|
|
||||||
|
function insert_devices() {
|
||||||
|
monitor_cmd "device_add nvme,drive=drive0,id=nvme0,serial=nvme0"
|
||||||
|
monitor_cmd "device_add nvme,drive=drive1,id=nvme1,serial=nvme1"
|
||||||
|
monitor_cmd "device_add nvme,drive=drive2,id=nvme2,serial=nvme2"
|
||||||
|
monitor_cmd "device_add nvme,drive=drive3,id=nvme3,serial=nvme3"
|
||||||
|
ssh_vm "scripts/setup.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_devices() {
|
||||||
|
monitor_cmd "device_del nvme0"
|
||||||
|
monitor_cmd "device_del nvme1"
|
||||||
|
monitor_cmd "device_del nvme2"
|
||||||
|
monitor_cmd "device_del nvme3"
|
||||||
|
}
|
||||||
|
|
||||||
|
function devices_delete() {
|
||||||
|
timing_enter devices_delete
|
||||||
|
rm /root/test0
|
||||||
|
rm /root/test1
|
||||||
|
rm /root/test2
|
||||||
|
rm /root/test3
|
||||||
|
timing_exit devices_delete
|
||||||
|
}
|
||||||
|
|
||||||
|
password=$1
|
||||||
|
base_img=/home/sys_sgsw/fedora24.img
|
||||||
|
test_img=/home/sys_sgsw/fedora24_test.img
|
||||||
|
qemu_pidfile=/home/sys_sgsw/qemupid
|
||||||
|
|
||||||
|
if [ ! -e "$base_img" ]; then
|
||||||
|
echo "Hotplug VM image not found; skipping test"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
timing_enter hotplug
|
||||||
|
|
||||||
|
timing_enter start_qemu
|
||||||
|
|
||||||
|
qemu-img create -b "$base_img" -f qcow2 "$test_img"
|
||||||
|
|
||||||
|
qemu-system-x86_64 \
|
||||||
|
-daemonize -display none -m 1024 \
|
||||||
|
-pidfile "$qemu_pidfile" \
|
||||||
|
-hda "$test_img" \
|
||||||
|
-net user,hostfwd=tcp::10022-:22 \
|
||||||
|
-net nic \
|
||||||
|
-cpu host \
|
||||||
|
-smp cores=16,sockets=1 \
|
||||||
|
--enable-kvm \
|
||||||
|
-chardev socket,id=mon0,host=localhost,port=4444,server,nowait \
|
||||||
|
-mon chardev=mon0,mode=readline
|
||||||
|
|
||||||
|
timing_exit start_qemu
|
||||||
|
|
||||||
|
timing_enter wait_for_vm
|
||||||
|
ssh_vm 'echo ready'
|
||||||
|
timing_exit wait_for_vm
|
||||||
|
|
||||||
|
timing_enter copy_repo
|
||||||
|
(cd "$rootdir"; tar -cf - .) | (ssh_vm 'tar -xf -')
|
||||||
|
timing_exit copy_repo
|
||||||
|
|
||||||
|
devices_initialization
|
||||||
|
insert_devices
|
||||||
|
|
||||||
|
timing_enter hotplug_test
|
||||||
|
|
||||||
|
ssh_vm "examples/nvme/hotplug/hotplug -t 10 -i 4 -r 8" &
|
||||||
|
example_pid=$!
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
remove_devices
|
||||||
|
sleep 2
|
||||||
|
insert_devices
|
||||||
|
sleep 2
|
||||||
|
remove_devices
|
||||||
|
devices_delete
|
||||||
|
|
||||||
|
timing_enter wait_for_example
|
||||||
|
wait $example_pid
|
||||||
|
timing_exit wait_for_example
|
||||||
|
|
||||||
|
trap - SIGINT SIGTERM EXIT
|
||||||
|
|
||||||
|
qemupid=`cat "$qemu_pidfile" | awk '{printf $0}'`
|
||||||
|
kill -9 $qemupid
|
||||||
|
rm "$qemu_pidfile"
|
||||||
|
rm "$test_img"
|
||||||
|
|
||||||
|
timing_exit hotplug_test
|
||||||
|
|
||||||
|
timing_exit hotplug
|
Loading…
Reference in New Issue
Block a user