From 09892fb60a33d010fc56efad8cc7b3d88dd58581 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 16 May 2007 00:41:14 +0200 Subject: [PATCH] tests: code refactoring -- new ts_skip_nonroot function The patch moves "if $UID != 0" test to a new function. That's better than duplicate the code on many places. Signed-off-by: Karel Zak --- tests/functions.sh | 6 ++++++ tests/ts-cramfs-mkfs | 6 +----- tests/ts-hwclock-systohc | 4 +--- tests/ts-ipcs-limits | 2 +- tests/ts-look-separator | 2 +- tests/ts-mkswap-doit | 5 +---- tests/ts-mount-move | 5 +---- tests/ts-mount-mtablock | 5 +---- tests/ts-mount-remount | 5 +---- tests/ts-mount-special | 5 +---- 10 files changed, 15 insertions(+), 30 deletions(-) diff --git a/tests/functions.sh b/tests/functions.sh index c04022b3..969592f7 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -9,6 +9,12 @@ function ts_skip { exit 0 } +function ts_skip_nonroot { + if [ $UID != 0 ]; then + ts_skip "not root permissions" + fi +} + function ts_failed { if [ x"$1" == x"" ]; then echo " FAILED ($TS_NAME)" diff --git a/tests/ts-cramfs-mkfs b/tests/ts-cramfs-mkfs index 1f7156ee..c1f46f11 100755 --- a/tests/ts-cramfs-mkfs +++ b/tests/ts-cramfs-mkfs @@ -24,14 +24,10 @@ TS_COMPONENT="mkfs.cramfs" TS_DESC="mkfs" ts_init - -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi +ts_skip_nonroot set -o pipefail - touch $TS_OUTPUT IMAGE="$TS_OUTDIR/cramfs-loop.img" diff --git a/tests/ts-hwclock-systohc b/tests/ts-hwclock-systohc index 6171ab30..43d66320 100755 --- a/tests/ts-hwclock-systohc +++ b/tests/ts-hwclock-systohc @@ -26,10 +26,8 @@ TS_DESC="systohc" NTP_SERVER="0.fedora.pool.ntp.org" ts_init +ts_skip_nonroot -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi if [ -x "ntpdate" ]; then ts_skip "cannot found ntpdate command" fi diff --git a/tests/ts-ipcs-limits b/tests/ts-ipcs-limits index 542819f1..99a11c20 100755 --- a/tests/ts-ipcs-limits +++ b/tests/ts-ipcs-limits @@ -8,7 +8,7 @@ TS_DESC="limits overflow" if [ $UID != 0 ]; then ts_init - ts_skip "not root permissions" + ts_skip_nonroot fi . ts-ipcs.sh diff --git a/tests/ts-look-separator b/tests/ts-look-separator index d86e7077..e7772bb4 100755 --- a/tests/ts-look-separator +++ b/tests/ts-look-separator @@ -21,7 +21,7 @@ TS_DESC="separator" ts_init if [ ! -f "/usr/share/dict/words" ]; then - ts_ignore "/usr/share/dict/words not such file" + ts_skip "/usr/share/dict/words not such file" fi touch $TS_OUTPUT diff --git a/tests/ts-mkswap-doit b/tests/ts-mkswap-doit index e4b5b763..b3632b70 100755 --- a/tests/ts-mkswap-doit +++ b/tests/ts-mkswap-doit @@ -24,10 +24,7 @@ TS_COMPONENT="mkswap" TS_DESC="doit" ts_init - -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi +ts_skip_nonroot set -o pipefail diff --git a/tests/ts-mount-move b/tests/ts-mount-move index aa253b75..76400b44 100755 --- a/tests/ts-mount-move +++ b/tests/ts-mount-move @@ -11,10 +11,7 @@ TS_COMPONENT="mount" TS_DESC="move " ts_init - -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi +ts_skip_nonroot touch $TS_OUTPUT diff --git a/tests/ts-mount-mtablock b/tests/ts-mount-mtablock index dc9c8e47..5ef76f2b 100755 --- a/tests/ts-mount-mtablock +++ b/tests/ts-mount-mtablock @@ -7,10 +7,7 @@ TS_COMPONENT="mount" TS_DESC="mtablock" ts_init - -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi +ts_skip_nonroot # # Be careful with number of processes. Don't forget that there is time limit diff --git a/tests/ts-mount-remount b/tests/ts-mount-remount index 16e84582..28064e74 100755 --- a/tests/ts-mount-remount +++ b/tests/ts-mount-remount @@ -11,10 +11,7 @@ TS_COMPONENT="mount" TS_DESC="remount" ts_init - -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi +ts_skip_nonroot # clean up test_cleanup() { diff --git a/tests/ts-mount-special b/tests/ts-mount-special index b2ea77d6..3fb193ea 100755 --- a/tests/ts-mount-special +++ b/tests/ts-mount-special @@ -13,13 +13,10 @@ TS_DESC="special program" MOUNTER="/sbin/mount.mytest" ts_init +ts_skip_nonroot touch $TS_OUTPUT -if [ $UID != 0 ]; then - ts_skip "not root permissions" -fi - cat > $MOUNTER << EOF #!/bin/bash # This util-linux-ng regression test component -- 2.39.5