| 1 | package Proc::Spawner::Graph; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 485 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # EXPERIMENTAL. The companion of Proc::Spawner: the spawn graph, which is what gets executed. It says, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # for the current moment, which of our children and which of our own reads and writes use which open | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # file, and carries on each process what to do when it ends. That reaction may start new processes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # each with its own reaction, close ends, read and write; so the graph grows and shrinks as it runs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # end an open file the parent keeps for its children or for its own reads and writes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # { kind => 'r' | 'w' | 'file' | 'parent', fd => N, fh => HANDLE while open, n => HOLDS, what => TEXT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # pipe => NAME, peer => the other half (weak) r and w | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # mode => '<' '>' '>>' '<>' '>|', path => PATH file; parent: its access | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # forgotten => 1 once the parent has closed it, g => the graph (weak) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # 'parent': the parent's own fd N, which it never closes. The others are close-on-exec, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # child gets only what its fd table gives it. Whoever needs an end holds it (hold); the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # release closes it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # proc a child: { name, pid, argv => TEXT, edges => [[CHILD_FD, OP, END, KEEP], ...], on_exit => HANDLER, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # st => 'pending' | 'running' | 'exited N' | 'signal N' | 'lost' | 'never', after => [PROC (weak), WORD] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # 'after': the process whose end led to this start (for the pictures). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # io Perl's own reads and writes, $g->{io} = { ID => [END, '<' or '>'] }; drawn as the process 'Perl'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # HANDLER: a code ref, or [NAME, DATA...] with NAME a fully qualified sub name (its module is loaded at | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # first use). Called from Proc::Spawner's queue, one at a time, never waiting: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # on_exit HANDLER->(GRAPH, PROC, WAIT STATUS or undef, DATA...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # perl_read, perl_write HANDLER->(GRAPH, BYTES or undef at end of file, DATA...), HANDLER->(GRAPH, DATA...) with $! the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # write's error (EPIPE, ...: the rest is dropped), or 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # No strong reference cycles: the graph holds its processes, a process its ends and its HANDLER (with | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # its DATA); ends refer back only weakly. So DATA must not hold the graph: a handler gets it as an argument. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 485 | ▶ | use strict; use warnings; use feature 'current_sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 485 | ▶ | use Scalar::Util qw(refaddr weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 485 | ▶ | use Fcntl qw(F_SETFD FD_CLOEXEC F_GETFL F_SETFL O_RDONLY O_WRONLY O_RDWR O_CREAT O_TRUNC O_APPEND O_NONBLOCK S_ISFIFO); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 485 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 485 | ▶ | use Proc::Spawner; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 622 | ▶ | sub tr_ { &Proc::Spawner::tr_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tr_: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 485 | our %OPEN = ('<' => O_RDONLY, '>' => O_WRONLY|O_CREAT|O_TRUNC, '>|' => O_WRONLY|O_CREAT|O_TRUNC, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | '>>' => O_WRONLY|O_CREAT|O_APPEND, '<>' => O_RDWR|O_CREAT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 485 | my %RD = ('<' => 1, '<>' => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 485 | my %WR = ('>' => 1, '>>' => 1, '>|' => 1, '<>' => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 484 | ▶ | sub new { my ($class, %o) = @_; bless { procs => [], io => {}, own => {}, pipes => 0, dot => $o{dot}, pics => 0 }, $class } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 485 | my %HANDLER; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 753 | ▶ | sub handler { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handler: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 753 | my $n = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 485 | ▶ | $HANDLER{$n} //= do { no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Condition66%2/3
$HANDLER{$n} //= do {
no strict 'refs';
unless (defined &$n) {
(my $m = $n) =~ s/::[^:]+\z//;
$m =~ s[::][/]g;
require "$m.pm";
};
\&$n
}
MC/DC0%0/2
$HANDLER{$n} //= do {
no strict 'refs';
unless (defined &$n) {
(my $m = $n) =~ s/::[^:]+\z//;
$m =~ s[::][/]g;
require "$m.pm";
};
\&$n
}
$HANDLER{$n}
do {
no strict 'refs';
unless (defined &$n) {
(my $m = $n) =~ s/::[^:]+\z//;
$m =~ s[::][/]g;
require "$m.pm";
};
\&$n
}
Truth table66%2/3
A //= B
A= $HANDLER{$n}B= do {
no strict 'refs';
unless (defined &$n) {
(my $m = $n) =~ s/::[^:]+\z//;
$m =~ s[::][/]g;
require "$m.pm";
};
\&$n
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 503 | ▶ | unless (defined &$n) { (my $m = $n) =~ s/::[^:]+\z//; $m =~ s{::}{/}g; require "$m.pm" } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 503 | \&$n } } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2848 | ▶ | sub call { my ($h, @a) = @_; ref $h eq 'CODE' ? $h->(@a) : handler($h->[0])->(@a, @$h[1 .. $#$h]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # ------------------------------------------------------------------ ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 386 | ▶ | sub adopt { # end $e gets the handle $fh, with one hold | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
adopt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 386 | my ($g, $e, $fh, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 386 | Proc::Spawner::__set_cloexec(fileno $fh, 1); # also when Perl gave it an fd <= $^F (Windows: not inherited) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 386 | @$e{qw(fd fh n what)} = (fileno $fh, $fh, 1, $what); delete $e->{forgotten}; weaken($e->{g} = $g); $e } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 148 | ▶ | sub peers { my @e = @_; $e[0]{peer} = $e[1]; $e[1]{peer} = $e[0]; weaken($_->{peer}) for @e; @e } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peers: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Where /proc/self/fd cannot open a pipe end anew (no /proc: FreeBSD; RT #182479), a pipe of ours is a named FIFO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # opened once more for Perl's own non-blocking writes and then unlinked: so Perl's flag never reaches the children. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 485 | our $REOPEN = -d '/proc/self/fd'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 485 | my ($FIFODIR, $FIFON); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub fifo_pipe { # (read handle, write handle, Perl's own non-blocking write handle), or () with $! | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fifo_pipe: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $FIFODIR //= do { require File::Temp; File::Temp::tempdir('proc-spawner-XXXXXX', TMPDIR => 1, CLEANUP => 1) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$FIFODIR //= do {
require File::Temp;
File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1)
}
MC/DC0%0/2
$FIFODIR //= do {
require File::Temp;
File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1)
}
$FIFODIR
do {
require File::Temp;
File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1)
}
Truth table0%0/3
A //= B
A= $FIFODIRB= do {
require File::Temp;
File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1)
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $p = "$FIFODIR/" . ++$FIFON; POSIX::mkfifo($p, 0600) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my ($r, $w, $nb); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $ok = sysopen($r, $p, O_RDONLY|O_NONBLOCK) && sysopen($w, $p, O_WRONLY) && sysopen($nb, $p, O_WRONLY|O_NONBLOCK); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
sysopen($r, $p, 2048) && sysopen($w, $p, 1) && sysopen($nb, $p, 2049)
sysopen $r, $p, 2048 and sysopen $w, $p, 1
MC/DC0%0/3
sysopen($r, $p, 2048) && sysopen($w, $p, 1) && sysopen($nb, $p, 2049)
sysopen $r, $p, 2048
sysopen $w, $p, 1
sysopen($nb, $p, 2049)
Truth table0%0/4
A and B && C
A= sysopen $r, $p, 2048B= sysopen $w, $p, 1C= sysopen($nb, $p, 2049)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $err = $!; unlink $p; $! = $err; $ok or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | fcntl($r, F_SETFL, fcntl($r, F_GETFL, 0) & ~O_NONBLOCK); # the read end as pipe(2) gives it: blocking | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | fcntl($nb, F_SETFD, FD_CLOEXEC); ($r, $w, $nb) } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 147 | ▶ | sub new_pipe { # (read end, write end) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_pipe: called CC=6 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 147 | my $g = shift; my ($r, $w, $nb); my $n = ++$g->{pipes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($REOPEN || $Proc::Spawner::WIN) { pipe $r, $w or return } else { ($r, $w, $nb) = fifo_pipe() or return } # (Windows: the loop | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$Proc::Spawner::Graph::REOPEN or $Proc::Spawner::WIN
MC/DC0%0/2
$Proc::Spawner::Graph::REOPEN or $Proc::Spawner::WIN
$Proc::Spawner::Graph::REOPEN
$Proc::Spawner::WIN
Truth table33%1/3
A or B
A= $Proc::Spawner::Graph::REOPENB= $Proc::Spawner::WIN
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # writes without a non-blocking flag, W5; Wine's /proc is Linux's, not Windows') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 147 | my @e = peers(map +{ kind => $_, pipe => $n }, qw(r w)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 147 | ▶ | adopt($g, $e[0], $r, "pipe $n read end"); adopt($g, $e[1], $w, "pipe $n write end"); $e[1]{nbw} = $nb if $nb; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 147 | tr_("pipe $n: read end fd $e[0]{fd}, write end fd $e[1]{fd}"); @e } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 89 | ▶ | sub file_end { # the end for a file the caller opened as $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 89 | my ($g, $fh, $mode, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 89 | my $e = adopt($g, { kind => 'file', mode => $mode, path => $path }, $fh, "file '$path' ($mode)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 89 | tr_("open fd $e->{fd} = '$path' ($mode)"); $e } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1428 | ▶ | sub parent_end { # the parent's own fd N | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent_end: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1428 | my ($g, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1428 | ▶ | $g->{own}{$n} //= { kind => 'parent', fd => $n, n => 0, what => "our fd $n", mode => access($n) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$g->{"own"}{$n} //= {"kind", "parent", "fd", $n, "n", 0, "what", "our fd $n", "mode", access($n)}
MC/DC100%1/1
$g->{"own"}{$n} //= {"kind", "parent", "fd", $n, "n", 0, "what", "our fd $n", "mode", access($n)}
$g->{"own"}{$n}
Truth table100%2/2
A
A= $g->{"own"}{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1425 | ▶ | sub access { # '<', '>' or '<>': how fd N was opened (read through a copy, so N stays untouched); Windows: '<>', | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
access: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1425 | ▶ | return '<>' if $Proc::Spawner::WIN; # unknown (no F_GETFL; the mode is used only in traces and pictures) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1425 | ▶ | my $d = POSIX::dup(shift) // return '<>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
POSIX::dup(shift()) // (return "<>")
MC/DC0%0/1
POSIX::dup(shift()) // (return "<>")
POSIX::dup(shift())
Truth table50%1/2
A
A= POSIX::dup(shift())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1425 | ▶ | open my $h, '<&=', $d or return POSIX::close($d), '<>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1425 | ▶ | (qw(< > <>))[fcntl($h, F_GETFL, 0) & 3] // '<>' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
("<", ">", "<>")[fcntl($h, 3, 0) & 3] // "<>"
MC/DC0%0/1
("<", ">", "<>")[fcntl($h, 3, 0) & 3] // "<>"
("<", ">", "<>")[fcntl($h, 3, 0) & 3]
Truth table50%1/2
A
A= ("<", ">", "<>")[fcntl($h, 3, 0) & 3]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4921 | ▶ | sub hold { $_[0]{n}++ if $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hold: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 5307 | ▶ | sub release { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
release: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 5307 | ▶ | my $e = shift or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 5305 | ▶ | return if !$e->{fh} or --$e->{n} > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $e->{"fh"} or --$e->{"n"} > 0
MC/DC100%2/2
not $e->{"fh"} or --$e->{"n"} > 0
not $e->{"fh"}
--$e->{"n"} > 0
Truth table100%3/3
not(A) or B
A= not $e->{"fh"}B= --$e->{"n"} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 386 | tr_("close fd $e->{fd} ($e->{what})"); close delete $e->{fh}; $e->{forgotten} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 386 | ▶ | close delete $e->{nbw} if $e->{nbw}; # Perl's own write handle of a FIFO pipe (fifo_pipe): else no end of file | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 386 | ▶ | $e->{g}->event("close $e->{what}") if $e->{g} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 824 | ▶ | sub op_of { my $e = shift; { r => '<', w => '>' }->{$e->{kind}} // ($e->{mode} =~ /^(<>|<)\z/ ? "$1" : '>') } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
op_of: called CC=3 SCAR=11.0
Pod
undocumented
Branch: 1 branch
Condition100%2/2
{"r", "<", "w", ">"}->{$e->{"kind"}} // ($e->{"mode"} =~ /^(<>|<)\z/ ? "$1" : ">")
MC/DC100%1/1
{"r", "<", "w", ">"}->{$e->{"kind"}} // ($e->{"mode"} =~ /^(<>|<)\z/ ? "$1" : ">")
{"r", "<", "w", ">"}->{$e->{"kind"}}
Truth table100%2/2
A
A= {"r", "<", "w", ">"}->{$e->{"kind"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # ------------------------------------------------------------------ processes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # start(PATH, ARGV, ENVP, MAP, %opt): the started process node, or undef with $!. MAP: { CHILD_FD => end, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # or undef for closed }; other fds are inherited as they are. %opt: on_exit => HANDLER, node => a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # pending node to start (a hand-written graph's), and Proc::Spawner::start's chdir, umask, sigdefault. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 277 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 277 | my ($g, $path, $argv, $envp, $map, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 277 | my $node = delete $o{node}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | my %fds = map +($_ => $map->{$_} && $map->{$_}{fd}), # an fd of ours under its own number: inherited | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 277 | ▶ | grep { my $e = $map->{$_}; !($e && $e->{kind} eq 'parent' && $e->{fd} == $_) } keys %$map; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$map->{$_} && $map->{$_}{'fd'}
$e && $e->{'kind'} eq 'parent' && $e->{'fd'} == $_
$e and $e->{"kind"} eq "parent"
MC/DC50%1/2
$map->{$_} && $map->{$_}{'fd'}
$map->{$_}
$map->{$_}{'fd'}
MC/DC100%3/3
$e && $e->{'kind'} eq 'parent' && $e->{'fd'} == $_
$e
$e->{"kind"} eq "parent"
$e->{'fd'} == $_
Truth table66%2/3
A && B
A= $map->{$_}B= $map->{$_}{'fd'}
Truth table100%4/4
A and B && C
A= $eB= $e->{"kind"} eq "parent"C= $e->{'fd'} == $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | my $n = $node // { argv => "@$argv", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 277 | ▶ | edges => [map [$_, op_of($map->{$_}), $map->{$_}], grep defined $map->{$_}, sort { $a <=> $b } keys %$map] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node // {"argv", join($", @$argv), "edges", [map([$_, op_of($map->{$_}), $map->{$_}], grep(defined($map->{$_}), (sort {$a <=> $b;} keys %$map)))]}
MC/DC100%1/1
$node // {"argv", join($", @$argv), "edges", [map([$_, op_of($map->{$_}), $map->{$_}], grep(defined($map->{$_}), (sort {$a <=> $b;} keys %$map)))]}
$node
Truth table100%2/2
A
A= $node
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 277 | ▶ | my $pid = Proc::Spawner::start($path, $argv, $envp, \%fds, %o, on_exit => sub { exited($g, $n, shift) }) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 273 | @$n{qw(pid st on_exit)} = ($pid, 'running', $o{on_exit}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 273 | ▶ | $n->{name} //= "p$pid"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$n->{"name"} //= "p$pid"
MC/DC100%1/1
$n->{"name"} //= "p$pid"
$n->{"name"}
Truth table100%2/2
A
A= $n->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 273 | ▶ | if (ref(my $c = $Proc::Spawner::CAUSE) eq 'ARRAY') { $n->{after} = [@$c]; weaken($n->{after}[0]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 273 | ▶ | push @{$g->{procs}}, $n unless $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 273 | $g->event("start $n->{argv}"); $n } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 273 | ▶ | sub exited { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exited: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 273 | my ($g, $n, $w) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 273 | $n->{wait} = $w; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 273 | ▶ | $n->{st} = !defined $w ? 'lost' : $w & 127 ? 'signal ' . ($w & 127) : 'exited ' . ($w >> 8); # (Windows: no WIFSIGNALED) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 273 | $g->event("exit $n->{argv} ($n->{st})"); $g->prune; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 273 | local $Proc::Spawner::CAUSE = [$n, $n->{st}]; # processes started by the reaction are drawn after this one | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 273 | ▶ | call($_, $g, $n, $w) for delete $n->{on_exit} // () } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $n->{"on_exit"} // ()
MC/DC0%0/2
delete $n->{"on_exit"} // ()
delete $n->{"on_exit"}
()
Truth table33%1/3
A // B
A= delete $n->{"on_exit"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Perl's own reads and writes of an end | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1808 | ▶ | sub perl_read { # one read of at most $len bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perl_read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1808 | my ($g, $e, $len, $h) = @_; my $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1808 | ▶ | $id = Proc::Spawner::on_read($e->{fd}, $len, sub { delete $g->{io}{$id}; call($h, $g, @_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1808 | $g->{io}{$id} = [$e, '<']; $id } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 767 | ▶ | sub perl_write { # to a pipe or FIFO through an open file of our own, made non-blocking: the flag on the | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perl_write: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # shared one would reach the children writing to it too (L10). Linux: /proc/self/fd/N opens anew; a pipe of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # ours without /proc: the FIFO's handle opened for this (fifo_pipe). Otherwise (a pipe we were given, without | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # /proc) the shared one stays blocking and takes PIPE_BUF bytes per write, which a writable pipe takes at once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 767 | my ($g, $e, $bytes, $h) = @_; my ($id, $nb); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Windows: the fd as it is (the loop writes a synchronous handle from a helper thread, W5). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | my ($to, $chunk) = $Proc::Spawner::WIN || !S_ISFIFO((POSIX::fstat($e->{fd}))[2] // 0) ? $e->{fd} : $e->{nbw} ? $e->{nbw} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 767 | ▶ | : sysopen($nb, "/proc/self/fd/$e->{fd}", O_WRONLY|O_NONBLOCK) ? $nb : ($e->{fd}, POSIX::PIPE_BUF()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition60%3/5
$Proc::Spawner::WIN or not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
(POSIX::fstat($e->{"fd"}))[2] // 0
MC/DC50%1/2
$Proc::Spawner::WIN or not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
$Proc::Spawner::WIN
not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
MC/DC0%0/1
(POSIX::fstat($e->{"fd"}))[2] // 0
(POSIX::fstat($e->{"fd"}))[2]
Truth table66%2/3
A or not(B)
A= $Proc::Spawner::WINB= not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
Truth table50%1/2
A
A= (POSIX::fstat($e->{"fd"}))[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 767 | ▶ | $id = Proc::Spawner::on_write($to, $bytes, sub { my $err = shift; undef $nb; delete $g->{io}{$id}; local $! = $err // 0; call($h, $g) }, $chunk); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$err // 0
MC/DC100%1/1
$err // 0
$err
Truth table100%2/2
A
A= $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 767 | $g->{io}{$id} = [$e, '>']; $id } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # An ended process stays while it shares an end, or a pipe, with a process still to run or with one of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # our own reads and writes; then it is dropped, so a long loop does not grow the graph. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 459 | ▶ | sub ends_of { map +($_->[2], $_->[2]{peer} // ()), @{$_[0]{edges}} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ends_of: called CC=2 SCAR=7.1
Pod
undocumented
Condition66%2/3
$_->[2]{"peer"} // ()
MC/DC0%0/2
$_->[2]{"peer"} // ()
$_->[2]{"peer"}
()
Truth table66%2/3
A // B
A= $_->[2]{"peer"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 273 | ▶ | sub prune { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prune: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 273 | my $g = shift; my $live = qr/^(?:pending|running)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 273 | ▶ | my %live = map +(refaddr $_ => 1), (map ends_of($_), grep $_->{st} =~ $live, @{$g->{procs}}), | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->[0]{"peer"} // ()
MC/DC0%0/2
$_->[0]{"peer"} // ()
$_->[0]{"peer"}
()
Truth table66%2/3
A // B
A= $_->[0]{"peer"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 273 | map +($_->[0], $_->[0]{peer} // ()), values %{$g->{io}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 273 | ▶ | @{$g->{procs}} = grep $_->{st} =~ $live || grep($live{refaddr $_}, ends_of($_)), @{$g->{procs}} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->{'st'} =~ /$live/ || grep($live{builtin::refaddr($_)}, ends_of($_))
MC/DC100%2/2
$_->{'st'} =~ /$live/ || grep($live{builtin::refaddr($_)}, ends_of($_))
$_->{'st'} =~ /$live/
grep($live{builtin::refaddr($_)}, ends_of($_))
Truth table100%3/3
A || B
A= $_->{'st'} =~ /$live/B= grep($live{builtin::refaddr($_)}, ends_of($_))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 932 | ▶ | sub event { # with dot => DIR: the graph now, as DIR/trace-001.dot, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
event: called CC=4 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 932 | ▶ | my $g = shift; defined(my $dir = $g->{dot}) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my %seen; my @io = grep !$seen{refaddr $_->[0]}++, values %{$g->{io}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $what = join ' and ', ('reading') x !!grep($_->[1] eq '<', @io), ('writing') x !!grep($_->[1] eq '>', @io); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my @p = (@{$g->{procs}}, @io ? { name => 'Perl', argv => $what, edges => [map ['', $_->[1], $_->[0]], @io] } : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $f = sprintf '%s/trace-%03d.dot', $dir, ++$g->{pics}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | open my $o, '>', $f or return warn "$f: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | print $o to_dot({ procs => \@p }, sprintf '%03d: %s', $g->{pics}, "@_") } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # ------------------------------------------------------------------ the notation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # pipe NAME [r:forgotten] [w:forgotten] the ends NAME.r and NAME.w | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # file NAME MODE PATH [forgotten] MODE: < > >> <> >| | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # PROC: ARGV ... | EDGES | after PROC WORD | STATE | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # EDGES: FD<END FD>END FD<>END, a '+' after END: drawn as 'keep'; END: NAME.r NAME.w NAME, or @N (the parent's fd N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # STATE: running, exited N (drawing only); none: not started | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # after PROC WORD: started when PROC has ended; WORD fail: if non-zero, ok: if zero, else always | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Perl: WHAT | <END the parent itself reading (or >END writing) an end | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # Arguments are split at blanks; quoting is not done yet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=19 SCAR=30.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | my (%end, @procs, @after); my $ln = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $bad = sub { die "$_[0] at line $ln\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | for (split /\n/, shift) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 6 | ▶ | $ln++; s/#.*//; s/^\s+|\s+$//g; next unless length; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | ▶ | if (/^pipe (\w+)(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | my ($n, %st) = ("$1", map /^([rw]):forgotten\z/ ? ("$1", 1) : $bad->("bad pipe state '$_'"), split ' ', "$2"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | @end{"$n.r", "$n.w"} = peers(map +{ kind => $_, pipe => $n }, qw(r w)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | $end{"$n.$_"}{forgotten} = 1 for keys %st } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | elsif (/^file (\w+) (<>|>>|>\||<|>) (\S+)(?: (forgotten))?\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | $end{$1} = { kind => 'file', mode => "$2", path => "$3", $4 ? (forgotten => 1) : () } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | elsif (/^(\w+): (.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | my ($n, $argv, $edges, @rest) = ("$1", split /\s*\|\s*/, "$2"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | my $p = { name => $n, argv => $argv, edges => [], st => 'pending' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | for (split ' ', $edges // '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$edges // ""
MC/DC0%0/1
$edges // ""
$edges
Truth table50%1/2
A
A= $edges
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 7 | ▶ | my ($fd, $op, $e, $keep) = /^(\d*)(<>|>>|>\||<|>)([\w.@]+)(\+?)\z/ or $bad->("bad edge '$_'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | push @{$p->{edges}}, [$fd, $op, $end{$e} //= $e =~ /^@(\d+)\z/ ? { kind => 'parent', fd => "$1" } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$end{$e} //= $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
MC/DC0%0/2
$end{$e} //= $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
$end{$e}
$e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
Truth table66%2/3
A //= B
A= $end{$e}B= $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | : $bad->("unknown end '$e'"), $keep] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | for (@rest) { /^after (\w+)\s*(.*)/ ? push @after, [$p, "$1", "$2"] : ($p->{st} = $_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | push @procs, $p } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | else { $bad->("cannot read '$_'") } } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | my %byname = map +($_->{name} => $_), @procs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | for (@after) { $_->[0]{after} = [$byname{$_->[1]} // die("after: no process $_->[1]\n"), $_->[2] || 'then']; weaken($_->[0]{after}[0]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$byname{$_->[1]} // die("after: no process $_->[1]\n")
$_->[2] || 'then'
MC/DC0%0/1
$byname{$_->[1]} // die("after: no process $_->[1]\n")
$byname{$_->[1]}
MC/DC0%0/1
$_->[2] || 'then'
$_->[2]
Truth table50%1/2
A
A= $byname{$_->[1]}
Truth table50%1/2
A
A= $_->[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | bless { procs => \@procs, ends => \%end, io => {}, own => {}, pipes => 0, pics => 0 } } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # ------------------------------------------------------------------ running a hand-written graph | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # run($g, bin => DIR): runs the parsed graph $g on the engine. Each process is started as DIR/ARGV0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # with its arguments and exactly its edges; one with 'after' is started by the reaction of that one, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # or never ('never') if WORD does not match. The parent closes its copy of an end when no process | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # still to start uses it. Returns { PROC_NAME => status, ... } and, for 'Perl', what it read from each end. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=19 SCAR=32.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | my ($g, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | my ($perl) = grep $_->{name} eq 'Perl', @{$g->{procs}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | @{$g->{procs}} = grep $_->{name} ne 'Perl', @{$g->{procs}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | my @procs = @{$g->{procs}}; $_->{st} = 'pending' for @procs; # a state written in the notation is for drawing | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | my %ends = map +(refaddr $_->[2] => $_->[2]), map @{$_->{edges}}, @procs, $perl // (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$perl // ()
MC/DC0%0/2
$perl // ()
$perl
()
Truth table33%1/3
A // B
A= $perlB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | for my $e (grep $_->{kind} ne 'parent', values %ends) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | next if $e->{fh}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | if ($e->{kind} eq 'file') { sysopen my $fh, $e->{path}, $OPEN{$e->{mode}}, 0666 or die "$e->{path}: $!\n"; adopt($g, $e, $fh, "file $e->{path}") } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | else { my ($r, $w) = $e->{kind} eq 'r' ? ($e, $e->{peer}) : ($e->{peer}, $e); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | ▶ | pipe my $rh, my $wh or die "pipe: $!\n"; adopt($g, $r, $rh, "pipe $r->{pipe} read end"); adopt($g, $w, $wh, "pipe $w->{pipe} write end") } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | hold($_->[2]) for map @{$_->{edges}}, @procs, $perl // (); # each user holds its ends; the creator lets go | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$perl // ()
MC/DC0%0/2
$perl // ()
$perl
()
Truth table33%1/3
A // B
A= $perlB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | my %all = map +(refaddr $_ => $_), map +($_, $_->{peer} // ()), values %ends; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{"peer"} // ()
MC/DC0%0/2
$_->{"peer"} // ()
$_->{"peer"}
()
Truth table66%2/3
A // B
A= $_->{"peer"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | release($_) for grep $_->{kind} ne 'parent', values %all; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | my %got; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | for my $e (map $_->[2], @{$perl ? $perl->{edges} : []}) { $got{refaddr $e} = ''; $g->perl_read($e, 65536, [__PACKAGE__ . '::collect', $e, \%got]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | launch($g, $_, $o{bin}) for grep !$_->{after}, @procs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | Proc::Spawner::wait_until(sub { !grep($_->{st} eq 'running', @procs) && !%{$g->{io}} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Condition66%2/3
grep(($_->{'st'} eq 'running'), @procs) || %{$g->{'io'};}
MC/DC50%1/2
grep(($_->{'st'} eq 'running'), @procs) || %{$g->{'io'};}
grep(($_->{'st'} eq 'running'), @procs)
%{$g->{'io'};}
Truth table66%2/3
A || B
A= grep(($_->{'st'} eq 'running'), @procs)B= %{$g->{'io'};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | my %res = map +($_->{name} => ($_->{wait} >> 8 || $_->{wait} & 127)), grep defined $_->{wait}, @procs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'wait'} >> 8 || $_->{'wait'} & 127
MC/DC0%0/2
$_->{'wait'} >> 8 || $_->{'wait'} & 127
$_->{'wait'} >> 8
$_->{'wait'} & 127
Truth table33%1/3
A || B
A= $_->{'wait'} >> 8B= $_->{'wait'} & 127
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $res{Perl} = { map +($_->[2]{pipe} // $_->[2]{path} => $got{refaddr $_->[2]}), @{$perl->{edges}} } if $perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->[2]{"pipe"} // $_->[2]{"path"}
MC/DC0%0/2
$_->[2]{"pipe"} // $_->[2]{"path"}
$_->[2]{"pipe"}
$_->[2]{"path"}
Truth table0%0/3
A // B
A= $_->[2]{"pipe"}B= $_->[2]{"path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | \%res } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | ▶ | sub launch { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
launch: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | my ($g, $p, $bin) = @_; my ($name, @args) = split ' ', $p->{argv}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | $g->start("$bin/$name", [$name, @args], undef, { map +($_->[0] => $_->[2]), @{$p->{edges}} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | node => $p, on_exit => [__PACKAGE__ . '::then', $bin]) or die "spawn $name: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | release($_->[2]) for @{$p->{edges}} } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | sub then { # on_exit of a hand-written graph's process: the processes after it | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
then: called CC=11 SCAR=32.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | ▶ | my ($g, $p, $w, $bin) = @_; my $st = ($w // 0) >> 8 || ($w // 0) & 127; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition28%2/7
($w // 0) >> 8 || ($w // 0) & 127
$w // 0
$w // 0
MC/DC0%0/2
($w // 0) >> 8 || ($w // 0) & 127
$w
$w
Truth table33%1/3
A || B
A= $wB= $w
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 3 | ▶ | for my $q (grep $_->{st} eq 'pending' && $_->{after} && $_->{after}[0] == $p, @{$g->{procs}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$_->{'st'} eq 'pending' && $_->{'after'} && $_->{'after'}[0] == $p
$_->{"st"} eq "pending" and $_->{"after"}
MC/DC33%1/3
$_->{'st'} eq 'pending' && $_->{'after'} && $_->{'after'}[0] == $p
$_->{"st"} eq "pending"
$_->{"after"}
$_->{'after'}[0] == $p
Truth table50%2/4
A and B && C
A= $_->{"st"} eq "pending"B= $_->{"after"}C= $_->{'after'}[0] == $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | my $word = $q->{after}[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | if ($word eq 'fail' ? $st : $word eq 'ok' ? !$st : 1) { launch($g, $q, $bin) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | else { $q->{st} = 'never'; release($_->[2]) for @{$q->{edges}} } } } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub collect { # Perl's read of a hand-written graph's end: all of it | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collect: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ($g, $b, $e, $got) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return release($e) unless defined $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $got->{refaddr $e} .= $b; $g->perl_read($e, 65536, [__PACKAGE__ . '::collect', $e, $got]) } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # ------------------------------------------------------------------ drawing | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub q_ { (my $s = "@_") =~ s/([&<>"])/'&#'.ord($1).';'/ge; $s } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
q_: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub id { 'e' . refaddr shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub to_dot { # Graphviz source for $g; $caption under the picture | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_dot: not called CC=40 SCAR=74.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my ($g, $caption) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my @procs = @{$g->{procs}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my %shown = map +(refaddr $_ => 1), @procs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my @edges = map { my $p = $_; # an fd a child inherits unchanged from the parent is not drawn | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | [$p, grep !($_->[2]{kind} eq 'parent' && $_->[0] eq $_->[2]{fd}), @{$p->{edges}}] } @procs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->[2]{'kind'} eq 'parent' && $_->[0] eq $_->[2]{'fd'}
MC/DC0%0/2
$_->[2]{'kind'} eq 'parent' && $_->[0] eq $_->[2]{'fd'}
$_->[2]{'kind'} eq 'parent'
$_->[0] eq $_->[2]{'fd'}
Truth table0%0/3
A && B
A= $_->[2]{'kind'} eq 'parent'B= $_->[0] eq $_->[2]{'fd'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my (%end, %pipe, %first); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | for my $i (reverse 0 .. $#edges) { my ($p, @e) = @{$edges[$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | for (@e) { $end{refaddr $_->[2]} = $_->[2]; $first{refaddr $_->[2]} = $i if $RD{$_->[1]} } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | for my $e (values %end) { push @{$pipe{$e->{pipe}}}, $e if defined $e->{pipe} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $dotted = sub { $_[0]{forgotten} ? 'dotted' : 'solid' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my @L = ('digraph G {', ' rankdir=' . ($ENV{RANKDIR} || 'LR') . '; nodesep=0.25; ranksep=0.45; bgcolor="transparent"; fontname="Helvetica";', | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{'RANKDIR'} || 'LR'
MC/DC0%0/1
$ENV{'RANKDIR'} || 'LR'
$ENV{'RANKDIR'}
Truth table0%0/2
A
A= $ENV{'RANKDIR'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ' node [fontname="Helvetica", fontsize=11, color="black", fontcolor="black"];', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ' edge [fontname="Helvetica", fontsize=10, color="black", fontcolor="black", arrowsize=0.7];', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | defined $caption ? (sprintf ' label="%s"; labelloc=b; fontsize=10;', q_($caption)) : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | for my $e (sort { refaddr $a <=> refaddr $b } grep !defined $_->{pipe}, values %end) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | push @L, sprintf ' %s [shape=%s, label="%s", style=%s];', id($e), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | $e->{kind} eq 'parent' ? ('cds', "Perl's fd $e->{fd}") : ('note', q_("$e->{mode} $e->{path}")), $dotted->($e) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | for my $n (sort keys %pipe) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my %h = map +($_->{kind} => $_), map +($_, $_->{peer} // ()), @{$pipe{$n}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{"peer"} // ()
MC/DC0%0/2
$_->{"peer"} // ()
$_->{"peer"}
()
Truth table0%0/3
A // B
A= $_->{"peer"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | my ($r, $w) = map $h{$_} // { kind => $_, forgotten => 1 }, qw(r w); # a half nobody holds any more | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$h{$_} // {"kind", $_, "forgotten", 1}
MC/DC0%0/1
$h{$_} // {"kind", $_, "forgotten", 1}
$h{$_}
Truth table0%0/2
A
A= $h{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $cid = $n =~ s/\W/_/gr; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | push @L, " subgraph cluster_$cid {", qq( label="pipe $n"; style="rounded,dashed"; color="#888888"; fontcolor="#888888"; fontsize=10;); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | push @L, sprintf ' %s [shape=circle, width=0.32, fixedsize=true, label="%s", style=%s];', id($_), $_->{kind}, $dotted->($_) for $w, $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | push @L, sprintf(' %s -> %s [penwidth=2.2, arrowhead=none];', id($w), id($r)), ' }' } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | for my $i (0 .. $#edges) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my ($p, @e) = @{$edges[$i]}; my $pn = 'P_' . ($p->{name} =~ s/\W/_/gr); my $st = $p->{st} // 'pending'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$p->{"st"} // "pending"
MC/DC0%0/1
$p->{"st"} // "pending"
$p->{"st"}
Truth table0%0/2
A
A= $p->{"st"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($p->{name} eq 'Perl') { push @L, sprintf ' %s [shape=box, style="rounded,filled", fillcolor="#88888822", label="Perl: %s"];', $pn, q_($p->{argv}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | my @in = grep $RD{$_->[1]} && !$WR{$_->[1]}, @e; my @o = grep $WR{$_->[1]}, @e; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$RD{$_->[1]} && !$WR{$_->[1]}
MC/DC0%0/2
$RD{$_->[1]} && !$WR{$_->[1]}
$RD{$_->[1]}
!$WR{$_->[1]}
Truth table0%0/3
A && not(B)
A= $RD{$_->[1]}B= !$WR{$_->[1]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | my $rows = (@in > @o ? @in : @o) || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
(@in > @o ? @in : @o) || 1
MC/DC0%0/1
(@in > @o ? @in : @o) || 1
(@in > @o ? @in : @o)
Truth table0%0/2
A
A= (@in > @o ? @in : @o)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my $cell = sub { my ($side, $x) = @_; $x ? qq{<TD PORT="$side$x->[0]" BORDER="1" CELLPADDING="2">$x->[0]</TD>} : '<TD></TD>' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $ended = $st !~ /^(pending|running|never)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | my $mid = q_($p->{argv}) . ($st ne 'pending' ? '<BR/><FONT POINT-SIZE="9">' . q_($st) . '</FONT>' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $html = '<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0"' . ($ended ? ' BGCOLOR="#88888833"' : '') . '>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $html .= '<TR>' . $cell->(i => $in[$_]) . ($_ ? '' : qq{<TD ROWSPAN="$rows" CELLPADDING="5">$mid</TD>}) . $cell->(o => $o[$_]) . '</TR>' for 0 .. $rows - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | push @L, sprintf ' %s [shape=box, style=%s, margin=0, label=<%s</TABLE>>];', $pn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | { pending => 'dashed', never => 'dashed', running => 'bold' }->{$st} // 'solid', $html } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
{"pending", "dashed", "never", "dashed", "running", "bold"}->{$st} // "solid"
MC/DC0%0/1
{"pending", "dashed", "never", "dashed", "running", "bold"}->{$st} // "solid"
{"pending", "dashed", "never", "dashed", "running", "bold"}->{$st}
Truth table0%0/2
A
A= {"pending", "dashed", "never", "dashed", "running", "bold"}->{$st}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | for (@e) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my ($fd, $op, $e, $keep) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my $k = $keep ? ', color="#2b7bb9", penwidth=2.2, label="keep", fontcolor="#2b7bb9"' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # a write into a pipe read by an earlier process closes a loop: drawn without pulling the layout | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $k .= ', constraint=false' if $e->{kind} eq 'w' && $e->{peer} && ($first{refaddr $e->{peer}} // 1e9) < $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
$e->{"kind"} eq "w" and $e->{"peer"} and ($first{builtin::refaddr($e->{"peer"})} // "1000000000") < $i
$e->{"kind"} eq "w" and $e->{"peer"}
$first{builtin::refaddr($e->{"peer"})} // "1000000000"
MC/DC0%0/3
$e->{"kind"} eq "w" and $e->{"peer"} and ($first{builtin::refaddr($e->{"peer"})} // "1000000000") < $i
$e->{"kind"} eq "w"
$e->{"peer"}
$first{builtin::refaddr($e->{"peer"})}
Truth table0%0/4
A and B and C
A= $e->{"kind"} eq "w"B= $e->{"peer"}C= $first{builtin::refaddr($e->{"peer"})}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $id = id($e); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | push @L, $fd eq '' ? ($RD{$op} ? " $id -> $pn [style=bold$k];" : " $pn -> $id [style=bold$k];") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | : !$WR{$op} ? " $id -> $pn:i$fd:w [arrowhead=normal$k];" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | : " $pn:o$fd:e -> $id [" . ($RD{$op} ? 'dir=both' : 'arrowhead=normal') . "$k];" } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if (my ($q, $word) = @{$p->{after} // []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$p->{"after"} // []
MC/DC0%0/1
$p->{"after"} // []
$p->{"after"}
Truth table0%0/2
A
A= $p->{"after"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | push @L, sprintf ' P_%s -> %s [style=dashed, color="#c07000", fontcolor="#c07000", label="%s", constraint=false];', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | $q->{name} =~ s/\W/_/gr, $pn, q_($word) if $q && $shown{refaddr $q} } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$q and $shown{builtin::refaddr($q)}
MC/DC0%0/2
$q and $shown{builtin::refaddr($q)}
$q
$shown{builtin::refaddr($q)}
Truth table0%0/3
A and B
A= $qB= $shown{builtin::refaddr($q)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | join '', map "$_\n", @L, '}' } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 485 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||