From a2ec738c75a11bb225b1a01cb6019cc360a6202c Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Thu, 9 Jul 2020 20:49:02 -0400 Subject: [PATCH] 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 Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #10551 --- tests/zfs-tests/include/math.shlib | 5 +++-- 1 file 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 }