aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-03-23 17:54:07 +0100
committerBrian Behlendorf <[email protected]>2022-04-01 17:59:24 -0700
commit6586085673db2e2d7e66652855d449b4abaab467 (patch)
tree581d6b6375620d4e4e32257e2b972767c7569c28
parentcaccfc870fe17ce9bc040ed559771cd81e3c2a38 (diff)
tests: include: math: simplify bc conditions, review $?
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13259
-rw-r--r--tests/zfs-tests/include/math.shlib11
1 files changed, 3 insertions, 8 deletions
diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib
index 7ac59f279..38d9fecea 100644
--- a/tests/zfs-tests/include/math.shlib
+++ b/tests/zfs-tests/include/math.shlib
@@ -30,17 +30,14 @@ function within_percent
typeset percent=$3
# Set $a or $b to $2 such that a >= b
- [[ '1' = $(echo "if ($2 > $a) 1 else 0" | bc) ]] && a=$2 || b=$2
+ [ 1 -eq $(echo "$2 > $a" | 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 else 0" | bc) ]] && \
- return 0
-
- return 1
+ [ 1 -eq $(echo "scale=2; $p >= $percent" | bc) ]
}
#
@@ -61,9 +58,7 @@ function within_tolerance #value #target #tolerance
typeset diff=$((abs(val - target)))
log_note "Checking if $val is within +/-$tol of $target (diff: $diff)"
- ((diff <= tol)) && return 0
-
- return 1
+ ((diff <= tol))
}
#