#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2019 Logan Gunthorpe
# Copyright (C) 2019 Eideticom Communications Inc.

. tests/nvme/rc
. common/xfs

DESCRIPTION="run mkfs and data verification fio job on an NVMeOF passthru controller"
TIMED=1

requires() {
	_nvme_requires
	_have_kernel_option NVME_TARGET_PASSTHRU
	_have_xfs
	_have_fio
}

device_requires() {
	_require_test_dev_size "${nvme_img_size}"
}

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

	_setup_nvmet

	local ctrldev
	local nsdev

	_nvmet_passthru_target_setup "${def_subsysnqn}"
	nsdev=$(_nvmet_passthru_target_connect "${nvme_trtype}" "${def_subsysnqn}")

	_xfs_run_fio_verify_io "${nsdev}" "${nvme_img_size}"

	_nvme_disconnect_subsys "${def_subsysnqn}"
	_nvmet_passthru_target_cleanup "${def_subsysnqn}"

	echo "Test complete"
}
