#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2018 Keith Busch <keith.busch@intel.com>
#
# Do disable PCI device while doing I/O to it

. tests/block/rc

DESCRIPTION="break PCI link device while doing I/O"
QUICK=1
CAN_BE_ZONED=1

requires() {
	_have_fio
	_have_program setpci
}

device_requires() {
	_require_test_dev_is_pci && _require_test_dev_in_hotplug_slot
}

test_device() {
	echo "Running ${TEST_NAME}"

	local parent

	parent="$(_get_pci_parent_from_blkdev)"

	# start fio job
	_run_fio_rand_io --filename="$TEST_DEV" --time_based --runtime=10 \
		--continue_on_error=io 2> /dev/null &
	sleep 5

	# masks  the slot's link disable bit to 'on'
	setpci -s "${parent}" CAP_EXP+10.w=10:10
	sleep 5

	# masks the slot's link disable bit back to 'off'
	setpci -s "${parent}" CAP_EXP+10.w=00:10
	sleep 5

	wait

	echo "Test complete"
}
