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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
2.6 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2017-03-27 12:39:29 +02:00
#
# Run integration tests
#
2022-03-15 09:18:01 -04:00
# Author: Steffen Vogel <post@steffenvogel.de>
2022-03-15 09:28:57 -04:00
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
2022-07-04 18:20:03 +02:00
# SPDX-License-Identifier: Apache-2.0
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
2021-09-22 13:04:54 +02:00
PATH=${BUILDDIR}/src:${SRCDIR}/tools:${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}
FAIL_FAST=${FAIL_FAST:-0}
2017-07-14 16:30:49 +02:00
FILTER=${FILTER:-'*'}
NUM_SAMPLES=${NUM_SAMPLES:-100}
TIMEOUT=${TIMEOUT:-1m}
2017-03-27 12:39:29 +02:00
# Parse command line arguments
while getopts ":f:l:t:vg" 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}
;;
g)
FAIL_FAST=1
;;
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
2021-09-21 16:13:03 +02:00
START=$(date +%s.%N)
2019-06-26 20:37:47 +02:00
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
2021-09-21 16:13:03 +02:00
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
# 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)
2021-09-21 16:13:03 +02:00
echo -e "\e[32m[PASS] \e[39m ${TESTNAME} (ran for ${DIFF}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))
;;
*)
2021-09-21 16:13:03 +02:00
echo -e "\e[31m[FAIL] \e[39m ${TESTNAME} (exited with code $RC, ran for ${DIFF}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))
if (( ${RC} != 0 && ${RC} != 99 && ${FAIL_FAST} > 0 )); then
break
fi
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