[PATCH] testbot: Keep the old logs around.

Francois Gouget fgouget at codeweavers.com
Tue May 15 02:08:24 CDT 2018


This helps figure out why the test was rerun: was it because it timed
out the first time around? Because there was a network glitch? Or
because the TestBot script got stuck or died unexpectedly? The error
message in the old logs will make it clear.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/lib/WineTestBot/Tasks.pm | 27 +++++++++++-
 testbot/web/JobDetails.pl        | 75 ++++++++++++++++++++------------
 2 files changed, 73 insertions(+), 29 deletions(-)

diff --git a/testbot/lib/WineTestBot/Tasks.pm b/testbot/lib/WineTestBot/Tasks.pm
index 36cbfadbe..69d551b84 100644
--- a/testbot/lib/WineTestBot/Tasks.pm
+++ b/testbot/lib/WineTestBot/Tasks.pm
@@ -83,7 +83,32 @@ sub _SetupTask($$)
   my ($VM, $self) = @_;
 
   # Remove the previous run's files if any
-  $self->RmTree();
+  my $Dir = $self->GetDir();
+  if (-d $Dir)
+  {
+    mkpath("$Dir.new", 0, 0775);
+    rename "$Dir/log.old", "$Dir.new/log.old" if (-f "$Dir/log.old");
+    rename "$Dir/err.old", "$Dir.new/err.old" if (-f "$Dir/err.old");
+    foreach my $Filename ("log", "err")
+    {
+      if (open(my $Src, "<", "$Dir/$Filename"))
+      {
+        if (open(my $Dst, ">>", "$Dir.new/$Filename.old"))
+        {
+          print $Dst "----- Run ", ($self->TestFailures || 0), " $Filename\n";
+          while (my $Line = <$Src>)
+          {
+            print $Dst $Line;
+          }
+          close($Dst);
+        }
+        close($Src);
+      }
+    }
+
+    $self->RmTree();
+    rename("$Dir.new", $Dir);
+  }
 
   # Capture Perl errors in the task's generic error log
   my $TaskDir = $self->CreateDir();
diff --git a/testbot/web/JobDetails.pl b/testbot/web/JobDetails.pl
index 0213eb5e2..4d9a77a57 100644
--- a/testbot/web/JobDetails.pl
+++ b/testbot/web/JobDetails.pl
@@ -249,16 +249,21 @@ sub GenerateBody($)
           $self->CGI->escapeHTML($VM->Details || "No details!"),
           "</details>\n";
 
-    my $ScreenshotParamName = "scrshot_$Key";
     my $FullLogParamName = "log_$Key";
-    my $LogName = "$TaskDir/log";
-    my $ErrName = "$TaskDir/err";
+    my $FullLog = $self->GetParam($FullLogParamName);
+    $FullLog = "" if ($FullLog !~ /^[12]$/);
+
+    my $ScreenshotParamName = "scrshot_$Key";
+    my $Screenshot = $self->GetParam($ScreenshotParamName);
+    $Screenshot = "" if ($Screenshot ne "1");
+
+
     print "<div class='TaskMoreInfoLinks'>\n";
     # FIXME: Disable live screenshots for now
     if (0 && $StepTask->Status eq "running" &&
         ($StepTask->Type eq "single" || $StepTask->Type eq "suite"))
     {
-      if (defined($self->GetParam($ScreenshotParamName)))
+      if ($Screenshot)
       {
         my $URI = "/Screenshot.pl?VMName=" . uri_escape($VM->Name);
         print "<div class='Screenshot'><img src='" .
@@ -277,7 +282,7 @@ sub GenerateBody($)
     }
     elsif (-r "$TaskDir/screenshot.png")
     {
-      if (defined($self->GetParam($ScreenshotParamName)))
+      if ($Screenshot)
       {
         my $URI = "/Screenshot.pl?JobKey=" . uri_escape($self->{JobId}) .
                   "&StepKey=" . uri_escape($StepTask->StepNo) .
@@ -289,10 +294,7 @@ sub GenerateBody($)
       {
         my $URI = $ENV{"SCRIPT_NAME"} . "?Key=" . uri_escape($self->{JobId}) .
                   "&$ScreenshotParamName=1";
-        if (defined($self->GetParam($FullLogParamName)))
-        {
-          $URI .= "&$FullLogParamName=1";
-        }
+        $URI .= "&$FullLogParamName=$FullLog";
         $URI .= "#k" . uri_escape($Key);
         print "<div class='TaskMoreInfoLink'><a href='" .
               $self->CGI->escapeHTML($URI) .
@@ -300,29 +302,46 @@ sub GenerateBody($)
         print "\n";
       }
     }
-    my $FullLog = !1;
-    if (-r $LogName)
+
+    my $LogName = "$TaskDir/log";
+    my $ErrName = "$TaskDir/err";
+    if (-r $LogName and $FullLog != "1")
     {
-      if (defined($self->GetParam($FullLogParamName)))
-      {
-        $FullLog = 1;
-      }
-      else
-      {
-        my $URI = $ENV{"SCRIPT_NAME"} . "?Key=" . uri_escape($self->{JobId}) .
-                  "&$FullLogParamName=1";
-        if (defined($self->GetParam($ScreenshotParamName)))
-        {
-          $URI .= "&$ScreenshotParamName=1";
-        }
-        $URI .= "#k" . uri_escape($Key);
-        print "<div class='TaskMoreInfoLink'><a href='" .
-              $self->CGI->escapeHTML($URI) .
-              "'>Show full log</a></div>\n";
-      }
+      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")
+    {
+      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";
     }
     print "</div>\n";
 
+    if ($FullLog eq "2")
+    {
+      $LogName .= ".old";
+      $ErrName .= ".old";
+    }
+
     if (open LOGFILE, "<$LogName")
     {
       my $HasLogEntries = !1;
-- 
2.17.0



More information about the wine-devel mailing list