[PATCH 5/5 blktests] nvme: make new testcases backward compatible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch makes newly added testcases backward compatible with
right value setting into the SKIP_REASON variable.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx>
---
 tests/nvme/033 | 60 +++++++++++++++++++++++++++-----------------------
 tests/nvme/034 | 59 ++++++++++++++++++++++++++-----------------------
 tests/nvme/rc  | 27 +++++++++++++++++------
 3 files changed, 83 insertions(+), 63 deletions(-)

diff --git a/tests/nvme/033 b/tests/nvme/033
index 97eba7f..db5ded3 100755
--- a/tests/nvme/033
+++ b/tests/nvme/033
@@ -9,49 +9,53 @@
 DESCRIPTION="Test NVMeOF target cntlid[min|max] attributes"
 QUICK=1
 
+PORT=""
+NVMEDEV=""
+LOOP_DEV=""
+FILE_PATH="$TMPDIR/img"
+SUBSYS_NAME="blktests-subsystem-1"
+
+_have_cid_min_max()
+{
+	local cid_min=14
+	local cid_max=15
+
+	_setup_nvmet
+	truncate -s 1G "${FILE_PATH}"
+	LOOP_DEV="$(losetup -f --show "${FILE_PATH}")"
+
+	# we can only know skip reason when we create a subsys
+	 _create_nvmet_subsystem "${SUBSYS_NAME}" "${LOOP_DEV}" \
+		"91fdba0d-f87b-4c25-b80f-db7be1418b9e" ${cid_min} ${cid_max}
+}
+
 requires() {
 	_have_program nvme && _have_modules loop nvme-loop nvmet && \
-		_have_configfs
+		_have_configfs && _have_cid_min_max
 }
 
 test() {
 	echo "Running ${TEST_NAME}"
 
-	_setup_nvmet
-
-	local port
-	local nvmedev
-	local loop_dev
-	local cid_min=14
-	local cid_max=15
-	local file_path="$TMPDIR/img"
-	local subsys_name="blktests-subsystem-1"
-
-	truncate -s 1G "${file_path}"
-
-	loop_dev="$(losetup -f --show "${file_path}")"
-
-	_create_nvmet_subsystem "${subsys_name}" "${loop_dev}" \
-		"91fdba0d-f87b-4c25-b80f-db7be1418b9e" ${cid_min} ${cid_max}
-	port="$(_create_nvmet_port "loop")"
-	_add_nvmet_subsys_to_port "${port}" "${subsys_name}"
+	PORT="$(_create_nvmet_port "loop")"
+	_add_nvmet_subsys_to_port "${PORT}" "${SUBSYS_NAME}"
 
-	nvme connect -t loop -n "${subsys_name}"
+	nvme connect -t loop -n "${SUBSYS_NAME}"
 
 	udevadm settle
 
-	nvmedev="$(_find_nvme_loop_dev)"
-	nvme id-ctrl /dev/${nvmedev}n1 | grep cntlid | tr -s ' ' ' '
+	NVMEDEV="$(_find_nvme_loop_dev)"
+	nvme id-ctrl /dev/${NVMEDEV}n1 | grep cntlid | tr -s ' ' ' '
 
-	nvme disconnect -n "${subsys_name}"
+	nvme disconnect -n "${SUBSYS_NAME}"
 
-	_remove_nvmet_subsystem_from_port "${port}" "${subsys_name}"
-	_remove_nvmet_subsystem "${subsys_name}"
-	_remove_nvmet_port "${port}"
+	_remove_nvmet_subsystem_from_port "${PORT}" "${SUBSYS_NAME}"
+	_remove_nvmet_subsystem "${SUBSYS_NAME}"
+	_remove_nvmet_port "${PORT}"
 
-	losetup -d "${loop_dev}"
+	losetup -d "${LOOP_DEV}"
 
-	rm "${file_path}"
+	rm "${FILE_PATH}"
 
 	echo "Test complete"
 }
diff --git a/tests/nvme/034 b/tests/nvme/034
index 1a55ff9..39d833f 100755
--- a/tests/nvme/034
+++ b/tests/nvme/034
@@ -9,50 +9,53 @@
 DESCRIPTION="Test NVMeOF target model attribute"
 QUICK=1
 
