blob: 1573b48aa7da05e6d912e2008b5f2cc76c7047da [file] [log] [blame]
Dave Wallace543852a2017-08-03 02:11:34 -04001#! /bin/bash
2#
3# socket_test.sh -- script to run socket tests.
4#
5script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6vpp_dir="$WS_ROOT/build-root/install-vpp-native/vpp/bin/"
7vpp_debug_dir="$WS_ROOT/build-root/install-vpp_debug-native/vpp/bin/"
8vpp_shm_dir="/dev/shm/"
Dave Wallace3079a642017-09-06 01:59:43 -04009vpp_run_dir="/run/vpp"
Dave Wallace543852a2017-08-03 02:11:34 -040010lib64_dir="$WS_ROOT/build-root/install-vpp-native/vpp/lib64/"
11lib64_debug_dir="$WS_ROOT/build-root/install-vpp_debug-native/vpp/lib64/"
Dave Wallace19481612017-09-15 18:47:44 -040012dpdk_devbind="/usr/share/dpdk/usertools/dpdk-devbind.py"
Dave Wallace543852a2017-08-03 02:11:34 -040013docker_vpp_dir="/vpp/"
Dave Wallace30fb4a22017-08-17 16:22:04 -040014docker_app_dir="/vpp/"
Dave Wallace543852a2017-08-03 02:11:34 -040015docker_lib64_dir="/vpp-lib64/"
16docker_os="ubuntu"
Dave Wallaced69f4f42017-08-14 18:26:46 -040017vcl_ldpreload_lib="libvcl_ldpreload.so.0.0.0"
Dave Wallace3079a642017-09-06 01:59:43 -040018user_gid="$(id -g)"
Dave Wallace543852a2017-08-03 02:11:34 -040019vpp_app="vpp"
20sock_srvr_app="sock_test_server"
21sock_clnt_app="sock_test_client"
22sock_srvr_addr="127.0.0.1"
23sock_srvr_port="22000"
Dave Wallace30fb4a22017-08-17 16:22:04 -040024iperf_srvr_app="iperf3 -V4d -s"
25iperf_clnt_app="iperf3 -V4d -c \$srvr_addr"
Dave Wallace543852a2017-08-03 02:11:34 -040026gdb_in_emacs="gdb_in_emacs"
27vppcom_conf="vppcom.conf"
28vppcom_conf_dir="$WS_ROOT/src/uri/"
29docker_vppcom_conf_dir="/etc/vpp/"
Keith Burns (alagalah)9e482bb2017-08-30 14:06:52 -070030xterm_geom="100x60"
Dave Wallace543852a2017-08-03 02:11:34 -040031bash_header="#! /bin/bash"
32tmp_cmdfile_prefix="/tmp/socket_test_cmd"
33cmd1_file="${tmp_cmdfile_prefix}1.$$"
34cmd2_file="${tmp_cmdfile_prefix}2.$$"
35cmd3_file="${tmp_cmdfile_prefix}3.$$"
Dave Wallace3079a642017-09-06 01:59:43 -040036tmp_vpp_exec_file="/tmp/vpp_config.$$"
Dave Wallace543852a2017-08-03 02:11:34 -040037tmp_gdb_cmdfile_prefix="/tmp/gdb_cmdfile"
38def_gdb_cmdfile_prefix="$WS_ROOT/extras/gdb/gdb_cmdfile"
39tmp_gdb_cmdfile_vpp="${tmp_gdb_cmdfile_prefix}_vpp.$$"
40tmp_gdb_cmdfile_client="${tmp_gdb_cmdfile_prefix}_vcl_client.$$"
41tmp_gdb_cmdfile_server="${tmp_gdb_cmdfile_prefix}_vcl_server.$$"
42get_docker_server_ip4addr='srvr_addr=$(docker network inspect bridge | grep IPv4Address | awk -e '\''{print $2}'\'' | sed -e '\''s,/16,,'\'' -e '\''s,",,g'\'' -e '\''s/,//'\'')'
43#' single quote to fix the confused emacs colorizer.
44trap_signals="SIGINT SIGTERM EXIT"
45
46# Set default values for imported environment variables if they don't exist.
47#
48VPP_GDB_CMDFILE="${VPP_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vpp}"
49VPPCOM_CLIENT_GDB_CMDFILE="${VPPCOM_CLIENT_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_client}"
50VPPCOM_SERVER_GDB_CMDFILE="${VPPCOM_SERVER_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_server}"
Dave Wallaced69f4f42017-08-14 18:26:46 -040051VCL_LDPRELOAD_LIB_DIR="${VCL_LDPRELOAD_LIB_DIR:-/usr/local/lib}"
Dave Wallace543852a2017-08-03 02:11:34 -040052
53usage() {
54 cat <<EOF
55Usage: socket_test.sh OPTIONS TEST
56TESTS:
57 nk, native-kernel Run server & client on host using kernel.
58 nv, native-vcl Run vpp, server & client on host using VppComLib.
59 np, native-preload Run vpp, server & client on host using LD_PRELOAD.
60 dk, docker-kernel Run server & client in docker using kernel stack.
61 dv, docker-vcl Run vpp on host, server & client in docker using VppComLib.
62 dp, docker-preload Run vpp on host, server & client in docker using LD_PRELOAD.
63
64OPTIONS:
65 -h Print this usage text.
66 -l Leave ${tmp_cmdfile_prefix}* files after test run.
67 -b Run bash after application exit.
68 -d Run the vpp_debug version of all apps.
69 -c Set VPPCOM_CONF to use the vppcom_test.conf file.
70 -i Run iperf3 for client/server app in native tests.
Dave Wallace3079a642017-09-06 01:59:43 -040071 -m c[lient] Run client in multi-host cfg (server on remote host)
72 s[erver] Run server in multi-host cfg (client on remote host)
Dave Wallace543852a2017-08-03 02:11:34 -040073 -e a[ll] Run all in emacs+gdb.
74 c[lient] Run client in emacs+gdb.
75 s[erver] Run server in emacs+gdb.
76 v[pp] Run vpp in emacs+gdb.
77 -g a[ll] Run all in gdb.
78 c[lient] Run client in gdb.
79 s[erver] Run server in gdb.
80 v[pp] Run vpp in gdb.
81 -t Use tabs in one xterm if available (e.g. xfce4-terminal).
82
83OPTIONS passed to client/server:
84 -S <ip address> Server IP address.
85 -P <server port> Server Port number.
86 -E <data> Run Echo test.
87 -N <num-writes> Test Cfg: number of writes.
88 -R <rxbuf-size> Test Cfg: rx buffer size.
89 -T <txbuf-size> Test Cfg: tx buffer size.
90 -U Run Uni-directional test.
91 -B Run Bi-directional test.
92 -I <num-tst-socks> Send data over multiple test sockets in parallel.
93 -V Test Cfg: Verbose mode.
94 -X Exit client/server after running test.
95
96Environment variables:
97 VPPCOM_CONF Pathname of vppcom configuration file.
98 VPP_GDB_CMDFILE Pathname of gdb command file for vpp.
99 VPPCOM_CLIENT_GDB_CMDFILE Pathname of gdb command file for client.
100 VPPCOM_SERVER_GDB_CMDFILE Pathname of gdb command file for server.
101EOF
102 exit 1
103}
104
105declare -i emacs_vpp=0
106declare -i emacs_client=0
107declare -i emacs_server=0
108declare -i gdb_vpp=0
109declare -i gdb_client=0
110declare -i gdb_server=0
111declare -i perf_vpp=0
112declare -i perf_client=0
113declare -i perf_server=0
114declare -i leave_tmp_files=0
115declare -i bash_after_exit=0
116declare -i iperf3=0
117
Dave Wallace3079a642017-09-06 01:59:43 -0400118while getopts ":hitlbcdm:e:g:p:E:I:N:P:R:S:T:UBVX" opt; do
Dave Wallace543852a2017-08-03 02:11:34 -0400119 case $opt in
120 h) usage ;;
121 l) leave_tmp_files=1
122 ;;
123 b) bash_after_exit=1
124 ;;
125 i) iperf3=1
126 ;;
127 t) xterm_geom="180x40"
128 use_tabs="true"
129 ;;
130 c) VPPCOM_CONF="${vppcom_conf_dir}vppcom_test.conf"
131 ;;
132 d) title_dbg="-DEBUG"
133 vpp_dir=$vpp_debug_dir
134 lib64_dir=$lib64_debug_dir
135 ;;
136 e) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then
137 emacs_client=1
138 emacs_server=1
139 emacs_vpp=1
140 elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
141 emacs_client=1
142 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
143 emacs_server=1
144 elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then
145 emacs_vpp=1
146 else
147 echo "ERROR: Option -e unknown argument \'$OPTARG\'" >&2
148 usage
149 fi
150 title_dbg="-DEBUG"
151 vpp_dir=$vpp_debug_dir
152 lib64_dir=$lib64_debug_dir
153 ;;
Dave Wallace3079a642017-09-06 01:59:43 -0400154 m) if [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
155 multi_host="client"
156 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
157 multi_host="server"
158 else
159 echo "ERROR: Option -e unknown argument \'$OPTARG\'" >&2
160 usage
161 fi
162 ;;
Dave Wallace543852a2017-08-03 02:11:34 -0400163 g) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then
164 gdb_client=1
165 gdb_server=1
166 gdb_vpp=1
167 elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
168 gdb_client=1
169 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
170 gdb_server=1
171 elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then
172 gdb_vpp=1
173 else
174 echo "ERROR: Option -g unknown argument \'$OPTARG\'" >&2
175 usage
176 fi
177 title_dbg="-DEBUG"
178 vpp_dir=$vpp_debug_dir
179 lib64_dir=$lib64_debug_dir
180 ;;
181 p) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then
182 perf_client=1
183 perf_server=1
184 perf_vpp=1
185 elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
186 perf_client=1
187 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
188 perf_server=1
189 elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then
190 perf_vpp=1
191 else
192 echo "ERROR: Option -p unknown argument \'$OPTARG\'" >&2
193 usage
194 fi
195 echo "WARNING: -p options TBD"
196 ;;
197 S) sock_srvr_addr="$OPTARG"
198 ;;
199 P) sock_srvr_port="$OPTARG"
200 ;;
201E|I|N|R|T) sock_clnt_options="$sock_clnt_options -$opt \"$OPTARG\""
202 ;;
203 U|B|V|X) sock_clnt_options="$sock_clnt_options -$opt"
204 ;;
205 \?)
206 echo "ERROR: Invalid option: -$OPTARG" >&2
207 usage
208 ;;
209 :)
210 echo "ERROR: Option -$OPTARG requires an argument." >&2
211 usage
212 ;;
213 esac
214done
215
216shift $(( $OPTIND-1 ))
217while ! [[ $run_test ]] && (( $# > 0 )) ; do
218 case $1 in
219 "nk" | "native-kernel")
220 run_test="native_kernel" ;;
221 "np" | "native-preload")
222 run_test="native_preload" ;;
223 "nv" | "native-vcl")
224 sock_srvr_app="vcl_test_server"
225 sock_clnt_app="vcl_test_client"
226 run_test="native_vcl" ;;
227 "dk" | "docker-kernel")
228 run_test="docker_kernel" ;;
229 "dp" | "docker-preload")
230 run_test="docker_preload" ;;
231 "dv" | "docker-vcl")
232 sock_srvr_app="vcl_test_server"
233 sock_clnt_app="vcl_test_client"
234 run_test="docker_vcl" ;;
235 *)
236 echo "ERROR: Unknown option '$1'!" >&2
237 usage ;;
238 esac
239 shift
240done
241
242if [ -z "$WS_ROOT" ] ; then
243 echo "ERROR: WS_ROOT environment variable not set!" >&2
244 echo " Please set WS_ROOT to VPP workspace root directory." >&2
Dave Wallace3079a642017-09-06 01:59:43 -0400245 exit 1
Dave Wallace543852a2017-08-03 02:11:34 -0400246fi
247
248if [ ! -d $vpp_dir ] ; then
249 echo "ERROR: Missing VPP$DEBUG bin directory!" >&2
250 echo " $vpp_dir" >&2
251 env_test_failed="true"
252fi
253
254if [[ $run_test =~ .*"_preload" ]] ; then
255 if [ ! -d $lib64_dir ] ; then
256 echo "ERROR: Missing VPP$DEBUG lib64 directory!" >&2
257 echo " $lib64_dir" >&2
Dave Wallaced69f4f42017-08-14 18:26:46 -0400258 elif [ ! -d $VCL_LDPRELOAD_LIB_DIR ] ; then
259 echo "ERROR: Missing VCL LD_PRELOAD Library directory!" >&2
260 echo " $VCL_LDPRELOAD_LIB_DIR" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400261 env_test_failed="true"
Dave Wallaced69f4f42017-08-14 18:26:46 -0400262 elif [ ! -f $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib ] ; then
263 echo "ERROR: Missing VCL LD_PRELOAD library!" >&2
264 echo " $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400265 env_test_failed="true"
266 fi
267fi
268
269if [ ! -f $vpp_dir$vpp_app ] ; then
270 echo "ERROR: Missing VPP$DEBUG Application!" >&2
271 echo " $vpp_dir$vpp_app" >&2
272 env_test_failed="true"
273fi
274
Dave Wallace30fb4a22017-08-17 16:22:04 -0400275if [ ! -f $vpp_dir$sock_srvr_app ] && [ ! $iperf3 -eq 1 ] ; then
Dave Wallace543852a2017-08-03 02:11:34 -0400276 echo "ERROR: Missing$DEBUG Socket Server Application!" >&2
277 echo " $vpp_dir$sock_srvr_app" >&2
278 env_test_failed="true"
279fi
280
Dave Wallace30fb4a22017-08-17 16:22:04 -0400281if [ ! -f $vpp_dir$sock_clnt_app ] && [ ! $iperf3 -eq 1 ] ; then
Dave Wallace543852a2017-08-03 02:11:34 -0400282 echo "ERROR: Missing$DEBUG Socket Client Application!" >&2
283 echo " $vpp_dir$sock_clnt_app" >&2
284 env_test_failed="true"
285fi
286
287if [[ $run_test =~ "docker_".* ]] ; then
288 if [ $emacs_client -eq 1 ] || [ $emacs_server -eq 1 ] || [ $gdb_client -eq 1 ] || [ $gdb_server -eq 1 ] ; then
289
290 echo "WARNING: gdb is not currently supported in docker."
291 echo " Ignoring client/server gdb options."
292 emacs_client=0
293 emacs_server=0
294 gdb_client=0
295 gdb_server=0
296 fi
297fi
298
Dave Wallace30fb4a22017-08-17 16:22:04 -0400299if [[ $run_test =~ .*"_vcl" ]] && [ $iperf3 -eq 1 ] ; then
300 echo "ERROR: Invalid option 'i' for test $run_test!"
301 echo " iperf3 is not compiled with the VCL library."
302 env_test_failed="true"
303fi
304
Dave Wallace19481612017-09-15 18:47:44 -0400305if [ -n "$mult_host"] && [ ! -f "$dpdk_devbind" ] ; then
306 echo "ERROR: Can't find dpdk-devbind.py!"
307 echo " Run \"cd \$WS_ROOT; make dpdk-install-dev\" to install it."
308 echo
309 env_test_failed="true"
310fi
311
Dave Wallace543852a2017-08-03 02:11:34 -0400312if [ -n "$env_test_failed" ] ; then
313 exit 1
314fi
315
316if [ -f "$VPPCOM_CONF" ] ; then
317 vppcom_conf="$(basename $VPPCOM_CONF)"
318 vppcom_conf_dir="$(dirname $VPPCOM_CONF)/"
319 api_prefix="$(egrep -s '^\s*api-prefix \w+' $VPPCOM_CONF | awk -e '{print $2}')"
320 if [ -n "$api_prefix" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400321 api_segment=" api-segment { gid $user_gid prefix $api_prefix }"
Dave Wallace543852a2017-08-03 02:11:34 -0400322 fi
323fi
Dave Wallace3079a642017-09-06 01:59:43 -0400324if [ -z "$api_segment" ] ; then
325 api_segment=" api-segment { gid $user_gid }"
326fi
327if [ -n "$multi_host" ] ; then
328 vpp_args="unix { interactive exec $tmp_vpp_exec_file}${api_segment}"
329else
330 vpp_args="unix { interactive }${api_segment}"
331fi
Dave Wallace543852a2017-08-03 02:11:34 -0400332
Dave Wallace30fb4a22017-08-17 16:22:04 -0400333if [ $iperf3 -eq 1 ] ; then
Dave Wallace543852a2017-08-03 02:11:34 -0400334 app_dir="$(dirname $(which iperf3))/"
335 srvr_app=$iperf_srvr_app
336 clnt_app=$iperf_clnt_app
Dave Wallace30fb4a22017-08-17 16:22:04 -0400337 if [[ $run_test =~ "docker_".* ]] ; then
338 unset -v app_dir
339 sock_srvr_port=5201
340 docker_app_dir="networkstatic/"
341 unset -v docker_os
342 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400343else
344 app_dir="$vpp_dir"
345 srvr_app="$sock_srvr_app $sock_srvr_port"
346 clnt_app="$sock_clnt_app${sock_clnt_options} \$srvr_addr $sock_srvr_port"
347fi
348
349verify_no_vpp() {
350 local running_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
351 if [ "$(eval $running_vpp)" != "" ] ; then
352 echo "ERROR: Please kill all running vpp instances:"
353 echo
354 eval $running_vpp
355 echo
356 exit 1
357 fi
358 clean_devshm="$vpp_shm_dir*db $vpp_shm_dir*global_vm $vpp_shm_dir*vpe-api $vpp_shm_dir[0-9]*-[0-9]* $vpp_shm_dir*:segment[0-9]*"
359 rm -f $clean_devshm
360 devshm_files="$(ls -l $clean_devshm 2>/dev/null | grep $(whoami))"
361 if [ "$devshm_files" != "" ] ; then
362 echo "ERROR: Please remove the following $vpp_shm_dir files:"
363 for file in "$devshm_files" ; do
364 echo " $file"
365 done
366 exit 1
367 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400368 if [ ! -d "$vpp_run_dir" ] ; then
369 sudo mkdir $vpp_run_dir
370 sudo chown root:$USER $vpp_run_dir
371 fi
372 if [ -n "$multi_host" ] ; then
373 vpp_eth_name="enp0s8"
374 vpp_eth_pci_id="$(ls -ld /sys/class/net/$vpp_eth_name/device | awk '{print $11}' | cut -d/ -f4)"
375 if [ -z "$vpp_eth_pci_id" ] ; then
376 echo "ERROR: Missing ethernet interface $vpp_eth_name!"
377 usage
378 fi
379 printf -v bus "%x" "0x$(echo $vpp_eth_pci_id | cut -d: -f2)"
380 printf -v slot "%x" "0x$(echo $vpp_eth_pci_id | cut -d: -f3 | cut -d. -f1)"
381 printf -v func "%x" "0x$(echo $vpp_eth_pci_id | cut -d. -f2)"
382
383 vpp_eth_kernel_driver="$(basename $(ls -l /sys/bus/pci/devices/$vpp_eth_pci_id/driver | awk '{print $11}'))"
384 if [ -z "$vpp_eth_kernel_driver" ] ; then
385 echo "ERROR: Missing kernel driver for $vpp_eth_name!"
386 usage
387 fi
388 case $vpp_eth_kernel_driver in
389 e1000)
390 vpp_eth_ifname="GigabitEthernet$bus/$slot/$func" ;;
391 ixgbe)
392 vpp_eth_ifname="TenGigabitEthernet$bus/$slot/$func" ;;
393 *)
394 echo "ERROR: Unknown ethernet kernel driver $vpp_eth_kernel_driver!"
395 usage ;;
396 esac
397
398 vpp_eth_ip4_addr="$(ip -4 -br addr show $vpp_eth_name | awk '{print $3}')"
399 if [ -z "$vpp_eth_ip4_addr" ] ; then
400 echo "ERROR: No inet address configured for $vpp_eth_name!"
401 usage
402 fi
403 vpp_eth_ip6_addr="$(ip -6 -br addr show $vpp_eth_name | awk '{print $3}')"
404 if [ -z "$vpp_eth_ip6_addr" ] ; then
405 echo "ERROR: No inet6 address configured for $vpp_eth_name!"
406 usage
407 fi
408 vpp_args="$vpp_args plugins { path $lib64_dir/vpp_plugins } dpdk { dev $vpp_eth_pci_id }"
409
410 sudo ifdown $vpp_eth_name 2> /dev/null
411 echo "Configuring VPP to use $vpp_eth_name ($vpp_eth_pci_id), inet addr $vpp_eth_ip4_addr"
412
413 cat <<EOF >> $tmp_vpp_exec_file
414set int state $vpp_eth_ifname up
415set int ip addr $vpp_eth_ifname $vpp_eth_ip4_addr
416EOF
417
418 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400419}
420
421verify_no_docker_containers() {
422 if (( $(which docker | wc -l) < 1 )) ; then
423 echo "ERROR: docker is not installed!"
424 echo "See https://docs.docker.com/engine/installation/linux/ubuntu/"
425 echo " or https://docs.docker.com/engine/installation/linux/centos/"
426 exit 1
427 fi
428 if (( $(docker ps | wc -l) > 1 )) ; then
429 echo "ERROR: Run the following to kill all docker containers:"
430 echo "docker kill \$(docker ps -q)"
431 echo
432 docker ps
433 exit 1
434 fi
435}
436
437set_pre_cmd() {
438 # arguments
439 # $1 : emacs flag
440 # $2 : gdb flag
441 # $3 : optional LD_PRELOAD library pathname
442 local -i emacs=$1
443 local -i gdb=$2
444
445 if [ $emacs -eq 1 ] ; then
446 write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3
447 pre_cmd="$gdb_in_emacs "
448 elif [ $gdb -eq 1 ] ; then
449 write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3
450 pre_cmd="gdb -x $tmp_gdb_cmdfile -i=mi --args "
451 elif [ -z $3 ] ; then
452 unset -v pre_cmd
453 else
454 docker_ld_preload="-e LD_PRELOAD=$3 "
455 pre_cmd="LD_PRELOAD=$3 "
456 fi
457}
458
459write_script_header() {
460 # arguments
461 # $1 : command script file
462 # $2 : gdb command file
463 # $3 : title
464 # $4 : optional command string (typically "sleep 2")
465 echo "$bash_header" > $1
466 echo -e "#\n# $1 generated on $(date)\n#" >> $1
467 if [ $leave_tmp_files -eq 0 ] ; then
Dave Wallace19481612017-09-15 18:47:44 -0400468 if [ -n "$multi_host" ] && [[ "$3" == VPP* ]] ; then
469 echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file; sudo $dpdk_devbind -b $vpp_eth_kernel_driver $vpp_eth_pci_id; sudo ifup $vpp_eth_name\" $trap_signals" >> $1
Dave Wallace3079a642017-09-06 01:59:43 -0400470 else
471 echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file\" $trap_signals" >> $1
472 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400473 fi
474 echo "export VPPCOM_CONF=${vppcom_conf_dir}${vppcom_conf}" >> $1
475 if [ "$pre_cmd" = "$gdb_in_emacs " ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400476 if [ -n "$multi_host" ] ; then
477 cat <<EOF >> $1
478$gdb_in_emacs() {
479 sudo emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
480}
481EOF
482 else
483 cat <<EOF >> $1
Dave Wallace543852a2017-08-03 02:11:34 -0400484$gdb_in_emacs() {
485 emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
486}
487EOF
Dave Wallace3079a642017-09-06 01:59:43 -0400488 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400489 fi
490 if [ -n "$4" ] ; then
491 echo "$4" >> $1
492 fi
493}
494
495write_script_footer() {
496 # arguments
497 # $1 : command script file
498 # $2 : perf flag indicating to run bash before exit
499 local -i perf=$2
500 if [ $bash_after_exit -eq 1 ] || [ $perf -eq 1 ] ; then
501 echo "bash" >> $1
502 fi
503}
504
505write_gdb_cmdfile() {
506 # arguments
507 # $1 : gdb command file
508 # $2 : User specified gdb cmdfile
509 # $3 : emacs flag
510 # $4 : optional LD_PRELOAD library pathname.
511 local -i emacs=$3
512
513 echo "# $1 generated on $(date)" > $1
514 echo "#" >> $1
515 echo "set confirm off" >> $1
516 if [ -n "$4" ] ; then
517 echo "set exec-wrapper env LD_PRELOAD=$4" >> $1
518 echo "start" >> $1
519 fi
520
521 if [ ! -f $2 ] ; then
522 echo -n "# " >> $1
523 fi
524 echo "source $2" >> $1
525 if [ $emacs -eq 0 ] ; then
526 echo "run" >> $1
527 fi
528}
529
530native_kernel() {
531 banner="Running NATIVE-KERNEL socket test"
Dave Wallace3079a642017-09-06 01:59:43 -0400532 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
533 title1="SERVER$title_dbg (Native-Kernel Socket Test)"
534 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
535 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
536 set_pre_cmd $emacs_server $gdb_server
537 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
538 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd1_file
539 write_script_footer $cmd1_file $perf_server
540 chmod +x $cmd1_file
541 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400542
Dave Wallace3079a642017-09-06 01:59:43 -0400543 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
544 title2="CLIENT$title_dbg (Native-Kernel Socket Test)"
545 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
546 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
547 set_pre_cmd $emacs_client $gdb_client
548 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
549 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd2_file
550 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd2_file
551 write_script_footer $cmd2_file $perf_client
552 chmod +x $cmd2_file
Dave Wallace543852a2017-08-03 02:11:34 -0400553
Dave Wallace3079a642017-09-06 01:59:43 -0400554 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400555}
556
557native_preload() {
558 verify_no_vpp
559 banner="Running NATIVE-PRELOAD socket test"
Dave Wallaced69f4f42017-08-14 18:26:46 -0400560 ld_preload="$VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib "
Dave Wallace543852a2017-08-03 02:11:34 -0400561
562 title1="VPP$title_dbg (Native-Preload Socket Test)"
563 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
564 gdb_cmdfile=$VPP_GDB_CMDFILE
565 set_pre_cmd $emacs_vpp $gdb_vpp
566 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400567 if [ -n "$multi_host" ] && [ $emacs_vpp -eq 0 ] ; then
568 echo -n "sudo " >> $cmd1_file
569 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400570 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file
571 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400572 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400573
Dave Wallace3079a642017-09-06 01:59:43 -0400574 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
575 title2="SERVER$title_dbg (Native-Preload Socket Test)"
576 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
577 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
578 set_pre_cmd $emacs_server $gdb_server $ld_preload
579 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
580 echo "export LD_LIBRARY_PATH=\"$lib64_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd2_file
581 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
582 write_script_footer $cmd2_file $perf_server
583 chmod +x $cmd2_file
584 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400585
Dave Wallace3079a642017-09-06 01:59:43 -0400586 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
587 title3="CLIENT$title_dbg (Native-Preload Socket Test)"
588 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
589 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
590 set_pre_cmd $emacs_client $gdb_client $ld_preload
591 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
592 echo "export LD_LIBRARY_PATH=\"$lib64_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd3_file
593 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
594 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file
595 write_script_footer $cmd3_file $perf_client
596 chmod +x $cmd3_file
597 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400598}
599
600native_vcl() {
601 verify_no_vpp
602 banner="Running NATIVE-VCL socket test"
603
604 title1="VPP$title_dbg (Native-VCL Socket Test)"
605 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
606 gdb_cmdfile=$VPP_GDB_CMDFILE
607 set_pre_cmd $emacs_vpp $gdb_vpp
608 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400609 if [ -n "$multi_host" ] && [ $emacs_vpp -eq 0 ] ; then
610 echo -n "sudo " >> $cmd1_file
611 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400612 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file
613 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400614 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400615
Dave Wallace3079a642017-09-06 01:59:43 -0400616 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
617 title2="SERVER$title_dbg (Native-VCL Socket Test)"
618 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
619 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
620 set_pre_cmd $emacs_server $gdb_server
621 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
622 echo "export LD_LIBRARY_PATH=\"$lib64_dir:$LD_LIBRARY_PATH\"" >> $cmd2_file
623 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
624 write_script_footer $cmd2_file $perf_server
625 chmod +x $cmd2_file
626 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400627
Dave Wallace3079a642017-09-06 01:59:43 -0400628 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
629 title3="CLIENT$title_dbg (Native-VCL Socket Test)"
630 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
631 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
632 set_pre_cmd $emacs_client $gdb_client
633 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
634 echo "export LD_LIBRARY_PATH=\"$lib64_dir:$LD_LIBRARY_PATH\"" >> $cmd3_file
635 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
636 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file
637 write_script_footer $cmd3_file $perf_client
638 chmod +x $cmd3_file
639 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400640}
641
642docker_kernel() {
643 verify_no_docker_containers
644 banner="Running DOCKER-KERNEL socket test"
645
Dave Wallace3079a642017-09-06 01:59:43 -0400646 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
647 title1="SERVER$title_dbg (Docker-Native Socket Test)"
648 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
649 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
650 set_pre_cmd $emacs_server $gdb_server
651 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
652 echo "docker run -it --cpuset-cpus='4-7' --cpuset-cpus='4-7' -v $vpp_dir:$docker_vpp_dir -p $sock_srvr_port:$sock_srvr_port $docker_os ${docker_app_dir}${srvr_app}" >> $cmd1_file
653 write_script_footer $cmd1_file $perf_server
654 chmod +x $cmd1_file
655 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400656
Dave Wallace3079a642017-09-06 01:59:43 -0400657 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
658 title2="CLIENT$title_dbg (Docker-Native Socket Test)"
659 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
660 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
661 set_pre_cmd $emacs_client $gdb_client
662 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
663 echo "$get_docker_server_ip4addr" >> $cmd2_file
664 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_dir:$docker_vpp_dir $docker_os ${docker_app_dir}${clnt_app}" >> $cmd2_file
665 write_script_footer $cmd2_file $perf_client
666 chmod +x $cmd2_file
667 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400668}
669
670docker_preload() {
671 verify_no_vpp
672 verify_no_docker_containers
673 banner="Running DOCKER-PRELOAD socket test"
Dave Wallace30fb4a22017-08-17 16:22:04 -0400674 docker_ld_preload_dir="/vcl-ldpreload/"
675 ld_preload_dir="$VCL_LDPRELOAD_LIB_DIR"
676 ld_preload="$docker_ld_preload_dir$vcl_ldpreload_lib "
677 docker_ld_preload_lib="$docker_ld_preload_dir$vcl_ldpreload_lib "
Dave Wallace543852a2017-08-03 02:11:34 -0400678
679 title1="VPP$title_dbg (Docker-Preload Socket Test)"
680 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
681 gdb_cmdfile=$VPP_GDB_CMDFILE
682 set_pre_cmd $emacs_vpp $gdb_vpp
683 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400684 if [ -n "$multi_host" ] ; then
685 echo -n "sudo " >> $cmd1_file
686 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400687 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file
688 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400689 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400690
Dave Wallace3079a642017-09-06 01:59:43 -0400691 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
692 title2="SERVER$title_dbg (Docker-Preload Socket Test)"
693 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
694 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
695 set_pre_cmd $emacs_server $gdb_server $docker_ld_preload_lib
696 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
697 echo "docker run -it -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib64_dir:$docker_lib64_dir -v $ld_preload_dir:$docker_ld_preload_dir -v $vppcom_conf_dir:$docker_vppcom_conf_dir -p $sock_srvr_port:$sock_srvr_port -e VPPCOM_CONF=${docker_vppcom_conf_dir}$vppcom_conf -e LD_LIBRARY_PATH=$docker_lib64_dir:$docker_ld_preload_dir ${docker_ld_preload}$docker_os ${docker_app_dir}${srvr_app}" >> $cmd2_file
698 write_script_footer $cmd2_file $perf_server
699 chmod +x $cmd2_file
700 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400701
Dave Wallace3079a642017-09-06 01:59:43 -0400702 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
703 title3="CLIENT$title_dbg (Docker-Preload Socket Test)"
704 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
705 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
706 set_pre_cmd $emacs_client $gdb_client $docker_ld_preload_lib
707 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
708 echo "$get_docker_server_ip4addr" >> $cmd3_file
709 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib64_dir:$docker_lib64_dir -v $ld_preload_dir:$docker_ld_preload_dir -v $vppcom_conf_dir:$docker_vppcom_conf_dir -e VPPCOM_CONF=${docker_vppcom_conf_dir}$vppcom_conf -e LD_LIBRARY_PATH=$docker_lib64_dir ${docker_ld_preload}$docker_os ${docker_app_dir}${clnt_app}" >> $cmd3_file
710 write_script_footer $cmd3_file $perf_client
711 chmod +x $cmd3_file
712 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400713}
714
715docker_vcl() {
716 verify_no_vpp
717 verify_no_docker_containers
718 banner="Running DOCKER-VCL socket test"
719
720 title1="VPP$title_dbg (Docker-VCL Socket Test)"
721 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
722 gdb_cmdfile=$VPP_GDB_CMDFILE
723 set_pre_cmd $emacs_vpp $gdb_vpp
724 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400725 if [ -n "$multi_host" ] ; then
726 echo -n "sudo " >> $cmd1_file
727 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400728 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file
729 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400730 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400731
Dave Wallace3079a642017-09-06 01:59:43 -0400732 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
733 title2="SERVER$title_dbg (Docker-VCL Socket Test)"
734 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
735 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
736 set_pre_cmd $emacs_server $gdb_server
737 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
738 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib64_dir:$docker_lib64_dir -v $vppcom_conf_dir:$docker_vppcom_conf_dir -p $sock_srvr_port:$sock_srvr_port -e VPPCOM_CONF=${docker_vppcom_conf_dir}/$vppcom_conf -e LD_LIBRARY_PATH=$docker_lib64_dir $docker_os ${docker_app_dir}${srvr_app}" >> $cmd2_file
739 write_script_footer $cmd2_file $perf_server
740 chmod +x $cmd2_file
741 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400742
Dave Wallace3079a642017-09-06 01:59:43 -0400743 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
744 title3="CLIENT$title_dbg (Docker-VCL Socket Test)"
745 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
746 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
747 set_pre_cmd $emacs_client $gdb_client
748 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
749 echo "$get_docker_server_ip4addr" >> $cmd3_file
750 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib64_dir:$docker_lib64_dir -v $vppcom_conf_dir:$docker_vppcom_conf_dir -e VPPCOM_CONF=${docker_vppcom_conf_dir}/$vppcom_conf -e LD_LIBRARY_PATH=$docker_lib64_dir $docker_os ${docker_app_dir}${clnt_app}" >> $cmd3_file
751 write_script_footer $cmd3_file $perf_client
752 chmod +x $cmd3_file
753 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400754}
755
756if [[ $run_test ]] ; then
757 eval $run_test
758else
759 echo "ERROR: Please specify a test to run!" >&2
760 usage;
761fi
762
763if (( $(which xfce4-terminal | wc -l) > 0 )) ; then
764 xterm_cmd="xfce4-terminal --geometry $xterm_geom"
765 if [[ $use_tabs ]] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400766 declare -a tab_cmd_files
767 declare -a tab_titles
768 declare -i i=0
769
770 if [ -x "$cmd1_file" ] ; then
771 tab_cmd_files[$i]="$cmd1_file"
772 tab_titles[$i]="$title1"
773 (( i++ ))
Dave Wallace543852a2017-08-03 02:11:34 -0400774 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400775 if [ -x "$cmd2_file" ] ; then
776 tab_cmd_files[$i]="$cmd2_file"
777 tab_titles[$i]="$title2"
778 (( i++ ))
779 fi
780 if [ -x "$cmd3_file" ] ; then
781 tab_cmd_files[$i]="$cmd3_file"
782 tab_titles[$i]="$title3"
783 fi
784
785 if [ -n "${tab_cmd_files[2]}" ] ; then
786 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}" --tab --title "${tab_titles[1]}" --command "${tab_cmd_files[1]}" --tab --title "${tab_titles[2]}" --command "${tab_cmd_files[2]}"
787 elif [ -n "${tab_cmd_files[1]}" ] ; then
788 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}" --tab --title "${tab_titles[1]}" --command "${tab_cmd_files[1]}"
789
790 else
791 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}"
792 fi
793
Dave Wallace543852a2017-08-03 02:11:34 -0400794 else
Dave Wallace3079a642017-09-06 01:59:43 -0400795 if [ -x "$cmd1_file" ] ; then
796 ($xterm_cmd --title "$title1" --command "$cmd1_file" &)
797 fi
798 if [ -x "$cmd2_file" ] ; then
799 ($xterm_cmd --title "$title2" --command "$cmd2_file" &)
800 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400801 if [ -x "$cmd3_file" ] ; then
802 ($xterm_cmd --title "$title3" --command "$cmd3_file" &)
803 fi
804 fi
805
806else
807 if [[ $use_tabs ]] ; then
808 echo "Sorry, plain ol' xterm doesn't support tabs."
809 fi
810 xterm_cmd="xterm -fs 10 -geometry $xterm_geom"
Dave Wallace3079a642017-09-06 01:59:43 -0400811 if [ -x "$cmd1_file" ] ; then
812 ($xterm_cmd -title "$title1" -e "$cmd1_file" &)
813 fi
814 if [ -x "$cmd2_file" ] ; then
815 ($xterm_cmd -title "$title2" -e "$cmd2_file" &)
816 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400817 if [ -x "$cmd3_file" ] ; then
818 ($xterm_cmd -title "$title3" -e "$cmd3_file" &)
819 fi
820fi
821
822sleep 1