From eb4cb081f1e9f141f703454ece963add5dbebf74 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 27 Mar 2017 12:39:29 +0200 Subject: [PATCH] added integration tests --- tests/Makefile.inc | 7 ++- tests/integration-tests.sh | 81 +++++++++++++++++++++++++++ tests/integration.sh | 35 ------------ tests/integration/api-config.sh | 26 +++++++++ tests/integration/hook-convert.sh | 42 ++++++++++++++ tests/integration/hook-decimate.sh | 36 ++++++++++++ tests/integration/hook-drop.sh | 42 ++++++++++++++ tests/integration/hook-map.sh | 42 ++++++++++++++ tests/integration/hook-shift_seq.sh | 18 ++++++ tests/integration/hook-shift_ts.sh | 18 ++++++ tests/integration/hook-skip_first.sh | 16 ++++++ tests/integration/hook-skip_first2.sh | 14 +++++ tools/tests.sh | 72 ------------------------ 13 files changed, 340 insertions(+), 109 deletions(-) create mode 100755 tests/integration-tests.sh delete mode 100755 tests/integration.sh create mode 100755 tests/integration/api-config.sh create mode 100755 tests/integration/hook-convert.sh create mode 100755 tests/integration/hook-decimate.sh create mode 100755 tests/integration/hook-drop.sh create mode 100755 tests/integration/hook-map.sh create mode 100755 tests/integration/hook-shift_seq.sh create mode 100755 tests/integration/hook-shift_ts.sh create mode 100755 tests/integration/hook-skip_first.sh create mode 100755 tests/integration/hook-skip_first2.sh delete mode 100755 tools/tests.sh diff --git a/tests/Makefile.inc b/tests/Makefile.inc index c6a5df1e0..dad98fc1d 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -2,6 +2,9 @@ tests: unit-tests -run-tests: run-unit-tests +run-tests: run-unit-tests run-integration-tests + +run-integration-tests: src tools + @$(SRCDIR)/tests/integration-tests.sh -.PHONY: tests run-tests +.PHONY: tests run-tests run-integration-tests diff --git a/tests/integration-tests.sh b/tests/integration-tests.sh new file mode 100755 index 000000000..c91e15f54 --- /dev/null +++ b/tests/integration-tests.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# +# Run integration tests +# +# @author Steffen Vogel +# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +################################################################################## + +SCRIPT=$(realpath ${BASH_SOURCE[0]}) +SCRIPTPATH=$(dirname $SCRIPT) + +export SRCDIR=$(realpath ${SCRIPTPATH}/..) +export BUILDDIR=${SRCDIR}/build/release +export LOGDIR=${BUILDDIR}/tests/integration +export PATH=${BUILDDIR}:${PATH} + +# Default values +VERBOSE=0 +FILTER='*' + +export NUM_SAMPLES=100 + +# Parse command line arguments +while getopts ":f:v" OPT; do + case ${OPT} in + f) + FILTER=${OPTARG} + ;; + v) + VERBOSE=1 + ;; + \?) + echo "Invalid option: -${OPTARG}" >&2 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +TESTS=${SRCDIR}/tests/integration/${FILTER}.sh + +# Preperations +mkdir -p ${LOGDIR} + +NUM_PASS=0 +NUM_FAIL=0 + +# Preamble +echo -e "Starting integration tests for VILLASnode/fpga:\n" + +for TEST in ${TESTS}; do + TESTNAME=$(basename -s .sh ${TEST}) + + # Run test + if (( ${VERBOSE} == 0 )); then + ${TEST} &> ${LOGDIR}/${TESTNAME}.log + else + ${TEST} + fi + + RC=$? + + if (( $RC != 0 )); then + echo -e "\e[31m[Fail] \e[39m ${TESTNAME} with code $RC" + NUM_FAIL=$((${NUM_FAIL} + 1)) + else + echo -e "\e[32m[Pass] \e[39m ${TESTNAME}" + NUM_PASS=$((${NUM_PASS} + 1)) + fi +done + +# Show summary +if (( ${NUM_FAIL} > 0 )); then + echo -e "\nSummary: ${NUM_FAIL} of $((${NUM_FAIL} + ${NUM_PASS})) tests failed." + exit 1 +else + echo -e "\nSummary: all tests passed!" + exit 0 +fi \ No newline at end of file diff --git a/tests/integration.sh b/tests/integration.sh deleted file mode 100755 index bc51ea8d0..000000000 --- a/tests/integration.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -SCRIPT=$(realpath ${BASH_SOURCE[0]}) -SCRIPTPATH=$(dirname $SCRIPT) - -TOPDIR=$(realpath ${SCRIPTPATH}/..) -BUILDDIR=${TOPDIR}/build/release -PATH=${BUILDDIR}:${PATH} - -CONFIGFILE=$(mktemp) -DATAFILE_ORIG=$(mktemp) -DATAFILE_LOOP=$(mktemp) - -cat > ${CONFIGFILE} <<- EOM -nodes = { - node1 = { - type = "socket"; - layer = "udp"; - - local = "*:12000"; - remote = "localhost:12000" - } -} -EOM - -# Generate test data -villas-signal random -l 10 -r 100 > ${DATAFILE_ORIG} - -villas-pipe ${CONFIGFILE} node1 < ${DATAFILE_ORIG} > ${DATAFILE_LOOP} - -diff -u ${DATAFILE_ORIG} ${DATAFILE_LOOP} - -rm ${DATAFILE_ORIG} -rm ${DATAFILE_LOOP} -rm ${CONFIGFILE} \ No newline at end of file diff --git a/tests/integration/api-config.sh b/tests/integration/api-config.sh new file mode 100755 index 000000000..72fd5d0dd --- /dev/null +++ b/tests/integration/api-config.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +LOCAL_CONF=${SRCDIR}/etc/loopback.conf +FETCHED_CONF=$(mktemp) + +echo ${CONF} + +# Start VILLASnode instance with local config (via advio) +villas-node file://${LOCAL_CONF} & + +sleep 1 + +# Fetch config via API +curl -sX POST --data '{ "command" : "config" }' http://localhost/api/v1 2>/dev/null > ${FETCHED_CONF} + +# Shutdown VILLASnode +kill $! + +# Compare local config with the fetched one +diff -u <(cat ${LOCAL_CONF} | conf2json | jq -S .) <(cat ${FETCHED_CONF} | jq -S .config) + +RC=$? + +rm -f ${FETCHED_CONF} + +exit $RC \ No newline at end of file diff --git a/tests/integration/hook-convert.sh b/tests/integration/hook-convert.sh new file mode 100755 index 000000000..95efd850e --- /dev/null +++ b/tests/integration/hook-convert.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +INPUT_FILE=$(mktemp) +OUTPUT_FILE=$(mktemp) +EXPECT_FILE=$(mktemp) + +cat < ${INPUT_FILE} +1490500399.776379108(0) 0.000000 0.000000 0.000000 0.000000 +1490500399.876379108(1) 0.587785 0.587785 0.587785 0.587785 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500400.076379108(3) 0.951057 0.951057 0.951057 0.951057 +1490500400.176379108(4) 0.587785 0.587785 0.587785 0.587785 +1490500400.276379108(5) 0.000000 0.000000 0.000000 0.000000 +1490500400.376379108(6) -0.587785 -0.587785 -0.587785 -0.587785 +1490500400.476379108(7) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.576379108(8) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.676379108(9) -0.587785 -0.587785 -0.587785 -0.587785 +EOF + +cat < ${EXPECT_FILE} +1490500399.776379108(0) 0.000000 0 0 0.000000 +1490500399.876379108(1) 0.587785 58 58 0.587785 +1490500399.976379108(2) 0.951057 95 95 0.951057 +1490500400.076379108(3) 0.951057 95 95 0.951057 +1490500400.176379108(4) 0.587785 58 58 0.587785 +1490500400.276379108(5) 0.000000 0 0 0.000000 +1490500400.376379108(6) -0.587785 -58 -58 -0.587785 +1490500400.476379108(7) -0.951057 -95 -95 -0.951057 +1490500400.576379108(8) -0.951057 -95 -95 -0.951057 +1490500400.676379108(9) -0.587785 -58 -58 -0.587785 +EOF + +villas-hook convert 'mode="fixed" scale=100 mask=0x6' < ${INPUT_FILE} > ${OUTPUT_FILE} + +# Compare only the data values +diff -u <(cut -f2- ${OUTPUT_FILE}) <(cut -f2- ${EXPECT_FILE}) + +RC=$? + +rm -f ${INPUT_FILE} ${OUTPUT_FILE} ${EXPECT_FILE} + +exit $RC \ No newline at end of file diff --git a/tests/integration/hook-decimate.sh b/tests/integration/hook-decimate.sh new file mode 100755 index 000000000..a62c7f0a1 --- /dev/null +++ b/tests/integration/hook-decimate.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +INPUT_FILE=$(mktemp) +OUTPUT_FILE=$(mktemp) +EXPECT_FILE=$(mktemp) + +cat < ${INPUT_FILE} +1490500399.776379108(0) 0.000000 0.000000 0.000000 0.000000 +1490500399.876379108(1) 0.587785 0.587785 0.587785 0.587785 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500400.076379108(3) 0.951057 0.951057 0.951057 0.951057 +1490500400.176379108(4) 0.587785 0.587785 0.587785 0.587785 +1490500400.276379108(5) 0.000000 0.000000 0.000000 0.000000 +1490500400.376379108(6) -0.587785 -0.587785 -0.587785 -0.587785 +1490500400.476379108(7) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.576379108(8) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.676379108(9) -0.587785 -0.587785 -0.587785 -0.587785 +EOF + +cat < ${EXPECT_FILE} +1490500399.776379108(0) 0.000000 0.000000 0.000000 0.000000 +1490500400.076379108(3) 0.951057 0.951057 0.951057 0.951057 +1490500400.376379108(6) -0.587785 -0.587785 -0.587785 -0.587785 +1490500400.676379108(9) -0.587785 -0.587785 -0.587785 -0.587785 +EOF + +villas-hook decimate 'ratio=3' < ${INPUT_FILE} > ${OUTPUT_FILE} + +# Compare only the data values +diff -u <(cut -f2- ${OUTPUT_FILE}) <(cut -f2- ${EXPECT_FILE}) + +RC=$? + +rm -f ${INPUT_FILE} ${OUTPUT_FILE} ${EXPECT_FILE} + +exit $RC \ No newline at end of file diff --git a/tests/integration/hook-drop.sh b/tests/integration/hook-drop.sh new file mode 100755 index 000000000..d18e2a8c3 --- /dev/null +++ b/tests/integration/hook-drop.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +INPUT_FILE=$(mktemp) +OUTPUT_FILE=$(mktemp) +EXPECT_FILE=$(mktemp) + +cat < ${INPUT_FILE} +1490500399.776379108(0) 0.000000 0.000000 0.000000 0.000000 +1490500399.876379108(1) 0.587785 0.587785 0.587785 0.587785 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500400.076379108(3) 0.951057 0.951057 0.951057 0.951057 +1490500400.176379108(4) 0.587785 0.587785 0.587785 0.587785 +1490500400.476379108(7) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.276379108(5) 0.000000 0.000000 0.000000 0.000000 +1490500400.576379108(8) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.376379108(6) -0.587785 -0.587785 -0.587785 -0.587785 +1490500400.676379108(9) -0.587785 -0.587785 -0.587785 -0.587785 +EOF + +cat < ${EXPECT_FILE} +1490500399.776379108(0) 0.000000 0.000000 0.000000 0.000000 +1490500399.876379108(1) 0.587785 0.587785 0.587785 0.587785 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500400.076379108(3) 0.951057 0.951057 0.951057 0.951057 +1490500400.176379108(4) 0.587785 0.587785 0.587785 0.587785 +1490500400.476379108(7) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.576379108(8) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.676379108(9) -0.587785 -0.587785 -0.587785 -0.587785 +EOF + +villas-hook drop < ${INPUT_FILE} > ${OUTPUT_FILE} + +# Compare only the data values +diff -u <(cut -f2- ${OUTPUT_FILE}) <(cut -f2- ${EXPECT_FILE}) + +RC=$? + +rm -f ${INPUT_FILE} ${OUTPUT_FILE} ${EXPECT_FILE} + +exit $RC \ No newline at end of file diff --git a/tests/integration/hook-map.sh b/tests/integration/hook-map.sh new file mode 100755 index 000000000..c46b75498 --- /dev/null +++ b/tests/integration/hook-map.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +INPUT_FILE=$(mktemp) +OUTPUT_FILE=$(mktemp) +EXPECT_FILE=$(mktemp) + +cat < ${INPUT_FILE} +1490500399.776379108(0) 0.000000 0.000000 0.000000 0.000000 +1490500399.876379108(1) 0.587785 0.587785 0.587785 0.587785 +1490500399.976379108(2) 0.951057 0.951057 0.951057 0.951057 +1490500400.076379108(3) 0.951057 0.951057 0.951057 0.951057 +1490500400.176379108(4) 0.587785 0.587785 0.587785 0.587785 +1490500400.276379108(5) 0.000000 0.000000 0.000000 0.000000 +1490500400.376379108(6) -0.587785 -0.587785 -0.587785 -0.587785 +1490500400.476379108(7) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.576379108(8) -0.951057 -0.951057 -0.951057 -0.951057 +1490500400.676379108(9) -0.587785 -0.587785 -0.587785 -0.587785 +EOF + +cat < ${EXPECT_FILE} +1490500399.776379108(0) 0.000000 0 1490500399 776379108 0.000000 0.000000 +1490500399.876379108(1) 0.587785 1 1490500399 876379108 0.587785 0.587785 +1490500399.976379108(2) 0.951057 2 1490500399 976379108 0.951057 0.951057 +1490500400.076379108(3) 0.951057 3 1490500400 76379108 0.951057 0.951057 +1490500400.176379108(4) 0.587785 4 1490500400 176379108 0.587785 0.587785 +1490500400.276379108(5) 0.000000 5 1490500400 276379108 0.000000 0.000000 +1490500400.376379108(6) -0.587785 6 1490500400 376379108 -0.587785 -0.587785 +1490500400.476379108(7) -0.951057 7 1490500400 476379108 -0.951057 -0.951057 +1490500400.576379108(8) -0.951057 8 1490500400 576379108 -0.951057 -0.951057 +1490500400.676379108(9) -0.587785 9 1490500400 676379108 -0.587785 -0.587785 +EOF + +villas-hook map 'mapping = [ "data[3]", "hdr.sequence", "ts.origin", "data[1-2]" ]' < ${INPUT_FILE} > ${OUTPUT_FILE} + +# Compare only the data values +diff -u <(cut -f2- ${OUTPUT_FILE}) <(cut -f2- ${EXPECT_FILE}) + +RC=$? + +rm -f ${INPUT_FILE} ${OUTPUT_FILE} ${EXPECT_FILE} + +exit $RC \ No newline at end of file diff --git a/tests/integration/hook-shift_seq.sh b/tests/integration/hook-shift_seq.sh new file mode 100755 index 000000000..6662a22de --- /dev/null +++ b/tests/integration/hook-shift_seq.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +OUTPUT_FILE=$(mktemp) + +OFFSET=100 + +villas-signal random -l ${NUM_SAMPLES} -n | villas-hook shift_seq offset=${OFFSET} > ${OUTPUT_FILE} + +# Compare shifted sequence no +diff -u \ + <(sed -re 's/^[0-9]+\.[0-9]+([\+\-][0-9]+\.[0-9]+(e[\+\-][0-9]+)?)?\(([0-9]+)\).*/\3/g' ${OUTPUT_FILE}) \ + <(seq ${OFFSET} $((${NUM_SAMPLES}+${OFFSET}-1))) + +RC=$? + +rm -f ${OUTPUT_FILE} + +exit $RC diff --git a/tests/integration/hook-shift_ts.sh b/tests/integration/hook-shift_ts.sh new file mode 100755 index 000000000..132f40570 --- /dev/null +++ b/tests/integration/hook-shift_ts.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +STATS_FILE=$(mktemp) + +OFFSET=10 +EPSILON=0.05 + +villas-signal sine -l 10 -r 10 | villas-hook shift_ts offset=${OFFSET} | villas-hook stats format=\"json\" output=\"${STATS_FILE}\" > /dev/null + +#jq .owd ${STATS_FILE} + +jq -e ".owd.mean - ${OFFSET} | length < ${EPSILON}" ${STATS_FILE} > /dev/null + +RC=$? + +rm ${STATS_FILE} + +exit $RC \ No newline at end of file diff --git a/tests/integration/hook-skip_first.sh b/tests/integration/hook-skip_first.sh new file mode 100755 index 000000000..f74751af9 --- /dev/null +++ b/tests/integration/hook-skip_first.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +OUTPUT_FILE=$(mktemp) + +SKIP=10 + +echo ${OUTPUT_FILE} + +villas-signal random -r 1 -l ${NUM_SAMPLES} -n | villas-hook skip_first seconds=${SKIP} > ${OUTPUT_FILE} + +LINES=$(wc -l < ${OUTPUT_FILE}) + +rm ${OUTPUT_FILE} + +# Test condition +(( ${LINES} == ${NUM_SAMPLES} - ${SKIP} )) \ No newline at end of file diff --git a/tests/integration/hook-skip_first2.sh b/tests/integration/hook-skip_first2.sh new file mode 100755 index 000000000..5986b5548 --- /dev/null +++ b/tests/integration/hook-skip_first2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +OUTPUT_FILE=$(mktemp) + +SKIP=50 + +villas-signal random -r 1 -l ${NUM_SAMPLES} -n | villas-hook skip_first samples=${SKIP} > ${OUTPUT_FILE} + +LINES=$(wc -l < ${OUTPUT_FILE}) + +rm ${OUTPUT_FILE} + +# Test condition +(( ${LINES} == ${NUM_SAMPLES} - ${SKIP} )) \ No newline at end of file diff --git a/tools/tests.sh b/tools/tests.sh deleted file mode 100755 index ab49eb1fb..000000000 --- a/tools/tests.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash - -set -e - -# Configuration - -HOST=$(hostname -s) - -#LOCAL_IP=10.10.12.2 -LOCAL_IP=127.0.0.1 -LOCAL_PORT=12001 - -#REMOTE_IP=10.10.12.3 -REMOTE_IP=127.0.0.1 -REMOTE_PORT=12002 - -#LOCAL_DIR=/villas/server/ -#REMOTE_DIR=/villas/server/ -LOCAL_DIR=/home/stv0g/workspace/rwth/acs/villas/server -REMOTE_DIR=$LOCAL_DIR -######################### End of Configuration ################################ -# There's no need to change something below this line - -SSH="ssh -T $REMOTE_IP" - -TEST_CONFIG=" - affinity = 0x02; # Mask of cores the server should run on - priority = 50; # Scheduler priority for the server - debug = 10; # The level of verbosity for debug messages - stats = 3; # The interval in seconds fo path statistics - - nodes = { - remote = { - type = \"udp\"; - local = \"$LOCAL_IP:$LOCAL_PORT\"; - remote = \"$REMOTE_IP:$REMOTE_PORT\"; - } - }; -" - - -REMOTE_CONFIG=" - affinity = 0x02; # Mask of cores the server should run on - priority = 50; # Scheduler priority for the server - debug = 0; # The level of verbosity for debug messages - stats = 0; # The interval in seconds fo path statistics - - nodes = { - remote = { - type = \"udp\"; - local = \"$REMOTE_IP:$REMOTE_PORT\"; - remote = \"$LOCAL_IP:$LOCAL_PORT\"; - }, - }; - - paths = ({ - in = \"remote\"; - out = \"remote\"; - }); -" - -# Start remote server -$SSH -n "echo '$REMOTE_CONFIG' | sudo $REMOTE_DIR/server -" & -REMOTE_PID=$! -echo "Started remote server with pid: $REMOTE_PID" - -# Start tests -echo "$TEST_CONFIG" | $LOCAL_DIR/test - rtt -f 3 -c 100000 3>> test_output - -# Stop remote server -$SSH sudo kill $REMOTE_PID -echo "Stopped remote server with pid: $REMOTE_PID" \ No newline at end of file