+PORT=""
+NVMEDEV=""
+LOOP_DEV=""
+FILE_PATH="$TMPDIR/img"
+SUBSYS_NAME="blktests-subsystem-1"
+
+_have_model()
+{
+	local model="test~model"
+
+	_setup_nvmet
+	truncate -s 1G "${FILE_PATH}"
+	LOOP_DEV="$(losetup -f --show "${FILE_PATH}")"
+
+	# we can only know skip reason when we create a subsys
+	 _create_nvmet_subsystem "${SUBSYS_NAME}" "${LOOP_DEV}" \
+		"91fdba0d-f87b-4c25-b80f-db7be1418b9e" 14 15 \
+		${model}
+}
 requires() {
 	_have_program nvme && _have_modules loop nvme-loop nvmet && \
-		_have_configfs
+		_have_configfs && _have_model
 }
 
 test() {
 	echo "Running ${TEST_NAME}"
 
-	_setup_nvmet
-
-	local port
-	local result
-	local nvmedev
-	local loop_dev
-	local model="test~model"
-	local file_path="$TMPDIR/img"
-	local subsys_name="blktests-subsystem-1"
-
-	truncate -s 1G "${file_path}"
-
-	loop_dev="$(losetup -f --show "${file_path}")"
-
-	_create_nvmet_subsystem "${subsys_name}" "${loop_dev}" \
-		"91fdba0d-f87b-4c25-b80f-db7be1418b9e" 0 100 ${model}
-	port="$(_create_nvmet_port "loop")"
-	_add_nvmet_subsys_to_port "${port}" "${subsys_name}"
+	PORT="$(_create_nvmet_port "loop")"
+	_add_nvmet_subsys_to_port "${PORT}" "${SUBSYS_NAME}"
 
-	nvme connect -t loop -n "${subsys_name}"
+	nvme connect -t loop -n "${SUBSYS_NAME}"
 
 	udevadm settle
 
-	nvmedev="$(_find_nvme_loop_dev)"
-	nvme list | grep ${nvmedev}n1 | grep -q test~model
+	NVMEDEV="$(_find_nvme_loop_dev)"
+	nvme list | grep ${NVMEDEV}n1 | grep -q test~model
 	result=$?
 
-	nvme disconnect -n "${subsys_name}"
+	nvme disconnect -n "${SUBSYS_NAME}"
 
-	_remove_nvmet_subsystem_from_port "${port}" "${subsys_name}"
-	_remove_nvmet_subsystem "${subsys_name}"
-	_remove_nvmet_port "${port}"
+	_remove_nvmet_subsystem_from_port "${PORT}" "${SUBSYS_NAME}"
+	_remove_nvmet_subsystem "${SUBSYS_NAME}"
+	_remove_nvmet_port "${PORT}"
 
-	losetup -d "${loop_dev}"
+	losetup -d "${LOOP_DEV}"
 
-	rm "${file_path}"
+	rm "${FILE_PATH}"
 
 	if [ ${result} -eq 0 ]; then
 		echo "Test complete"
diff --git a/tests/nvme/rc b/tests/nvme/rc
index 377c7f7..77bafd8 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -128,15 +128,28 @@ _create_nvmet_subsystem() {
 
 	mkdir -p "${cfs_path}"
 	echo 1 > "${cfs_path}/attr_allow_any_host"
-	_create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}"
-
-	if [ $# -eq 5 ] && [ -f ${cfs_path}/attr_cntlid_min ]; then
-		echo ${cntlid_min} > ${cfs_path}/attr_cntlid_min
-		echo ${cntlid_max} > ${cfs_path}/attr_cntlid_max
+	if [ $# -eq 5 ]; then
+		if [ -f ${cfs_path}/attr_cntlid_min ]; then
+			echo ${cntlid_min} > ${cfs_path}/attr_cntlid_min
+			echo ${cntlid_max} > ${cfs_path}/attr_cntlid_max
+		else
+			SKIP_REASON="attr_cntlid_[min|max] not found"
+			rmdir "${cfs_path}"
+			return 1
+		fi
 	fi
-	if [ $# -eq 6 ] && [ -f ${cfs_path}/attr_model ]; then
-		echo ${model} > ${cfs_path}/attr_model
+	if [ $# -eq 6 ]; then
+		if [ -f ${cfs_path}/attr_model ]; then
+			echo ${model} > ${cfs_path}/attr_model
+		else
+			SKIP_REASON="attr_cntlid_model not found"
+			rmdir "${cfs_path}"
+			return 1
+		fi
 	fi
+	_create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}"
+
+	return 0
 }
 
 _remove_nvmet_ns() {
-- 
2.22.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux