From 51eaed7fb243a989fdf96461ba2d9acfc07977f8 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Wed, 26 Nov 2014 09:59:25 +0100 Subject: Regression test portability: batch of bugs (volume 2) Fix various regression test portability in tests/bugs. bug-861542.t - Avoid syntax specific to GNU sed. bug-860663.t - Command argument length is system dependent, and specifying 1000 file path may overflow it. Use a C program to do the job in a portable and efficient way. - Add a test that we created the specified amount of files. bug-858242.c, bug-808400-fcntl.c, bug-808400-flock.c - fstat64() is Linux-specific. Define it as fstat for other systems. bug-823081.t - Use portable tail -n instead of tail --lines In many tests: - Do not assume python interpreter name. Use $PYTHON as defined in env.rc by configure. utils/libcxattr.py - If python version is 2.6 or higher, use a portable mechanism to recover errno. The original version is retained for python version 2.5 and earlier but it only works on Linux. BUG: 1129939 Change-Id: If2fea1ffec5cc6ab2de426fb200e884450afe61b Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/9097 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/include.rc | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 3 deletions(-) (limited to 'tests/include.rc') diff --git a/tests/include.rc b/tests/include.rc index dc6fc6e25d..cd5d07f262 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -301,7 +301,7 @@ which killall > /dev/null || { which pidof > /dev/null || { pidof() { - pidof.py $@ + $PYTHON pidof.py $@ } } @@ -612,13 +612,13 @@ which md5sum > /dev/null || { which setfattr > /dev/null || { setfattr() { - setfattr.py $@ + $PYTHON setfattr.py $@ } } which getfattr > /dev/null || { getfattr() { - getfattr.py $@ + $PYTHON getfattr.py $@ } } @@ -659,6 +659,26 @@ useradd --help 2>/dev/null | grep -q -- '--no-create-home' || { } } +userdel --help 2>/dev/null | grep -q -- '--force' || { + userdel() { + if [ "x$1" = "x--force" ]; then + user=$2 + else + user=$1 + fi + eval "$( which userdel ) $user" + } +} + +useradd --help 2>/dev/null | grep -q -- '--no-create-home' || { + useradd() { + # Just remove -M (do not create home) which is the default + # other options are identical + args=`echo $*|sed 's/-M//'` + eval "$( which useradd ) $args" + } +} + alias EXPECT='_EXPECT $LINENO' alias EXPECT_NOT='_EXPECT_NOT $LINENO' alias TEST='_TEST $LINENO' @@ -827,6 +847,156 @@ function UMOUNT_LOOP () esac } +function SETUP_LOOP () +{ + if [ $# != 1 ] ; then + echo "SETUP_LOOP usage" >&2 + exit 1; + fi + + backend=$1 + + case ${OSTYPE} in + Linux) + losetup --find --show ${backend} + ;; + NetBSD) + vnd=`vnconfig -l|awk -F: '/not in use/{print $1; exit}'` + if [ "x${vnd}" = "x" ] ; then + echo "no more vnd" >&2 + exit 1; + fi + vnconfig ${vnd} ${backend} + echo ${vnd} + ;; + *) + echo "Please define SETUP_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + +function MKFS_LOOP () +{ + args=`getopt i: $*` + if [ $? -ne 0 ] ; then + echo "MKFS_LOOP usage" >&2 + exit 1; + fi + set -- ${args} + + isize="" + while test $# -gt 0; do + case "$1" in + -i) isize=$2; shift ;; + --) shift; break ;; + esac + shift + done + + dev=$1 + + case ${OSTYPE} in + Linux) + test "x${isize}" != "x" && isize="-i size=${isize}" + mkfs.xfs -f ${isize} ${dev} + ;; + NetBSD) + test "x${isize}" != "x" && isize="-i ${isize}" + + echo ${dev} | grep -q '^vnd' + if [ $? -ne 0 ] ; then + vnd=`vnconfig -l|awk -F: '/not in use/{print $1; exit}'` + if [ "x${vnd}" = "x" ] ; then + echo "no more vnd" >&2 + exit 1; + fi + vnconfig ${vnd} ${dev} + else + vnd=${dev} + fi + newfs ${isize} /dev/r${vnd}a + ;; + *) + echo "Please define MKFS_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + +function MOUNT_LOOP () +{ + if [ $# != 2 ] ; then + echo "MOUNT_LOOP usage" >&2 + exit 1; + fi + + dev=$1 + target=$2 + + case ${OSTYPE} in + Linux) + echo ${dev} | grep -q '^/dev/loop' + if [ $? -eq 0 ] ; then + mount -t xfs ${dev} ${target} + else + mount -o loop ${dev} ${target} + fi + ;; + NetBSD) + echo ${dev} | grep -q '^vnd' + if [ $? -ne 0 ] ; then + ino=`/usr/bin/stat -f %i ${dev}` + dev=`vnconfig -l | awk -v ino=${ino} -F'[: ]*' '($5 == ino) {print $1}'` + fi + + mount /dev/${dev}a ${target} >&2 + if [ $? -ne 0 ] ; then + echo "failed to mount /dev/${dev}a on ${target}" >&2 + exit 1 + fi + + mkdir -p ${target}/.attribute/system ${target}/.attribute/user + mount -u -o extattr ${target} >&2 + + ;; + *) + echo "Please define MOUNT_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + +function UMOUNT_LOOP () +{ + case ${OSTYPE} in + Linux) + force_umount $* + ;; + NetBSD) + for target in $* ; do + dev=`mount | awk -v target=${target} '($3 == target) {print $1}'` + force_umount ${target} + echo ${dev} | grep -q '^/dev/vnd' + if [ $? -eq 0 ] ; then + dev=`echo ${dev} | sed 's|^/dev/||; s|a$||'` + vnconfig -u ${dev} + else + ino=`/usr/bin/stat -f %i ${dev}` + dev=`vnconfig -l | awk -v ino=${ino} -F'[: ]*' '($5 == ino) {print $1}'` + if [ "x${dev}" != "x" ] ; then + vnconfig -u ${dev} + fi + fi + done + ;; + *) + echo "Please define UMOUNT_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + function STAT() { stat $1 -- cgit