Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # socket_test.sh -- script to run socket tests. |
| 4 | # |
| 5 | script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 | vpp_dir="$WS_ROOT/build-root/install-vpp-native/vpp/bin/" |
| 7 | vpp_debug_dir="$WS_ROOT/build-root/install-vpp_debug-native/vpp/bin/" |
| 8 | vpp_shm_dir="/dev/shm/" |
| 9 | lib64_dir="$WS_ROOT/build-root/install-vpp-native/vpp/lib64/" |
| 10 | lib64_debug_dir="$WS_ROOT/build-root/install-vpp_debug-native/vpp/lib64/" |
| 11 | docker_vpp_dir="/vpp/" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 12 | docker_app_dir="/vpp/" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 13 | docker_lib64_dir="/vpp-lib64/" |
| 14 | docker_os="ubuntu" |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 15 | vcl_ldpreload_lib="libvcl_ldpreload.so.0.0.0" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 16 | vpp_app="vpp" |
| 17 | sock_srvr_app="sock_test_server" |
| 18 | sock_clnt_app="sock_test_client" |
| 19 | sock_srvr_addr="127.0.0.1" |
| 20 | sock_srvr_port="22000" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 21 | iperf_srvr_app="iperf3 -V4d -s" |
| 22 | iperf_clnt_app="iperf3 -V4d -c \$srvr_addr" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 23 | gdb_in_emacs="gdb_in_emacs" |
| 24 | vppcom_conf="vppcom.conf" |
| 25 | vppcom_conf_dir="$WS_ROOT/src/uri/" |
| 26 | docker_vppcom_conf_dir="/etc/vpp/" |
| 27 | xterm_geom="60x40" |
| 28 | bash_header="#! /bin/bash" |
| 29 | tmp_cmdfile_prefix="/tmp/socket_test_cmd" |
| 30 | cmd1_file="${tmp_cmdfile_prefix}1.$$" |
| 31 | cmd2_file="${tmp_cmdfile_prefix}2.$$" |
| 32 | cmd3_file="${tmp_cmdfile_prefix}3.$$" |
| 33 | tmp_gdb_cmdfile_prefix="/tmp/gdb_cmdfile" |
| 34 | def_gdb_cmdfile_prefix="$WS_ROOT/extras/gdb/gdb_cmdfile" |
| 35 | tmp_gdb_cmdfile_vpp="${tmp_gdb_cmdfile_prefix}_vpp.$$" |
| 36 | tmp_gdb_cmdfile_client="${tmp_gdb_cmdfile_prefix}_vcl_client.$$" |
| 37 | tmp_gdb_cmdfile_server="${tmp_gdb_cmdfile_prefix}_vcl_server.$$" |
| 38 | get_docker_server_ip4addr='srvr_addr=$(docker network inspect bridge | grep IPv4Address | awk -e '\''{print $2}'\'' | sed -e '\''s,/16,,'\'' -e '\''s,",,g'\'' -e '\''s/,//'\'')' |
| 39 | #' single quote to fix the confused emacs colorizer. |
| 40 | trap_signals="SIGINT SIGTERM EXIT" |
| 41 | |
| 42 | # Set default values for imported environment variables if they don't exist. |
| 43 | # |
| 44 | VPP_GDB_CMDFILE="${VPP_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vpp}" |
| 45 | VPPCOM_CLIENT_GDB_CMDFILE="${VPPCOM_CLIENT_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_client}" |
| 46 | VPPCOM_SERVER_GDB_CMDFILE="${VPPCOM_SERVER_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_server}" |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 47 | VCL_LDPRELOAD_LIB_DIR="${VCL_LDPRELOAD_LIB_DIR:-/usr/local/lib}" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 48 | |
| 49 | usage() { |
| 50 | cat <<EOF |
| 51 | Usage: socket_test.sh OPTIONS TEST |
| 52 | TESTS: |
| 53 | nk, native-kernel Run server & client on host using kernel. |
| 54 | nv, native-vcl Run vpp, server & client on host using VppComLib. |
| 55 | np, native-preload Run vpp, server & client on host using LD_PRELOAD. |
| 56 | dk, docker-kernel Run server & client in docker using kernel stack. |
| 57 | dv, docker-vcl Run vpp on host, server & client in docker using VppComLib. |
| 58 | dp, docker-preload Run vpp on host, server & client in docker using LD_PRELOAD. |
| 59 | |
| 60 | OPTIONS: |
| 61 | -h Print this usage text. |
| 62 | -l Leave ${tmp_cmdfile_prefix}* files after test run. |
| 63 | -b Run bash after application exit. |
| 64 | -d Run the vpp_debug version of all apps. |
| 65 | -c Set VPPCOM_CONF to use the vppcom_test.conf file. |
| 66 | -i Run iperf3 for client/server app in native tests. |
| 67 | -e a[ll] Run all in emacs+gdb. |
| 68 | c[lient] Run client in emacs+gdb. |
| 69 | s[erver] Run server in emacs+gdb. |
| 70 | v[pp] Run vpp in emacs+gdb. |
| 71 | -g a[ll] Run all in gdb. |
| 72 | c[lient] Run client in gdb. |
| 73 | s[erver] Run server in gdb. |
| 74 | v[pp] Run vpp in gdb. |
| 75 | -t Use tabs in one xterm if available (e.g. xfce4-terminal). |
| 76 | |
| 77 | OPTIONS passed to client/server: |
| 78 | -S <ip address> Server IP address. |
| 79 | -P <server port> Server Port number. |
| 80 | -E <data> Run Echo test. |
| 81 | -N <num-writes> Test Cfg: number of writes. |
| 82 | -R <rxbuf-size> Test Cfg: rx buffer size. |
| 83 | -T <txbuf-size> Test Cfg: tx buffer size. |
| 84 | -U Run Uni-directional test. |
| 85 | -B Run Bi-directional test. |
| 86 | -I <num-tst-socks> Send data over multiple test sockets in parallel. |
| 87 | -V Test Cfg: Verbose mode. |
| 88 | -X Exit client/server after running test. |
| 89 | |
| 90 | Environment variables: |
| 91 | VPPCOM_CONF Pathname of vppcom configuration file. |
| 92 | VPP_GDB_CMDFILE Pathname of gdb command file for vpp. |
| 93 | VPPCOM_CLIENT_GDB_CMDFILE Pathname of gdb command file for client. |
| 94 | VPPCOM_SERVER_GDB_CMDFILE Pathname of gdb command file for server. |
| 95 | EOF |
| 96 | exit 1 |
| 97 | } |
| 98 | |
| 99 | declare -i emacs_vpp=0 |
| 100 | declare -i emacs_client=0 |
| 101 | declare -i emacs_server=0 |
| 102 | declare -i gdb_vpp=0 |
| 103 | declare -i gdb_client=0 |
| 104 | declare -i gdb_server=0 |
| 105 | declare -i perf_vpp=0 |
| 106 | declare -i perf_client=0 |
| 107 | declare -i perf_server=0 |
| 108 | declare -i leave_tmp_files=0 |
| 109 | declare -i bash_after_exit=0 |
| 110 | declare -i iperf3=0 |
| 111 | |
| 112 | while getopts ":hitlbcde:g:p:E:I:N:P:R:S:T:UBVX" opt; do |
| 113 | case $opt in |
| 114 | h) usage ;; |
| 115 | l) leave_tmp_files=1 |
| 116 | ;; |
| 117 | b) bash_after_exit=1 |
| 118 | ;; |
| 119 | i) iperf3=1 |
| 120 | ;; |
| 121 | t) xterm_geom="180x40" |
| 122 | use_tabs="true" |
| 123 | ;; |
| 124 | c) VPPCOM_CONF="${vppcom_conf_dir}vppcom_test.conf" |
| 125 | ;; |
| 126 | d) title_dbg="-DEBUG" |
| 127 | vpp_dir=$vpp_debug_dir |
| 128 | lib64_dir=$lib64_debug_dir |
| 129 | ;; |
| 130 | e) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then |
| 131 | emacs_client=1 |
| 132 | emacs_server=1 |
| 133 | emacs_vpp=1 |
| 134 | elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then |
| 135 | emacs_client=1 |
| 136 | elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then |
| 137 | emacs_server=1 |
| 138 | elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then |
| 139 | emacs_vpp=1 |
| 140 | else |
| 141 | echo "ERROR: Option -e unknown argument \'$OPTARG\'" >&2 |
| 142 | usage |
| 143 | fi |
| 144 | title_dbg="-DEBUG" |
| 145 | vpp_dir=$vpp_debug_dir |
| 146 | lib64_dir=$lib64_debug_dir |
| 147 | ;; |
| 148 | g) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then |
| 149 | gdb_client=1 |
| 150 | gdb_server=1 |
| 151 | gdb_vpp=1 |
| 152 | elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then |
| 153 | gdb_client=1 |
| 154 | elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then |
| 155 | gdb_server=1 |
| 156 | elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then |
| 157 | gdb_vpp=1 |
| 158 | else |
| 159 | echo "ERROR: Option -g unknown argument \'$OPTARG\'" >&2 |
| 160 | usage |
| 161 | fi |
| 162 | title_dbg="-DEBUG" |
| 163 | vpp_dir=$vpp_debug_dir |
| 164 | lib64_dir=$lib64_debug_dir |
| 165 | ;; |
| 166 | p) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then |
| 167 | perf_client=1 |
| 168 | perf_server=1 |
| 169 | perf_vpp=1 |
| 170 | elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then |
| 171 | perf_client=1 |
| 172 | elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then |
| 173 | perf_server=1 |
| 174 | elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then |
| 175 | perf_vpp=1 |
| 176 | else |
| 177 | echo "ERROR: Option -p unknown argument \'$OPTARG\'" >&2 |
| 178 | usage |
| 179 | fi |
| 180 | echo "WARNING: -p options TBD" |
| 181 | ;; |
| 182 | S) sock_srvr_addr="$OPTARG" |
| 183 | ;; |
| 184 | P) sock_srvr_port="$OPTARG" |
| 185 | ;; |
| 186 | E|I|N|R|T) sock_clnt_options="$sock_clnt_options -$opt \"$OPTARG\"" |
| 187 | ;; |
| 188 | U|B|V|X) sock_clnt_options="$sock_clnt_options -$opt" |
| 189 | ;; |
| 190 | \?) |
| 191 | echo "ERROR: Invalid option: -$OPTARG" >&2 |
| 192 | usage |
| 193 | ;; |
| 194 | :) |
| 195 | echo "ERROR: Option -$OPTARG requires an argument." >&2 |
| 196 | usage |
| 197 | ;; |
| 198 | esac |
| 199 | done |
| 200 | |
| 201 | shift $(( $OPTIND-1 )) |
| 202 | while ! [[ $run_test ]] && (( $# > 0 )) ; do |
| 203 | case $1 in |
| 204 | "nk" | "native-kernel") |
| 205 | run_test="native_kernel" ;; |
| 206 | "np" | "native-preload") |
| 207 | run_test="native_preload" ;; |
| 208 | "nv" | "native-vcl") |
| 209 | sock_srvr_app="vcl_test_server" |
| 210 | sock_clnt_app="vcl_test_client" |
| 211 | run_test="native_vcl" ;; |
| 212 | "dk" | "docker-kernel") |
| 213 | run_test="docker_kernel" ;; |
| 214 | "dp" | "docker-preload") |
| 215 | run_test="docker_preload" ;; |
| 216 | "dv" | "docker-vcl") |
| 217 | sock_srvr_app="vcl_test_server" |
| 218 | sock_clnt_app="vcl_test_client" |
| 219 | run_test="docker_vcl" ;; |
| 220 | *) |
| 221 | echo "ERROR: Unknown option '$1'!" >&2 |
| 222 | usage ;; |
| 223 | esac |
| 224 | shift |
| 225 | done |
| 226 | |
| 227 | if [ -z "$WS_ROOT" ] ; then |
| 228 | echo "ERROR: WS_ROOT environment variable not set!" >&2 |
| 229 | echo " Please set WS_ROOT to VPP workspace root directory." >&2 |
| 230 | env_test_failed="true" |
| 231 | fi |
| 232 | |
| 233 | if [ ! -d $vpp_dir ] ; then |
| 234 | echo "ERROR: Missing VPP$DEBUG bin directory!" >&2 |
| 235 | echo " $vpp_dir" >&2 |
| 236 | env_test_failed="true" |
| 237 | fi |
| 238 | |
| 239 | if [[ $run_test =~ .*"_preload" ]] ; then |
| 240 | if [ ! -d $lib64_dir ] ; then |
| 241 | echo "ERROR: Missing VPP$DEBUG lib64 directory!" >&2 |
| 242 | echo " $lib64_dir" >&2 |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 243 | elif [ ! -d $VCL_LDPRELOAD_LIB_DIR ] ; then |
| 244 | echo "ERROR: Missing VCL LD_PRELOAD Library directory!" >&2 |
| 245 | echo " $VCL_LDPRELOAD_LIB_DIR" >&2 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 246 | env_test_failed="true" |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 247 | elif [ ! -f $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib ] ; then |
| 248 | echo "ERROR: Missing VCL LD_PRELOAD library!" >&2 |
| 249 | echo " $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib" >&2 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 250 | env_test_failed="true" |
| 251 | fi |
| 252 | fi |
| 253 | |
| 254 | if [ ! -f $vpp_dir$vpp_app ] ; then |
| 255 | echo "ERROR: Missing VPP$DEBUG Application!" >&2 |
| 256 | echo " $vpp_dir$vpp_app" >&2 |
| 257 | env_test_failed="true" |
| 258 | fi |
| 259 | |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 260 | if [ ! -f $vpp_dir$sock_srvr_app ] && [ ! $iperf3 -eq 1 ] ; then |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 261 | echo "ERROR: Missing$DEBUG Socket Server Application!" >&2 |
| 262 | echo " $vpp_dir$sock_srvr_app" >&2 |
| 263 | env_test_failed="true" |
| 264 | fi |
| 265 | |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 266 | if [ ! -f $vpp_dir$sock_clnt_app ] && [ ! $iperf3 -eq 1 ] ; then |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 267 | echo "ERROR: Missing$DEBUG Socket Client Application!" >&2 |
| 268 | echo " $vpp_dir$sock_clnt_app" >&2 |
| 269 | env_test_failed="true" |
| 270 | fi |
| 271 | |
| 272 | if [[ $run_test =~ "docker_".* ]] ; then |
| 273 | if [ $emacs_client -eq 1 ] || [ $emacs_server -eq 1 ] || [ $gdb_client -eq 1 ] || [ $gdb_server -eq 1 ] ; then |
| 274 | |
| 275 | echo "WARNING: gdb is not currently supported in docker." |
| 276 | echo " Ignoring client/server gdb options." |
| 277 | emacs_client=0 |
| 278 | emacs_server=0 |
| 279 | gdb_client=0 |
| 280 | gdb_server=0 |
| 281 | fi |
| 282 | fi |
| 283 | |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 284 | if [[ $run_test =~ .*"_vcl" ]] && [ $iperf3 -eq 1 ] ; then |
| 285 | echo "ERROR: Invalid option 'i' for test $run_test!" |
| 286 | echo " iperf3 is not compiled with the VCL library." |
| 287 | env_test_failed="true" |
| 288 | fi |
| 289 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 290 | if [ -n "$env_test_failed" ] ; then |
| 291 | exit 1 |
| 292 | fi |
| 293 | |
| 294 | if [ -f "$VPPCOM_CONF" ] ; then |
| 295 | vppcom_conf="$(basename $VPPCOM_CONF)" |
| 296 | vppcom_conf_dir="$(dirname $VPPCOM_CONF)/" |
| 297 | api_prefix="$(egrep -s '^\s*api-prefix \w+' $VPPCOM_CONF | awk -e '{print $2}')" |
| 298 | if [ -n "$api_prefix" ] ; then |
| 299 | api_segment=" api-segment { prefix $api_prefix }" |
| 300 | fi |
| 301 | fi |
| 302 | vpp_args="unix { interactive cli-listen /run/vpp/cli.sock }${api_segment}" |
| 303 | |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 304 | if [ $iperf3 -eq 1 ] ; then |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 305 | app_dir="$(dirname $(which iperf3))/" |
| 306 | srvr_app=$iperf_srvr_app |
| 307 | clnt_app=$iperf_clnt_app |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 308 | if [[ $run_test =~ "docker_".* ]] ; then |
| 309 | unset -v app_dir |
| 310 | sock_srvr_port=5201 |
| 311 | docker_app_dir="networkstatic/" |
| 312 | unset -v docker_os |
| 313 | fi |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 314 | else |
| 315 | app_dir="$vpp_dir" |
| 316 | srvr_app="$sock_srvr_app $sock_srvr_port" |
| 317 | clnt_app="$sock_clnt_app${sock_clnt_options} \$srvr_addr $sock_srvr_port" |
| 318 | fi |
| 319 | |
| 320 | verify_no_vpp() { |
| 321 | local running_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\"" |
| 322 | if [ "$(eval $running_vpp)" != "" ] ; then |
| 323 | echo "ERROR: Please kill all running vpp instances:" |
| 324 | echo |
| 325 | eval $running_vpp |
| 326 | echo |
| 327 | exit 1 |
| 328 | fi |
| 329 | 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]*" |
| 330 | rm -f $clean_devshm |
| 331 | devshm_files="$(ls -l $clean_devshm 2>/dev/null | grep $(whoami))" |
| 332 | if [ "$devshm_files" != "" ] ; then |
| 333 | echo "ERROR: Please remove the following $vpp_shm_dir files:" |
| 334 | for file in "$devshm_files" ; do |
| 335 | echo " $file" |
| 336 | done |
| 337 | exit 1 |
| 338 | fi |
| 339 | } |
| 340 | |
| 341 | verify_no_docker_containers() { |
| 342 | if (( $(which docker | wc -l) < 1 )) ; then |
| 343 | echo "ERROR: docker is not installed!" |
| 344 | echo "See https://docs.docker.com/engine/installation/linux/ubuntu/" |
| 345 | echo " or https://docs.docker.com/engine/installation/linux/centos/" |
| 346 | exit 1 |
| 347 | fi |
| 348 | if (( $(docker ps | wc -l) > 1 )) ; then |
| 349 | echo "ERROR: Run the following to kill all docker containers:" |
| 350 | echo "docker kill \$(docker ps -q)" |
| 351 | echo |
| 352 | docker ps |
| 353 | exit 1 |
| 354 | fi |
| 355 | } |
| 356 | |
| 357 | set_pre_cmd() { |
| 358 | # arguments |
| 359 | # $1 : emacs flag |
| 360 | # $2 : gdb flag |
| 361 | # $3 : optional LD_PRELOAD library pathname |
| 362 | local -i emacs=$1 |
| 363 | local -i gdb=$2 |
| 364 | |
| 365 | if [ $emacs -eq 1 ] ; then |
| 366 | write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3 |
| 367 | pre_cmd="$gdb_in_emacs " |
| 368 | elif [ $gdb -eq 1 ] ; then |
| 369 | write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3 |
| 370 | pre_cmd="gdb -x $tmp_gdb_cmdfile -i=mi --args " |
| 371 | elif [ -z $3 ] ; then |
| 372 | unset -v pre_cmd |
| 373 | else |
| 374 | docker_ld_preload="-e LD_PRELOAD=$3 " |
| 375 | pre_cmd="LD_PRELOAD=$3 " |
| 376 | fi |
| 377 | } |
| 378 | |
| 379 | write_script_header() { |
| 380 | # arguments |
| 381 | # $1 : command script file |
| 382 | # $2 : gdb command file |
| 383 | # $3 : title |
| 384 | # $4 : optional command string (typically "sleep 2") |
| 385 | echo "$bash_header" > $1 |
| 386 | echo -e "#\n# $1 generated on $(date)\n#" >> $1 |
| 387 | if [ $leave_tmp_files -eq 0 ] ; then |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 388 | echo "trap \"rm -f $1 $2\" $trap_signals" >> $1 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 389 | fi |
| 390 | echo "export VPPCOM_CONF=${vppcom_conf_dir}${vppcom_conf}" >> $1 |
| 391 | if [ "$pre_cmd" = "$gdb_in_emacs " ] ; then |
| 392 | cat <<EOF >> $1 |
| 393 | $gdb_in_emacs() { |
| 394 | emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")" |
| 395 | } |
| 396 | EOF |
| 397 | fi |
| 398 | if [ -n "$4" ] ; then |
| 399 | echo "$4" >> $1 |
| 400 | fi |
| 401 | } |
| 402 | |
| 403 | write_script_footer() { |
| 404 | # arguments |
| 405 | # $1 : command script file |
| 406 | # $2 : perf flag indicating to run bash before exit |
| 407 | local -i perf=$2 |
| 408 | if [ $bash_after_exit -eq 1 ] || [ $perf -eq 1 ] ; then |
| 409 | echo "bash" >> $1 |
| 410 | fi |
| 411 | } |
| 412 | |
| 413 | write_gdb_cmdfile() { |
| 414 | # arguments |
| 415 | # $1 : gdb command file |
| 416 | # $2 : User specified gdb cmdfile |
| 417 | # $3 : emacs flag |
| 418 | # $4 : optional LD_PRELOAD library pathname. |
| 419 | local -i emacs=$3 |
| 420 | |
| 421 | echo "# $1 generated on $(date)" > $1 |
| 422 | echo "#" >> $1 |
| 423 | echo "set confirm off" >> $1 |
| 424 | if [ -n "$4" ] ; then |
| 425 | echo "set exec-wrapper env LD_PRELOAD=$4" >> $1 |
| 426 | echo "start" >> $1 |
| 427 | fi |
| 428 | |
| 429 | if [ ! -f $2 ] ; then |
| 430 | echo -n "# " >> $1 |
| 431 | fi |
| 432 | echo "source $2" >> $1 |
| 433 | if [ $emacs -eq 0 ] ; then |
| 434 | echo "run" >> $1 |
| 435 | fi |
| 436 | } |
| 437 | |
| 438 | native_kernel() { |
| 439 | banner="Running NATIVE-KERNEL socket test" |
| 440 | |
| 441 | title1="SERVER$title_dbg (Native-Kernel Socket Test)" |
| 442 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server |
| 443 | gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE |
| 444 | set_pre_cmd $emacs_server $gdb_server |
| 445 | write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1" |
| 446 | echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd1_file |
| 447 | write_script_footer $cmd1_file $perf_server |
| 448 | |
| 449 | title2="CLIENT$title_dbg (Native-Kernel Socket Test)" |
| 450 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client |
| 451 | gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE |
| 452 | set_pre_cmd $emacs_client $gdb_client |
| 453 | write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2" |
| 454 | echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd2_file |
| 455 | echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd2_file |
| 456 | write_script_footer $cmd2_file $perf_client |
| 457 | |
| 458 | chmod +x $cmd1_file $cmd2_file |
| 459 | } |
| 460 | |
| 461 | native_preload() { |
| 462 | verify_no_vpp |
| 463 | banner="Running NATIVE-PRELOAD socket test" |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 464 | ld_preload="$VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib " |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 465 | |
| 466 | title1="VPP$title_dbg (Native-Preload Socket Test)" |
| 467 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp |
| 468 | gdb_cmdfile=$VPP_GDB_CMDFILE |
| 469 | set_pre_cmd $emacs_vpp $gdb_vpp |
| 470 | write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1" |
| 471 | echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file |
| 472 | write_script_footer $cmd1_file $perf_vpp |
| 473 | |
| 474 | title2="SERVER$title_dbg (Native-Preload Socket Test)" |
| 475 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server |
| 476 | gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE |
| 477 | set_pre_cmd $emacs_server $gdb_server $ld_preload |
| 478 | write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 479 | echo "export LD_LIBRARY_PATH=\"$lib64_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd2_file |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 480 | echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file |
| 481 | write_script_footer $cmd2_file $perf_server |
| 482 | |
| 483 | title3="CLIENT$title_dbg (Native-Preload Socket Test)" |
| 484 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client |
| 485 | gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE |
| 486 | set_pre_cmd $emacs_client $gdb_client $ld_preload |
| 487 | write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 488 | echo "export LD_LIBRARY_PATH=\"$lib64_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd3_file |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 489 | echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file |
| 490 | echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file |
| 491 | write_script_footer $cmd3_file $perf_client |
| 492 | |
| 493 | chmod +x $cmd1_file $cmd2_file $cmd3_file |
| 494 | } |
| 495 | |
| 496 | native_vcl() { |
| 497 | verify_no_vpp |
| 498 | banner="Running NATIVE-VCL socket test" |
| 499 | |
| 500 | title1="VPP$title_dbg (Native-VCL Socket Test)" |
| 501 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp |
| 502 | gdb_cmdfile=$VPP_GDB_CMDFILE |
| 503 | set_pre_cmd $emacs_vpp $gdb_vpp |
| 504 | write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1" |
| 505 | echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file |
| 506 | write_script_footer $cmd1_file $perf_vpp |
| 507 | |
| 508 | title2="SERVER$title_dbg (Native-VCL Socket Test)" |
| 509 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server |
| 510 | gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE |
| 511 | set_pre_cmd $emacs_server $gdb_server |
| 512 | write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2" |
| 513 | echo "export LD_LIBRARY_PATH=\"$lib64_dir:$LD_LIBRARY_PATH\"" >> $cmd2_file |
| 514 | echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file |
| 515 | write_script_footer $cmd2_file $perf_server |
| 516 | |
| 517 | title3="CLIENT$title_dbg (Native-VCL Socket Test)" |
| 518 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client |
| 519 | gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE |
| 520 | set_pre_cmd $emacs_client $gdb_client |
| 521 | write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3" |
| 522 | echo "export LD_LIBRARY_PATH=\"$lib64_dir:$LD_LIBRARY_PATH\"" >> $cmd3_file |
| 523 | echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file |
| 524 | echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file |
| 525 | write_script_footer $cmd3_file $perf_client |
| 526 | |
| 527 | chmod +x $cmd1_file $cmd2_file $cmd3_file |
| 528 | } |
| 529 | |
| 530 | docker_kernel() { |
| 531 | verify_no_docker_containers |
| 532 | banner="Running DOCKER-KERNEL socket test" |
| 533 | |
| 534 | title1="SERVER$title_dbg (Docker-Native Socket Test)" |
| 535 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server |
| 536 | gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE |
| 537 | set_pre_cmd $emacs_server $gdb_server |
| 538 | write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 539 | echo "docker run -it -v $vpp_dir:$docker_vpp_dir -p $sock_srvr_port:$sock_srvr_port $docker_os ${docker_app_dir}${srvr_app}" >> $cmd1_file |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 540 | write_script_footer $cmd1_file $perf_server |
| 541 | |
| 542 | title2="CLIENT$title_dbg (Docker-Native Socket Test)" |
| 543 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client |
| 544 | gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE |
| 545 | set_pre_cmd $emacs_client $gdb_client |
| 546 | write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2" |
| 547 | echo "$get_docker_server_ip4addr" >> $cmd2_file |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 548 | echo "docker run -it -v $vpp_dir:$docker_vpp_dir $docker_os ${docker_app_dir}${clnt_app}" >> $cmd2_file |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 549 | write_script_footer $cmd2_file $perf_client |
| 550 | |
| 551 | chmod +x $cmd1_file $cmd2_file |
| 552 | } |
| 553 | |
| 554 | docker_preload() { |
| 555 | verify_no_vpp |
| 556 | verify_no_docker_containers |
| 557 | banner="Running DOCKER-PRELOAD socket test" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 558 | docker_ld_preload_dir="/vcl-ldpreload/" |
| 559 | ld_preload_dir="$VCL_LDPRELOAD_LIB_DIR" |
| 560 | ld_preload="$docker_ld_preload_dir$vcl_ldpreload_lib " |
| 561 | docker_ld_preload_lib="$docker_ld_preload_dir$vcl_ldpreload_lib " |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 562 | |
| 563 | title1="VPP$title_dbg (Docker-Preload Socket Test)" |
| 564 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp |
| 565 | gdb_cmdfile=$VPP_GDB_CMDFILE |
| 566 | set_pre_cmd $emacs_vpp $gdb_vpp |
| 567 | write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1" |
| 568 | echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file |
| 569 | write_script_footer $cmd1_file $perf_vpp |
| 570 | |
| 571 | title2="SERVER$title_dbg (Docker-Preload Socket Test)" |
| 572 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server |
| 573 | gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 574 | set_pre_cmd $emacs_server $gdb_server $docker_ld_preload_lib |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 575 | write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 576 | 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 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 577 | write_script_footer $cmd2_file $perf_server |
| 578 | |
| 579 | title3="CLIENT$title_dbg (Docker-Preload Socket Test)" |
| 580 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client |
| 581 | gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE |
Dave Wallace | d69f4f4 | 2017-08-14 18:26:46 -0400 | [diff] [blame] | 582 | set_pre_cmd $emacs_client $gdb_client $docker_ld_preload_lib |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 583 | write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3" |
| 584 | echo "$get_docker_server_ip4addr" >> $cmd3_file |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 585 | 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 -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 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 586 | write_script_footer $cmd3_file $perf_client |
| 587 | |
| 588 | chmod +x $cmd1_file $cmd2_file $cmd3_file |
| 589 | } |
| 590 | |
| 591 | docker_vcl() { |
| 592 | verify_no_vpp |
| 593 | verify_no_docker_containers |
| 594 | banner="Running DOCKER-VCL socket test" |
| 595 | |
| 596 | title1="VPP$title_dbg (Docker-VCL Socket Test)" |
| 597 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp |
| 598 | gdb_cmdfile=$VPP_GDB_CMDFILE |
| 599 | set_pre_cmd $emacs_vpp $gdb_vpp |
| 600 | write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1" |
| 601 | echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file |
| 602 | write_script_footer $cmd1_file $perf_vpp |
| 603 | |
| 604 | title2="SERVER$title_dbg (Docker-VCL Socket Test)" |
| 605 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server |
| 606 | gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE |
| 607 | set_pre_cmd $emacs_server $gdb_server |
| 608 | write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2" |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 609 | echo "docker run -it -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 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 610 | write_script_footer $cmd2_file $perf_server |
| 611 | |
| 612 | title3="CLIENT$title_dbg (Docker-VCL Socket Test)" |
| 613 | tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client |
| 614 | gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE |
| 615 | set_pre_cmd $emacs_client $gdb_client |
| 616 | write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3" |
| 617 | echo "$get_docker_server_ip4addr" >> $cmd3_file |
Dave Wallace | 30fb4a2 | 2017-08-17 16:22:04 -0400 | [diff] [blame] | 618 | echo "docker run -it -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 |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 619 | write_script_footer $cmd3_file $perf_client |
| 620 | |
| 621 | chmod +x $cmd1_file $cmd2_file $cmd3_file |
| 622 | } |
| 623 | |
| 624 | if [[ $run_test ]] ; then |
| 625 | eval $run_test |
| 626 | else |
| 627 | echo "ERROR: Please specify a test to run!" >&2 |
| 628 | usage; |
| 629 | fi |
| 630 | |
| 631 | if (( $(which xfce4-terminal | wc -l) > 0 )) ; then |
| 632 | xterm_cmd="xfce4-terminal --geometry $xterm_geom" |
| 633 | if [[ $use_tabs ]] ; then |
| 634 | if [ -x "$cmd3_file" ] ; then |
| 635 | $xterm_cmd --title "$title1" --command "$cmd1_file" --tab --title "$title2" --command "$cmd2_file" --tab --title "$title3" --command "$cmd3_file" |
| 636 | else |
| 637 | $xterm_cmd --title "$title1" --command "$cmd1_file" --tab --title "$title2" --command "$cmd2_file" |
| 638 | fi |
| 639 | else |
| 640 | ($xterm_cmd --title "$title1" --command "$cmd1_file" &) |
| 641 | ($xterm_cmd --title "$title2" --command "$cmd2_file" &) |
| 642 | if [ -x "$cmd3_file" ] ; then |
| 643 | ($xterm_cmd --title "$title3" --command "$cmd3_file" &) |
| 644 | fi |
| 645 | fi |
| 646 | |
| 647 | else |
| 648 | if [[ $use_tabs ]] ; then |
| 649 | echo "Sorry, plain ol' xterm doesn't support tabs." |
| 650 | fi |
| 651 | xterm_cmd="xterm -fs 10 -geometry $xterm_geom" |
| 652 | ($xterm_cmd -title "$title1" -e "$cmd1_file" &) |
| 653 | ($xterm_cmd -title "$title2" -e "$cmd2_file" &) |
| 654 | if [ -x "$cmd3_file" ] ; then |
| 655 | ($xterm_cmd -title "$title3" -e "$cmd3_file" &) |
| 656 | fi |
| 657 | fi |
| 658 | |
| 659 | sleep 1 |