[PATCH 1/2] testbot/web: Better present the logs and task errors.

Francois Gouget fgouget at codeweavers.com
Thu Jun 21 07:23:54 CDT 2018


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 <fgouget at codeweavers.com>
---
 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 = <LOGFILE>))
+      $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 "</code></pre>" if (!$LogFirst);
+          print "<div class='LogDllName'>$CurrentDll:</div><pre><code>";
+          $PrintedDll = $CurrentDll;
+          $LogFirst = 0;
+        }
+        elsif ($LogFirst)
+        {
+          print "<pre><code>";
+          $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 "</code></pre>";
-            }
-            print "<div class='LogDllName'>$CurrentDll:</div><pre><code>";
-            $PrintedDll = $CurrentDll;
-          }
-          elsif ($First)
-          {
-            print "<pre><code>";
-            $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 = <ERRFILE>))
+        print "</code></pre>\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 "</code></pre>\n";
-            }
-            print "<br><pre><code>";
-            $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 "</code></pre>\n";
+        $EmptyDiag = "<p>No log, task was canceled</p>\n";
+      }
+      elsif ($StepTask->Status eq "skipped")
+      {
+        $EmptyDiag = "<p>No log, task skipped</p>\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 = <ERRFILE>))
+      my $ErrFirst = 1;
+      foreach my $Line (<$ErrFile>)
       {
-        chomp($Line);
-        if (! $HasErrEntries)
+        chomp $Line;
+        if ($ErrFirst)
         {
+          print "<hr>\n" if (!$LogFirst);
           print "<pre><code>";
-          $HasErrEntries = 1;
+          $ErrFirst = 0;
         }
         print $self->escapeHTML($Line), "\n";
       }
-      if ($HasErrEntries)
+      close($ErrFile);
+
+      if (!$ErrFirst)
       {
         print "</code></pre>\n";
       }
-      else
+      elsif (defined $EmptyDiag)
       {
-        print "Empty log";
+        print $EmptyDiag;
       }
-      close ERRFILE;
-    }
-    elsif ($StepTask->Status eq "canceled")
-    {
-      print "<p>No log, task was canceled</p>\n";
-    }
-    elsif ($StepTask->Status eq "skipped")
-    {
-      print "<p>No log, task skipped</p>\n";
-    }
-    else
-    {
-      print "<p>No log available yet</p>\n";
     }
   }
   print "</div>\n";
-- 
2.17.1




More information about the wine-devel mailing list