| 1 | #!/usr/local/bin/perl -w | ||
| 2 | use strict; | ||
| 3 | $| = 1; | ||
| 4 | |||
| 5 | # $Id$ | ||
| 6 | use vars qw( $VERSION ); | ||
| 7 | $VERSION = '0.014'; | ||
| 8 | |||
| 9 | use Cwd; | ||
| 10 | use Time::Local; | ||
| 11 | use File::Spec::Functions; | ||
| 12 | use File::Path; | ||
| 13 | use File::Copy; | ||
| 14 | use FindBin; | ||
| 15 | use lib catdir( $FindBin::Bin, 'lib' ); | ||
| 16 | use Test::Smoke; | ||
| 17 | use Test::Smoke::Reporter; | ||
| 18 | use Test::Smoke::Util qw( | ||
| 19 | do_pod2usage time_in_hhmm calc_timeout | ||
| 20 | get_patch parse_report_Config ); | ||
| 21 | |||
| 22 | my $myusage = "Usage: $0 -c [smokeconfig]"; | ||
| 23 | use Getopt::Long; | ||
| 24 | Getopt::Long::Configure( 'bundling' ); | ||
| 25 | my %opt = ( | ||
| 26 | dir => undef, | ||
| 27 | config => undef, | ||
| 28 | matrix => undef, | ||
| 29 | help => 0, | ||
| 30 | man => 0, | ||
| 31 | ); | ||
| 32 | |||
| 33 | =head1 NAME | ||
| 34 | |||
| 35 | tssmokestatus.pl - Check the status of a running smoke | ||
| 36 | |||
| 37 | =head1 SYNOPSIS | ||
| 38 | |||
| 39 | $ ./smokestatus.pl -c [smokecurrent_config] | ||
| 40 | |||
| 41 | =head1 OPTIONS | ||
| 42 | |||
| 43 | =over 4 | ||
| 44 | |||
| 45 | =item * B<All configurations> | ||
| 46 | |||
| 47 | -a | --all Find all *_config | ||
| 48 | -r | --running Check all *.lck | ||
| 49 | |||
| 50 | =item * B<Configuration file> | ||
| 51 | |||
| 52 | -c | --config <configfile> Use the settings from the configfile | ||
| 53 | |||
| 54 | F<smokestatus.pl> uses the configuration file created by | ||
| 55 | F<configsmoke.pl>. | ||
| 56 | |||
| 57 | =item * B<Output options> | ||
| 58 | |||
| 59 | -m | --matrix Add the letter-matrix when possible | ||
| 60 | |||
| 61 | =item * B<General options> | ||
| 62 | |||
| 63 | -d | --dir <directory> Specify where the *_config files are | ||
| 64 | -h | --help Show help message (needs Pod::Usage) | ||
| 65 | --man Show the perldoc (needs Pod::Usage) | ||
| 66 | |||
| 67 | =back | ||
| 68 | |||
| 69 | =head1 DESCRIPTION | ||
| 70 | |||
| 71 | This is a small program that checks the status of a running smoke and | ||
| 72 | reports. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | GetOptions( \%opt, qw( | ||
| 77 | all|a running|r | ||
| 78 | dir|d=s | ||
| 79 | matrix|m | ||
| 80 | |||
| 81 | help|h man | ||
| 82 | |||
| 83 | config|c:s | ||
| 84 | )) or do_pod2usage( verbose => 1, myusage => $myusage ); | ||
| 85 | |||
| 86 | do_pod2usage( verbose => 1, exitval => 1, myusage => $myusage ) | ||
| 87 | unless $opt{all} || $opt{running} || defined $opt{config}; | ||
| 88 | $opt{ man} and do_pod2usage( verbose => 2, exitval => 0, myusage => $myusage ); | ||
| 89 | $opt{help} and do_pod2usage( verbose => 1, exitval => 0, myusage => $myusage ); | ||
| 90 | |||
| 91 | defined $opt{dir} or $opt{dir} = curdir(); | ||
| 92 | $opt{dir} && -d $opt{dir} or $opt{dir} = ''; | ||
| 93 | $opt{dir} ||= $FindBin::Bin; | ||
| 94 | |||
| 95 | my %save_opt = %opt; | ||
| 96 | my @configs = $opt{all} | ||
| 97 | ? get_configs() : $opt{running} ? get_lcks() : $opt{config}; | ||
| 98 | |||
| 99 | print "$0-$VERSION Test::Smoke-$Test::Smoke::VERSION Test::Smoke::Reporter-$Test::Smoke::Reporter::VERSION\n\n"; | ||
| 100 | |||
| 101 | foreach my $config ( @configs ) { | ||
| 102 | %opt = %save_opt; | ||
| 103 | $opt{config} = $config; | ||
| 104 | process_args(); | ||
| 105 | print "\n" unless $config eq $configs[0]; | ||
| 106 | my $pver = $opt{perl_version} ? " ($opt{perl_version})" : ""; | ||
| 107 | print "Checking status for configuration '$opt{config}'$pver\n"; | ||
| 108 | my $rpt = parse_out( { ddir => $opt{ddir} } ) or do { | ||
| 109 | guess_status( $opt{ddir}, $opt{adir}, $opt{config} ); | ||
| 110 | next; | ||
| 111 | }; | ||
| 112 | my $bcfg = Test::Smoke::BuildCFG->new( $conf->{cfg} ); | ||
| 113 | my $ccnt = 0; | ||
| 114 | Test::Smoke::skip_config( $_ ) or $ccnt++ for $bcfg->configurations; | ||
| 115 | |||
| 116 | printf " Change number $rpt->{patch} started on %s.\n", | ||
| 117 | scalar localtime( $rpt->{started} ); | ||
| 118 | |||
| 119 | print " $rpt->{ccount} out of $ccnt configurations finished", | ||
| 120 | $rpt->{ccount} ? " in $rpt->{time}.\n" : ".\n"; | ||
| 121 | |||
| 122 | printf " $rpt->{fail} configuration%s showed failures%s.\n", | ||
| 123 | ($rpt->{fail} == 1 ? "":"s"), $rpt->{stat} ? " ($rpt->{stat})":"" | ||
| 124 | if $rpt->{ccount}; | ||
| 125 | |||
| 126 | printf " $rpt->{running} failure%s in the running configuration.\n", | ||
| 127 | ($rpt->{running} == 1 ? "" : "s") | ||
| 128 | if exists $rpt->{running}; | ||
| 129 | |||
| 130 | my $todo = $ccnt - $rpt->{ccount}; | ||
| 131 | my $est_curr = $rpt->{avg} > 0 | ||
| 132 | ? $rpt->{avg} - ( $rpt->{rtime} - $rpt->{ccount}*$rpt->{avg} ) : 0; | ||
| 133 | my $est_todo = $todo > 0 && $rpt->{avg} > 0 | ||
| 134 | ? ( (($todo - 1) * $rpt->{avg}) + $est_curr ) : 0; | ||
| 135 | $est_todo > $todo * $rpt->{avg} and $est_todo = $todo * $rpt->{avg}; | ||
| 136 | my $killtime = calc_timeout( $conf->{killtime}, $rpt->{started} ) | ||
| 137 | ? timeout_msg( $conf->{killtime}, $rpt->{started } ) | ||
| 138 | : ""; | ||
| 139 | |||
| 140 | my $todo_time = $rpt->{avg} <= 0 ? '.' : | ||
| 141 | $est_todo <= 0 | ||
| 142 | ? has_lck( $config ) | ||
| 143 | ? ", smoke looks hanging delay " . time_in_hhmm( -$est_todo ) | ||
| 144 | : ", smoke looks terminated${killtime}." | ||
| 145 | : ", estimated completion in " . time_in_hhmm( $est_todo ); | ||
| 146 | |||
| 147 | printf " $todo configuration%s to finish$todo_time\n", | ||
| 148 | $todo == 1 ? "" : "s" | ||
| 149 | if $todo; | ||
| 150 | |||
| 151 | printf " Average smoke duration: %s.\n", time_in_hhmm( $rpt->{avg} ) | ||
| 152 | if $rpt->{ccount}; | ||
| 153 | |||
| 154 | if ( $rpt->{ccount} > 0 && $opt{matrix} ) { | ||
| 155 | printf " Matrix, using %s:\n", $rpt->{reporter}->ccinfo; | ||
| 156 | print join "", map " $_\n" | ||
| 157 | => split /\n/, $rpt->{reporter}->smoke_matrix; | ||
| 158 | print join "", map " $_\n" | ||
| 159 | => split /\n/, $rpt->{reporter}->bldenv_legend; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | sub guess_status { | ||
| 164 | my( $ddir, $adir, $config ) = @_; | ||
| 165 | ( my $patch = get_patch( $ddir )->[0] || "" ) =~ s/\?//g; | ||
| 166 | if ( $patch && $adir ) { | ||
| 167 | my $a_rpt = catfile( $adir, "rpt${patch}.rpt" ); | ||
| 168 | my $mtime = -e $a_rpt ? (stat $a_rpt)[9] : undef; | ||
| 169 | if ( $mtime ) { | ||
| 170 | local *REPORT; | ||
| 171 | my $status; | ||
| 172 | if ( open REPORT, "< $a_rpt" ) { | ||
| 173 | my $report = do { local $/; <REPORT> }; | ||
| 174 | close REPORT; | ||
| 175 | my $summary = ( parse_report_Config( $report ) )[-1]; | ||
| 176 | $status = $summary ? " [$summary]" : ""; | ||
| 177 | } | ||
| 178 | printf " Change number %s%s finshed on %s\n", | ||
| 179 | $patch, $status, scalar localtime( $mtime ); | ||
| 180 | } else { | ||
| 181 | print " Change number $patch found, but no (previous) results.\n"; | ||
| 182 | } | ||
| 183 | } else { | ||
| 184 | print " No (previous) results for $config\n"; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | sub parse_out { | ||
| 189 | my( $conf ) = @_; | ||
| 190 | |||
| 191 | return unless -f catfile $conf->{ddir}, 'mktest.out'; | ||
| 192 | |||
| 193 | my $reporter = Test::Smoke::Reporter->new( $conf ); | ||
| 194 | my %rpt = %{ $reporter->{_rpt} }; | ||
| 195 | |||
| 196 | $rpt{finished} ||= "Busy"; | ||
| 197 | $rpt{ccount} = scalar keys %{ $rpt{statcfg} }; | ||
| 198 | $rpt{avg} = $rpt{ccount} ? $rpt{secs} / $rpt{ccount} : 0; | ||
| 199 | $rpt{time} = time_in_hhmm( $rpt{secs} ); | ||
| 200 | $rpt{rtime} = time() - $rpt{started}; | ||
| 201 | $rpt{fail} = 0; $rpt{stat} = { }; | ||
| 202 | |||
| 203 | my $fcnt = 0; | ||
| 204 | foreach my $config ( keys %{ $rpt{statcfg} } ) { | ||
| 205 | |||
| 206 | if ( $rpt{statcfg}{ $config } ) { | ||
| 207 | $fcnt = $rpt{statcfg}{ $config }; | ||
| 208 | $rpt{statcfg}{ $config } = "F" | ||
| 209 | if $rpt{statcfg}{ $config } =~ /^\d+$/; | ||
| 210 | |||
| 211 | $rpt{fail}++; | ||
| 212 | $rpt{stat}->{ $rpt{statcfg}{ $config } }++; | ||
| 213 | } | ||
| 214 | } | ||
| 215 | $rpt{stat} = join "", sort keys %{ $rpt{stat} }; | ||
| 216 | |||
| 217 | $rpt{reporter} = $reporter; | ||
| 218 | return \%rpt | ||
| 219 | } | ||
| 220 | |||
| 221 | sub get_configs { | ||
| 222 | local *DH; | ||
| 223 | opendir DH, $opt{dir} or return; | ||
| 224 | my @list = grep /_config\z/ => readdir DH; | ||
| 225 | closedir DH; | ||
| 226 | return sort @list; | ||
| 227 | } | ||
| 228 | |||
| 229 | sub get_lcks { | ||
| 230 | local *DH; | ||
| 231 | opendir DH, $opt{dir} or return; | ||
| 232 | my @list = map { s/\.lck\z/_config/; $_ } grep /\.lck\z/ => readdir DH; | ||
| 233 | closedir DH; | ||
| 234 | return sort @list; | ||
| 235 | } | ||
| 236 | |||
| 237 | sub has_lck { | ||
| 238 | ( my $lck = shift ) =~ s/_config\z/.lck/; | ||
| 239 | return -f File::Spec->catfile( $opt{dir}, $lck ); | ||
| 240 | } | ||
| 241 | |||
| 242 | sub process_args { | ||
| 243 | return unless defined $opt{config}; | ||
| 244 | |||
| 245 | $opt{config} eq "" and $opt{config} = 'smokecurrent_config'; | ||
| 246 | read_config( $opt{config} ) or do { | ||
| 247 | my $config_name = File::Spec->catfile( $opt{dir}, $opt{config} ); | ||
| 248 | read_config( $config_name ); | ||
| 249 | }; | ||
| 250 | |||
| 251 | unless ( Test::Smoke->config_error ) { | ||
| 252 | foreach my $option ( keys %$conf ) { | ||
| 253 | $opt{ $option } = $conf->{ $option }, next | ||
| 254 | unless defined $opt{ $option }; | ||
| 255 | $conf->{ $option } = $opt{ $option } | ||
| 256 | } | ||
| 257 | } else { | ||
| 258 | warn "WARNING: Could not process '$opt{config}': " . | ||
| 259 | Test::Smoke->config_error . "\n"; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | sub timeout_msg { | ||
| 264 | my( $killtime, $from ) = @_; | ||
| 265 | |||
| 266 | defined $from or $from = time; | ||
| 267 | if ( $killtime =~ /^\+(\d+):(\d+)/ ) { | ||
| 268 | my( $hh, $mm ) = ( $1, $2 ); | ||
| 269 | $from += 60 * $mm; | ||
| 270 | $from += 60 * 60 * $hh; | ||
| 271 | return " from " . localtime $from; | ||
| 272 | } else { | ||
| 273 | my @lt = localtime $from; | ||
| 274 | my( $hh, $mm ) = $killtime =~ /(\d+):(\d+)/; | ||
| 275 | my $time_min = 60 * $hh + $mm; | ||
| 276 | my( $now_m, $now_h ) = @lt[1, 2]; | ||
| 277 | my $now_min = 60 * $now_h + $now_m; | ||
| 278 | my $kill_min = $time_min - $now_min; | ||
| 279 | $kill_min += 60 * 24 if $kill_min < 0; | ||
| 280 | |||
| 281 | $hh = int( $kill_min / 60 ); | ||
| 282 | $mm = $kill_min % 60; | ||
| 283 | @lt[ 1, 2] = ( $mm, $hh ); | ||
| 284 | |||
| 285 | return " at " . localtime timelocal @lt; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | =head1 COPYRIGHT | ||
| 290 | |||
| 291 | E<copy> 2002-2003, All rights reserved. | ||
| 292 | |||
| 293 | * Abe Timmerman <abeltje@cpan.org> | ||
| 294 | |||
| 295 | This library is free software; you can redistribute it and/or modify | ||
| 296 | it under the same terms as Perl itself. | ||
| 297 | |||
| 298 | See: | ||
| 299 | |||
| 300 | =over 4 | ||
| 301 | |||
| 302 | item * L<http://www.perl.com/perl/misc/Artistic.html> | ||
| 303 | |||
| 304 | item * L<http://www.gnu.org/copyleft/gpl.html> | ||
| 305 | |||
| 306 | =back | ||
| 307 | |||
| 308 | This program is distributed in the hope that it will be useful, | ||
| 309 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 310 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 311 | |||
| 312 | =cut |