| 1 | package HPCI::Run; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ### INCLUDES ################################################################## | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # safe Perl | ||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 20 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 20 | ▶ | use MooseX::Role::Parameterized; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 20 | ▶ | use MooseX::Types::Path::Class qw(Dir File); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 20 | parameter theDriver => ( | |||||||||||||||||||||||||||
| 16 | isa => 'Str', | ||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 20 | ▶ | die "No sigs?" unless $Config{sig_name} && $Config{sig_num}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$HPCI::Run::Config{"sig_name"} and $HPCI::Run::Config{"sig_num"}
MC/DC0%0/2
$HPCI::Run::Config{"sig_name"} and $HPCI::Run::Config{"sig_num"}
$HPCI::Run::Config{"sig_name"}
$HPCI::Run::Config{"sig_num"}
Truth table33%1/3
A and B
A= $HPCI::Run::Config{"sig_name"}B= $HPCI::Run::Config{"sig_num"}
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 20 | my %sig_num; | |||||||||||||||||||||||||||
| 23 | my @sig_name; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 20 | @sig_num{split ' ', $Config{sig_name}} = split ' ', $Config{sig_num}; | |||||||||||||||||||||||||||
| 26 | 20 | ▶ | while (my($k,$v) = each %sig_num) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 1360 | ▶ | $sig_name[$v] ||= $k; | ||||||||||||||||||||||||||
|
Condition66%2/3
$sig_name[$v] ||= $k
MC/DC0%0/2
$sig_name[$v] ||= $k
$sig_name[$v]
$k
Truth table66%2/3
A ||= B
A= $sig_name[$v]B= $k
| |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | role { | ||||||||||||||||||||||||||||
| 31 | 20 | ▶ | my $p = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||
| 32 | 20 | my $theDriver = $p->theDriver; | |||||||||||||||||||||||||||
| 33 | 20 | my $StageClass = "${theDriver}::Stage"; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # do nothing, but let roles write before/after/around wrappers | ||||||||||||||||||||||||||||
| 36 | ▶ | method BUILD => sub { | |||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=0.0
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 20 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 20 | has 'stage' => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | required => 1, | ||||||||||||||||||||||||||||
| 42 | isa => $StageClass, | ||||||||||||||||||||||||||||
| 43 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 44 | handles => { | ||||||||||||||||||||||||||||
| 45 | debug => 'debug', | ||||||||||||||||||||||||||||
| 46 | info => 'info', | ||||||||||||||||||||||||||||
| 47 | warn => 'warn', | ||||||||||||||||||||||||||||
| 48 | error => 'error', | ||||||||||||||||||||||||||||
| 49 | fatal => 'fatal', | ||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 20 | has 'index' => ( | |||||||||||||||||||||||||||
| 54 | is => 'ro', | ||||||||||||||||||||||||||||
| 55 | isa => 'Int', | ||||||||||||||||||||||||||||
| 56 | required => 1, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 20 | has 'pid' => ( | |||||||||||||||||||||||||||
| 60 | is => 'rw', | ||||||||||||||||||||||||||||
| 61 | isa => 'Int', | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | has 'unique_id' => ( | ||||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||
| 66 | isa => 'Str', | ||||||||||||||||||||||||||||
| 67 | lazy => 1, | ||||||||||||||||||||||||||||
| 68 | init_arg => undef, | ||||||||||||||||||||||||||||
| 69 | default => sub { | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 0 | my $stage = $self->stage; | |||||||||||||||||||||||||||
| 72 | 0 | return $stage->group->_unique_name | |||||||||||||||||||||||||||
| 73 | . '_' . $stage->name | ||||||||||||||||||||||||||||
| 74 | . '._' . $self->index; | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | 20 | ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | has 'dir' => ( | ||||||||||||||||||||||||||||
| 79 | is => 'ro', | ||||||||||||||||||||||||||||
| 80 | isa => Dir, | ||||||||||||||||||||||||||||
| 81 | init_arg => undef, | ||||||||||||||||||||||||||||
| 82 | lazy => 1, | ||||||||||||||||||||||||||||
| 83 | default => sub { | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 85 | 0 | my $stage_dir = $self->stage->stage_dir; | |||||||||||||||||||||||||||
| 86 | 0 | my $run_dir = $stage_dir->subdir( $self->index ); | |||||||||||||||||||||||||||
| 87 | 0 | HPCI::_trigger_mkdir( $self, $run_dir ); | |||||||||||||||||||||||||||
| 88 | 0 | my $sym = $stage_dir->file('final_retry'); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | unlink $sym if -e $sym; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | symlink $self->index, $sym; | |||||||||||||||||||||||||||
| 91 | 0 | return $run_dir; | |||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||
| 93 | 20 | ); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | has '_stdout' => ( | ||||||||||||||||||||||||||||
| 96 | is => 'ro', | ||||||||||||||||||||||||||||
| 97 | isa => File, | ||||||||||||||||||||||||||||
| 98 | init_arg => undef, | ||||||||||||||||||||||||||||
| 99 | lazy => 1, | ||||||||||||||||||||||||||||
| 100 | default => sub { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 102 | 0 | $self->dir->file( 'stdout' ); | |||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||
| 104 | 20 | ); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | has '_stderr' => ( | ||||||||||||||||||||||||||||
| 107 | is => 'ro', | ||||||||||||||||||||||||||||
| 108 | isa => File, | ||||||||||||||||||||||||||||
| 109 | init_arg => undef, | ||||||||||||||||||||||||||||
| 110 | lazy => 1, | ||||||||||||||||||||||||||||
| 111 | default => sub { | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 113 | 0 | $self->dir->file( 'stderr' ); | |||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||
| 115 | 20 | ); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 20 | has 'status' => ( # exit code if job exitted normally | |||||||||||||||||||||||||||
| 118 | is => 'rw', | ||||||||||||||||||||||||||||
| 119 | isa => 'Str', | ||||||||||||||||||||||||||||
| 120 | init_arg => undef, | ||||||||||||||||||||||||||||
| 121 | lazy => 1, | ||||||||||||||||||||||||||||
| 122 | default => 0, | ||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 20 | has 'kill' => ( # true if job was killed | |||||||||||||||||||||||||||
| 126 | is => 'rw', | ||||||||||||||||||||||||||||
| 127 | isa => 'Str', | ||||||||||||||||||||||||||||
| 128 | init_arg => undef, | ||||||||||||||||||||||||||||
| 129 | lazy => 1, | ||||||||||||||||||||||||||||
| 130 | default => 0, | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 20 | has 'killsignal' => ( # kill signal if job was killed | |||||||||||||||||||||||||||
| 134 | is => 'rw', | ||||||||||||||||||||||||||||
| 135 | isa => 'Str', | ||||||||||||||||||||||||||||
| 136 | init_arg => undef, | ||||||||||||||||||||||||||||
| 137 | lazy => 1, | ||||||||||||||||||||||||||||
| 138 | default => 0, | ||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 20 | has 'abort' => ( # abort info if job was not able to start | |||||||||||||||||||||||||||
| 142 | is => 'rw', | ||||||||||||||||||||||||||||
| 143 | isa => 'Str', | ||||||||||||||||||||||||||||
| 144 | init_arg => undef, | ||||||||||||||||||||||||||||
| 145 | lazy => 1, | ||||||||||||||||||||||||||||
| 146 | default => 0, | ||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | has 'stats' => ( | ||||||||||||||||||||||||||||
| 150 | is => 'ro', | ||||||||||||||||||||||||||||
| 151 | isa => 'HashRef[Str]', | ||||||||||||||||||||||||||||
| 152 | lazy => 1, | ||||||||||||||||||||||||||||
| 153 | init_arg => undef, | ||||||||||||||||||||||||||||
| 154 | default => sub { | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 156 | return { | ||||||||||||||||||||||||||||
| 157 | 0 | map { $_ => 'unknown' } (@{ $self->stats_keys }, 'exit_status') | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | }, | ||||||||||||||||||||||||||||
| 160 | 20 | ); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 20 | has '_analysis_chose_retry' => ( | |||||||||||||||||||||||||||
| 163 | is => 'rw', | ||||||||||||||||||||||||||||
| 164 | isa => 'Int', | ||||||||||||||||||||||||||||
| 165 | lazy => 1, | ||||||||||||||||||||||||||||
| 166 | init_arg => undef, | ||||||||||||||||||||||||||||
| 167 | default => 0, | ||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | method soft_timeout => sub { | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
soft_timeout: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 172 | 0 | $self->info( "Sending soft timeout: " . $self->unique_id ); | |||||||||||||||||||||||||||
| 173 | 0 | my $pid = $self->pid; | |||||||||||||||||||||||||||
| 174 | 0 | kill 'USR1', $self->pid; | |||||||||||||||||||||||||||
| 175 | 20 | }; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | method hard_timeout => sub { | ||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 179 | 0 | my $pid = $self->pid; | |||||||||||||||||||||||||||
| 180 | 0 | $self->info( "Sending hard timeout: " . $self->unique_id ); | |||||||||||||||||||||||||||
| 181 | 0 | kill 'KILL', $self->pid; | |||||||||||||||||||||||||||
| 182 | 20 | }; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | method _submit_command => sub { | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 186 | 0 | my $cmd = shift; | |||||||||||||||||||||||||||
| 187 | 0 | my $pid = fork; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | # normal parent | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return $pid if $pid; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # parent after fork failure | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | $self->_croak( "Fork failed: $!" ) unless defined $pid; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # child | ||||||||||||||||||||||||||||
| 196 | 0 | setpgrp 0, $$; | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | exec $cmd or die "Exec failed ($!) on command: $cmd\n"; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 198 | 20 | }; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | before '_collect_job_stats' => sub { | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 202 | 0 | my $status = shift; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | $self->_base_register_status( $status ); | |||||||||||||||||||||||||||
| 205 | 20 | }; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | sub _base_register_status { | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_base_register_status: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 209 | 0 | my $status = shift; | |||||||||||||||||||||||||||
| 210 | 0 | my $stath = $self->stats; | |||||||||||||||||||||||||||
| 211 | 0 | $stath->{exit_status} = $status; | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($status =~ /\D/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 213 | 0 | $self->killsignal( "internal code failed: $status" ); | |||||||||||||||||||||||||||
| 214 | 0 | $self->status( $stath->{exit_status} = 126 ); | |||||||||||||||||||||||||||
| 215 | ; | ||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | elsif ($status & 127) { | ||||||||||||||||||||||||||||
| 218 | 0 | $self->kill( 1 ); | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | $self->killsignal( $sig_name[$status & 127] // "Unknown signal #".($status&127) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$sig_name[$status & 127] // 'Unknown signal #' . ($status & 127)
MC/DC0%0/1
$sig_name[$status & 127] // 'Unknown signal #' . ($status & 127)
$sig_name[$status & 127]
Truth table0%0/2
A
A= $sig_name[$status & 127]
| |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||
| 222 | 0 | $self->status( $stath->{exit_status} = $status >> 8 ); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | }; | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | around '_register_status' => sub { | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 228 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 229 | 0 | ▶ | my $status = shift || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 230 | 0 | $orig->($self,$status); | |||||||||||||||||||||||||||
| 231 | 0 | $self->_base_register_status( $status ); | |||||||||||||||||||||||||||
| 232 | 20 | }; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 20 | }; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 20 | 1; | |||||||||||||||||||||||||||