123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #!/bin/bash
- . etc/config
- ### version for this script
- VERSION='1.0.1'
- LOGDATE=`date`
- ### return non-zero code if at least one test failed
- TESTS_FAILED=0
- ktestsctl_usage() {
- cat <<EOF
- $0 [options] cmd [params]
- Options:
- -m | --mysql ..... prepare mysql database
- -q | --quiet ..... execution of unit tests in silent mode
- -w | --wait ...... wait at the end of running the unit tests
- ...... (for docker it requires interactive mode: docker run -i ...)
- Commands:
- -- command 'run' --
- run .............. run all tests
- run <filter> ..... run tests with a filter on unit names
- run <unitname> ... run the test unit
- -- command 'help' --
- help ............. print the help text
- -- command 'version' --
- version .......... print the version string
- Version: $0 ${VERSION}
- EOF
- }
- ktestsctl_mysqld_alive() {
- mysqladmin -h localhost ping
- }
- # prepare mysql server
- ktestsctl_mysql() {
- echo "=== unit tests - prepare mysql server ==="
- if [ -f /etc/redhat-release ] ; then
- mysqld_safe &
- else
- /usr/sbin/mysqld --user=root &
- fi
- sleep 5
- count=0
- until ( ktestsctl_mysqld_alive )
- do
- ((count++))
- if [ ${count} -gt 50 ]
- then
- echo "error: mysqld did not become ready in time"
- exit 1
- fi
- sleep 0.1
- done
- sleep 1
- mysqladmin -u root password "${DBROOTPW}"
- INSTALL_EXTRA_TABLES=yes INSTALL_PRESENCE_TABLES=yes \
- INSTALL_DBUID_TABLES=yes CHARSET="latin1" kamdbctl create
- }
- # execute one or more test units
- ktestsrun() {
- echo "=== unit tests execution start ==="
- echo "running test units at: ${LOGDATE}" >${LOGFILE}
- echo "" >>${LOGFILE}
- if [ $# -lt 1 ] ; then
- UNITSLIST=`find units/t* -maxdepth 1 -type d`
- else
- UNITSLIST=`find units/${1}* -maxdepth 1 -type d`
- fi
- for tdir in ${UNITSLIST} ; do
- if [[ ${tdir} =~ $(echo ^units\/\($(paste -sd'|' excludeunits.txt)\)$) ]]; then
- echo
- echo "Skipping ${tdir} as requested..."
- continue
- fi
- if [[ -d "${tdir}" && ! -L "${tdir}" ]]; then
- tname=`basename ${tdir}`
- texec="${tname}.sh"
- tpath="${tdir}/${texec}"
- if [[ -f "${tpath}" && -x "${tpath}" ]]; then
- echo
- tsummary=""
- if [[ -f "${tdir}/README.md" ]]; then
- tsummary=`grep "^Summary: " ${tdir}/README.md | cut -c10-`
- fi
- if [[ ! -z "${tsummary}" ]]; then
- echo "* test unit ${tname}: ${tsummary}" | tee -a ${LOGFILE}
- fi
- echo "test unit ${tname}: running ..."
- cd ${tdir}
- if [ "${UNITOUTPUT}" == "no" ]; then
- # save stdout and stderr, then redirect to /dev/null
- exec 3>&1 4>&2 >/dev/null 2>&1
- fi
- ./${texec}
- ret=$?
- if [ "${UNITOUTPUT}" == "no" ]; then
- # restore stdout and stderr
- exec 1>&3 2>&4
- fi
- cd ../..
- if [ ! "$ret" -eq 0 ] ; then
- echo "- test unit ${tname}: failed" | tee -a ${LOGFILE}
- TESTS_FAILED=1
- else
- echo "- test unit ${tname}: ok" | tee -a ${LOGFILE}
- fi
- fi
- fi
- done
- sleep 1
- echo
- echo "=== unit tests execution report ==="
- echo
- cat ${LOGFILE}
- echo
- echo "=== unit tests execution end ==="
- echo
- }
- #
- ##### ================================================ #####
- ### evaluate first the options
- CMDPARAMS=()
- KTESTSWAIT="no"
- while [[ $# -gt 0 ]]
- do
- key="$1"
- case $key in
- -m|--mysql)
- ktestsctl_mysql
- shift
- ;;
- -q|--quiet)
- UNITOUTPUT="no"
- shift
- ;;
- -w|--wait)
- KTESTSWAIT="yes"
- shift
- ;;
- *)
- CMDPARAMS+=("$1")
- shift
- ;;
- esac
- done
- set -- "${CMDPARAMS[@]}" # restore positional parameters
- ### main command switch
- #
- echo
- if [ -n "${KAMRUN}" ] ; then
- mkdir -p ${KAMRUN}
- chmod a+w ${KAMRUN}
- fi
- case $1 in
- run)
- if [ $# -lt 2 ] ; then
- ktestsrun
- else
- ktestsrun "${2}"
- fi
- if [ "${KTESTSWAIT}" == "yes" ]; then
- echo
- echo "=== waiting ..."
- echo "=== this option requires to use 'docker run -i ...''"
- echo "=== to exit: press any key and <enter>"
- read -rs -n 1 key
- fi
- exit $TESTS_FAILED
- ;;
- help)
- ktestsctl_usage
- exit 1
- ;;
- version)
- echo "$0 $VERSION"
- ;;
- *)
- ktestsctl_usage
- exit 1
- ;;
- esac
|