blob: 2395efc9d0bbafba54650d7eb3b31c834ace2d86 [file] [log] [blame]
Milosz Wasilewski16e827c2016-11-03 23:51:53 +00001#!/bin/sh
2
3. ../../lib/sh-test-lib
4OUTPUT="$(pwd)/output"
5RESULT_FILE="${OUTPUT}/result.txt"
6LOGFILE="${OUTPUT}/ablog.txt"
7
8usage() {
9 echo "Usage: $0 [-s <true|false>]" 1>&2
10 exit 1
11}
12
13NUMBER=1000
14CONCURENT=100
15
16while getopts "s:n:c:" o; do
17 case "$o" in
18 n) NUMBER="${OPTARG}" ;;
19 c) CONCURENT="${OPTARG}" ;;
20 s) SKIP_INSTALL="${OPTARG}" ;;
21 *) usage ;;
22 esac
23done
24
25! check_root && error_msg "This script must be run as root"
26[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
27mkdir -p "${OUTPUT}"
28
29# Install apache and use systemctl for service management. Tested on Ubuntu 16.04,
30# Debian 8, CentOS 7 and Fedora 24. systemctl should available on newer releases
31# as well.
32if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
33 warn_msg "Apache package installation skipped"
34else
35 dist_name
36 # shellcheck disable=SC2154
37 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010038 debian|ubuntu)
Milosz Wasilewski16e827c2016-11-03 23:51:53 +000039 pkgs="apache2 apache2-utils"
40 install_deps "${pkgs}"
41 systemctl restart apache2
42 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010043 centos|fedora)
Milosz Wasilewski16e827c2016-11-03 23:51:53 +000044 pkgs="httpd httpd-tools"
45 install_deps "${pkgs}"
46 systemctl start httpd.service
47 ;;
48 *)
49 error_msg "Unsupported distribution!"
50 esac
51fi
52
53cp ./html/* /var/www/html/
54
55# Test Apachebench on Apache.
56ab -n "${NUMBER}" -c "${CONCURENT}" "http://localhost/index.html" | tee "${LOGFILE}"
57# shellcheck disable=SC2129
58grep "Time taken for tests:" "${LOGFILE}" | awk '{print "Time-taken-for-tests pass " $5 " s"}' >> "${RESULT_FILE}"
59# shellcheck disable=SC2129
60grep "Complete requests:" "${LOGFILE}" | awk '{print "Complete-requests pass " $3 " items"}' >> "${RESULT_FILE}"
61# shellcheck disable=SC2129
62grep "Failed requests:" "${LOGFILE}" | awk '{ORS=""} {print "Failed-requests "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}"
63# shellcheck disable=SC2129
64grep "Write errors:" "${LOGFILE}" | awk '{ORS=""} {print "Write-errors "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}"
65# shellcheck disable=SC2129
66grep "Total transferred:" "${LOGFILE}" | awk '{print "Total-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}"
67# shellcheck disable=SC2129
68grep "HTML transferred:" "${LOGFILE}" | awk '{print "HTML-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}"
69# shellcheck disable=SC2129
70grep "Requests per second:" "${LOGFILE}" | awk '{print "Requests-per-second pass " $4 " #/s"}' >> "${RESULT_FILE}"
71# shellcheck disable=SC2129
72grep "Time per request:" "${LOGFILE}" | grep -v "across" | awk '{print "Time-per-request-mean pass " $4 " ms"}' >> "${RESULT_FILE}"
73# shellcheck disable=SC2129
74grep "Time per request:" "${LOGFILE}" | grep "across" | awk '{print "Time-per-request-concurent pass " $4 " ms"}' >> "${RESULT_FILE}"
75# shellcheck disable=SC2129
76grep "Transfer rate:" "${LOGFILE}" | awk '{print "Transfer-rate pass " $3 " kb/s"}' >> "${RESULT_FILE}"