From: Francois Gouget Subject: [22/25] testbot/LogUtils: Share code between _SaveLogErrors() and _DumpErrors(). Message-Id: <8765e5c16baeaf46afc2e3be5abcf1aa0d4484d1.1579000229.git.fgouget@codeweavers.com> Date: Tue, 14 Jan 2020 16:43:17 +0100 (CET) In-Reply-To: References: _SaveLogErrors() provides more details about the errors than the old _DumpErrors() code did. --- 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 8c2fea41f..88386310a 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) = @_; @@ -855,21 +837,7 @@ sub GetLogErrors($) Loads the specified log errors file. -The file contains two types of lines: -* GroupName lines - - Where 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 - - Where: - - is a space, as well as the spaces in the line above. - - is either 'n' for new errors, or 'o' for old ones. - - 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. - - is the error message. +See _WriteLogErrors() for the format of the errors file. Returns the errors in the same format as TagNewErrors(). @@ -945,11 +913,11 @@ sub LoadLogErrors($) =pod =over 12 -=item C<_SaveLogErrors()> +=item C<_WriteLogErrors()> -Saves the LogInfo structure to .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: The values depend on the of the line. and must not @@ -980,6 +948,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) = @_; @@ -987,21 +976,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 @@ -1011,6 +986,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 -- 2.20.1