From b54ab01db86ae58982f2af7705bed5938e4d331a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 8 Nov 2026 15:43:55 -0600 Subject: [PATCH] Add skip_all to runtest.sh plus some minor cleanups. --- scripts/runtest.sh | 12 +++++++++--- tests/chattr.test | 6 +----- tests/chgrp.test | 7 +------ tests/chown.test | 7 +------ tests/du.test | 13 +++---------- tests/groupadd.test | 7 +------ tests/groupdel.test | 7 +------ tests/ifconfig.test | 18 +++--------------- tests/losetup.test | 19 +++---------------- tests/modinfo.test | 9 ++------- tests/nbd-client.test | 7 +------ tests/taskset.test | 8 ++------ tests/useradd.test | 7 +------ 13 files changed, 29 insertions(+), 98 deletions(-) diff --git a/scripts/runtest.sh b/scripts/runtest.sh index 4a10b4e6..ffc66c5a 100644 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -44,6 +44,12 @@ fi # Helper functions +skip_all() +{ + echo "$SHOWSKIP: $CMDNAME ($1)" + exit +} + # Check if VERBOSE= contains a given string. (This allows combining.) verbose_has() { @@ -137,7 +143,7 @@ testing() fi echo -n${RAW-e} "$3" > "$TESTDIR"/expected - [ ! -z "$4" ] && echo -ne "$4" > input || rm -f input + [ ! -z "$4" ] && echo -n${RAW-e} "$4" > input || rm -f input echo -n${RAW-e} "$5" | ${EVAL:-eval --} "$2" > "$TESTDIR"/actual RETVAL=$? @@ -148,7 +154,7 @@ testing() [ -z "$DIFF" ] && do_pass || VERBOSE=all do_fail if ! verbose_has quiet && { [ -n "$DIFF" ] || verbose_has spam; } then - [ ! -z "$4" ] && printf "%s\n" "echo -ne \"$4\" > input" + [ ! -z "$4" ] && echo -ne "$4" > input [ ! -z "$5" ] && printf "%s" "echo -ne '$5' |" printf "%s\n" "$EVAL ${2@Q}" [ -n "$DIFF" ] && printf "%s\n" "$DIFF" @@ -167,7 +173,7 @@ testcmd() { wrong_args "$@" - testing "${1:-$CMDNAME $2}" "\"$C\" $2" "$3" "$4" "$5" + testing "$1" "\"$C\" $2" "$3" "$4" "$5" } utf8locale() diff --git a/tests/chattr.test b/tests/chattr.test index 01549b07..43fd8423 100755 --- a/tests/chattr.test +++ b/tests/chattr.test @@ -4,11 +4,7 @@ #testing "name" "command" "result" "infile" "stdin" -if [ "$(id -u)" -ne 0 ]; then - echo "$SHOWSKIP: chattr (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" function clean() { diff --git a/tests/chgrp.test b/tests/chgrp.test index a137baed..c1662e41 100755 --- a/tests/chgrp.test +++ b/tests/chgrp.test @@ -2,12 +2,7 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: chgrp (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" # We chgrp between "root" and the last group in /etc/group. GRP="$(sed -n '$s/:.*//p' /etc/group)" diff --git a/tests/chown.test b/tests/chown.test index f79d5c1a..0ed806fa 100755 --- a/tests/chown.test +++ b/tests/chown.test @@ -2,12 +2,7 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: chown (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && SKIP_ALL "not root" # We chown between user "root" and the last user in /etc/passwd, # and group "root" and the last group in /etc/group. diff --git a/tests/du.test b/tests/du.test index d7e58b43..8b9468a1 100755 --- a/tests/du.test +++ b/tests/du.test @@ -5,19 +5,12 @@ # ext stores extended attributes in a way that makes all the numbers in the # tests below incorrect. # TODO: include a read-only ext file system that we can mount for the tests? -if [ "$(stat --format %C . 2>/dev/null)" != "?" ]; then - echo "$SHOWSKIP: du (SELinux extended attributes present)" - return 2>/dev/null - exit -fi +[ "$(stat --format %C . 2>/dev/null)" != "?" ] && + skip_all "SELinux extended attributes present" # darwin stores empty directories in the inode itself, making all the numbers # in the tests below 0. (TODO this is not the right fix.) -if [ "$(uname)" == "Darwin" ]; then - echo "$SHOWSKIP: du (Darwin stores empty directories in inode)" - return 2>/dev/null - exit -fi +[ "$(uname)" == "Darwin" ] && skip_all "Darwin stores empty dir in inode" #testing "name" "command" "result" "infile" "stdin" diff --git a/tests/groupadd.test b/tests/groupadd.test index 1ca018d1..09d69a76 100755 --- a/tests/groupadd.test +++ b/tests/groupadd.test @@ -4,12 +4,7 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: groupadd (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" # 70 characters long string; hereafter, we will use it as per our need. _s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" diff --git a/tests/groupdel.test b/tests/groupdel.test index 0bd4d38a..a029c8a1 100755 --- a/tests/groupdel.test +++ b/tests/groupdel.test @@ -5,12 +5,7 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: groupdel (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" # Redirecting all output to /dev/null for grep and delgroup arg="&>/dev/null" diff --git a/tests/ifconfig.test b/tests/ifconfig.test index 150feb97..b44e9197 100755 --- a/tests/ifconfig.test +++ b/tests/ifconfig.test @@ -23,21 +23,9 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: ifconfig (not root)" - return 2>/dev/null - exit -fi - -# Add a dummy interface to test with -modprobe dummy >/dev/null 2>&1 -if ! ifconfig dummy0 up 2>/dev/null -then - echo "$SHOWSKIP: ifconfig dummy0 up failed" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" +modprobe dummy 2>/dev/null +[ ! ifconfig dummy0 up 2>/dev/null ] && skip_all "ifconfig dummy0 up failed" # Results Expected: After calling ifconfig, no lines with dummy0 are displayed testing "Disable the dummy0 interface" \ diff --git a/tests/losetup.test b/tests/losetup.test index 2f72b920..b57adeeb 100755 --- a/tests/losetup.test +++ b/tests/losetup.test @@ -2,25 +2,12 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ]; then - echo "$SHOWSKIP: losetup (not root)" - return 2>/dev/null - exit -fi - -if [ "$(losetup -a | wc -l)" -ne 0 ]; then - echo "$SHOWSKIP: losetup (devices already in use)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" +[ ! -z "$(losetup -a)" ] && skip_all "devices already in use" # Android's loopback devices are only in /dev/block/loop*. # Debian has symlinks like /dev/block/7:0 back to ../loop*. -if [ -b /dev/block/sda ]; then - DIR="/dev/block" # Presumably Android. -else - DIR="/dev" -fi +[ -b /dev/block/sda ] && DIR="/dev/block" || DIR="/dev" #testing "name" "command" "result" "infile" "stdin" diff --git a/tests/modinfo.test b/tests/modinfo.test index be94bcf2..6fddb5b6 100644 --- a/tests/modinfo.test +++ b/tests/modinfo.test @@ -10,17 +10,12 @@ MODULE_ROOT=/vendor/lib/modules [ -d $MODULE_ROOT ] || MODULE_ROOT=/lib/modules/$(uname -r) -no_modules() { - echo "$SHOWSKIP: modinfo (no modules)" - exit -} - -[[ ! -e /proc/modules || ! -d $MODULE_ROOT ]] && no_modules +[[ ! -e /proc/modules || ! -d $MODULE_ROOT ]] && skip_all "no modules" # Find some modules to work with. # Don't need to quote wildcards because test runs in an empty dir. MODULE_PATH1=$(find $MODULE_ROOT -name *.ko | head -1) -[ ! -e "$MODULE_PATH1" ] && no_modules +[ ! -e "$MODULE_PATH1" ] && skip_all "no modules" MODULE1=$(basename -s .ko $MODULE_PATH1) MODULE_PATH2=$(find $MODULE_ROOT -name *.ko | head -2 | tail -1) MODULE2=$(basename -s .ko $MODULE_PATH2) diff --git a/tests/nbd-client.test b/tests/nbd-client.test index f6600c30..65497bb9 100755 --- a/tests/nbd-client.test +++ b/tests/nbd-client.test @@ -4,12 +4,7 @@ #testing "name" "command" "result" "infile" "stdin" -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: nbd-client (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" # Test filesystem images diff --git a/tests/taskset.test b/tests/taskset.test index 73e62d00..70c0c9c4 100755 --- a/tests/taskset.test +++ b/tests/taskset.test @@ -5,12 +5,8 @@ #testing "name" "command" "result" "infile" "stdin" CPUS=$(($(nproc)+0)) -if [ $CPUS -lt 2 ] -then - echo "$SHOWSKIP: taskset (not SMP)" - return 2 > /dev/null - exit -fi +[ $CPUS -lt 2 ] && skip_all "not SMP" + # Masks can be >64 bits but shell bitshifts usually can't MOVER= LOVER= CCNT=$CPUS while [ $CCNT -gt 8 ]; do MOVER+=ff; LOVER+=00; CCNT=$((CCNT-8)); done diff --git a/tests/useradd.test b/tests/useradd.test index 1567f2f1..34894471 100755 --- a/tests/useradd.test +++ b/tests/useradd.test @@ -5,12 +5,7 @@ [ -f testing.sh ] && . testing.sh -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: useradd (not root)" - return 2>/dev/null - exit -fi +[ $UID -ne 0 ] && skip_all "not root" # Redirecting all output to /dev/null for grep, adduser and deluser arg="&>/dev/null" -- 2.39.5