Add second test.

pull/768/head
Fredrik Öhrström 2022-12-25 20:52:19 +01:00
rodzic 45b06ead75
commit 97e64ae4b1
1 zmienionych plików z 38 dodań i 0 usunięć

38
tests/test_nc2.sh 100755
Wyświetl plik

@ -0,0 +1,38 @@
#!/bin/bash
if nc 2>&1 | grep -q apple
then
exit 0
fi
PROG="$1"
TEST=testoutput
rm -rf $TEST
mkdir -p $TEST
TESTNAME="Test using netcat to feed hex stream using tcp."
TESTRESULT="ERROR"
PORT=$(( $RANDOM % 10000 + 30000 ))
rm -f $TEST/response
$PROG --silent --oneshot --exitafter=5s --format=fields --selectfields=total_m3 "hex:CMD(nc -lk $PORT)" MyWater iperl 33225544 NOKEY >> $TEST/response 2>&1 &
sleep 0.5
echo "1844AE4C4455223368077A55000000041389E20100023B0000" | nc -q1 localhost $PORT
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