From 2bfd6805e3028c67ce3b7b4670b33ca4df02f259 Mon Sep 17 00:00:00 2001 From: root Date: Jun 05 2011 12:43:11 +0000 Subject: Added Apache basic auth test from Athmane. Fixed a bug in runtests.sh - scripts weren't being executed in order Added a couple of tests for the sysstat package - iostat and mpstat. Added owner comments to all of my scripts. Added another point to the WritingTests page. --- diff --git a/WritingTests b/WritingTests index 5128084..e294b6c 100644 --- a/WritingTests +++ b/WritingTests @@ -1,20 +1,22 @@ -This file provides some basic guidance on things to bear in mind when writing test scripts for the QA process: +This file provides some basic guidance on things to consider when writing test scripts for the QA process: -(a) scripts should exit with either zero to signal success, or a non-zero value to signal failure. A failure exit code causes the entire test script execution process to stop (which is fine - we need to see what failed) +- scripts should exit with either zero to signal success, or a non-zero value to signal failure. A failure exit code causes the entire test script execution process to stop (which is fine - we need to see what failed) -(b) several helper functions are available in test/0_lib/*. Please use these in preference to directly calling any of the commands they implement. You don't have to source the file in your test scripts, just call/use the functions as required. The helper functions are there (for example) to promote consistency in debugging output and help avoid timing related test failures eg, daemons not being given sufficient time to start before testing for their existence. Please review the contents of 0_lib/ so you're familiar with what's on offer. +- you can use any language to write test scripts, but at present, the largest collection of helper functions are available to Bash/sh scripts. If the language you intend to use isn't available by default, the first thing you test script should do is yum install . -(c) if you're using Bash, the first thing you should ideally do is make a call to t_Log, passing in $0 and a description of what the test is doing, something like: +- several helper functions are available in test/0_lib/*. Please use these in preference to directly calling any of the commands they implement. You don't have to source the file in your test scripts, just call/use the functions as required. The helper functions are there (for example) to promote consistency in debugging output and help avoid timing related test failures eg, daemons not being given sufficient time to start before testing for their existence. Please review the contents of 0_lib/ so you're familiar with what's on offer. + +- if you're using Bash, the first thing you should ideally do is make a call to t_Log, passing in $0 and a description of what the test is doing, something like: t_Log "Running $0 - Postfix SMTP test." -(d) test scripts are processed in alphabetical order, so it's sensible to install any required packages in a 0-install-blah.sh script. +- test scripts are processed in alphabetical order, so it's sensible to install any required packages in a 0-install-blah.sh script. -(e) anything starting with a _ is ignored, and so are files named `readme` (case insensitive). If you need a file to store config values or any kind of metadata that's used in your test script, it probably makes sense to put it in a file starting with _ and then sourcing/including it in your test script. +- anything starting with a _ is ignored, and so are files named `readme` (case insensitive). If you need a file to store config values or any kind of metadata that's used in your test script, it probably makes sense to put it in a file starting with _ and then sourcing/including it in your test script. -(f) all test scripts should be chmod +x in order to be executed. Equally, removing execute permissions from a script will prevent it from being run (or prefixing it with an _, both approaches work) +- all test scripts should be chmod +x in order to be executed. Equally, removing execute permissions from a script will prevent it from being run (or prefixing it with an _, both approaches work) -(g) please include a suitable #Author comment line in your test scripts, so we know who to contact in the event of questions/changes/issues. +- please include a suitable #Author comment line in your test scripts, so we know who to contact in the event of questions/changes/issues. -(h) try and keep stdout/debugging messages generated by your test scripts to a minimum. +- try and keep stdout/debugging messages generated by your test scripts to a minimum. diff --git a/runtests.sh b/runtests.sh index 44a2591..9fa697e 100755 --- a/runtests.sh +++ b/runtests.sh @@ -22,9 +22,9 @@ set -e set -u # process our test scripts -t_Process <(/usr/bin/find ./tests/0_common/ -type f|sort) -t_Process <(/usr/bin/find ./tests/p_*/ -type f|sort) -t_Process <(/usr/bin/find ./tests/r_*/ -type f|sort) +t_Process <(/usr/bin/find ./tests/0_*/ -type f|sort -t'/' -k3,3 -k4,4n) +t_Process <(/usr/bin/find ./tests/p_*/ -type f|sort -t'/' -k3,3 -k4,4n) +t_Process <(/usr/bin/find ./tests/r_*/ -type f|sort -t'/' -k3,3 -k4,4n) # and, we're done. t_Log "Finished." diff --git a/tests/p_httpd/httpd_basic_auth.sh b/tests/p_httpd/httpd_basic_auth.sh new file mode 100755 index 0000000..873795d --- /dev/null +++ b/tests/p_httpd/httpd_basic_auth.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Author: Athmane Madjoudj + +t_Log "Running $0 - httpd basic authentication test." + +cat > /etc/httpd/conf.d/dir-test-basic-auth.conf < + AuthType Basic + AuthName "Test" + AuthUserFile /etc/httpd/htpasswd + require user test + +EOF + +htpasswd -c -b /etc/httpd/htpasswd test test +mkdir -p /var/www/html/basic_auth_test +echo "Basic authentication Test Page" > /var/www/html/basic_auth_test/index.html +t_ServiceControl httpd reload +curl -s -u test:test http://localhost/basic_auth_test/ | grep 'Basic authentication Test Page' > /dev/null 2>&1 + +t_CheckExitStatus $? diff --git a/tests/p_iptraf/0-install_iptraf.sh b/tests/p_iptraf/0-install_iptraf.sh index 3467feb..39a5b02 100755 --- a/tests/p_iptraf/0-install_iptraf.sh +++ b/tests/p_iptraf/0-install_iptraf.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) # IPTraf traffic monitoring package t_InstallPackage iptraf diff --git a/tests/p_iptraf/5-test_iptraf.sh b/tests/p_iptraf/5-test_iptraf.sh index b5b5e79..16fdadc 100755 --- a/tests/p_iptraf/5-test_iptraf.sh +++ b/tests/p_iptraf/5-test_iptraf.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) t_Log "Running $0 - checking iptraf runs and returns non-zero exit status." @@ -15,10 +16,10 @@ PING=`which ping` STAT=`which stat` KILL=`which kill` -[ -z "${IPTRAF}" ] && { t_log "Failed to find iptraf binary. That ain't good..."; exit $FAIL; } -[ -z "${PING}" ] && { t_Log "Failed to find the ping binary. That ain't good..."; exit $FAIL; } -[ -z "${STAT}" ] && { t_Log "Failed to find the stat binary. That ain't good..."; exit $FAIL; } -[ -z "${KILL}" ] && { t_Log "Failed to find the kill binary. That ain't good..."; exit $FAIL; } +[ "$IPTRAF" ] || { t_log "Failed to find iptraf binary. That ain't good..."; exit $FAIL; } +[ "$PING" ] || { t_Log "Failed to find the ping binary. That ain't good..."; exit $FAIL; } +[ "$STAT" ] || { t_Log "Failed to find the stat binary. That ain't good..."; exit $FAIL; } +[ "$KILL" ] || { t_Log "Failed to find the kill binary. That ain't good..."; exit $FAIL; } # start iptraf running in the background on all interfaces, logging to a file. ${IPTRAF} -i all -t 1 -B -L ${TMP} &>/dev/null diff --git a/tests/p_ntp/0-install_ntp.sh b/tests/p_ntp/0-install_ntp.sh index 2191475..4500806 100755 --- a/tests/p_ntp/0-install_ntp.sh +++ b/tests/p_ntp/0-install_ntp.sh @@ -1,5 +1,4 @@ #!/bin/bash - # Author: Steve Barnes (steve@echo.id.au) # NTPd diff --git a/tests/p_ntp/5-start-check.sh b/tests/p_ntp/5-start-check.sh index d0bff73..48090cd 100755 --- a/tests/p_ntp/5-start-check.sh +++ b/tests/p_ntp/5-start-check.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) # Start NTPd services and confirm it's running. chkconfig ntpd on @@ -6,8 +7,4 @@ t_ServiceControl ntpd start NTPD_PID=$(pidof ntpd) -[ -z "$NTPD_PID" ] && { t_Log "FAIL: couldn't find 'ntpd' in the process list."; exit $FAIL; } - -# this is here because otherwise the [ operator exit -# status would become the return value from the function -exit 0 +[ "$NTPD_PID" ] || { t_Log "FAIL: couldn't find 'ntpd' in the process list."; exit $FAIL; } diff --git a/tests/p_procinfo/0-install_procinfo.sh b/tests/p_procinfo/0-install_procinfo.sh index ae3f89a..c575130 100755 --- a/tests/p_procinfo/0-install_procinfo.sh +++ b/tests/p_procinfo/0-install_procinfo.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) # ProcInfo Utility Package t_InstallPackage procinfo diff --git a/tests/p_procinfo/5-test_procinfo.sh b/tests/p_procinfo/5-test_procinfo.sh index a0dc6ce..6339c57 100755 --- a/tests/p_procinfo/5-test_procinfo.sh +++ b/tests/p_procinfo/5-test_procinfo.sh @@ -1,11 +1,12 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) t_Log "Running $0 - checking procinfo runs and returns non-zero exit status." PROCINFO=`which procinfo` -[ -z "${PROCINFO}" ] && { t_log "Failed to find procinfo binary. Cannot continue."; exit $FAIL; } +[ "$PROCINFO" ] || { t_log "Failed to find procinfo binary. Cannot continue."; exit $FAIL; } -${PROCINFO} &>/dev/null +$PROCINFO &>/dev/null [ $? -eq 0 ] || { t_log "Procinfo exited with non-zero status. That ain't good..."; exit $FAIL; } diff --git a/tests/p_strace/0-install_strace.sh b/tests/p_strace/0-install_strace.sh index fa214cb..792b964 100755 --- a/tests/p_strace/0-install_strace.sh +++ b/tests/p_strace/0-install_strace.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) # Strace stack tracer package t_InstallPackage strace diff --git a/tests/p_strace/5-test_strace.sh b/tests/p_strace/5-test_strace.sh index c6da3cd..64ecaf9 100755 --- a/tests/p_strace/5-test_strace.sh +++ b/tests/p_strace/5-test_strace.sh @@ -1,11 +1,12 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) t_Log "Running $0 - checking strace runs and returns non-zero exit status." STRACE=`which strace` -[ -z "${STRACE}" ] && { t_log "Failed to find strace. Cannot continue."; exit $FAIL; } +[ "$STRACE" ] || { t_log "Failed to find strace. Cannot continue."; exit $FAIL; } -${STRACE} ls &>/dev/null +$STRACE ls &>/dev/null [ $? -eq 0 ] || { t_log "Strace exited with non-zero status. That ain't good..."; exit $FAIL; } diff --git a/tests/p_sysstat/0-install_sysstat.sh b/tests/p_sysstat/0-install_sysstat.sh index f03a7a3..918a269 100755 --- a/tests/p_sysstat/0-install_sysstat.sh +++ b/tests/p_sysstat/0-install_sysstat.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) # SysStat Performance Monitoring Tools for Linux t_InstallPackage sysstat diff --git a/tests/p_sysstat/10-iostat-disk-basic.sh b/tests/p_sysstat/10-iostat-disk-basic.sh new file mode 100755 index 0000000..b5903fd --- /dev/null +++ b/tests/p_sysstat/10-iostat-disk-basic.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) + +# A simple iostat test to verify transfers are being recorded + +t_Log "Running $0 - a basic iostat test to verify disk measurement" + +# Save our iostat output somewhere +TMP=/tmp/iostat.disk.scratch + +# dd options +BS=4196 +COUNT=10100 +SUM=$(expr $BS \* $COUNT / 1024) + +# Clean up after ourselves +trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT + +# Clear out the pagecache to get an accurate reading +echo 1 > /proc/sys/vm/drop_caches + +# Capture a storage device name +DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') + +# Run iostat on the device +/usr/bin/iostat -dkx 1 5 $DRIVE >$TMP & + +# Let the dust settle +sleep 1 + +# Generate some read traffic +/bin/dd if=$DRIVE of=/dev/null bs=$BS count=$COUNT &>/dev/null + +# Give iostat a chance to log our traffic +sleep 3 + +# Confirm our read bytes are >0, excluding the first +# line since that's the average since boot. +BYTES_READ=$(awk '$6 ~ /[0-9]/ {NR>1 && sum+=$6} END {print int(sum)}' $TMP) + +# Check we read at least as much as requested +[ "$BYTES_READ" -ge "$SUM" ] || { t_Log "iostat didn't log as much traffic as we generated?!...that ain't good"; exit $FAIL; } + +t_CheckExitStatus $? diff --git a/tests/p_sysstat/15-mpstat-basic.sh b/tests/p_sysstat/15-mpstat-basic.sh new file mode 100755 index 0000000..d7f5a56 --- /dev/null +++ b/tests/p_sysstat/15-mpstat-basic.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) + +# A simple mpstat test to verify cpu load is being measured + +t_Log "Running $0 - a simple mpstat test to verify cpu load is being measured" + +# Save our iostat output somewhere +TMP=/tmp/mpstat.scratch + +# Clean up after ourselves +trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT + +# Run iostat on the first CPU +/usr/bin/mpstat -P 0 1 5 >$TMP & + +# Let the dust settle +sleep 1 + +# Give the CPU something to chew on +/bin/dd if=/dev/urandom bs=1k count=10000 2>/dev/null|sha1sum -b - &>/dev/null + +# Give mpstat a chance to log our task +sleep 3 + +# Confirm our read bytes are >0, excluding the first +# line since that's the average since boot. +CPU_SYS_PCENT=$(awk '$6 ~ /[0-9]\./ {$6>a ? a=$6 : $6} END {print int(a)}' $TMP) + +# Check mpstat registered some level of cpu activity +[ "$CPU_SYS_PCENT" -gt 5 ] || { t_Log "mpstat didn't log any CPU activity?!...that ain't good"; exit $FAIL; } + +t_CheckExitStatus $? diff --git a/tests/p_sysstat/5-iostat-cpu-basic.sh b/tests/p_sysstat/5-iostat-cpu-basic.sh new file mode 100755 index 0000000..997fc8f --- /dev/null +++ b/tests/p_sysstat/5-iostat-cpu-basic.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) + +# A simple iostat test to verify cpu loads are being recorded + +t_Log "Running $0 - a basic iostat test to verify cpu measurement" + +# Save our iostat output somewhere +TMP=/tmp/iostat.cpu.scratch + +# Clear out the pagecache to get an accurate reading +echo 1 > /proc/sys/vm/drop_caches + +# Clean up after ourselves +trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT + +# Capture a storage device name +DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') + +# Run iostat on the cpu +/usr/bin/iostat -c 1 5 >$TMP & + +# Let the dust settle +sleep 1 + +# Give the CPU something to chew on +/bin/dd if=$DRIVE bs=4k count=25000 2>/dev/null|sha1sum -b - &>/dev/null + +# Give iostat a chance to log our task +sleep 3 + +# Extract the CPU utilisation (user field, percentage) +CPU_USER_PCENT=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' $TMP) + +# Confirm the CPU registered some level of user activity +[ "$CPU_USER_PCENT" -gt 3 ] || { t_Log "iostat didn't log any CPU activity?!...that ain't good"; exit $FAIL; } + +t_CheckExitStatus $?