Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better handling of exit codes and signals
  • Loading branch information
MasterDuke17 committed Jul 24, 2016
1 parent e0be906 commit 6341f19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
15 changes: 8 additions & 7 deletions Perl6IRCBotable.pm
Expand Up @@ -47,24 +47,25 @@ sub timeout {
sub get_output {
my $self = shift;

my $out = undef;
my $out = '';
my $wait = $self->timeout();
my $s_start = time();
my $pid = open3(undef, \*RESULT, \*RESULT, @_);
{
local $SIG{ALRM} = sub { kill 9, $pid; $out = "timed out after $wait seconds"; };
local $SIG{ALRM} = sub { kill 9, $pid; $out = encode_utf8("«timed out after $wait seconds, output»: "); };
alarm $wait;
waitpid($pid, 0);
alarm 0;
}
my $s_end = time();

my $exit_status = $? & 127;
my $exit_status = $? >> 8;
my $exit_signal = $? & 127;

$out .= do { local $/; <RESULT> };
chomp $out if defined $out;
$out .= do { local $/; <RESULT> } // '';
chomp $out;

return ($out, $exit_status, $s_end - $s_start)
return ($out, $exit_status, $exit_signal, $s_end - $s_start)
}

sub to_full_commit {
Expand All @@ -73,7 +74,7 @@ sub to_full_commit {
my $old_dir = cwd();
chdir RAKUDO;
return if system('git', 'rev-parse', '--verify', $commit) != 0; # make sure that $commit is valid
my ($result, $exit_status, $time) = $self->get_output('git', 'rev-list', '-1', $commit); # use rev-list to handle tags
my ($result, $exit_status, $exit_signal, $time) = $self->get_output('git', 'rev-list', '-1', $commit); # use rev-list to handle tags
chdir $old_dir;

return if $exit_status != 0;
Expand Down
6 changes: 3 additions & 3 deletions benchable.pl
Expand Up @@ -60,7 +60,7 @@ sub process_message {
return "Bad start" if system('git', 'rev-parse', '--verify', $start) != 0;
return "Bad end" if system('git', 'rev-parse', '--verify', $end) != 0;

my ($result, $exit_status, $time) = $self->get_output('git', 'rev-list', "$start^..$end");
my ($result, $exit_status, $exit_signal, $time) = $self->get_output('git', 'rev-list', "$start^..$end");
chdir $old_dir;

return "Couldn't find anything in the range" if $exit_status != 0;
Expand Down Expand Up @@ -92,8 +92,8 @@ sub process_message {
$times{$short_commit} = 'No build for this commit';
} else { # actually run the code
for (1..ITERATIONS) {
(undef, my $exit, my $time) = $self->get_output($self->BUILDS . "/$full_commit/bin/perl6", $filename);
push @{$times{$short_commit}}, $exit == 0 ? sprintf('%.4f', $time) : "run failed, exit code = $exit";
(undef, my $exit, my $signal, my $time) = $self->get_output($self->BUILDS . "/$full_commit/bin/perl6", $filename);
push @{$times{$short_commit}}, $exit == 0 ? sprintf('%.4f', $time) : "«run failed, exit code = $exit, exit signal = $signal»";
}
my @times = @{$times{$short_commit}};
$times{$short_commit} = {};
Expand Down
4 changes: 2 additions & 2 deletions bisectable.pl
Expand Up @@ -93,8 +93,8 @@ sub process_message {

my $old_dir = cwd();
chdir $self->RAKUDO;
my ($out_good, $exit_good, $time_good) = $self->get_output($self->BUILDS . "/$full_good/bin/perl6", $filename);
my ($out_bad, $exit_bad, $time_bad) = $self->get_output($self->BUILDS . "/$full_bad/bin/perl6", $filename);
my ($out_good, $exit_good, $signal_good, $time_good) = $self->get_output($self->BUILDS . "/$full_good/bin/perl6", $filename);
my ($out_bad, $exit_bad, $signal_bad, $time_bad) = $self->get_output($self->BUILDS . "/$full_bad/bin/perl6", $filename);
chdir $old_dir;
$out_good //= '';
$out_bad //= '';
Expand Down
9 changes: 5 additions & 4 deletions committable.pl
Expand Up @@ -54,7 +54,7 @@ sub process_message {
return "Bad start" if system('git', 'rev-parse', '--verify', $start) != 0;
return "Bad end" if system('git', 'rev-parse', '--verify', $end) != 0;

my ($result, $exit_status, $time) = $self->get_output('git', 'rev-list', "$start^..$end");
my ($result, $exit_status, $exit_signal, $time) = $self->get_output('git', 'rev-list', "$start^..$end");
chdir $old_dir;

return "Couldn't find anything in the range" if $exit_status != 0;
Expand Down Expand Up @@ -86,9 +86,10 @@ sub process_message {
} elsif (not -e $self->BUILDS . "/$full_commit/bin/perl6") {
$out = 'No build for this commit';
} else { # actually run the code
($out, my $exit, my $time) = $self->get_output($self->BUILDS . "/$full_commit/bin/perl6", $filename);
($out, my $exit, my $signal, my $time) = $self->get_output($self->BUILDS . "/$full_commit/bin/perl6", $filename);
$out = decode_utf8($out);
$out .= " exit code = $exit" if ($exit != 0);
$out .= " «exit code = $exit»" if ($exit != 0);
$out .= " «exit signal = $signal»" if ($signal != 0);
}
my $short_commit = substr($commit, 0, 7);

Expand All @@ -104,7 +105,7 @@ sub process_message {
}
}

$msg_response .= '|' . join("\n|", map { '«' . join(',', @{$_->{commits}}) . '»: ' . $_->{output} } @result);
$msg_response .= '¦' . join("\n|", map { '«' . join(',', @{$_->{commits}}) . '»: ' . $_->{output} } @result);
} else {
$msg_response = help();
}
Expand Down

0 comments on commit 6341f19

Please sign in to comment.