Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce dmsg Tests fs10 with corrupt data #1034

Merged
merged 27 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/prove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# uses: mxschmitt/action-tmate@v1
- name: run prove on perl modules (testscripts)
run: |
prove --exec 'perl -MDevel::Cover=-silent,1 -I FHEM ' -I FHEM -r -v t/SD_Protoco*
prove -j2 --exec 'perl -MDevel::Cover=-silent,1 -I FHEM ' -I FHEM -r -v t/SD_Protoco*
- name: Create clover report
run: cover -report clover
- uses: codecov/codecov-action@v2.1.0
Expand All @@ -46,9 +46,9 @@ jobs:
- name: run prove fhem testsuite ${{ matrix.perl }}
run: |
cp -R ${GITHUB_WORKSPACE}/FHEM/* ${FHEM_DIR}/FHEM/
# cp -R ${GITHUB_WORKSPACE}/lib/* ${FHEM_DIR}/lib/
cp -R ${GITHUB_WORKSPACE}/lib/* ${FHEM_DIR}/lib/
#find ${GITHUB_WORKSPACE}/t/FHEM -maxdepth 1 -regex '.*/t/FHEM/[0-9][0-9]_.*' -print0 | xargs -0 -I'{}' prove --exec 'perl -MDevel::Cover=-silent,1 fhem.pl -t' -I FHEM -r -vv -r "{}"
prove --exec 'perl -MDevel::Cover=-silent,1 fhem.pl -t' -I FHEM -r -vv -r ${GITHUB_WORKSPACE}/t/FHEM/
prove -j2 --exec 'perl -MDevel::Cover=-silent,1 fhem.pl -t' -I FHEM -vv -r ${GITHUB_WORKSPACE}/t/FHEM/
working-directory: /opt/fhem/
env:
FHEM_DIR: /opt/fhem
Expand Down
4 changes: 2 additions & 2 deletions FHEM/10_FS10.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################
# $Id: 10_FS10.pm 11 2020-06-06 21:30:00Z elektron-bbs $
# $Id: 10_FS10.pm 11 2021-11-21 17:54:21Z sidey79 $
#
# FS10 basierend auf dem FS20 Modul angepasst fuer SIGNALduino, elektron-bbs
#
Expand Down Expand Up @@ -89,7 +89,7 @@ sub Initialize {
"$main::readingFnAttributes " .
'model:'.join q{,} , sort keys %models;
$hash->{AutoCreate} = {'FS10.*' => {FILTER => '%NAME', autocreateThreshold => '5:180', GPLOT => q{}}};
return
return;
}

