]> git.proxmox.com Git - mirror_zfs.git/commitdiff
ZTS: Make bc conditional use compatible with new BSD bc
authorRyan Moeller <ryan@iXsystems.com>
Fri, 10 Jul 2020 00:49:02 +0000 (20:49 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 00:49:02 +0000 (17:49 -0700)
FreeBSD recently replaced the GNU bc and dc in the base system with
BSD licensed versions.  They are supposed to be compatible with all
the features present in the GNU versions, but it turns out they are
picky about `if` statements having a corresponding `else`.  ZTS uses
`echo "if ($x > $y) 1" | bc` in a few places, which causes tests to
fail unexpectedly with the new bc.

Change the two expressions in ZTS to `if ($x > $y) 1 else 0` for
compatibility with the new BSD bc.

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #10551

tests/zfs-tests/include/math.shlib

index 692a2a45ba4b204808fa0b612d4e240070919b3e..7ac59f279604052de074baf7e56c03d83fab1a47 100644 (file)
@@ -30,14 +30,15 @@ function within_percent
        typeset percent=$3
 
        # Set $a or $b to $2 such that a >= b
-       [[ '1' = $(echo "if ($2 > $a) 1" | bc) ]] && a=$2 || b=$2
+       [[ '1' = $(echo "if ($2 > $a) 1 else 0" | bc) ]] && a=$2 || b=$2
 
        # Prevent division by 0
        [[ $a =~ [1-9] ]] || return 1
 
        typeset p=$(echo "scale=2; $b * 100 / $a" | bc)
        log_note "Comparing $a and $b given $percent% (calculated: $p%)"
-       [[ '1' = $(echo "scale=2; if ($p >= $percent) 1" | bc) ]] && return 0
+       [[ '1' = $(echo "scale=2; if ($p >= $percent) 1 else 0" | bc) ]] && \
+           return 0
 
        return 1
 }