]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/scripts/autotest_common.sh
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / spdk / scripts / autotest_common.sh
1 set -xe
2 ulimit -c unlimited
3
4 export RUN_NIGHTLY=0
5
6 config_params='--enable-debug --enable-werror'
7
8 export UBSAN_OPTIONS='halt_on_error=1:print_stacktrace=1:abort_on_error=1'
9
10 # Override the default NRHUGE in scripts/setup.sh
11 export NRHUGE=4096
12
13 case `uname` in
14 FreeBSD)
15 config_params+=' --with-dpdk=/usr/local/share/dpdk/x86_64-native-bsdapp-clang'
16 MAKE=gmake
17 MAKEFLAGS=${MAKEFLAGS:--j$(sysctl -a | egrep -i 'hw.ncpu' | awk '{print $2}')}
18 ;;
19 Linux)
20 config_params+=' --with-dpdk=/usr/local/share/dpdk/x86_64-native-linuxapp-gcc'
21 MAKE=make
22 MAKEFLAGS=${MAKEFLAGS:--j$(nproc)}
23 config_params+=' --enable-coverage'
24 config_params+=' --enable-ubsan'
25 ;;
26 *)
27 echo "Unknown OS in $0"
28 exit 1
29 ;;
30 esac
31
32 if [ -f /usr/include/infiniband/verbs.h ]; then
33 config_params+=' --with-rdma'
34 fi
35
36 if [ -d /usr/src/fio ]; then
37 config_params+=' --with-fio=/usr/src/fio'
38 fi
39
40 if [ -d /usr/include/rbd ] && [ -d /usr/include/rados ]; then
41 config_params+=' --with-rbd'
42 fi
43
44 export config_params
45
46 if [ -z "$output_dir" ]; then
47 if [ -z "$rootdir" ] || [ ! -d "$rootdir/../output" ]; then
48 output_dir=.
49 else
50 output_dir=$rootdir/../output
51 fi
52 export output_dir
53 fi
54
55 if hash valgrind &> /dev/null; then
56 valgrind='valgrind --leak-check=full --error-exitcode=2'
57 else
58 valgrind=''
59 fi
60
61 function timing() {
62 direction="$1"
63 testname="$2"
64
65 now=$(date +%s)
66
67 if [ "$direction" = "enter" ]; then
68 export timing_stack="${timing_stack};${now}"
69 export test_stack="${test_stack};${testname}"
70 else
71 child_time=$(grep "^${test_stack:1};" $output_dir/timing.txt | awk '{s+=$2} END {print s}')
72
73 start_time=$(echo "$timing_stack" | sed -e 's@^.*;@@')
74 timing_stack=$(echo "$timing_stack" | sed -e 's@;[^;]*$@@')
75
76 elapsed=$((now - start_time - child_time))
77 echo "${test_stack:1} $elapsed" >> $output_dir/timing.txt
78
79 test_stack=$(echo "$test_stack" | sed -e 's@;[^;]*$@@')
80 fi
81 }
82
83 function timing_enter() {
84 set +x
85 timing "enter" "$1"
86 set -x
87 }
88
89 function timing_exit() {
90 set +x
91 timing "exit" "$1"
92 set -x
93 }
94
95 function timing_finish() {
96 flamegraph='/usr/local/FlameGraph/flamegraph.pl'
97 if [ -x "$flamegraph" ]; then
98 "$flamegraph" \
99 --title 'Build Timing' \
100 --nametype 'Step:' \
101 --countname seconds \
102 $output_dir/timing.txt \
103 >$output_dir/timing.svg
104 fi
105 }
106
107 function process_core() {
108 ret=0
109 for core in $(find . -type f \( -name 'core*' -o -name '*.core' \)); do
110 exe=$(eu-readelf -n "$core" | grep psargs | sed "s/.*psargs: \([^ \'\" ]*\).*/\1/")
111 echo "exe for $core is $exe"
112 if [[ ! -z "$exe" ]]; then
113 if hash gdb; then
114 gdb -batch -ex "bt full" $exe $core
115 fi
116 cp $exe $output_dir
117 fi
118 mv $core $output_dir
119 chmod a+r $output_dir/$core
120 ret=1
121 done
122 return $ret
123 }
124
125 function waitforlisten() {
126 # $1 = process pid
127 # $2 = TCP port number
128 if [ -z "$1" ] || [ -z "$2" ]; then
129 exit 1
130 fi
131
132 echo "Waiting for process to start up and listen on TCP port $2..."
133 # turn off trace for this loop
134 set +x
135 ret=1
136 while [ $ret -ne 0 ]; do
137 # if the process is no longer running, then exit the script
138 # since it means the application crashed
139 if ! kill -s 0 $1; then
140 exit
141 fi
142 if netstat -an --tcp | grep -iw listen | grep -q $2; then
143 ret=0
144 fi
145 done
146 set -x
147 }
148
149 function killprocess() {
150 # $1 = process pid
151 if [ -z "$1" ]; then
152 exit 1
153 fi
154
155 echo "killing process with pid $1"
156 kill $1
157 wait $1
158 }
159
160 function iscsicleanup() {
161 echo "Cleaning up iSCSI connection"
162 iscsiadm -m node --logout || true
163 iscsiadm -m node -o delete || true
164 }
165
166 function stop_iscsi_service() {
167 if cat /etc/*-release | grep Ubuntu; then
168 service open-iscsi stop
169 else
170 service iscsid stop
171 fi
172 }
173
174 function start_iscsi_service() {
175 if cat /etc/*-release | grep Ubuntu; then
176 service open-iscsi start
177 else
178 service iscsid start
179 fi
180 }
181
182 function rbd_setup() {
183 export CEPH_DIR=/home/sys_sgsw/ceph/build
184
185 if [ -d $CEPH_DIR ]; then
186 export RBD_POOL=rbd
187 export RBD_NAME=foo
188 (cd $CEPH_DIR && ../src/vstart.sh -d -n -x -l)
189 /usr/local/bin/rbd create $RBD_NAME --size 1000
190 fi
191 }
192
193 function rbd_cleanup() {
194 if [ -d $CEPH_DIR ]; then
195 (cd $CEPH_DIR && ../src/stop.sh || true)
196 fi
197 }
198
199 function run_test() {
200 set +x
201 echo "************************************"
202 echo "START TEST $1"
203 echo "************************************"
204 set -x
205 time "$@"
206 set +x
207 echo "************************************"
208 echo "END TEST $1"
209 echo "************************************"
210 set -x
211 }
212
213 function print_backtrace() {
214 set +x
215 echo "========== Backtrace start: =========="
216 echo ""
217 for i in $(seq 1 $((${#FUNCNAME[@]} - 1))); do
218 local func="${FUNCNAME[$i]}"
219 local line_nr="${BASH_LINENO[$((i - 1))]}"
220 local src="${BASH_SOURCE[$i]/#$rootdir/.}"
221 echo "in $src:$line_nr -> $func()"
222 echo " ..."
223 nl -w 4 -ba -nln $src | grep -B 5 -A 5 "^$line_nr" | \
224 sed "s/^/ /g" | sed "s/^ $line_nr /=> $line_nr /g"
225 echo " ..."
226 done
227 echo ""
228 echo "========== Backtrace end =========="
229 set -x
230 return 0
231 }
232
233 set -o errtrace
234 trap "trap - ERR; print_backtrace >&2" ERR