1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tools/integration-tests.sh

140 lines
3.1 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2017-03-27 12:39:29 +02:00
#
# Run integration tests
#
# @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
# @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 13:08:17 +02:00
# @license GNU General Public License (version 3)
#
# VILLASnode
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
2017-04-27 13:08:17 +02:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
2017-04-27 13:08:17 +02:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-03-27 12:39:29 +02:00
##################################################################################
SCRIPT=$(realpath ${BASH_SOURCE[0]})
SCRIPTPATH=$(dirname $SCRIPT)
SRCDIR=${SRCDIR:-$(realpath ${SCRIPTPATH}/..)}
2018-06-25 09:44:58 +02:00
BUILDDIR=${BUILDDIR:-${SRCDIR}/build}
LOGDIR=${BUILDDIR}/tests/integration
2018-06-25 09:44:58 +02:00
PATH=${BUILDDIR}/src:${PATH}
export PATH SRCDIR BUILDDIR LOGDIR
2017-03-27 12:39:29 +02:00
# Default values
2017-07-14 16:30:49 +02:00
VERBOSE=${VERBOSE:-0}
FILTER=${FILTER:-'*'}
NUM_SAMPLES=${NUM_SAMPLES:-100}
2019-06-27 21:47:46 +02:00
TIMEOUT=${TIMEOUT:-2m}
2017-03-27 12:39:29 +02:00
# Parse command line arguments
while getopts ":f:l:t:v" OPT; do
2017-03-27 12:39:29 +02:00
case ${OPT} in
f)
FILTER=${OPTARG}
;;
v)
VERBOSE=1
;;
l)
NUM_SAMPLES=${OPTARG}
;;
t)
TIMEOUT=${OPTARG}
;;
2017-03-27 12:39:29 +02:00
\?)
echo "Invalid option: -${OPTARG}" >&2
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
export VERBOSE
export NUM_SAMPLES
2017-03-27 12:39:29 +02:00
TESTS=${SRCDIR}/tests/integration/${FILTER}.sh
# Preperations
mkdir -p ${LOGDIR}
2017-07-02 00:14:42 +02:00
PASSED=0
FAILED=0
SKIPPED=0
TIMEDOUT=0
2017-03-27 12:39:29 +02:00
# Preamble
echo -e "Starting integration tests for VILLASnode:\n"
2017-03-27 12:39:29 +02:00
for TEST in ${TESTS}; do
TESTNAME=$(basename -s .sh ${TEST})
2019-06-26 20:37:47 +02:00
# Start time measurement
SECONDS=0
2017-03-27 12:39:29 +02:00
# Run test
if (( ${VERBOSE} == 0 )); then
timeout ${TIMEOUT} ${TEST} &> ${LOGDIR}/${TESTNAME}.log
RC=$?
2017-03-27 12:39:29 +02:00
else
timeout ${TIMEOUT} ${TEST} | tee ${LOGDIR}/${TESTNAME}.log
RC=${PIPESTATUS[0]}
fi
2019-06-26 20:37:47 +02:00
TOTAL_SECONDS=${SECONDS}
# Show full log in case of an error
if (( ${VERBOSE} == 0 )); then
2017-09-03 10:55:04 +02:00
if (( $RC != 99 )) && (( $RC != 0 )); then
cat ${LOGDIR}/${TESTNAME}.log
fi
2017-03-27 12:39:29 +02:00
fi
case $RC in
0)
2019-06-27 21:47:46 +02:00
echo -e "\e[32m[PASS] \e[39m ${TESTNAME} (ran for ${SECONDS}s)"
2017-07-02 00:14:42 +02:00
PASSED=$((${PASSED} + 1))
;;
99)
echo -e "\e[93m[SKIP] \e[39m ${TESTNAME}: $(head -n1 ${LOGDIR}/${TESTNAME}.log)"
2017-07-02 00:14:42 +02:00
SKIPPED=$((${SKIPPED} + 1))
;;
124)
2019-06-27 21:47:46 +02:00
echo -e "\e[33m[TIME] \e[39m ${TESTNAME} (ran for more then ${TIMEOUT})"
2017-07-02 00:14:42 +02:00
TIMEDOUT=$((${TIMEDOUT} + 1))
FAILED=$((${FAILED} + 1))
;;
*)
2019-06-27 21:47:46 +02:00
echo -e "\e[31m[FAIL] \e[39m ${TESTNAME} (exited with code $RC, ran for ${SECONDS}s)"
2017-07-02 00:14:42 +02:00
FAILED=$((${FAILED} + 1))
;;
esac
2017-07-14 16:30:49 +02:00
2017-07-02 00:14:42 +02:00
TOTAL=$((${TOTAL} + 1))
2017-03-27 12:39:29 +02:00
done
# Show summary
2017-07-02 00:14:42 +02:00
if (( ${FAILED} > 0 )); then
echo -e "\nSummary: ${FAILED} of ${TOTAL} tests failed."
echo -e " Timedout: ${TIMEDOUT}"
echo -e " Skipped: ${SKIPPED}"
2017-03-27 12:39:29 +02:00
exit 1
else
echo -e "\nSummary: all tests passed!"
exit 0
2017-07-14 16:30:49 +02:00
fi