blob: 73f2911b57ccc8d3f4a47c3547879454aef3d7f6 [file] [log] [blame]
Dave Wallace80b48a62017-10-17 04:00:50 -04001#! /bin/bash
2#
3# nginx_test.sh
4#
5# Run specified app using LD_PRELOAD to fetch a page from
6# nginx running in vpp1 net-namespace.
7#
8# Specify the following environment variables:
9#
10# STRACE_ONLY - Run app with strace instead of LD_PRELOAD.
11# TEST_APP - App to run (default: curl)
12#
13
14# Configuration variables.
15#
Dave Wallace3bd43b82017-11-11 22:45:38 -050016vpp_dk_name="NGINX"
Dave Wallace80b48a62017-10-17 04:00:50 -040017# Comment out the next line to run the VPP release version
18debug="_debug"
19vpp_app="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/bin/vpp"
20
21check_for_vpp() {
22 local grep_for_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
23 running_vpp="$(eval $grep_for_vpp)"
24}
25
26# Verify Environment.
27if [ -z "$WS_ROOT" ] ; then
28 echo "ERROR: WS_ROOT environment variable not set!" >&2
29 echo " Please set WS_ROOT to VPP workspace root directory." >&2
30 exit 1
31fi
Dave Wallace5c7cf1c2017-10-24 04:12:18 -040032
33if [ -z "$VCL_LDPRELOAD_LIB_DIR" ] ; then
34 echo "ERROR: VCL_LDPRELOAD_LIB_DIR environment variable not set!" >&2
35 echo " Please set VCL_LDPRELOAD_LIB_DIR to " >&2
Damjan Marion79dcbc72018-09-12 14:01:10 +020036 echo " $WS_ROOT/build-root/install-vpp[_debug]-native/vpp/lib." >&2
Dave Wallace5c7cf1c2017-10-24 04:12:18 -040037 exit 1
Dave Wallace80b48a62017-10-17 04:00:50 -040038fi
39
40TEST_APP="${TEST_APP:-curl}"
Dave Wallace5c7cf1c2017-10-24 04:12:18 -040041LDP_DIR="${WS_ROOT}/extras/vcl-ldpreload"
Dave Wallace80b48a62017-10-17 04:00:50 -040042LDP_TEST_DIR="${LDP_TEST_DIR:-${LDP_DIR}/test}"
43LDP_LIB="${LDP_LIB:-${VCL_LDPRELOAD_LIB_DIR}/libvcl_ldpreload.so.0.0.0}"
44
45if [ ! -f "$LDP_LIB" ] ; then
46 echo "ERROR: Missing VCL-LDPRELOAD Library: $LDP_LIB"
Dave Wallace5c7cf1c2017-10-24 04:12:18 -040047 echo " Run 'cd $WS_ROOT; make build[-release] ' !"
Dave Wallace80b48a62017-10-17 04:00:50 -040048 exit 1
49fi
50
Dave Wallace80b48a62017-10-17 04:00:50 -040051if [ -n "$STRACE_ONLY" ] ; then
52 echo "Running strace -tt $TEST_APP http://$nginx_addr"
53 strace -tt $TEST_APP http://$nginx_addr
54else
55 check_for_vpp
56 if [ -z "$running_vpp" ] ; then
Dave Wallace3bd43b82017-11-11 22:45:38 -050057 echo -e "\nConfiguring network interfaces"
58 sudo ip link del dev vpp_dk
59 sudo ip link add name vpp_dk type veth peer name vpp1
60 sudo ip link set dev vpp_dk up
61 sudo ethtool --offload vpp_dk rx off tx off
62 sudo ip link set dev vpp1 up
63 sudo ethtool --offload vpp1 rx off tx off
64 sudo ip link set dev lo up
65 sudo brctl addif docker0 vpp_dk
66
67 echo "Starting VPP "
68 sudo rm -f /dev/shm/*
69 sudo xfce4-terminal --title VPP --command "$vpp_app unix { interactive exec $LDP_TEST_DIR/common/vpp_docker.conf full-coredump coredump-size unlimited } api-segment { gid $(id -g) }" &
70# sudo $vpp_app unix { cli-listen localhost:5002 exec $LDP_TEST_DIR/common/vpp_docker.conf } api-segment { gid $(id -g) }
71 sleep 4
Dave Wallace80b48a62017-10-17 04:00:50 -040072 fi
Dave Wallace3bd43b82017-11-11 22:45:38 -050073
74 if [ -z "$(docker ps -qf name=$vpp_dk_name)" ] ; then
75 echo -e "\nStarting NGINX in docker container ($vpp_dk_name)"
76 echo "docker run --rm --name $vpp_dk_name -v $LDP_TEST_DIR/common/nginx_welcome.html:/usr/share/nginx/html/index.html:ro -d nginx"
77 docker run --rm --name $vpp_dk_name -v $LDP_TEST_DIR/common/nginx_welcome.html:/usr/share/nginx/html/index.html:ro -d nginx
78
Damjan Marion79dcbc72018-09-12 14:01:10 +020079 export LD_LIBRARY_PATH="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/lib/:$LDP_DIR/src/.libs:"
Dave Wallace3bd43b82017-11-11 22:45:38 -050080
81 # Extract nginx IPv4 address from docker bridge
82 #
83 nginx_addr=$(docker network inspect bridge | grep IPv4Address | awk -e '{print $2}' | sed -e 's,/16,,' -e 's,",,g' -e 's/,//')
84
85 if [ -z "$nginx_addr" ] ; then
86 echo "ERROR: Unable to determine docker container address!"
87 exit 1
88 fi
89 fi
90
91 echo -e "\nRunning wget"
92 echo -e "LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr\n"
Dave Wallace80b48a62017-10-17 04:00:50 -040093 LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr
94fi