]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/iscsi_tgt/trace_record/trace_record.sh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / iscsi_tgt / trace_record / trace_record.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 TRACE_TMP_FOLDER=./tmp-trace
13 TRACE_RECORD_OUTPUT=${TRACE_TMP_FOLDER}/record.trace
14 TRACE_RECORD_NOTICE_LOG=${TRACE_TMP_FOLDER}/record.notice
15 TRACE_TOOL_LOG=${TRACE_TMP_FOLDER}/trace.log
16
17 delete_tmp_files() {
18 rm -rf $TRACE_TMP_FOLDER
19 }
20
21 if [ -z "$TARGET_IP" ]; then
22 echo "TARGET_IP not defined in environment"
23 exit 1
24 fi
25
26 if [ -z "$INITIATOR_IP" ]; then
27 echo "INITIATOR_IP not defined in environment"
28 exit 1
29 fi
30
31 NUM_TRACE_ENTRIES=4096
32 MALLOC_BDEV_SIZE=64
33 MALLOC_BLOCK_SIZE=4096
34
35 rpc_py="$rootdir/scripts/rpc.py"
36 fio_py="$rootdir/scripts/fio.py"
37
38 timing_enter start_iscsi_tgt
39
40 echo "start iscsi_tgt with trace enabled"
41 "${ISCSI_APP[@]}" -m 0xf --num-trace-entries $NUM_TRACE_ENTRIES --tpoint-group-mask 0xf &
42 iscsi_pid=$!
43 echo "Process pid: $iscsi_pid"
44
45 trap 'killprocess $iscsi_pid; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT
46
47 waitforlisten $iscsi_pid
48
49 echo "iscsi_tgt is listening. Running tests..."
50
51 timing_exit start_iscsi_tgt
52
53 mkdir -p ${TRACE_TMP_FOLDER}
54 ./build/bin/spdk_trace_record -s iscsi -p ${iscsi_pid} -f ${TRACE_RECORD_OUTPUT} -q 1> ${TRACE_RECORD_NOTICE_LOG} &
55 record_pid=$!
56 echo "Trace record pid: $record_pid"
57
58 RPCS=
59 RPCS+="iscsi_create_portal_group $PORTAL_TAG $TARGET_IP:$ISCSI_PORT\n"
60 RPCS+="iscsi_create_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK\n"
61
62 echo "Create bdevs and target nodes"
63 CONNECTION_NUMBER=15
64 for i in $(seq 0 $CONNECTION_NUMBER); do
65 RPCS+="bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc$i\n"
66 RPCS+="iscsi_create_target_node Target$i Target${i}_alias "Malloc$i:0" $PORTAL_TAG:$INITIATOR_TAG 256 -d\n"
67 done
68 echo -e $RPCS | $rpc_py
69
70 sleep 1
71
72 iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT
73 iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
74 waitforiscsidevices $((CONNECTION_NUMBER + 1))
75
76 trap 'iscsicleanup; killprocess $iscsi_pid; killprocess $record_pid; delete_tmp_files; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT
77
78 echo "Running FIO"
79 $fio_py -p iscsi -i 131072 -d 32 -t randrw -r 1
80
81 iscsicleanup
82
83 RPCS=
84 # Delete Malloc blockdevs and targets
85 for i in $(seq 0 $CONNECTION_NUMBER); do
86 RPCS+="iscsi_delete_target_node iqn.2016-06.io.spdk:Target$i\n"
87 RPCS+="bdev_malloc_delete Malloc$i\n"
88 done
89 echo -e $RPCS | $rpc_py
90
91 trap 'delete_tmp_files; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT
92
93 killprocess $iscsi_pid
94 killprocess $record_pid
95 ./build/bin/spdk_trace -f ${TRACE_RECORD_OUTPUT} > ${TRACE_TOOL_LOG}
96
97 #verify trace record and trace tool
98 #trace entries str in trace-record, like "Trace Size of lcore (0): 4136"
99 record_num="$(grep "trace entries for lcore" ${TRACE_RECORD_NOTICE_LOG} | cut -d ' ' -f 2)"
100
101 #trace entries str in trace-tool, like "Port 4096 trace entries for lcore (0) in 441871 msec"
102 trace_tool_num="$(grep "Trace Size of lcore" ${TRACE_TOOL_LOG} | cut -d ' ' -f 6)"
103
104 delete_tmp_files
105
106 echo "entries numbers from trace record are:" $record_num
107 echo "entries numbers from trace tool are:" $trace_tool_num
108
109 arr_record_num=($record_num)
110 arr_trace_tool_num=($trace_tool_num)
111 len_arr_record_num=${#arr_record_num[@]}
112 len_arr_trace_tool_num=${#arr_trace_tool_num[@]}
113
114 #lcore num check
115 if [ $len_arr_record_num -ne $len_arr_trace_tool_num ]; then
116 echo "trace record test on iscsi: failure on lcore number check"
117 set -e
118 exit 1
119 fi
120 #trace entries num check
121 for i in $(seq 0 $((len_arr_record_num - 1))); do
122 if [ ${arr_record_num[$i]} -le ${NUM_TRACE_ENTRIES} ]; then
123 echo "trace record test on iscsi: failure on inefficient entries number check"
124 set -e
125 exit 1
126 fi
127 if [ ${arr_record_num[$i]} -ne ${arr_trace_tool_num[$i]} ]; then
128 echo "trace record test on iscsi: failure on entries number check"
129 set -e
130 exit 1
131 fi
132 done
133
134 trap - SIGINT SIGTERM EXIT
135 iscsitestfini $1 $2