From: Kamal Heib <kamalheib1@gmail.com>
To: linux-rdma@vger.kernel.org
Cc: Doug Ledford <dledford@redhat.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Kamal Heib <kamalheib1@gmail.com>
Subject: [PATCH for-next] selftests: rdma: Add rdma tests
Date: Wed, 23 Oct 2019 20:39:54 +0300 [thread overview]
Message-ID: <20191023173954.29291-1-kamalheib1@gmail.com> (raw)
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@gmail.com>
---
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
next reply other threads:[~2019-10-23 17:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-23 17:39 Kamal Heib [this message]
2019-10-23 17:42 ` [PATCH for-next] selftests: rdma: Add rdma tests Jason Gunthorpe
2019-10-23 20:10 ` Kamal Heib
2019-10-24 6:39 ` Leon Romanovsky
2019-10-24 13:39 ` Kamal Heib
2019-10-24 16:11 ` Leon Romanovsky
2019-10-24 12:11 ` Dennis Dalessandro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191023173954.29291-1-kamalheib1@gmail.com \
--to=kamalheib1@gmail.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=linux-rdma@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox