Milosz Wasilewski | 16e827c | 2016-11-03 23:51:53 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | . ../../lib/sh-test-lib |
| 4 | OUTPUT="$(pwd)/output" |
| 5 | RESULT_FILE="${OUTPUT}/result.txt" |
| 6 | LOGFILE="${OUTPUT}/ablog.txt" |
| 7 | |
| 8 | usage() { |
| 9 | echo "Usage: $0 [-s <true|false>]" 1>&2 |
| 10 | exit 1 |
| 11 | } |
| 12 | |
| 13 | NUMBER=1000 |
| 14 | CONCURENT=100 |
| 15 | |
| 16 | while 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 |
| 23 | done |
| 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)" |
| 27 | mkdir -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. |
| 32 | if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then |
| 33 | warn_msg "Apache package installation skipped" |
| 34 | else |
| 35 | dist_name |
| 36 | # shellcheck disable=SC2154 |
| 37 | case "${dist}" in |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame^] | 38 | debian|ubuntu) |
Milosz Wasilewski | 16e827c | 2016-11-03 23:51:53 +0000 | [diff] [blame] | 39 | pkgs="apache2 apache2-utils" |
| 40 | install_deps "${pkgs}" |
| 41 | systemctl restart apache2 |
| 42 | ;; |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame^] | 43 | centos|fedora) |
Milosz Wasilewski | 16e827c | 2016-11-03 23:51:53 +0000 | [diff] [blame] | 44 | pkgs="httpd httpd-tools" |
| 45 | install_deps "${pkgs}" |
| 46 | systemctl start httpd.service |
| 47 | ;; |
| 48 | *) |
| 49 | error_msg "Unsupported distribution!" |
| 50 | esac |
| 51 | fi |
| 52 | |
| 53 | cp ./html/* /var/www/html/ |
| 54 | |
| 55 | # Test Apachebench on Apache. |
| 56 | ab -n "${NUMBER}" -c "${CONCURENT}" "http://localhost/index.html" | tee "${LOGFILE}" |
| 57 | # shellcheck disable=SC2129 |
| 58 | grep "Time taken for tests:" "${LOGFILE}" | awk '{print "Time-taken-for-tests pass " $5 " s"}' >> "${RESULT_FILE}" |
| 59 | # shellcheck disable=SC2129 |
| 60 | grep "Complete requests:" "${LOGFILE}" | awk '{print "Complete-requests pass " $3 " items"}' >> "${RESULT_FILE}" |
| 61 | # shellcheck disable=SC2129 |
| 62 | grep "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 |
| 64 | grep "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 |
| 66 | grep "Total transferred:" "${LOGFILE}" | awk '{print "Total-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}" |
| 67 | # shellcheck disable=SC2129 |
| 68 | grep "HTML transferred:" "${LOGFILE}" | awk '{print "HTML-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}" |
| 69 | # shellcheck disable=SC2129 |
| 70 | grep "Requests per second:" "${LOGFILE}" | awk '{print "Requests-per-second pass " $4 " #/s"}' >> "${RESULT_FILE}" |
| 71 | # shellcheck disable=SC2129 |
| 72 | grep "Time per request:" "${LOGFILE}" | grep -v "across" | awk '{print "Time-per-request-mean pass " $4 " ms"}' >> "${RESULT_FILE}" |
| 73 | # shellcheck disable=SC2129 |
| 74 | grep "Time per request:" "${LOGFILE}" | grep "across" | awk '{print "Time-per-request-concurent pass " $4 " ms"}' >> "${RESULT_FILE}" |
| 75 | # shellcheck disable=SC2129 |
| 76 | grep "Transfer rate:" "${LOGFILE}" | awk '{print "Transfer-rate pass " $3 " kb/s"}' >> "${RESULT_FILE}" |