From d42bbae57d1184a7671782151c5413b874b0c23c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 19 Jan 2009 18:08:06 +0100 Subject: [PATCH] tests: add support for subdirs to basic test functions Signed-off-by: Karel Zak --- tests/functions.sh | 67 +++++++++++++++------ tests/run.sh | 8 +-- tests/ts/col/multibyte | 2 +- tests/ts/ipcs/{function.sh => functions.sh} | 0 tests/ts/ipcs/limits | 3 +- tests/ts/ipcs/limits2 | 8 +-- tests/ts/login/islocal | 2 +- tests/ts/mount/fstab-symlink | 2 +- tests/ts/script/race | 2 +- 9 files changed, 60 insertions(+), 34 deletions(-) rename tests/ts/ipcs/{function.sh => functions.sh} (100%) diff --git a/tests/functions.sh b/tests/functions.sh index 371deb6a..ecb205b1 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -20,6 +20,8 @@ TS_EXPECTEDDIR="expected" TS_INPUTDIR="input" TS_VERBOSE="no" +. ./commands.sh + function ts_skip { echo " IGNORE ($1)" if [ -n "$2" -a -b "$2" ]; then @@ -36,7 +38,7 @@ function ts_skip_nonroot { function ts_failed { if [ x"$1" == x"" ]; then - echo " FAILED ($TS_NAME)" + echo " FAILED ($TS_NS)" else echo " FAILED ($1)" fi @@ -64,28 +66,37 @@ function ts_has_option { } function ts_init { + local is_fake + export LANG="en_US.UTF-8": - TS_NAME=$(basename $0) - if [ ! -d $TS_OUTDIR ]; then - mkdir -p $TS_OUTDIR - fi - if [ ! -d $TS_DIFFDIR ]; then - mkdir -p $TS_DIFFDIR - fi + + TS_VERBOSE=$( ts_has_option "verbose" "$*") + is_fake=$( ts_has_option "fake" "$*") + + TS_SCRIPT="$0" + TS_SUBDIR=$(dirname $TS_SCRIPT) + TS_TESTNAME=$(basename $TS_SCRIPT) + TS_COMPONENT=$(basename $TS_SUBDIR) + + TS_NS="$TS_COMPONENT/$TS_TESTNAME" + TS_SELF="$TS_SUBDIR" + + TS_OUTPUT="$TS_OUTDIR/$TS_NS" + TS_DIFF="$TS_DIFFDIR/$TS_NS" + TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NS" + TS_MOUNTPOINT="$(pwd)/$TS_OUTDIR/${TS_NS}_mnt" + + TS_HAS_VOLUMEID="no" + + BLKID_FILE="$TS_OUTDIR/${TS_NS}.blkidtab" + + [ ! -d "$(dirname $TS_OUTPUT)" ] && mkdir -p $(dirname $TS_OUTPUT) + [ ! -d "$(dirname $TS_DIFF)" ] && mkdir -p $(dirname $TS_DIFF) declare -a TS_SUID_PROGS declare -a TS_SUID_USER declare -a TS_SUID_GROUP - TS_VERBOSE=$( ts_has_option "verbose" "$*") - TS_OUTPUT="$TS_OUTDIR/$TS_NAME" - TS_DIFF="$TS_DIFFDIR/$TS_NAME" - TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME" - TS_INPUT="$TS_INPUTDIR/$TS_NAME" - TS_MOUNTPOINT="$(pwd)/$TS_OUTDIR/${TS_NAME}_mnt" - TS_HAS_VOLUMEID="no" - BLKID_FILE="$TS_OUTDIR/$TS_NAME.blkidtab" - export BLKID_FILE if [ -x $TS_CMD_MOUNT ]; then @@ -99,6 +110,26 @@ function ts_init { touch $TS_OUTPUT printf "%15s: %-25s ..." "$TS_COMPONENT" "$TS_DESC" + + if [ "$TS_VERBOSE" == "yes" ]; then + echo + echo " script: $TS_SCRIPT" + echo " top dir: $TS_TOPDIR" + echo " sub dir: $TS_SUBDIR" + echo " self: $TS_SELF" + echo " test name: $TS_TESTNAME" + echo " test desc: $TS_DESC" + echo " component: $TS_COMPONENT" + echo " namespace: $TS_NS" + echo " verbose: $TS_VERBOSE" + echo " output: $TS_OUTPUT" + echo " expected: $TS_EXPECTED" + echo " mountpoint: $TS_MOUNTPOINT" + echo + fi + + [ "$is_fake" == "yes" ] && ts_skip "fake mode" + } function ts_init_suid { @@ -153,7 +184,7 @@ function ts_die { } function ts_device_init { - local IMAGE="$TS_OUTDIR/$TS_NAME.img" + local IMAGE="$TS_OUTDIR/${TS_NS}.img" local DEV="" dd if=/dev/zero of="$IMAGE" bs=1M count=5 &> /dev/null diff --git a/tests/run.sh b/tests/run.sh index 7b662390..cef13716 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -15,7 +15,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -. ./commands.sh +. functions.sh echo echo "------------------ Utils-linux-ng regression tests ------------------" @@ -24,12 +24,10 @@ echo " For development purpose only. " echo " Don't execute on production system! " echo -rm -f *~ - res=0 count=0 -for ts in $(find -maxdepth 1 -regex "\./ts[^\.~]*" | sort); do - $TS_TOPDIR/$ts "$1" +for ts in $(find ts/ -type f -perm /a+x -regex "[^\.~]*" | sort); do + ./$ts "$1" res=$(( $res + $? )) count=$(( $count + 1 )) done diff --git a/tests/ts/col/multibyte b/tests/ts/col/multibyte index 357d7f15..b030bead 100755 --- a/tests/ts/col/multibyte +++ b/tests/ts/col/multibyte @@ -23,7 +23,7 @@ TS_DESC="multibyte" ts_init "$*" -cat $TS_INPUT | $TS_CMD_COL > /dev/null 2> $TS_OUTPUT +cat $TS_SELF/multibyte.data | $TS_CMD_COL > /dev/null 2> $TS_OUTPUT ts_finalize diff --git a/tests/ts/ipcs/function.sh b/tests/ts/ipcs/functions.sh similarity index 100% rename from tests/ts/ipcs/function.sh rename to tests/ts/ipcs/functions.sh diff --git a/tests/ts/ipcs/limits b/tests/ts/ipcs/limits index 6224ac44..0fb31606 100755 --- a/tests/ts/ipcs/limits +++ b/tests/ts/ipcs/limits @@ -21,10 +21,9 @@ TS_COMPONENT="ipcs" TS_DESC="limits overflow" -. ./ts-ipcs.sh - ts_init "$*" ts_skip_nonroot +. $TS_SELF/functions.sh ts_log "load original values" for i in $IPCS_IDX; do diff --git a/tests/ts/ipcs/limits2 b/tests/ts/ipcs/limits2 index f539e8a6..17c3c702 100755 --- a/tests/ts/ipcs/limits2 +++ b/tests/ts/ipcs/limits2 @@ -15,16 +15,14 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -. ./commands.sh -. ./functions.sh -TS_COMPONENT="ipcs" TS_DESC="basic limits" -. ./ts-ipcs.sh - +. ./functions.sh ts_init "$*" +. $TS_SELF/functions.sh + ts_log "check for difference between kernel and IPC" ipcs_limits_check >> $TS_OUTPUT diff --git a/tests/ts/login/islocal b/tests/ts/login/islocal index 0c8d7798..acffb077 100755 --- a/tests/ts/login/islocal +++ b/tests/ts/login/islocal @@ -22,7 +22,7 @@ TS_COMPONENT="login" TS_DESC="islocal" ts_init "$*" -$TS_CMD_ISLOCAL "$TS_INPUT" root nobody "" youngman youngman2 \ +$TS_CMD_ISLOCAL "$TS_SELF/islocal.data" root nobody "" youngman youngman2 \ abcdefghx nobo long rot al malformed \ nonl znobody >> $TS_OUTPUT ts_finalize diff --git a/tests/ts/mount/fstab-symlink b/tests/ts/mount/fstab-symlink index 336ecdba..f567e8fd 100755 --- a/tests/ts/mount/fstab-symlink +++ b/tests/ts/mount/fstab-symlink @@ -26,7 +26,7 @@ ts_skip_nonroot set -o pipefail -LINKNAME="$(pwd)/$TS_OUTDIR/${TS_NAME}_lnk" +LINKNAME="$(pwd)/$TS_OUTDIR/${TS_NS}_lnk" DEVICE=$(ts_device_init) [ "$?" == 0 ] || ts_die "Cannot init device" diff --git a/tests/ts/script/race b/tests/ts/script/race index 818d0c5e..d450ec5d 100755 --- a/tests/ts/script/race +++ b/tests/ts/script/race @@ -23,7 +23,7 @@ TS_DESC="race conditions" ts_init "$*" -bingofile="$TS_OUTDIR/$TS_NAME-bingo" +bingofile="$TS_OUTDIR/${TS_NS}-bingo" set -o pipefail -- 2.39.5