aboutsummaryrefslogtreecommitdiffstats
path: root/tests/zfs-tests
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2020-07-09 20:49:02 -0400
committerGitHub <[email protected]>2020-07-09 17:49:02 -0700
commita2ec738c75a11bb225b1a01cb6019cc360a6202c (patch)
tree52c0fe038753b4e6db9e5cababe569a505d1606d /tests/zfs-tests
parent659f4008be86d5eaf67184c83fddbcb6800a3705 (diff)
ZTS: Make bc conditional use compatible with new BSD bc
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 <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #10551
Diffstat (limited to 'tests/zfs-tests')
-rw-r--r--tests/zfs-tests/include/math.shlib5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib
index 692a2a45b..7ac59f279 100644
--- a/tests/zfs-tests/include/math.shlib
+++ b/tests/zfs-tests/include/math.shlib
@@ -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
}