#!/usr/bin/perl -w
# Generate HTML summary page for a collection of GUI reports (with kpi.csv)
# (C) 2020 Candela Technologies Inc.
#
use strict;
use warnings;
use diagnostics;
use Carp;
$SIG{ __DIE__  } = sub { Carp::confess( @_ ) };
$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output
$| = 1;
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use Getopt::Long;
use HTML::Entities;
our $dir = "";
our $notes = "";
our $gitlog = "";
our $dutgitlog = "";
our $title = "Automated test results.";
########################################################################
# Nothing to configure below here, most likely.
########################################################################
our $usage = <<"__EndOfUsage__";
$0 [ --dir directory-to-process --notes testbed-notes-file.html --dutgitlog dut-gitlog-output.html --gitlog gitlog-output.html ] < html_template.html
Example:
 cat html-template | $0 --dir ~/tmp/results --title "My Title" --notes testbeds/my_testbed/testbed_notes.html --dutgitlog /tmp/dgitlog.html --gitlog /tmp/gitlog.html
__EndOfUsage__
my $i = 0;
my $show_help = 0;
GetOptions
(
   'dir|d=s'            => \$::dir,
   'notes|n=s'          => \$::notes,
   'gitlog|g=s'         => \$::gitlog,
   'dutgitlog=s'        => \$::dutgitlog,
   'title|t=s'          => \$::title,
   'help|h'             => \$show_help,
) || die("$::usage");
if ($show_help) {
   print $usage;
   exit 0;
}
my $testbed_notes = "";
if (-f "$notes") {
   $testbed_notes .= "Test Bed Notes.
\n";
   $testbed_notes .= `cat $notes`;
}
if (-f "$dutgitlog") {
   $testbed_notes .= "
\n"; $testbed_notes .= `cat $dutgitlog`; $testbed_notes .= "
\n"; } if (-f "$gitlog") { $testbed_notes .= "
\n"; $testbed_notes .= `cat $gitlog`; $testbed_notes .= "
\n"; } $testbed_notes .= "
Top lanforge-scripts commits.
\n"; $testbed_notes .= `git log -n 8 --oneline`; $testbed_notes .= "\n"; chdir($dir); my @files = `ls`; chomp(@files); my $line; # Find some html helpers and copy them to current dir. foreach $line (@files) { if ( -d $line) { if ( -f "$line/canvil.ico") { `cp $line/canvil.ico ./`; `cp $line/*.css ./`; `cp $line/candela_swirl* ./`; `cp $line/CandelaLogo* ./`; last; } } } my $dut_tr = ""; my $kpi_tr = ""; my $tests_tr = ""; # TODO: Add git commit history for other repositories perhaps? foreach my $line (@files) { if ( -d $line) { #print "Checking report: $line\n"; if ( -d "$line/logs") { processLogs("$line/logs"); my $log_links = ""; my $li = 0; my $iline; my @ifiles = `ls $line/logs/*-idx.html`; chomp(@ifiles); foreach $iline (@ifiles) { $log_links .= " [$li]"; } if ($log_links ne "") { $log_links = "Errors: $log_links"; } $tests_tr .= "