#!/pro/bin/perl -w

my $p7    = "/pro/3gl/CPAN/perl-5.7.1";
my @hosts = qw(l1 k1 i2 ibm);
my (%rpt, @confs, %confs, $patch);

open RPT, "> $p7/mktest.rpt" or die "mktest.rpt: $!";
select RPT;

for my $host (@hosts) {
    my $perlio = "";
    my $conf   = "";
    open OUT, "</$host$p7/mktest.out" or next;
    for (<OUT>) {
	m/^\s*$/ and next;
	m/^-+$/  and next;
	if (m/^\s*Smoking patch (\d+)/) {
	    $patch = $1;
	    next;
	    }
	if (s/^Configuration:\s+//) {
	    s/-Dusedevel\s+//;
	    s/\s+-des//;
	    s/\s+$//;
	    $conf = $_;
	    $confs{$_}++ or push @confs, $conf;
	    next;
	    }
	if (m/PERLIO\s*=\s*(\w+)/) {
	    $perlio = $1;
	    next;
	    }
	if (m/^\s*All tests successful/) {
	    $rpt{$host}{$conf}{$perlio} = "O";
	    next;
	    }
	if (m/^\s*Skipped this configuration/) {
	    $rpt{$host}{$conf}{stdio}  = "o";
	    $rpt{$host}{$conf}{perlio} = "o";
	    next;
	    }
	if (m/^\s*Unable to build/) {
	    $rpt{$host}{$conf}{stdio}  = "-";
	    $rpt{$host}{$conf}{perlio} = "-";
	    next;
	    }
	if (m/FAILED/) {
	    push @{$rpt{$host}{$conf}{$perlio}}, $_;
	    next;
	    }
	}
    }

print <<EOH;
Automated smoke report for patch $patch

O = OK
o = OK (but skipped, cause tested in an earlier configuration)
- = not tested (cause unable to build)
F = Failure(s), extended report at the bottom
  left  letter for PERLIO = stdio,
  right letter for PERLIO = perlio

HP-UX HP-UX  AIX   AIX
11.00 10.20  4.3   4.2  Configuration
----- ----- ----- ----- --------------------------------------------------------------------
EOH

my @fail = ();
for my $conf (@confs) {
    for my $host (@hosts) {
	for my $perlio ("stdio", "perlio") {
	    my $res = $rpt{$host}{$conf}{$perlio};
	    if (ref $res) {
		print " F";
		push @fail, [ $host, $perlio, $conf, $res ];
		next;
		}
	    print " ", $res?$res:"?";
	    }
	print "  ";
	}
    print "$conf\n";
    }

my %os = (
    l1  => "HP-UX 11.00",
    k1  => "HP-UX 10.20",
    i2  => "AIX 4.3",
    ibm => "AIX 4.2",
    );
for my $ref (@fail) {
    printf "\n%-12s %-8s %s\n", $os{$ref->[0]}, @{$ref}[1,2];
    print @{$ref->[-1]};
    }
