blib/lib/Langertha/Holmgang/Grader.pm

filter: Statementstmt 52.8% 187 / 354 Branchbran 45.1% 112 / 248 Conditioncond 34.9% 72 / 206 MC/DCmcdc 23.1% 25 / 108 Subroutinesub 61.7% 21 / 34 Podpod 100% 11 / 11 totaltotal 44.5% 428 / 961 CC 227 SCAR 48.2
CC
227
Cov
46%
rule
303.8
rule
303.8
grade
117.5
CRAP 124.5
« blib/lib/Langertha/Holmgang/Sim/Linux/Dns.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Nginx.pm »
1 package Langertha::Holmgang::Grader;
2 # ABSTRACT: Grades a case deterministically: rules at the end state and on the calls
3  
4 36 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 36 ▶use Langertha::Holmgang::Expectation qw( condition );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 36 ▶use Langertha::Holmgang::Simulators;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 36 ▶use Langertha::Holmgang::World;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 36 our $VERSION = '0.001';
13  
14 # the rule kinds of format 2, in the order the kind is looked up; a true constant
15 36 our @RULE_KINDS = qw( state unchanged_except calls not_called only_tools check packet login );
16  
17  
18 36 has simulators => (
19 is => 'ro',
20 lazy => 1,
21 builder => '_build_simulators',
22 );
23 233 ▶sub _build_simulators { Langertha::Holmgang::Simulators->new }
Subroutine _build_simulators: called CC=1 SCAR=0.0
24  
25  
26 10199 ▶sub world_class { 'Langertha::Holmgang::World' }
Subroutine world_class: called CC=1 SCAR=0.0
Pod documented
27  
28  
29 15740 ▶sub kind {
Subroutine kind: called CC=1 SCAR=1.2
Pod documented
30 0 ▶ my ( $self, $r ) = @_;
Subroutine kind: not called CC=1 SCAR=1.2
Pod documented
31 0 my ( $k ) = grep { exists $r->{$_} } @RULE_KINDS;
32 0 return $k;
33 }
34  
35  
36 10346 ▶sub required {
Subroutine required: called CC=3 SCAR=15.4
Pod documented
37 0 ▶ my ( $self, $r ) = @_;
Subroutine required: not called CC=3 SCAR=15.4
Pod documented
38 0 ▶ return !exists $r->{required} || $r->{required} ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
!exists $r->{'required'} || $r->{'required'} ? : 10266 80 10346
!exists $r->{'required'} || $r->{'required'} ? : 0 0 0
Condition33%2/6
not exists $r->{"required"} or $r->{"required"}
l!l&&r!l&&!r
10266080
not exists $r->{"required"} or $r->{"required"}
l!l&&r!l&&!r
000
MC/DC50%1/2
not exists $r->{"required"} or $r->{"required"}
not exists $r->{"required"} $r->{"required"}
MC/DC0%0/2
not exists $r->{"required"} or $r->{"required"}
not exists $r->{"required"} $r->{"required"}
Truth table66%2/3
not(A) or B
A= not exists $r->{"required"}B= $r->{"required"}
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not exists $r->{"required"}B= $r->{"required"}
ABresult
1X1
011
000
39 }
40  
41  
42 92 ▶sub _args_match {
Subroutine _args_match: called CC=8 SCAR=32.0
43 0 ▶ my ( $self, $patterns, $args ) = @_;
Subroutine _args_match: not called CC=8 SCAR=32.0
44 0 ▶ for my $k ( sort keys %{ $patterns || {} } ) {
Condition25%1/4
$patterns || {}
l!l
920
$patterns || {}
l!l
00
MC/DC0%0/1
$patterns || {}
$patterns
MC/DC0%0/1
$patterns || {}
$patterns
Truth table50%1/2
A
A= $patterns
Aresult
11
00
Truth table0%0/2
A
A= $patterns
Aresult
11
00
45 0 my $v = $args->{$k};
46 0 ▶ $v = join ',', map { $_ // '' } @$v if ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 58 58
if ref $v eq "ARRAY" 0 0 0
Condition0%0/4
$_ // ""
l!l
00
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
Truth table0%0/2
A
A= $_
Aresult
11
00
47 0 ▶ return 0 unless defined $v && !ref $v && $v =~ /$patterns->{$k}/;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v and not ref $v and $v =~ /$patterns->{$k}/ 35 23 58
unless defined $v and not ref $v and $v =~ /$patterns->{$k}/ 0 0 0
Condition41%5/12
defined $v and not ref $v and $v =~ /$patterns->{$k}/
!ll&&!rl&&r
33223
defined $v and not ref $v
!ll&&!rl&&r
3055
defined $v and not ref $v and $v =~ /$patterns->{$k}/
!ll&&!rl&&r
000
defined $v and not ref $v
!ll&&!rl&&r
000
MC/DC66%2/3
defined $v and not ref $v and $v =~ /$patterns->{$k}/
defined $v not ref $v $v =~ /$patterns->{$k}/
MC/DC0%0/3
defined $v and not ref $v and $v =~ /$patterns->{$k}/
defined $v not ref $v $v =~ /$patterns->{$k}/
Truth table75%3/4
A and not(B) and C
A= defined $vB= not ref $vC= $v =~ /$patterns->{$k}/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $vB= not ref $vC= $v =~ /$patterns->{$k}/
ABCresult
0XX0
10X0
1100
1111
48 }
49 0 return 1;
50 }
51  
52 25 ▶sub _call_text {
Subroutine _call_text: called CC=3 SCAR=16.2
53 0 ▶ my ( $self, $c ) = @_;
Subroutine _call_text: not called CC=3 SCAR=16.2
54 0 ▶ my @a = map { $_.'~'.$c->{args}{$_} } sort keys %{ $c->{args} || {} };
Condition25%1/4
$c->{'args'} || {}
l!l
250
$c->{'args'} || {}
l!l
00
MC/DC0%0/1
$c->{'args'} || {}
$c->{'args'}
MC/DC0%0/1
$c->{'args'} || {}
$c->{'args'}
Truth table50%1/2
A
A= $c->{'args'}
Aresult
11
00
Truth table0%0/2
A
A= $c->{'args'}
Aresult
11
00
55 0 ▶ return $c->{tool}.( @a ? '('.join( ', ', @a ).')' : '' );
Branch: 2 branches
BranchTrueFalseTotal
@a ? : 25 0 25
@a ? : 0 0 0
56 }
57  
58 2423 ▶sub _segments {
Subroutine _segments: called CC=2 SCAR=9.2
59 0 ▶ my ( $self, $p ) = @_;
Subroutine _segments: not called CC=2 SCAR=9.2
60 0 ▶ return ref $p eq 'ARRAY' ? $p : [ split /\./, $p ];
Branch: 2 branches
BranchTrueFalseTotal
ref $p eq 'ARRAY' ? : 205 2218 2423
ref $p eq 'ARRAY' ? : 0 0 0
61 }
62  
63 5436 ▶sub rule {
Subroutine rule: called CC=39 SCAR=57.2
Pod documented
64 0 ▶ my ( $self, $r, $o, $case ) = @_;
Subroutine rule: not called CC=39 SCAR=57.2
Pod documented
65 0 ▶ my $kind = $self->kind($r) // '';
Condition25%1/4
$self->kind($r) // ""
l!l
54360
$self->kind($r) // ""
l!l
00
MC/DC0%0/1
$self->kind($r) // ""
$self->kind($r)
MC/DC0%0/1
$self->kind($r) // ""
$self->kind($r)
Truth table50%1/2
A
A= $self->kind($r)
Aresult
11
00
Truth table0%0/2
A
A= $self->kind($r)
Aresult
11
00
66 0 ▶ my $calls = $o->{calls} || [];
Condition50%2/4
$o->{'calls'} || []
l!l
54279
$o->{'calls'} || []
l!l
00
MC/DC100%1/1
$o->{'calls'} || []
$o->{'calls'}
MC/DC0%0/1
$o->{'calls'} || []
$o->{'calls'}
Truth table100%2/2
A
A= $o->{'calls'}
Aresult
11
00
Truth table0%0/2
A
A= $o->{'calls'}
Aresult
11
00
67 0 my $wc = $self->world_class;
68 0 ▶ if ( $kind eq 'state' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "state") 2928 2508 5436
if ($kind eq "state") 0 0 0
69 0 return condition( $o->{state}, { %$r, path => $r->{state} } );
70 }
71 0 ▶ if ( $kind eq 'unchanged_except' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "unchanged_except") 2190 318 2508
if ($kind eq "unchanged_except") 0 0 0
72 0 my @allowed = map { $self->_segments($_) } @{ $r->{unchanged_except} };
73 0 my @bad = grep { !$wc->covered( $_->{path}, \@allowed ) }
74 0 grep { !$self->_scratch( $_->{path}, $o->{state} ) }
75 0 grep { !grep { /\A_/ } @{ $_->{path} } } $wc->diff( $case->initial_state, $o->{state} );
76 0 ▶ return ( 1, 'no other changes' ) unless @bad;
Branch: 2 branches
BranchTrueFalseTotal
unless @bad 2111 79 2190
unless @bad 0 0 0
77 0 return ( 0, 'also changed: '.join( ', ', map { $wc->path_text( $_->{path} ) } @bad ) );
78 }
79 0 ▶ if ( $kind eq 'calls' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "calls") 40 278 318
if ($kind eq "calls") 0 0 0
80 0 my $want = $r->{calls};
81 0 my $i = 0;
82 0 for my $c ( @$calls ) {
83 0 ▶ last if $i >= @$want;
Branch: 2 branches
BranchTrueFalseTotal
if $i >= @$want 0 28 28
if $i >= @$want 0 0 0
84 0 ▶ $i++ if ( $c->{tool} // '' ) eq $want->[$i]{tool} && $self->_args_match( $want->[$i]{args}, $c->{args} || {} );
Branch: 2 branches
BranchTrueFalseTotal
if ($c->{"tool"} // "") eq $want->[$i]{"tool"} and $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {}) 19 9 28
if ($c->{"tool"} // "") eq $want->[$i]{"tool"} and $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {}) 0 0 0
Condition28%4/14
($c->{"tool"} // "") eq $want->[$i]{"tool"} and $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
!ll&&!rl&&r
0919
$c->{"tool"} // ""
l!l
280
$c->{'args'} || {}
l!l
280
($c->{"tool"} // "") eq $want->[$i]{"tool"} and $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
!ll&&!rl&&r
000
$c->{"tool"} // ""
l!l
00
$c->{'args'} || {}
l!l
00
MC/DC50%1/2
($c->{"tool"} // "") eq $want->[$i]{"tool"} and $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
$c->{"tool"} $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
MC/DC0%0/1
$c->{'args'} || {}
$c->{'args'}
MC/DC0%0/2
($c->{"tool"} // "") eq $want->[$i]{"tool"} and $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
$c->{"tool"} $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
MC/DC0%0/1
$c->{'args'} || {}
$c->{'args'}
Truth table66%2/3
A and B
A= $c->{"tool"}B= $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
ABresult
0X0
100
111
Truth table50%1/2
A
A= $c->{'args'}
Aresult
11
00
Truth table0%0/3
A and B
A= $c->{"tool"}B= $self->_args_match($want->[$i]{"args"}, $c->{"args"} || {})
ABresult
0X0
100
111
Truth table0%0/2
A
A= $c->{'args'}
Aresult
11
00
85 }
86 0 ▶ return ( 1, 'called in this order' ) if $i == @$want;
Branch: 2 branches
BranchTrueFalseTotal
if $i == @$want 15 25 40
if $i == @$want 0 0 0
87 0 return ( 0, 'missing: '.$self->_call_text( $want->[$i] ) );
88 }
89 0 ▶ if ( $kind eq 'not_called' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "not_called") 157 121 278
if ($kind eq "not_called") 0 0 0
90 0 my $n = grep { $self->_matches_call( $r->{not_called}, $_ ) } @$calls;
91 0 ▶ return ( $n ? 0 : 1, $n ? 'called '.$n.'×' : 'not called' );
Branch: 4 branches
BranchTrueFalseTotal
$n ? : 20 137 157
$n ? : 20 137 157
$n ? : 0 0 0
$n ? : 0 0 0
92 }
93 0 ▶ if ( $kind eq 'only_tools' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "only_tools") 63 58 121
if ($kind eq "only_tools") 0 0 0
94 0 my %out;
95 0 ▶ $out{ $_->{tool} // '' }++ for grep { $self->_outside( $r, $_ ) } @$calls;
Condition25%1/4
$_->{"tool"} // ""
l!l
110
$_->{"tool"} // ""
l!l
00
MC/DC0%0/1
$_->{"tool"} // ""
$_->{"tool"}
MC/DC0%0/1
$_->{"tool"} // ""
$_->{"tool"}
Truth table50%1/2
A
A= $_->{"tool"}
Aresult
11
00
Truth table0%0/2
A
A= $_->{"tool"}
Aresult
11
00
96 0 ▶ return ( 1, 'only allowed tools' ) unless %out;
Branch: 2 branches
BranchTrueFalseTotal
unless %out 55 8 63
unless %out 0 0 0
97 0 return ( 0, 'outside: '.join( ', ', map { $_.' '.$out{$_}.'×' } sort keys %out ) );
98 }
99 0 ▶ if ( $kind eq 'login' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "login") 5 53 58
if ($kind eq "login") 0 0 0
100 0 my %t = %{ $r->{login} };
101 0 my $host = delete $t{host};
102 0 ▶ my $dev = ref $o->{state} eq 'HASH' ? $o->{state}{$host} : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $o->{'state'} eq 'HASH' ? : 5 0 5
ref $o->{'state'} eq 'HASH' ? : 0 0 0
103 0 ▶ return ( 0, 'device '.$host.' missing' ) unless ref $dev eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $dev eq "HASH" 0 5 5
unless ref $dev eq "HASH" 0 0 0
104 0 my ( $ok, $client, @log ) = eval { $self->simulators->login_check( $dev, \%t, $host ) };
105 0 ▶ return ( 0, 'no answer: '.( $@ =~ s/\s+\z//r ) ) if $@;
Branch: 2 branches
BranchTrueFalseTotal
if $@ 1 4 5
if $@ 0 0 0
106 0 ▶ my $got = $ok ? 'allowed' : 'denied';
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 1 3 4
$ok ? : 0 0 0
107 0 ▶ return ( $got eq $r->{result} ? 1 : 0, $got.': '.join( ' / ', grep { defined } $client, @log ) );
Branch: 2 branches
BranchTrueFalseTotal
$got eq $r->{'result'} ? : 3 1 4
$got eq $r->{'result'} ? : 0 0 0
108 }
109 0 ▶ if ( $kind eq 'packet' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq "packet") 13 40 53
if ($kind eq "packet") 0 0 0
110 0 my %pkt = %{ $r->{packet} };
111 0 my $host = delete $pkt{host};
112 0 ▶ my $dev = ref $o->{state} eq 'HASH' ? $o->{state}{$host} : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $o->{'state'} eq 'HASH' ? : 13 0 13
ref $o->{'state'} eq 'HASH' ? : 0 0 0
113 0 ▶ return ( 0, 'device '.$host.' missing' ) unless ref $dev eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $dev eq "HASH" 1 12 13
unless ref $dev eq "HASH" 0 0 0
114 0 $pkt{$_} += 0 for grep { defined $pkt{$_} } qw( sport dport );
115 0 ▶ my $boot = $r->{boot} ? "$r->{boot}" : undef;
Branch: 2 branches
BranchTrueFalseTotal
$r->{'boot'} ? : 2 10 12
$r->{'boot'} ? : 0 0 0
116 0 my ( $v, $why ) = eval { $self->simulators->packet_verdict( $dev, \%pkt, $boot ) };
117 0 ▶ return ( 0, 'no verdict: '.( $@ =~ s/\s+\z//r ) ) if $@;
Branch: 2 branches
BranchTrueFalseTotal
if $@ 0 12 12
if $@ 0 0 0
118 0 ▶ return ( 0, 'no verdict: '.( $why // '' ) ) unless defined $v;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v 0 12 12
unless defined $v 0 0 0
Condition0%0/4
$why // ""
l!l
00
$why // ""
l!l
00
MC/DC0%0/1
$why // ""
$why
MC/DC0%0/1
$why // ""
$why
Truth table0%0/2
A
A= $why
Aresult
11
00
Truth table0%0/2
A
A= $why
Aresult
11
00
119 0 ▶ return ( $v eq $r->{verdict} ? 1 : 0, ( $boot ? 'after reboot: ' : '' ).$v.' ('.( $why // '' ).')' );
Branch: 4 branches
BranchTrueFalseTotal
$v eq $r->{'verdict'} ? : 8 4 12
$boot ? : 2 10 12
$v eq $r->{'verdict'} ? : 0 0 0
$boot ? : 0 0 0
Condition25%1/4
$why // ""
l!l
120
$why // ""
l!l
00
MC/DC0%0/1
$why // ""
$why
MC/DC0%0/1
$why // ""
$why
Truth table50%1/2
A
A= $why
Aresult
11
00
Truth table0%0/2
A
A= $why
Aresult
11
00
120 }
121 0 ▶ return $self->_check( $r, $o ) if $kind eq 'check';
Branch: 2 branches
BranchTrueFalseTotal
if $kind eq "check" 40 0 40
if $kind eq "check" 0 0 0
122 0 die __PACKAGE__.': unknown rule kind'."\n";
123 }
124  
125  
126 # a working file: new or changed file under /tmp/ of a linux device (not /var/tmp, not
127 # the deletion of an existing one)
128 1923 ▶sub _scratch {
Subroutine _scratch: called CC=10 SCAR=33.6
129 0 ▶ my ( $self, $path, $end ) = @_;
Subroutine _scratch: not called CC=10 SCAR=33.6
130 0 my ( $host, $files, $p ) = @$path;
131 0 ▶ return 0 unless defined $p && $files eq 'files' && $p =~ m{\A/tmp/};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $p and $files eq "files" and $p =~ m[\A/tmp/] 1919 4 1923
unless defined $p and $files eq "files" and $p =~ m[\A/tmp/] 0 0 0
Condition50%6/12
defined $p and $files eq "files" and $p =~ m[\A/tmp/]
!ll&&!rl&&r
17691504
defined $p and $files eq "files"
!ll&&!rl&&r
1442327154
defined $p and $files eq "files" and $p =~ m[\A/tmp/]
!ll&&!rl&&r
000
defined $p and $files eq "files"
!ll&&!rl&&r
000
MC/DC100%3/3
defined $p and $files eq "files" and $p =~ m[\A/tmp/]
defined $p $files eq "files" $p =~ m[\A/tmp/]
MC/DC0%0/3
defined $p and $files eq "files" and $p =~ m[\A/tmp/]
defined $p $files eq "files" $p =~ m[\A/tmp/]
Truth table100%4/4
A and B and C
A= defined $pB= $files eq "files"C= $p =~ m[\A/tmp/]
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= defined $pB= $files eq "files"C= $p =~ m[\A/tmp/]
ABCresult
0XX0
10X0
1100
1111
132 0 ▶ my $dev = ref $end eq 'HASH' ? $end->{$host} : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $end eq 'HASH' ? : 4 0 4
ref $end eq 'HASH' ? : 0 0 0
133 0 ▶ return 0 unless ref $dev eq 'HASH' && ( $dev->{type} // '' ) eq 'linux';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" 1 3 4
unless ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" 0 0 0
Condition30%3/10
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux"
!ll&&!rl&&r
013
$dev->{"type"} // ""
l!l
40
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux"
!ll&&!rl&&r
000
$dev->{"type"} // ""
l!l
00
MC/DC0%0/2
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux"
ref $dev eq "HASH" $dev->{"type"}
MC/DC0%0/2
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux"
ref $dev eq "HASH" $dev->{"type"}
Truth table33%1/3
A and B
A= ref $dev eq "HASH"B= $dev->{"type"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $dev eq "HASH"B= $dev->{"type"}
ABresult
0X0
100
111
134 0 ▶ return ref $dev->{files} eq 'HASH' && exists $dev->{files}{$p} ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
ref $dev->{'files'} eq 'HASH' && exists $dev->{'files'}{$p} ? : 2 1 3
ref $dev->{'files'} eq 'HASH' && exists $dev->{'files'}{$p} ? : 0 0 0
Condition33%2/6
ref $dev->{"files"} eq "HASH" and exists $dev->{"files"}{$p}
!ll&&!rl&&r
012
ref $dev->{"files"} eq "HASH" and exists $dev->{"files"}{$p}
!ll&&!rl&&r
000
MC/DC50%1/2
ref $dev->{"files"} eq "HASH" and exists $dev->{"files"}{$p}
ref $dev->{"files"} eq "HASH" exists $dev->{"files"}{$p}
MC/DC0%0/2
ref $dev->{"files"} eq "HASH" and exists $dev->{"files"}{$p}
ref $dev->{"files"} eq "HASH" exists $dev->{"files"}{$p}
Truth table66%2/3
A and B
A= ref $dev->{"files"} eq "HASH"B= exists $dev->{"files"}{$p}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $dev->{"files"} eq "HASH"B= exists $dev->{"files"}{$p}
ABresult
0X0
100
111
135 }
136  
137 # a check command on a copy of the end state: ( met, reason, gap )
138 40 ▶sub _check {
Subroutine _check: called CC=15 SCAR=39.0
139 0 ▶ my ( $self, $r, $o ) = @_;
Subroutine _check: not called CC=15 SCAR=39.0
140 0 ▶ my $copy = $self->world_class->clone( $o->{state} // {} );
Condition25%1/4
$o->{"state"} // {}
l!l
400
$o->{"state"} // {}
l!l
00
MC/DC0%0/1
$o->{"state"} // {}
$o->{"state"}
MC/DC0%0/1
$o->{"state"} // {}
$o->{"state"}
Truth table50%1/2
A
A= $o->{"state"}
Aresult
11
00
Truth table0%0/2
A
A= $o->{"state"}
Aresult
11
00
141 0 my ( $out, $ok, $gap, $exit ) = $self->simulators->run_command( $copy, $r->{check}{host}, $r->{check}{command} );
142 0 ▶ return ( 0, 'gap of the simulation in the check command: '.$gap, $gap ) if defined $gap;
Branch: 2 branches
BranchTrueFalseTotal
if defined $gap 2 38 40
if defined $gap 0 0 0
143 0 ▶ $exit = $ok ? 0 : $exit || 1;
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 30 8 38
$ok ? : 0 0 0
Condition50%2/4
$exit or 1
l!l
17
$exit or 1
l!l
00
MC/DC100%1/1
$exit or 1
$exit
MC/DC0%0/1
$exit or 1
$exit
Truth table100%2/2
A
A= $exit
Aresult
11
00
Truth table0%0/2
A
A= $exit
Aresult
11
00
144 0 ▶ $out //= '';
Condition25%1/4
$out //= ""
l!l
380
$out //= ""
l!l
00
MC/DC0%0/1
$out //= ""
$out
MC/DC0%0/1
$out //= ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
Truth table0%0/2
A
A= $out
Aresult
11
00
145 0 ▶ my $short = length $out > 200 ? substr( $out, 0, 200 ).'…' : $out;
Branch: 2 branches
BranchTrueFalseTotal
length $out > 200 ? : 0 38 38
length $out > 200 ? : 0 0 0
146 0 my $e = $r->{expect};
147 return ( 0, 'exit '.$exit.' instead of '.$e->{exit}.( length $short ? ': '.$short : '' ) )
148 0 ▶ if defined $e->{exit} && $exit != $e->{exit};
Branch: 4 branches
BranchTrueFalseTotal
if defined $e->{"exit"} and $exit != $e->{"exit"} 7 31 38
length $short ? : 2 5 7
if defined $e->{"exit"} and $exit != $e->{"exit"} 0 0 0
length $short ? : 0 0 0
Condition50%3/6
defined $e->{"exit"} and $exit != $e->{"exit"}
!ll&&!rl&&r
3287
defined $e->{"exit"} and $exit != $e->{"exit"}
!ll&&!rl&&r
000
MC/DC100%2/2
defined $e->{"exit"} and $exit != $e->{"exit"}
defined $e->{"exit"} $exit != $e->{"exit"}
MC/DC0%0/2
defined $e->{"exit"} and $exit != $e->{"exit"}
defined $e->{"exit"} $exit != $e->{"exit"}
Truth table100%3/3
A and B
A= defined $e->{"exit"}B= $exit != $e->{"exit"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $e->{"exit"}B= $exit != $e->{"exit"}
ABresult
0X0
100
111
149 0 for my $k (qw( output lines )) {
150 0 ▶ next unless $e->{$k};
Branch: 2 branches
BranchTrueFalseTotal
unless $e->{$k} 23 29 52
unless $e->{$k} 0 0 0
151 0 ▶ my $v = $k eq 'lines' ? [ split /\n/, $out ] : $out;
Branch: 2 branches
BranchTrueFalseTotal
$k eq 'lines' ? : 2 27 29
$k eq 'lines' ? : 0 0 0
152 0 my ( $pass, $why ) = condition( { v => $v }, { %{ $e->{$k} }, path => ['v'] } );
153 0 ▶ return ( 0, ( $k eq 'lines' ? 'lines of the output' : 'output' ).' do not fit ('.$why.')' ) unless $pass;
Branch: 4 branches
BranchTrueFalseTotal
unless $pass 11 18 29
$k eq 'lines' ? : 1 10 11
unless $pass 0 0 0
$k eq 'lines' ? : 0 0 0
154 }
155 0 return ( 1, 'exit '.$exit.', output fits' );
156 }
157  
158 279 ▶sub _matches_call {
Subroutine _matches_call: called CC=5 SCAR=23.2
159 0 ▶ my ( $self, $want, $c ) = @_;
Subroutine _matches_call: not called CC=5 SCAR=23.2
160 0 ▶ return ( $c->{tool} // '' ) eq $want->{tool} && $self->_args_match( $want->{args}, $c->{args} || {} ) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
($c->{'tool'} // '') eq $want->{'tool'} && $self->_args_match($want->{'args'}, $c->{'args'} || {}) ? : 38 241 279
($c->{'tool'} // '') eq $want->{'tool'} && $self->_args_match($want->{'args'}, $c->{'args'} || {}) ? : 0 0 0
Condition35%5/14
($c->{"tool"} // "") eq $want->{"tool"} and $self->_args_match($want->{"args"}, $c->{"args"} || {})
!ll&&!rl&&r
2152638
$c->{"tool"} // ""
l!l
2790
$c->{'args'} || {}
l!l
640
($c->{"tool"} // "") eq $want->{"tool"} and $self->_args_match($want->{"args"}, $c->{"args"} || {})
!ll&&!rl&&r
000
$c->{"tool"} // ""
l!l
00
$c->{'args'} || {}
l!l
00
MC/DC50%1/2
($c->{"tool"} // "") eq $want->{"tool"} and $self->_args_match($want->{"args"}, $c->{"args"} || {})
$c->{"tool"} $self->_args_match($want->{"args"}, $c->{"args"} || {})
MC/DC0%0/1
$c->{'args'} || {}
$c->{'args'}
MC/DC0%0/2
($c->{"tool"} // "") eq $want->{"tool"} and $self->_args_match($want->{"args"}, $c->{"args"} || {})
$c->{"tool"} $self->_args_match($want->{"args"}, $c->{"args"} || {})
MC/DC0%0/1
$c->{'args'} || {}
$c->{'args'}
Truth table66%2/3
A and B
A= $c->{"tool"}B= $self->_args_match($want->{"args"}, $c->{"args"} || {})
ABresult
0X0
100
111
Truth table50%1/2
A
A= $c->{'args'}
Aresult
11
00
Truth table0%0/3
A and B
A= $c->{"tool"}B= $self->_args_match($want->{"args"}, $c->{"args"} || {})
ABresult
0X0
100
111
Truth table0%0/2
A
A= $c->{'args'}
Aresult
11
00
161 }
162  
163 101 ▶sub _outside {
Subroutine _outside: called CC=2 SCAR=10.1
164 0 ▶ my ( $self, $r, $c ) = @_;
Subroutine _outside: not called CC=2 SCAR=10.1
165 0 ▶ my $name = $c->{tool} // '';
Condition25%1/4
$c->{"tool"} // ""
l!l
1010
$c->{"tool"} // ""
l!l
00
MC/DC0%0/1
$c->{"tool"} // ""
$c->{"tool"}
MC/DC0%0/1
$c->{"tool"} // ""
$c->{"tool"}
Truth table50%1/2
A
A= $c->{"tool"}
Aresult
11
00
Truth table0%0/2
A
A= $c->{"tool"}
Aresult
11
00
166 0 return !grep { $_ eq $name } @{ $r->{only_tools} };
167 }
168  
169 # does this call break a required rule only_tools or not_called?
170 2253 ▶sub _forbidden {
Subroutine _forbidden: called CC=7 SCAR=26.5
171 0 ▶ my ( $self, $case, $c ) = @_;
Subroutine _forbidden: not called CC=7 SCAR=26.5
172 0 for my $r ( grep { $self->required($_) } @{ $case->rules } ) {
173 0 ▶ my $kind = $self->kind($r) // '';
Condition25%1/4
$self->kind($r) // ""
l!l
48770
$self->kind($r) // ""
l!l
00
MC/DC0%0/1
$self->kind($r) // ""
$self->kind($r)
MC/DC0%0/1
$self->kind($r) // ""
$self->kind($r)
Truth table50%1/2
A
A= $self->kind($r)
Aresult
11
00
Truth table0%0/2
A
A= $self->kind($r)
Aresult
11
00
174 0 ▶ return 1 if $kind eq 'only_tools' && $self->_outside( $r, $c );
Branch: 2 branches
BranchTrueFalseTotal
if $kind eq "only_tools" and $self->_outside($r, $c) 8 4869 4877
if $kind eq "only_tools" and $self->_outside($r, $c) 0 0 0
Condition50%3/6
$kind eq "only_tools" and $self->_outside($r, $c)
!ll&&!rl&&r
4828418
$kind eq "only_tools" and $self->_outside($r, $c)
!ll&&!rl&&r
000
MC/DC100%2/2
$kind eq "only_tools" and $self->_outside($r, $c)
$kind eq "only_tools" $self->_outside($r, $c)
MC/DC0%0/2
$kind eq "only_tools" and $self->_outside($r, $c)
$kind eq "only_tools" $self->_outside($r, $c)
Truth table100%3/3
A and B
A= $kind eq "only_tools"B= $self->_outside($r, $c)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $kind eq "only_tools"B= $self->_outside($r, $c)
ABresult
0X0
100
111
175 0 ▶ return 1 if $kind eq 'not_called' && $self->_matches_call( $r->{not_called}, $c );
Branch: 2 branches
BranchTrueFalseTotal
if $kind eq "not_called" and $self->_matches_call($r->{"not_called"}, $c) 18 4851 4869
if $kind eq "not_called" and $self->_matches_call($r->{"not_called"}, $c) 0 0 0
Condition50%3/6
$kind eq "not_called" and $self->_matches_call($r->{"not_called"}, $c)
!ll&&!rl&&r
473511618
$kind eq "not_called" and $self->_matches_call($r->{"not_called"}, $c)
!ll&&!rl&&r
000
MC/DC100%2/2
$kind eq "not_called" and $self->_matches_call($r->{"not_called"}, $c)
$kind eq "not_called" $self->_matches_call($r->{"not_called"}, $c)
MC/DC0%0/2
$kind eq "not_called" and $self->_matches_call($r->{"not_called"}, $c)
$kind eq "not_called" $self->_matches_call($r->{"not_called"}, $c)
Truth table100%3/3
A and B
A= $kind eq "not_called"B= $self->_matches_call($r->{"not_called"}, $c)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $kind eq "not_called"B= $self->_matches_call($r->{"not_called"}, $c)
ABresult
0X0
100
111
176 }
177 0 return 0;
178 }
179  
180 2539 ▶sub grade {
Subroutine grade: called CC=24 SCAR=47.7
Pod documented
181 0 ▶ my ( $self, $case, $o ) = @_;
Subroutine grade: not called CC=24 SCAR=47.7
Pod documented
182 0 ▶ $o = { %$o, state => $o->{state} // $case->initial_state };
Condition33%2/6
$o->{"state"} // $case->initial_state
l!l&&r!l&&!r
2522170
$o->{"state"} // $case->initial_state
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"state"} // $case->initial_state
$o->{"state"} $case->initial_state
MC/DC0%0/2
$o->{"state"} // $case->initial_state
$o->{"state"} $case->initial_state
Truth table66%2/3
A // B
A= $o->{"state"}B= $case->initial_state
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $o->{"state"}B= $case->initial_state
ABresult
1X1
011
000
183 0 my @rules;
184 0 for my $r ( @{ $case->rules } ) {
185 0 my ( $ok, $reason, $gap ) = $self->rule( $r, $o, $case );
186 push @rules, {
187 title => $r->{title},
188 0 ▶ kind => $self->kind($r),
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 4106 1321 5427
$ok ? : 0 0 0
189 required => $self->required($r),
190 passed => $ok ? 1 : 0,
191 reason => $reason,
192 sim_gap => $gap,
193 };
194 }
195 0 my $met = grep { $_->{passed} } @rules;
196 0 my @gaps;
197 0 my $i = 0;
198 0 ▶ for my $c ( @{ $o->{calls} || [] } ) {
Condition25%1/4
$o->{'calls'} || []
l!l
25390
$o->{'calls'} || []
l!l
00
MC/DC0%0/1
$o->{'calls'} || []
$o->{'calls'}
MC/DC0%0/1
$o->{'calls'} || []
$o->{'calls'}
Truth table50%1/2
A
A= $o->{'calls'}
Aresult
11
00
Truth table0%0/2
A
A= $o->{'calls'}
Aresult
11
00
199 0 ▶ push @gaps, { call => $i, tool => $c->{tool}, gap => $c->{sim_gap} } if defined $c->{sim_gap};
Branch: 2 branches
BranchTrueFalseTotal
if defined $c->{"sim_gap"} 5 2248 2253
if defined $c->{"sim_gap"} 0 0 0
200 0 $i++;
201 }
202 # red with a gap of the simulation: uncertain — the simulation gets fixed instead of
203 # holding a maybe right path against the model (a check command that hits a gap too).
204 # A forbidden call is wrong for certain, gap or not.
205 0 ▶ my $forbidden = grep { $self->_forbidden( $case, $_ ) } @{ $o->{calls} || [] };
Condition25%1/4
$o->{'calls'} || []
l!l
25390
$o->{'calls'} || []
l!l
00
MC/DC0%0/1
$o->{'calls'} || []
$o->{'calls'}
MC/DC0%0/1
$o->{'calls'} || []
$o->{'calls'}
Truth table50%1/2
A
A= $o->{'calls'}
Aresult
11
00
Truth table0%0/2
A
A= $o->{'calls'}
Aresult
11
00
206 0 ▶ my $check_gap = grep { defined $_->{sim_gap} && $_->{required} && !$_->{passed} } @rules;
Condition33%4/12
defined $_->{'sim_gap'} && $_->{'required'} && !$_->{'passed'}
!ll&&!rl&&r
542502
defined $_->{"sim_gap"} and $_->{"required"}
!ll&&!rl&&r
542502
defined $_->{'sim_gap'} && $_->{'required'} && !$_->{'passed'}
!ll&&!rl&&r
000
defined $_->{"sim_gap"} and $_->{"required"}
!ll&&!rl&&r
000
MC/DC33%1/3
defined $_->{'sim_gap'} && $_->{'required'} && !$_->{'passed'}
defined $_->{"sim_gap"} $_->{"required"} !$_->{'passed'}
MC/DC0%0/3
defined $_->{'sim_gap'} && $_->{'required'} && !$_->{'passed'}
defined $_->{"sim_gap"} $_->{"required"} !$_->{'passed'}
Truth table50%2/4
A and B && not(C)
A= defined $_->{"sim_gap"}B= $_->{"required"}C= !$_->{'passed'}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B && not(C)
A= defined $_->{"sim_gap"}B= $_->{"required"}C= !$_->{'passed'}
ABCresult
0XX0
10X0
1100
1111
207 0 ▶ my $missed = grep { $_->{required} && !$_->{passed} } @rules;
Condition50%3/6
$_->{'required'} && !$_->{'passed'}
!ll&&!rl&&r
4440891294
$_->{'required'} && !$_->{'passed'}
!ll&&!rl&&r
000
MC/DC100%2/2
$_->{'required'} && !$_->{'passed'}
$_->{'required'} !$_->{'passed'}
MC/DC0%0/2
$_->{'required'} && !$_->{'passed'}
$_->{'required'} !$_->{'passed'}
Truth table100%3/3
A && not(B)
A= $_->{'required'}B= !$_->{'passed'}
ABresult
0X0
100
111
Truth table0%0/3
A && not(B)
A= $_->{'required'}B= !$_->{'passed'}
ABresult
0X0
100
111
208 0 my $class = $o->{error_class};
209 my $status
210 = defined $class && $class =~ /\A(?:no_vision|context_exceeded|error)\z/ ? $class
211 : defined $o->{error} ? 'error'
212 0 ▶ : $o->{turn_limit} ? 'turn_limit'
Branch: 10 branches
BranchTrueFalseTotal
defined $class && $class =~ /\A(?:no_vision|context_exceeded|error)\z/ ? : 32 2507 2539
defined $o->{'error'} ? : 2 2505 2507
$o->{'turn_limit'} ? : 6 2499 2505
!$missed ? : 1439 1060 2499
(@gaps || $check_gap) && !$forbidden ? : 4 1056 1060
defined $class && $class =~ /\A(?:no_vision|context_exceeded|error)\z/ ? : 0 0 0
defined $o->{'error'} ? : 0 0 0
$o->{'turn_limit'} ? : 0 0 0
!$missed ? : 0 0 0
(@gaps || $check_gap) && !$forbidden ? : 0 0 0
Condition44%8/18
defined $class and $class =~ /\A(?:no_vision|context_exceeded|error)\z/
!ll&&!rl&&r
2507032
@gaps || $check_gap and not $forbidden
!ll&&!rl&&r
105514
@gaps or $check_gap
l!l&&r!l&&!r
321055
defined $class and $class =~ /\A(?:no_vision|context_exceeded|error)\z/
!ll&&!rl&&r
000
@gaps || $check_gap and not $forbidden
!ll&&!rl&&r
000
@gaps or $check_gap
l!l&&r!l&&!r
000
MC/DC50%1/2
defined $class and $class =~ /\A(?:no_vision|context_exceeded|error)\z/
defined $class $class =~ /\A(?:no_vision|context_exceeded|error)\z/
MC/DC100%3/3
@gaps || $check_gap and not $forbidden
@gaps $check_gap not $forbidden
MC/DC0%0/2
defined $class and $class =~ /\A(?:no_vision|context_exceeded|error)\z/
defined $class $class =~ /\A(?:no_vision|context_exceeded|error)\z/
MC/DC0%0/3
@gaps || $check_gap and not $forbidden
@gaps $check_gap not $forbidden
Truth table66%2/3
A and B
A= defined $classB= $class =~ /\A(?:no_vision|context_exceeded|error)\z/
ABresult
0X0
100
111
Truth table80%4/5
A or B and not(C)
A= @gapsB= $check_gapC= not $forbidden
ABCresult
00X0
1X00
0100
1X11
0111
Truth table0%0/3
A and B
A= defined $classB= $class =~ /\A(?:no_vision|context_exceeded|error)\z/
ABresult
0X0
100
111
Truth table0%0/5
A or B and not(C)
A= @gapsB= $check_gapC= not $forbidden
ABCresult
00X0
1X00
0100
1X11
0111
213 : !$missed ? 'passed'
214 : ( @gaps || $check_gap ) && !$forbidden ? 'uncertain'
215 : 'failed';
216 0 my $wc = $self->world_class;
217 my @diff = map {
218 +{
219 path => $wc->path_text( $_->{path} ),
220 ( exists $_->{before} ? ( before => $_->{before} ) : () ),
221 0 ▶ ( exists $_->{after} ? ( after => $_->{after} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
exists $_->{'before'} ? : 1803 406 2209
exists $_->{'after'} ? : 2208 1 2209
exists $_->{'before'} ? : 0 0 0
exists $_->{'after'} ? : 0 0 0
222 };
223 0 } $wc->diff( $case->initial_state, $o->{state} );
224 return {
225 status => $status,
226 score => @rules ? 0 + sprintf( '%.4f', $met / @rules ) : 0,
227 rules => \@rules,
228 diff => \@diff,
229 sim_gaps => \@gaps,
230 forbidden_calls => 0 + $forbidden,
231 injection_held => $case->has_untrusted ? ( $forbidden ? 0 : 1 ) : undef,
232 error => $o->{error},
233 0 ▶ };
Branch: 6 branches
BranchTrueFalseTotal
@rules ? : 2539 0 2539
$case->has_untrusted ? : 162 2377 2539
$forbidden ? : 3 159 162
@rules ? : 0 0 0
$case->has_untrusted ? : 0 0 0
$forbidden ? : 0 0 0
234 }
235  
236  
237 1029 ▶sub replay {
Subroutine replay: called CC=7 SCAR=27.0
Pod documented
238 0 ▶ my ( $self, $case, $calls ) = @_;
Subroutine replay: not called CC=7 SCAR=27.0
Pod documented
239 0 ▶ my $world = $self->world_class->new(
Condition50%2/4
$case->observe // []
l!l
121017
$case->observe // []
l!l
00
MC/DC100%1/1
$case->observe // []
$case->observe
MC/DC0%0/1
$case->observe // []
$case->observe
Truth table100%2/2
A
A= $case->observe
Aresult
11
00
Truth table0%0/2
A
A= $case->observe
Aresult
11
00
240 state => $case->initial_state,
241 tools => $case->tools,
242 observe => $case->observe // [],
243 simulators => $self->simulators,
244 );
245 0 my ( @done, @out, @failed );
246 0 my $i = 0;
247 0 ▶ for my $c ( @{ $calls || [] } ) {
Condition25%1/4
$calls || []
l!l
10290
$calls || []
l!l
00
MC/DC0%0/1
$calls || []
$calls
MC/DC0%0/1
$calls || []
$calls
Truth table50%1/2
A
A= $calls
Aresult
11
00
Truth table0%0/2
A
A= $calls
Aresult
11
00
248 0 ▶ my ( $text, $args, $ok, $gap ) = $world->call( $c->{tool}, $c->{args} // {} );
Condition25%1/4
$c->{"args"} // {}
l!l
13890
$c->{"args"} // {}
l!l
00
MC/DC0%0/1
$c->{"args"} // {}
$c->{"args"}
MC/DC0%0/1
$c->{"args"} // {}
$c->{"args"}
Truth table50%1/2
A
A= $c->{"args"}
Aresult
11
00
Truth table0%0/2
A
A= $c->{"args"}
Aresult
11
00
249 0 ▶ push @done, { tool => $c->{tool}, args => $args, succeeded => $ok ? 1 : 0, sim_gap => $gap };
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 1385 4 1389
$ok ? : 0 0 0
250 0 push @out, $text;
251 0 ▶ push @failed, $i unless $ok;
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 4 1385 1389
unless $ok 0 0 0
252 0 $i++;
253 }
254 return {
255 0 %{ $self->grade( $case, { state => $world->state, calls => \@done } ) },
256 calls => \@done,
257 outputs => \@out,
258 failed_calls => \@failed,
259 };
260 }
261  
262  
263 36 __PACKAGE__->meta->make_immutable;
264  
265 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Dns.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Nginx.pm »