2019-07-18 12:12:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
|
2022-04-22 11:15:48 +00:00
|
|
|
function beetle_ssh() {
|
2022-04-22 12:25:57 +00:00
|
|
|
ssh_opts="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
2022-04-22 11:15:48 +00:00
|
|
|
if [[ -n $BEETLE_SSH_KEY ]]; then
|
2022-04-22 12:25:57 +00:00
|
|
|
ssh_opts+=" -i $(readlink -f $BEETLE_SSH_KEY)"
|
2022-04-22 11:15:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#shellcheck disable=SC2029
|
|
|
|
ssh $ssh_opts root@$ip "$@"
|
|
|
|
}
|
|
|
|
|
2019-07-18 12:12:34 +00:00
|
|
|
function insert_device() {
|
2022-04-22 11:15:48 +00:00
|
|
|
beetle_ssh 'Beetle --SetGpio "$gpio" HIGH'
|
2019-07-18 12:12:34 +00:00
|
|
|
waitforblk $name
|
|
|
|
DRIVER_OVERRIDE=$driver $rootdir/scripts/setup.sh
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_device() {
|
2022-04-22 11:15:48 +00:00
|
|
|
beetle_ssh 'Beetle --SetGpio "$gpio" LOW'
|
2019-07-18 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 09:50:32 +00:00
|
|
|
function restore_device() {
|
2022-04-22 11:15:48 +00:00
|
|
|
beetle_ssh 'Beetle --SetGpio "$gpio" HIGH'
|
2022-04-05 09:50:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 12:12:34 +00:00
|
|
|
ip=$1
|
|
|
|
gpio=$2
|
|
|
|
driver=$3
|
2022-04-22 11:15:48 +00:00
|
|
|
|
2019-07-18 12:12:34 +00:00
|
|
|
declare -i io_time=5
|
|
|
|
declare -i kernel_hotplug_time=7
|
|
|
|
|
|
|
|
timing_enter hotplug_hw_cfg
|
|
|
|
|
|
|
|
# Configure microcontroller
|
2022-04-22 11:15:48 +00:00
|
|
|
beetle_ssh 'Beetle --SetGpioDirection "$gpio" OUT'
|
2019-07-18 12:12:34 +00:00
|
|
|
|
|
|
|
# Get blk dev name connected to interposer
|
2022-04-22 11:15:48 +00:00
|
|
|
beetle_ssh 'Beetle --SetGpio "$gpio" HIGH'
|
2019-07-18 12:12:34 +00:00
|
|
|
sleep $kernel_hotplug_time
|
|
|
|
$rootdir/scripts/setup.sh reset
|
|
|
|
blk_list1=$(lsblk -d --output NAME | grep "^nvme")
|
|
|
|
remove_device
|
|
|
|
sleep $kernel_hotplug_time
|
|
|
|
blk_list2=$(lsblk -d --output NAME | grep "^nvme") || true
|
|
|
|
name=${blk_list1#"$blk_list2"}
|
|
|
|
|
|
|
|
insert_device
|
|
|
|
|
|
|
|
timing_exit hotplug_hw_cfg
|
|
|
|
|
|
|
|
timing_enter hotplug_hw_test
|
|
|
|
|
2021-10-06 11:36:14 +00:00
|
|
|
mode=""
|
|
|
|
if [ "$driver" = "uio_pci_generic" ]; then
|
|
|
|
mode="-m pa"
|
|
|
|
fi
|
|
|
|
|
2021-10-01 07:25:03 +00:00
|
|
|
exec {log}> >(tee -a "$testdir/log.txt")
|
|
|
|
exec >&$log 2>&1
|
|
|
|
|
2021-10-06 11:36:14 +00:00
|
|
|
$SPDK_EXAMPLE_DIR/hotplug -i 0 -t 100 -n 2 -r 2 $mode &
|
2021-10-01 07:25:03 +00:00
|
|
|
hotplug_pid=$!
|
|
|
|
|
2022-05-13 10:43:26 +00:00
|
|
|
trap 'killprocess $hotplug_pid; restore_device; rm $testdir/log.txt; exit 1' SIGINT SIGTERM EXIT
|
2019-07-18 12:12:34 +00:00
|
|
|
|
|
|
|
i=0
|
2022-09-15 11:47:02 +00:00
|
|
|
while ! grep -q "Starting I/O" $testdir/log.txt; do
|
2019-07-18 12:12:34 +00:00
|
|
|
[ $i -lt 20 ] || break
|
2020-05-07 11:27:06 +00:00
|
|
|
i=$((i + 1))
|
2019-07-18 12:12:34 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2022-09-15 11:47:02 +00:00
|
|
|
if ! grep -q "Starting I/O" $testdir/log.txt; then
|
2022-05-13 10:43:26 +00:00
|
|
|
rm $testdir/log.txt
|
2022-04-29 09:15:36 +00:00
|
|
|
exit 1
|
2019-07-18 12:12:34 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Add and remove NVMe with delays between to give some time for IO to proceed
|
|
|
|
remove_device
|
|
|
|
sleep $io_time
|
|
|
|
insert_device
|
|
|
|
sleep $io_time
|
|
|
|
remove_device
|
|
|
|
sleep $io_time
|
|
|
|
insert_device
|
|
|
|
sleep $io_time
|
|
|
|
|
|
|
|
timing_enter wait_for_example
|
2021-10-01 07:25:03 +00:00
|
|
|
|
|
|
|
if ! wait $hotplug_pid; then
|
|
|
|
echo "Hotplug example returned error!"
|
2022-05-13 10:43:26 +00:00
|
|
|
rm $testdir/log.txt
|
2022-04-29 09:15:36 +00:00
|
|
|
exit 1
|
2021-10-01 07:25:03 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-18 12:12:34 +00:00
|
|
|
timing_exit wait_for_example
|
|
|
|
|
2022-05-13 10:43:26 +00:00
|
|
|
rm $testdir/log.txt
|
|
|
|
|
2019-07-18 12:12:34 +00:00
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
|
|
|
|
timing_exit hotplug_hw_test
|