From f04434f5054d04ff3b9809fee3f085efe4ca700e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Thu, 3 Feb 2022 15:40:59 +0100 Subject: [PATCH] Add new test case for configurable electricity meters. --- simulations/simulation_el_meters.txt | 10 +++++ test.sh | 3 ++ tests/test_electricity_meters.sh | 56 ++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 simulations/simulation_el_meters.txt create mode 100755 tests/test_electricity_meters.sh diff --git a/simulations/simulation_el_meters.txt b/simulations/simulation_el_meters.txt new file mode 100644 index 0000000..cc10932 --- /dev/null +++ b/simulations/simulation_el_meters.txt @@ -0,0 +1,10 @@ + +# Test different kinds of electricity meters with radio converters. +# The meters might report the same mfct/media/version but contains +# quite different content. + +# This is eBZ DD3 meter with a wMB-E01 wmbus radio converter module. + +telegram=|4B445A146450000002378C20F3900F002C25F38B00006CBB07CEB215901172635213015A140102F3002007102F2F#04039D3E03000429E82201000DFD110E333632353331313031305A424531| +{"media":"electricity","meter":"ehzp","name":"MyEl","id":"01135263","total_energy_consumption_kwh":212.637,"current_power_consumption_kw":0.74472,"total_energy_production_kwh":0,"on_time_h":0,"timestamp":"1111-11-11T11:11:11Z"} +|MyEl;01135263;212.637000;0.744720;0.000000;1111-11-11 11:11.11 diff --git a/test.sh b/test.sh index d3f6234..55d2121 100755 --- a/test.sh +++ b/test.sh @@ -24,6 +24,9 @@ if [ "$?" != "0" ]; then RC="1"; fi tests/test_s1_meters.sh $PROG if [ "$?" != "0" ]; then RC="1"; fi +tests/test_electricity_meters.sh $PROG +if [ "$?" != "0" ]; then RC="1"; fi + tests/test_mbus.sh $PROG if [ "$?" != "0" ]; then RC="1"; fi diff --git a/tests/test_electricity_meters.sh b/tests/test_electricity_meters.sh new file mode 100755 index 0000000..c0b9fe0 --- /dev/null +++ b/tests/test_electricity_meters.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +PROG="$1" + +mkdir -p testoutput +TEST=testoutput + +TESTNAME="Test electricity meters with radio converter plugins" +TESTRESULT="ERROR" + +METERS="MyEl ehzp 01135263 NOKEY" + +cat simulations/simulation_el_meters.txt | grep '^{' > $TEST/test_expected.txt +$PROG --format=json simulations/simulation_el_meters.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt +if [ "$?" = "0" ] +then + cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + diff $TEST/test_expected.txt $TEST/test_responses.txt + if [ "$?" = "0" ] + then + echo OK json: $TESTNAME + TESTRESULT="OK" + else + TESTRESULT="ERROR" + fi +else + echo "wmbusmeters returned error code: $?" + cat $TEST/test_output.txt + cat $TEST/test_stderr.txt +fi + +cat simulations/simulation_el_meters.txt | grep '^|' | sed 's/^|//' > $TEST/test_expected.txt +$PROG --format=fields simulations/simulation_el_meters.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt +if [ "$?" = "0" ] +then + cat $TEST/test_output.txt | sed 's/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9].[0-9][0-9]$/1111-11-11 11:11.11/' > $TEST/test_responses.txt + diff $TEST/test_expected.txt $TEST/test_responses.txt + if [ "$?" = "0" ] + then + echo OK fields: $TESTNAME + TESTRESULT="OK" + else + TESTRESULT="ERROR" + fi +else + echo "wmbusmeters returned error code: $?" + cat $TEST/test_output.txt + cat $TEST/test_stderr.txt +fi + + +if [ "$TESTRESULT" = "ERROR" ] +then + echo ERROR: $TESTNAME + exit 1 +fi