| 1 | package Test::Smoke::App::SmokeStatus; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | |||
| 5 | our $VERSION = '0.001'; | ||
| 6 | |||
| 7 | use base 'Test::Smoke::App::Base'; | ||
| 8 | |||
| 9 | use POSIX qw/ strftime /; | ||
| 10 | use File::Spec::Functions; | ||
| 11 | use Test::Smoke::BuildCFG; | ||
| 12 | use Test::Smoke::Reporter; | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | Test::Smoke::App::SmokeStatus - Guess the status of the current smoke. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | sub new { | ||
| 21 | my $class = shift; | ||
| 22 | my $self = $class->SUPER::new(@_); | ||
| 23 | |||
| 24 | return $self; | ||
| 25 | } | ||
| 26 | |||
| 27 | =head2 run | ||
| 28 | |||
| 29 | Analyse the report... | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | sub run { | ||
| 34 | my $self = shift; | ||
| 35 | |||
| 36 | my $report = $self->parse_out(); | ||
| 37 | return $self->guess_status if !$report; | ||
| 38 | |||
| 39 | return $self->report_status($report); | ||
| 40 | |||
| 41 | } | ||
| 42 | |||
| 43 | sub report_status { | ||
| 44 | my $self = shift; | ||
| 45 | my ($rpt) = @_; | ||
| 46 | |||
| 47 | my $bcfg = Test::Smoke::BuildCFG->new($self->option('cfg')); | ||
| 48 | my $ccnt = 0; | ||
| 49 | Test::Smoke::skip_config($_) or $ccnt++ for $bcfg->configurations; | ||
| 50 | |||
| 51 | my $todo = $ccnt - $rpt->{ccount}; | ||
| 52 | my $est_curr = $rpt->{avg} > 0 | ||
| 53 | ? $rpt->{avg} - ( $rpt->{rtime} - $rpt->{ccount}*$rpt->{avg} ) : 0; | ||
| 54 | my $est_todo = $todo > 0 && $rpt->{avg} > 0 | ||
| 55 | ? ( (($todo - 1) * $rpt->{avg}) + $est_curr ) : 0; | ||
| 56 | $est_todo > $todo * $rpt->{avg} and $est_todo = $todo * $rpt->{avg}; | ||
| 57 | my $killtime = calc_timeout( $conf->{killtime}, $rpt->{started} ) | ||
| 58 | ? timeout_msg( $conf->{killtime}, $rpt->{started } ) | ||
| 59 | : ""; | ||
| 60 | |||
| 61 | my $todo_time = $rpt->{avg} <= 0 ? '.' : | ||
| 62 | $est_todo <= 0 | ||
| 63 | ? has_lck( $config ) | ||
| 64 | ? ", smoke looks hanging delay " . time_in_hhmm( -$est_todo ) | ||
| 65 | : ", smoke looks terminated${killtime}." | ||
| 66 | : ", estimated completion in " . time_in_hhmm( $est_todo ); | ||
| 67 | |||
| 68 | |||
| 69 | my $status = sprintf( | ||
| 70 | " Change number %s started on %s.\n", | ||
| 71 | $rpt->{patch}, | ||
| 72 | strftime("%Y %m %d %H:%M:%S%z", localtime($rpt->{started})) | ||
| 73 | ); | ||
| 74 | $status .= sprintf( | ||
| 75 | " %u out of %u configurations finished%s\n", | ||
| 76 | $rpt->{ccount}, $ccnt, | ||
| 77 | $rpt->{ccount} ? " in $rpt->{time}." : "." | ||
| 78 | ); | ||
| 79 | $status .= sprintf( | ||
| 80 | " %u configuration%s showed failures%s.\n", | ||
| 81 | $rpt->{fail} | ||
| 82 | ($rpt->{fail} == 1 ? "" : "s"), | ||
| 83 | $rpt->{stat} ? " ($rpt->{stat})":"" | ||
| 84 | ) if $rpt->{ccount}; | ||
| 85 | $status .= sprintf( | ||
| 86 | " %u failure%s in the running configuration.\n", | ||
| 87 | $rpt->{running}, | ||
| 88 | ($rpt->{running} == 1 ? "" : "s") | ||
| 89 | ) if exists $rpt->{running}; | ||
| 90 | $status .= sprintf( | ||
| 91 | " %u configuration%s to finish$todo_time\n", | ||
| 92 | $todo, $todo == 1 ? "" : "s" | ||
| 93 | ) if $todo; | ||
| 94 | $status .= sprintf( | ||
| 95 | " Average smoke duration: %s.\n", | ||
| 96 | time_in_hhmm( $rpt->{avg} ) | ||
| 97 | ) if $rpt->{ccount}; | ||
| 98 | |||
| 99 | print "\n$status\n"; | ||
| 100 | } | ||
| 101 | |||
| 102 | =head2 parse_out($bldconfigs) | ||
| 103 | |||
| 104 | Uses the L<Test::Smoke::Reporter> object to parse the current B<outfile>. | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | sub parse_out { | ||
| 109 | my $self = shift; | ||
| 110 | my $outfile = catfile($self->option('ddir'), $self->option('out')); | ||
| 111 | |||
| 112 | return if ! -f $outfile; | ||
| 113 | |||
| 114 | my $reporter = Test::Smoke::Reporter->new( | ||
| 115 | $self->options, | ||
| 116 | v => $self->option('verbose') | ||
| 117 | ); | ||
| 118 | my %rpt = %{ $reporter->{_rpt} }; | ||
| 119 | } | ||
| 120 | |||
| 121 | 1; | ||
| 122 | |||
| 123 | =head1 COPYRIGHT | ||
| 124 | |||
| 125 | (c) 2002-2021, Abe Timmerman <abeltje@cpan.org> All rights reserved. | ||
| 126 | |||
| 127 | With contributions from Jarkko Hietaniemi, Merijn Brand, Campo | ||
| 128 | Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop, | ||
| 129 | Rich Rauenzahn, David Cantrell. | ||
| 130 | |||
| 131 | This library is free software; you can redistribute it and/or modify | ||
| 132 | it under the same terms as Perl itself. | ||
| 133 | |||
| 134 | See: | ||
| 135 | |||
| 136 | =over 4 | ||
| 137 | |||
| 138 | =item * L<http://www.perl.com/perl/misc/Artistic.html> | ||
| 139 | |||
| 140 | =item * L<http://www.gnu.org/copyleft/gpl.html> | ||
| 141 | |||
| 142 | =back | ||
| 143 | |||
| 144 | This program is distributed in the hope that it will be useful, | ||
| 145 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 146 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 147 | |||
| 148 | =cut |