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:
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
[[ "$(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
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
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
set -o pipefail
U=/run/systemd/system/test12.socket
-cat <<'EOF' >$U
+cat >$U <<EOF
[Unit]
Description=Test 12 socket
[Socket]
SocketMode=0660
EOF
-cat <<'EOF' >/run/systemd/system/test12@.service
+cat >/run/systemd/system/test12@.service <<EOF
[Unit]
Description=Test service
[Service]
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
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
# 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
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
}
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
}
}
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
}
}
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 \
}
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 \
}
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 \
}
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 \
runas() {
declare userid=$1
shift
+ # shellcheck disable=SC2016
su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@"
}
-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 '
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
}