diff options
author | Giuseppe Di Natale <[email protected]> | 2018-03-07 09:53:04 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-03-07 09:53:04 -0800 |
commit | a07ad58847158fcd90a2a98f1476a81bfcd3c3ac (patch) | |
tree | b8597fd267bac6841d6370d527441918ee6b2e35 | |
parent | 639b18944a6a3483c02039621c02dac08a954a90 (diff) |
Fix dbufstats_001_pos
Implement a new helper within_tolerance to test if a value
is within range of a target.
Because the dbufstats and dbufs kstat file are being read
at slightly different times, it is possible for stats to be
slightly off. Use within_tolerance to determine if the value
is "close enough" to the target.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Giuseppe Di Natale <[email protected]>
Closes #7239
Closes #7266
-rw-r--r-- | tests/zfs-tests/include/math.shlib | 23 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh | 9 |
2 files changed, 28 insertions, 4 deletions
diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib index 66658cdda..0c3508ec2 100644 --- a/tests/zfs-tests/include/math.shlib +++ b/tests/zfs-tests/include/math.shlib @@ -43,6 +43,29 @@ function within_percent } # +# Return 0 if value is within +/-tolerance of target. +# Return 1 if value exceeds our tolerance. +# For use like this: +# +# Do $action if value is within the tolerance from target passed in: +# within_tolerance VAL TAR TOL && $action +# Do $action if value surpasses the tolerance from target passed in: +# within_tolerance VAL TAR TOL || $action +# +function within_tolerance #value #target #tolerance +{ + typeset val=$1 + typeset target=$2 + typeset tol=$3 + + typeset diff=$((abs(val - target))) + log_note "Checking if $val is within +/-$tol of $target (diff: $diff)" + ((diff <= tol)) && return 0 + + return 1 +} + +# # Return 0 if the human readable string of the form <value>[suffix] can # be converted to bytes. Allow suffixes are shown in the table below. # diff --git a/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh b/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh index 97d370b1f..7813d263d 100755 --- a/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh @@ -55,10 +55,11 @@ function testdbufstat # stat_name dbufstat_filter [[ -n "$2" ]] && filter="-F $2" - verify_eq \ - $(grep -w "$name" "$DBUFSTATS_FILE" | awk '{ print $3 }') \ - $(dbufstat.py -bxn -i "$DBUFS_FILE" "$filter" | wc -l) \ - "$name" + from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" | awk '{ print $3 }') + from_dbufs=$(dbufstat.py -bxn -i "$DBUFS_FILE" "$filter" | wc -l) + + within_tolerance $from_dbufstat $from_dbufs 5 \ + || log_fail "Stat $name exceeded tolerance" } verify_runnable "both" |