[PATCH for-next] selftests: rdma: Add rdma tests

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

 



Add a new directory to house the rdma specific tests and add the first
rdma_dev.sh test that checks the renaming and setting of adaptive
moderation using the rdma tool for the available RDMA devices in the
system.

Signed-off-by: Kamal Heib <kamalheib1@xxxxxxxxx>
---
 tools/testing/selftests/Makefile         |  1 +
 tools/testing/selftests/rdma/Makefile    |  6 ++
 tools/testing/selftests/rdma/lib.sh      | 55 ++++++++++++++++
 tools/testing/selftests/rdma/rdma_dev.sh | 83 ++++++++++++++++++++++++
 4 files changed, 145 insertions(+)
 create mode 100644 tools/testing/selftests/rdma/Makefile
 create mode 100644 tools/testing/selftests/rdma/lib.sh
 create mode 100755 tools/testing/selftests/rdma/rdma_dev.sh

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index c3feccb99ff5..870b9d0c36c9 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -37,6 +37,7 @@ TARGETS += powerpc
 TARGETS += proc
 TARGETS += pstore
 TARGETS += ptrace
+TARGETS += rdma
 TARGETS += rseq
 TARGETS += rtc
 TARGETS += seccomp
diff --git a/tools/testing/selftests/rdma/Makefile b/tools/testing/selftests/rdma/Makefile
new file mode 100644
index 000000000000..56df64b9b5d9
--- /dev/null
+++ b/tools/testing/selftests/rdma/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for rdma selftests
+
+TEST_PROGS := rdma_dev.sh
+
+include ../lib.mk
diff --git a/tools/testing/selftests/rdma/lib.sh b/tools/testing/selftests/rdma/lib.sh
new file mode 100644
index 000000000000..5f1cc08bc6b2
--- /dev/null
+++ b/tools/testing/selftests/rdma/lib.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+EXIT_STATUS=0
+RET=0
+#Kselftest framework requirement - SKIP code is 4
+ksft_skip=4
+
+check_and_skip()
+{
+	local rc=$1
+	local msg=$2
+
+	if [ $rc -ne 0 ]; then
+		echo "SKIP: $msg"
+		exit $ksft_skip
+	fi
+}
+
+check_ret_val()
+{
+	local rc=$1
+	local msg=$2
+
+	if [[ $RET -eq 0 && $rc -ne 0 ]]; then
+		RET=$rc
+		retmsg=$msg
+	fi
+}
+
+print_results()
+{
+	local test_name=$1
+
+	if [[ $RET -ne 0 ]]; then
+		EXIT_STATUS=1
+		printf "TEST: %-60s [FAIL]\n" "$test_name"
+		if [[ ! -z "$retmsg" ]]; then
+			printf "\t%s\n" "$retmsg"
+		fi
+		return 1
+	fi
+
+	printf "TEST: %-60s [OK]\n" "$test_name"
+	return 0
+}
+
+run_tests()
+{
+	local cur_test
+
+	for cur_test in ${ALL_TESTS}; do
+		$cur_test
+	done
+}
diff --git a/tools/testing/selftests/rdma/rdma_dev.sh b/tools/testing/selftests/rdma/rdma_dev.sh
new file mode 100755
index 000000000000..ca3ae7ddac9b
--- /dev/null
+++ b/tools/testing/selftests/rdma/rdma_dev.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+lib=$(dirname $0)/lib.sh
+source $lib
+
+ALL_TESTS="
+	test_rename
+	test_adaptive_moderation
+"
+
+test_rename()
+{
+	local dev=$RDMA_DEV
+
+	rdma dev set $dev name "tmp_$dev"
+	check_ret_val $? "Failed to rename $dev to tmp_$dev"
+
+	rdma dev set tmp_$dev name $dev
+	check_ret_val $? "Failed to restore $dev name"
+
+	print_results "$dev: Rename"
+}
+
+test_adaptive_moderation()
+{
+	local dev=$RDMA_DEV
+
+	rdma dev show $dev -d | grep -qE "adaptive-moderation"
+	check_and_skip $? "Setting adaptive-moderation is not supported"
+
+	rdma dev show $dev -d | grep -qE "adaptive-moderation off"
+	if [ $? -ne 0 ]; then
+		rdma dev set $dev adaptive-moderation off
+		check_ret_val $? "$dev: Failed to set adaptive-moderation to on"
+
+		rdma dev set $dev adaptive-moderation on
+		check_ret_val $? "$dev: Failed to restroe adaptive-moderation to off"
+	else
+		rdma dev set $dev adaptive-moderation on
+		check_ret_val $? "$dev: Failed to set adaptive-moderation to on"
+
+		rdma dev set $dev adaptive-moderation off
+		check_ret_val $? "$dev: Failed to restroe adaptive-moderation to off"
+	fi
+
+	print_results "$dev: Setting adaptive-moderation"
+}
+
+prepare()
+{
+	TMP_LIST_RDMADEV="$(mktemp)"
+	if [ ! -e $TMP_LIST_RDMADEV ]; then
+		echo "FAIL: Failed to create temp file to hold rdma devices"
+		exit 1
+	fi
+}
+
+cleanup()
+{
+	rm $TMP_LIST_RDMADEV
+}
+
+trap cleanup EXIT
+
+check_and_skip $(id -u) "Need root privileges"
+
+rdma dev show 2>/dev/null >/dev/null
+check_and_skip $? "Can not run the test without rdma tool"
+
+prepare
+
+rdma dev show | grep '^[0-9]' | cut -d" " -f 2 | cut -d: -f1> "$TMP_LIST_RDMADEV"
+test -s "$TMP_LIST_RDMADEV"
+check_and_skip $? "No RDMA devices available"
+
+while read rdma_dev
+do
+	RDMA_DEV=$rdma_dev
+	run_tests
+done < $TMP_LIST_RDMADEV
+
+exit $EXIT_STATUS
-- 
2.20.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux