Skip to content

Commit 4d9328f

Browse files
authored
Merge pull request #38 from kuznetsovmoci/Buffer
Failed Tests Log
2 parents 770cfbf + 97b2bd6 commit 4d9328f

File tree

2 files changed

+246
-8
lines changed

2 files changed

+246
-8
lines changed

common/prettify.pm

Lines changed: 222 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,204 @@ sub Normal ($)
353353
###############################################################################
354354
###############################################################################
355355

356+
package Prettify::Failed_Tests_HTML;
357+
358+
use strict;
359+
use warnings;
360+
361+
use FileHandle;
362+
363+
###############################################################################
364+
365+
sub new ($)
366+
{
367+
my $proto = shift;
368+
my $class = ref ($proto) || $proto;
369+
my $self = {};
370+
my $basename = shift;
371+
my $buildname = shift;
372+
my $rev_link = shift;
373+
my $log_prefix = shift;
374+
375+
my $filename = $log_prefix . "_Failed_Tests_By_Build.html";
376+
377+
$basename =~ s/^.*\///;
378+
379+
$self->{FULLHTML} = "$buildname/$basename" . "_Full.html";
380+
$self->{ERROR_COUNTER} = 0;
381+
$self->{WARNING_COUNTER} = 0;
382+
$self->{SECTION_COUNTER} = 0;
383+
$self->{SUBSECTION_COUNTER} = 0;
384+
$self->{TITLE} = "Failed Test Brief Log By Build";
385+
$self->{GIT_CHECKEDOUT_OPENDDS} = "unknown";
386+
$self->{REV_LINK} = $rev_link;
387+
388+
unless (-e $filename) {
389+
my $file_handle = new FileHandle ($filename, 'w');
390+
print {$file_handle} "<h1>$self->{TITLE}</h1>\n";
391+
}
392+
393+
$self->{FH} = new FileHandle ($filename, '>>');
394+
$self->{FILENAME} = $filename;
395+
$self->{BUILDNAME} = $buildname;
396+
397+
bless ($self, $class);
398+
return $self;
399+
}
400+
401+
sub Header ()
402+
{
403+
my $self = shift;
404+
405+
if (defined $self->{LAST_SECTION} && $self->{LAST_SECTION} eq 'Test') {
406+
print {$self->{FH}} "<html>\n";
407+
print {$self->{FH}} "<body bgcolor=\"white\">\n";
408+
}
409+
}
410+
411+
sub Footer ()
412+
{
413+
my $self = shift;
414+
415+
if (defined $self->{LAST_SECTION} && $self->{LAST_SECTION} eq 'Test') {
416+
# In the case where there was no errors or warnings, output a note
417+
if ($self->{ERROR_COUNTER} == 0 && $self->{WARNING_COUNTER} == 0) {
418+
print {$self->{FH}} "No Errors or Warnings detected<br>\n";
419+
}
420+
421+
print {$self->{FH}} "</body>\n";
422+
print {$self->{FH}} "</html>\n";
423+
}
424+
}
425+
426+
sub Section ($)
427+
{
428+
my $self = shift;
429+
my $s = shift;
430+
431+
# Escape any '<' or '>' signs
432+
$s =~ s/</&lt;/g;
433+
$s =~ s/>/&gt;/g;
434+
435+
my $counter = ++$self->{SECTION_COUNTER};
436+
437+
# Save for later use
438+
439+
$self->{LAST_SECTION} = $s;
440+
}
441+
442+
sub Description ($)
443+
{
444+
my $self = shift;
445+
446+
# Ignore
447+
}
448+
449+
sub Timestamp ($)
450+
{
451+
my $self = shift;
452+
# Ignore
453+
}
454+
455+
sub Subsection ($)
456+
{
457+
my $self = shift;
458+
my $s = shift;
459+
460+
# Escape any '<' or '>' signs
461+
$s =~ s/</&lt;/g;
462+
$s =~ s/>/&gt;/g;
463+
464+
my $counter = ++$self->{SUBSECTION_COUNTER};
465+
466+
# Save for later use
467+
468+
$self->{LAST_SUBSECTION} = $s;
469+
}
470+
471+
sub Print_Sections ()
472+
{
473+
my $self = shift;
474+
475+
if (defined $self->{LAST_SECTION} && defined $self->{LAST_SUBSECTION} && $self->{LAST_SECTION} eq 'Test') {
476+
if (defined $self->{BUILDNAME}) {
477+
print {$self->{FH}} "<hr><h2>$self->{BUILDNAME}</h2>\n";
478+
my $rev = substr($self->{GIT_CHECKEDOUT_OPENDDS}, 0, 8);
479+
if ($rev ne "unknown") {
480+
my $rev_line = "Rev: ";
481+
if (length($self->{REV_LINK})) {
482+
$rev_line .= "<a href=$self->{REV_LINK}";
483+
$rev_line =~ s/\/$//g;
484+
$rev_line .= "/$rev>";
485+
}
486+
$rev_line .= $rev;
487+
if (length($self->{REV_LINK})) {
488+
$rev_line .= "</a>";
489+
}
490+
print {$self->{FH}} "$rev_line<hr>\n";
491+
}
492+
$self->{BUILDNAME} = undef;
493+
}
494+
495+
print {$self->{FH}} "<a name=\"subsection_$self->{SUBSECTION_COUNTER}\"></a>";
496+
print {$self->{FH}} "<h3>$self->{LAST_SUBSECTION}</h3>\n";
497+
$self->{LAST_SUBSECTION} = undef;
498+
}
499+
}
500+
501+
sub Error ($)
502+
{
503+
my $self = shift;
504+
my $s = shift;
505+
506+
if (defined $self->{LAST_SECTION} && $self->{LAST_SECTION} eq 'Test') {
507+
508+
# Escape any '<' or '>' signs
509+
$s =~ s/</&lt;/g;
510+
$s =~ s/>/&gt;/g;
511+
512+
my $counter = ++$self->{ERROR_COUNTER};
513+
514+
$self->Print_Sections ();
515+
516+
print {$self->{FH}} "<a name=\"error_$counter\"></a>\n";
517+
print {$self->{FH}} "<tt>[<a href=\"$self->{FULLHTML}#error_$counter"
518+
. "\">Details</a>] </tt>";
519+
print {$self->{FH}} "<font color=\"FF0000\"><tt>$s</tt></font><br>\n";
520+
}
521+
}
522+
523+
sub Warning ($)
524+
{
525+
my $self = shift;
526+
my $s = shift;
527+
528+
if (defined $self->{LAST_SECTION} && $self->{LAST_SECTION} eq 'Test') {
529+
# Escape any '<' or '>' signs
530+
$s =~ s/</&lt;/g;
531+
$s =~ s/>/&gt;/g;
532+
533+
my $counter = ++$self->{WARNING_COUNTER};
534+
535+
$self->Print_Sections ();
536+
537+
print {$self->{FH}} "<a name=\"warning_$counter\"></a>\n";
538+
print {$self->{FH}} "<tt>[<a href=\"$self->{FULLHTML}#warning_$counter"
539+
. "\">Details</a>] </tt>";
540+
print {$self->{FH}} "<font color=\"FF7700\"><tt>$s</tt></font><br>\n";
541+
}
542+
}
543+
544+
sub Normal ($)
545+
{
546+
my $self = shift;
547+
548+
# Ignore
549+
}
550+
551+
###############################################################################
552+
###############################################################################
553+
356554
package Prettify::JUnit;
357555

