Francois Gouget : testbot/LogUtils: Allow loading the errors from a file handle.
Alexandre Julliard
julliard at winehq.org
Tue Jan 19 15:31:28 CST 2021
Module: tools
Branch: master
Commit: ce7d15ceed9dd318959e51dbfe3edfa93e4d82e0
URL: https://source.winehq.org/git/tools.git/?a=commit;h=ce7d15ceed9dd318959e51dbfe3edfa93e4d82e0
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Tue Jan 19 18:55:56 2021 +0100
testbot/LogUtils: Allow loading the errors from a file handle.
Furthermore LoadLogErrorsFromFh() returns unsupported lines to the
caller (in addition to setting BadLog) which allows embedding
.errors-formatted sections in other text files.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
testbot/lib/WineTestBot/LogUtils.pm | 99 ++++++++++++++++++++++---------------
1 file changed, 60 insertions(+), 39 deletions(-)
diff --git a/testbot/lib/WineTestBot/LogUtils.pm b/testbot/lib/WineTestBot/LogUtils.pm
index 1e7dcda..17be624 100644
--- a/testbot/lib/WineTestBot/LogUtils.pm
+++ b/testbot/lib/WineTestBot/LogUtils.pm
@@ -31,7 +31,7 @@ our @EXPORT = qw(GetLogFileNames GetLogLabel
GetLogLineCategory GetReportLineCategory
ParseTaskLog ParseWineTestReport
SnapshotLatestReport UpdateLatestReport UpdateLatestReports
- CreateLogErrorsCache LoadLogErrors);
+ CreateLogErrorsCache LoadLogErrorsFromFh LoadLogErrors);
use Algorithm::Diff;
use File::Basename;
@@ -830,11 +830,10 @@ sub GetLogLabel($)
=pod
=over 12
-=item C<LoadLogErrors()>
-
-Loads the specified log errors file.
+=item C<LoadLogErrorsFromFh()>
-Returns the errors in the same format as TagNewErrors().
+Loads the specified log errors file, returning the errors in the same format
+as TagNewErrors().
All lines are of the following form:
<type> <value1> <value2>
@@ -867,37 +866,23 @@ different type.
=back
=cut
-sub LoadLogErrors($)
+sub LoadLogErrorsFromFh($$)
{
- my ($LogPath) = @_;
+ my ($LogInfo, $ErrorsFile) = @_;
- my $LogName = basename($LogPath);
- my $LogInfo = {
- LogName => $LogName,
- LogPath => $LogPath,
+ $LogInfo->{ErrGroupNames} ||= [];
+ $LogInfo->{ErrGroups} ||= {};
- ErrGroupNames => [],
- ErrGroups => {},
- };
- $LogPath .= ".errors";
-
- my $ErrorsFile;
- if (!open($ErrorsFile, "<", $LogPath))
- {
- $LogInfo->{BadLog} = "Unable to open '$LogName.errors' for reading: $!";
- return $LogInfo;
- }
-
- my ($LineNo, $CurGroup);
- foreach my $Line (<$ErrorsFile>)
+ while (my $Line = <$ErrorsFile>)
{
- $LineNo++;
+ $LogInfo->{LineNo}++;
chomp $Line;
+
my ($Type, $Property, $Value) = split / /, $Line, 3;
if (!defined $Value)
{
- $LogInfo->{BadLog} = "$LineNo: Found an invalid line";
- last;
+ $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Found an invalid line";
+ return $Line;
}
# else $Type, $Property and $Value are all defined
elsif ($Type eq "p")
@@ -908,34 +893,70 @@ sub LoadLogErrors($)
}
else
{
- $LogInfo->{BadLog} = "$LineNo: Cannot set $Property = $Value because it is already set to $LogInfo->{$Property}";
- last;
+ $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Cannot set $Property = $Value because it is already set to $LogInfo->{$Property}";
+ return $Line;
}
}
elsif ($Type eq "g")
{
- $CurGroup = _AddLogGroup($LogInfo, $Value, $Property);
+ $LogInfo->{CurGroup} = _AddLogGroup($LogInfo, $Value, $Property);
}
- elsif (!$CurGroup)
+ elsif (!$LogInfo->{CurGroup})
{
- $LogInfo->{BadLog} = "$LineNo: Got a $Type line with no group";
- last;
+ $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Got a $Type line with no group";
+ return $Line;
}
elsif ($Type eq "o")
{
- _AddLogError($LogInfo, $CurGroup, $Value, $Property);
+ _AddLogError($LogInfo, $LogInfo->{CurGroup}, $Value, $Property);
}
elsif ($Type eq "n")
{
- _AddLogError($LogInfo, $CurGroup, $Value, $Property, "new");
+ _AddLogError($LogInfo, $LogInfo->{CurGroup}, $Value, $Property, "new");
}
else
{
- $LogInfo->{BadLog} = "$LineNo: Found an unknown line type ($Type)";
- last;
+ $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Found an unknown line type ($Type)";
+ return $Line;
}
}
- close($ErrorsFile);
+
+ return undef;
+}
+
+=pod
+=over 12
+
+=item C<LoadLogErrors()>
+
+Loads the specified log errors file.
+
+See _LoadLogErrorsFromFh() for the format of the errors file.
+
+Returns the errors in the same format as TagNewErrors().
+
+=back
+=cut
+
+sub LoadLogErrors($)
+{
+ my ($LogPath) = @_;
+
+ my $LogInfo = {
+ LogName => basename($LogPath),
+ LogPath => $LogPath,
+ };
+ if (open(my $ErrorsFile, "<", "$LogPath.errors"))
+ {
+ LoadLogErrorsFromFh($LogInfo, $ErrorsFile);
+ delete $LogInfo->{CurGroup};
+ close($ErrorsFile);
+ }
+ else
+ {
+ $LogInfo->{BadLog} = "Unable to open '$LogInfo->{LogName}.errors' for reading: $!";
+ return $LogInfo;
+ }
return $LogInfo;
}
More information about the wine-cvs
mailing list