diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh index e7e6371fb6b..a708465bdd5 100755 --- a/test/TEST-13-NSPAWN-SMOKE/test.sh +++ b/test/TEST-13-NSPAWN-SMOKE/test.sh @@ -14,7 +14,7 @@ test_append_files() { # On openSUSE the static linked version of busybox is named "busybox-static". busybox="$(type -P busybox-static || type -P busybox)" - inst_simple "$busybox" "$(dirname $busybox)/busybox" + inst_simple "$busybox" "$(dirname "$busybox")/busybox" if selinuxenabled >/dev/null; then image_install selinuxenabled diff --git a/test/TEST-57-ONSUCCESS-UPHOLD/test.sh b/test/TEST-57-ONSUCCESS-UPHOLD/test.sh index 145c88fcd8d..34513f2ba22 100755 --- a/test/TEST-57-ONSUCCESS-UPHOLD/test.sh +++ b/test/TEST-57-ONSUCCESS-UPHOLD/test.sh @@ -2,6 +2,7 @@ set -e TEST_DESCRIPTION="test OnSuccess= + Uphold= + PropagatesStopTo= + BindsTo=" -. $TEST_BASE_DIR/test-functions +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" do_test "$@" 57 diff --git a/test/TEST-58-REPART/test.sh b/test/TEST-58-REPART/test.sh index 3a3c33f1411..df5ad3c0c61 100755 --- a/test/TEST-58-REPART/test.sh +++ b/test/TEST-58-REPART/test.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash set -e + TEST_DESCRIPTION="test systemd-repart" TEST_NO_NSPAWN=1 -. $TEST_BASE_DIR/test-functions + +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" do_test "$@" diff --git a/test/TEST-59-RELOADING-RESTART/test.sh b/test/TEST-59-RELOADING-RESTART/test.sh index 9232d7816a4..343848e33a6 100755 --- a/test/TEST-59-RELOADING-RESTART/test.sh +++ b/test/TEST-59-RELOADING-RESTART/test.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash set -e -TEST_DESCRIPTION="Test auto restart of exited services which are stuck in reloading state" +TEST_DESCRIPTION="Test auto restart of exited services which are stuck in reloading state" TEST_NO_QEMU=1 -. $TEST_BASE_DIR/test-functions +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" do_test "$@" diff --git a/test/TEST-60-MOUNT-RATELIMIT/test.sh b/test/TEST-60-MOUNT-RATELIMIT/test.sh index f9eb11ccb44..e14bc83e09f 100755 --- a/test/TEST-60-MOUNT-RATELIMIT/test.sh +++ b/test/TEST-60-MOUNT-RATELIMIT/test.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash set -e + TEST_DESCRIPTION="Test that mount/unmount storms can enter/exit rate limit state and will not leak units" -. $TEST_BASE_DIR/test-functions +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" do_test "$@" diff --git a/test/TEST-62-RESTRICT-IFACES/test.sh b/test/TEST-62-RESTRICT-IFACES/test.sh index b2829d2a1fd..85d5a53473e 100755 --- a/test/TEST-62-RESTRICT-IFACES/test.sh +++ b/test/TEST-62-RESTRICT-IFACES/test.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash +set -e +TEST_DESCRIPTION="test RestrictNetworkInterfaces=" TEST_NO_NSPAWN=1 -set -e -TEST_DESCRIPTION="test RestrictNetworkInterfaces=" -. $TEST_BASE_DIR/test-functions +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" -do_test "$@" 62 +do_test "$@" diff --git a/test/hwdb-test.sh b/test/hwdb-test.sh index 57d98e513bf..0551f26a2d9 100755 --- a/test/hwdb-test.sh +++ b/test/hwdb-test.sh @@ -10,7 +10,7 @@ set -e export SYSTEMD_LOG_LEVEL=info -ROOTDIR=$(dirname $(dirname $(readlink -f $0))) +ROOTDIR="$(dirname "$(dirname "$(readlink -f "$0")")")" SYSTEMD_HWDB="${1:?missing argument}" if [ ! -x "$SYSTEMD_HWDB" ]; then @@ -18,7 +18,8 @@ if [ ! -x "$SYSTEMD_HWDB" ]; then exit 1 fi -D=$(mktemp --tmpdir --directory "hwdb-test.XXXXXXXXXX") +D="$(mktemp --tmpdir --directory "hwdb-test.XXXXXXXXXX")" +# shellcheck disable=SC2064 trap "rm -rf '$D'" EXIT INT QUIT PIPE mkdir -p "$D/etc/udev" ln -s "$ROOTDIR/hwdb.d" "$D/etc/udev/hwdb.d" diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index 47cf8a89124..2b48417d583 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -3,7 +3,7 @@ set -e if [ "$NO_BUILD" ]; then BUILD_DIR="" -elif BUILD_DIR="$($(dirname "$0")/../tools/find-build-dir.sh)"; then +elif BUILD_DIR="$("$(dirname "$0")/../tools/find-build-dir.sh")"; then ninja -C "$BUILD_DIR" else echo "No build found, please set BUILD_DIR or NO_BUILD" >&2 @@ -73,35 +73,36 @@ fi # Run actual tests (if requested) if [[ $args =~ [a-z] ]]; then for TEST in $SELECTED_TESTS; do - COUNT=$(($COUNT+1)) + COUNT=$((COUNT+1)) - pass_deny_list $TEST || continue + pass_deny_list "$TEST" || continue start=$(date +%s) echo -e "\n--x-- Running $TEST --x--" set +e + # shellcheck disable=SC2086 ( set -x ; make -C "$TEST" $args ) RESULT=$? set -e echo "--x-- Result of $TEST: $RESULT --x--" results["$TEST"]="$RESULT" - times["$TEST"]=$(( $(date +%s) - $start )) + times["$TEST"]=$(( $(date +%s) - start )) - [ "$RESULT" -ne "0" ] && FAILURES=$(($FAILURES+1)) + [ "$RESULT" -ne "0" ] && FAILURES=$((FAILURES+1)) done fi # Run clean-again, if requested, and if no tests failed -if [ $FAILURES -eq 0 -a $CLEANAGAIN = 1 ]; then - for TEST in ${!results[@]}; do +if [[ $FAILURES -eq 0 && $CLEANAGAIN -eq 1 ]]; then + for TEST in "${!results[@]}"; do ( set -x ; make -C "$TEST" clean-again ) done fi echo "" -for TEST in ${!results[@]}; do +for TEST in "${!results[@]}"; do RESULT="${results[$TEST]}" time="${times[$TEST]}" string=$([ "$RESULT" = "0" ] && echo "SUCCESS" || echo "FAIL") diff --git a/test/test-functions b/test/test-functions index 2d1d15c389c..a9a01a80d0d 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# shellcheck disable=SC2031 +# shellcheck disable=SC2030,SC2031 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh tw=180 # Note: the shellcheck line above disables warning for variables which were @@ -992,9 +992,11 @@ install_iscsi() { # dumps a list of files (perl modules) required by `tgt-admin` at # the runtime plus any DSOs loaded via DynaLoader. This list is then # passed to `inst_simple` which installs the necessary files into the image + # + # shellcheck disable=SC2016 while read -r file; do inst_simple "$file" - done < <(perl -- <(cat $(command -v tgt-admin) <(echo -e 'use DynaLoader; print map { "$_\n" } values %INC; print join("\n", @DynaLoader::dl_shared_objects)')) -p | awk '/^\// { print $1 }') + done < <(perl -- <(cat "$(command -v tgt-admin)" <(echo -e 'use DynaLoader; print map { "$_\n" } values %INC; print join("\n", @DynaLoader::dl_shared_objects)')) -p | awk '/^\// { print $1 }') fi } @@ -1529,7 +1531,7 @@ install_haveged() { dinfo "Install haveged files" inst /usr/sbin/haveged for u in /usr/lib/systemd/system/haveged*; do - inst $u + inst "$u" done fi } @@ -1718,6 +1720,7 @@ install_pam() { done } +# shellcheck disable=SC2120 install_keymaps() { dinfo "Install keymaps" # The first three paths may be deprecated. @@ -2579,7 +2582,7 @@ _test_cleanup() { [[ -n "$initdir" ]] && _umount_dir "$initdir" [[ -n "$IMAGE_PUBLIC" ]] && rm -vf "$IMAGE_PUBLIC" # If multiple setups/cleans are ran in parallel, this can cause a race - if [[ -n "$IMAGESTATEDIR" && $TEST_PARALLELIZE -ne 1 ]]; then + if [[ -n "$IMAGESTATEDIR" && $TEST_PARALLELIZE -ne 1 ]]; then rm -vf "${IMAGESTATEDIR}/default.img" fi [[ -n "$TESTDIR" ]] && rm -vfr "$TESTDIR" diff --git a/test/test-network-generator-conversion.sh b/test/test-network-generator-conversion.sh index 50df69f1b01..da7f985deec 100755 --- a/test/test-network-generator-conversion.sh +++ b/test/test-network-generator-conversion.sh @@ -18,11 +18,13 @@ for f in "$src"/test-*.input; do ( out=$(mktemp --tmpdir --directory "test-network-generator-conversion.XXXXXXXXXX") + # shellcheck disable=SC2064 trap "rm -rf '$out'" EXIT INT QUIT PIPE - $generator --root "$out" -- $(cat $f) + # shellcheck disable=SC2046 + $generator --root "$out" -- $(cat "$f") - if ! diff -u "$out"/run/systemd/network ${f%.input}.expected; then + if ! diff -u "$out/run/systemd/network" "${f%.input}.expected"; then echo "**** Unexpected output for $f" exit 1 fi diff --git a/test/test-path-util/script.sh b/test/test-path-util/script.sh index 57c93e74762..8ffd8d78891 100755 --- a/test/test-path-util/script.sh +++ b/test/test-path-util/script.sh @@ -1,6 +1,6 @@ #!/bin/sh -echo "$0 $@" -test "$(basename $0)" = "script.sh" || exit 1 +echo "$0 $*" +test "$(basename "$0")" = "script.sh" || exit 1 test "$1" = "--version" || exit 2 echo "Life is good" diff --git a/test/testsuite-16.units/extend-timeout.sh b/test/testsuite-16.units/extend-timeout.sh index ed1af8afeb3..c7b26279459 100755 --- a/test/testsuite-16.units/extend-timeout.sh +++ b/test/testsuite-16.units/extend-timeout.sh @@ -1,62 +1,62 @@ #!/usr/bin/env bash -set -x -set -e +set -eux set -o pipefail # sleep interval (seconds) -: ${sleep_interval:=1} +sleep_interval="${sleep_interval:-1}" # extend_timeout_interval second(s) -: ${extend_timeout_interval:=1} +extend_timeout_interval="${extend_timeout_interval:-1}" # number of sleep_intervals before READY=1 -: ${start_intervals:=10} +start_intervals="${start_intervals:-10}" # number of sleep_intervals before exiting -: ${stop_intervals:=10} +stop_intervals="${stop_intervals:-10}" # run intervals, number of sleep_intervals to run -: ${run_intervals:=7} +run_intervals="${run_intervals:-7}" # We convert to usec -extend_timeout_interval=$(( $extend_timeout_interval * 1000000 )) +extend_timeout_interval=$((extend_timeout_interval * 1000000)) -trap "{ touch /${SERVICE}.terminated; exit 1; }" SIGTERM SIGABRT +# shellcheck disable=SC2064 +trap "{ touch /${SERVICE}.terminated; exit 1; }" SIGTERM SIGABRT -rm -f /${SERVICE}.* -touch /${SERVICE}.startfail +rm -f "/${SERVICE}".* +touch "/${SERVICE}.startfail" -systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval -while [ $start_intervals -gt 0 ] +systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval" +while [[ $start_intervals -gt 0 ]] do - sleep $sleep_interval - start_intervals=$(( $start_intervals - 1 )) - systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval + sleep "$sleep_interval" + start_intervals=$((start_intervals - 1)) + systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval" done systemd-notify --ready --status="Waiting for your request" -touch /${SERVICE}.runtimefail -rm /${SERVICE}.startfail +touch "/${SERVICE}.runtimefail" +rm "/${SERVICE}.startfail" -systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval -while [ $run_intervals -gt 0 ] +systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval" +while [[ $run_intervals -gt 0 ]] do - sleep $sleep_interval - run_intervals=$(( $run_intervals - 1 )) - systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval + sleep "$sleep_interval" + run_intervals=$((run_intervals - 1)) + systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval" done systemd-notify STOPPING=1 -touch /${SERVICE}.stopfail -rm /${SERVICE}.runtimefail +touch "/${SERVICE}.stopfail" +rm "/${SERVICE}.runtimefail" -systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval -while [ $stop_intervals -gt 0 ] +systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval" +while [[ $stop_intervals -gt 0 ]] do - sleep $sleep_interval - stop_intervals=$(( $stop_intervals - 1 )) - systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval + sleep "$sleep_interval" + stop_intervals=$((stop_intervals - 1)) + systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval" done -touch /${SERVICE}.success -rm /${SERVICE}.stopfail +touch "/${SERVICE}.success" +rm "/${SERVICE}.stopfail" exit 0 diff --git a/test/udev-dmi-memory-id-test.sh b/test/udev-dmi-memory-id-test.sh index e8b69245d83..f1f4c26caa8 100755 --- a/test/udev-dmi-memory-id-test.sh +++ b/test/udev-dmi-memory-id-test.sh @@ -8,10 +8,11 @@ input="$2" expected="$3" output=$(mktemp --tmpdir "test-udev-dmi-memory-id.XXXXXXXXXX") +# shellcheck disable=SC2064 trap "rm '$output'" EXIT INT QUIT PIPE ( set -x - "$dmi_memory_id" -F "$input" >$output + "$dmi_memory_id" -F "$input" >"$output" diff -u "$output" "$expected" ) diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 4f009b4c456..562f3647009 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -7,7 +7,7 @@ trap "journalctl --rotate --vacuum-size=16M" EXIT # Rotation/flush test, see https://github.com/systemd/systemd/issues/19895 journalctl --relinquish-var -for i in {0..50}; do +for _ in {0..50}; do dd if=/dev/urandom bs=1M count=1 | base64 | systemd-cat done journalctl --rotate @@ -116,7 +116,7 @@ cmp /expected /output # test that LogLevelMax can also suppress logging about services, not only by services systemctl start silent-success journalctl --sync -[[ -z `journalctl -b -q -u silent-success.service` ]] +[[ -z "$(journalctl -b -q -u silent-success.service)" ]] # Add new tests before here, the journald restarts below # may make tests flappy. diff --git a/test/units/testsuite-17.06.sh b/test/units/testsuite-17.06.sh index 71769bc50ae..cd98ed82175 100755 --- a/test/units/testsuite-17.06.sh +++ b/test/units/testsuite-17.06.sh @@ -8,9 +8,9 @@ function check_validity() { local f ID_OR_HANDLE for f in /run/udev/watch/*; do - ID_OR_HANDLE=$(readlink $f) - test -L /run/udev/watch/${ID_OR_HANDLE} - test $(readlink /run/udev/watch/${ID_OR_HANDLE}) = $(basename $f) + ID_OR_HANDLE="$(readlink "$f")" + test -L "/run/udev/watch/${ID_OR_HANDLE}" + test "$(readlink "/run/udev/watch/${ID_OR_HANDLE}")" = "$(basename "$f")" done } @@ -49,7 +49,7 @@ check MAJOR=$(udevadm info /dev/sda | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//') MINOR=$(udevadm info /dev/sda | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//') -test -L /run/udev/watch/b${MAJOR}:${MINOR} +test -L "/run/udev/watch/b${MAJOR}:${MINOR}" cat >/run/udev/rules.d/50-testsuite.rules <