blob: 22d66a10e4b412bf4eb319dc202407e3bebed590 [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"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -060026create_out_dir "${OUTPUT}"
Milosz Wasilewski16e827c2016-11-03 23:51:53 +000027
28# Install apache and use systemctl for service management. Tested on Ubuntu 16.04,
29# Debian 8, CentOS 7 and Fedora 24. systemctl should available on newer releases
30# as well.
31if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
32 warn_msg "Apache package installation skipped"
33else
34 dist_name
35 # shellcheck disable=SC2154
36 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010037 debian|ubuntu)
Milosz Wasilewski16e827c2016-11-03 23:51:53 +000038 pkgs="apache2 apache2-utils"
39 install_deps "${pkgs}"
40 systemctl restart apache2
41 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010042 centos|fedora)
Milosz Wasilewski16e827c2016-11-03 23:51:53 +000043 pkgs="httpd httpd-tools"
44 install_deps "${pkgs}"
45 systemctl start httpd.service
46 ;;
47 *)
48 error_msg "Unsupported distribution!"
49 esac
50fi
51
52cp ./html/* /var/www/html/
53
54# Test Apachebench on Apache.
55ab -n "${NUMBER}" -c "${CONCURENT}" "http://localhost/index.html" | tee "${LOGFILE}"
56# shellcheck disable=SC2129
57grep "Time taken for tests:" "${LOGFILE}" | awk '{print "Time-taken-for-tests pass " $5 " s"}' >> "${RESULT_FILE}"
58# shellcheck disable=SC2129
59grep "Complete requests:" "${LOGFILE}" | awk '{print "Complete-requests pass " $3 " items"}' >> "${RESULT_FILE}"
60# shellcheck disable=SC2129
61grep "Failed requests:" "${LOGFILE}" | awk '{ORS=""} {print "Failed-requests "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}"
62# shellcheck disable=SC2129
63grep "Write errors:" "${LOGFILE}" | awk '{ORS=""} {print "Write-errors "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}"
64# shellcheck disable=SC2129
65grep "Total transferred:" "${LOGFILE}" | awk '{print "Total-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}"
66# shellcheck disable=SC2129
67grep "HTML transferred:" "${LOGFILE}" | awk '{print "HTML-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}"
68# shellcheck disable=SC2129
69grep "Requests per second:" "${LOGFILE}" | awk '{print "Requests-per-second pass " $4 " #/s"}' >> "${RESULT_FILE}"
70# shellcheck disable=SC2129
71grep "Time per request:" "${LOGFILE}" | grep -v "across" | awk '{print "Time-per-request-mean pass " $4 " ms"}' >> "${RESULT_FILE}"
72# shellcheck disable=SC2129
73grep "Time per request:" "${LOGFILE}" | grep "across" | awk '{print "Time-per-request-concurent pass " $4 " ms"}' >> "${RESULT_FILE}"
74# shellcheck disable=SC2129
75grep "Transfer rate:" "${LOGFILE}" | awk '{print "Transfer-rate pass " $3 " kb/s"}' >> "${RESULT_FILE}"