summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Dreyfus <manu@netbsd.org>2014-07-29 02:21:20 +0200
committerVijay Bellur <vbellur@redhat.com>2014-08-06 04:49:14 -0700
commitf29da9bcc812e3d0711005ce86051d70c277a165 (patch)
tree80cfe9927800c503060cfe3cd6d8e8a9accc1bea
parent9978e61dc51d0318f92b1f2c2cbebfe9ce70b2ea (diff)
Regression test portability: truncate, md5
Add shell functions to replace truncate and md5, which are Linux specific Resubmit because of failed regression test with no apparent cause BUG: 764655 Change-Id: I07200cf886bd52904a5cf63c66f43f0b1cc91540 Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org> Reviewed-on: http://review.gluster.org/8341 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Harshavardhana <harsha@harshavardhana.net> Tested-by: Harshavardhana <harsha@harshavardhana.net> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r--tests/include.rc112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/include.rc b/tests/include.rc
index 0638a22c7bd..8919d0a663c 100644
--- a/tests/include.rc
+++ b/tests/include.rc
@@ -334,6 +334,118 @@ function process_leak_count ()
return $(ls -lh /proc/$pid/fd | grep "(deleted)"| wc -l)
}
+which truncate > /dev/null || {
+ truncate() {
+ local nocreate=0
+ local ioblocks=0
+ local fileref=""
+ local newsize=""
+
+ args=`getopt xor:s: $*`
+ if [ $? -ne 0 ]; then
+ echo 'Usage: truncate [-co](-r file | -s size) file ...'
+ exit 2
+ fi
+ set -- $args
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ -c)
+ nocreate=1;
+ ;;
+ -o)
+ ioblocks=1;
+ echo "Unimplemented -o option"
+ exit 2
+ ;;
+ -r)
+ fileref=$2;
+ shift;
+ ;;
+ -s)
+ newsize=$2;
+ shift;
+ ;;
+ --)
+ shift;
+ break;
+ ;;
+ *)
+ echo 'Usage: truncate [-co](-r file | -s size) file ...'
+ exit 2;
+ ;;
+ esac
+ shift
+ done
+
+ if [ "x$newsize" = "x" -a "x$fileref" = "x" ] ; then
+ echo 'Usage: truncate [-co](-r file | -s size) file ...'
+ exit 2;
+ fi
+
+ if [ "x$newsize" != "x" -a "x$fileref" != "x" ] ; then
+ echo 'Usage: truncate [-co](-r file | -s size) file ...'
+ exit 2;
+ fi
+
+ if [ "x$newsize" != "x" ] ; then
+ echo $newsize | grep -q '^[-_<>%/]' && {
+ echo "Unimplemented prefix in ${newsize}"
+ exit 2;
+ }
+
+ echo $newsize | egrep -q '[GTPEZY]B?$' && {
+ echo "Unit not implemented for ${newsize}"
+ exit 2;
+ }
+
+ case $newsize in
+ *KB)
+ newsize=$(( ${newsize/KB/} * 1000 ))
+ ;;
+ *K)
+ newsize=$(( ${newsize/K/} * 1024 ))
+ ;;
+ *MB)
+ newsize=$(( ${newsize/MB/} * 1000 * 1000 ))
+ ;;
+ *M)
+ newsize=$(( ${newsize/M/} * 1024 * 1024 ))
+ ;;
+ esac
+
+ fi
+
+ if [ "x$fileref" != "x" ] ; then
+ if [ ! -f $fileref ] ; then
+ echo "File does not exists: ${fileref}"
+ exit 2;
+ fi
+ newsize=`ls -l ${fileref}|awk '{print $5}'`
+ fi
+
+ if [ $# -eq 0 ]; then
+ echo 'Usage: truncate [-co](-r file | -s size) file ...'
+ exit 2;
+ fi
+
+ for f in $* ; do
+ if [ "x$nocreate" = "x1" -a ! -f $f ] ; then
+ continue;
+ fi
+
+ dd bs=1 seek=$newsize if=/dev/null of=$f
+ done
+ }
+}
+
+which md5sum > /dev/null || {
+ md5sum() {
+ for f in $* ; do
+ md5 $f | awk -F'[() ]' '{printf("%s %s\n", $6, $3)}'
+ done
+ }
+}
+
alias EXPECT='_EXPECT $LINENO'
alias EXPECT_NOT='_EXPECT_NOT $LINENO'
alias TEST='_TEST $LINENO'