358556
use strict;
@@ -862,12 +1060,16 @@ use FileHandle;
8621060

8631061
###############################################################################
8641062

865-
sub new ($)
1063+
sub new ($$$$$$)
8661064
{
8671065
my $proto = shift;
8681066
my $class = ref ($proto) || $proto;
8691067
my $self = {};
8701068
my $basename = shift;
1069+
my $buildname = shift;
1070+
my $skip_failed_test_logs = shift;
1071+
my $rev_link = shift;
1072+
my $log_prefix = shift;
8711073

8721074
# Initialize some variables
8731075

@@ -897,6 +1099,10 @@ sub new ($)
8971099
new Prettify::Totals_HTML ($basename), #Must be 2
8981100
new Prettify::Config_HTML ($basename), #Must be 3
8991101
);
1102+
1103+
if (!$skip_failed_test_logs) {
1104+
push @{$self->{OUTPUT}}, new Prettify::Failed_Tests_HTML ($basename, $buildname, $rev_link, $log_prefix); #Must be 4, if used
1105+
}
9001106

9011107
my $junit = main::GetVariable ('junit_xml_output');
9021108
if (defined $junit) {
@@ -1242,6 +1448,11 @@ sub Setup_Handler ($)
12421448
elsif ("$totals->{GIT_CHECKEDOUT_OPENDDS}" eq "Matched")
12431449
{
12441450
$totals->{GIT_CHECKEDOUT_OPENDDS} = $sha;
1451+
if (exists ($self->{OUTPUT}[4]))
1452+
{
1453+
(@{$self->{OUTPUT}})[4]->{GIT_CHECKEDOUT_OPENDDS} = $sha;
1454+
}
1455+
12451456
}
12461457
$self->Output_Normal ($s);
12471458
}
@@ -1372,6 +1583,10 @@ sub Config_Handler ($)
13721583
my $revision = $totals->{GIT_REVISIONS}[0];
13731584
print "Matched GIT url to revision $revision\n";
13741585
$totals->{GIT_CHECKEDOUT_OPENDDS} = $revision;
1586+
if (exists ($self->{OUTPUT}[4]))
1587+
{
1588+
(@{$self->{OUTPUT}})[4]->{GIT_CHECKEDOUT_OPENDDS} = $revision;
1589+
}
13751590
}
13761591
}
13771592
elsif ($s =~ m/GIT_COMMIT=(.+)/)
@@ -1505,13 +1720,17 @@ sub BuildErrors ($)
15051720
# In this function we process the log file line by line,
15061721
# looking for errors.
15071722

