blob: 21bbc66623dcca6413d00e73215985bdee4cfafa [file] [log] [blame]
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +02001#!/bin/bash
2set -o errexit
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +01003set -x
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +02004
5THIS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
6TEST_DEFS_DIR=$(readlink -f "${THIS_DIR}/../../..")
7GET_VLAND_IFACE=${TEST_DEFS_DIR}/automated/utils/vland/get_vland_interface.sh
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +02008
9# vlnad name to use
10VLAND_NAME=${VLAND_NAME:-vlan_one}
11VLAND_IFACE=$($GET_VLAND_IFACE "$VLAND_NAME")
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020012
13# Do not run tests on more than MAX_CORES cores
14# 0 means use all cores
15MAX_CORES=${MAX_CORES:-0}
16
17# IP address of the server
18SERVER_IP=${SERVER_IP:-192.168.1.4}
19
20# What kind of configuration to use:
21# linux-ip: plain Linux IP stack
22# odp-dpdk: NGiNX with OFP+ODP+DPDK
23CONFIG_TYPE=${CONFIG_TYPE:-linux-ip}
24
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020025function configure_ramdisk {
26 local ROOT=/www
27 mkdir "$ROOT"
28 mount -t tmpfs -o size=1M tmpfs "$ROOT"
29 echo "-- Ramdisk created: "
30 df -h "$ROOT"
31 echo "-- END"
32 lava-test-case server_www_ramdisk --result pass
33
34 cat > "$ROOT/index.html" <<-EOF
35 <html>
36 <head><title>NGiNX test</title></head>
37 <body>
38 IT WORKS
39 </body>
40 </html>
41 EOF
42}
43
44function write_config {
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +010045 local cores=${1}
46 local config_file=${2:-/etc/nginx/nginx.conf}
47
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020048 # Simple configuration file for NGiNX
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +010049 cat > "$config_file" <<-EOF
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020050 user www-data;
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +010051 worker_processes $cores;
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020052 timer_resolution 1s;
53 worker_rlimit_nofile 4096;
54 error_log /dev/null crit;
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020055 ${WRITE_CONFIG_CORE}
56
57 events {
58 worker_connections 1024;
59 ${WRITE_CONFIG_EVENTS}
60 }
61
62 http {
63 access_log off;
64 sendfile on;
65 tcp_nopush on;
66 tcp_nodelay on;
67 keepalive_timeout 0;
68 open_file_cache max=10;
69 server {
70 # TODO: investigate backlog value
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +010071 ${WRITE_CONFIG_LISTEN:-listen 80 default_server;}
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020072 location / {
73 root /www;
74 }
75 }
76 }
77 EOF
78 echo "-- CONFIG FOR $1:"
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +010079 cat "$config_file"
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020080 echo "-- END --"
81}
82
83function get_num_real_cores {
84 local cores_socket
85 local num_sockets
86 local num_cores
87
88 cores_socket=$(lscpu | awk -F : '/^Core\(s\) per/ {print $2;}')
89 num_sockets=$(lscpu | awk -F : '/^Socket\(s\)/ {print $2;}')
90 num_cores=$((cores_socket * num_sockets))
91
92 if [ "${MAX_CORES}" -ne 0 ] && [ "${num_cores}" -gt "${MAX_CORES}" ]; then
93 num_cores=$MAX_CORES
94 fi
95 echo "$num_cores"
96}
97
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +010098test_functions="${THIS_DIR}/${CONFIG_TYPE}.sh"
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +020099
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100100if [ ! -f "$test_functions" ]; then
101 echo "Invalid CONFIG_TYPE: $CONFIG_TYPE"
102 exit 1
103fi
104
105echo "-- Sourcing $test_functions" >&2
106
107# shellcheck disable=SC1090
108. "$test_functions"
109
110do_configure_system "$(get_num_real_cores)" "$VLAND_IFACE" "$SERVER_IP"
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200111
112NUM_CORES=$(get_num_real_cores)
113echo ">> SEND num_cores cores=$NUM_CORES"
114lava-send num_cores cores="$NUM_CORES"
115
116echo "<< WAIT client_ready"
117lava-wait client_ready
118
119for num_cores in 1 $(seq 2 2 "$NUM_CORES"); do
120 echo "-- BEGIN $num_cores"
121 echo "-- Stopping NGiNX"
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100122 do_stop_nginx
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200123 echo "-- Writing configuration file for $num_cores"
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100124 do_write_nginx_config "$num_cores" "$VLAND_IFACE" "$SERVER_IP"
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200125 echo "-- CALLING PRE-TEST CALLBACK $PRE_TEST_CB"
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100126 do_pre_test_cb "$num_cores" "$VLAND_IFACE" "$SERVER_IP"
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200127 echo "-- STARTING NGiNX for test $num_cores"
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100128 do_start_nginx
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200129 echo ">> SEND server_num_cores_${num_cores}_ready"
130 lava-send "server_num_cores_${num_cores}_ready"
131 echo "<< WAIT client_num_cores_${num_cores}_done"
132 lava-wait "client_num_cores_${num_cores}_done"
133 echo "-- CALLING POST-TEST CALLBACK $POST_TEST_CB"
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100134 do_post_test_cb "$num_cores" "$VLAND_IFACE" "$SERVER_IP"
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200135 echo "-- END $num_cores"
136done
137
Josep Puigdemont6cdfbb52017-03-17 10:01:49 +0100138do_stop_nginx
139
Josep Puigdemont88cf9ea2016-10-20 14:39:29 +0200140echo "<< WAIT client_done"
141lava-wait client_done
142echo "A10"