]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
commit.rc: Add helper for math operation using bc
authorLukas Czerner <lczerner@redhat.com>
Mon, 26 Sep 2011 18:45:09 +0000 (18:45 +0000)
committerAlex Elder <aelder@sgi.com>
Tue, 27 Sep 2011 04:01:24 +0000 (23:01 -0500)
Sometimes using bash $(()) math might not be enough due to some
limitation (big numbers), so add helper using 'bc' program. For
now the results are only in perfect numbers (as in bash) since this is
all I need for now.

This commit also adds _require_math() helper which should be called by
every test which uses _math() since it requires "bc" to be installed on
the system.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Alex Elder <aelder@sgi.com>
common.rc

index 35f782b3f46b898818ea3cdf5d53c32ce2543ed4..e948169b554cdf166e8a9a9dd04630da37559f5d 100644 (file)
--- a/common.rc
+++ b/common.rc
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
+BC=$(which bc 2> /dev/null) || BC=
+
+_require_math()
+{
+       if [ -z "$BC" ]; then
+               _notrun "this test requires 'bc' tool for doing math operations"
+       fi
+}
+
+_math()
+{
+       [ $# -le 0 ] && return
+       if [ "$BC" ]; then
+               result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
+       else
+               _notrun "this test requires 'bc' tool for doing math operations"
+       fi
+       echo "$result"
+}
+
 dd()
 {
    if [ "$HOSTOS" == "Linux" ]