sub Attr {
Expand Down
2 changes: 1 addition & 1 deletion controls_signalduino.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
UPD 2021-11-21_18:12:02 230712 FHEM/00_SIGNALduino.pm
UPD 2020-06-15_17:41:39 17876 FHEM/10_FS10.pm
UPD 2021-11-21_15:58:21 17872 FHEM/10_FS10.pm
UPD 2020-05-26_11:51:12 20465 FHEM/10_SD_GT.pm
UPD 2021-08-11_21:38:30 10096 FHEM/14_BresserTemeo.pm
UPD 2020-08-17_22:17:34 13964 FHEM/14_FLAMINGO.pm
Expand Down
172 changes: 172 additions & 0 deletions lib/Test2/SIGNALduino/RDmsg.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package Test2::SIGNALduino::RDmsg;

use strict;
use warnings;
use Test2::V0;
use Test2::Tools::Compare qw{is U };
use Test2::Todo;
use JSON;
use File::Basename;
use Test2::API qw/context run_subtest/;
use base 'Exporter';

our @EXPORT = qw/dmsgCheck/;
our $VERSION = 1.00;
our $testDataArray;
our @JSONTestList = (
{
testname => 'Test with pre-release SD_Device_ProtocolList',
url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/pre-release/FHEM/lib/SD_Device_ProtocolList.json',
todo => 'Checking with pre-release Version of SD_Device_ProtocolList which can fail',
},
{
testname => 'Test with master SD_Device_ProtocolList',
url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/master/FHEM/lib/SD_Device_ProtocolList.json',
#todo => 'Checking with master Version of SD_Device_ProtocolList which can fail',
}
);
my $EMPTY = q{};


sub loadJson {
my $url = shift;

my $json_text;
if ($url =~ /^https:\/\//i)
{
use HTTP::Tiny;
my $response = HTTP::Tiny->new->get($url);
fail("Failed!\n") unless $response->{success};
$json_text = $response->{content};
} else {
$json_text = do {
open(my $json_fh, "<:encoding(UTF-8)", $url)
or fail(qq[Can't open $url: $!\n]);
local $/;
<$json_fh>
};
}


$testDataArray = eval { decode_json($json_text) };
if($@){
fail("open json file SD_Device_ProtocolList was not possible $?");
#use Data::Dumper;
diag $json_text;
}
}

sub filterTestDataArray {
my $modulename = shift;

$modulename =~ s/^[0-9][0-9]_//; # Remove leading digtis
my @results;

while ( (my $pID, my $testSet) = each (@{$testDataArray}) )
{
if (defined $testSet->{module} && $testSet->{module} eq $modulename)
{
push @results, $testSet
}
}

return @results;
}

sub checkParseFn {
my $module = shift;
my $tData = shift;
my $ioHash = shift;
use Data::Dumper;

my $tplan=3; # one for readings and one for internals and one for defmod

if (defined $tData->{internals}{DEF} && defined $tData->{internals}{NAME}) {
$tplan++;
note("device will be defined temporary");
is(::CommandDefMod(undef,"-temporary $tData->{internals}{NAME} $module $tData->{internals}{DEF}"),U(),"Verify device return from defmod ",$tData);
}

if (defined $tData->{attributes}{model} ) {
note("device attribute model $tData->{attributes}{model} set for right result");
::CommandAttr(undef,"$tData->{internals}{NAME} model $tData->{attributes}{model}"); # set attribute
}


#print Dumper(%main::modules);
#my $ret=$main::modules{$module}{ParseFn}->($ioHash,$tData->{dmsg});

no strict "refs";
my $ret=&{$main::modules{$module}{ParseFn}}($ioHash,$tData->{dmsg});
use strict "refs";

is($ret,$tData->{internals}{NAME},'verify parseFn return equal internal NAME');

SKIP: {
skip 'readings' if ( !defined $ret || $ret eq $EMPTY || $ret eq q[NEXT] || scalar keys %{$tData->{readings}} < 1);

subtest "Verify readings" => sub {
plan(scalar keys %{$tData->{readings}} );
while ( (my $rName, my $rValue) = each (%{$tData->{readings}}) )
{
is(::ReadingsVal($tData->{internals}{NAME} ,$rName,undef),$rValue,"check reading $rName");
}
};
} #skip

SKIP : {
skip 'internals' if ( !defined $ret || $ret eq $EMPTY || $ret eq q[NEXT] || scalar keys %{$tData->{internals}} < 1);
subtest "Verify internals" => sub {
plan(scalar keys %{$tData->{internals}} );
while ( (my $iName, my $iValue) = each (%{$tData->{internals}}) )
{
is(::InternalVal($tData->{internals}{NAME} ,$iName, undef),$iValue,"check internal $iName");
}
};

::CommandDelete(undef,$tData->{internals}{NAME});
} #skip

plan($tplan);
}; # subtest

sub dmsgCheck {
my $testDef = shift;
my $modulename = shift;
my $ioHash = shift;

my $pID;
my $tID;
my $testSet;
# use Data::Dumper;
# print Dumper($main::modules{FS10});

my $ctx = context();
loadJson($testDef->{url});
my @filt_testDataArray = filterTestDataArray($modulename);

if (scalar @filt_testDataArray == 0) { pass('No testdata for module provided'); };

my $todo;
if ( exists $testDef->{todo}) {
$todo = Test2::Todo->new(reason => $testDef->{todo} );
}


while ( ($pID, $testSet) = each @filt_testDataArray )
{
SKIP: {
#skip 'Testset id not in scope' if (!defined $testSet->{id} || $testSet->{id} ne '61');
skip 'Protocol does not exsists in ProtocolObject' if ( !$ioHash->{protocolObject}->protocolExists($testSet->{id}) );
# skip 'Protocol is under development' if ( defined $ioHash->{protocolObject}->checkProperty($testSet->{id},'developId',undef) );
while ( (my $tID, my $tData) = each (@{$testSet->{data}}) )
{
my $bool = run_subtest(qq[Checking parseFN for module: $testSet->{module} device: $testSet->{name} TestNo: $tID ($tData->{comment})], \&checkParseFn, {buffered => 1, inherit_trace => 1},$testSet->{module},$tData, $ioHash);
} # while testSet
} # SKIP
} # while filt_testDataArray

$ctx->release;
}

1;
50 changes: 50 additions & 0 deletions t/FHEM/10_FS10/09_ParseData.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use strict;
use warnings;
use Test2::V0;
use File::Basename;

# Testtool which supports DMSG Tests from SIGNALDuino_tool
use Test2::SIGNALduino::RDmsg;

our %defs;
our $init_done;

my $module = basename (dirname(__FILE__));


sub runTest {
my $ioName = shift;
my $ioHash = $defs{$ioName};
#use Data::Dumper;
#print Dumper(@Test::RDmsg::JSONTestList);
my $filepath = dirname(__FILE__);
push @Test2::SIGNALduino::RDmsg::JSONTestList, {
testname => q[Testdata with corrupt FS10 data],
url => qq[$filepath/testData.json],
};

plan( scalar @Test2::SIGNALduino::RDmsg::JSONTestList);
for my $maintest (@Test2::SIGNALduino::RDmsg::JSONTestList)
{
subtest $maintest->{testname} => sub {
Test2::SIGNALduino::RDmsg::dmsgCheck($maintest,$module,$ioHash);
};
}
exit(0);
}

sub waitDone {

if ($init_done)
{
runTest(@_);
} else {
InternalTimer(time()+0.5, &waitDone,@_);
}

}

waitDone('dummyDuino');


1;
4 changes: 3 additions & 1 deletion t/FHEM/10_FS10/fhem.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

define dummyDuino SIGNALduino none
attr dummyDuino dummy 1
attr dummyDuino verbose 5
37 changes: 37 additions & 0 deletions t/FHEM/10_FS10/testData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{"name":"FS10", "id":"61", "module":"FS10", "data": [
{
"dmsg":"P61#5A4EE12254", "comment":"sum != rsum", "user":"unknown",
"internals": {"NAME": "" },
"readings": {},
"minProtocolVersion":"1.27", "revision_entry":"2021-04-22 22:09:16",
"revision_modul":"10_FS10.pm 11 2021-11-17 21:48:53Z sidey79",
"rmsg":"MU;P0=-1440;P1=432;P2=-357;P3=635;P4=-559;D=012121212123412343412123434121234343412123412343434341234343412123434121212121212341231212343412341212121;CP=1;"
},
{
"dmsg":"P61#0011DC71120", "comment":"parity/bit5 error", "user":"unknown",
"internals": {"NAME": "" },
"readings": {},
"minProtocolVersion":"1.27", "revision_entry":"2021-04-22 22:09:16",
"revision_modul":"10_FS10.pm 11 2021-11-17 21:48:53Z sidey79",
"rmsg":"MU;P0=1776;P1=-410;P2=383;P3=-820;D=01212121212121212121212123212121232323212323232121212323232121212321212123212123212120;CP=2;R=74;"
},
{
"dmsg":"P61#0004771C468", "comment":"ERROR message contains too many zeros", "user":"unknown",
"internals": {"NAME": "" },
"readings": {},
"minProtocolVersion":"1.27", "revision_entry":"2021-04-22 22:09:16",
"revision_modul":"10_FS10.pm 11 2021-11-17 21:48:53Z sidey79",
"rmsg":"MU;P0=1776;P1=-410;P2=383;P3=-820;D=012121212121212121212121212123212121232323212323232121212323232121212321212123232123212120;CP=2;R=74;"
},
{
"dmsg":"P61#0011DC711A", "comment":"ERROR message too short or too long ", "user":"unknown",
"internals": {"NAME": "" },
"readings": {},
"minProtocolVersion":"1.27", "revision_entry":"2021-04-22 22:09:16",
"revision_modul":"10_FS10.pm 11 2021-11-17 21:48:53Z sidey79",
"rmsg":"MU;P0=1776;P1=-410;P2=383;P3=-820;D=012121212121212121212121232121212323232123232321212123232321212123212121232321232120;CP=2;R=74;"
}
]
}
]