Virt/Transport.pm

filter: Statementstmt 10.9% 17 / 155 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 37 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 38.4% 5 / 13 Podpod 100% 4 / 4 totaltotal 8.6% 26 / 300 CC 49 SCAR 55.9
CC
49
Cov
6%
_send
420.0
_receive
272.0
_dispatch
240.0
CRAP 268.3
« Virt/Transport/XDR.pm ↑ Summary Virt/Remote/XDR.pm »
1 ####################################################################
2 #
3 # This file was generated using XDR::Parse version v1.0.1,
4 # XDR::Gen version 1.1.2 and LibVirt version v12.9.0
5 #
6 # Don't edit this file, use the source template instead
7 #
8 # ANY CHANGES HERE WILL BE LOST !
9 #
10 ####################################################################
11  
12  
13 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 package Protocol::Sys::Virt::Transport v12.9.0;
17  
18 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Protocol::Sys::Virt::Transport::XDR;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 my $msgs = 'Protocol::Sys::Virt::Transport::XDR';
24  
25 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
26 0 my ($class, %args) = @_;
27 return bless {
28 buf => '',
29 fds => undef,
30 expect => 'START', # first state of the state machine...
31 want => -1,
32 need_length => 4,
33 need_type => 'data',
34 role => $args{role},
35 serial => 1,
36 prog_cb => {},
37 on_send => $args{on_send},
38 0 }, $class;
39 };
40  
41 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod documented
42 0 my ($self, $prog, $version, $callbacks) = @_;
43 0 $self->{prog_cb}->{$prog} = $callbacks;
44  
45 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 return $self->_send( $prog, $version, @_ );
47 0 };
48 }
49  
50 1 my @dispatch = qw(
51 on_call on_reply on_message on_stream
52 on_call on_reply on_stream );
53  
54  
55 0 ▶sub _dispatch {
Subroutine _dispatch: not called CC=15 SCAR=54.8
56 0 my ($self) = @_;
57 0 my $data = $self->{payload};
58 0 my $fds = $self->{fds};
59 0 my $hdr = $self->{hdr};
60 0 my $status = $hdr->{status};
61 0 my $type = $hdr->{type};
62 0 my $prog = $hdr->{prog};
63  
64 0 ▶ if ($status == $msgs->OK) {
Branch: 3 branches
BranchTrueFalseTotal
if ($status == $msgs->OK) { } 0 0 0
elsif ($status == $msgs->ERROR) { } 0 0 0
elsif ($status == $msgs->CONTINUE) { } 0 0 0
65 0 ▶ if ($type < 0 or $type > $#dispatch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type < 0 or $type > $#dispatch) 0 0 0
Condition0%0/3
$type < 0 or $type > $#dispatch
l!l&&r!l&&!r
000
MC/DC0%0/2
$type < 0 or $type > $#dispatch
$type < 0 $type > $#dispatch
Truth table0%0/3
A or B
A= $type < 0B= $type > $#dispatch
ABresult
1X1
011
000
66 0 croak $log->fatal("Unsupported frame type $type");
67 }
68  
69 0 my $hole;
70 0 ▶ if ($type == $msgs->STREAM_HOLE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == $msgs->STREAM_HOLE) 0 0 0
71 0 my $idx = 0;
72 0 $msgs->deserialize_StreamHole( $hole, $idx, $self->{buf} );
73 0 $self->{buf} = substr( $self->{buf}, $idx );
74  
75 0 $data = undef;
76 }
77 0 $log->trace("Invoking callback $dispatch[$type] on program $prog");
78 0 return $self->{prog_cb}->{$prog}->{$dispatch[$type]}->(
79 header => $hdr,
80 data => $data,
81 fds => $fds,
82 hole => $hole
83 );
84 }
85 elsif ($status == $msgs->ERROR) {
86 0 ▶ if ($type == $msgs->STREAM
Branch: 1 branch
BranchTrueFalseTotal
if ($type == $msgs->STREAM and $self->{"role"} eq "server") 0 0 0
Condition0%0/3
$type == $msgs->STREAM and $self->{"role"} eq "server"
!ll&&!rl&&r
000
MC/DC0%0/2
$type == $msgs->STREAM and $self->{"role"} eq "server"
$type == $msgs->STREAM $self->{"role"} eq "server"
Truth table0%0/3
A and B
A= $type == $msgs->STREAMB= $self->{"role"} eq "server"
ABresult
0X0
100
111
87 and $self->{role} eq 'server') { # client message
88 # no payload
89 0 return $self->{prog_cb}->{$prog}->{on_stream}->(
90 header => $hdr,
91 );
92 }
93  
94 #deserialize the server error...
95 0 my $err;
96 0 my $idx = 0;
97 0 $msgs->deserialize_Error( $err, $idx, $data );
98 0 ▶ if ($type == $msgs->REPLY
Branch: 1 branch
BranchTrueFalseTotal
if ($type == $msgs->REPLY or $type == $msgs->STREAM or $type == $msgs->STREAM_HOLE or $type == $msgs->REPLY_WITH_FDS) { } 0 0 0
Condition0%0/9
$type == $msgs->REPLY or $type == $msgs->STREAM or $type == $msgs->STREAM_HOLE or $type == $msgs->REPLY_WITH_FDS
l!l&&r!l&&!r
000
$type == $msgs->REPLY or $type == $msgs->STREAM or $type == $msgs->STREAM_HOLE
l!l&&r!l&&!r
000
$type == $msgs->REPLY or $type == $msgs->STREAM
l!l&&r!l&&!r
000
MC/DC0%0/4
$type == $msgs->REPLY or $type == $msgs->STREAM or $type == $msgs->STREAM_HOLE or $type == $msgs->REPLY_WITH_FDS
$type == $msgs->REPLY $type == $msgs->STREAM $type == $msgs->STREAM_HOLE $type == $msgs->REPLY_WITH_FDS
Truth table0%0/5
A or B or C or D
A= $type == $msgs->REPLYB= $type == $msgs->STREAMC= $type == $msgs->STREAM_HOLED= $type == $msgs->REPLY_WITH_FDS
ABCDresult
1XXX1
01XX1
001X1
00011
00000
99 or $type == $msgs->STREAM
100 or $type == $msgs->STREAM_HOLE
101 or $type == $msgs->REPLY_WITH_FDS) {
102 0 $log->trace("Invoking callback $dispatch[$type] on program $prog");
103 0 return $self->{prog_cb}->{$prog}->{$dispatch[$type]}->(
104 header => $hdr,
105 error => $err,
106 );
107 }
108 else {
109 0 croak $log->fatal( "Status ERROR not supported on frame type $type" );
110 }
111 }
112 elsif ($status == $msgs->CONTINUE) {
113 0 ▶ if ($type == $msgs->STREAM) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == $msgs->STREAM) { } 0 0 0
elsif ($type == $msgs->STREAM_HOLE) { } 0 0 0
114 0 return $self->{prog_cb}->{$prog}->{on_stream}->(
115 header => $hdr,
116 data => $data
117 );
118 }
119 elsif ($type == $msgs->STREAM_HOLE) {
120 0 my $hole;
121 0 my $idx = 0;
122 0 $msgs->deserialize_StreamHole( $hole, $idx, $self->{buf} );
123 0 $log->trace("Invoking callback $dispatch[$type] on program $prog");
124 0 return $self->{prog_cb}->{$prog}->{on_stream}->(
125 header => $hdr,
126 hole => $hole
127 );
128 }
129 else {
130 0 croak $log->fatal( "Status CONTINUE not supported on frame type $type" );
131 }
132 }
133 else {
134 0 croak $log->fatal( "Unsupported 'status' value ($status)" );
135 }
136  
137 # unreachable
138 }
139  
140 # state machine
141 #
142 # states:
143 # START (nothing happened yet)
144 # FRAMELEN (awaiting 4 bytes of data)
145 # FRAMEDATA (awaiting remaining data)
146 # FD (awaiting file descriptors)
147  
148 0 ▶sub _receive {
Subroutine _receive: not called CC=16 SCAR=56.1
149 0 my ($self, $data) = @_;
150 0 my @dispatch_values = ();
151  
152 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
153 0 ▶ if ($self->{expect} eq 'FD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'expect'} eq 'FD') { } 0 0 0
154 0 push @{ $self->{fds} }, $data;
155 }
156 else {
157 0 $self->{buf} .= $data;
158 }
159 }
160  
161 0 while (1) {
162 0 ▶ if ($self->{expect} eq 'START') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect"} eq "START") 0 0 0
163 0 $self->{want} = 4;
164 0 $self->{want_fds} = 0;
165 0 $self->{fds} = undef;
166 0 $self->{payload} = '';
167  
168 0 $self->{expect} = 'FRAMELEN';
169 }
170 0 ▶ if ($self->{expect} eq 'FRAMELEN') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect"} eq "FRAMELEN") 0 0 0
171 0 my $len = length($self->{buf});
172 0 ▶ if ($self->{want} > $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want"} > $len) 0 0 0
173 0 $self->{need_length} = $self->{want} - $len;
174 0 $self->{need_type} = 'data';
175 0 last;
176 }
177 0 $self->{want} = unpack('L>', $self->{buf} );
178 0 ▶ if ($self->{want} < ($msgs->LEN_MAX
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want"} < $msgs->LEN_MAX + $msgs->HEADER_MAX) 0 0 0
179 + $msgs->HEADER_MAX)) {
180 0 croak $log->fatal(
181 "Received message too short (length: $self->{want})" );
182 }
183 0 ▶ if ($self->{want} > $msgs->STRING_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want"} > $msgs->STRING_MAX) 0 0 0
184 0 croak $log->fatal(
185 "Received message too big (length: $self->{want})" );
186 }
187  
188 0 $self->{expect} = 'FRAMEDATA';
189 }
190 0 ▶ if ($self->{expect} eq 'FRAMEDATA') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect"} eq "FRAMEDATA") 0 0 0
191 0 my $len = length($self->{buf});
192 0 ▶ if ($self->{want} > $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want"} > $len) 0 0 0
193 0 $self->{need_length} = $self->{want} - $len;
194 0 $self->{need_type} = 'data';
195 0 last;
196 }
197  
198 # we have our frame
199 0 my $idx = 4;
200 0 my $hdr = {};
201 0 $msgs->deserialize_Header( $hdr, $idx, $self->{buf} );
202 0 $self->{hdr} = $hdr;
203  
204 0 my $type = $hdr->{type};
205 0 my $status = $hdr->{status};
206 0 ▶ if ($status == $msgs->OK
Branch: 1 branch
BranchTrueFalseTotal
if ($status == $msgs->OK and $type == $msgs->CALL_WITH_FDS || $type == $msgs->REPLY_WITH_FDS) 0 0 0
Condition0%0/6
$status == $msgs->OK and $type == $msgs->CALL_WITH_FDS || $type == $msgs->REPLY_WITH_FDS
!ll&&!rl&&r
000
$type == $msgs->CALL_WITH_FDS or $type == $msgs->REPLY_WITH_FDS
l!l&&r!l&&!r
000
MC/DC0%0/3
$status == $msgs->OK and $type == $msgs->CALL_WITH_FDS || $type == $msgs->REPLY_WITH_FDS
$status == $msgs->OK $type == $msgs->CALL_WITH_FDS $type == $msgs->REPLY_WITH_FDS
Truth table0%0/4
A and B or C
A= $status == $msgs->OKB= $type == $msgs->CALL_WITH_FDSC= $type == $msgs->REPLY_WITH_FDS
ABCresult
0XX0
1000
11X1
1011
207 and ($type == $msgs->CALL_WITH_FDS
208 or $type == $msgs->REPLY_WITH_FDS)) {
209 $self->{want_fds} =
210 0 unpack('L>', substr( $self->{buf}, $idx, 4 ));
211 0 $self->{fds} = [];
212 0 $idx += 4;
213  
214 0 $self->{expect} = 'FD';
215 }
216 $self->{payload} =
217 0 substr( $self->{buf}, $idx, $self->{want} - $idx );
218 0 $self->{buf} = '' . substr( $self->{buf}, $self->{want} );
219 }
220 0 ▶ if ($self->{expect} eq 'FD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect"} eq "FD") 0 0 0
221 0 my $len = scalar( @{ $self->{fds} } );
222 0 ▶ if ($self->{want_fds} > $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want_fds"} > $len) 0 0 0
223 0 $self->{need_length} = $self->{want_fds} - $len;
224 0 $self->{need_type} = 'fd';
225 0 last;
226 }
227 }
228 # we have our frame *and* (optionally) FDs
229  
230 0 my $dv = $self->_dispatch;
231 0 ▶ push @dispatch_values, $dv if defined $dv;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dv 0 0 0
232  
233 0 $self->{expect} = 'START';
234 }
235  
236 0 return @dispatch_values;
237 }
238  
239  
240 0 ▶sub need {
Subroutine need: not called CC=1 SCAR=6.9
Pod documented
241 0 my $self = shift;
242 0 return ($self->{need_length}, $self->{need_type});
243 }
244  
245 0 ▶sub receive {
Subroutine receive: not called CC=1 SCAR=6.9
Pod documented
246 0 my ($self, $data, %args) = @_;
247  
248 0 return $self->_receive($data, %args);
249 }
250  
251 0 ▶sub _send {
Subroutine _send: not called CC=20 SCAR=60.4
252 0 my ($self, $prog, $version, $proc, $type, %args) = @_;
253  
254 0 my $hdr = pack('L>', 0);
255 0 my $serial;
256 0 my $idx = length($hdr);
257 0 ▶ my $status = $args{status} // $msgs->OK;
Condition0%0/3
$args{"status"} // $msgs->OK
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"status"} // $msgs->OK
$args{"status"} $msgs->OK
Truth table0%0/3
A // B
A= $args{"status"}B= $msgs->OK
ABresult
1X1
011
000
258 0 ▶ if ($type == $msgs->CALL
Branch: 3 branches
BranchTrueFalseTotal
if ($type == $msgs->CALL or $type == $msgs->CALL_WITH_FDS) { } 0 0 0
elsif ($type == $msgs->MESSAGE) { } 0 0 0
elsif (defined $args{'serial'}) { } 0 0 0
Condition0%0/3
$type == $msgs->CALL or $type == $msgs->CALL_WITH_FDS
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == $msgs->CALL or $type == $msgs->CALL_WITH_FDS
$type == $msgs->CALL $type == $msgs->CALL_WITH_FDS
Truth table0%0/3
A or B
A= $type == $msgs->CALLB= $type == $msgs->CALL_WITH_FDS
ABresult
1X1
011
000
259 or $type == $msgs->CALL_WITH_FDS) {
260 0 $serial = $self->{serial}++;
261 }
262 elsif ($type == $msgs->MESSAGE) {
263 0 $serial = 0;
264 }
265 elsif (defined $args{serial}) {
266 0 $serial = $args{serial};
267 }
268 else {
269 0 croak $log->fatal( "Missing 'serial' argument for frame type $type" );
270 }
271 0 $msgs->serialize_Header(
272 {
273 prog => $prog,
274 vers => $version,
275 proc => $proc,
276 type => $type,
277 serial => $serial,
278 status => $status,
279 },
280 $idx, $hdr );
281  
282 0 ▶ if ($status == $msgs->OK) {
Branch: 3 branches
BranchTrueFalseTotal
if ($status == $msgs->OK) { } 0 0 0
elsif ($status == $msgs->ERROR) { } 0 0 0
elsif ($status == $msgs->CONTINUE) { } 0 0 0
283 0 ▶ if ($type == $msgs->CALL_WITH_FDS
Branch: 1 branch
BranchTrueFalseTotal
if ($type == $msgs->CALL_WITH_FDS or $type == $msgs->REPLY_WITH_FDS) 0 0 0
Condition0%0/3
$type == $msgs->CALL_WITH_FDS or $type == $msgs->REPLY_WITH_FDS
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == $msgs->CALL_WITH_FDS or $type == $msgs->REPLY_WITH_FDS
$type == $msgs->CALL_WITH_FDS $type == $msgs->REPLY_WITH_FDS
Truth table0%0/3
A or B
A= $type == $msgs->CALL_WITH_FDSB= $type == $msgs->REPLY_WITH_FDS
ABresult
1X1
011
000
284 or $type == $msgs->REPLY_WITH_FDS) {
285 # Add FD count before the call arguments data
286 }
287  
288 0 ▶ my $length = length($hdr) + length($args{data} // '');
Condition0%0/2
$args{"data"} // ""
l!l
00
MC/DC0%0/1
$args{"data"} // ""
$args{"data"}
Truth table0%0/2
A
A= $args{"data"}
Aresult
11
00
289 0 ▶ croak "Message too large: $length" if $length > $msgs->MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $msgs->MAX 0 0 0
290  
291 0 substr($hdr, 0, 4) = pack('L>', $length);
292 0 return $self->{on_send}->( $serial, $hdr, $args{data} );
293 ###BUG: Send FDs
294 }
295 elsif ($status == $msgs->ERROR) {
296 0 my $payload = '';
297 0 ▶ unless ($type == $msgs->STREAM
Branch: 1 branch
BranchTrueFalseTotal
unless ($type == $msgs->STREAM and $self->{"role"} eq "client") 0 0 0
Condition0%0/3
$type == $msgs->STREAM and $self->{"role"} eq "client"
!ll&&!rl&&r
000
MC/DC0%0/2
$type == $msgs->STREAM and $self->{"role"} eq "client"
$type == $msgs->STREAM $self->{"role"} eq "client"
Truth table0%0/3
A and B
A= $type == $msgs->STREAMB= $self->{"role"} eq "client"
ABresult
0X0
100
111
298 and $self->{role} eq 'client') { # client message
299 0 my $i = 0;
300 0 $msgs->serialize_Error( $args{error}, $i, $payload );
301 }
302  
303 0 my $length = length($hdr) + length($payload);
304 0 ▶ croak "Message too large: $length" if $length > $msgs->MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $msgs->MAX 0 0 0
305  
306 0 substr($hdr, 0, 4) = pack('L>', $length);
307 0 return $self->{on_send}->( $serial, $hdr, $payload );
308 }
309 elsif ($status == $msgs->CONTINUE) {
310 0 my $payload = '';
311 0 ▶ if ($type == $msgs->STREAM_HOLE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == $msgs->STREAM_HOLE) { } 0 0 0
elsif ($type == $msgs->STREAM) { } 0 0 0
312 0 my $i = 0;
313 0 $msgs->serialize_StreamHole( $args{hole}, $i, $payload );
314 }
315 elsif ($type == $msgs->STREAM) {
316 0 $payload = $args{data};
317 }
318 else {
319 0 croak $log->fatal( "Unsupported frame type $type with status CONTINUE" );
320 }
321  
322 0 ▶ my $length = length($hdr) + length($payload // '');
Condition0%0/2
$payload // ""
l!l
00
MC/DC0%0/1
$payload // ""
$payload
Truth table0%0/2
A
A= $payload
Aresult
11
00
323 0 ▶ croak "Message too large: $length" if $length > $msgs->MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $msgs->MAX 0 0 0
324  
325 0 substr($hdr, 0, 4) = pack('L>', $length);
326 0 return $self->{on_send}->( $serial, $hdr, $payload );
327 }
328 else {
329 0 croak $log->fatal( "Unsupported frame status $status" );
330 }
331  
332 # unreachable
333 }
334  
335 1 1;
336  
337 __END__
« Virt/Transport/XDR.pm ↑ Summary Virt/Remote/XDR.pm »