[PATCH 1/2] testbot/web: Allow showing multiple job screenshots and logs.

Francois Gouget fgouget at codeweavers.com
Tue Jun 19 19:46:51 CDT 2018


It's now possible to have the job details page show multiple
screenshots and multiple logs.
Once a screenshot / log is shown, the link can be clicked again to hide
it.
The code can also more easily be extended to handle more log files.
The code inserting the links is simpler too.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/bin/WineRunTask.pl |   2 +-
 testbot/web/JobDetails.pl  | 156 +++++++++++++++++++++++--------------
 2 files changed, 97 insertions(+), 61 deletions(-)

diff --git a/testbot/bin/WineRunTask.pl b/testbot/bin/WineRunTask.pl
index 3d8113fd9..c4ca578e2 100755
--- a/testbot/bin/WineRunTask.pl
+++ b/testbot/bin/WineRunTask.pl
@@ -448,7 +448,7 @@ elsif ($Step->Type eq "suite")
   if (defined($WebHostName))
   {
     my $StepTask = 100 * $StepNo + $TaskNo;
-    $Script .= "-u \"http://$WebHostName/JobDetails.pl?Key=$JobId&scrshot_$StepTask=1#k$StepTask\"";
+    $Script .= "-u \"http://$WebHostName/JobDetails.pl?Key=$JobId&s$StepTask=1#k$StepTask\"";
   }
   my $Info = $VM->Description ? $VM->Description : "";
   if ($VM->Details)
diff --git a/testbot/web/JobDetails.pl b/testbot/web/JobDetails.pl
index 70d8b5983..f829407eb 100644
--- a/testbot/web/JobDetails.pl
+++ b/testbot/web/JobDetails.pl
@@ -228,12 +228,95 @@ sub GeneratePage($)
   $self->SUPER::GeneratePage();
 }
 
