aboutsummaryrefslogtreecommitdiffstats
path: root/extras/vcl-ldpreload/test
diff options
context:
space:
mode:
authorDave Wallace <dwallacelf@gmail.com>2017-10-17 04:00:50 -0400
committerKeith Burns <alagalah@gmail.com>2017-10-17 16:09:25 +0000
commit80b48a61b8781b41b5c2eeca482c2778562422f4 (patch)
treef95c26598652be0f08c568e9c6d0d13c409a2f35 /extras/vcl-ldpreload/test
parent68a40c868d84284ce5a4d048a2a1a1415a5a24f8 (diff)
VCL_LDPRELOAD: Add unit test scripts.
Change-Id: I5fbb3339a6dbd7b40fecf66bfda3fd3249b4a90c Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Diffstat (limited to 'extras/vcl-ldpreload/test')
-rwxr-xr-xextras/vcl-ldpreload/test/common/nginx_test.sh84
-rw-r--r--extras/vcl-ldpreload/test/common/nginx_welcome.html25
-rw-r--r--extras/vcl-ldpreload/test/common/vpp_docker.conf3
-rwxr-xr-xextras/vcl-ldpreload/test/curl_test.sh24
-rwxr-xr-xextras/vcl-ldpreload/test/wget_test.sh24
5 files changed, 160 insertions, 0 deletions
diff --git a/extras/vcl-ldpreload/test/common/nginx_test.sh b/extras/vcl-ldpreload/test/common/nginx_test.sh
new file mode 100755
index 00000000000..7c43324dbc8
--- /dev/null
+++ b/extras/vcl-ldpreload/test/common/nginx_test.sh
@@ -0,0 +1,84 @@
+#! /bin/bash
+#
+# nginx_test.sh
+#
+# Run specified app using LD_PRELOAD to fetch a page from
+# nginx running in vpp1 net-namespace.
+#
+# Specify the following environment variables:
+#
+# STRACE_ONLY - Run app with strace instead of LD_PRELOAD.
+# TEST_APP - App to run (default: curl)
+#
+
+# Configuration variables.
+#
+vpp_dk_name="VPP-TEST-NGINX"
+# Comment out the next line to run the VPP release version
+debug="_debug"
+vpp_app="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/bin/vpp"
+
+check_for_vpp() {
+ local grep_for_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
+ running_vpp="$(eval $grep_for_vpp)"
+}
+
+# Verify Environment.
+if [ -z "$WS_ROOT" ] ; then
+ echo "ERROR: WS_ROOT environment variable not set!" >&2
+ echo " Please set WS_ROOT to VPP workspace root directory." >&2
+ exit 1
+fi
+if [ -z "$LDP_DIR" ] ; then
+ echo "WARNING: LDP_DIR environment variable is not set!"
+ echo " Sourcing $WS_ROOT/extras/vcl-ldpreload/env.sh"
+ source $WS_ROOT/extras/vcl-ldpreload/env.sh
+fi
+
+TEST_APP="${TEST_APP:-curl}"
+LDP_TEST_DIR="${LDP_TEST_DIR:-${LDP_DIR}/test}"
+LDP_LIB="${LDP_LIB:-${VCL_LDPRELOAD_LIB_DIR}/libvcl_ldpreload.so.0.0.0}"
+
+if [ ! -f "$LDP_LIB" ] ; then
+ echo "ERROR: Missing VCL-LDPRELOAD Library: $LDP_LIB"
+ echo " See $LDP_DIR/README.md for build instructions!"
+ exit 1
+fi
+
+if [ -z "$(docker ps -qf name=$vpp_dk_name)" ] ; then
+ echo "Starting NGINX in docker container ($vpp_dk_name)"
+ docker run --rm --name $vpp_dk_name -v $LDP_TEST_DIR/common/nginx_welcome.html:/usr/share/nginx/html/index.html:ro -d nginx
+
+ echo "Configuring network interfaces"
+ sudo ip link del dev vpp_dk
+ sudo ip link add name vpp_dk type veth peer name vpp1
+ sudo ip link set dev vpp_dk up
+ sudo ip link set dev vpp1 up
+ sudo ip link set dev lo up
+ sudo brctl addif docker0 vpp_dk
+fi
+
+export LD_LIBRARY_PATH="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/lib64/:$LDP_DIR/src/.libs:"
+
+# Extract nginx IPv4 address from docker bridge
+#
+nginx_addr=$(docker network inspect bridge | grep IPv4Address | awk -e '{print $2}' | sed -e 's,/16,,' -e 's,",,g' -e 's/,//')
+
+if [ -z "$nginx_addr" ] ; then
+ echo "ERROR: Unable to determine docker container address!"
+ exit 1
+fi
+
+if [ -n "$STRACE_ONLY" ] ; then
+ echo "Running strace -tt $TEST_APP http://$nginx_addr"
+ strace -tt $TEST_APP http://$nginx_addr
+else
+ check_for_vpp
+ if [ -z "$running_vpp" ] ; then
+ echo "Starting VPP ('telnet 0 5002' to connect to cli)"
+ sudo $vpp_app unix { cli-listen localhost:5002 exec $LDP_TEST_DIR/common/vpp_docker.conf } api-segment { gid $(id -g) }
+ sleep 2
+ fi
+ echo "Running LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr"
+ LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr
+fi
diff --git a/extras/vcl-ldpreload/test/common/nginx_welcome.html b/extras/vcl-ldpreload/test/common/nginx_welcome.html
new file mode 100644
index 00000000000..2ca3b9543c0
--- /dev/null
+++ b/extras/vcl-ldpreload/test/common/nginx_welcome.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Welcome to nginx!</title>
+<style>
+ body {
+ width: 35em;
+ margin: 0 auto;
+ font-family: Tahoma, Verdana, Arial, sans-serif;
+ }
+</style>
+</head>
+<body>
+<h1>Welcome to nginx!</h1>
+<p>If you see this page, the nginx web server is successfully installed and
+working. Further configuration is required.</p>
+
+<p>For online documentation and support please refer to
+<a href="http://nginx.org/">nginx.org</a>.<br/>
+Commercial support is available at
+<a href="http://nginx.com/">nginx.com</a>.</p>
+
+<p><em>Thank you for using nginx.</em></p>
+</body>
+</html>
diff --git a/extras/vcl-ldpreload/test/common/vpp_docker.conf b/extras/vcl-ldpreload/test/common/vpp_docker.conf
new file mode 100644
index 00000000000..4d18bb2d208
--- /dev/null
+++ b/extras/vcl-ldpreload/test/common/vpp_docker.conf
@@ -0,0 +1,3 @@
+create host-interface name vpp1
+set int state host-vpp1 up
+set int ip address host-vpp1 172.17.0.123/24
diff --git a/extras/vcl-ldpreload/test/curl_test.sh b/extras/vcl-ldpreload/test/curl_test.sh
new file mode 100755
index 00000000000..c0d88d7af4a
--- /dev/null
+++ b/extras/vcl-ldpreload/test/curl_test.sh
@@ -0,0 +1,24 @@
+#! /bin/bash
+#
+# curl_test.sh - VCL-LDPRELOAD curl test.
+#
+# Run curl using LD_PRELOAD to fetch a page from
+# nginx running in vpp1 net-namespace.
+#
+#
+
+# Verify Environment.
+if [ -z "$WS_ROOT" ] ; then
+ echo "ERROR: WS_ROOT environment variable not set!" >&2
+ echo " Please set WS_ROOT to VPP workspace root directory." >&2
+ exit 1
+fi
+if [ -z "$LDP_DIR" ] ; then
+ echo "WARNING: LDP_DIR environment variable is not set!"
+ echo " Sourcing $WS_ROOT/extras/vcl-ldpreload/env.sh"
+ source $WS_ROOT/extras/vcl-ldpreload/env.sh
+fi
+
+TEST_APP="${TEST_APP:-curl}"
+LDP_TEST_DIR="${LDP_TEST_DIR:-${LDP_DIR}/test}"
+source $LDP_TEST_DIR/common/nginx_test.sh
diff --git a/extras/vcl-ldpreload/test/wget_test.sh b/extras/vcl-ldpreload/test/wget_test.sh
new file mode 100755
index 00000000000..f85065b0d9b
--- /dev/null
+++ b/extras/vcl-ldpreload/test/wget_test.sh
@@ -0,0 +1,24 @@
+#! /bin/bash
+#
+# wget_test.sh - VCL-LDPRELOAD wget test.
+#
+# Run wget using LD_PRELOAD to fetch a page from
+# nginx running in vpp1 net-namespace.
+#
+#
+
+# Verify Environment.
+if [ -z "$WS_ROOT" ] ; then
+ echo "ERROR: WS_ROOT environment variable not set!" >&2
+ echo " Please set WS_ROOT to VPP workspace root directory." >&2
+ exit 1
+fi
+if [ -z "$LDP_DIR" ] ; then
+ echo "WARNING: LDP_DIR environment variable is not set!"
+ echo " Sourcing $WS_ROOT/extras/vcl-ldpreload/env.sh"
+ source $WS_ROOT/extras/vcl-ldpreload/env.sh
+fi
+
+TEST_APP="${TEST_APP:-wget}"
+LDP_TEST_DIR="${LDP_TEST_DIR:-${LDP_DIR}/test}"
+source $LDP_TEST_DIR/common/nginx_test.sh
span> typedef struct { u32 *random_pool; u32 seed; u32 iter; u32 verbose; f64 branching_factor; clib_slist_t slist; } test_main_t; test_main_t test_main; #define foreach_simple_test \ _(2) \ _(4) \ _(3) \ _(1) void run_test (test_main_t * tm) { int i; u32 *tv; u32 ncompares; u64 total_compares = 0; if (1) { /* * Add a bunch of random numbers to the skip-list, * sorting them. */ for (i = 0; i < tm->iter; i++) { pool_get (tm->random_pool, tv); *tv = random_u32 (&tm->seed); clib_slist_add (&tm->slist, tv, tv - tm->random_pool); } /* make sure we can find each one */ for (i = 0; i < tm->iter; i++) { u32 search_result; tv = pool_elt_at_index (tm->random_pool, i); search_result = clib_slist_search (&tm->slist, tv, &ncompares); ASSERT (search_result == i); total_compares += ncompares; } fformat (stdout, "%.2f avg compares/search\n", (f64) total_compares / (f64) i); fformat (stdout, "%U\n", format_slist, &tm->slist, tm->iter < 1000 /* verbose */ ); /* delete half of them */ for (i = tm->iter / 2; i < tm->iter; i++) { tv = pool_elt_at_index (tm->random_pool, i); (void) clib_slist_del (&tm->slist, tv); } /* make sure we can find the set we should find, and no others */ for (i = 0; i < tm->iter; i++) { u32 search_result; tv = pool_elt_at_index (tm->random_pool, i); search_result = clib_slist_search (&tm->slist, tv, &ncompares); if (i >= tm->iter / 2) ASSERT (search_result == (u32) ~ 0); else ASSERT (search_result == i); } fformat (stdout, "%U\n", format_slist, &tm->slist, tm->iter < 1000 /* verbose */ ); /* delete the rest */ for (i = 0; i < tm->iter; i++) { tv = pool_elt_at_index (tm->random_pool, i); (void) clib_slist_del (&tm->slist, tv); } fformat (stdout, "%U\n", format_slist, &tm->slist, tm->iter < 1000 /* verbose */ ); } else { #define _(n) \ do { \ pool_get (tm->random_pool, tv); \ *tv = n; \ clib_slist_add (&tm->slist, tv, tv - tm->random_pool); \ fformat(stdout, "%U\n", format_slist, &tm->slist, 1 /* verbose */); \ } while (0); foreach_simple_test; #undef _ } return; } word test_compare (void *key, u32 elt_index) { u32 *k = (u32 *) key; u32 elt = test_main.random_pool[elt_index]; if (*k < elt) return -1; if (*k > elt) return 1; return 0; } u8 * test_format (u8 * s, va_list * args) { u32 elt_index = va_arg (*args, u32); u32 elt = test_main.random_pool[elt_index]; return format (s, "%u", elt); } void initialize_slist (test_main_t * tm) { clib_slist_init (&tm->slist, tm->branching_factor, test_compare, test_format); } int test_slist_main (unformat_input_t * input) { test_main_t *tm = &test_main; u32 tmp; tm->seed = 0xbabeb00b; tm->iter = 100000; tm->verbose = 1; tm->branching_factor = 1.0 / 5.0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "seed %d", &tm->seed)) continue; else if (unformat (input, "iter %d", &tm->iter)) continue; else if (unformat (input, "verbose")) tm->verbose = 1; else if (unformat (input, "branch %d", &tmp)) { if (tmp > 0) tm->branching_factor = 1.0 / (f64) tmp; else fformat (stderr, "warning: branch = 0, ignored\n"); } else { clib_error ("unknown input `%U'", format_unformat_error, input); goto usage; } } initialize_slist (tm); run_test (tm); return 0; usage: fformat (stderr, "usage: test_slist seed <seed> iter <iter> [verbose]\n"); return 1; } #ifdef CLIB_UNIX int main (int argc, char *argv[]) { unformat_input_t i; int ret; clib_mem_init (0, (u64) 4 << 30); unformat_init_command_line (&i, argv); ret = test_slist_main (&i); unformat_free (&i); return ret; } #endif /* CLIB_UNIX */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */