Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -o errexit |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 3 | set -x |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 4 | |
| 5 | THIS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" |
| 6 | TEST_DEFS_DIR=$(readlink -f "${THIS_DIR}/../../..") |
| 7 | GET_VLAND_IFACE=${TEST_DEFS_DIR}/automated/utils/vland/get_vland_interface.sh |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 8 | |
| 9 | # vlnad name to use |
| 10 | VLAND_NAME=${VLAND_NAME:-vlan_one} |
| 11 | VLAND_IFACE=$($GET_VLAND_IFACE "$VLAND_NAME") |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 12 | |
| 13 | # Do not run tests on more than MAX_CORES cores |
| 14 | # 0 means use all cores |
| 15 | MAX_CORES=${MAX_CORES:-0} |
| 16 | |
| 17 | # IP address of the server |
| 18 | SERVER_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 |
| 23 | CONFIG_TYPE=${CONFIG_TYPE:-linux-ip} |
| 24 | |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 25 | function 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 | |
| 44 | function write_config { |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 45 | local cores=${1} |
| 46 | local config_file=${2:-/etc/nginx/nginx.conf} |
| 47 | |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 48 | # Simple configuration file for NGiNX |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 49 | cat > "$config_file" <<-EOF |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 50 | user www-data; |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 51 | worker_processes $cores; |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 52 | timer_resolution 1s; |
| 53 | worker_rlimit_nofile 4096; |
| 54 | error_log /dev/null crit; |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 55 | ${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 Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 71 | ${WRITE_CONFIG_LISTEN:-listen 80 default_server;} |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 72 | location / { |
| 73 | root /www; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | EOF |
| 78 | echo "-- CONFIG FOR $1:" |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 79 | cat "$config_file" |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 80 | echo "-- END --" |
| 81 | } |
| 82 | |
| 83 | function 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 Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 98 | test_functions="${THIS_DIR}/${CONFIG_TYPE}.sh" |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 99 | |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 100 | if [ ! -f "$test_functions" ]; then |
| 101 | echo "Invalid CONFIG_TYPE: $CONFIG_TYPE" |
| 102 | exit 1 |
| 103 | fi |
| 104 | |
| 105 | echo "-- Sourcing $test_functions" >&2 |
| 106 | |
| 107 | # shellcheck disable=SC1090 |
| 108 | . "$test_functions" |
| 109 | |
| 110 | do_configure_system "$(get_num_real_cores)" "$VLAND_IFACE" "$SERVER_IP" |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 111 | |
| 112 | NUM_CORES=$(get_num_real_cores) |
| 113 | echo ">> SEND num_cores cores=$NUM_CORES" |
| 114 | lava-send num_cores cores="$NUM_CORES" |
| 115 | |
| 116 | echo "<< WAIT client_ready" |
| 117 | lava-wait client_ready |
| 118 | |
| 119 | for num_cores in 1 $(seq 2 2 "$NUM_CORES"); do |
| 120 | echo "-- BEGIN $num_cores" |
| 121 | echo "-- Stopping NGiNX" |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 122 | do_stop_nginx |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 123 | echo "-- Writing configuration file for $num_cores" |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 124 | do_write_nginx_config "$num_cores" "$VLAND_IFACE" "$SERVER_IP" |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 125 | echo "-- CALLING PRE-TEST CALLBACK $PRE_TEST_CB" |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 126 | do_pre_test_cb "$num_cores" "$VLAND_IFACE" "$SERVER_IP" |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 127 | echo "-- STARTING NGiNX for test $num_cores" |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 128 | do_start_nginx |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 129 | 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 Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 134 | do_post_test_cb "$num_cores" "$VLAND_IFACE" "$SERVER_IP" |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 135 | echo "-- END $num_cores" |
| 136 | done |
| 137 | |
Josep Puigdemont | 6cdfbb5 | 2017-03-17 10:01:49 +0100 | [diff] [blame] | 138 | do_stop_nginx |
| 139 | |
Josep Puigdemont | 88cf9ea | 2016-10-20 14:39:29 +0200 | [diff] [blame] | 140 | echo "<< WAIT client_done" |
| 141 | lava-wait client_done |
| 142 | echo "A10" |