mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 10:13:34 +08:00
test: shellcheck-ify test scripts
This commit is contained in:
parent
91c64ad620
commit
1c3f490f23
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 "$@"
|
||||
|
@ -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 "$@"
|
||||
|
@ -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 "$@"
|
||||
|
@ -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 "$@"
|
||||
|
@ -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"
|
||||
|
@ -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")
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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.
|
||||
|
@ -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 <<EOF
|
||||
ACTION=="change", SUBSYSTEM=="block", KERNEL=="sda", OPTIONS:="nowatch"
|
||||
@ -59,7 +59,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 ! -e /run/udev/watch/b${MAJOR}:${MINOR}
|
||||
test ! -e "/run/udev/watch/b${MAJOR}:${MINOR}"
|
||||
|
||||
rm /run/udev/rules.d/00-debug.rules
|
||||
rm /run/udev/rules.d/50-testsuite.rules
|
||||
|
@ -43,7 +43,7 @@ if systemctl --version | grep -q -- +OPENSSL ; then
|
||||
systemd-creds encrypt --name=test-54 /tmp/test-54-plaintext /tmp/test-54-ciphertext
|
||||
systemd-creds decrypt --name=test-54 /tmp/test-54-ciphertext | cmp /tmp/test-54-plaintext
|
||||
|
||||
systemd-run -p SetCredentialEncrypted=test-54:"`cat /tmp/test-54-ciphertext`" \
|
||||
systemd-run -p SetCredentialEncrypted=test-54:"$(cat /tmp/test-54-ciphertext)" \
|
||||
--wait \
|
||||
--pipe \
|
||||
cat '${CREDENTIALS_DIRECTORY}/test-54' | cmp /tmp/test-54-plaintext
|
||||
|
@ -3,6 +3,7 @@ set -eux
|
||||
set -o pipefail
|
||||
|
||||
TESTS_GLOB="test-loop-block"
|
||||
. $(dirname $0)/testsuite-02.sh
|
||||
# shellcheck source=test/units/testsuite-02.sh
|
||||
. "$(dirname "$0")/testsuite-02.sh"
|
||||
|
||||
exit 0
|
||||
|
@ -6,28 +6,28 @@ setup() {
|
||||
systemd-analyze log-level debug
|
||||
systemd-analyze log-target console
|
||||
|
||||
for i in `seq 0 3`;
|
||||
for i in {0..3};
|
||||
do
|
||||
ip netns del ns${i} || true
|
||||
ip link del veth${i} || true
|
||||
ip netns add ns${i}
|
||||
ip link add veth${i} type veth peer name veth${i}_
|
||||
ip link set veth${i}_ netns ns${i}
|
||||
ip -n ns${i} link set dev veth${i}_ up
|
||||
ip -n ns${i} link set dev lo up
|
||||
ip -n ns${i} addr add "192.168.113."$((4*i+1))/30 dev veth${i}_
|
||||
ip link set dev veth${i} up
|
||||
ip addr add "192.168.113."$((4*i+2))/30 dev veth${i}
|
||||
ip netns del "ns${i}" || true
|
||||
ip link del "veth${i}" || true
|
||||
ip netns add "ns${i}"
|
||||
ip link add "veth${i}" type veth peer name "veth${i}_"
|
||||
ip link set "veth${i}_" netns "ns${i}"
|
||||
ip -n "ns${i}" link set dev "veth${i}_" up
|
||||
ip -n "ns${i}" link set dev lo up
|
||||
ip -n "ns${i}" addr add "192.168.113."$((4*i+1))/30 dev "veth${i}_"
|
||||
ip link set dev "veth${i}" up
|
||||
ip addr add "192.168.113."$((4*i+2))/30 dev "veth${i}"
|
||||
done
|
||||
}
|
||||
|
||||
teardown() {
|
||||
set +e
|
||||
|
||||
for i in `seq 0 3`;
|
||||
for i in {0..3};
|
||||
do
|
||||
ip netns del ns${i}
|
||||
ip link del veth${i}
|
||||
ip netns del "ns${i}"
|
||||
ip link del "veth${i}"
|
||||
done
|
||||
|
||||
systemd-analyze log-level info
|
||||
|
@ -76,6 +76,8 @@ helper_wait_for_pvscan() {
|
||||
# Get major and minor numbers from the udev database
|
||||
# (udevadm returns MAJOR= and MINOR= expressions, so let's pull them into
|
||||
# the current environment via `source` for easier parsing)
|
||||
#
|
||||
# shellcheck source=/dev/null
|
||||
source <(udevadm info -q property "$real_dev" | grep -E "(MAJOR|MINOR)=")
|
||||
# Sanity check if we got correct major and minor numbers
|
||||
test -e "/sys/dev/block/$MAJOR:$MINOR/"
|
||||
|
Loading…
Reference in New Issue
Block a user