From ffa328f060f437f3e1f0f0cb13513ee3dd9c3da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 7 Apr 2021 23:24:25 +0200 Subject: [PATCH 01/12] tests: make inverted tests actually count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "! test ..." does not cause the script to fail, even with set -e. IIUC, bash treats this command as part of an expression line, as it would if 'test ... && ...' was used. Failing expression lines do not terminate the script. This fixes the obvious cases by changing '! test' → 'test !'. Then the inversion happens internally in test and bash will propagate the failure. --- test/units/testsuite-22.01.sh | 2 +- test/units/testsuite-22.02.sh | 2 +- test/units/testsuite-22.03.sh | 30 +++--- test/units/testsuite-22.06.sh | 6 +- test/units/testsuite-22.07.sh | 8 +- test/units/testsuite-22.08.sh | 4 +- test/units/testsuite-25.sh | 16 ++-- test/units/testsuite-30.sh | 8 +- test/units/testsuite-33.sh | 172 +++++++++++++++++----------------- test/units/testsuite-34.sh | 14 +-- test/units/testsuite-37.sh | 2 +- 11 files changed, 132 insertions(+), 132 deletions(-) diff --git a/test/units/testsuite-22.01.sh b/test/units/testsuite-22.01.sh index d233e37fb2..b10b5aaa1a 100755 --- a/test/units/testsuite-22.01.sh +++ b/test/units/testsuite-22.01.sh @@ -10,4 +10,4 @@ rm -fr /tmp/test echo "e /tmp/test - root root 1d" | systemd-tmpfiles --create - -! test -e /tmp/test +test ! -e /tmp/test diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh index d1bf1ea04b..54dcb405b0 100755 --- a/test/units/testsuite-22.02.sh +++ b/test/units/testsuite-22.02.sh @@ -63,7 +63,7 @@ e /tmp/e/1 0755 daemon daemon - - e /tmp/e/2/* 0755 daemon daemon - - EOF -! test -d /tmp/e/1 +test ! -d /tmp/e/1 test -d /tmp/e/2 test $(stat -c %U:%G:%a /tmp/e/2) = "root:root:777" diff --git a/test/units/testsuite-22.03.sh b/test/units/testsuite-22.03.sh index 8d009fb5bb..c865699731 100755 --- a/test/units/testsuite-22.03.sh +++ b/test/units/testsuite-22.03.sh @@ -19,7 +19,7 @@ f /tmp/f/2 0644 - - - This string should be written EOF ### '1' should exist and be empty -test -f /tmp/f/1; ! test -s /tmp/f/1 +test -f /tmp/f/1; test ! -s /tmp/f/1 test $(stat -c %U:%G:%a /tmp/f/1) = "root:root:644" test $(stat -c %U:%G:%a /tmp/f/2) = "root:root:644" @@ -31,7 +31,7 @@ f /tmp/f/1 0666 daemon daemon - This string should not be written EOF # file should be empty -! test -s /tmp/f/1 +test ! -s /tmp/f/1 test $(stat -c %U:%G:%a /tmp/f/1) = "daemon:daemon:666" ### But we shouldn't try to set perms on an existing file which is not a @@ -54,7 +54,7 @@ ln -s /tmp/file-owned-by-root /tmp/f/symlink f /tmp/f/dangling 0644 daemon daemon - - f /tmp/f/symlink 0644 daemon daemon - - EOF -! test -e /tmp/f/missing +test ! -e /tmp/f/missing test $(stat -c %U:%G:%a /tmp/file-owned-by-root) = "root:root:644" ### Handle read-only filesystem gracefully: we shouldn't fail if the target @@ -70,7 +70,7 @@ mount -o bind,ro /tmp/f/rw-fs /tmp/f/ro-fs systemd-tmpfiles --create - </tmp/F/rw-fs/foo ! systemd-tmpfiles --create - </tmp/F/rw-fs/foo @@ -170,7 +170,7 @@ test $(stat -c %U:%G:%a /tmp/F/ro-fs/foo) = "root:root:644" ! systemd-tmpfiles --create - < fails. ! systemd-tmpfiles --create - < /testok diff --git a/test/units/testsuite-30.sh b/test/units/testsuite-30.sh index a507ffcd7b..425f153c3b 100755 --- a/test/units/testsuite-30.sh +++ b/test/units/testsuite-30.sh @@ -13,16 +13,16 @@ timedatectl set-time 1980-10-15 systemd-run --on-timezone-change touch /tmp/timezone-changed systemd-run --on-clock-change touch /tmp/clock-changed -! test -f /tmp/timezone-changed -! test -f /tmp/clock-changed +test ! -f /tmp/timezone-changed +test ! -f /tmp/clock-changed timedatectl set-timezone Europe/Kiev -while ! test -f /tmp/timezone-changed ; do sleep .5 ; done +while test ! -f /tmp/timezone-changed ; do sleep .5 ; done timedatectl set-time 2018-1-1 -while ! test -f /tmp/clock-changed ; do sleep .5 ; done +while test ! -f /tmp/clock-changed ; do sleep .5 ; done systemd-analyze log-level info diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index 0a6ee57b99..ef225438a7 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -18,11 +18,11 @@ EOF systemctl daemon-reload -! test -e /etc/testservice -! test -e /run/testservice -! test -e /var/lib/testservice -! test -e /var/cache/testservice -! test -e /var/log/testservice +test ! -e /etc/testservice +test ! -e /run/testservice +test ! -e /var/lib/testservice +test ! -e /var/cache/testservice +test ! -e /var/log/testservice systemctl start testservice @@ -44,7 +44,7 @@ test -d /var/log/testservice systemctl clean testservice --what=configuration -! test -e /etc/testservice +test ! -e /etc/testservice test -d /run/testservice test -d /var/lib/testservice test -d /var/cache/testservice @@ -52,27 +52,27 @@ test -d /var/log/testservice systemctl clean testservice -! test -e /etc/testservice -! test -e /run/testservice +test ! -e /etc/testservice +test ! -e /run/testservice test -d /var/lib/testservice -! test -e /var/cache/testservice +test ! -e /var/cache/testservice test -d /var/log/testservice systemctl clean testservice --what=logs -! test -e /etc/testservice -! test -e /run/testservice +test ! -e /etc/testservice +test ! -e /run/testservice test -d /var/lib/testservice -! test -e /var/cache/testservice -! test -e /var/log/testservice +test ! -e /var/cache/testservice +test ! -e /var/log/testservice systemctl clean testservice --what=all -! test -e /etc/testservice -! test -e /run/testservice -! test -e /var/lib/testservice -! test -e /var/cache/testservice -! test -e /var/log/testservice +test ! -e /etc/testservice +test ! -e /run/testservice +test ! -e /var/lib/testservice +test ! -e /var/cache/testservice +test ! -e /var/log/testservice cat > /etc/systemd/system/testservice.service < /etc/systemd/system/tmp-hoge.mount < /etc/systemd/system/testservice.socket < /testok diff --git a/test/units/testsuite-34.sh b/test/units/testsuite-34.sh index 6d9488688a..596fc15ee8 100755 --- a/test/units/testsuite-34.sh +++ b/test/units/testsuite-34.sh @@ -12,10 +12,10 @@ systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/t ! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing test -d /var/lib/zzz -! test -L /var/lib/zzz -! test -e /var/lib/private/zzz +test ! -L /var/lib/zzz +test ! -e /var/lib/private/zzz test -f /var/lib/zzz/test -! test -f /var/lib/zzz/test-missing +test ! -f /var/lib/zzz/test-missing # Convert to DynamicUser=1 @@ -26,7 +26,7 @@ test -L /var/lib/zzz test -d /var/lib/private/zzz test -f /var/lib/zzz/test -! test -f /var/lib/zzz/test-missing +test ! -f /var/lib/zzz/test-missing # Convert back @@ -34,10 +34,10 @@ systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/t ! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing test -d /var/lib/zzz -! test -L /var/lib/zzz -! test -e /var/lib/private/zzz +test ! -L /var/lib/zzz +test ! -e /var/lib/private/zzz test -f /var/lib/zzz/test -! test -f /var/lib/zzz/test-missing +test ! -f /var/lib/zzz/test-missing systemd-analyze log-level info diff --git a/test/units/testsuite-37.sh b/test/units/testsuite-37.sh index 32a9dd8694..696b8cdeef 100755 --- a/test/units/testsuite-37.sh +++ b/test/units/testsuite-37.sh @@ -12,7 +12,7 @@ touch /tmp/aaa/bbb systemctl restart tmp-aaa.mount test -e /run/hoge/foo -! test -e /tmp/aaa/bbb +test ! -e /tmp/aaa/bbb echo OK > /testok From 4e324ce42c8563f20a930ac0945ae06a1324955a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 7 Apr 2021 23:32:14 +0200 Subject: [PATCH 02/12] TEST-22-TMPFILES: fix broken test exposed by condition check fix --- test/units/testsuite-22.03.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/units/testsuite-22.03.sh b/test/units/testsuite-22.03.sh index c865699731..5e3b1ead19 100755 --- a/test/units/testsuite-22.03.sh +++ b/test/units/testsuite-22.03.sh @@ -157,7 +157,8 @@ EOF ! systemd-tmpfiles --create - </tmp/F/rw-fs/foo From b065dfc8ed7b0465be113a0d739f153ca0230ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 00:09:38 +0200 Subject: [PATCH 03/12] TEST-33-CLEAN-UNIT: fix broken test exposed by condition check fix --- test/units/testsuite-33.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index ef225438a7..3618bee7fb 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -267,7 +267,7 @@ test ! -e /var/log/testsocket systemctl start testservice.socket test -d /etc/testsocket -test ! -d /run/testsocket +test -d /run/testsocket test -d /var/lib/testsocket test -d /var/cache/testsocket test -d /var/log/testsocket From b88ba6c76116b6e03e202b1bdffd37933f748f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 00:48:35 +0200 Subject: [PATCH 04/12] tmpfiles: make handling of existing-but-different targets more consistent create_fifo() was added in a2fc2f8dd30c17ad1e23a31fc6ff2aeba4c6fa27, and would always ignore failure. The test was trying to fail in this case, but we actually don't fail, which seems to be correct. We didn't notice before because the test was ineffective. To make things consistent, generally log at warning level, but don't propagate the error. For symlinks, log at debug level, as before. For 'e', failure is not propagated now. The test is adjusted to match. I think warning is appropriate in most cases: we do not expect a device node to be replaced by a different device node or even a non-device file. This would most likely be an error somewhere. An exception is made for symlinks, which are mismatched on purpose, for example /etc/resolv.conf. With this patch, we don't get any warnings with the any of the 74 tmpfiles.d files, which suggests that increasing the warning levels will not cause too many unexpected warnings. If it turns out that there are valid cases where people have expected mismatches for non-symlink types, we can always decrease the log levels again. --- man/systemd-tmpfiles.xml | 22 ++++++++++++---------- src/tmpfiles/tmpfiles.c | 21 +++++++++++---------- test/units/testsuite-22.02.sh | 4 ++-- test/units/testsuite-22.04.sh | 4 ++-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml index 5f97e37025..15bc1ea889 100644 --- a/man/systemd-tmpfiles.xml +++ b/man/systemd-tmpfiles.xml @@ -263,16 +263,18 @@ Exit status - On success, 0 is returned. If the configuration was syntactically invalid (syntax errors, - missing arguments, …), so some lines had to be ignored, but no other errors occurred, - 65 is returned (EX_DATAERR from - /usr/include/sysexits.h). If the configuration was syntactically valid, but - could not be executed (lack of permissions, creation of files in missing directories, invalid - contents when writing to /sys/ values, …), 73 is - returned (EX_CANTCREAT from /usr/include/sysexits.h). - Otherwise, 1 is returned (EXIT_FAILURE from - /usr/include/stdlib.h). - + On success, 0 is returned. If the configuration was syntactically invalid (syntax errors, missing + arguments, …), so some lines had to be ignored, but no other errors occurred, 65 is + returned (EX_DATAERR from /usr/include/sysexits.h). If the + configuration was syntactically valid, but could not be executed (lack of permissions, creation of files + in missing directories, invalid contents when writing to /sys/ values, …), + 73 is returned (EX_CANTCREAT from + /usr/include/sysexits.h). Otherwise, 1 is returned + (EXIT_FAILURE from /usr/include/stdlib.h). + + Note: when creating items, if the target already exists, but is of the wrong type or otherwise does + not match the requested state, and forced operation has not been requested with +, + a message is emitted, but the failure is otherwise ignored. diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index f11b4eed7c..6b26dc8b9c 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1656,10 +1656,9 @@ static int create_directory_or_subvolume(const char *path, mode_t mode, bool sub return log_error_errno(r, "%s does not exist and cannot be created as the file system is read-only.", path); if (k < 0) return log_error_errno(k, "Failed to check if %s exists: %m", path); - if (!k) { - log_warning("\"%s\" already exists and is not a directory.", path); - return -EEXIST; - } + if (!k) + return log_warning_errno(SYNTHETIC_ERRNO(EEXIST), + "\"%s\" already exists and is not a directory.", path); *creation = CREATION_EXISTING; } else @@ -1742,10 +1741,10 @@ static int empty_directory(Item *i, const char *path) { } if (r < 0) return log_error_errno(r, "is_dir() failed on path %s: %m", path); - if (r == 0) - return log_error_errno(SYNTHETIC_ERRNO(EEXIST), - "'%s' already exists and is not a directory.", - path); + if (r == 0) { + log_warning("\"%s\" already exists and is not a directory.", path); + return 0; + } return path_set_perms(i, path); } @@ -1804,7 +1803,7 @@ static int create_device(Item *i, mode_t file_type) { return log_error_errno(r, "Failed to create device node \"%s\": %m", i->path); creation = CREATION_FORCE; } else { - log_debug("%s is not a device node.", i->path); + log_warning("\"%s\" already exists is not a device node.", i->path); return 0; } } else @@ -2575,7 +2574,9 @@ static int patch_var_run(const char *fname, unsigned line, char **path) { /* Also log about this briefly. We do so at LOG_NOTICE level, as we fixed up the situation automatically, hence * there's no immediate need for action by the user. However, in the interest of making things less confusing * to the user, let's still inform the user that these snippets should really be updated. */ - log_syntax(NULL, LOG_NOTICE, fname, line, 0, "Line references path below legacy directory /var/run/, updating %s → %s; please update the tmpfiles.d/ drop-in file accordingly.", *path, n); + log_syntax(NULL, LOG_NOTICE, fname, line, 0, + "Line references path below legacy directory /var/run/, updating %s → %s; please update the tmpfiles.d/ drop-in file accordingly.", + *path, n); free_and_replace(*path, n); diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh index 54dcb405b0..c337cd6e05 100755 --- a/test/units/testsuite-22.02.sh +++ b/test/units/testsuite-22.02.sh @@ -80,7 +80,7 @@ chmod 777 /tmp/e/3/d* touch /tmp/e/3/f1 chmod 644 /tmp/e/3/f1 -! systemd-tmpfiles --create - < Date: Thu, 8 Apr 2021 01:23:49 +0200 Subject: [PATCH 05/12] TEST-42-EXECSTOPPOST: un-invert test Since we test for the file right below, it seems we expected the command to succeed. --- test/units/testsuite-42.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/testsuite-42.sh b/test/units/testsuite-42.sh index 154398dd66..087e2cb294 100755 --- a/test/units/testsuite-42.sh +++ b/test/units/testsuite-42.sh @@ -58,7 +58,7 @@ systemd-run --unit=dbus1.service --wait -p StandardOutput=tty -p StandardError=t || : test -f /run/dbus1 -! systemd-run --unit=dbus2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p BusName=systemd.test.ExecStopPost -p ExecStopPost='/bin/touch /run/dbus2' true +systemd-run --unit=dbus2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p BusName=systemd.test.ExecStopPost -p ExecStopPost='/bin/touch /run/dbus2' true test -f /run/dbus2 cat > /tmp/notify1.sh < Date: Thu, 8 Apr 2021 01:27:33 +0200 Subject: [PATCH 06/12] TEST-*: make failure tests actually fail on failure Here the intent was actually correct, and the tests still pass when the check is made effective. --- test/units/testsuite-03.sh | 8 ++++---- test/units/testsuite-04.sh | 4 ++-- test/units/testsuite-18.sh | 2 +- test/units/testsuite-20.sh | 14 ++++++++++++-- test/units/testsuite-22.03.sh | 28 ++++++++++++++-------------- test/units/testsuite-22.08.sh | 6 ++++-- test/units/testsuite-23.sh | 4 ++-- test/units/testsuite-25.sh | 16 ++++++++-------- test/units/testsuite-26.sh | 4 ++-- test/units/testsuite-33.sh | 8 ++++---- test/units/testsuite-34.sh | 9 ++++++--- test/units/testsuite-39.sh | 4 ++-- test/units/testsuite-41.sh | 11 +++++++++-- test/units/testsuite-42.sh | 18 ++++++++++++------ test/units/testsuite-54.sh | 10 ++++++---- test/units/testsuite-56.sh | 12 ++++++++---- 16 files changed, 96 insertions(+), 62 deletions(-) diff --git a/test/units/testsuite-03.sh b/test/units/testsuite-03.sh index 85efeeb741..ec731aa11b 100755 --- a/test/units/testsuite-03.sh +++ b/test/units/testsuite-03.sh @@ -19,7 +19,7 @@ systemctl start --job-mode=ignore-dependencies hello END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) -[ "$ELAPSED" -lt 3 ] +test "$ELAPSED" -lt 3 # sleep should still be running, hello not. systemctl list-jobs > /root/list-jobs.txt @@ -28,11 +28,11 @@ grep 'hello\.service' /root/list-jobs.txt && exit 1 systemctl stop sleep.service hello-after-sleep.target # Some basic testing that --show-transaction does something useful -! systemctl is-active systemd-importd +systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; } systemctl -T start systemd-importd systemctl is-active systemd-importd systemctl --show-transaction stop systemd-importd -! systemctl is-active systemd-importd +systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; } # Test for a crash when enqueuing a JOB_NOP when other job already exists systemctl start --no-block hello-after-sleep.target @@ -80,7 +80,7 @@ ELAPSED=$(($END_SEC-$START_SEC)) # wait5fail fails, so systemctl should fail START_SEC=$(date -u '+%s') -! systemctl start --wait wait2.service wait5fail.service || exit 1 +systemctl start --wait wait2.service wait5fail.service && { echo 'unexpected success'; exit 1; } END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1 diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 3dce73b778..f464f61a36 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -59,8 +59,8 @@ journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MES grep -q '^__CURSOR=' /output grep -q '^MESSAGE=foo$' /output grep -q '^PRIORITY=6$' /output -! grep -q '^FOO=' /output -! grep -q '^SYSLOG_FACILITY=' /output +grep '^FOO=' /output && { echo 'unexpected success'; exit 1; } +grep '^SYSLOG_FACILITY=' /output && { echo 'unexpected success'; exit 1; } # `-b all` negates earlier use of -b (-b and -m are otherwise exclusive) journalctl -b -1 -b all -m > /dev/null diff --git a/test/units/testsuite-18.sh b/test/units/testsuite-18.sh index e471cda51b..d3c2df8101 100755 --- a/test/units/testsuite-18.sh +++ b/test/units/testsuite-18.sh @@ -3,7 +3,7 @@ set -ex set -o pipefail systemd-run --wait -p FailureAction=poweroff true -! systemd-run --wait -p SuccessAction=poweroff false +systemd-run --wait -p SuccessAction=poweroff false && { echo 'unexpected success'; exit 1; } if ! test -f /firstphase ; then echo OK > /firstphase diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index d94f6b2afb..0e0feded39 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -126,8 +126,18 @@ test -f /run/mainpidsh3/pid EOF chmod 755 /dev/shm/test20-mainpid3.sh -# This has to fail, as we shouldn't accept the dangerous PID file, and then inotify-wait on it to be corrected which we never do -! systemd-run --unit=test20-mainpidsh3.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh3 -p PIDFile=/run/mainpidsh3/pid -p DynamicUser=1 -p TimeoutStartSec=2s /dev/shm/test20-mainpid3.sh +# This has to fail, as we shouldn't accept the dangerous PID file, and then +# inotify-wait on it to be corrected which we never do. +systemd-run --unit=test20-mainpidsh3.service \ + -p StandardOutput=tty \ + -p StandardError=tty \ + -p Type=forking \ + -p RuntimeDirectory=mainpidsh3 \ + -p PIDFile=/run/mainpidsh3/pid \ + -p DynamicUser=1 \ + -p TimeoutStartSec=2s \ + /dev/shm/test20-mainpid3.sh \ + && { 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 diff --git a/test/units/testsuite-22.03.sh b/test/units/testsuite-22.03.sh index 5e3b1ead19..c905784bee 100755 --- a/test/units/testsuite-22.03.sh +++ b/test/units/testsuite-22.03.sh @@ -39,7 +39,7 @@ test $(stat -c %U:%G:%a /tmp/f/1) = "daemon:daemon:666" mkfifo /tmp/f/fifo chmod 644 /tmp/f/fifo -! systemd-tmpfiles --create - </tmp/F/rw-fs/foo -! systemd-tmpfiles --create - </tmp/F/rw-fs/foo -! systemd-tmpfiles --create - < fails. -! systemd-tmpfiles --create - < /testok diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh index 89c0937c8d..22bd22c2b0 100755 --- a/test/units/testsuite-26.sh +++ b/test/units/testsuite-26.sh @@ -22,8 +22,8 @@ systemctl show-environment | grep -q '^FOO=BAR$' systemctl unset-environment FOO PATH # Check that one is gone and the other reverted to the built-in -! (systemctl show-environment | grep -q '^FOO=$') -! (systemctl show-environment | grep -q '^PATH=.*testaddition$') +systemctl show-environment | grep '^FOO=$' && exit 1 +systemctl show-environment | grep '^PATH=.*testaddition$' && exit 1 systemctl show-environment | grep -q '^PATH=' echo OK > /testok diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index 3618bee7fb..d79d054fcd 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -32,7 +32,7 @@ test -d /var/lib/testservice test -d /var/cache/testservice test -d /var/log/testservice -! systemctl clean testservice +systemctl clean testservice && { echo 'unexpected success'; exit 1; } systemctl stop testservice @@ -107,7 +107,7 @@ test -L /var/lib/testservice test -L /var/cache/testservice test -L /var/log/testservice -! systemctl clean testservice +systemctl clean testservice && { echo 'unexpected success'; exit 1; } systemctl stop testservice @@ -196,7 +196,7 @@ test -d /var/lib/hoge test -d /var/cache/hoge test -d /var/log/hoge -! systemctl clean tmp-hoge.mount +systemctl clean tmp-hoge.mount && { echo 'unexpected success'; exit 1; } test -d /etc/hoge test -d /run/hoge @@ -272,7 +272,7 @@ test -d /var/lib/testsocket test -d /var/cache/testsocket test -d /var/log/testsocket -! systemctl clean testservice.socket +systemctl clean testservice.socket && { echo 'unexpected success'; exit 1; } systemctl stop testservice.socket diff --git a/test/units/testsuite-34.sh b/test/units/testsuite-34.sh index 596fc15ee8..827eafc433 100755 --- a/test/units/testsuite-34.sh +++ b/test/units/testsuite-34.sh @@ -9,7 +9,8 @@ systemd-analyze log-target console systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz touch /var/lib/zzz/test systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -d /var/lib/zzz test ! -L /var/lib/zzz @@ -20,7 +21,8 @@ test ! -f /var/lib/zzz/test-missing # Convert to DynamicUser=1 systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -L /var/lib/zzz test -d /var/lib/private/zzz @@ -31,7 +33,8 @@ test ! -f /var/lib/zzz/test-missing # Convert back systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -d /var/lib/zzz test ! -L /var/lib/zzz diff --git a/test/units/testsuite-39.sh b/test/units/testsuite-39.sh index eb7363fa6a..0b0cfc5aa5 100755 --- a/test/units/testsuite-39.sh +++ b/test/units/testsuite-39.sh @@ -21,7 +21,7 @@ systemctl daemon-reload systemctl start $SERVICE_NAME systemctl status $SERVICE_NAME # The reload SHOULD fail but SHOULD NOT affect the service state -! systemctl reload $SERVICE_NAME +systemctl reload $SERVICE_NAME && { echo 'unexpected success'; exit 1; } systemctl status $SERVICE_NAME systemctl stop $SERVICE_NAME @@ -39,7 +39,7 @@ systemctl daemon-reload systemctl start $SERVICE_NAME systemctl status $SERVICE_NAME # The reload SHOULD fail but SHOULD NOT affect the service state -! systemctl reload $SERVICE_NAME +systemctl reload $SERVICE_NAME && { echo 'unexpected success'; exit 1; } systemctl status $SERVICE_NAME systemctl stop $SERVICE_NAME diff --git a/test/units/testsuite-41.sh b/test/units/testsuite-41.sh index 81fa1716f1..7caf99be24 100755 --- a/test/units/testsuite-41.sh +++ b/test/units/testsuite-41.sh @@ -9,7 +9,8 @@ systemd-analyze log-level debug systemd-analyze log-target console # test one: Restart=on-failure should restart the service -! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" +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 [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break @@ -25,7 +26,13 @@ TMP_FILE="/tmp/test-41-oneshot-restart-test" # test two: make sure StartLimitBurst correctly limits the number of restarts # and restarts execution of the unit from the first ExecStart= -! systemd-run --unit=two -p StartLimitIntervalSec=120 -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" +systemd-run --unit=two \ + -p StartLimitIntervalSec=120 \ + -p StartLimitBurst=3 \ + -p Type=oneshot \ + -p Restart=on-failure \ + -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" \ + && { echo 'unexpected success'; exit 1; } # wait for at least 3 restarts for ((secs=0; secs<$MAX_SECS; secs++)); do diff --git a/test/units/testsuite-42.sh b/test/units/testsuite-42.sh index 087e2cb294..155c3c7384 100755 --- a/test/units/testsuite-42.sh +++ b/test/units/testsuite-42.sh @@ -6,13 +6,15 @@ systemd-analyze log-level debug systemd-run --unit=simple1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple1' true test -f /run/simple1 -! systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false +systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false \ + && { echo 'unexpected success'; exit 1; } test -f /run/simple2 systemd-run --unit=exec1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec1' sleep 1 test -f /run/exec1 -! systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' +systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' \ + && { echo 'unexpected success'; exit 1; } test -f /run/exec2 cat > /tmp/forking1.sh < Date: Thu, 8 Apr 2021 00:09:55 +0200 Subject: [PATCH 07/12] TEST-*: use spacing before redirection operator, but not after MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit << EOF → < foo < bar → >foo /dev/null -do_test "$@" 52 > /tmp/honorfirstshutdown.log +do_test "$@" 52 >/tmp/honorfirstshutdown.log diff --git a/test/test-execute/exec-standardoutput-append.service b/test/test-execute/exec-standardoutput-append.service index 8983bb056b..2118bfc2a6 100644 --- a/test/test-execute/exec-standardoutput-append.service +++ b/test/test-execute/exec-standardoutput-append.service @@ -2,8 +2,8 @@ Description=Test for StandardOutput=append: [Service] -ExecStartPre=sh -c 'printf "hello\n" > /tmp/test-exec-standardoutput-output' -ExecStartPre=sh -c 'printf "hello\nhello\n" > /tmp/test-exec-standardoutput-expected' +ExecStartPre=sh -c 'printf "hello\n" >/tmp/test-exec-standardoutput-output' +ExecStartPre=sh -c 'printf "hello\nhello\n" >/tmp/test-exec-standardoutput-expected' StandardInput=data StandardInputText=hello StandardOutput=append:/tmp/test-exec-standardoutput-output diff --git a/test/test-execute/exec-standardoutput-file.service b/test/test-execute/exec-standardoutput-file.service index 71e2604b94..8d484a456e 100644 --- a/test/test-execute/exec-standardoutput-file.service +++ b/test/test-execute/exec-standardoutput-file.service @@ -2,8 +2,8 @@ Description=Test for StandardOutput=file: [Service] -ExecStartPre=sh -c 'printf "nooo\nhello\n" > /tmp/test-exec-standardoutput-output' -ExecStartPre=sh -c 'printf "hello\nello\n" > /tmp/test-exec-standardoutput-expected' +ExecStartPre=sh -c 'printf "nooo\nhello\n" >/tmp/test-exec-standardoutput-output' +ExecStartPre=sh -c 'printf "hello\nello\n" >/tmp/test-exec-standardoutput-expected' StandardInput=data StandardInputText=hello StandardOutput=file:/tmp/test-exec-standardoutput-output diff --git a/test/test-execute/exec-standardoutput-truncate.service b/test/test-execute/exec-standardoutput-truncate.service index 4b4bb87b75..8d6ea2769f 100644 --- a/test/test-execute/exec-standardoutput-truncate.service +++ b/test/test-execute/exec-standardoutput-truncate.service @@ -2,8 +2,8 @@ Description=Test for StandardOutput=truncate: [Service] -ExecStartPre=sh -c 'printf "hello\n" > /tmp/test-exec-standardoutput-output' -ExecStartPre=sh -c 'printf "hi\n" > /tmp/test-exec-standardoutput-expected' +ExecStartPre=sh -c 'printf "hello\n" >/tmp/test-exec-standardoutput-output' +ExecStartPre=sh -c 'printf "hi\n" >/tmp/test-exec-standardoutput-expected' StandardInput=data StandardInputText=hi StandardOutput=truncate:/tmp/test-exec-standardoutput-output diff --git a/test/test-functions b/test/test-functions index 6b94058fd3..063a6096fd 100644 --- a/test/test-functions +++ b/test/test-functions @@ -503,13 +503,13 @@ install_verity_minimal() { ln -s ../usr/lib/os-release $initdir/etc/os-release touch $initdir/etc/machine-id $initdir/etc/resolv.conf touch $initdir/opt/some_file - echo MARKER=1 >> $initdir/usr/lib/os-release - echo -e "[Service]\nExecStartPre=cat /usr/lib/os-release\nExecStart=sleep 120" > $initdir/usr/lib/systemd/system/app0.service + echo MARKER=1 >>$initdir/usr/lib/os-release + echo -e "[Service]\nExecStartPre=cat /usr/lib/os-release\nExecStart=sleep 120" >$initdir/usr/lib/systemd/system/app0.service cp $initdir/usr/lib/systemd/system/app0.service $initdir/usr/lib/systemd/system/app0-foo.service mksquashfs $initdir $oldinitdir/usr/share/minimal_0.raw veritysetup format $oldinitdir/usr/share/minimal_0.raw $oldinitdir/usr/share/minimal_0.verity | \ - grep '^Root hash:' | cut -f2 | tr -d '\n' > $oldinitdir/usr/share/minimal_0.roothash + grep '^Root hash:' | cut -f2 | tr -d '\n' >$oldinitdir/usr/share/minimal_0.roothash sed -i "s/MARKER=1/MARKER=2/g" $initdir/usr/lib/os-release rm $initdir/usr/lib/systemd/system/app0-foo.service @@ -517,7 +517,7 @@ install_verity_minimal() { mksquashfs $initdir $oldinitdir/usr/share/minimal_1.raw veritysetup format $oldinitdir/usr/share/minimal_1.raw $oldinitdir/usr/share/minimal_1.verity | \ - grep '^Root hash:' | cut -f2 | tr -d '\n' > $oldinitdir/usr/share/minimal_1.roothash + grep '^Root hash:' | cut -f2 | tr -d '\n' >$oldinitdir/usr/share/minimal_1.roothash # Rolling distros like Arch do not set VERSION_ID local version_id="" @@ -527,42 +527,42 @@ install_verity_minimal() { export initdir=$TESTDIR/app0 mkdir -p $initdir/usr/lib/extension-release.d $initdir/usr/lib/systemd/system $initdir/opt - grep "^ID=" $os_release > $initdir/usr/lib/extension-release.d/extension-release.app0 - echo "${version_id}" >> $initdir/usr/lib/extension-release.d/extension-release.app0 - cat < $initdir/usr/lib/systemd/system/app0.service + grep "^ID=" $os_release >$initdir/usr/lib/extension-release.d/extension-release.app0 + echo "${version_id}" >>$initdir/usr/lib/extension-release.d/extension-release.app0 + cat <$initdir/usr/lib/systemd/system/app0.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/opt/script0.sh EOF - cat < $initdir/opt/script0.sh + cat <$initdir/opt/script0.sh #!/bin/bash set -e test -e /usr/lib/os-release cat /usr/lib/extension-release.d/extension-release.app0 EOF chmod +x $initdir/opt/script0.sh - echo MARKER=1 > $initdir/usr/lib/systemd/system/some_file + echo MARKER=1 >$initdir/usr/lib/systemd/system/some_file mksquashfs $initdir $oldinitdir/usr/share/app0.raw export initdir=$TESTDIR/app1 mkdir -p $initdir/usr/lib/extension-release.d $initdir/usr/lib/systemd/system $initdir/opt - grep "^ID=" $os_release > $initdir/usr/lib/extension-release.d/extension-release.app1 - echo "${version_id}" >> $initdir/usr/lib/extension-release.d/extension-release.app1 - cat < $initdir/usr/lib/systemd/system/app1.service + grep "^ID=" $os_release >$initdir/usr/lib/extension-release.d/extension-release.app1 + echo "${version_id}" >>$initdir/usr/lib/extension-release.d/extension-release.app1 + cat <$initdir/usr/lib/systemd/system/app1.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/opt/script1.sh EOF - cat < $initdir/opt/script1.sh + cat <$initdir/opt/script1.sh #!/bin/bash set -e test -e /usr/lib/os-release cat /usr/lib/extension-release.d/extension-release.app1 EOF chmod +x $initdir/opt/script1.sh - echo MARKER=1 > $initdir/usr/lib/systemd/system/other_file + echo MARKER=1 >$initdir/usr/lib/systemd/system/other_file mksquashfs $initdir $oldinitdir/usr/share/app1.raw ) } @@ -700,7 +700,7 @@ if [[ "$ASAN_COMPILER" == "clang" ]]; then # Let's add the ASan DSO's path to the dynamic linker's cache. This is pretty # unnecessary for gcc & libasan, however, for clang this is crucial, as its # runtime ASan DSO is in a non-standard (library) path. - echo "${ASAN_RT_PATH%/*}" > /etc/ld.so.conf.d/asan-path-override.conf + echo "${ASAN_RT_PATH%/*}" >/etc/ld.so.conf.d/asan-path-override.conf ldconfig fi echo DefaultEnvironment=\$DEFAULT_ENVIRONMENT >>/etc/systemd/system.conf @@ -741,7 +741,7 @@ printf "[Service]\nEnvironment=ASAN_OPTIONS=leak_check_at_exit=false\n" >/etc/sy # they're uninstrumented (like dmsetup). Let's add a simple rule which sets # LD_PRELOAD to the ASan RT library to fix this. mkdir -p /etc/udev/rules.d -cat > /etc/udev/rules.d/00-set-LD_PRELOAD.rules << INNER_EOF +cat >/etc/udev/rules.d/00-set-LD_PRELOAD.rules <> $initdir/etc/systemd/system.conf + echo LogLevel=debug >>$initdir/etc/systemd/system.conf # store coredumps in journal - echo Storage=journal >> $initdir/etc/systemd/coredump.conf + echo Storage=journal >>$initdir/etc/systemd/coredump.conf } get_ldpath() { @@ -1174,12 +1174,12 @@ install_config_files() { inst_any /etc/os-release /usr/lib/os-release inst /etc/localtime # we want an empty environment - > $initdir/etc/environment - > $initdir/etc/machine-id - > $initdir/etc/resolv.conf + >$initdir/etc/environment + >$initdir/etc/machine-id + >$initdir/etc/resolv.conf # set the hostname - echo systemd-testsuite > $initdir/etc/hostname + echo systemd-testsuite >$initdir/etc/hostname # let's set up just one image with the traditional verbose output if [ ${IMAGE_NAME} != "basic" ]; then @@ -1202,9 +1202,9 @@ install_debug_tools() { # Set default TERM from vt220 to linux, so at least basic key shortcuts work local _getty_override="$initdir/etc/systemd/system/serial-getty@.service.d" mkdir -p "$_getty_override" - echo -e "[Service]\nEnvironment=TERM=linux" > "$_getty_override/default-TERM.conf" + echo -e "[Service]\nEnvironment=TERM=linux" >"$_getty_override/default-TERM.conf" - cat > "$initdir/etc/motd" << EOF + cat >"$initdir/etc/motd" < $initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf <$initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf < @@ -1987,7 +1987,7 @@ install_kmod_with_fw() { fi [ -d "$initdir/.kernelmodseen" ] && \ - > "$initdir/.kernelmodseen/${1##*/}" + >"$initdir/.kernelmodseen/${1##*/}" inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \ || return $? @@ -2059,11 +2059,11 @@ filter_kernel_modules_by_path () ( for _modname in $(eval $_filtercmd); do case $_modname in *.ko) "$2" "$_modname" && echo "$_modname";; - *.ko.gz) gzip -dc "$_modname" > $initdir/$$.ko + *.ko.gz) gzip -dc "$_modname" >$initdir/$$.ko $2 $initdir/$$.ko && echo "$_modname" rm -f $initdir/$$.ko ;; - *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko + *.ko.xz) xz -dc "$_modname" >$initdir/$$.ko $2 $initdir/$$.ko && echo "$_modname" rm -f $initdir/$$.ko ;; @@ -2276,7 +2276,7 @@ test_setup() { fi local hook_defined=1 - if declare -f -F test_append_files > /dev/null; then + if declare -f -F test_append_files >/dev/null; then hook_defined=$? fi diff --git a/test/testsuite-28.units/specifier-j-wants.service b/test/testsuite-28.units/specifier-j-wants.service index facf5577be..766a454d6a 100644 --- a/test/testsuite-28.units/specifier-j-wants.service +++ b/test/testsuite-28.units/specifier-j-wants.service @@ -7,4 +7,4 @@ After=testsuite-28-pre.service [Service] Type=oneshot ExecStart=test -f /tmp/test-specifier-j-%j -ExecStart=sh -c 'echo OK > /testok' +ExecStart=sh -c 'echo OK >/testok' diff --git a/test/testsuite-52.units/testsuite-52.sh b/test/testsuite-52.units/testsuite-52.sh index 9cccf1b6c1..e10bf56110 100755 --- a/test/testsuite-52.units/testsuite-52.sh +++ b/test/testsuite-52.units/testsuite-52.sh @@ -3,7 +3,7 @@ set -ex set -o pipefail if ! test -x /usr/lib/systemd/tests/testdata/units/test-honor-first-shutdown.sh ; then - echo "honor-first-shutdown script not found - FAIL" > /testok + echo "honor-first-shutdown script not found - FAIL" >/testok exit 0 fi @@ -13,6 +13,6 @@ systemd-analyze log-target console systemctl enable test-honor-first-shutdown.service systemctl start test-honor-first-shutdown.service -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-03.sh b/test/units/testsuite-03.sh index ec731aa11b..5a2dadd6b8 100755 --- a/test/units/testsuite-03.sh +++ b/test/units/testsuite-03.sh @@ -6,9 +6,9 @@ set -ex systemctl start --no-block hello-after-sleep.target -systemctl list-jobs > /root/list-jobs.txt +systemctl list-jobs >/root/list-jobs.txt while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do - systemctl list-jobs > /root/list-jobs.txt + systemctl list-jobs >/root/list-jobs.txt done grep 'hello\.service.*waiting' /root/list-jobs.txt @@ -22,7 +22,7 @@ ELAPSED=$(($END_SEC-$START_SEC)) test "$ELAPSED" -lt 3 # sleep should still be running, hello not. -systemctl list-jobs > /root/list-jobs.txt +systemctl list-jobs >/root/list-jobs.txt grep 'sleep\.service.*running' /root/list-jobs.txt grep 'hello\.service' /root/list-jobs.txt && exit 1 systemctl stop sleep.service hello-after-sleep.target @@ -58,13 +58,13 @@ systemctl stop --job-mode=replace-irreversibly unstoppable.service systemctl start unstoppable.service # Test waiting for a started unit(s) to terminate again -cat < /run/systemd/system/wait2.service +cat </run/systemd/system/wait2.service [Unit] Description=Wait for 2 seconds [Service] ExecStart=/bin/sh -ec 'sleep 2' EOF -cat < /run/systemd/system/wait5fail.service +cat </run/systemd/system/wait5fail.service [Unit] Description=Wait for 5 seconds and fail [Service] diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index f464f61a36..a2a1292380 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -63,15 +63,15 @@ grep '^FOO=' /output && { echo 'unexpected success'; exit 1; } grep '^SYSLOG_FACILITY=' /output && { echo 'unexpected success'; exit 1; } # `-b all` negates earlier use of -b (-b and -m are otherwise exclusive) -journalctl -b -1 -b all -m > /dev/null +journalctl -b -1 -b all -m >/dev/null # -b always behaves like -b0 -journalctl -q -b-1 -b0 | head -1 > /expected -journalctl -q -b-1 -b | head -1 > /output +journalctl -q -b-1 -b0 | head -1 >/expected +journalctl -q -b-1 -b | head -1 >/output cmp /expected /output # ... even when another option follows (both of these should fail due to -m) -{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 > /expected -{ journalctl -ball -b -m 2>&1 || :; } | head -1 > /output +{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 >/expected +{ journalctl -ball -b -m 2>&1 || :; } | head -1 >/output cmp /expected /output # https://github.com/systemd/systemd/issues/13708 diff --git a/test/units/testsuite-12.sh b/test/units/testsuite-12.sh index b5888a255b..7e7b0ec25a 100755 --- a/test/units/testsuite-12.sh +++ b/test/units/testsuite-12.sh @@ -14,7 +14,7 @@ SocketGroup=adm SocketMode=0660 EOF -cat <<'EOF' > /run/systemd/system/test12@.service +cat <<'EOF' >/run/systemd/system/test12@.service [Unit] Description=Test service [Service] diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index 1844323d2f..3e66aa9d54 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -51,9 +51,9 @@ function check_norbind { local _root="/var/lib/machines/testsuite-13.norbind-path" rm -rf "$_root" mkdir -p /tmp/binddir/subdir - echo -n "outer" > /tmp/binddir/subdir/file + echo -n "outer" >/tmp/binddir/subdir/file mount -t tmpfs tmpfs /tmp/binddir/subdir - echo -n "inner" > /tmp/binddir/subdir/file + 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' } @@ -73,7 +73,7 @@ if [ -n "${VERSION_ID:+set}" ] && [ "${VERSION_ID}" != "${container_host_version if [ -n "${BUILD_ID:+set}" ] && [ "${BUILD_ID}" != "${container_host_build_id}" ]; then exit 1; fi if [ -n "${VARIANT_ID:+set}" ] && [ "${VARIANT_ID}" != "${container_host_variant_id}" ]; then exit 1; fi cd /tmp; (cd /run/host; md5sum os-release) | md5sum -c -if echo test >> /run/host/os-release; then exit 1; fi +if echo test >>/run/host/os-release; then exit 1; fi ' local _os_release_source="/etc/os-release" @@ -82,7 +82,7 @@ if echo test >> /run/host/os-release; then exit 1; fi 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 + 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" @@ -96,7 +96,7 @@ 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 [Service] Type=notify ExecStart=systemd-nspawn $SUSE_OPTS -D /testsuite-13.nc-container --notify-ready=no /bin/sh -x -e -c "$_cmd" diff --git a/test/units/testsuite-15.sh b/test/units/testsuite-15.sh index 23a39bf090..fc392c584d 100755 --- a/test/units/testsuite-15.sh +++ b/test/units/testsuite-15.sh @@ -165,7 +165,7 @@ test_hierarchical_dropins () { echo " [Service] ExecCondition=/bin/echo $dropin - " > /usr/lib/systemd/system/$dropin/override.conf + " >/usr/lib/systemd/system/$dropin/override.conf systemctl daemon-reload check_ok a-b-c ExecCondition "/bin/echo $dropin" done diff --git a/test/units/testsuite-17.01.sh b/test/units/testsuite-17.01.sh index 573ad41079..8be27d9507 100755 --- a/test/units/testsuite-17.01.sh +++ b/test/units/testsuite-17.01.sh @@ -19,7 +19,7 @@ while : ; do sleep .5 done -cat > /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < "${test_rule}" - echo "event_timeout=30" >> /etc/udev/udev.conf - echo "timeout_signal=SIGABRT" >> /etc/udev/udev.conf + echo 'KERNEL=="lo", SUBSYSTEM=="net", PROGRAM=="/bin/sleep 60"' >"${test_rule}" + echo "event_timeout=30" >>/etc/udev/udev.conf + echo "timeout_signal=SIGABRT" >>/etc/udev/udev.conf systemctl restart systemd-udevd.service } @@ -25,7 +25,7 @@ teardown() { run_test() { since="$(date +%T)" - echo add > /sys/class/net/lo/uevent + echo add >/sys/class/net/lo/uevent for n in {1..20}; do sleep 5 diff --git a/test/units/testsuite-17.04.sh b/test/units/testsuite-17.04.sh index c799936c0a..428aa81332 100755 --- a/test/units/testsuite-17.04.sh +++ b/test/units/testsuite-17.04.sh @@ -11,7 +11,7 @@ mkdir -p /run/udev/rules.d/ udevadm info /dev/null | grep -q -v 'E: TAGS=.*:changed:.*' && udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:changed:.*' -cat > /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /firstphase + echo OK >/firstphase systemd-run --wait -p SuccessAction=reboot true else - echo OK > /testok + echo OK >/testok systemd-run --wait -p FailureAction=poweroff false fi diff --git a/test/units/testsuite-19.sh b/test/units/testsuite-19.sh index 57831c267f..dea2f4ba1f 100755 --- a/test/units/testsuite-19.sh +++ b/test/units/testsuite-19.sh @@ -34,6 +34,6 @@ else echo "Skipping TEST-19-DELEGATE, as the kernel doesn't actually support cgroup v2" >&2 fi -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index 0e0feded39..6003e4f181 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -71,7 +71,7 @@ disown sleep infinity & disown -echo \$MAINPID > /run/mainpidsh/pid +echo \$MAINPID >/run/mainpidsh/pid EOF chmod +x /tmp/test20-mainpid.sh @@ -95,7 +95,7 @@ disown sleep infinity & disown -echo \$MAINPID > /run/mainpidsh2/pid +echo \$MAINPID >/run/mainpidsh2/pid chown 1001:1001 /run/mainpidsh2/pid EOF chmod +x /tmp/test20-mainpid2.sh @@ -140,10 +140,10 @@ 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 -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-23.sh b/test/units/testsuite-23.sh index ebee20a65a..a215237562 100755 --- a/test/units/testsuite-23.sh +++ b/test/units/testsuite-23.sh @@ -29,6 +29,6 @@ systemctl stop seven.service systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-25.sh b/test/units/testsuite-25.sh index ef27e2dfbf..d4d2e0f953 100755 --- a/test/units/testsuite-25.sh +++ b/test/units/testsuite-25.sh @@ -67,7 +67,7 @@ mkdir /var/tmp/scratch mv /var/tmp/testimage.raw /var/tmp/scratch/ touch /var/tmp/scratch/anotherfile mkdir /var/tmp/scratch/adirectory -echo "piep" > /var/tmp/scratch/adirectory/athirdfile +echo "piep" >/var/tmp/scratch/adirectory/athirdfile # Test import-fs machinectl import-fs /var/tmp/scratch/ @@ -138,6 +138,6 @@ machinectl remove scratch5 test ! -f /var/lib/machines/scratch5 machinectl image-status scratch5 && { echo 'unexpected success'; exit 1; } -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh index 22bd22c2b0..9c1abc5916 100755 --- a/test/units/testsuite-26.sh +++ b/test/units/testsuite-26.sh @@ -26,6 +26,6 @@ systemctl show-environment | grep '^FOO=$' && exit 1 systemctl show-environment | grep '^PATH=.*testaddition$' && exit 1 systemctl show-environment | grep -q '^PATH=' -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-29.sh b/test/units/testsuite-29.sh index 2e55c275bf..4e91aa7336 100755 --- a/test/units/testsuite-29.sh +++ b/test/units/testsuite-29.sh @@ -93,6 +93,6 @@ umount /tmp/overlay umount /tmp/rootdir umount /tmp/app1 -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-30.sh b/test/units/testsuite-30.sh index 425f153c3b..cb3b46d2cb 100755 --- a/test/units/testsuite-30.sh +++ b/test/units/testsuite-30.sh @@ -26,6 +26,6 @@ while test ! -f /tmp/clock-changed ; do sleep .5 ; done systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-31.sh b/test/units/testsuite-31.sh index fcff82d804..42873bfd83 100755 --- a/test/units/testsuite-31.sh +++ b/test/units/testsuite-31.sh @@ -6,5 +6,5 @@ if journalctl -b -t systemd --grep '\.device: Changed plugged -> dead'; then exit 1 fi -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index d79d054fcd..929c76062b 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -4,7 +4,7 @@ set -ex set -o pipefail -cat > /etc/systemd/system/testservice.service </etc/systemd/system/testservice.service < /etc/systemd/system/testservice.service </etc/systemd/system/testservice.service < /etc/systemd/system/tmp-hoge.mount </etc/systemd/system/tmp-hoge.mount < /etc/systemd/system/testservice.socket </etc/systemd/system/testservice.socket < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-34.sh b/test/units/testsuite-34.sh index 827eafc433..ca54a01f40 100755 --- a/test/units/testsuite-34.sh +++ b/test/units/testsuite-34.sh @@ -44,6 +44,6 @@ test ! -f /var/lib/zzz/test-missing systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-36.sh b/test/units/testsuite-36.sh index f5579ce825..3decf4b3f3 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() { @@ -64,21 +64,21 @@ checkNUMA() { } writePID1NUMAPolicy() { - echo [Manager] > $confDir/numa.conf - echo NUMAPolicy=$1 >> $confDir/numa.conf - echo NUMAMask=$2>> $confDir/numa.conf + echo [Manager] >$confDir/numa.conf + echo NUMAPolicy=$1 >>$confDir/numa.conf + echo NUMAMask=$2 >>$confDir/numa.conf } writeTestUnit() { mkdir -p $testUnitFile.d/ - echo [Service] > $testUnitFile - echo ExecStart=/bin/sleep 3600 >> $testUnitFile + echo [Service] >$testUnitFile + echo ExecStart=/bin/sleep 3600 >>$testUnitFile } writeTestUnitNUMAPolicy() { - echo [Service] > $testUnitNUMAConf - echo NUMAPolicy=$1 >> $testUnitNUMAConf - echo NUMAMask=$2>> $testUnitNUMAConf + echo [Service] >$testUnitNUMAConf + echo NUMAPolicy=$1 >>$testUnitNUMAConf + echo NUMAMask=$2 >>$testUnitNUMAConf systemctl daemon-reload } @@ -115,13 +115,13 @@ pid1StopUnit() { systemctlCheckNUMAProperties() { local LOGFILE="$(mktemp)" - systemctl show -p NUMAPolicy $1 > "$LOGFILE" + systemctl show -p NUMAPolicy $1 >"$LOGFILE" grep "NUMAPolicy=$2" "$LOGFILE" - > "$LOGFILE" + >"$LOGFILE" if [ -n "$3" ]; then - systemctl show -p NUMAMask $1 > "$LOGFILE" + systemctl show -p NUMAMask $1 >"$LOGFILE" grep "NUMAMask=$3" "$LOGFILE" fi } @@ -281,7 +281,7 @@ else 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" @@ -336,6 +336,6 @@ systemctl daemon-reload systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-37.sh b/test/units/testsuite-37.sh index 696b8cdeef..3ae0cb32fe 100755 --- a/test/units/testsuite-37.sh +++ b/test/units/testsuite-37.sh @@ -14,6 +14,6 @@ systemctl restart tmp-aaa.mount test -e /run/hoge/foo test ! -e /tmp/aaa/bbb -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-38.sh b/test/units/testsuite-38.sh index 18b7bd6dce..707fd8a864 100755 --- a/test/units/testsuite-38.sh +++ b/test/units/testsuite-38.sh @@ -245,7 +245,7 @@ test_preserve_state() { echo "Test that freezer state is preserved when recursive freezing is initiated from outside (e.g. by manager up the tree):" echo -n " - freeze from outside: " - echo 1 > /sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 1 >/sys/fs/cgroup/"${slice}"/cgroup.freeze # Give kernel some time to freeze the slice sleep 1 @@ -259,7 +259,7 @@ test_preserve_state() { echo "[ OK ]" echo -n " - thaw from outside: " - echo 0 > /sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 0 >/sys/fs/cgroup/"${slice}"/cgroup.freeze sleep 1 check_freezer_state "${unit}" "running" @@ -271,8 +271,8 @@ test_preserve_state() { echo -n " - thaw from outside while inner service is frozen: " systemctl freeze "$unit" check_freezer_state "${unit}" "frozen" - echo 1 > /sys/fs/cgroup/"${slice}"/cgroup.freeze - echo 0 > /sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 1 >/sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 0 >/sys/fs/cgroup/"${slice}"/cgroup.freeze check_freezer_state "${slice}" "running" check_freezer_state "${unit}" "frozen" echo "[ OK ]" @@ -293,5 +293,5 @@ test -e /sys/fs/cgroup/system.slice/cgroup.freeze && { test_preserve_state } -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-39.sh b/test/units/testsuite-39.sh index 0b0cfc5aa5..5c0680878f 100755 --- a/test/units/testsuite-39.sh +++ b/test/units/testsuite-39.sh @@ -11,7 +11,7 @@ SERVICE_PATH="$(mktemp /etc/systemd/system/execreloadXXX.service)" SERVICE_NAME="${SERVICE_PATH##*/}" echo "[#1] Failing ExecReload= should not kill the service" -cat > "$SERVICE_PATH" << EOF +cat >"$SERVICE_PATH" < "$SERVICE_PATH" << EOF +cat >"$SERVICE_PATH" < "$SERVICE_PATH" << EOF +cat >"$SERVICE_PATH" < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-40.sh b/test/units/testsuite-40.sh index 957d22031a..7593401369 100755 --- a/test/units/testsuite-40.sh +++ b/test/units/testsuite-40.sh @@ -41,6 +41,6 @@ done systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-41.sh b/test/units/testsuite-41.sh index 7caf99be24..0a43f8ba57 100755 --- a/test/units/testsuite-41.sh +++ b/test/units/testsuite-41.sh @@ -51,6 +51,6 @@ fi systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-42.sh b/test/units/testsuite-42.sh index 155c3c7384..ca13c5dec5 100755 --- a/test/units/testsuite-42.sh +++ b/test/units/testsuite-42.sh @@ -17,7 +17,7 @@ systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=t && { echo 'unexpected success'; exit 1; } test -f /run/exec2 -cat > /tmp/forking1.sh </tmp/forking1.sh < /tmp/forking2.sh </tmp/forking2.sh < /tmp/notify1.sh </tmp/notify1.sh < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-43.sh b/test/units/testsuite-43.sh index ec84868a21..d9453e81a1 100755 --- a/test/units/testsuite-43.sh +++ b/test/units/testsuite-43.sh @@ -63,6 +63,6 @@ runas testuser systemd-run --wait --user --unit=test-protect-home-yes \ systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-44.sh b/test/units/testsuite-44.sh index 97541634d0..78022cb545 100755 --- a/test/units/testsuite-44.sh +++ b/test/units/testsuite-44.sh @@ -6,14 +6,14 @@ systemd-analyze log-level debug systemd-run -p LogNamespace=foobar echo "hello world" journalctl --namespace=foobar --sync -journalctl --namespace=foobar > /tmp/hello-world -journalctl > /tmp/no-hello-world +journalctl --namespace=foobar >/tmp/hello-world +journalctl >/tmp/no-hello-world grep "hello world" /tmp/hello-world ! grep "hello world" /tmp/no-hello-world systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-46.sh b/test/units/testsuite-46.sh index 00bbdf507e..5390acabf3 100755 --- a/test/units/testsuite-46.sh +++ b/test/units/testsuite-46.sh @@ -4,7 +4,7 @@ set -o pipefail # Check if homectl is installed, and if it isn't bail out early instead of failing if ! test -x /usr/bin/homectl ; then - echo OK > /testok + echo OK >/testok exit 0 fi @@ -76,6 +76,6 @@ homectl remove test-user systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-47-repro.sh b/test/units/testsuite-47-repro.sh index 8c34289c52..b008f52e95 100755 --- a/test/units/testsuite-47-repro.sh +++ b/test/units/testsuite-47-repro.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash sleep infinity & -echo $! > /leakedtestpid +echo $! >/leakedtestpid wait $! diff --git a/test/units/testsuite-47.sh b/test/units/testsuite-47.sh index 50034cf3d9..f8529083a2 100755 --- a/test/units/testsuite-47.sh +++ b/test/units/testsuite-47.sh @@ -20,6 +20,6 @@ ps -p "$leaked_pid" && exit 42 systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-48.sh b/test/units/testsuite-48.sh index 03231e71b1..ea84b1d723 100755 --- a/test/units/testsuite-48.sh +++ b/test/units/testsuite-48.sh @@ -3,7 +3,7 @@ # ex: ts=8 sw=4 sts=4 et filetype=sh set -ex -cat > /run/systemd/system/testservice-48.target </run/systemd/system/testservice-48.target < /run/systemd/system/testservice-48.service </run/systemd/system/testservice-48.service < /run/systemd/system/testservice-48.service </run/systemd/system/testservice-48.service < /run/systemd/system/testservice-48.target </run/systemd/system/testservice-48.target < /run/systemd/system/testservice-48.service </run/systemd/system/testservice-48.service < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-49.sh b/test/units/testsuite-49.sh index 07bb20d99c..f92280f884 100755 --- a/test/units/testsuite-49.sh +++ b/test/units/testsuite-49.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -ex -echo "MARKER_FIXED" > /run/testservice-49-fixed +echo "MARKER_FIXED" >/run/testservice-49-fixed mkdir -p /run/inaccessible systemctl start testsuite-49-namespaced.service @@ -11,7 +11,7 @@ set +e systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-fixed /run/inaccessible/testfile_fixed && exit 1 set -e -echo "MARKER_RUNTIME" > /run/testservice-49-runtime +echo "MARKER_RUNTIME" >/run/testservice-49-runtime systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime @@ -38,6 +38,6 @@ set +e systemctl is-active testsuite-49-non-namespaced.service && exit 1 set -e -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh index e2d8ef6da2..c3e7b4f04e 100755 --- a/test/units/testsuite-50.sh +++ b/test/units/testsuite-50.sh @@ -207,7 +207,7 @@ grep -F "squashfs" ${image_dir}/result/c | grep -q -F -v "nosuid" # Adding a new mounts at runtime works if the unit is in the active state, # so use Type=notify to make sure there's no race condition in the test -cat > /run/systemd/system/testservice-50d.service </run/systemd/system/testservice-50d.service < /tmp/ts54-concat + cat '${CREDENTIALS_DIRECTORY}/passwd' '${CREDENTIALS_DIRECTORY}/shadow' '${CREDENTIALS_DIRECTORY}/dog' >/tmp/ts54-concat ( cat /etc/passwd /etc/shadow && echo -n wuff ) | cmp /tmp/ts54-concat rm /tmp/ts54-concat @@ -28,6 +28,6 @@ systemd-run -p LoadCredential=passwd:/etc/passwd \ systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-55.sh b/test/units/testsuite-55.sh index f7896ada42..d73f4b1e7a 100755 --- a/test/units/testsuite-55.sh +++ b/test/units/testsuite-55.sh @@ -6,19 +6,19 @@ systemd-analyze log-level debug systemd-analyze log-target console # Loose checks to ensure the environment has the necessary features for systemd-oomd -[[ -e /proc/pressure ]] || echo "no PSI" >> /skipped +[[ -e /proc/pressure ]] || echo "no PSI" >>/skipped cgroup_type=$(stat -fc %T /sys/fs/cgroup/) if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]; then - echo "no cgroup2" >> /skipped + echo "no cgroup2" >>/skipped fi if [ ! -f /usr/lib/systemd/systemd-oomd ] && [ ! -f /lib/systemd/systemd-oomd ]; then - echo "no oomd" >> /skipped + echo "no oomd" >>/skipped fi [[ -e /skipped ]] && exit 0 || true rm -rf /etc/systemd/system/testsuite-55-testbloat.service.d -echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf +echo "DefaultMemoryPressureDurationSec=5s" >>/etc/systemd/oomd.conf systemctl start testsuite-55-testchill.service systemctl start testsuite-55-testbloat.service @@ -47,8 +47,8 @@ if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down mkdir -p /etc/systemd/system/testsuite-55-testbloat.service.d/ - echo "[Service]" > /etc/systemd/system/testsuite-55-testbloat.service.d/override.conf - echo "ManagedOOMPreference=avoid" >> /etc/systemd/system/testsuite-55-testbloat.service.d/override.conf + echo "[Service]" >/etc/systemd/system/testsuite-55-testbloat.service.d/override.conf + echo "ManagedOOMPreference=avoid" >>/etc/systemd/system/testsuite-55-testbloat.service.d/override.conf systemctl daemon-reload systemctl start testsuite-55-testchill.service @@ -71,6 +71,6 @@ fi systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh index 0b5010b9f9..079da07201 100755 --- a/test/units/testsuite-56.sh +++ b/test/units/testsuite-56.sh @@ -93,6 +93,6 @@ systemd-run --wait --unit=eight -p ExitType=cgroup /tmp/test56-exit-cgroup-uncle systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 From d933ccd30bf1879a3e0df47c4b39021daa6cd01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 09:45:28 +0200 Subject: [PATCH 08/12] TEST-43: fix exit condition testing We were invoking 'systemd-run bash', but the test invoked by bash was not effective. When the result of that check is propagated, the outer command fails. --- test/units/testsuite-43.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/units/testsuite-43.sh b/test/units/testsuite-43.sh index d9453e81a1..f3c0ca4fd2 100755 --- a/test/units/testsuite-43.sh +++ b/test/units/testsuite-43.sh @@ -34,9 +34,10 @@ test -e /home/testuser/works.txt runas testuser systemd-run --wait --user --unit=test-protect-home-read-only \ -p PrivateUsers=yes -p ProtectHome=read-only \ -P bash -c ' - test -e /home/testuser/works.txt - ! touch /home/testuser/blocked.txt - ' + test -e /home/testuser/works.txt || exit 10 + touch /home/testuser/blocked.txt && exit 11 + ' \ + && { echo 'unexpected success'; exit 1; } test ! -e /home/testuser/blocked.txt # Check that tmpfs hides the whole directory @@ -57,9 +58,10 @@ runas testuser systemd-run --wait --user --unit=test-protect-home-yes \ # namespace (no CAP_SETGID in the parent namespace to write the additional # mapping of the user supplied group and thus cannot change groups to an # unmapped group ID) -! runas testuser systemd-run --wait --user --unit=test-group-fail \ +runas testuser systemd-run --wait --user --unit=test-group-fail \ -p PrivateUsers=yes -p Group=daemon \ - -P true + -P true \ + && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info From f49467b959cb612fba053d152b446eff70184d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 09:47:04 +0200 Subject: [PATCH 09/12] TEST-44: fix test We were grepping for 'hello world', and in the namespace we would match on 'hello world', and outside, on 'echo "hello world"'. When the condition check was fixed, the test gave a false positive. --- test/units/testsuite-44.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/units/testsuite-44.sh b/test/units/testsuite-44.sh index 78022cb545..0badb71125 100755 --- a/test/units/testsuite-44.sh +++ b/test/units/testsuite-44.sh @@ -6,11 +6,11 @@ systemd-analyze log-level debug systemd-run -p LogNamespace=foobar echo "hello world" journalctl --namespace=foobar --sync -journalctl --namespace=foobar >/tmp/hello-world -journalctl >/tmp/no-hello-world +journalctl -o cat --namespace=foobar >/tmp/hello-world +journalctl -o cat >/tmp/no-hello-world -grep "hello world" /tmp/hello-world -! grep "hello world" /tmp/no-hello-world +grep "^hello world$" /tmp/hello-world +grep "^hello world$" /tmp/no-hello-world && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info From b9bfa250f2c04caeecd49e54cdbadee3986d64b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 10:34:28 +0200 Subject: [PATCH 10/12] homectl,TEST-46: fix test and fix homectl return value, update docs The usual: the test wasn't testing, so we didn't notice that the command wasn't returning as expected. --- man/homectl.xml | 4 ++++ src/home/homectl.c | 2 +- test/units/testsuite-46.sh | 8 ++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/man/homectl.xml b/man/homectl.xml index 184bdcf6fd..f2858166f7 100644 --- a/man/homectl.xml +++ b/man/homectl.xml @@ -846,6 +846,10 @@ Exit status On success, 0 is returned, a non-zero failure code otherwise. + + When a command is invoked with with, the exit status of the child is + propagated. Effectively, homectl will exit without error if the command is + successfully invoked and finishes successfully. diff --git a/src/home/homectl.c b/src/home/homectl.c index cf1a2d9f9b..a187a75d86 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -3362,4 +3362,4 @@ static int run(int argc, char *argv[]) { return dispatch_verb(argc, argv, verbs, NULL); } -DEFINE_MAIN_FUNCTION(run); +DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); diff --git a/test/units/testsuite-46.sh b/test/units/testsuite-46.sh index 5390acabf3..570780030b 100755 --- a/test/units/testsuite-46.sh +++ b/test/units/testsuite-46.sh @@ -66,11 +66,15 @@ inspect test-user PASSWORD=xEhErW0ndafV4s homectl deactivate test-user inspect test-user -! PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \ + && { echo 'unexpected success'; exit 1; } PASSWORD=xEhErW0ndafV4s homectl with test-user -- touch /home/test-user/xyz PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz PASSWORD=xEhErW0ndafV4s homectl with test-user -- rm /home/test-user/xyz -! PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \ + && { echo 'unexpected success'; exit 1; } homectl remove test-user From 68bb821e21d44e8dff86414fe0ae137ecdbc9934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 10:34:53 +0200 Subject: [PATCH 11/12] TEST-46: simplify lossy diff invocation --- test/units/testsuite-46.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/units/testsuite-46.sh b/test/units/testsuite-46.sh index 570780030b..d3f0f71043 100755 --- a/test/units/testsuite-46.sh +++ b/test/units/testsuite-46.sh @@ -9,17 +9,16 @@ if ! test -x /usr/bin/homectl ; then fi inspect() { - # As updating disk-size-related attributes can take some time on - # some filesystems, let's drop these fields before comparing the - # outputs to avoid unexpected fails. To see the full outputs of both - # homectl & userdbctl (for debugging purposes) drop the fields just - # before the comparison. - homectl inspect $1 | tee /tmp/a - userdbctl user $1 | tee /tmp/b + # As updating disk-size-related attributes can take some time on some + # filesystems, let's drop these fields before comparing the outputs to + # avoid unexpected fails. To see the full outputs of both homectl & + # userdbctl (for debugging purposes) drop the fields just before the + # comparison. + homectl inspect $1 | tee /tmp/a + userdbctl user $1 | tee /tmp/b - local PATTERN='/^\s*Disk (Size|Free|Floor|Ceiling):/d' - diff <(sed -r "$PATTERN" /tmp/a) <(sed -r "$PATTERN" /tmp/b) - rm /tmp/a /tmp/b + diff -I '/^\s*Disk (Size|Free|Floor|Ceiling):/' /tmp/{a,b} + rm /tmp/{a,b} } systemd-analyze log-level debug From b1e1e5ac255285aac2a26467df3a7b934a3f2000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 10:57:40 +0200 Subject: [PATCH 12/12] TEST-17: make the test test '! grep -v' does *not* test that there are no matching lines. Instead, it checks that whether there are any non-matching lines. And of course, for the test to fail, '! grep' cannot be part of an expression with &&. --- test/units/testsuite-17.04.sh | 57 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/test/units/testsuite-17.04.sh b/test/units/testsuite-17.04.sh index 428aa81332..b33d47ef6d 100755 --- a/test/units/testsuite-17.04.sh +++ b/test/units/testsuite-17.04.sh @@ -4,12 +4,9 @@ set -o pipefail mkdir -p /run/udev/rules.d/ -! test -f /run/udev/tags/added/c1:3 && - ! test -f /run/udev/tags/changed/c1:3 && - udevadm info /dev/null | grep -q -v 'E: TAGS=.*:added:.*' && - udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:added:.*' && - udevadm info /dev/null | grep -q -v 'E: TAGS=.*:changed:.*' && - udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:changed:.*' +test ! -f /run/udev/tags/added/c1:3 +test ! -f /run/udev/tags/changed/c1:3 +udevadm info /dev/null | grep -E 'E: (TAGS|CURRENT_TAGS)=.*:(added|changed):' && exit 1 cat >/run/udev/rules.d/50-testsuite.rules <