VCL: clean up disconnect_session debug output.
[vpp.git] / extras / vcl-ldpreload / test / common / nginx_test.sh
1 #! /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 #
16 vpp_dk_name="NGINX"
17 # Comment out the next line to run the VPP release version
18 debug="_debug"
19 vpp_app="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/bin/vpp"
20
21 check_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.
27 if [ -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
31 fi
32
33 if [ -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
36     echo "       $WS_ROOT/build-root/install-vpp[_debug]-native/vpp/lib64." >&2
37     exit 1
38 fi
39
40 TEST_APP="${TEST_APP:-curl}"
41 LDP_DIR="${WS_ROOT}/extras/vcl-ldpreload"
42 LDP_TEST_DIR="${LDP_TEST_DIR:-${LDP_DIR}/test}"
43 LDP_LIB="${LDP_LIB:-${VCL_LDPRELOAD_LIB_DIR}/libvcl_ldpreload.so.0.0.0}"
44
45 if [ ! -f "$LDP_LIB" ] ; then
46     echo "ERROR: Missing VCL-LDPRELOAD Library: $LDP_LIB"
47     echo "       Run 'cd $WS_ROOT; make build[-release] ' !"
48     exit 1
49 fi
50
51 if [ -n "$STRACE_ONLY" ] ; then
52     echo "Running strace -tt $TEST_APP http://$nginx_addr"
53     strace -tt $TEST_APP http://$nginx_addr
54 else
55     check_for_vpp
56     if [ -z "$running_vpp" ] ; then
57         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
72     fi
73
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         
79         export LD_LIBRARY_PATH="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/lib64/:$LDP_DIR/src/.libs:"
80
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"
93     LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr
94 fi