1508-
sub Process ($)
1723+
sub Process ($;$$$$)
15091724
{
15101725
my $filename = shift;
15111726
my $basename = $filename;
15121727
$basename =~ s/\.txt$//;
1728+
my $buildname = shift // "";
1729+
my $skip_failed_test_logs = shift // 1;
1730+
my $rev_link = shift // "";
1731+
my $log_prefix = shift // "";
15131732

1514-
my $processor = new Prettify ($basename);
1733+
my $processor = new Prettify ($basename, $buildname, $skip_failed_test_logs, $rev_link, $log_prefix);
15151734

15161735
my $input = new FileHandle ($filename, 'r');
15171736

scoreboard.pl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383

8484
our $custom_css = "";
8585

86+
our $log_prefix = "";
87+
8688
my $build_instructions = "<br><p>Instructions for setting up your
8789
own scoreboard are
8890
<A HREF=\"https://github.com/DOCGroup/autobuild/blob/master/README.md\">
@@ -149,8 +151,10 @@ ($$)
149151
print $indexhtml "$preamble\n";
150152
print $indexhtml "\n<hr>\n";
151153

154+
### Failed Test Reports
155+
print $indexhtml "<br><a href=\"" . $log_prefix . "_Failed_Tests_By_Build.html\">Failed Test Brief Log By Build</a><br>\n";
156+
152157
### Print timestamp
153-
154158
print $indexhtml '<br>Last updated at ' . get_time_str() . "<br>\n";
155159

156160
### Print the Footer
@@ -539,7 +543,8 @@ ($)
539543
}
540544

541545
print " Prettifying\n" if($verbose);
542-
Prettify::Process ("$directory/$buildname/$filename");
546+
547+
Prettify::Process ("$directory/$buildname/$filename", $buildname, $use_build_logs, $builds{$buildname}->{DIFFROOT}, "$directory/$log_prefix");
543548
}
544549
}
545550
}
@@ -567,6 +572,11 @@ ($)
567572
return;
568573
}
569574

575+
my $failed_tests = $directory . "/" . $log_prefix . "_Failed_Tests_By_Build.html";
576+
if (-e $failed_tests) {
577+
unlink $failed_tests;
578+
}
579+
570580
foreach my $buildname (keys %builds) {
571581
my $keep = $keep_default;
572582
my @existing;
@@ -650,10 +660,10 @@ ($)
650660
print " in local_update_cache, post=$post\n" if $verbose;
651661

652662
foreach my $file (@existing) {
653-
if ( -e $file . "_Totals.html" ) {next;}
654-
if ( $post == 1 ) {
663+
if ( -e $file . "_Totals.html" || $post == 1 ) {
655664
print " Prettifying $file.txt\n" if($verbose);
656-
Prettify::Process ("$file.txt");
665+
666+
Prettify::Process ("$file.txt", $buildname, $use_build_logs, $builds{$buildname}->{DIFFROOT}, "$directory/$log_prefix");
657667
$updated++;
658668
} else {
659669
# Create the triggerfile for the next time we run
@@ -779,6 +789,11 @@ ($)
779789
return;
780790
}
781791

792+
my $failed_tests = $directory . "/" . $log_prefix . "_Failed_Tests_By_Build.html";
793+
if (-e $failed_tests) {
794+
unlink $failed_tests;
795+
}
796+
782797
foreach my $buildname (keys %builds) {
783798
### Do we use the local cache or do we work
784799
### with the storage of the build itself?
@@ -1138,6 +1153,9 @@ ($$$)
11381153

11391154
### Print timestamp
11401155

1156+
if (!$use_build_logs) {
1157+
print $indexhtml "<br><a href=\"" . $log_prefix . "_Failed_Tests_By_Build.html\">Failed Test Brief Log By Build</a><br>\n";
1158+
}
11411159
print $indexhtml '<br>Last updated at ' . get_time_str() . "<br>\n";
11421160

11431161
### Print the Footer
@@ -1787,6 +1805,7 @@ sub get_time_str
17871805

17881806
if (defined $opt_o) {
17891807
$out_file = $opt_o;
1808+
($log_prefix = $out_file) =~ s/\.[^.]+$//;
17901809
}
17911810

17921811
if (defined $opt_r) {

0 commit comments

Comments
 (0)