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

. tests/nvme/rc

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

requires() {
	_nvme_requires
	_have_kernel_option NVME_TARGET_PASSTHRU
	_have_fio
}

device_requires() {
	_require_test_dev_is_not_nvme_multipath
	_test_dev_has_no_metadata
}

set_conditions() {
	_set_nvme_trtype "$@"
}

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

	_setup_nvmet

	local nsdev

	_nvmet_passthru_target_setup
	nsdev=$(_nvmet_passthru_target_connect)
	if [[ -z "$nsdev" ]]; then
		echo "FAIL: Failed to find passthru target namespace"
	else
		_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
	fi

	_nvme_disconnect_subsys
	_nvmet_passthru_target_cleanup

	echo "Test complete"
}
