From: Geliang Tang <tanggeliang@kylinos.cn>
A test case for NVMe over MPTCP has been implemented. It verifies the
proper functionality of nvme list, discover, connect, and disconnect
commands. Additionally, read/write performance has been evaluated using
fio.
Co-developed-by: Hui Zhu <zhuhui@kylinos.cn>
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Co-developed-by: zhenwei pi <zhenwei.pi@linux.dev>
Signed-off-by: zhenwei pi <zhenwei.pi@linux.dev>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/net/mptcp/config | 7 +
.../testing/selftests/net/mptcp/mptcp_nvme.sh | 120 ++++++++++++++++++
2 files changed, 127 insertions(+)
create mode 100755 tools/testing/selftests/net/mptcp/mptcp_nvme.sh
diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selftests/net/mptcp/config
index 59051ee2a986..0eee348eff8b 100644
--- a/tools/testing/selftests/net/mptcp/config
+++ b/tools/testing/selftests/net/mptcp/config
@@ -34,3 +34,10 @@ CONFIG_NFT_SOCKET=m
CONFIG_NFT_TPROXY=m
CONFIG_SYN_COOKIES=y
CONFIG_VETH=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_NVME_CORE=y
+CONFIG_NVME_FABRICS=y
+CONFIG_NVME_TCP=y
+CONFIG_NVME_TARGET=y
+CONFIG_NVME_TARGET_TCP=y
+CONFIG_NVME_MULTIPATH=y
diff --git a/tools/testing/selftests/net/mptcp/mptcp_nvme.sh b/tools/testing/selftests/net/mptcp/mptcp_nvme.sh
new file mode 100755
index 000000000000..1c24198003e2
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/mptcp_nvme.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+trtype="${1:-mptcp}"
+traddr="${2:-127.0.0.1}"
+ns=1
+port=1234
+trsvcid=4420
+nqn=nqn.2014-08.org.nvmexpress.${trtype}dev
+final_ret=0
+
+#ip mptcp monitor &
+
+cleanup()
+{
+ rm -rf /sys/kernel/config/nvmet/ports/${port}/subsystems/${trtype}subsys
+ rmdir /sys/kernel/config/nvmet/ports/${port}
+ echo 0 > /sys/kernel/config/nvmet/subsystems/${nqn}/namespaces/${ns}/enable
+ echo -n 0 > /sys/kernel/config/nvmet/subsystems/${nqn}/namespaces/${ns}/device_path
+ rmdir /sys/kernel/config/nvmet/subsystems/${nqn}/namespaces/${ns}
+ rmdir /sys/kernel/config/nvmet/subsystems/${nqn}
+ losetup -d /dev/loop100
+ rm -rf /tmp/test.raw
+}
+
+check_error()
+{
+ if dmesg | grep -E -q "starting error recovery|Buffer I/O error"; then
+ cleanup
+ exit 1
+ fi
+}
+
+dd if=/dev/zero of=/tmp/test.raw bs=1M count=0 seek=512
+losetup /dev/loop100 /tmp/test.raw
+cd /sys/kernel/config/nvmet/subsystems
+mkdir ${nqn}
+cd ${nqn}
+echo 1 > attr_allow_any_host
+cd namespaces
+mkdir ${ns}
+cd ${ns}
+echo /dev/loop100 > device_path
+echo 1 > enable
+cd /sys/kernel/config/nvmet/ports
+mkdir ${port}
+cd ${port}
+echo ${trtype} > addr_trtype
+echo ipv4 > addr_adrfam
+echo ${traddr} > addr_traddr
+echo ${trsvcid} > addr_trsvcid
+cd subsystems
+ln -s ../../../subsystems/${nqn} ${trtype}subsys
+
+echo
+echo "nvme discover"
+echo
+nvme discover -t ${trtype} -a ${traddr} -s ${trsvcid}
+
+echo
+echo "nvme connect"
+echo
+devname=$(nvme connect -t ${trtype} -a ${traddr} -s ${trsvcid} -n ${nqn} | awk '{print $4}')
+lret=$?
+if [ $lret -ne 0 ]; then
+ final_ret=${lret}
+fi
+check_error
+
+sleep 0.5
+echo
+echo "nvme list"
+echo
+nvme list
+lret=$?
+if [ $lret -ne 0 ]; then
+ final_ret=${lret}
+fi
+check_error
+
+echo
+echo "fio randread"
+echo
+fio --name=global --direct=1 --norandommap --randrepeat=0 --ioengine=libaio \
+ --thread=1 --blocksize=4k --runtime=10 --time_based --rw=randread --numjobs=4 \
+ --iodepth=256 --group_reporting --size=100% --name=libaio_4_256_4k_randread \
+ --filename=/dev/${devname}n1
+lret=$?
+if [ $lret -ne 0 ]; then
+ final_ret=${lret}
+fi
+check_error
+
+echo
+echo "fio randwrite"
+echo
+fio --name=global --direct=1 --norandommap --randrepeat=0 --ioengine=libaio \
+ --thread=1 --blocksize=4k --runtime=10 --time_based --rw=randwrite --numjobs=4 \
+ --iodepth=256 --group_reporting --size=100% --name=libaio_4_256_4k_randwrite \
+ --filename=/dev/${devname}n1
+lret=$?
+if [ $lret -ne 0 ]; then
+ final_ret=${lret}
+fi
+check_error
+
+sleep 0.5
+echo
+echo "nvme disconnect"
+echo
+nvme disconnect -n ${nqn}
+lret=$?
+if [ $lret -ne 0 ]; then
+ final_ret=${lret}
+fi
+check_error
+
+cleanup
+echo "final_ret=${final_ret}"
+exit ${final_ret}
--
2.51.0