From: Karel Zak Date: Fri, 18 May 2007 13:34:28 +0000 (+0200) Subject: tests: add ts_log and --verbose support X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57a917d630b18908ac0b83336b3b0692c5033f9a;p=util-linux tests: add ts_log and --verbose support Signed-off-by: Karel Zak --- diff --git a/tests/README b/tests/README index bcade3d7..8eca0854 100644 --- a/tests/README +++ b/tests/README @@ -8,9 +8,9 @@ Run all tests: - ./run.sh + ./run.sh [--verbose] Run one tests: - ./ts--.sh + ./ts--.sh [--verbose] diff --git a/tests/functions.sh b/tests/functions.sh index 001c39f9..24308f69 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -3,6 +3,7 @@ TS_OUTDIR="output" TS_DIFFDIR="diff" TS_EXPECTEDDIR="expected" TS_INPUTDIR="input" +TS_VERBOSE="no" function ts_skip { echo " IGNORE ($1)" @@ -36,6 +37,11 @@ function ts_ok { exit 0 } +function ts_log { + echo "$1" >> $TS_OUTPUT + [ "$TS_VERBOSE" == "yes" ] && echo "$1" +} + function ts_init { export LANG="en_US.UTF-8": TS_NAME=$(basename $0) @@ -45,6 +51,7 @@ function ts_init { if [ ! -d $TS_DIFFDIR ]; then mkdir -p $TS_DIFFDIR fi + [ "$1" == "--verbose" ] && TS_VERBOSE="yes" TS_OUTPUT="$TS_OUTDIR/$TS_NAME" TS_DIFF="$TS_DIFFDIR/$TS_NAME" TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME" @@ -80,7 +87,7 @@ function ts_finalize { } function ts_die { - echo "$1" >> $TS_OUTPUT + ts_log "$1" if [ -n "$2" ] && [ -b "$2" ]; then ts_device_deinit "$2" fi diff --git a/tests/run.sh b/tests/run.sh index 4a475d82..51b7f738 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -11,7 +11,7 @@ rm -f *~ res=0 count=0 for ts in $(find -maxdepth 1 -regex "\./ts[^\.~]*" | sort); do - $TS_TOPDIR/$ts + $TS_TOPDIR/$ts "$1" res=$(( $res + $? )) count=$(( $count + 1 )) done diff --git a/tests/ts-col-multibyte b/tests/ts-col-multibyte index c1affe48..00ebb2b3 100755 --- a/tests/ts-col-multibyte +++ b/tests/ts-col-multibyte @@ -6,7 +6,7 @@ TS_COMPONENT="col" TS_DESC="multibyte" -ts_init +ts_init "$1" cat $TS_INPUT | $TS_CMD_COL > /dev/null 2> $TS_OUTPUT diff --git a/tests/ts-cramfs-mkfs b/tests/ts-cramfs-mkfs index d183f472..cbe37292 100755 --- a/tests/ts-cramfs-mkfs +++ b/tests/ts-cramfs-mkfs @@ -23,7 +23,7 @@ TS_COMPONENT="mkfs.cramfs" TS_DESC="mkfs" -ts_init +ts_init "$1" ts_skip_nonroot set -o pipefail @@ -34,10 +34,10 @@ IMAGE_RE=$( echo $IMAGE | sed 's:/:\\/:g' ) LABEL="testCramfs" MOUNTPOINT="$TS_OUTDIR/cramfs-mnt" -echo "create mountpoint dir" >> $TS_OUTPUT +ts_log "create mountpoint dir" [ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT -echo "generate data" >> $TS_OUTPUT +ts_log "generate data" if [ ! -d "$IMAGE_DATA" ]; then mkdir -p $IMAGE_DATA for d in `seq 0 110`; do @@ -50,45 +50,45 @@ if [ ! -d "$IMAGE_DATA" ]; then done fi -echo "list checksums from original data" >> $TS_OUTPUT +ts_log "list checksums from original data" find $IMAGE_DATA -type f -exec md5sum {} \; >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "create cramfs image" >> $TS_OUTPUT +ts_log "create cramfs image" $TS_CMD_MKCRAMFS -n $LABEL $IMAGE_DATA $IMAGE 2>&1 >> $TS_OUTPUT [ -s "$IMAGE" ] || ts_die "Cannot create $IMAGE" -echo "count MD5 from the image" >> $TS_OUTPUT +ts_log "count MD5 from the image" md5sum $IMAGE 2>&1 >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "create loop device from image" >> $TS_OUTPUT +ts_log "create loop device from image" DEVICE=$( $TS_CMD_LOSETUP -f ) $TS_CMD_LOSETUP $DEVICE $IMAGE 2>&1 >> $TS_OUTPUT -echo "check the image" >> $TS_OUTPUT +ts_log "check the image" ts_device_has "TYPE" "cramfs" $DEVICE [ "$?" == "0" ] || ts_die "Cannot found cramfs on $DEVICE" $DEVICE ts_udev_dev_support "by-label" $LABEL [ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE -echo "mount the image" >> $TS_OUTPUT +ts_log "mount the image" $TS_CMD_MOUNT -L $LABEL $MOUNTPOINT 2>&1 >> $TS_OUTPUT # check it grep -q $DEVICE /proc/mounts [ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE -echo "list the image" >> $TS_OUTPUT +ts_log "list the image" ls -laR $MOUNTPOINT >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "list checksums from new data" >> $TS_OUTPUT +ts_log "list checksums from new data" find $MOUNTPOINT -type f -exec md5sum {} \; >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "umount the image" >> $TS_OUTPUT +ts_log "umount the image" $TS_CMD_UMOUNT $DEVICE $TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT ts_finalize diff --git a/tests/ts-hwclock-systohc b/tests/ts-hwclock-systohc index 743eea69..2bbe9ce1 100755 --- a/tests/ts-hwclock-systohc +++ b/tests/ts-hwclock-systohc @@ -25,7 +25,7 @@ TS_DESC="systohc" NTP_SERVER="0.fedora.pool.ntp.org" -ts_init +ts_init "$1" ts_skip_nonroot [ -x "/usr/sbin/ntpdate" ] || ts_skip "cannot found ntpdate command" diff --git a/tests/ts-ipcs-headers b/tests/ts-ipcs-headers index c0f1e147..b8728d6c 100755 --- a/tests/ts-ipcs-headers +++ b/tests/ts-ipcs-headers @@ -6,9 +6,9 @@ TS_COMPONENT="ipcs" TS_DESC="headers" -ts_init +ts_init "$1" -echo "test: shm headers" >> $TS_OUTPUT +ts_log "test: shm headers" $TS_CMD_IPCS -m -t | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -m -p | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -m -c | grep --after-context=1 "^---" >> $TS_OUTPUT @@ -16,7 +16,7 @@ $TS_CMD_IPCS -m -l | grep "^---" >> $TS_OUTPUT $TS_CMD_IPCS -m -u | grep "^---" >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "test: mesg headers" >> $TS_OUTPUT +ts_log "test: mesg headers" $TS_CMD_IPCS -q -t | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -q -p | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -q -c | grep --after-context=1 "^---" >> $TS_OUTPUT @@ -24,7 +24,7 @@ $TS_CMD_IPCS -q -l | grep "^---" >> $TS_OUTPUT $TS_CMD_IPCS -q -u | grep "^---" >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "test: sem headers" >> $TS_OUTPUT +ts_log "test: sem headers" $TS_CMD_IPCS -s -t | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -s -p | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -s -c | grep --after-context=1 "^---" >> $TS_OUTPUT @@ -32,7 +32,7 @@ $TS_CMD_IPCS -s -l | grep "^---" >> $TS_OUTPUT $TS_CMD_IPCS -s -u | grep "^---" >> $TS_OUTPUT echo >> $TS_OUTPUT -echo "test: all headers" >> $TS_OUTPUT +ts_log "test: all headers" $TS_CMD_IPCS -a | grep --after-context=1 "^---" >> $TS_OUTPUT $TS_CMD_IPCS -a -t | grep --after-context=1 "^---" >> $TS_OUTPUT diff --git a/tests/ts-ipcs-limits b/tests/ts-ipcs-limits index 99a11c20..98656b68 100755 --- a/tests/ts-ipcs-limits +++ b/tests/ts-ipcs-limits @@ -7,37 +7,34 @@ TS_COMPONENT="ipcs" TS_DESC="limits overflow" if [ $UID != 0 ]; then - ts_init + ts_init "$1" ts_skip_nonroot fi . ts-ipcs.sh -ts_init +ts_init "$1" -( - echo "load original values" - for i in $IPCS_IDX; do - SHM_ORG[$i]=$(cat ${IPCS_PROCFILES[$i]}) - done +ts_log "load original values" +for i in $IPCS_IDX; do + SHM_ORG[$i]=$(cat ${IPCS_PROCFILES[$i]}) +done >> $TS_OUTPUT - echo "check for difference between kernel and IPC" - ipcs_limits_check +ts_log "check for difference between kernel and IPC" +ipcs_limits_check >> $TS_OUTPUT - echo "maximalize kernel setting" - for i in $IPCS_IDX; do - echo ${IPCS_LIMITS[$i]} >> ${IPCS_PROCFILES[$i]} - done +ts_log "maximalize kernel setting" +for i in $IPCS_IDX; do + echo ${IPCS_LIMITS[$i]} >> ${IPCS_PROCFILES[$i]} +done >> $TS_OUTPUT - echo "re-check for difference between kernel and IPC" - ipcs_limits_check +ts_log "re-check for difference between kernel and IPC" +ipcs_limits_check >> $TS_OUTPUT - echo "write original values to kernel" - for i in $IPCS_IDX; do - echo ${SHM_ORG[$i]} >> ${IPCS_PROCFILES[$i]} - done - -) > $TS_OUTPUT +ts_log "write original values to kernel" +for i in $IPCS_IDX; do + echo ${SHM_ORG[$i]} >> ${IPCS_PROCFILES[$i]} +done >> $TS_OUTPUT ts_finalize diff --git a/tests/ts-ipcs-limits2 b/tests/ts-ipcs-limits2 index 59e10d4f..05256f97 100755 --- a/tests/ts-ipcs-limits2 +++ b/tests/ts-ipcs-limits2 @@ -8,13 +8,10 @@ TS_DESC="basic limits" . ts-ipcs.sh -ts_init +ts_init "$1" -( - echo "check for difference between kernel and IPC" - ipcs_limits_check - -) > $TS_OUTPUT +ts_log "check for difference between kernel and IPC" +ipcs_limits_check >> $TS_OUTPUT ts_finalize diff --git a/tests/ts-ipcs.sh b/tests/ts-ipcs.sh index 9f9e119c..ff0fc717 100644 --- a/tests/ts-ipcs.sh +++ b/tests/ts-ipcs.sh @@ -1,10 +1,5 @@ #!/bin/bash -if [ ! -f "/proc/sys/kernel/shmall" ]; then - ts_init - ts_skip "not IPC in kernel" -fi - PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize) # kernel files diff --git a/tests/ts-login-checktty b/tests/ts-login-checktty index d0509b05..a79b02d0 100755 --- a/tests/ts-login-checktty +++ b/tests/ts-login-checktty @@ -6,7 +6,7 @@ TS_COMPONENT="login" TS_DESC="checktty" -ts_init +ts_init "$1" $TS_CMD_CHECKTTY >> $TS_OUTPUT ts_finalize diff --git a/tests/ts-look-separator b/tests/ts-look-separator index fe86e2ca..c6f6ed4c 100755 --- a/tests/ts-look-separator +++ b/tests/ts-look-separator @@ -18,7 +18,7 @@ TS_COMPONENT="look" TS_DESC="separator" -ts_init +ts_init "$1" [ -f "/usr/share/dict/words" ] || ts_skip "/usr/share/dict/words not such file" diff --git a/tests/ts-mount-move b/tests/ts-mount-move index 88458110..3b182658 100755 --- a/tests/ts-mount-move +++ b/tests/ts-mount-move @@ -10,7 +10,7 @@ TS_COMPONENT="mount" TS_DESC="move " -ts_init +ts_init "$1" ts_skip_nonroot PWD=$(pwd) @@ -44,6 +44,6 @@ fi $TS_CMD_UMOUNT $DIR_SRC rmdir $DIR_SRC $DIR_A $DIR_B -echo "Success" >> $TS_OUTPUT +ts_log "Success" ts_finalize diff --git a/tests/ts-mount-mtablock b/tests/ts-mount-mtablock index 5ef76f2b..87f80770 100755 --- a/tests/ts-mount-mtablock +++ b/tests/ts-mount-mtablock @@ -6,7 +6,7 @@ TS_COMPONENT="mount" TS_DESC="mtablock" -ts_init +ts_init "$1" ts_skip_nonroot # diff --git a/tests/ts-mount-paths b/tests/ts-mount-paths index 137aade3..32198c41 100755 --- a/tests/ts-mount-paths +++ b/tests/ts-mount-paths @@ -6,7 +6,7 @@ TS_COMPONENT="mount" TS_DESC="basic paths" -ts_init +ts_init "$1" $TS_CMD_MOUNT -n -f --debug=2 /dev/dummy /mnt &> $TS_OUTPUT diff --git a/tests/ts-mount-remount b/tests/ts-mount-remount index dcaf2888..295ca509 100755 --- a/tests/ts-mount-remount +++ b/tests/ts-mount-remount @@ -9,7 +9,7 @@ TS_COMPONENT="mount" TS_DESC="remount" -ts_init +ts_init "$1" ts_skip_nonroot # mountpoint @@ -40,6 +40,6 @@ egrep -q "^$DEVICE $MOUNTPOINT ext2 ro 0 0" /etc/mtab ts_device_deinit $DEVICE -echo "Success" >> $TS_OUTPUT +ts_log "Success" ts_finalize diff --git a/tests/ts-mount-special b/tests/ts-mount-special index 4d29167c..e0d3f997 100755 --- a/tests/ts-mount-special +++ b/tests/ts-mount-special @@ -12,7 +12,7 @@ TS_DESC="special program" MOUNTER="/sbin/mount.mytest" -ts_init +ts_init "$1" ts_skip_nonroot cat > $MOUNTER << EOF diff --git a/tests/ts-namei-logic b/tests/ts-namei-logic index 55cd7579..0a4693c4 100755 --- a/tests/ts-namei-logic +++ b/tests/ts-namei-logic @@ -6,15 +6,13 @@ TS_COMPONENT="namei" TS_DESC="logic" -ts_init +ts_init "$1" SANDBOX="$TS_OUTDIR/namei" mkdir -p $SANDBOX/namei1/namei2 touch $SANDBOX/namei1/namei2/a $SANDBOX/namei1/namei2/b -touch $TS_OUTPUT - $TS_CMD_NAMEI $SANDBOX/namei1/namei2/a >> $TS_OUTPUT 2>&1 $TS_CMD_NAMEI $SANDBOX/namei1/namei2/b >> $TS_OUTPUT 2>&1 $TS_CMD_NAMEI $SANDBOX/namei1/namei2/a/b >> $TS_OUTPUT 2>&1 diff --git a/tests/ts-swapon-devname b/tests/ts-swapon-devname index 674f179c..f8552a6e 100755 --- a/tests/ts-swapon-devname +++ b/tests/ts-swapon-devname @@ -21,7 +21,7 @@ TS_COMPONENT="swapon" TS_DESC="devname" -ts_init +ts_init "$1" ts_skip_nonroot set -o pipefail @@ -43,6 +43,6 @@ grep -q $DEVICE /proc/swaps ts_swapoff $DEVICE ts_device_deinit $DEVICE -echo "Success" >> $TS_OUTPUT +ts_log "Success" ts_finalize diff --git a/tests/ts-swapon-label b/tests/ts-swapon-label index 2f8aef10..0d7dc93a 100755 --- a/tests/ts-swapon-label +++ b/tests/ts-swapon-label @@ -23,7 +23,7 @@ TS_DESC="label" LABEL="testSwapLabel" -ts_init +ts_init "$1" ts_skip_nonroot set -o pipefail @@ -48,6 +48,6 @@ grep -q $DEVICE /proc/swaps ts_swapoff $DEVICE ts_device_deinit $DEVICE -echo "Success" >> $TS_OUTPUT +ts_log "Success" ts_finalize diff --git a/tests/ts-swapon-uuid b/tests/ts-swapon-uuid index b77b06aa..6e2a90fa 100755 --- a/tests/ts-swapon-uuid +++ b/tests/ts-swapon-uuid @@ -21,7 +21,7 @@ TS_COMPONENT="swapon" TS_DESC="uuid" -ts_init +ts_init "$1" ts_skip_nonroot set -o pipefail @@ -48,6 +48,6 @@ grep -q $DEVICE /proc/swaps ts_swapoff $DEVICE ts_device_deinit $DEVICE -echo "Success" >> $TS_OUTPUT +ts_log "Success" ts_finalize