#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2018 Johannes Thumshirn
#
# Regression test for commit 74c6c7153084 ("nvme: don't send keep-alives to the
# discovery controller").

. tests/nvme/rc

DESCRIPTION="test if we're sending keep-alives to a discovery controller"
QUICK=1

requires() {
	_nvme_requires
	_have_loop
	_require_nvme_trtype_is_fabrics
	_have_writeable_kmsg
}

set_conditions() {
	_set_nvme_trtype "$@"
}

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

	_setup_nvmet

	_nvmet_target_setup

	_nvme_connect_subsys --port none \
			     --subsysnqn "nqn.2014-08.org.nvmexpress.discovery"

	# This is ugly but checking for the absence of error messages is ...
	sleep 10

	if _dmesg_since_test_start | grep -q "failed nvme_keep_alive_end_io error="; then
		echo "Fail"
	fi

	if _dmesg_since_test_start | grep -q "nvmet: unsupported cmd 24"; then
		echo "Fail"
	fi

	_nvme_disconnect_subsys --subsysnqn "nqn.2014-08.org.nvmexpress.discovery"

	_nvmet_target_cleanup

	echo "Test complete"
}
