blib/lib/Test2/IPC.pm

filter: Statementstmt 54.1% 33 / 61 Branchbran 9.0% 2 / 22 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 80.0% 12 / 15 Podpod 50.0% 1 / 2 totaltotal 42.0% 50 / 119 CC 17 SCAR 37.1
CC
17
Cov
39%
apply_ipc
110.0
import
22.9
_make_ipc
6.0
CRAP 40.8
« blib/lib/Test2/Util/Importer.pm ↑ Summary blib/lib/Test2/Workflow/Task.pm »
1 package Test2::IPC;
2 97 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 97 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 97 our $VERSION = '1.302226';
6  
7  
8 97 ▶use Test2::API::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 97 ▶use Test2::Util qw/get_tid/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 97 ▶use Test2::API qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
11 test2_in_preload
12 test2_init_done
13 test2_ipc
14 test2_has_ipc
15 test2_ipc_enable_polling
16 test2_pid
17 test2_stack
18 test2_tid
19 context
20 97 };
21  
22 # Make sure stuff is finalized before anyone tried to fork or start a new thread.
23 {
24 # Avoid warnings if things are loaded at run-time
25 97 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 97 ▶ INIT {
Subroutine INIT: called CC=2 SCAR=7.0
27 97 ▶ use warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 97 ▶ context()->release() unless test2_in_preload();
Branch: 1 branch
BranchTrueFalseTotal
unless test2_in_preload() 97 0 97
29 }
30 }
31  
32 97 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 97 our @EXPORT_OK = qw/cull/;
35 97 ▶BEGIN { require Exporter; our @ISA = qw(Exporter) }
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 ▶sub unimport { Test2::API::test2_ipc_disable() }
Subroutine unimport: called CC=1 SCAR=0.0
38  
39 147 ▶sub import {
Subroutine import: called CC=6 SCAR=31.3
40 147 ▶ goto &Exporter::import if test2_has_ipc || !test2_init_done();
Branch: 1 branch
BranchTrueFalseTotal
if test2_has_ipc() or not test2_init_done() 147 0 147
Condition66%2/3
test2_has_ipc() or not test2_init_done()
l!l&&r!l&&!r
11460
MC/DC0%0/2
test2_has_ipc() or not test2_init_done()
test2_has_ipc() not test2_init_done()
Truth table66%2/3
A or not(B)
A= test2_has_ipc()B= not test2_init_done()
ABresult
1X1
011
000
41  
42 0 ▶ confess "IPC is disabled" if Test2::API::test2_ipc_disabled();
Branch: 1 branch
BranchTrueFalseTotal
if Test2::API::test2_ipc_disabled() 0 0 0
43 0 ▶ confess "Cannot add IPC in a child process (" . test2_pid() . " vs $$)" if test2_pid() != $$;
Branch: 1 branch
BranchTrueFalseTotal
if test2_pid() != $$ 0 0 0
44 0 ▶ confess "Cannot add IPC in a child thread (" . test2_tid() . " vs " . get_tid() . ")" if test2_tid() != get_tid();
Branch: 1 branch
BranchTrueFalseTotal
if test2_tid() != 0 0 0 0
45  
46 0 Test2::API::_set_ipc(_make_ipc());
47 0 apply_ipc(test2_stack());
48  
49 0 goto &Exporter::import;
50 }
51  
52 0 ▶sub _make_ipc {
Subroutine _make_ipc: not called CC=2 SCAR=17.9
53 # Find a driver
54 0 my ($driver) = Test2::API::test2_ipc_drivers();
55 0 ▶ unless ($driver) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($driver) 0 0 0
56 0 require Test2::IPC::Driver::Files;
57 0 $driver = 'Test2::IPC::Driver::Files';
58 }
59  
60 0 return $driver->new();
61 }
62  
63 0 ▶sub apply_ipc {
Subroutine apply_ipc: not called CC=10 SCAR=47.0
Pod undocumented
64 0 my $stack = shift;
65  
66 0 my ($root) = @$stack;
67  
68 0 ▶ return unless $root;
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 0 0
69  
70 0 ▶ confess "Cannot add IPC in a child process" if $root->pid != $$;
Branch: 1 branch
BranchTrueFalseTotal
if $root->pid != $$ 0 0 0
71 0 ▶ confess "Cannot add IPC in a child thread" if $root->tid != get_tid();
Branch: 1 branch
BranchTrueFalseTotal
if $root->tid != 0 0 0 0
72  
73 0 ▶ my $ipc = $root->ipc || test2_ipc() || _make_ipc();
Condition0%0/6
$root->ipc || test2_ipc() || _make_ipc()
l!l&&r!l&&!r
000
$root->ipc or test2_ipc()
l!l&&r!l&&!r
000
MC/DC0%0/3
$root->ipc || test2_ipc() || _make_ipc()
$root->ipc test2_ipc() _make_ipc()
Truth table0%0/4
A or B || C
A= $root->ipcB= test2_ipc()C= _make_ipc()
ABCresult
1XX1
01X1
0011
0000
74  
75 # Add the IPC to all hubs
76 0 for my $hub (@$stack) {
77 0 my $has = $hub->ipc;
78 0 ▶ confess "IPC Mismatch!" if $has && $has != $ipc;
Branch: 1 branch
BranchTrueFalseTotal
if $has and $has != $ipc 0 0 0
Condition0%0/3
$has and $has != $ipc
!ll&&!rl&&r
000
MC/DC0%0/2
$has and $has != $ipc
$has $has != $ipc
Truth table0%0/3
A and B
A= $hasB= $has != $ipc
ABresult
0X0
100
111
79 0 ▶ next if $has;
Branch: 1 branch
BranchTrueFalseTotal
if $has 0 0 0
80 0 $hub->set_ipc($ipc);
81 0 $ipc->add_hub($hub->hid);
82 }
83  
84 0 test2_ipc_enable_polling();
85  
86 0 return $ipc;
87 }
88  
89 0 ▶sub cull {
Subroutine cull: not called CC=1 SCAR=6.9
Pod documented
90 0 my $ctx = context();
91 0 $ctx->hub->cull;
92 0 $ctx->release;
93 }
94  
95 97 1;
96  
97 __END__
« blib/lib/Test2/Util/Importer.pm ↑ Summary blib/lib/Test2/Workflow/Task.pm »