All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: xfs@oss.sgi.com
Cc: Lukas Czerner <lczerner@redhat.com>, aelder@sgi.com
Subject: [PATCH v4] commit.rc: Add helper for math operation using bc
Date: Mon, 26 Sep 2011 20:45:09 +0200	[thread overview]
Message-ID: <1317062709-2133-1-git-send-email-lczerner@redhat.com> (raw)
In-Reply-To: <1316787311-23428-1-git-send-email-lczerner@redhat.com>

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>
---
v3: Nothing has changed
v4: Add _require_math helper

 common.rc |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/common.rc b/common.rc
index 35f782b..e948169 100644
--- a/common.rc
+++ b/common.rc
@@ -20,6 +20,26 @@
 #  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" ]
-- 
1.7.4.4

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2011-09-26 18:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-23 14:15 [PATCH 1/2 v3] commit.rc: Add helper for math operation using bc Lukas Czerner
2011-09-23 14:15 ` [PATCH 2/2] Add test 257: Check proper FITRIM argument handling Lukas Czerner
2011-09-23 15:00   ` Alex Elder
2011-09-23 16:06     ` Lukas Czerner
2011-09-23 23:04   ` Michael Monnerie
2011-09-26  6:15     ` Lukas Czerner
2011-09-26  7:14   ` [PATCH] " Lukas Czerner
2011-09-26 11:42     ` Lukas Czerner
2011-09-26 12:47     ` Alex Elder
2011-09-26 13:52       ` Lukas Czerner
2011-09-26 15:47         ` Alex Elder
2011-09-23 15:00 ` [PATCH 1/2 v3] commit.rc: Add helper for math operation using bc Alex Elder
2011-09-26 18:45 ` Lukas Czerner [this message]
2011-09-26 21:32   ` [PATCH v4] " Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317062709-2133-1-git-send-email-lczerner@redhat.com \
    --to=lczerner@redhat.com \
    --cc=aelder@sgi.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.