]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/iscsi_tgt/sock/sock.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / test / iscsi_tgt / sock / sock.sh
1 #!/usr/bin/env bash
2
3 testdir=$(readlink -f $(dirname $0))
4 rootdir=$(readlink -f $testdir/../../..)
5 source $rootdir/test/common/autotest_common.sh
6 source $rootdir/test/iscsi_tgt/common.sh
7
8 # $1 = "iso" - triggers isolation mode (setting up required environment).
9 # $2 = test type posix or vpp. defaults to posix.
10 iscsitestinit $1 $2
11
12 HELLO_SOCK_APP="$TARGET_NS_CMD $rootdir/examples/sock/hello_world/hello_sock"
13 SOCAT_APP="socat"
14
15 # ----------------
16 # Test client path
17 # ----------------
18 timing_enter sock_client
19 echo "Testing client path"
20
21 # start echo server using socat
22 $SOCAT_APP tcp-l:$ISCSI_PORT,fork,bind=$INITIATOR_IP exec:'/bin/cat' & server_pid=$!
23 trap "killprocess $server_pid;iscsitestfini $1 $2; exit 1" SIGINT SIGTERM EXIT
24
25 waitforlisten $server_pid $INITIATOR_IP:$ISCSI_PORT
26
27 # send message using hello_sock client
28 message="**MESSAGE:This is a test message from the client**"
29 response=$( echo $message | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT )
30
31 if ! echo "$response" | grep -q "$message"; then
32 exit 1
33 fi
34
35 trap '-' SIGINT SIGTERM EXIT
36 # NOTE: socat returns code 143 on SIGINT
37 killprocess $server_pid || true
38
39 report_test_completion "sock_client"
40 timing_exit sock_client
41
42 # ----------------
43 # Test server path
44 # ----------------
45
46 timing_enter sock_server
47
48 # start echo server using hello_sock echo server
49 $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT -S & server_pid=$!
50 trap "killprocess $server_pid; iscsitestfini $1 $2; exit 1" SIGINT SIGTERM EXIT
51 waitforlisten $server_pid
52
53 # send message to server using socat
54 message="**MESSAGE:This is a test message to the server**"
55 response=$( echo $message | $SOCAT_APP - tcp:$TARGET_IP:$ISCSI_PORT 2>/dev/null )
56
57 if [ "$message" != "$response" ]; then
58 exit 1
59 fi
60
61 trap - SIGINT SIGTERM EXIT
62
63 killprocess $server_pid
64
65 iscsitestfini $1 $2
66 report_test_completion "sock_server"
67 timing_exit sock_server