2018-08-10 13:21:42 +00:00
|
|
|
#!/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
|
|
|
|
|
2019-06-17 04:04:58 +00:00
|
|
|
function waitfortcp() {
|
|
|
|
local addr="$2"
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
if hash ip &> /dev/null; then
|
2019-06-17 04:04:58 +00:00
|
|
|
local have_ip_cmd=true
|
|
|
|
else
|
|
|
|
local have_ip_cmd=false
|
|
|
|
fi
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
if hash ss &> /dev/null; then
|
2019-06-17 04:04:58 +00:00
|
|
|
local have_ss_cmd=true
|
|
|
|
else
|
|
|
|
local have_ss_cmd=false
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Waiting for process to start up and listen on address $addr..."
|
|
|
|
# turn off trace for this loop
|
|
|
|
xtrace_disable
|
|
|
|
local ret=0
|
|
|
|
local i
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 40; i != 0; i--)); do
|
2019-06-17 04:04:58 +00:00
|
|
|
# if the process is no longer running, then exit the script
|
|
|
|
# since it means the application crashed
|
|
|
|
if ! kill -s 0 $1; then
|
|
|
|
echo "ERROR: process (pid: $1) is no longer running"
|
|
|
|
ret=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $have_ip_cmd; then
|
|
|
|
namespace=$(ip netns identify $1)
|
|
|
|
if [ -n "$namespace" ]; then
|
|
|
|
ns_cmd="ip netns exec $namespace"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $have_ss_cmd; then
|
2019-07-04 12:52:35 +00:00
|
|
|
if $ns_cmd ss -ln | grep -E -q "\s+$addr\s+"; then
|
2019-06-17 04:04:58 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
elif [[ "$(uname -s)" == "Linux" ]]; then
|
|
|
|
# For Linux, if system doesn't have ss, just assume it has netstat
|
2019-07-04 12:52:35 +00:00
|
|
|
if $ns_cmd netstat -an | grep -iw LISTENING | grep -E -q "\s+$addr\$"; then
|
2019-06-17 04:04:58 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
|
|
|
|
xtrace_restore
|
2020-05-07 11:27:06 +00:00
|
|
|
if ((i == 0)); then
|
2019-06-17 04:04:58 +00:00
|
|
|
echo "ERROR: timeout while waiting for process (pid: $1) to start listening on '$addr'"
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2020-08-11 10:36:11 +00:00
|
|
|
iscsitestinit
|
2020-01-18 16:07:36 +00:00
|
|
|
|
2020-05-11 22:02:01 +00:00
|
|
|
HELLO_SOCK_APP="${TARGET_NS_CMD[*]} $SPDK_EXAMPLE_DIR/hello_sock"
|
2018-08-10 13:21:42 +00:00
|
|
|
SOCAT_APP="socat"
|
|
|
|
|
|
|
|
# ----------------
|
|
|
|
# Test client path
|
|
|
|
# ----------------
|
|
|
|
timing_enter sock_client
|
|
|
|
echo "Testing client path"
|
|
|
|
|
|
|
|
# start echo server using socat
|
2020-05-07 11:27:06 +00:00
|
|
|
$SOCAT_APP tcp-l:$ISCSI_PORT,fork,bind=$INITIATOR_IP exec:'/bin/cat' &
|
|
|
|
server_pid=$!
|
2020-08-11 10:36:11 +00:00
|
|
|
trap 'killprocess $server_pid;iscsitestfini; exit 1' SIGINT SIGTERM EXIT
|
2018-08-10 13:21:42 +00:00
|
|
|
|
2019-06-17 04:04:58 +00:00
|
|
|
waitfortcp $server_pid $INITIATOR_IP:$ISCSI_PORT
|
2018-08-10 13:21:42 +00:00
|
|
|
|
|
|
|
# send message using hello_sock client
|
|
|
|
message="**MESSAGE:This is a test message from the client**"
|
2020-08-11 10:36:11 +00:00
|
|
|
response=$(echo $message | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix")
|
2018-08-10 13:21:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
timing_exit sock_client
|
|
|
|
|
|
|
|
# ----------------
|
|
|
|
# Test server path
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
timing_enter sock_server
|
|
|
|
|
|
|
|
# start echo server using hello_sock echo server
|
2020-08-11 10:36:11 +00:00
|
|
|
$HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT -S -N "posix" &
|
2020-05-07 11:27:06 +00:00
|
|
|
server_pid=$!
|
2020-08-11 10:36:11 +00:00
|
|
|
trap 'killprocess $server_pid; iscsitestfini; exit 1' SIGINT SIGTERM EXIT
|
2018-08-10 13:21:42 +00:00
|
|
|
waitforlisten $server_pid
|
|
|
|
|
|
|
|
# send message to server using socat
|
|
|
|
message="**MESSAGE:This is a test message to the server**"
|
2020-05-07 11:27:06 +00:00
|
|
|
response=$(echo $message | $SOCAT_APP - tcp:$TARGET_IP:$ISCSI_PORT 2> /dev/null)
|
2018-08-10 13:21:42 +00:00
|
|
|
|
|
|
|
if [ "$message" != "$response" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
|
|
|
|
killprocess $server_pid
|
|
|
|
|
2020-08-11 10:36:11 +00:00
|
|
|
iscsitestfini
|
2018-08-10 13:21:42 +00:00
|
|
|
timing_exit sock_server
|