compare_dg_tests.pl: Avoid division by zero in case no test was actually executed.
Change-Id: I38f7de089d7a5db9ea161024d29f84d3e902eeb0
diff --git a/compare_dg_tests.pl b/compare_dg_tests.pl
index cc45605..0c49bd5 100755
--- a/compare_dg_tests.pl
+++ b/compare_dg_tests.pl
@@ -416,25 +416,42 @@
my $rtotal = 0;
my $quiet_reg = $quiet;
my $ref_ratio = 0;
+ my $ref_total = 0;
my $res_ratio = 0;
+ my $res_total = 0;
my $ratio_thresh = 0.95; # Warn if pass ratio is below this threshold
my $ignore_exec = 0;
my $ref_has_exec_tests = 0;
my $res_has_exec_tests = 0;
# Compute the pass ratio as a sanity check
- $ref_ratio = ($ref->{PASS} + $ref->{XFAIL}) /
- ($ref->{PASS} + $ref->{XFAIL}
- + $ref->{XPASS} + $ref->{FAIL}
- + $ref->{UNRESOLVED}
- + $ref->{UNSUPPORTED}
- + $ref->{UNTESTED});
- $res_ratio = ($res->{PASS} + $res->{XFAIL}) /
- ($res->{PASS} + $res->{XFAIL}
- + $res->{XPASS} + $res->{FAIL}
- + $res->{UNRESOLVED}
- + $res->{UNSUPPORTED}
- + $res->{UNTESTED});
+ $ref_total = $ref->{PASS} +
+ $ref->{XFAIL} +
+ $ref->{XPASS} +
+ $ref->{FAIL} +
+ $ref->{UNRESOLVED} +
+ $ref->{UNSUPPORTED} +
+ $ref->{UNTESTED};
+
+ # It is possible that no test is executed at all (for instance if
+ # RUNTESTFLAGS was too restrictive). Avoid division by 0.
+ if ($ref_total > 0) {
+ $ref_ratio = ($ref->{PASS} + $ref->{XFAIL}) /
+ $ref_total;
+ }
+
+ $res_total = $res->{PASS} +
+ $res->{XFAIL} +
+ $res->{XPASS} +
+ $res->{FAIL} +
+ $res->{UNRESOLVED} +
+ $res->{UNSUPPORTED} +
+ $res->{UNTESTED};
+
+ if ($res_total > 0) {
+ $res_ratio = ($res->{PASS} + $res->{XFAIL}) /
+ $res_total;
+ }
if (not $quiet)
{