summaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorAnand Avati <avati@gluster.com>2010-11-19 06:25:40 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-11-24 00:33:25 -0800
commitc509e7f185d4f76be9f5ddbd61839239198a0b1d (patch)
tree8b3338f5fbfab6ce392fdca9f7e28cdb333381b5 /extras
parentf6785d2b4999db7d42e8c1cd054fd7ec174e8136 (diff)
rpc-coverage.sh: enhancements for more extensive testing
Signed-off-by: Anand V. Avati <avati@blackhole.gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 875 (Implement a new protocol to provide proper backward/forward compatibility) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=875
Diffstat (limited to 'extras')
-rwxr-xr-xextras/rpc-coverage.sh469
1 files changed, 440 insertions, 29 deletions
diff --git a/extras/rpc-coverage.sh b/extras/rpc-coverage.sh
index 1f4dfcc9a9d..ce12fddb4d4 100755
--- a/extras/rpc-coverage.sh
+++ b/extras/rpc-coverage.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# This script can be used to provoke 35 fops (if afr is used),
# 28 fops (if afr is not used) (-fstat,-readdirp, and lk,xattrop calls)
@@ -44,40 +44,451 @@
# WRITE
# XATTROP
-set -e
+set -e;
+set -o pipefail;
-MOUNTPOINT=$1;
+function test_mkdir()
+{
+ mkdir -p $PFX/dir;
-[ -z $MOUNTPOINT ] && {
- MOUNTPOINT="/mnt/glusterfs";
+ test $(stat -c '%F' $PFX/dir) == "directory";
}
-current_dir=$PWD;
-TESTDIR="${MOUNTPOINT}/fop-test-$(date +%Y%m%d%H%M%S)"
-mkdir $TESTDIR;
-cd $TESTDIR;
-echo "Lets see open working" >> testfile;
-echo "Lets see truncate working 012345678" > testfile;
-truncate -s 30 testfile;
-mkdir testdir;
-mkfifo testfifo;
-ln testfile testfile-ln;
-ln -sf testfile testfile-symlink;
-mv testfile-symlink testfile-symlink-mv;
-chmod 0777 testfile;
-flock -x testfile.lock dd if=/dev/zero of=testfile1 conv=fsync bs=1M count=2 > /dev/null 2>&1;
-cat testfile1 > /dev/null;
-ls -lR . > /dev/null;
-setfattr -n trusted.rpc.coverage -v testing testfile;
-getfattr -d -m . testfile > /dev/null;
-setfattr -x trusted.rpc.coverage testfile;
-df -h testdir > /dev/null;
+function test_create()
+{
+ : > $PFX/dir/file;
-rm -f testfifo testfile testfile1 testfile-ln testfile.lock testfile-symlink-mv;
-rmdir testdir;
+ test "$(stat -c '%F' $PFX/dir/file)" == "regular empty file";
+}
+
+
+function test_statfs()
+{
+ local size;
+
+ size=$(stat -f -c '%s' $PFX/dir/file);
+
+ test "x$size" != "x0";
+}
+
+
+function test_open()
+{
+ exec 4<$PFX/dir/file;
+ exec 4>&-;
+}
+
+
+function test_write()
+{
+ dd if=/dev/zero of=$PFX/dir/file bs=65536 count=16 2>/dev/null;
+
+ test $(stat -c '%s' $PFX/dir/file) == 1048576;
+}
+
+
+function test_read()
+{
+ local count;
+
+ count=$(dd if=$PFX/dir/file bs=64k count=16 2>/dev/null | wc -c);
+
+ test $count == 1048576;
+}
+
+
+function test_truncate()
+{
+ truncate -s 512 $PFX/dir/file;
+
+ test $(stat -c '%s' $PFX/dir/file) == 512;
+
+ truncate -s 0 $PFX/dir/file;
+
+ test $(stat -c '%s' $PFX/dir/file) == 0;
+}
+
+
+function test_fstat()
+{
+ local msg;
+
+ export PFX;
+ msg=$(sh -c 'tail -f $PFX/dir/file --pid=$$ & sleep 1 && echo hooha > $PFX/dir/file && sleep 1');
+
+ test "x$msg" == "xhooha";
+}
+
+
+function test_mknod()
+{
+ mknod -m 0666 $PFX/dir/block b 13 42;
+
+ test "$(stat -c '%F %a %t %T' $PFX/dir/block)" == "block special file 666 d 2a";
+
+ mknod -m 0666 $PFX/dir/char c 13 42;
+
+ test "$(stat -c '%F %a %t %T' $PFX/dir/char)" == "character special file 666 d 2a";
+
+ mknod -m 0666 $PFX/dir/fifo p;
+
+ test "$(stat -c '%F %a' $PFX/dir/fifo)" == "fifo 666";
+}
+
+
+function test_symlink()
+{
+ local msg;
+
+ ln -s $PFX/dir/file $PFX/dir/symlink;
+
+ test "$(stat -c '%F' $PFX/dir/symlink)" == "symbolic link";
+
+ msg=$(cat $PFX/dir/symlink);
+
+ test "x$msg" == "xhooha";
+}
+
+
+function test_hardlink()
+{
+ local ino1;
+ local ino2;
+ local nlink1;
+ local nlink2;
+ local msg;
+
+ ln $PFX/dir/file $PFX/dir/hardlink;
+
+ ino1=$(stat -c '%i' $PFX/dir/file);
+ nlink1=$(stat -c '%h' $PFX/dir/file);
+ ino2=$(stat -c '%i' $PFX/dir/hardlink);
+ nlink2=$(stat -c '%h' $PFX/dir/hardlink);
+
+ test $ino1 == $ino2;
+ test $nlink1 == 2;
+ test $nlink2 == 2;
+
+ msg=$(cat $PFX/dir/hardlink);
+
+ test "x$msg" == "xhooha";
+}
+
+
+function test_rename()
+{
+ local ino1;
+ local ino2;
+ local ino3;
+ local msg;
+
+ #### file
+
+ ino1=$(stat -c '%i' $PFX/dir/file);
+
+ mv $PFX/dir/file $PFX/dir/file2;
+
+ msg=$(cat $PFX/dir/file2);
+ test "x$msg" == "xhooha";
+
+ ino2=$(stat -c '%i' $PFX/dir/file2);
+ test $ino1 == $ino2;
+
+ mv $PFX/dir/file2 $PFX/dir/file;
+
+ msg=$(cat $PFX/dir/file);
+ test "x$msg" == "xhooha";
+
+ ino3=$(stat -c '%i' $PFX/dir/file);
+ test $ino1 == $ino3;
+
+ #### dir
+
+ ino1=$(stat -c '%i' $PFX/dir);
+
+ mv $PFX/dir $PFX/dir2;
+
+ ino2=$(stat -c '%i' $PFX/dir2);
+ test $ino1 == $ino2;
+
+ mv $PFX/dir2 $PFX/dir;
+
+ ino3=$(stat -c '%i' $PFX/dir);
+ test $ino1 == $ino3;
+}
+
+
+function test_chmod()
+{
+ local mode0;
+ local mode1;
+ local mode2;
+
+
+ #### file
+
+ mode0=$(stat -c '%a' $PFX/dir/file);
+
+ chmod 0753 $PFX/dir/file;
+
+ mode1=$(stat -c '%a' $PFX/dir/file);
+ test 0$mode1 == 0753;
+
+ chmod 0$mode0 $PFX/dir/file;
+
+ mode2=$(stat -c '%a' $PFX/dir/file);
+
+ test 0$mode2 == 0$mode0;
+
+ #### dir
+
+ mode0=$(stat -c '%a' $PFX/dir);
+
+ chmod 0753 $PFX/dir;
+
+ mode1=$(stat -c '%a' $PFX/dir);
+ test 0$mode1 == 0753;
+
+ chmod 0$mode0 $PFX/dir;
-cd $current_dir;
+ mode2=$(stat -c '%a' $PFX/dir);
+
+ test 0$mode2 == 0$mode0;
+}
+
+
+function test_chown()
+{
+ local user1;
+ local user2;
+ local group1;
+ local group2;
+
+ #### file
+
+ user1=$(stat -c '%u' $PFX/dir/file);
+ group1=$(stat -c '%g' $PFX/dir/file);
+
+ chown 13:42 $PFX/dir/file;
+
+ user2=$(stat -c '%u' $PFX/dir/file);
+ group2=$(stat -c '%g' $PFX/dir/file);
+
+ test $user2 == 13;
+ test $group2 == 42;
+
+ chown $user1:$group1 $PFX/dir/file;
+
+ user2=$(stat -c '%u' $PFX/dir/file);
+ group2=$(stat -c '%g' $PFX/dir/file);
+
+ test $user2 == $user1;
+ test $group2 == $group1;
+
+ #### dir
+
+ user1=$(stat -c '%u' $PFX/dir);
+ group1=$(stat -c '%g' $PFX/dir);
+
+ chown 13:42 $PFX/dir;
+
+ user2=$(stat -c '%u' $PFX/dir);
+ group2=$(stat -c '%g' $PFX/dir);
+
+ test $user2 == 13;
+ test $group2 == 42;
+
+ chown $user1:$group1 $PFX/dir;
+
+ user2=$(stat -c '%u' $PFX/dir);
+ group2=$(stat -c '%g' $PFX/dir);
+
+ test $user2 == $user1;
+ test $group2 == $group1;
+}
+
+
+function test_utimes()
+{
+ local acc0;
+ local acc1;
+ local acc2;
+ local mod0;
+ local mod1;
+ local mod2;
+
+ #### file
+
+ acc0=$(stat -c '%X' $PFX/dir/file);
+ mod0=$(stat -c '%Y' $PFX/dir/file);
+
+ sleep 1;
+ touch -a $PFX/dir/file;
+
+ acc1=$(stat -c '%X' $PFX/dir/file);
+ mod1=$(stat -c '%Y' $PFX/dir/file);
+
+ sleep 1;
+ touch -m $PFX/dir/file;
+
+ acc2=$(stat -c '%X' $PFX/dir/file);
+ mod2=$(stat -c '%Y' $PFX/dir/file);
+
+ test $acc0 != $acc1;
+ test $acc1 == $acc2;
+ test $mod0 == $mod1;
+ test $mod1 != $mod2;
+
+ #### dir
+
+ acc0=$(stat -c '%X' $PFX/dir);
+ mod0=$(stat -c '%Y' $PFX/dir);
+
+ sleep 1;
+ touch -a $PFX/dir;
+
+ acc1=$(stat -c '%X' $PFX/dir);
+ mod1=$(stat -c '%Y' $PFX/dir);
+
+ sleep 1;
+ touch -m $PFX/dir;
+
+ acc2=$(stat -c '%X' $PFX/dir);
+ mod2=$(stat -c '%Y' $PFX/dir);
+
+ test $acc0 != $acc1;
+ test $acc1 == $acc2;
+ test $mod0 == $mod1;
+ test $mod1 != $mod2;
+}
+
+
+function test_locks()
+{
+ exec 200>$PFX/dir/lockfile;
+
+ ## exclusive locks test
+ flock -e 200;
+ ! flock -n -e $PFX/dir/lockfile -c true;
+ ! flock -n -s $PFX/dir/lockfile -c true;
+ flock -u 200;
+
+ ## shared locks test
+ flock -s 200;
+ ! flock -n -e $PFX/dir/lockfile -c true;
+ flock -n -s $PFX/dir/lockfile -c true;
+ flock -u 200;
+
+ exec 200>&-;
+
+}
+
+
+function test_readdir()
+{
+ /bin/ls $PFX/dir >/dev/null
+}
+
+
+function test_setxattr()
+{
+ setfattr -n trusted.testing -v c00k33 $PFX/dir/file;
+}
+
+
+function test_listxattr()
+{
+ getfattr -m trusted $PFX/dir/file 2>/dev/null | grep -q trusted.testing;
+}
+
+
+function test_getxattr()
+{
+ getfattr -n trusted.testing $PFX/dir/file 2>/dev/null | grep -q c00k33;
+}
+
+
+function test_removexattr()
+{
+ setfattr -x trusted.testing $PFX/dir/file;
+ getfattr -n trusted.testing $PFX/dir/file 2>&1 | grep -q 'No such attribute';
+}
+
+
+function test_unlink()
+{
+ rm $PFX/dir/file;
+}
+
+
+function test_rmdir()
+{
+ rm -rf $PFX;
+}
+
+
+function run_tests()
+{
+ test_mkdir;
+ test_create;
+ test_statfs;
+ test_open;
+ test_write;
+ test_read;
+ test_truncate;
+ test_fstat;
+ test_mknod;
+ test_hardlink;
+ test_symlink;
+ test_rename;
+ test_chmod;
+ test_chown;
+ test_utimes;
+ test_locks;
+ test_readdir;
+ test_setxattr;
+ test_listxattr;
+ test_getxattr;
+ test_removexattr;
+ test_unlink;
+ test_rmdir;
+}
+
+
+function _init()
+{
+ DIR=$(pwd);
+}
+
+
+function parse_cmdline()
+{
+ if [ "x$1" == "x" ] ; then
+ echo "Usage: $0 /path/mount"
+ exit 1
+ fi
+
+ DIR=$1;
+
+ if [ ! -d "$DIR" ] ; then
+ echo "$DIR: not a directory"
+ exit 1
+ fi
+
+ PFX="$DIR/coverage";
+ rm -rvf $PFX;
+}
+
+
+function main()
+{
+ parse_cmdline "$@";
+
+ run_tests;
+
+ exit 0;
+}
-rmdir ${TESTDIR}
+_init && main "$@";