]> git.ipfire.org Git - thirdparty/systemd.git/commit
test-execute: Fix systemd escaping and shell issues 1834/head
authorFilipe Brandenburger <filbranden@google.com>
Sun, 8 Nov 2015 18:19:45 +0000 (10:19 -0800)
committerFilipe Brandenburger <filbranden@google.com>
Tue, 10 Nov 2015 15:58:29 +0000 (07:58 -0800)
commitcdaf5070480c09a7650589fa02b4d59c0af00112
treeb72102d42e15a30ac0c3ff4c88cad7d00aaea4af
parent8f84882240b776dab07c4ee5aaf2dd1acd8cb45b
test-execute: Fix systemd escaping and shell issues

In most cases, systemd requires escaping $ (for systemd variable
substitution) and % (for specifiers) by doubling them. This was somewhat
of an issue in tests like exec-environment*.service where systemd was
doing the substitutions and we were not really checking that those were
available in the actual environment of the command. Fix that.

Expressions such as `exit $(test ...)` are incorrect. They only work
because $(test ...) will produce no output, so the command will become a
bare "exit" which will exit with the status of the latest executed
command which turns out to be the test... The direct approach is simply
calling "test" as the last command, for which the shell will propagate
the exit status.

One situation where this was breaking tests was on `exit $(test ...) &&
$(test ...) && $(test ...)` where the second and third tests were not
really executing, since the first command is actually `exit` so && was
doing nothing there. Fixed it by just using `test ... && test ... &&
test ...` as it was initially intended.

Pass -x to all shell executions for them to produce useful debugging
output to stderr. Consequently, removed most of the explicit `echo`s
that are no longer needed.

Mark all units as Type=oneshot explicitly.

Also made sure all shell variables are properly quoted.

v2: Added an explicit LC_ALL=C to ionice invocations since some locales
(such as French) will add a space before the colon in the output.

Tested by running `sudo ./test-execute` and confirming all tests enabled
on my system (essentially all of them except for the s390 one) passed.
Tweaked the variables or options or expected values and confirmed the
tests do indeed fail when the values are not exactly the expected ones.

v2: Also tested with `LANG=fr_FR.UTF-8 sudo ./test-execute` to confirm
it still works in a different locale.
37 files changed:
test/test-execute/exec-capabilityboundingset-invert.service
test/test-execute/exec-capabilityboundingset-merge.service
test/test-execute/exec-capabilityboundingset-reset.service
test/test-execute/exec-capabilityboundingset-simple.service
test/test-execute/exec-environment-empty.service
test/test-execute/exec-environment-multiple.service
test/test-execute/exec-environment.service
test/test-execute/exec-environmentfile.service
test/test-execute/exec-group.service
test/test-execute/exec-ignoresigpipe-no.service
test/test-execute/exec-ignoresigpipe-yes.service
test/test-execute/exec-ioschedulingclass-best-effort.service
test/test-execute/exec-ioschedulingclass-idle.service
test/test-execute/exec-ioschedulingclass-none.service
test/test-execute/exec-ioschedulingclass-realtime.service
test/test-execute/exec-oomscoreadjust-negative.service
test/test-execute/exec-oomscoreadjust-positive.service
test/test-execute/exec-personality-s390.service
test/test-execute/exec-personality-x86-64.service
test/test-execute/exec-personality-x86.service
test/test-execute/exec-privatedevices-no.service
test/test-execute/exec-privatedevices-yes.service
test/test-execute/exec-privatenetwork-yes.service
test/test-execute/exec-privatetmp-no.service
test/test-execute/exec-privatetmp-yes.service
test/test-execute/exec-runtimedirectory-mode.service
test/test-execute/exec-runtimedirectory-owner.service
test/test-execute/exec-runtimedirectory.service
test/test-execute/exec-systemcallerrornumber.service
test/test-execute/exec-systemcallfilter-failing.service
test/test-execute/exec-systemcallfilter-failing2.service
test/test-execute/exec-systemcallfilter-not-failing.service
test/test-execute/exec-systemcallfilter-not-failing2.service
test/test-execute/exec-umask-0177.service
test/test-execute/exec-umask-default.service
test/test-execute/exec-user.service
test/test-execute/exec-workingdirectory.service