From: Frantisek Sumsal Date: Fri, 9 Apr 2021 17:56:12 +0000 (+0200) Subject: test: bunch of assorted tweaks to make shellcheck happy X-Git-Tag: v249-rc1~417^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=84031b5d6e26e77192e1aebeb12aab93f0ce894b;p=thirdparty%2Fsystemd.git test: bunch of assorted tweaks to make shellcheck happy --- diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index ea4efda70bd..da02304a32a 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -4,10 +4,10 @@ set -o pipefail NPROC=$(nproc) MAX_QUEUE_SIZE=${NPROC:-2} -IFS=$'\n' TEST_LIST=($(ls /usr/lib/systemd/tests/test-*)) +mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/ -maxdepth 1 -type f -name "test-*") # reset state -rm /failed-tests /skipped-tests /skipped +rm -fv /failed-tests /skipped-tests /skipped # Check & report test results # Arguments: @@ -56,8 +56,7 @@ for task in "${TEST_LIST[@]}"; do for key in "${!running[@]}"; do if ! kill -0 "${running[$key]}" &>/dev/null; then # Task has finished, report its result and drop it from the queue - wait "${running[$key]}" - ec=$? + wait "${running[$key]}" && ec=0 || ec=$? report_result "$key" $ec unset running["$key"] # Break from inner for loop and outer while loop to skip diff --git a/test/units/testsuite-05.sh b/test/units/testsuite-05.sh index f899fcaa4f6..c98d849b08a 100755 --- a/test/units/testsuite-05.sh +++ b/test/units/testsuite-05.sh @@ -18,7 +18,9 @@ systemctl daemon-reload [[ "$(systemctl show -P LimitNOFILESoft testsuite-05.service)" = "10000" ]] [[ "$(systemctl show -P LimitNOFILE testsuite-05.service)" = "16384" ]] +# shellcheck disable=SC2016 systemd-run --wait -t bash -c '[[ "$(ulimit -n -S)" = "10000" ]]' +# shellcheck disable=SC2016 systemd-run --wait -t bash -c '[[ "$(ulimit -n -H)" = "16384" ]]' touch /testok diff --git a/test/units/testsuite-07.sh b/test/units/testsuite-07.sh index c63394e68cd..bd1da341acb 100755 --- a/test/units/testsuite-07.sh +++ b/test/units/testsuite-07.sh @@ -2,30 +2,30 @@ set -eux set -o pipefail ->/failed +: >/failed -cat <<'EOL' >/lib/systemd/system/my.service +cat >/lib/systemd/system/my.service </lib/systemd/system/my.timer +cat >/lib/systemd/system/my.timer </etc/systemd/system/my.timer.d/override.conf +cat >/etc/systemd/system/my.timer.d/override.conf <$U +cat >$U </run/systemd/system/test12@.service +cat >/run/systemd/system/test12@.service </sys/class/net/lo/uevent - for n in {1..20}; do + for _ in {1..20}; do sleep 5 if coredumpctl --since "$since" --no-legend --no-pager | grep /bin/udevadm ; then return 0 diff --git a/test/units/testsuite-25.sh b/test/units/testsuite-25.sh index 05448efb0ac..fbe2d0b1d4d 100755 --- a/test/units/testsuite-25.sh +++ b/test/units/testsuite-25.sh @@ -120,6 +120,7 @@ test ! -f /var/lib/machines/scratch4 machinectl image-status scratch4 && { echo 'unexpected success'; exit 1; } # Test import-tar hyphen/stdin pipe behavior +# shellcheck disable=SC2002 cat /var/tmp/scratch.tar.gz | machinectl import-tar - scratch5 test -d /var/lib/machines/scratch5 machinectl image-status scratch5 diff --git a/test/units/testsuite-32.sh b/test/units/testsuite-32.sh index a025b73a042..2393601a007 100755 --- a/test/units/testsuite-32.sh +++ b/test/units/testsuite-32.sh @@ -9,7 +9,6 @@ set -o pipefail # kernels where the concept was still new. if test -f /sys/fs/cgroup/system.slice/testsuite-32.service/memory.oom.group; then - systemd-analyze log-level debug systemd-analyze log-target console diff --git a/test/units/testsuite-36.sh b/test/units/testsuite-36.sh index 6d3713c9623..94fd927a5d1 100755 --- a/test/units/testsuite-36.sh +++ b/test/units/testsuite-36.sh @@ -3,11 +3,12 @@ set -eux set -o pipefail at_exit() { - if [ $? -ne 0 ]; then + # shellcheck disable=SC2181 + if [[ $? -ne 0 ]]; then # We're exiting with a non-zero EC, let's dump test artifacts # for easier debugging - [ -f "$straceLog" ] && cat "$straceLog" - [ -f "$journalLog" ] && cat "$journalLog" + [[ -v straceLog && -f "$straceLog" ]] && cat "$straceLog" + [[ -v journalLog && -f "$journalLog" ]] && cat "$journalLog" fi } @@ -26,25 +27,28 @@ testUnitFile="/run/systemd/system/$testUnit" testUnitNUMAConf="$testUnitFile.d/numa.conf" # Sleep constants (we should probably figure out something better but nothing comes to mind) -journalSleep=5 sleepAfterStart=1 # Journal cursor for easier navigation journalCursorFile="jounalCursorFile" startStrace() { - coproc strace -qq -p 1 -o $straceLog -e set_mempolicy -s 1024 $1 + coproc strace -qq -p 1 -o "$straceLog" -e set_mempolicy -s 1024 ${1:+"$1"} # Wait for strace to properly "initialize" sleep $sleepAfterStart } stopStrace() { - kill -s TERM $COPROC_PID + [[ -v COPROC_PID ]] || return + + local PID=$COPROC_PID + kill -s TERM "$PID" # Make sure the strace process is indeed dead - while kill -0 $COPROC_PID 2>/dev/null; do sleep 0.1; done + while kill -0 "$PID" 2>/dev/null; do sleep 0.1; done } startJournalctl() { + : >"$journalCursorFile" # Save journal's cursor for later navigation journalctl --no-pager --cursor-file="$journalCursorFile" -n0 -ocat } @@ -64,21 +68,24 @@ checkNUMA() { } writePID1NUMAPolicy() { - echo [Manager] >$confDir/numa.conf - echo NUMAPolicy=$1 >>$confDir/numa.conf - echo NUMAMask=$2 >>$confDir/numa.conf + cat >"$confDir/numa.conf" <$testUnitFile - echo ExecStart=/bin/sleep 3600 >>$testUnitFile + mkdir -p "$testUnitFile.d/" + printf "[Service]\nExecStart=/bin/sleep 3600\n" >"$testUnitFile" } writeTestUnitNUMAPolicy() { - echo [Service] >$testUnitNUMAConf - echo NUMAPolicy=$1 >>$testUnitNUMAConf - echo NUMAMask=$2 >>$testUnitNUMAConf + cat >"$testUnitNUMAConf" <