Francois Gouget : testbot/LogUtils: Share code between _SaveLogErrors() and _DumpErrors().

Alexandre Julliard julliard at winehq.org
Wed Feb 12 16:13:58 CST 2020


Module: tools
Branch: master
Commit: 0cbb595564267b66cd7dcfeb9316a48ce286582f
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=0cbb595564267b66cd7dcfeb9316a48ce286582f

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Wed Feb 12 16:02:11 2020 +0100

testbot/LogUtils: Share code between _SaveLogErrors() and _DumpErrors().

_SaveLogErrors() provides more details about the errors than the old
_DumpErrors() code did.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/lib/WineTestBot/LogUtils.pm | 90 ++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 51 deletions(-)

diff --git a/testbot/lib/WineTestBot/LogUtils.pm b/testbot/lib/WineTestBot/LogUtils.pm
index 9bde76c..a5c6217 100644
--- a/testbot/lib/WineTestBot/LogUtils.pm
+++ b/testbot/lib/WineTestBot/LogUtils.pm
@@ -687,24 +687,6 @@ sub GetLogLabel($)
   return defined $Label ? sprintf($Label, $Extra) : $LogFileName;
 }
 
-
-sub _DumpErrors($$)
-{
-  my ($Label, $LogInfo) = @_;
-
-  print STDERR "$Label: ", join(" ", keys %$LogInfo), "\n";
-  my $GroupNames = $LogInfo->{ErrGroupNames};
-  print STDERR "  Groups=", scalar(@$GroupNames), " [", join(",", @$GroupNames), "]\n";
-  my @ErrorKeys = sort keys %{$LogInfo->{Groups}};
-  print STDERR "  Errors=", scalar(@ErrorKeys), " [", join(",", @ErrorKeys), "]\n";
-  foreach my $GroupName (@$GroupNames)
-  {
-    print STDERR "  [$GroupName]\n";
-    my $Group = $LogInfo->{Groups}->{$GroupName};
-    print STDERR "    [$_]\n" for (@{$Group->{Errors}});
-  }
-}
-
 sub _AddLogGroup($$;$)
 {
   my ($LogInfo, $GroupName, $LineNo) = @_;
@@ -859,21 +841,7 @@ sub GetLogErrors($)
 
 Loads the specified log errors file.
 
-The file contains two types of lines:
-* GroupName lines
-  <GroupName>
-  Where <GroupName> is a unique string which would typically be the name of a
-  WineTest dll or program, but may also be empty or be used to specify an
-  extra group errors. It must not start with a space.
-
-* Error lines
-  <Space> <New> <SrcLineNo> <Error>
-  Where:
-  - <Space> is a space, as well as the spaces in the line above.
-  - <New> is either 'n' for new errors, or 'o' for old ones.
-  - <SrcLineNo> is the 1-base line number of the error in the source log file.
-      If there is no source line then this should be 0.
-  - <Error> is the error message.
+See _WriteLogErrors() for the format of the errors file.
 
 Returns the errors in the same format as TagNewErrors().
 
@@ -949,11 +917,11 @@ sub LoadLogErrors($)
 =pod
 =over 12
 
-=item C<_SaveLogErrors()>
+=item C<_WriteLogErrors()>
 
-Saves the LogInfo structure to <LogName>.errors.
+Writes the LogInfo structure in text form to the specified file descriptor.
 
-The file contains lines of the form:
+All lines follow are of the following form:
   <type> <value1> <value2>
 
 The values depend on the <type> of the line. <type> and <value1> must not
@@ -984,6 +952,27 @@ different type.
 =back
 =cut
 
+sub _WriteLogErrors($$)
+{
+  my ($Fh, $LogInfo) = @_;
+
+  foreach my $Name ("BadRef", "NoRef")
+  {
+    next if (!defined $LogInfo->{$Name});
+    print $Fh "p $Name $LogInfo->{$Name}\n";
+  }
+  foreach my $GroupName (@{$LogInfo->{ErrGroupNames}})
+  {
+    my $Group = $LogInfo->{ErrGroups}->{$GroupName};
+    print $Fh "g $Group->{LineNo} $GroupName\n";
+    foreach my $Index (0..@{$Group->{Errors}} - 1)
+    {
+      my $IsNew = $Group->{IsNew}->[$Index] ? "n" : "o";
+      print $Fh "$IsNew $Group->{LineNos}->[$Index] $Group->{Errors}->[$Index]\n";
+    }
+  }
+}
+
 sub _SaveLogErrors($)
 {
   my ($LogInfo) = @_;
@@ -991,21 +980,7 @@ sub _SaveLogErrors($)
   my $ErrorsPath = "$LogInfo->{LogPath}.errors";
   if (open(my $ErrorsFile, ">", $ErrorsPath))
   {
-    foreach my $Name ("BadRef", "NoRef")
-    {
-      next if (!defined $LogInfo->{$Name});
-      print $ErrorsFile "p $Name $LogInfo->{$Name}\n";
-    }
-    foreach my $GroupName (@{$LogInfo->{ErrGroupNames}})
-    {
-      my $Group = $LogInfo->{ErrGroups}->{$GroupName};
-      print $ErrorsFile "g $Group->{LineNo} $GroupName\n";
-      foreach my $Index (0..@{$Group->{Errors}} - 1)
-      {
-        my $IsNew = $Group->{IsNew}->[$Index] ? "n" : "o";
-        print $ErrorsFile "$IsNew $Group->{LineNos}->[$Index] $Group->{Errors}->[$Index]\n";
-      }
-    }
+    _WriteLogErrors($ErrorsFile, $LogInfo);
     close($ErrorsFile);
 
     # Set the mtime so Janitor reaps both at the same time
@@ -1015,6 +990,19 @@ sub _SaveLogErrors($)
   return "Could not open '$LogInfo->{LogName}.errors' for writing: $!";
 }
 
+sub _DumpErrors($$)
+{
+  my ($Label, $LogInfo) = @_;
+
+  print STDERR "$Label:\n";
+  foreach my $Key (sort keys %{$LogInfo})
+  {
+    next if ($Key =~ /^(?:ErrGroupNames|ErrGroups|NewCount)$/);
+    print STDERR "+ $Key $LogInfo->{$Key}\n";
+  }
+  _WriteLogErrors(*STDERR, $LogInfo);
+}
+
 
 #
 # New error detection




More information about the wine-cvs mailing list