return 1
}
+#
+# 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.
[[ -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"