+my %MILogLabels = (
+  "log" => "task log",
+  "log.old" => "old logs",
+);
+
+sub InitMoreInfo($)
+{
+  my ($self) = @_;
+
+  my $More = $self->{More} = {};
+  my $Keys = $self->SortKeys(undef, $self->{Collection}->GetKeys());
+  foreach my $Key (@$Keys)
+  {
+    my $StepTask = $self->{Collection}->GetItem($Key);
+    $More->{$Key}->{Screenshot} = $self->GetParam("s$Key");
+
+    my $Value = $self->GetParam("f$Key");
+    my $TaskDir = $StepTask->GetTaskDir();
+    foreach my $Log ("log", "log.old")
+    {
+      if (!-f "$TaskDir/$Log" or -z "$TaskDir/$Log")
+      {
+        my $Err = $Log;
+        next if ($Err !~ s/^log/err/ or !-f "$TaskDir/$Err" or -z "$TaskDir/$Err");
+      }
+      push @{$More->{$Key}->{Logs}}, $Log;
+
+      $More->{$Key}->{Full} = $Log if (uri_escape($Log) eq $Value);
+    }
+    $More->{$Key}->{Full} ||= "";
+  }
+}
+
+sub GenerateMoreInfoLink($$$;$)
+{
+  my ($self, $LinkKey, $Label, $Set, $Value) = @_;
+
+  my $Url = $ENV{"SCRIPT_NAME"} ."?Key=". uri_escape($self->{JobId});
+
+  my $Action = "Show";
+  foreach my $Key (sort keys %{$self->{More}})
+  {
+    my $MoreInfo = $self->{More}->{$Key};
+    if ($Key eq $LinkKey and $Set eq "Screenshot")
+    {
+      if (!$MoreInfo->{Screenshot})
+      {
+        $Url .= "&s$Key=1";
+      }
+      else
+      {
+        $Action = "Hide";
+      }
+    }
+    else
+    {
+      $Url .= "&s$Key=1" if ($MoreInfo->{Screenshot});
+    }
+
+    if ($Key eq $LinkKey and $Set eq "Full")
+    {
+      if ($MoreInfo->{Full} ne $Value)
+      {
+        $Url .= "&f$Key=". uri_escape($Value);
+      }
+      else
+      {
+        $Action = "Hide";
+      }
+    }
+    else
+    {
+      $Url .= "&f$Key=". uri_escape($MoreInfo->{Full}) if ($MoreInfo->{Full});
+    }
+  }
+  $Url .= "#k" . uri_escape($LinkKey);
+
+  print "<div class='TaskMoreInfoLink'><a href='",
+        $self->CGI->escapeHTML($Url), "'>$Action $Label</a></div>\n";
+}
+
 sub GenerateBody($)
 {
   my ($self) = @_;
 
   $self->SUPER::GenerateBody();
 
+  $self->InitMoreInfo();
+
   print "<div class='Content'>\n";
   my $Keys = $self->SortKeys(undef, $self->{Collection}->GetKeys());
   foreach my $Key (@$Keys)
@@ -249,18 +332,11 @@ sub GenerateBody($)
           $self->CGI->escapeHTML($VM->Details || "No details!"),
           "</details>\n";
 
-    my $FullLogParamName = "log_$Key";
-    my $FullLog = $self->GetParam($FullLogParamName);
-    $FullLog = "" if ($FullLog !~ /^[12]$/);
-
-    my $ScreenshotParamName = "scrshot_$Key";
-    my $Screenshot = $self->GetParam($ScreenshotParamName);
-    $Screenshot = "" if ($Screenshot ne "1");
-
+    my $MoreInfo = $self->{More}->{$Key};
     print "<div class='TaskMoreInfoLinks'>\n";
     if (-r "$TaskDir/screenshot.png")
     {
-      if ($Screenshot)
+      if ($MoreInfo->{Screenshot})
       {
         my $URI = "/Screenshot.pl?JobKey=" . uri_escape($self->{JobId}) .
                   "&StepKey=" . uri_escape($StepTask->StepNo) .
@@ -268,59 +344,19 @@ sub GenerateBody($)
         print "<div class='Screenshot'><img src='" .
               $self->CGI->escapeHTML($URI) . "' alt='Screenshot' /></div>\n";
       }
-      else
-      {
-        my $URI = $ENV{"SCRIPT_NAME"} . "?Key=" . uri_escape($self->{JobId}) .
-                  "&$ScreenshotParamName=1";
-        $URI .= "&$FullLogParamName=$FullLog";
-        $URI .= "#k" . uri_escape($Key);
-        print "<div class='TaskMoreInfoLink'><a href='" .
-              $self->CGI->escapeHTML($URI) .
-              "'>Show final screenshot</a></div>";
-        print "\n";
-      }
+      $self->GenerateMoreInfoLink($Key, "final screenshot", "Screenshot");
     }
 
-    my $LogName = "$TaskDir/log";
-    my $ErrName = "$TaskDir/err";
-    if (-r $LogName and $FullLog != "1")
-    {
-      my $URI = $ENV{"SCRIPT_NAME"} . "?Key=" . uri_escape($self->{JobId}) .
-                "&$FullLogParamName=1";
-      $URI .= "&$ScreenshotParamName=$Screenshot";
-      $URI .= "#k" . uri_escape($Key);
-      print "<div class='TaskMoreInfoLink'><a href='" .
-            $self->CGI->escapeHTML($URI) .
-            "'>Show full log</a></div>\n";
-    }
-    if ((-r $LogName or -r $ErrName) and $FullLog == "2")
+    foreach my $Log (@{$MoreInfo->{Logs}})
     {
-      my $URI = $ENV{"SCRIPT_NAME"} . "?Key=" . uri_escape($self->{JobId});
-      $URI .= "&$ScreenshotParamName=$Screenshot";
-      $URI .= "#k" . uri_escape($Key);
-      print "<div class='TaskMoreInfoLink'><a href='" .
-            $self->CGI->escapeHTML($URI) .
-            "'>Show latest log</a></div>\n";
-    }
-    if ((-r "$LogName.old" or -r "$ErrName.old") and $FullLog != "2")
-    {
-      my $URI = $ENV{"SCRIPT_NAME"} . "?Key=" . uri_escape($self->{JobId}) .
-                "&$FullLogParamName=2";
-      $URI .= "&$ScreenshotParamName=$Screenshot";
-      $URI .= "#k" . uri_escape($Key);
-      print "<div class='TaskMoreInfoLink'><a href='" .
-            $self->CGI->escapeHTML($URI) .
-            "'>Show old logs</a></div>\n";
+      $self->GenerateMoreInfoLink($Key, $MILogLabels{$Log}, "Full", $Log);
     }
     print "</div>\n";
 
-    if ($FullLog eq "2")
-    {
-      $LogName .= ".old";
-      $ErrName .= ".old";
-    }
+    my $LogName = $MoreInfo->{Full} || $MoreInfo->{Logs}->[0] || "log";
+    my $ErrName = $LogName eq "log.old" ? "err.old" : "err";
 
-    if (open LOGFILE, "<$LogName")
+    if (open LOGFILE, "<", "$TaskDir/$LogName")
     {
       my $HasLogEntries = !1;
       my $First = 1;
@@ -335,13 +371,13 @@ sub GenerateBody($)
         {
           $CurrentDll = $1;
         }
-        if ($FullLog ||
+        if ($MoreInfo->{Full} ||
             $Line =~ m/: Test (?:failed|succeeded inside todo block): / ||
             $Line =~ m/Fatal: test '[^']+' does not exist/ ||
             $Line =~ m/ done \(258\)/ ||
             $Line =~ m/: unhandled exception [0-9a-fA-F]{8} at /)
         {
-          if ($PrintedDll ne $CurrentDll && ! $FullLog)
+          if ($PrintedDll ne $CurrentDll && !$MoreInfo->{Full})
           {
             if ($First)
             {
@@ -359,7 +395,7 @@ sub GenerateBody($)
             print "<pre><code>";
             $First = !1;
           }
-          if (! $FullLog && $Line =~ m/^[^:]+:([^:]*)(?::[0-9a-f]+)? done \(258\)/)
+          if (!$MoreInfo->{Full} && $Line =~ m/^[^:]+:([^:]*)(?::[0-9a-f]+)? done \(258\)/)
           {
             my $Unit = $1 ne "" ? "$1: " : "";
             print "${Unit}Timeout\n";
@@ -372,7 +408,7 @@ sub GenerateBody($)
       }
       close LOGFILE;
 
-      if (open ERRFILE, "<$ErrName")
+      if (open ERRFILE, "<", "$TaskDir/$ErrName")
       {
         $CurrentDll = "*err*";
         while (defined($Line = <ERRFILE>))
@@ -409,7 +445,7 @@ sub GenerateBody($)
                                " failures found" : "Empty log";
       }
     }
-    elsif (open ERRFILE, "<$ErrName")
+    elsif (open ERRFILE, "<", "$TaskDir/$ErrName")
     {
       my $HasErrEntries = !1;
       my $Line;
-- 
2.17.1




More information about the wine-devel mailing list