From 084575ff91e4291e1659ddfb6f2b74d10adc5fb0 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:39:41 +0200 Subject: [PATCH 1/7] test: use set -eux and set -o pipefail everywhere This should make the scripts more robust. --- test/units/testsuite-02.sh | 4 ++-- test/units/testsuite-03.sh | 3 ++- test/units/testsuite-04.sh | 3 +-- test/units/testsuite-05.sh | 3 +-- test/units/testsuite-06.sh | 3 +-- test/units/testsuite-07.sh | 4 ++-- test/units/testsuite-11.sh | 3 ++- test/units/testsuite-12.sh | 3 +-- test/units/testsuite-13.sh | 5 ++--- test/units/testsuite-14.sh | 4 ++-- test/units/testsuite-15.sh | 6 +++--- test/units/testsuite-16.sh | 3 ++- test/units/testsuite-17.sh | 4 ++-- test/units/testsuite-18.sh | 2 +- test/units/testsuite-19.sh | 2 +- test/units/testsuite-20.sh | 2 +- test/units/testsuite-22.01.sh | 5 +++-- test/units/testsuite-22.02.sh | 6 +++--- test/units/testsuite-22.03.sh | 6 +++--- test/units/testsuite-22.04.sh | 6 +++--- test/units/testsuite-22.05.sh | 4 ++-- test/units/testsuite-22.06.sh | 5 +++-- test/units/testsuite-22.07.sh | 6 +++--- test/units/testsuite-22.08.sh | 5 +++-- test/units/testsuite-22.09.sh | 4 ++-- test/units/testsuite-22.10.sh | 3 +-- test/units/testsuite-22.sh | 4 ++-- test/units/testsuite-23.sh | 2 +- test/units/testsuite-25.sh | 2 +- test/units/testsuite-26.sh | 2 +- test/units/testsuite-27.sh | 2 +- test/units/testsuite-29.sh | 2 +- test/units/testsuite-30.sh | 2 +- test/units/testsuite-31.sh | 2 +- test/units/testsuite-32.sh | 2 +- test/units/testsuite-33.sh | 2 +- test/units/testsuite-34.sh | 2 +- test/units/testsuite-36.sh | 2 +- test/units/testsuite-37.sh | 2 +- test/units/testsuite-38.sh | 2 +- test/units/testsuite-39.sh | 2 +- test/units/testsuite-40.sh | 2 +- test/units/testsuite-41.sh | 2 +- test/units/testsuite-42.sh | 2 +- test/units/testsuite-43.sh | 2 +- test/units/testsuite-44.sh | 2 +- test/units/testsuite-46.sh | 2 +- test/units/testsuite-47.sh | 2 +- test/units/testsuite-48.sh | 2 +- test/units/testsuite-49.sh | 2 +- test/units/testsuite-50.sh | 2 +- test/units/testsuite-51.sh | 2 +- test/units/testsuite-53.sh | 2 +- test/units/testsuite-54.sh | 3 ++- test/units/testsuite-55-slowgrowth.sh | 5 ++++- test/units/testsuite-55.sh | 2 +- test/units/testsuite-56.sh | 2 +- 57 files changed, 88 insertions(+), 84 deletions(-) diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index 1ff1c3347b..b0807c9d8a 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -#set -ex -#set -o pipefail +set -eux +set -o pipefail NPROC=$(nproc) MAX_QUEUE_SIZE=${NPROC:-2} diff --git a/test/units/testsuite-03.sh b/test/units/testsuite-03.sh index 5a2dadd6b8..82858f0c8e 100755 --- a/test/units/testsuite-03.sh +++ b/test/units/testsuite-03.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -ex +set -eux +set -o pipefail # Test merging of a --job-mode=ignore-dependencies job into a previously # installed job. diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index a2a1292380..0969a8313e 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -set -x -set -e +set -eux set -o pipefail # Test stdout stream diff --git a/test/units/testsuite-05.sh b/test/units/testsuite-05.sh index 9168e72799..f899fcaa4f 100755 --- a/test/units/testsuite-05.sh +++ b/test/units/testsuite-05.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -set -x -set -e +set -eux set -o pipefail P=/run/systemd/system.conf.d diff --git a/test/units/testsuite-06.sh b/test/units/testsuite-06.sh index f9b106da7b..f89698ded4 100755 --- a/test/units/testsuite-06.sh +++ b/test/units/testsuite-06.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -set -x -set -e +set -eux set -o pipefail echo 1 >/sys/fs/selinux/enforce || { diff --git a/test/units/testsuite-07.sh b/test/units/testsuite-07.sh index fbb2d1d30a..c63394e68c 100755 --- a/test/units/testsuite-07.sh +++ b/test/units/testsuite-07.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -x -set -e +set -eux +set -o pipefail >/failed diff --git a/test/units/testsuite-11.sh b/test/units/testsuite-11.sh index 708c7cebb7..3ec391f6e6 100755 --- a/test/units/testsuite-11.sh +++ b/test/units/testsuite-11.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -x +set -eux +set -o pipefail systemctl start fail-on-restart.service active_state=$(systemctl show --value --property ActiveState fail-on-restart.service) diff --git a/test/units/testsuite-12.sh b/test/units/testsuite-12.sh index 7e7b0ec25a..a02f38c488 100755 --- a/test/units/testsuite-12.sh +++ b/test/units/testsuite-12.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -set -x -set -e +set -eux set -o pipefail U=/run/systemd/system/test12.socket diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index 3e66aa9d54..03b1bc3971 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -set -x -set -e -set -u +# shellcheck disable=SC2016 +set -eux set -o pipefail export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-14.sh b/test/units/testsuite-14.sh index 95ac9b65ae..6eecf916a2 100755 --- a/test/units/testsuite-14.sh +++ b/test/units/testsuite-14.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e -set -x +set -eux +set -o pipefail function setup_root { local _root="$1" diff --git a/test/units/testsuite-15.sh b/test/units/testsuite-15.sh index fc392c584d..018ae8aab9 100755 --- a/test/units/testsuite-15.sh +++ b/test/units/testsuite-15.sh @@ -1,6 +1,6 @@ -#! /bin/bash -set -e -set -x +#!/bin/bash +set -eux +set -o pipefail _clear_service () { systemctl stop $1.service 2>/dev/null || : diff --git a/test/units/testsuite-16.sh b/test/units/testsuite-16.sh index 8388ef7a5d..8d2117b4cf 100755 --- a/test/units/testsuite-16.sh +++ b/test/units/testsuite-16.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -v -x +set -eux +set -o pipefail rm -f /test.log diff --git a/test/units/testsuite-17.sh b/test/units/testsuite-17.sh index afce85aceb..3cf57550fc 100755 --- a/test/units/testsuite-17.sh +++ b/test/units/testsuite-17.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -x -set -e +set -eux +set -o pipefail >/failed diff --git a/test/units/testsuite-18.sh b/test/units/testsuite-18.sh index c4e3ca2110..fe4f9ce5e0 100755 --- a/test/units/testsuite-18.sh +++ b/test/units/testsuite-18.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemd-run --wait -p FailureAction=poweroff true diff --git a/test/units/testsuite-19.sh b/test/units/testsuite-19.sh index dea2f4ba1f..8ea89e6cfe 100755 --- a/test/units/testsuite-19.sh +++ b/test/units/testsuite-19.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail if grep -q cgroup2 /proc/filesystems ; then diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index 6003e4f181..56f07933a9 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemd-analyze log-level debug diff --git a/test/units/testsuite-22.01.sh b/test/units/testsuite-22.01.sh index b10b5aaa1a..7975980799 100755 --- a/test/units/testsuite-22.01.sh +++ b/test/units/testsuite-22.01.sh @@ -1,10 +1,11 @@ -#! /bin/bash +#!/bin/bash # # With "e" don't attempt to set permissions when file doesn't exist, see # https://github.com/systemd/systemd/pull/6682. # -set -e +set -eux +set -o pipefail rm -fr /tmp/test diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh index c337cd6e05..5d1254db03 100755 --- a/test/units/testsuite-22.02.sh +++ b/test/units/testsuite-22.02.sh @@ -1,10 +1,10 @@ -#! /bin/bash +#!/bin/bash # # Basic tests for types creating directories # -set -e -set -x +set -eux +set -o pipefail rm -fr /tmp/{C,d,D,e} mkdir /tmp/{C,d,D,e} diff --git a/test/units/testsuite-22.03.sh b/test/units/testsuite-22.03.sh index c905784bee..bb321c1c2f 100755 --- a/test/units/testsuite-22.03.sh +++ b/test/units/testsuite-22.03.sh @@ -1,10 +1,10 @@ -#! /bin/bash +#!/bin/bash # # Basic tests for types creating/writing files # -set -e -set -x +set -eux +set -o pipefail rm -fr /tmp/{f,F,w} mkdir /tmp/{f,F,w} diff --git a/test/units/testsuite-22.04.sh b/test/units/testsuite-22.04.sh index fc90ab4dc7..3298aa04ed 100755 --- a/test/units/testsuite-22.04.sh +++ b/test/units/testsuite-22.04.sh @@ -1,10 +1,10 @@ -#! /bin/bash +#!/bin/bash # # Basic tests for types creating fifos # -set -e -set -x +set -eux +set -o pipefail rm -fr /tmp/p mkdir /tmp/p diff --git a/test/units/testsuite-22.05.sh b/test/units/testsuite-22.05.sh index 13c4ac80fc..a1820089c0 100755 --- a/test/units/testsuite-22.05.sh +++ b/test/units/testsuite-22.05.sh @@ -1,7 +1,7 @@ #! /bin/bash -set -e -set -x +set -eux +set -o pipefail rm -fr /tmp/{z,Z} mkdir /tmp/{z,Z} diff --git a/test/units/testsuite-22.06.sh b/test/units/testsuite-22.06.sh index 8ce0a08f68..ce5b1bf698 100755 --- a/test/units/testsuite-22.06.sh +++ b/test/units/testsuite-22.06.sh @@ -1,9 +1,10 @@ -#! /bin/bash +#!/bin/bash # # Inspired by https://github.com/systemd/systemd/issues/9508 # -set -e +set -eux +set -o pipefail test_snippet() { systemd-tmpfiles "$@" - </failed diff --git a/test/units/testsuite-23.sh b/test/units/testsuite-23.sh index a215237562..c66ed26229 100755 --- a/test/units/testsuite-23.sh +++ b/test/units/testsuite-23.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemd-analyze log-level debug diff --git a/test/units/testsuite-25.sh b/test/units/testsuite-25.sh index d4d2e0f953..05448efb0a 100755 --- a/test/units/testsuite-25.sh +++ b/test/units/testsuite-25.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail export SYSTEMD_PAGER=cat diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh index 9c1abc5916..7982099307 100755 --- a/test/units/testsuite-26.sh +++ b/test/units/testsuite-26.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail # Make sure PATH is set diff --git a/test/units/testsuite-27.sh b/test/units/testsuite-27.sh index 0e9ffe1189..2248380351 100755 --- a/test/units/testsuite-27.sh +++ b/test/units/testsuite-27.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemd-analyze log-level debug diff --git a/test/units/testsuite-29.sh b/test/units/testsuite-29.sh index 4e91aa7336..3408e6d71a 100755 --- a/test/units/testsuite-29.sh +++ b/test/units/testsuite-29.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh -set -ex +set -eux set -o pipefail export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-30.sh b/test/units/testsuite-30.sh index cb3b46d2cb..ac8a3e06cf 100755 --- a/test/units/testsuite-30.sh +++ b/test/units/testsuite-30.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemd-analyze log-level debug diff --git a/test/units/testsuite-31.sh b/test/units/testsuite-31.sh index 42873bfd83..a9a50e1470 100755 --- a/test/units/testsuite-31.sh +++ b/test/units/testsuite-31.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -eux set -o pipefail if journalctl -b -t systemd --grep '\.device: Changed plugged -> dead'; then diff --git a/test/units/testsuite-32.sh b/test/units/testsuite-32.sh index c1704ab34e..d7827090bb 100755 --- a/test/units/testsuite-32.sh +++ b/test/units/testsuite-32.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail # Let's run this test only if the "memory.oom.group" cgroupfs attribute diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index 929c76062b..6e750f63a3 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh -set -ex +set -eux set -o pipefail cat >/etc/systemd/system/testservice.service </run/systemd/system/testservice-48.target </run/testservice-49-fixed mkdir -p /run/inaccessible diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh index b3c120d9a6..8067997a9d 100755 --- a/test/units/testsuite-50.sh +++ b/test/units/testsuite-50.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh -set -ex +set -eux set -o pipefail export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-51.sh b/test/units/testsuite-51.sh index 246412a079..06bc1602f8 100755 --- a/test/units/testsuite-51.sh +++ b/test/units/testsuite-51.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemctl start testsuite-51-repro-1 diff --git a/test/units/testsuite-53.sh b/test/units/testsuite-53.sh index 3536c24271..298d5d50eb 100755 --- a/test/units/testsuite-53.sh +++ b/test/units/testsuite-53.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail >/failed diff --git a/test/units/testsuite-54.sh b/test/units/testsuite-54.sh index d145d7e33e..f8ddff4a30 100755 --- a/test/units/testsuite-54.sh +++ b/test/units/testsuite-54.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -ex +# shellcheck disable=SC2016 +set -eux systemd-analyze log-level debug diff --git a/test/units/testsuite-55-slowgrowth.sh b/test/units/testsuite-55-slowgrowth.sh index ff5a747348..ed4ec6d6e4 100755 --- a/test/units/testsuite-55-slowgrowth.sh +++ b/test/units/testsuite-55-slowgrowth.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash -set -eu -o pipefail +# Don't use set -x here, since it generates a lot of output and slows +# the script down, causing unexpected test fails. +set -eu +set -o pipefail PAGE_SIZE=$(getconf PAGE_SIZE) BLOAT_ITERATION_TARGET=$(( 100 << 20 )) # 100 MB diff --git a/test/units/testsuite-55.sh b/test/units/testsuite-55.sh index d73f4b1e7a..25c7f8cc63 100755 --- a/test/units/testsuite-55.sh +++ b/test/units/testsuite-55.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux set -o pipefail systemd-analyze log-level debug diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh index 079da07201..27bd3ca8f7 100755 --- a/test/units/testsuite-56.sh +++ b/test/units/testsuite-56.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -eux systemd-analyze log-level debug From 38825267983a439f2cf8375463b1edc9ca2d3323 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:49:32 +0200 Subject: [PATCH 2/7] test: use quotes where necessary to avoid possible word splitting. --- test/TEST-50-DISSECT/test.sh | 1 + test/units/testsuite-02.sh | 4 +- test/units/testsuite-13.sh | 2 +- test/units/testsuite-14.sh | 10 +- test/units/testsuite-15.sh | 44 +++--- test/units/testsuite-16.sh | 29 ++-- test/units/testsuite-17.sh | 4 +- test/units/testsuite-20.sh | 2 +- test/units/testsuite-22.02.sh | 26 ++-- test/units/testsuite-22.03.sh | 20 +-- test/units/testsuite-22.04.sh | 4 +- test/units/testsuite-22.05.sh | 18 +-- test/units/testsuite-22.sh | 4 +- test/units/testsuite-23.sh | 4 +- test/units/testsuite-36.sh | 197 +++++++++++++------------- test/units/testsuite-39.sh | 30 ++-- test/units/testsuite-46.sh | 5 +- test/units/testsuite-50.sh | 155 ++++++++++---------- test/units/testsuite-55-slowgrowth.sh | 18 +-- test/units/testsuite-55.sh | 13 +- 20 files changed, 301 insertions(+), 289 deletions(-) diff --git a/test/TEST-50-DISSECT/test.sh b/test/TEST-50-DISSECT/test.sh index 9d42e4891c..86a4f079bb 100755 --- a/test/TEST-50-DISSECT/test.sh +++ b/test/TEST-50-DISSECT/test.sh @@ -23,6 +23,7 @@ test_append_files() { install_dmevent generate_module_dependencies inst_binary losetup + inst_binary wc install_verity_minimal ) } diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index b0807c9d8a..ea4efda70b 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -54,9 +54,9 @@ for task in "${TEST_LIST[@]}"; do # until one of the tasks finishes, so we can replace it. while [[ ${#running[@]} -ge $MAX_QUEUE_SIZE ]]; do for key in "${!running[@]}"; do - if ! kill -0 ${running[$key]} &>/dev/null; then + if ! kill -0 "${running[$key]}" &>/dev/null; then # Task has finished, report its result and drop it from the queue - wait ${running[$key]} + wait "${running[$key]}" ec=$? report_result "$key" $ec unset running["$key"] diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index 03b1bc3971..d93cc7b145 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -112,7 +112,7 @@ EOF sleep 0.1 done - return $(systemctl show -P ExecMainStatus nspawn_machinectl_bind.service) + return "$(systemctl show -P ExecMainStatus nspawn_machinectl_bind.service)" } function run { diff --git a/test/units/testsuite-14.sh b/test/units/testsuite-14.sh index 6eecf916a2..7a64d93736 100755 --- a/test/units/testsuite-14.sh +++ b/test/units/testsuite-14.sh @@ -21,18 +21,18 @@ r="$(pwd)/overwrite-broken-machine-id" setup_root "$r" systemd-machine-id-setup --print --root "$r" echo abc >>"$r/etc/machine-id" -id=$(systemd-machine-id-setup --print --root "$r") -echo $id >expected +id="$(systemd-machine-id-setup --print --root "$r")" +echo "$id" >expected check expected "$r/etc/machine-id" -r="$(pwd)/transient-machine-id" +r="$PWD/transient-machine-id" setup_root "$r" systemd-machine-id-setup --print --root "$r" echo abc >>"$r/etc/machine-id" mount -o remount,ro "$r" mount -t tmpfs tmpfs "$r/run" -transient_id=$(systemd-machine-id-setup --print --root "$r") +transient_id="$(systemd-machine-id-setup --print --root "$r")" mount -o remount,rw "$r" -commited_id=$(systemd-machine-id-setup --print --commit --root "$r") +commited_id="$(systemd-machine-id-setup --print --commit --root "$r")" [[ "$transient_id" = "$commited_id" ]] check "$r/etc/machine-id" "$r/run/machine-id" diff --git a/test/units/testsuite-15.sh b/test/units/testsuite-15.sh index 018ae8aab9..23c2156501 100755 --- a/test/units/testsuite-15.sh +++ b/test/units/testsuite-15.sh @@ -3,51 +3,53 @@ set -eux set -o pipefail _clear_service () { - systemctl stop $1.service 2>/dev/null || : - rm -f /{etc,run,usr/lib}/systemd/system/$1.service - rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.d - rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.{wants,requires} - if [[ $1 == *@ ]]; then - systemctl stop $1*.service 2>/dev/null || : - rm -f /{etc,run,usr/lib}/systemd/system/$1*.service - rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.d - rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.{wants,requires} + local SERVICE_NAME="${1:?_clear_service: missing argument}" + systemctl stop "$SERVICE_NAME.service" 2>/dev/null || : + rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service + rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d + rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{wants,requires} + if [[ $SERVICE_NAME == *@ ]]; then + systemctl stop "$SERVICE_NAME"*.service 2>/dev/null || : + rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service + rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.d + rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.{wants,requires} fi } clear_services () { - for u in $*; do - _clear_service $u + for u in "$@"; do + _clear_service "$u" done systemctl daemon-reload } create_service () { - clear_services $1 + local SERVICE_NAME="${1:?create_service: missing argument}" + clear_services "$SERVICE_NAME" - cat >/etc/systemd/system/$1.service</etc/systemd/system/"$SERVICE_NAME".service <> "${TL}" + if [[ ! -f /${service}.${result} ]]; then + journalctl -u "${service/_/-}.service" >>"$TESTLOG" fi } @@ -45,12 +43,11 @@ wait_for fail_start startfail wait_for fail_stop stopfail wait_for fail_runtime runtimefail -if [[ -f "${TL}" ]] -then +if [[ -f "$TESTLOG" ]]; then # no mv - cp "${TL}" /test.log + cp "$TESTLOG" /test.log exit 1 -else - touch /testok - exit 0 fi + +touch /testok +exit 0 diff --git a/test/units/testsuite-17.sh b/test/units/testsuite-17.sh index 3cf57550fc..2ec9f6a891 100755 --- a/test/units/testsuite-17.sh +++ b/test/units/testsuite-17.sh @@ -5,8 +5,8 @@ set -o pipefail >/failed -for t in ${0%.sh}.*.sh; do - echo "Running $t"; ./$t +for t in "${0%.sh}".*.sh; do + echo "Running $t"; ./"$t" done touch /testok diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index 56f07933a9..111713dabf 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -140,7 +140,7 @@ systemd-run --unit=test20-mainpidsh3.service \ && { echo 'unexpected success'; exit 1; } # Test that this failed due to timeout, and not some other error -test $(systemctl show -P Result test20-mainpidsh3.service) = timeout +test "$(systemctl show -P Result test20-mainpidsh3.service)" = timeout systemd-analyze log-level info diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh index 5d1254db03..94fa11ba88 100755 --- a/test/units/testsuite-22.02.sh +++ b/test/units/testsuite-22.02.sh @@ -21,10 +21,10 @@ d /tmp/d/2 0755 daemon daemon - - EOF test -d /tmp/d/1 -test $(stat -c %U:%G:%a /tmp/d/1) = "daemon:daemon:755" +test "$(stat -c %U:%G:%a /tmp/d/1)" = "daemon:daemon:755" test -d /tmp/d/2 -test $(stat -c %U:%G:%a /tmp/d/2) = "daemon:daemon:755" +test "$(stat -c %U:%G:%a /tmp/d/2)" = "daemon:daemon:755" # # 'D' @@ -39,10 +39,10 @@ D /tmp/D/2 0755 daemon daemon - - EOF test -d /tmp/D/1 -test $(stat -c %U:%G:%a /tmp/D/1) = "daemon:daemon:755" +test "$(stat -c %U:%G:%a /tmp/D/1)" = "daemon:daemon:755" test -d /tmp/D/2 -test $(stat -c %U:%G:%a /tmp/D/2) = "daemon:daemon:755" +test "$(stat -c %U:%G:%a /tmp/D/2)" = "daemon:daemon:755" systemd-tmpfiles --remove - </failed -for t in ${0%.sh}.*.sh; do - echo "Running $t"; ./$t +for t in "${0%.sh}".*.sh; do + echo "Running $t"; ./"$t" done touch /testok diff --git a/test/units/testsuite-23.sh b/test/units/testsuite-23.sh index c66ed26229..4ef7c878a8 100755 --- a/test/units/testsuite-23.sh +++ b/test/units/testsuite-23.sh @@ -21,8 +21,8 @@ systemd-run --unit=six -p Type=exec /tmp/brokenbinary && { echo 'unexpected succ systemd-run --unit=seven -p KillSignal=SIGTERM -p RestartKillSignal=SIGINT -p Type=exec /bin/sleep infinity # Both TERM and SIGINT happen to have the same number on all architectures -test $(systemctl show --value -p KillSignal seven.service) -eq 15 -test $(systemctl show --value -p RestartKillSignal seven.service) -eq 2 +test "$(systemctl show --value -p KillSignal seven.service)" -eq 15 +test "$(systemctl show --value -p RestartKillSignal seven.service)" -eq 2 systemctl restart seven.service systemctl stop seven.service diff --git a/test/units/testsuite-36.sh b/test/units/testsuite-36.sh index 46c08017d1..6d3713c962 100755 --- a/test/units/testsuite-36.sh +++ b/test/units/testsuite-36.sh @@ -55,7 +55,7 @@ stopJournalctl() { # the --sync wait until the synchronization is complete echo "Force journald to write all queued messages" journalctl --sync - journalctl -u $unit --cursor-file="$journalCursorFile" >"$journalLog" + journalctl -u "$unit" --cursor-file="$journalCursorFile" >"$journalLog" } checkNUMA() { @@ -97,32 +97,38 @@ pid1ReloadWithJournal() { pid1StartUnitWithStrace() { startStrace '-f' - systemctl start $1 + systemctl start "${1:?missing unit name}" sleep $sleepAfterStart stopStrace } pid1StartUnitWithJournal() { startJournalctl - systemctl start $1 + systemctl start "${1:?missing unit name}" sleep $sleepAfterStart stopJournalctl } pid1StopUnit() { - systemctl stop $1 + systemctl stop "${1:?missing unit name}" } systemctlCheckNUMAProperties() { - local LOGFILE="$(mktemp)" - systemctl show -p NUMAPolicy $1 >"$LOGFILE" - grep "NUMAPolicy=$2" "$LOGFILE" + local UNIT_NAME="${1:?missing unit name}" + local NUMA_POLICY="${2:?missing NUMAPolicy}" + local NUMA_MASK="${3:-""}" + local LOGFILE - >"$LOGFILE" + LOGFILE="$(mktemp)" - if [ -n "$3" ]; then - systemctl show -p NUMAMask $1 >"$LOGFILE" - grep "NUMAMask=$3" "$LOGFILE" + systemctl show -p NUMAPolicy "$UNIT_NAME" >"$LOGFILE" + grep "NUMAPolicy=$NUMA_POLICY" "$LOGFILE" + + : >"$LOGFILE" + + if [ -n "$NUMA_MASK" ]; then + systemctl show -p NUMAMask "$UNIT_NAME" >"$LOGFILE" + grep "NUMAMask=$NUMA_MASK" "$LOGFILE" fi } @@ -145,10 +151,10 @@ if ! checkNUMA; then echo "systemd-run NUMAPolicy=default && NUMAMask=0 check without NUMA support" runUnit='numa-systemd-run-test.service' startJournalctl - systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000 + systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit "$runUnit" sleep 1000 sleep $sleepAfterStart - pid1StopUnit $runUnit - stopJournalctl $runUnit + pid1StopUnit "$runUnit" + stopJournalctl "$runUnit" grep "NUMA support not available, ignoring" "$journalLog" else @@ -156,43 +162,43 @@ else writePID1NUMAPolicy "default" pid1ReloadWithStrace # Kernel requires that nodemask argument is set to NULL when setting default policy - grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + grep "set_mempolicy(MPOL_DEFAULT, NULL" "$straceLog" echo "PID1 NUMAPolicy support - Default policy w/ mask" writePID1NUMAPolicy "default" "0" pid1ReloadWithStrace - grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + grep "set_mempolicy(MPOL_DEFAULT, NULL" "$straceLog" echo "PID1 NUMAPolicy support - Bind policy w/o mask" writePID1NUMAPolicy "bind" pid1ReloadWithJournal - grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + grep "Failed to set NUMA memory policy: Invalid argument" "$journalLog" echo "PID1 NUMAPolicy support - Bind policy w/ mask" writePID1NUMAPolicy "bind" "0" pid1ReloadWithStrace - grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog + grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" "$straceLog" echo "PID1 NUMAPolicy support - Interleave policy w/o mask" writePID1NUMAPolicy "interleave" pid1ReloadWithJournal - grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + grep "Failed to set NUMA memory policy: Invalid argument" "$journalLog" echo "PID1 NUMAPolicy support - Interleave policy w/ mask" writePID1NUMAPolicy "interleave" "0" pid1ReloadWithStrace - grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog + grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" "$straceLog" echo "PID1 NUMAPolicy support - Preferred policy w/o mask" writePID1NUMAPolicy "preferred" pid1ReloadWithJournal # Preferred policy with empty node mask is actually allowed and should reset allocation policy to default - ! grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + grep "Failed to set NUMA memory policy: Invalid argument" "$journalLog" && { echo >&2 "unexpected pass"; exit 1; } echo "PID1 NUMAPolicy support - Preferred policy w/ mask" writePID1NUMAPolicy "preferred" "0" pid1ReloadWithStrace - grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog + grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" "$straceLog" echo "PID1 NUMAPolicy support - Local policy w/o mask" writePID1NUMAPolicy "local" @@ -202,136 +208,133 @@ else # return a numerical constant instead (with a comment): # set_mempolicy(0x4 /* MPOL_??? */, NULL, 0) = 0 # Let's cover this scenario as well - grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" "$straceLog" echo "PID1 NUMAPolicy support - Local policy w/ mask" writePID1NUMAPolicy "local" "0" pid1ReloadWithStrace - grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" "$straceLog" echo "Unit file NUMAPolicy support - Default policy w/o mask" writeTestUnitNUMAPolicy "default" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "default" - pid1StopUnit $testUnit - grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "default" + pid1StopUnit "$testUnit" + grep "set_mempolicy(MPOL_DEFAULT, NULL" "$straceLog" echo "Unit file NUMAPolicy support - Default policy w/ mask" writeTestUnitNUMAPolicy "default" "0" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "default" "0" + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "default" "0" pid1StopUnit $testUnit # Mask must be ignored - grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + grep "set_mempolicy(MPOL_DEFAULT, NULL" "$straceLog" echo "Unit file NUMAPolicy support - Bind policy w/o mask" writeTestUnitNUMAPolicy "bind" - pid1StartUnitWithJournal $testUnit - pid1StopUnit $testUnit - grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + pid1StartUnitWithJournal "$testUnit" + pid1StopUnit "$testUnit" + grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" "$journalLog" echo "Unit file NUMAPolicy support - Bind policy w/ mask" writeTestUnitNUMAPolicy "bind" "0" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "bind" "0" - pid1StopUnit $testUnit - grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "bind" "0" + pid1StopUnit "$testUnit" + grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" "$straceLog" echo "Unit file NUMAPolicy support - Interleave policy w/o mask" writeTestUnitNUMAPolicy "interleave" - pid1StartUnitWithStrace $testUnit - pid1StopUnit $testUnit - grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + pid1StartUnitWithStrace "$testUnit" + pid1StopUnit "$testUnit" + grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" "$journalLog" echo "Unit file NUMAPolicy support - Interleave policy w/ mask" writeTestUnitNUMAPolicy "interleave" "0" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "interleave" "0" - pid1StopUnit $testUnit - grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "interleave" "0" + pid1StopUnit "$testUnit" + grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" "$straceLog" echo "Unit file NUMAPolicy support - Preferred policy w/o mask" writeTestUnitNUMAPolicy "preferred" - pid1StartUnitWithJournal $testUnit - systemctlCheckNUMAProperties $testUnit "preferred" - pid1StopUnit $testUnit - ! grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + pid1StartUnitWithJournal "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "preferred" + pid1StopUnit "$testUnit" + grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" "$journalLog" && { echo >&2 "unexpected pass"; exit 1; } echo "Unit file NUMAPolicy support - Preferred policy w/ mask" writeTestUnitNUMAPolicy "preferred" "0" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "preferred" "0" - pid1StopUnit $testUnit - grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "preferred" "0" + pid1StopUnit "$testUnit" + grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" "$straceLog" echo "Unit file NUMAPolicy support - Local policy w/o mask" writeTestUnitNUMAPolicy "local" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "local" - pid1StopUnit $testUnit - grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "local" + pid1StopUnit "$testUnit" + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" "$straceLog" echo "Unit file NUMAPolicy support - Local policy w/ mask" writeTestUnitNUMAPolicy "local" "0" - pid1StartUnitWithStrace $testUnit - systemctlCheckNUMAProperties $testUnit "local" "0" - pid1StopUnit $testUnit + pid1StartUnitWithStrace "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "local" "0" + pid1StopUnit "$testUnit" # Mask must be ignored - grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" "$straceLog" echo "Unit file CPUAffinity=NUMA support" writeTestUnitNUMAPolicy "bind" "0" - echo "CPUAffinity=numa" >>$testUnitNUMAConf + echo "CPUAffinity=numa" >>"$testUnitNUMAConf" systemctl daemon-reload - systemctl start $testUnit - systemctlCheckNUMAProperties $testUnit "bind" "0" - pid=$(systemctl show --value -p MainPID $testUnit) - cpulist=$(cat /sys/devices/system/node/node0/cpulist) - affinity_systemd=$(systemctl show --value -p CPUAffinity $testUnit) - [ $cpulist = $affinity_systemd ] - pid1StopUnit $testUnit + systemctl start "$testUnit" + systemctlCheckNUMAProperties "$testUnit" "bind" "0" + cpulist="$(cat /sys/devices/system/node/node0/cpulist)" + affinity_systemd="$(systemctl show --value -p CPUAffinity "$testUnit")" + [ "$cpulist" = "$affinity_systemd" ] + pid1StopUnit "$testUnit" echo "systemd-run NUMAPolicy support" runUnit='numa-systemd-run-test.service' - systemd-run -p NUMAPolicy=default --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "default" - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=default --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "default" + pid1StopUnit "$runUnit" - systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "default" "" - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "default" "" + pid1StopUnit "$runUnit" - systemd-run -p NUMAPolicy=bind -p NUMAMask=0 --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "bind" "0" - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=bind -p NUMAMask=0 --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "bind" "0" + pid1StopUnit "$runUnit" - systemd-run -p NUMAPolicy=interleave -p NUMAMask=0 --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "interleave" "0" - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=interleave -p NUMAMask=0 --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "interleave" "0" + pid1StopUnit "$runUnit" - systemd-run -p NUMAPolicy=preferred -p NUMAMask=0 --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "preferred" "0" - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=preferred -p NUMAMask=0 --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "preferred" "0" + pid1StopUnit "$runUnit" - systemd-run -p NUMAPolicy=local --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "local" - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=local --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "local" + pid1StopUnit "$runUnit" - systemd-run -p NUMAPolicy=local -p NUMAMask=0 --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "local" "" - pid1StopUnit $runUnit - - systemd-run -p NUMAPolicy=local -p NUMAMask=0 -p CPUAffinity=numa --unit $runUnit sleep 1000 - systemctlCheckNUMAProperties $runUnit "local" "" - systemctl cat $runUnit | grep -q 'CPUAffinity=numa' - pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=local -p NUMAMask=0 --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "local" "" + pid1StopUnit "$runUnit" + systemd-run -p NUMAPolicy=local -p NUMAMask=0 -p CPUAffinity=numa --unit "$runUnit" sleep 1000 + systemctlCheckNUMAProperties "$runUnit" "local" "" + systemctl cat "$runUnit" | grep -q 'CPUAffinity=numa' + pid1StopUnit "$runUnit" fi # Cleanup -rm -rf $testDir -rm -rf $confDir +rm -rf "$confDir" systemctl daemon-reload systemd-analyze log-level info diff --git a/test/units/testsuite-39.sh b/test/units/testsuite-39.sh index 90da2bf5e1..3b0d893a4c 100755 --- a/test/units/testsuite-39.sh +++ b/test/units/testsuite-39.sh @@ -18,12 +18,12 @@ ExecReload=/bin/false EOF systemctl daemon-reload -systemctl start $SERVICE_NAME -systemctl status $SERVICE_NAME +systemctl start "$SERVICE_NAME" +systemctl status "$SERVICE_NAME" # The reload SHOULD fail but SHOULD NOT affect the service state -systemctl reload $SERVICE_NAME && { echo 'unexpected success'; exit 1; } -systemctl status $SERVICE_NAME -systemctl stop $SERVICE_NAME +systemctl reload "$SERVICE_NAME" && { echo 'unexpected success'; exit 1; } +systemctl status "$SERVICE_NAME" +systemctl stop "$SERVICE_NAME" echo "[#2] Failing ExecReload= should not kill the service (multiple ExecReload=)" @@ -36,12 +36,12 @@ ExecReload=/bin/true EOF systemctl daemon-reload -systemctl start $SERVICE_NAME -systemctl status $SERVICE_NAME +systemctl start "$SERVICE_NAME" +systemctl status "$SERVICE_NAME" # The reload SHOULD fail but SHOULD NOT affect the service state -systemctl reload $SERVICE_NAME && { echo 'unexpected success'; exit 1; } -systemctl status $SERVICE_NAME -systemctl stop $SERVICE_NAME +systemctl reload "$SERVICE_NAME" && { echo 'unexpected success'; exit 1; } +systemctl status "$SERVICE_NAME" +systemctl stop "$SERVICE_NAME" echo "[#3] Failing ExecReload=- should not affect reload's exit code" cat >"$SERVICE_PATH" </run/systemd/system/testservice-50a.service </run/systemd/system/testservice-50b.service </run/systemd/system/testservice-50c.service </run/systemd/system/testservice-50e.service <>/skipped -cgroup_type=$(stat -fc %T /sys/fs/cgroup/) +cgroup_type="$(stat -fc %T /sys/fs/cgroup/)" if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]; then echo "no cgroup2" >>/skipped fi if [ ! -f /usr/lib/systemd/systemd-oomd ] && [ ! -f /lib/systemd/systemd-oomd ]; then echo "no oomd" >>/skipped fi -[[ -e /skipped ]] && exit 0 || true + +if [[ -e /skipped ]]; then + exit 0 +fi rm -rf /etc/systemd/system/testsuite-55-testbloat.service.d @@ -30,7 +33,7 @@ oomctl | grep "Default Memory Pressure Duration: 5s" # systemd-oomd watches for elevated pressure for 5 seconds before acting. # It can take time to build up pressure so either wait 2 minutes or for the service to fail. -timeout=$(date -ud "2 minutes" +%s) +timeout="$(date -ud "2 minutes" +%s)" while [[ $(date -u +%s) -le $timeout ]]; do if ! systemctl status testsuite-55-testbloat.service; then break @@ -55,8 +58,8 @@ if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then systemctl start testsuite-55-testmunch.service systemctl start testsuite-55-testbloat.service - timeout=$(date -ud "2 minutes" +%s) - while [[ $(date -u +%s) -le $timeout ]]; do + timeout="$(date -ud "2 minutes" +%s)" + while [[ "$(date -u +%s)" -le "$timeout" ]]; do if ! systemctl status testsuite-55-testmunch.service; then break fi From f79409835665a8ae600249d97671f05706b6dc78 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:50:52 +0200 Subject: [PATCH 3/7] test: tidy up arithmetic expressions --- test/units/testsuite-03.sh | 8 ++++---- test/units/testsuite-41.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/units/testsuite-03.sh b/test/units/testsuite-03.sh index 82858f0c8e..8a8ba870e8 100755 --- a/test/units/testsuite-03.sh +++ b/test/units/testsuite-03.sh @@ -18,7 +18,7 @@ grep 'hello\.service.*waiting' /root/list-jobs.txt START_SEC=$(date -u '+%s') systemctl start --job-mode=ignore-dependencies hello END_SEC=$(date -u '+%s') -ELAPSED=$(($END_SEC-$START_SEC)) +ELAPSED=$((END_SEC-START_SEC)) test "$ELAPSED" -lt 3 @@ -76,14 +76,14 @@ EOF START_SEC=$(date -u '+%s') systemctl start --wait wait2.service END_SEC=$(date -u '+%s') -ELAPSED=$(($END_SEC-$START_SEC)) +ELAPSED=$((END_SEC-START_SEC)) [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1 # wait5fail fails, so systemctl should fail START_SEC=$(date -u '+%s') systemctl start --wait wait2.service wait5fail.service && { echo 'unexpected success'; exit 1; } END_SEC=$(date -u '+%s') -ELAPSED=$(($END_SEC-$START_SEC)) +ELAPSED=$((END_SEC-START_SEC)) [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1 # Test time-limited scopes @@ -92,7 +92,7 @@ set +e systemd-run --scope --property=RuntimeMaxSec=3s sleep 10 RESULT=$? END_SEC=$(date -u '+%s') -ELAPSED=$(($END_SEC-$START_SEC)) +ELAPSED=$((END_SEC-START_SEC)) [[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] || exit 1 [[ "$RESULT" -ne 0 ]] || exit 1 diff --git a/test/units/testsuite-41.sh b/test/units/testsuite-41.sh index 527213fcf8..e7993e8df7 100755 --- a/test/units/testsuite-41.sh +++ b/test/units/testsuite-41.sh @@ -12,7 +12,7 @@ systemd-analyze log-target console systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" \ && { echo 'unexpected success'; exit 1; } -for ((secs=0; secs<$MAX_SECS; secs++)); do +for ((secs = 0; secs < MAX_SECS; secs++)); do [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break sleep 1 done @@ -35,7 +35,7 @@ systemd-run --unit=two \ && { echo 'unexpected success'; exit 1; } # wait for at least 3 restarts -for ((secs=0; secs<$MAX_SECS; secs++)); do +for ((secs = 0; secs < MAX_SECS; secs++)); do [[ $(cat $TMP_FILE) != "aaa" ]] || break sleep 1 done From 70ad107bdf9efef35bbfecfb9edfdb6f84271bc1 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:52:46 +0200 Subject: [PATCH 4/7] test: use an explicit no-op for file truncation --- test/units/testsuite-04.sh | 4 ++-- test/units/testsuite-17.sh | 2 +- test/units/testsuite-22.03.sh | 2 +- test/units/testsuite-22.sh | 2 +- test/units/testsuite-53.sh | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 0969a8313e..52a105d3d4 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -6,14 +6,14 @@ set -o pipefail # Skip empty lines ID=$(journalctl --new-id128 | sed -n 2p) ->/expected +: >/expected printf $'\n\n\n' | systemd-cat -t "$ID" --level-prefix false journalctl --sync journalctl -b -o cat -t "$ID" >/output cmp /expected /output ID=$(journalctl --new-id128 | sed -n 2p) ->/expected +: >/expected printf $'<5>\n<6>\n<7>\n' | systemd-cat -t "$ID" --level-prefix true journalctl --sync journalctl -b -o cat -t "$ID" >/output diff --git a/test/units/testsuite-17.sh b/test/units/testsuite-17.sh index 2ec9f6a891..65d0802969 100755 --- a/test/units/testsuite-17.sh +++ b/test/units/testsuite-17.sh @@ -3,7 +3,7 @@ set -eux set -o pipefail ->/failed +: >/failed for t in "${0%.sh}".*.sh; do echo "Running $t"; ./"$t" diff --git a/test/units/testsuite-22.03.sh b/test/units/testsuite-22.03.sh index e4311dcfb6..1ed026eb70 100755 --- a/test/units/testsuite-22.03.sh +++ b/test/units/testsuite-22.03.sh @@ -161,7 +161,7 @@ test -f /tmp/F/ro-fs/foo grep -q 'truncating is not allowed' /tmp/F/ro-fs/foo # Trying to change the perms should fail. ->/tmp/F/rw-fs/foo +: >/tmp/F/rw-fs/foo systemd-tmpfiles --create - </failed +: >/failed for t in "${0%.sh}".*.sh; do echo "Running $t"; ./"$t" diff --git a/test/units/testsuite-53.sh b/test/units/testsuite-53.sh index 298d5d50eb..3eef94bc14 100755 --- a/test/units/testsuite-53.sh +++ b/test/units/testsuite-53.sh @@ -2,7 +2,7 @@ set -eux set -o pipefail ->/failed +: >/failed # Reset host date to current time, 3 days in the past. date -s "-3 days" From ea539ad297506868835eb00affedf3f4d8010f2c Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:54:42 +0200 Subject: [PATCH 5/7] test: replace the obsolete `` syntax with $() --- test/units/testsuite-04.sh | 4 ++-- test/units/testsuite-20.sh | 32 ++++++++++++++++---------------- test/units/testsuite-32.sh | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 52a105d3d4..da5f9ee2af 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -54,7 +54,7 @@ ID=$(journalctl --new-id128 | sed -n 2p) printf $'foo' | systemd-cat -t "$ID" --level-prefix false journalctl --sync journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MESSAGE -t "$ID" >/output -[[ `grep -c . /output` -eq 6 ]] +[[ $(grep -c . /output) -eq 6 ]] grep -q '^__CURSOR=' /output grep -q '^MESSAGE=foo$' /output grep -q '^PRIORITY=6$' /output @@ -82,7 +82,7 @@ journalctl --sync # We can drop this grep when https://github.com/systemd/systemd/issues/13937 # has a fix. journalctl -b -o export -t "$ID" --output-fields=_PID | grep '^_PID=' >/output -[[ `grep -c . /output` -eq 2 ]] +[[ $(grep -c . /output) -eq 2 ]] grep -q "^_PID=$PID" /output grep -vq "^_PID=$PID" /output diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index 111713dabf..7876a9d10c 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -5,7 +5,7 @@ set -o pipefail systemd-analyze log-level debug systemd-analyze log-target console -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ # Start a test process inside of our own cgroup sleep infinity & @@ -14,45 +14,45 @@ disown # Start a test process outside of our own cgroup systemd-run -p DynamicUser=1 --unit=test20-sleep.service /bin/sleep infinity -EXTERNALPID=`systemctl show -P MainPID test20-sleep.service` +EXTERNALPID="$(systemctl show -P MainPID test20-sleep.service)" # Update our own main PID to the external test PID, this should work -systemd-notify MAINPID=$EXTERNALPID -test `systemctl show -P MainPID testsuite-20.service` -eq $EXTERNALPID +systemd-notify MAINPID="$EXTERNALPID" +test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$EXTERNALPID" # Update our own main PID to the internal test PID, this should work, too systemd-notify MAINPID=$INTERNALPID -test `systemctl show -P MainPID testsuite-20.service` -eq $INTERNALPID +test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID" # Update it back to our own PID, this should also work systemd-notify MAINPID=$$ -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ # Try to set it to PID 1, which it should ignore, because that's the manager systemd-notify MAINPID=1 -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ # Try to set it to PID 0, which is invalid and should be ignored systemd-notify MAINPID=0 -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ # Try to set it to a valid but non-existing PID, which should be ignored. (Note # that we set the PID to a value well above any known /proc/sys/kernel/pid_max, # which means we can be pretty sure it doesn't exist by coincidence) systemd-notify MAINPID=1073741824 -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ # Change it again to the external PID, without privileges this time. This should be ignored, because the PID is from outside of our cgroup and we lack privileges. -systemd-notify --uid=1000 MAINPID=$EXTERNALPID -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +systemd-notify --uid=1000 MAINPID="$EXTERNALPID" +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ # Change it again to the internal PID, without privileges this time. This should work, as the process is on our cgroup, and that's enough even if we lack privileges. -systemd-notify --uid=1000 MAINPID=$INTERNALPID -test `systemctl show -P MainPID testsuite-20.service` -eq $INTERNALPID +systemd-notify --uid=1000 MAINPID="$INTERNALPID" +test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID" # Update it back to our own PID, this should also work systemd-notify --uid=1000 MAINPID=$$ -test `systemctl show -P MainPID testsuite-20.service` -eq $$ +test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ cat >/tmp/test20-mainpid.sh </tmp/test20-mainpid2.sh </dev/shm/test20-mainpid3.sh </proc/sysrq-trigger while : ; do - STATE=`systemctl show -P ActiveState oomtest.service` + STATE="$(systemctl show -P ActiveState oomtest.service)" [ "$STATE" = "failed" ] && break sleep .5 done - RESULT=`systemctl show -P Result oomtest.service` + RESULT="$(systemctl show -P Result oomtest.service)" test "$RESULT" = "oom-kill" systemd-analyze log-level info From 4544002cae317311b02590c9b4422e2783471813 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:55:27 +0200 Subject: [PATCH 6/7] test: use arrays to make things a bit cleaner --- test/units/testsuite-13.sh | 81 ++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index d93cc7b145..0d468b2db1 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -30,10 +30,10 @@ if unshare -U sh -c :; then is_user_ns_supported=yes fi -SUSE_OPTS="" +SUSE_OPTS=() ID_LIKE=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' /etc/os-release) if [[ "$ID_LIKE" = *"suse"* ]]; then - SUSE_OPTS="--bind /lib64 --bind /usr/lib64 " + SUSE_OPTS+=(--bind /lib64 --bind /usr/lib64) fi function check_bind_tmp_path { @@ -41,8 +41,8 @@ function check_bind_tmp_path { local _root="/var/lib/machines/testsuite-13.bind-tmp-path" rm -rf "$_root" /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" - >/tmp/bind - systemd-nspawn $SUSE_OPTS--register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' + : >/tmp/bind + systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' } function check_norbind { @@ -54,15 +54,15 @@ function check_norbind { mount -t tmpfs tmpfs /tmp/binddir/subdir echo -n "inner" >/tmp/binddir/subdir/file /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" - systemd-nspawn $SUSE_OPTS--register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' + systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' } function check_notification_socket { # https://github.com/systemd/systemd/issues/4944 local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/host/notify' # /testsuite-13.nc-container is prepared by test.sh - systemd-nspawn $SUSE_OPTS--register=no -D /testsuite-13.nc-container /bin/sh -x -c "$_cmd" - systemd-nspawn $SUSE_OPTS--register=no -D /testsuite-13.nc-container -U /bin/sh -x -c "$_cmd" + systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container /bin/sh -x -c "$_cmd" + systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container -U /bin/sh -x -c "$_cmd" } function check_os_release { @@ -76,15 +76,15 @@ if echo test >>/run/host/os-release; then exit 1; fi ' local _os_release_source="/etc/os-release" - if [ ! -r "${_os_release_source}" ]; then + if [[ ! -r "${_os_release_source}" ]]; then _os_release_source="/usr/lib/os-release" - elif [ -L "${_os_release_source}" ] && rm /etc/os-release; then + elif [[ -L "${_os_release_source}" ]] && rm /etc/os-release; then # Ensure that /etc always wins if available cp /usr/lib/os-release /etc echo MARKER=1 >>/etc/os-release fi - systemd-nspawn $SUSE_OPTS--register=no -D /testsuite-13.nc-container --bind="${_os_release_source}":/tmp/os-release /bin/sh -x -e -c "$_cmd" + systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container --bind="${_os_release_source}":/tmp/os-release /bin/sh -x -e -c "$_cmd" if grep -q MARKER /etc/os-release; then rm /etc/os-release @@ -95,10 +95,10 @@ if echo test >>/run/host/os-release; then exit 1; fi function check_machinectl_bind { local _cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; sleep 0.5; done; exit 1;' - cat </run/systemd/system/nspawn_machinectl_bind.service + cat >/run/systemd/system/nspawn_machinectl_bind.service <&2 "unexpected pass" + return 1 + fi + done # allow combination of --network-namespace-path and --private-network - if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn $SUSE_OPTS--register=no -D "$_root" "$_netns_opt" --private-network -b; then + if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" -b "$_netns_opt" --private-network; then return 1 fi # test --network-namespace-path works with a network namespace created by "ip netns" ip netns add nspawn_test _netns_opt="--network-namespace-path=/run/netns/nspawn_test" - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn $SUSE_OPTS--register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP' + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP' local r=$? ip netns del nspawn_test - if [ $r -ne 0 ]; then + if [[ $r -ne 0 ]]; then return 1 fi From 84031b5d6e26e77192e1aebeb12aab93f0ce894b Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 9 Apr 2021 19:56:12 +0200 Subject: [PATCH 7/7] test: bunch of assorted tweaks to make shellcheck happy --- test/units/testsuite-02.sh | 7 +++-- test/units/testsuite-05.sh | 2 ++ test/units/testsuite-07.sh | 14 +++++----- test/units/testsuite-11.sh | 2 +- test/units/testsuite-12.sh | 4 +-- test/units/testsuite-17.03.sh | 2 +- test/units/testsuite-25.sh | 1 + test/units/testsuite-32.sh | 1 - test/units/testsuite-36.sh | 39 ++++++++++++++++----------- test/units/testsuite-38.sh | 32 +++++++++++----------- test/units/testsuite-43.sh | 2 ++ test/units/testsuite-55-slowgrowth.sh | 14 +++++----- 12 files changed, 66 insertions(+), 54 deletions(-) diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index ea4efda70b..da02304a32 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 f899fcaa4f..c98d849b08 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 c63394e68c..bd1da341ac 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 05448efb0a..fbe2d0b1d4 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 a025b73a04..2393601a00 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 6d3713c962..94fd927a5d 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" <