From 405d005cb5fcd138f6b5a11e1d5f84ad8a72d9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Sun, 25 Dec 2022 20:23:41 +0100 Subject: [PATCH] Add test of netcat feeding wmbusmeters. --- test.sh | 3 +++ tests/test_nc.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 tests/test_nc.sh diff --git a/test.sh b/test.sh index 7d95c37..d452b94 100755 --- a/test.sh +++ b/test.sh @@ -168,6 +168,9 @@ then (cd ..; ./additional_tests.sh $PROG) fi +./tests/test_nc.sh $PROG +if [ "$?" != "0" ]; then RC="1"; fi + echo Slower tests... tests/test_pipe.sh $PROG diff --git a/tests/test_nc.sh b/tests/test_nc.sh new file mode 100755 index 0000000..d979e9a --- /dev/null +++ b/tests/test_nc.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +PROG="$1" + +TEST=testoutput + +rm -rf $TEST +mkdir -p $TEST + +TESTNAME="Test using netcat to feed rtlwmbus stream using tcp." +TESTRESULT="ERROR" + +PORT=$(( $RANDOM % 10000 + 30000 )) + +rm -f $TEST/response +$PROG --silent --oneshot --format=fields --selectfields=total_m3 "rtlwmbus:CMD(nc -lkv $PORT)" MyWater iperl 33225544 NOKEY >> $TEST/response 2>&1 & + +sleep 0.5 + +echo "T1;1;1;2019-04-03 19:00:42.000;97;148;33225544;0x1844AE4C4455223368077A55000000041389E20100023B0000" | nc -q1 localhost $PORT + +sleep 0.5 + +GOT=$(cat $TEST/response | tr -d '\n') +EXPECTED="123.529" + +if [ "$GOT" = "$EXPECTED" ] +then + echo "OK: $TESTNAME" + TESTRESULT="OK" +else + echo "ERROR: GOT $GOT but expected $EXPECTED" +fi + +if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi