[Tools 1/3] winetest: Improve error reporting.
Francois Gouget
fgouget at codeweavers.com
Sat Jun 3 17:39:49 CDT 2017
Add a function to report errors.
Always report renaming errors and the reason for the error.
Standardize the file open error messages.
die, and by extension mydie, does not need a trailing new-line.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
winetest/build-errors | 14 ++++++++++++-
winetest/build-index | 33 +++++++++++++++++++++++------
winetest/dissect | 57 +++++++++++++++++++++++++++++----------------------
winetest/gather | 45 ++++++++++++++++++++++++++++------------
4 files changed, 104 insertions(+), 45 deletions(-)
diff --git a/winetest/build-errors b/winetest/build-errors
index b5625032..f9ac4aa6 100755
--- a/winetest/build-errors
+++ b/winetest/build-errors
@@ -36,11 +36,19 @@ sub BEGIN
use vars qw/$workdir/;
require "winetest.conf";
+my $name0=$0;
+$name0 =~ s+^.*/++;
+
#
# Common helpers
#
+sub error(@)
+{
+ print STDERR "$name0:error: ", @_;
+}
+
use POSIX qw(locale_h strftime);
setlocale(LC_ALL, "C");
@@ -88,6 +96,10 @@ foreach my $err (sort { $b->{date} <=> $a->{date}; } @errors)
print OUT "</table>", end_html();
close OUT;
-rename "data/errors.html.new", "data/errors.html" or unlink "data/errors.html.new";
+if (!rename "$filename.new", "$filename")
+{
+ error("could not move '$filename.new' into place: $!\n");
+ unlink "$filename.new";
+}
exit 0;
diff --git a/winetest/build-index b/winetest/build-index
index 770ca9a6..dcd9795a 100755
--- a/winetest/build-index
+++ b/winetest/build-index
@@ -37,11 +37,19 @@ sub BEGIN
use vars qw/$workdir $gitdir $gitweb/;
require "winetest.conf";
+my $name0=$0;
+$name0 =~ s+^.*/++;
+
#
# Common helpers
#
+sub error(@)
+{
+ print STDERR "$name0:error: ", @_;
+}
+
$ENV{GIT_DIR} = $gitdir;
sub get_build_info($)
@@ -110,7 +118,7 @@ chdir($workdir) or die "could not chdir to the work directory: $!";
my @builds;
my @too_old;
-opendir(DIR, "data") or die "cannot open 'data'";
+opendir(DIR, "data") or die "could not open the 'data' directory: $!";
foreach my $build (readdir(DIR))
{
next if $build =~ /^\./;
@@ -135,7 +143,10 @@ closedir(DIR);
# remove the too old results
foreach my $build (@too_old)
{
- rename "data/$build", "old-data/$build";
+ if (!rename "data/$build", "old-data/$build")
+ {
+ error("could not move 'data/$build' to old-data: $!\n");
+ }
}
@@ -178,7 +189,8 @@ foreach my $test (sort keys %alltests)
foreach my $test (keys %alltests)
{
- open OUT, ">data/tests/$test.html.new" or die "cannot create 'data/tests/$test.html.new'";
+ my $filename = "data/tests/$test.html";
+ open OUT, ">", "$filename.new" or die "could not open '$filename.new' for writing: $!";
print OUT <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
@@ -240,7 +252,11 @@ EOF
}
print OUT "</table></body></html>\n";
close OUT;
- rename "data/tests/$test.html.new", "data/tests/$test.html" or unlink "data/tests/$test.html.new";
+ if (!rename "$filename.new", "$filename")
+ {
+ error("could not move '$filename.new' into place: $!\n");
+ unlink "$filename.new";
+ }
}
@@ -275,7 +291,8 @@ foreach my $build (@builds)
# Write the global index page
#
-open OUT, ">data/index.html.new" or die "cannot create 'data/index.html.new'";
+my $filename = "data/index.html";
+open OUT, ">", "$filename.new" or die "could not open '$filename.new' for writing: $!";
print OUT <<"EOF";
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
@@ -357,6 +374,10 @@ EOF
close OUT;
-rename "data/index.html.new", "data/index.html" or unlink "data/index.html.new";
+if (!rename "$filename.new", "$filename")
+{
+ error("could not move '$filename.new' into place: $!\n");
+ unlink "$filename.new";
+}
exit 0;
diff --git a/winetest/dissect b/winetest/dissect
index 05565985..ccfb15f5 100755
--- a/winetest/dissect
+++ b/winetest/dissect
@@ -64,6 +64,11 @@ my $summary_version=4;
# Common helpers
#
+sub error(@)
+{
+ print STDERR "$name0:error: ", @_;
+}
+
$ENV{GIT_DIR} = $gitdir;
sub get_build_info($)
@@ -128,37 +133,37 @@ sub mydie(@)
if (!$update) {
my $errdir = tempdir ("errXXXXX", DIR => "$workdir/queue");
if (!rename $tmpdir, $errdir) {
- print STDERR "$name0:error: unable to rename '$tmpdir' to '$errdir': $!\n";
+ error("could not rename '$tmpdir' to '$errdir': $!\n");
exit 3;
}
if (open ERR, ">$errdir/error")
{
- print ERR "$label: ", @_;
+ print ERR "$label: ", @_, "\n";
close ERR;
}
}
- print STDERR "$name0:error:$label: ", @_;
+ print STDERR "$name0:error:$label: ", @_, "\n";
exit 1;
}
-open IN, "<:raw", $report or mydie "unable to open '$report' for reading: $!\n";
-open SUM, ">$tmpdir/summary.txt" or mydie "unable to open '$tmpdir/summary.txt' for writing: $!\n";
+open IN, "<:raw", $report or mydie "could not open '$report' for reading: $!";
+open SUM, ">$tmpdir/summary.txt" or mydie "could not open '$tmpdir/summary.txt' for writing: $!";
# Get the size of the report file
my $filesize = -s "$report";
$_ = <IN>;
/^Version (\d+)\r?$/ or mydie "no version header: $_";
-mydie "illegal version: $1\n" if ($1 lt $minimum_report_version);
+mydie "illegal version: $1" if ($1 lt $minimum_report_version);
print SUM "Version $summary_version\n";
$_ = <IN>;
/^Tests from build ([-.0-9a-zA-Z]+)\r?$/ or mydie "no build header: $_";
my $testbuild = $1;
-$testbuild =~ /^[0-9a-f]{40}$/ or mydie "not a valid commit id $testbuild\n";
+$testbuild =~ /^[0-9a-f]{40}$/ or mydie "not a valid commit id $testbuild";
my $commit = `git rev-parse --verify $testbuild^0 2>/dev/null`;
chomp $commit;
-$testbuild eq $commit or mydie "not an existing commit $testbuild\n";
+$testbuild eq $commit or mydie "not an existing commit $testbuild";
my $shortbuild = substr($testbuild,0,12);
my $archive = "winetest-$shortbuild.exe";
@@ -293,13 +298,13 @@ if ($wine_build) {
}
else
{
- mydie "invalid wine build '$wine_build'\n";
+ mydie "invalid wine build '$wine_build'";
}
chomp $wine_commit;
- mydie "unknown wine build '$wine_build'\n" unless $wine_commit;
+ mydie "unknown wine build '$wine_build'" unless $wine_commit;
my $merge_base = `git merge-base $wine_commit $testbuild 2>/dev/null`;
chomp $merge_base;
- $merge_base eq $testbuild or mydie "wine build '$wine_build' not a descendant of build $testbuild\n";
+ $merge_base eq $testbuild or mydie "wine build '$wine_build' not a descendant of build $testbuild";
}
@@ -325,7 +330,7 @@ while ($_ = <IN>) {
elsif ($2 eq "skipped")
{
print SUM "- $module - skipped - - - - -\n";
- mydie "too many dlls skipped by user request\n" if ++$user_skips > $maxuserskips;
+ mydie "too many dlls skipped by user request" if ++$user_skips > $maxuserskips;
}
}
@@ -357,7 +362,7 @@ while (<IN>) {
$testbox->{data} .= "<div class=\"test result skipped\">Skipped by user request.</div>\n";
print SUM "- $dll $unit skipped - - - $source $rev\n";
$dll = undef;
- mydie "too many tests skipped by user request\n" if ++$user_skips > $maxuserskips;
+ mydie "too many tests skipped by user request" if ++$user_skips > $maxuserskips;
}
} elsif (/^((?:[0-9a-f]+:)?$unit: (\d+) tests executed \((\d+) marked as todo, (\d+) failures?\), (\d+) skipped\.)\r?$/) {
$lines++;
@@ -379,10 +384,12 @@ while (<IN>) {
if ($1 == 258) { $reason = "test failed: timed out"; }
elsif ($1 < 0) { $reason = "test failed: crash"; }
$testbox->{data} .= "<div class=\"test end\">$reason</div>\n";
- mydie "too many test failures\n" if ++$failed_tests > $maxfailedtests;
+ mydie "too many test failures" if ++$failed_tests > $maxfailedtests;
} else {
$result = "$total $todo $failed $skipped";
- if ($failed) { mydie "too many test failures\n" if ++$failed_tests > $maxfailedtests; }
+ if ($failed && ++$failed_tests > $maxfailedtests) {
+ mydie "too many test failures";
+ }
}
print SUM "- $dll $unit $result $source $rev\n";
$dll = undef;
@@ -411,12 +418,12 @@ while (<IN>) {
if (defined $dll) {
# Either winetest crashed or the report file was cut off
if ($filesize == $maxfilesize) {
- mydie "report reached file limit (runaway test?)\n";
+ mydie "report reached file limit (runaway test?)";
} else {
- mydie "report truncated (winetest crash?)\n";
+ mydie "report truncated (winetest crash?)";
}
}
-close SUM or mydie "error writing to '$tmpdir/summary.txt': $!\n";
+close SUM or mydie "error writing to '$tmpdir/summary.txt': $!";
close IN;
@@ -476,7 +483,7 @@ for (my $i = 0; $i <= $#boxes; $i++)
# Create the 'full report' page
#
-open REPORT, ">$tmpdir/report.html" or mydie "unable to open '$tmpdir/report.html' for writing: $!\n";
+open REPORT, ">$tmpdir/report.html" or mydie "could not open '$tmpdir/report.html' for writing: $!";
print REPORT start_html( -title => "$short_date $tag report", -style => {src=>"/report.css"} );
print REPORT "<div class=\"navbar\">";
@@ -494,7 +501,7 @@ for (my $i = 0; $i <= $#boxes; $i++)
print REPORT $boxes[$i]->{data}, "</div>\n";
}
print REPORT end_html();
-close REPORT or mydie "error writing to '$tmpdir/report.html': $!\n";
+close REPORT or mydie "error writing to '$tmpdir/report.html': $!";
#
@@ -503,7 +510,7 @@ close REPORT or mydie "error writing to '$tmpdir/report.html': $!\n";
for (my $i = 0; $i <= $#boxes; $i++)
{
- open FILE, ">$tmpdir/$boxes[$i]->{id}.html" or mydie "unable to open '$tmpdir/$boxes[$i]->{id}.html' for writing: $!\n";
+ open FILE, ">$tmpdir/$boxes[$i]->{id}.html" or mydie "could not open '$tmpdir/$boxes[$i]->{id}.html' for writing: $!";
print FILE start_html( -title => "$short_date $boxes[$i]->{id} $tag", -style => {src=>"/report.css"} );
print FILE "<div class=\"navbar\">";
print FILE $boxes[$i]->{prev} ? "<a href=\"./$boxes[$i]->{prev}.html\">prev</a> | " : "prev | ";
@@ -517,7 +524,7 @@ for (my $i = 0; $i <= $#boxes; $i++)
printf FILE "<div class=\"updownbar\">%s</div>\n", $boxes[$i]->{title};
print FILE $boxes[$i]->{data}, "</div>\n";
print FILE end_html();
- close FILE or mydie "error writing to '$tmpdir/$boxes[$i]->{id}.html': $!\n";
+ close FILE or mydie "error writing to '$tmpdir/$boxes[$i]->{id}.html': $!";
}
@@ -540,14 +547,14 @@ if (!$update) {
$dir = $dirbase = "$builddir/${version}_$tag";
$try = 0;
while (!rename $tmpdir, $dir) {
- $!{ENOTEMPTY} or mydie "unable to rename '$tmpdir' to '$dir': $!\n";
- ++$try < $maxmult or mydie "more than $maxmult submissions for $dirbase\n";
+ $!{ENOTEMPTY} or mydie "could not rename '$tmpdir' to '$dir': $!";
+ ++$try < $maxmult or mydie "more than $maxmult submissions for $shortbuild/$version";
$dir = "${dirbase}_$try";
}
}
if (!-e "$builddir/outdated") {
if (!open SIGN, ">$builddir/outdated") {
- print STDERR "$name0:error: unable to open '$builddir/outdated' for writing: $!\n";
+ error("could not open '$builddir/outdated' for writing: $!\n");
exit 1;
}
close SIGN;
diff --git a/winetest/gather b/winetest/gather
index 86f2a732..94f35410 100755
--- a/winetest/gather
+++ b/winetest/gather
@@ -59,6 +59,11 @@ my $summary_version=4;
# Common helpers
#
+sub error(@)
+{
+ print STDERR "$name0:error: ", @_;
+}
+
$ENV{GIT_DIR} = $gitdir;
sub get_build_info($)
@@ -190,7 +195,7 @@ foreach my $file (glob "data/$build/*/summary.txt") {
(my $id, my @tag) = split /_/, $dir;
my $group = $idmap{$id};
if (!defined $group) {
- print STDERR "$name0:error: unknown architecture '$id' in '$file'\n";
+ error("unknown architecture '$id' in '$file'\n");
next;
}
@@ -198,11 +203,11 @@ foreach my $file (glob "data/$build/*/summary.txt") {
$report->{tag} = @tag?"@tag":"";
$report->{dir} = $dir;
if (!open TEST, "<$file") {
- print STDERR "$name0:error: unable to open '$file' for reading: $!\n";
+ error("could not open '$file' for reading: $!\n");
next;
}
if (($_ = <TEST>) ne "Version $summary_version\n") {
- print STDERR "$name0:error: wrong header in '$file': $_";
+ error("wrong header in '$file': $_\n");
close TEST;
next;
}
@@ -649,8 +654,8 @@ sub write_build_index_and_summary($)
}
my $idx_file = "data/$build/$filename";
- if (!open OUT, ">$idx_file.new") {
- print STDERR "$name0:error: unable to open '$idx_file.new' for writing: $!\n";
+ if (!open OUT, ">", "$idx_file.new") {
+ error("could not open '$idx_file.new' for writing: $!\n");
return;
}
@@ -740,7 +745,11 @@ If you have a 64-bit Windows OS, you can also run the <a href="/builds/winetest6
EOF
close OUT;
- rename "$idx_file.new", $idx_file or unlink "$idx_file.new";
+ if (!rename "$idx_file.new", "$idx_file")
+ {
+ error("could not move '$idx_file.new' into place: $!\n");
+ unlink "$idx_file.new";
+ }
}
@@ -753,9 +762,10 @@ sub write_totals($)
{
my ($reports)=@_;
- if (!open TOTAL, ">data/$build/total.txt.new")
+ my $filename = "data/$build/total.txt";
+ if (!open TOTAL, ">", "$filename.new")
{
- print STDERR "$name0:error: unable to open 'data/$build/total.txt.new' for writing: $!\n";
+ error("could not open '$filename.new' for writing: $!\n");
return;
}
my $unit_count=scalar(keys %alltests);
@@ -774,7 +784,11 @@ sub write_totals($)
printf TOTAL "%s %u %u %u %u %u\n", $report->{group}->{name}, $report_count, $unit_count, $report->{errors}, $report->{todos}, $report->{successes};
}
close TOTAL;
- rename "data/$build/total.txt.new", "data/$build/total.txt" or unlink "data/$build/total.txt.new";
+ if (!rename "$filename.new", "$filename")
+ {
+ error("could not move '$filename.new' into place: $!\n");
+ unlink "$filename.new";
+ }
}
@@ -782,9 +796,10 @@ sub write_totals($)
# Actually generate the build's files
#
-if (!open SUMMARY, ">data/$build/summary.txt.new")
+my $filename = "data/$build/summary.txt";
+if (!open SUMMARY, ">", "$filename.new")
{
- print STDERR "$name0:error: unable to open 'data/$build/summary.txt.new' for writing: $!\n";
+ error("could not open '$filename.new' for writing: $!\n");
goto DONE;
}
@@ -797,12 +812,16 @@ foreach my $group (@groups) {
write_build_index_and_summary(undef);
close SUMMARY;
-rename "data/$build/summary.txt.new", "data/$build/summary.txt" or unlink "data/$build/summary.txt.new";
+if (!rename "$filename.new", "$filename")
+{
+ error("could not move '$filename.new' into place: $!\n");
+ unlink "$filename.new";
+}
write_totals(\@groups);
DONE:
if (!unlink $outdated) {
- print STDERR "$name0:error: unable to unlink '$outdated': $!\n";
+ error("unable to unlink '$outdated': $!\n");
exit 3;
}
--
2.11.0
More information about the wine-patches
mailing list