From: Francois Gouget Subject: [PATCH 1/2] testbot/web: Better present the logs and task errors. Message-Id: <5c4cc185034c5cbaf4e69dde7aab683d5f67ed00.1529583802.git.fgouget@codeweavers.com> Date: Thu, 21 Jun 2018 14:23:54 +0200 (CEST) Add a horizontal ruler so the log / test report is always clearly separated from the task error messages. Avoid duplicating the code that shows the task errors. Signed-off-by: Francois Gouget --- testbot/web/JobDetails.pl | 152 +++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 85 deletions(-) diff --git a/testbot/web/JobDetails.pl b/testbot/web/JobDetails.pl index 3add52b4c..1536e87cd 100644 --- a/testbot/web/JobDetails.pl +++ b/testbot/web/JobDetails.pl @@ -408,127 +408,109 @@ sub GenerateBody($) my $LogName = $MoreInfo->{Full} || $MoreInfo->{Logs}->[0] || "log"; my $ErrName = $LogName eq "log.old" ? "err.old" : "err"; - if (open LOGFILE, "<", "$TaskDir/$LogName") + my ($EmptyDiag, $LogFirst); + if (open(my $LogFile, "<", "$TaskDir/$LogName")) { - my $HasLogEntries = !1; - my $First = 1; + my $HasLogEntries; my $CurrentDll = ""; my $PrintedDll = ""; - my $Line; - while (defined($Line = )) + $LogFirst = 1; + foreach my $Line (<$LogFile>) { $HasLogEntries = 1; - chomp($Line); + chomp $Line; if ($Line =~ m/^([^:]+):[^ ]+ start [^ ]+ -\s*$/) { $CurrentDll = $1; } my ($Highlight, $Plain) = $self->GetHtmlLine($MoreInfo->{Full}, $Line); - if ($MoreInfo->{Full} || defined $Highlight) + next if (!$MoreInfo->{Full} and !defined $Highlight); + + if ($PrintedDll ne $CurrentDll && !$MoreInfo->{Full}) + { + print "" if (!$LogFirst); + print "
$CurrentDll:
";
+          $PrintedDll = $CurrentDll;
+          $LogFirst = 0;
+        }
+        elsif ($LogFirst)
+        {
+          print "
";
+          $LogFirst = 0;
+        }
+        if (!$MoreInfo->{Full} && $Line =~ m/^[^:]+:([^:]*)(?::[0-9a-f]+)? done \(258\)/)
+        {
+          my $Unit = $1 ne "" ? "$1: " : "";
+          print "${Unit}Timeout\n";
+        }
+        else
         {
-          if ($PrintedDll ne $CurrentDll && !$MoreInfo->{Full})
-          {
-            if ($First)
-            {
-              $First = !1;
-            }
-            else
-            {
-              print "
"; - } - print "
$CurrentDll:
";
-            $PrintedDll = $CurrentDll;
-          }
-          elsif ($First)
-          {
-            print "
";
-            $First = !1;
-          }
-          if (!$MoreInfo->{Full} && $Line =~ m/^[^:]+:([^:]*)(?::[0-9a-f]+)? done \(258\)/)
-          {
-            my $Unit = $1 ne "" ? "$1: " : "";
-            print "${Unit}Timeout\n";
-          }
-          else
-          {
-            print(($Highlight || $Plain), "\n");
-          }
+          print(($Highlight || $Plain), "\n");
         }
       }
-      close LOGFILE;
+      close($LogFile);
 
-      if (open ERRFILE, "<", "$TaskDir/$ErrName")
+      if (!$LogFirst)
       {
-        $CurrentDll = "*err*";
-        while (defined($Line = ))
+        print "
\n"; + } + elsif ($HasLogEntries) + { + # Here we know we did not show the full log since it was not empty, + # and yet we did not show anything to the user. But don't claim there + # is no failure if the error log is not empty. + if (-z "$TaskDir/$ErrName") { - $HasLogEntries = 1; - chomp($Line); - if ($PrintedDll ne $CurrentDll) - { - if ($First) - { - $First = !1; - } - else - { - print "
\n"; - } - print "
";
-            $PrintedDll = $CurrentDll;
-          }
-          print $self->escapeHTML($Line), "\n";
+          print "No ". ($StepTask->Type eq "single" ||
+                        $StepTask->Type eq "suite" ? "test" : "build") .
+                " failures found";
+          $LogFirst = 0;
         }
-        close ERRFILE;
       }
-
-      if (! $First)
+      elsif ($StepTask->Status eq "canceled")
       {
-        print "
\n"; + $EmptyDiag = "

No log, task was canceled

\n"; + } + elsif ($StepTask->Status eq "skipped") + { + $EmptyDiag = "

No log, task skipped

\n"; } else { - print $HasLogEntries ? "No " . - ($StepTask->Type eq "single" || - $StepTask->Type eq "suite" ? "test" : "build") . - " failures found" : "Empty log"; + print "Empty log"; + $LogFirst = 0; } } - elsif (open ERRFILE, "<", "$TaskDir/$ErrName") + else + { + print "No log". ($StepTask->Status =~ /^(?:queued|running)$/ ? " yet" : ""); + $LogFirst = 0; + } + + if (open(my $ErrFile, "<", "$TaskDir/$ErrName")) { - my $HasErrEntries = !1; - my $Line; - while (defined($Line = )) + my $ErrFirst = 1; + foreach my $Line (<$ErrFile>) { - chomp($Line); - if (! $HasErrEntries) + chomp $Line; + if ($ErrFirst) { + print "
\n" if (!$LogFirst); print "
";
-          $HasErrEntries = 1;
+          $ErrFirst = 0;
         }
         print $self->escapeHTML($Line), "\n";
       }
-      if ($HasErrEntries)
+      close($ErrFile);
+
+      if (!$ErrFirst)
       {
         print "
\n"; } - else + elsif (defined $EmptyDiag) { - print "Empty log"; + print $EmptyDiag; } - close ERRFILE; - } - elsif ($StepTask->Status eq "canceled") - { - print "

No log, task was canceled

\n"; - } - elsif ($StepTask->Status eq "skipped") - { - print "

No log, task skipped

\n"; - } - else - { - print "

No log available yet

\n"; } } print "\n"; -- 2.17.1