From 21bd9427513b52d42d21efb91f57805631e40b82 Mon Sep 17 00:00:00 2001 From: Tomasz Kulasek Date: Fri, 10 Aug 2018 15:21:42 +0200 Subject: [PATCH] libsock: add functional tests Change-Id: I3c86c1b4a9c8ae3f18264f33b15d647e4081a12c Signed-off-by: Tomasz Kulasek Reviewed-on: https://review.gerrithub.io/421911 Chandler-Test-Pool: SPDK Automated Test System Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- test/common/autotest_common.sh | 4 +-- test/iscsi_tgt/common.sh | 3 ++ test/iscsi_tgt/iscsi_tgt.sh | 1 + test/iscsi_tgt/sock/sock.sh | 62 ++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100755 test/iscsi_tgt/sock/sock.sh diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 1a55b7ca1..cc71354d8 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -314,12 +314,12 @@ function waitforlisten() { fi if hash ss; then - if $ns_cmd ss -lx | egrep -q "\s+$rpc_addr\s+"; then + if $ns_cmd ss -ln | egrep -q "\s+$rpc_addr\s+"; then ret=0 fi else # if system doesn't have ss, just assume it has netstat - if $ns_cmd netstat -an -x | grep -iw LISTENING | egrep -q "\s+$rpc_addr\$"; then + if $ns_cmd netstat -an | grep -iw LISTENING | egrep -q "\s+$rpc_addr\$"; then ret=0 fi fi diff --git a/test/iscsi_tgt/common.sh b/test/iscsi_tgt/common.sh index 1928449b5..dfeebbe0d 100644 --- a/test/iscsi_tgt/common.sh +++ b/test/iscsi_tgt/common.sh @@ -31,6 +31,9 @@ function create_veth_interfaces() { ip netns add $TARGET_NAMESPACE ip link set $TARGET_INTERFACE netns $TARGET_NAMESPACE + # Accept connections from veth interface + iptables -I INPUT 1 -i $INITIATOR_INTERFACE -p tcp --dport $ISCSI_PORT -j ACCEPT + $TARGET_NS_CMD ip link set lo up $TARGET_NS_CMD ip addr add $TARGET_IP/24 dev $TARGET_INTERFACE $TARGET_NS_CMD ip link set $TARGET_INTERFACE up diff --git a/test/iscsi_tgt/iscsi_tgt.sh b/test/iscsi_tgt/iscsi_tgt.sh index fbf9f239b..49c988349 100755 --- a/test/iscsi_tgt/iscsi_tgt.sh +++ b/test/iscsi_tgt/iscsi_tgt.sh @@ -32,6 +32,7 @@ create_veth_interfaces $TEST_TYPE start_stub "-s 2048 -i 0 -m $ISCSI_TEST_CORE_MASK" trap "kill_stub; cleanup_veth_interfaces $TEST_TYPE; exit 1" SIGINT SIGTERM EXIT +run_test suite ./test/iscsi_tgt/sock/sock.sh run_test suite ./test/iscsi_tgt/calsoft/calsoft.sh run_test suite ./test/iscsi_tgt/filesystem/filesystem.sh run_test suite ./test/iscsi_tgt/reset/reset.sh diff --git a/test/iscsi_tgt/sock/sock.sh b/test/iscsi_tgt/sock/sock.sh new file mode 100755 index 000000000..990f91701 --- /dev/null +++ b/test/iscsi_tgt/sock/sock.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../../..) +source $rootdir/test/common/autotest_common.sh +source $rootdir/test/iscsi_tgt/common.sh + +HELLO_SOCK_APP="$TARGET_NS_CMD $rootdir/examples/sock/hello_world/hello_sock" +SOCAT_APP="socat" + +# ---------------- +# Test client path +# ---------------- +timing_enter sock_client +echo "Testing client path" + +# start echo server using socat +$SOCAT_APP tcp-l:$ISCSI_PORT,fork,bind=$INITIATOR_IP exec:'/bin/cat' & server_pid=$! +trap "killprocess $server_pid;exit 1" SIGINT SIGTERM EXIT + +waitforlisten $server_pid $INITIATOR_IP:$ISCSI_PORT + +# send message using hello_sock client +message="**MESSAGE:This is a test message from the client**" +response=$( echo $message | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT ) + +if ! echo "$response" | grep -q "$message"; then + exit 1 +fi + +trap '-' SIGINT SIGTERM EXIT +# NOTE: socat returns code 143 on SIGINT +killprocess $server_pid || true + +report_test_completion "sock_client" +timing_exit sock_client + +# ---------------- +# Test server path +# ---------------- + +timing_enter sock_server + +# start echo server using hello_sock echo server +$HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT -S & server_pid=$! +trap "killprocess $server_pid;exit 1" SIGINT SIGTERM EXIT +waitforlisten $server_pid + +# send message to server using socat +message="**MESSAGE:This is a test message to the server**" +response=$( echo $message | $SOCAT_APP - tcp:$TARGET_IP:$ISCSI_PORT 2>/dev/null ) + +if [ "$message" != "$response" ]; then + exit 1 +fi + +trap - SIGINT SIGTERM EXIT + +killprocess $server_pid + +report_test_completion "sock_server" +timing_exit sock_server