1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-28 05:57:33 +03:00

test: bunch of assorted tweaks to make shellcheck happy

This commit is contained in:
Frantisek Sumsal 2021-04-09 19:56:12 +02:00
parent 4544002cae
commit 84031b5d6e
12 changed files with 66 additions and 54 deletions

View File

@ -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

View File

@ -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

View File

@ -2,30 +2,30 @@
set -eux
set -o pipefail
>/failed
: >/failed
cat <<'EOL' >/lib/systemd/system/my.service
cat >/lib/systemd/system/my.service <<EOF
[Service]
Type=oneshot
ExecStart=/bin/echo Timer runs me
EOL
EOF
cat <<'EOL' >/lib/systemd/system/my.timer
cat >/lib/systemd/system/my.timer <<EOF
[Timer]
OnBootSec=10s
OnUnitInactiveSec=1h
EOL
EOF
systemctl unmask my.timer
systemctl start my.timer
mkdir -p /etc/systemd/system/my.timer.d/
cat <<'EOL' >/etc/systemd/system/my.timer.d/override.conf
cat >/etc/systemd/system/my.timer.d/override.conf <<EOF
[Timer]
OnBootSec=10s
OnUnitInactiveSec=1h
EOL
EOF
systemctl daemon-reload

View File

@ -2,7 +2,7 @@
set -eux
set -o pipefail
systemctl start fail-on-restart.service
systemctl --no-block start fail-on-restart.service
active_state=$(systemctl show --value --property ActiveState fail-on-restart.service)
while [[ "$active_state" == "activating" || "$active_state" == "active" ]]; do
sleep 1

View File

@ -3,7 +3,7 @@ set -eux
set -o pipefail
U=/run/systemd/system/test12.socket
cat <<'EOF' >$U
cat >$U <<EOF
[Unit]
Description=Test 12 socket
[Socket]
@ -13,7 +13,7 @@ SocketGroup=adm
SocketMode=0660
EOF
cat <<'EOF' >/run/systemd/system/test12@.service
cat >/run/systemd/system/test12@.service <<EOF
[Unit]
Description=Test service
[Service]

View File

@ -27,7 +27,7 @@ run_test() {
echo add >/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

View File

@ -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

View File

@ -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

View File

@ -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" <<EOF
[Manager]
NUMAPolicy=${1:?missing argument: NUMAPolicy}
NUMAMask=${2:-""}
EOF
}
writeTestUnit() {
mkdir -p $testUnitFile.d/
echo [Service] >$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" <<EOF
[Service]
NUMAPolicy=${1:?missing argument: NUMAPolicy}
NUMAMask=${2:-""}
EOF
systemctl daemon-reload
}

View File

@ -14,11 +14,11 @@ start_test_service() {
}
dbus_freeze() {
local suffix=
suffix="${1##*.}"
local name object_path suffix
local name="$(echo ${1%.$suffix} | sed s/-/_2d/g)"
local object_path="/org/freedesktop/systemd1/unit/${name}_2e${suffix}"
suffix="${1##*.}"
name="${1%.$suffix}"
object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
busctl call \
org.freedesktop.systemd1 \
@ -28,11 +28,11 @@ dbus_freeze() {
}
dbus_thaw() {
local suffix=
suffix="${1##*.}"
local name object_path suffix
local name="$(echo ${1%.$suffix} | sed s/-/_2d/g)"
local object_path="/org/freedesktop/systemd1/unit/${name}_2e${suffix}"
suffix="${1##*.}"
name="${1%.$suffix}"
object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
busctl call \
org.freedesktop.systemd1 \
@ -62,11 +62,11 @@ dbus_thaw_unit() {
}
dbus_can_freeze() {
local suffix=
suffix="${1##*.}"
local name object_path suffix
local name="$(echo ${1%.$suffix} | sed s/-/_2d/g)"
local object_path="/org/freedesktop/systemd1/unit/${name}_2e${suffix}"
suffix="${1##*.}"
name="${1%.$suffix}"
object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
busctl get-property \
org.freedesktop.systemd1 \
@ -76,11 +76,11 @@ dbus_can_freeze() {
}
check_freezer_state() {
local suffix=
suffix="${1##*.}"
local name object_path suffix
local name="$(echo ${1%.$suffix} | sed s/-/_2d/g)"
local object_path="/org/freedesktop/systemd1/unit/${name}_2e${suffix}"
suffix="${1##*.}"
name="${1%.$suffix}"
object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
state=$(busctl get-property \
org.freedesktop.systemd1 \

View File

@ -7,6 +7,7 @@ systemd-analyze log-level debug
runas() {
declare userid=$1
shift
# shellcheck disable=SC2016
su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@"
}
@ -46,6 +47,7 @@ runas testuser systemd-run --wait --user --unit=test-protect-home-tmpfs \
-P test ! -e /home/testuser
# Confirm that home, /root, and /run/user are inaccessible under "yes"
# shellcheck disable=SC2016
runas testuser systemd-run --wait --user --unit=test-protect-home-yes \
-p PrivateUsers=yes -p ProtectHome=yes \
-P bash -c '

View File

@ -5,24 +5,26 @@ set -eu
set -o pipefail
PAGE_SIZE=$(getconf PAGE_SIZE)
BLOAT_ITERATION_TARGET=$(( 100 << 20 )) # 100 MB
BLOAT_ITERATION_TARGET=$((100 << 20)) # 100 MB
BLOAT_HOLDER=()
PID="$$"
function bloat {
local set_size mem_usage target_mem_size
set_size=$(cut -d " " -f2 "/proc/$PID/statm")
mem_usage=$(( "$set_size" * "$PAGE_SIZE" ))
target_mem_size=$(( "$mem_usage" + "$1" ))
# Following `| cat` weirdness is intentional to generate some reclaim
# activity in case there's no swap available.
set_size=$(cut -d " " -f2 "/proc/$PID/statm" | cat)
mem_usage=$((set_size * PAGE_SIZE))
target_mem_size=$((mem_usage + $1))
BLOAT_HOLDER=()
while [[ "$mem_usage" -lt "$target_mem_size" ]]; do
echo "target $target_mem_size"
echo "mem usage $mem_usage"
BLOAT_HOLDER+=("$(printf "=%0.s" {1..1000000})")
set_size=$(cut -d " " -f2 "/proc/$PID/statm")
mem_usage=$(("$set_size" * "$PAGE_SIZE"))
set_size=$(cut -d " " -f2 "/proc/$PID/statm" | cat)
mem_usage=$((set_size * PAGE_SIZE))
done
}