diff options
author | Michael Biebl <biebl@debian.org> | 2017-12-14 23:22:02 +0100 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2017-12-14 23:22:02 +0100 |
commit | 52ad194e0b816b8273dd8d0fea3e6d467f6ca34e (patch) | |
tree | 1a3b3117e015f200ca0ce23f5ad27be6d0a7b0fb /test | |
parent | f5e65279187b6aa0c0c5a00b14dca9eab441ffb2 (diff) | |
download | systemd-52ad194e0b816b8273dd8d0fea3e6d467f6ca34e.tar.gz |
New upstream version 236
Diffstat (limited to 'test')
69 files changed, 1056 insertions, 162 deletions
diff --git a/test/Makefile.guess b/test/Makefile.guess deleted file mode 100644 index 1916d09a6c..0000000000 --- a/test/Makefile.guess +++ /dev/null @@ -1,14 +0,0 @@ -# Try to guess the build directory: -# we look for subdirectories of ../.. that look like ninja build dirs. - -ifeq ($(BUILD_DIR),) - dirs = $(dir $(wildcard ../../*/.ninja_log)) - ifeq ($(dirs),) - $(error Cannot guess build dir, set BUILD_DIR) - endif - ifneq ($(firstword $(dirs)),$(dirs)) - $(warning Candidates: $(dirs)) - $(error Too many build dirs to pick from, set BUILD_DIR) - endif - BUILD_DIR=$(dirs) -endif diff --git a/test/TEST-01-BASIC/Makefile b/test/TEST-01-BASIC/Makefile index b895de8bcb..3a212a07a9 100644 --- a/test/TEST-01-BASIC/Makefile +++ b/test/TEST-01-BASIC/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup clean run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh index 1280148b58..545602e17a 100755 --- a/test/TEST-02-CRYPTSETUP/test.sh +++ b/test/TEST-02-CRYPTSETUP/test.sh @@ -31,7 +31,7 @@ test_setup() { echo -n test >$TESTDIR/keyfile cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile - mkfs.ext3 -L var /dev/mapper/varcrypt + mkfs.ext4 -L var /dev/mapper/varcrypt mkdir -p $TESTDIR/root mount ${LOOPDEV}p1 $TESTDIR/root mkdir -p $TESTDIR/root/var @@ -67,7 +67,7 @@ EOF cat $initdir/etc/crypttab | ddebug cat >>$initdir/etc/fstab <<EOF -/dev/mapper/varcrypt /var ext3 defaults 0 1 +/dev/mapper/varcrypt /var ext4 defaults 0 1 EOF ) || return 1 diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh index 493ff00ce0..260cae09ab 100755 --- a/test/TEST-04-JOURNAL/test-journal.sh +++ b/test/TEST-04-JOURNAL/test-journal.sh @@ -51,6 +51,18 @@ journalctl --sync journalctl -b -o cat -t "$ID" >/output cmp /expected /output +# --output-fields restricts output +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 -q '^__CURSOR=' /output +grep -q '^MESSAGE=foo$' /output +grep -q '^PRIORITY=6$' /output +! grep -q '^FOO=' /output +! grep -q '^SYSLOG_FACILITY=' /output + # Don't lose streams on restart systemctl start forever-print-hola sleep 3 diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh index e7eb1cb303..2f95e9062d 100755 --- a/test/TEST-10-ISSUE-2467/test.sh +++ b/test/TEST-10-ISSUE-2467/test.sh @@ -3,7 +3,6 @@ # ex: ts=8 sw=4 sts=4 et filetype=sh set -e TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467" -TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions SKIP_INITRD=yes @@ -19,7 +18,7 @@ test_setup() { eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) setup_basic_environment - dracut_install nc true rm + dracut_install true rm # setup the testsuite service cat >$initdir/etc/systemd/system/testsuite.service <<'EOF' @@ -29,13 +28,15 @@ After=multi-user.target [Service] Type=oneshot -ExecStart=/bin/sh -e -x -c 'rm -f /tmp/nonexistent; systemctl start test.socket; echo a | nc -U /run/test.ctl; >/testok' +StandardOutput=tty +StandardError=tty +ExecStart=/bin/sh -e -x -c 'rm -f /tmp/nonexistent; systemctl start test.socket; echo > /run/test.ctl; >/testok' TimeoutStartSec=10s EOF cat >$initdir/etc/systemd/system/test.socket <<'EOF' [Socket] -ListenStream=/run/test.ctl +ListenFIFO=/run/test.ctl EOF cat > $initdir/etc/systemd/system/test.service <<'EOF' @@ -49,6 +50,7 @@ EOF setup_testsuite ) || return 1 + setup_nspawn_root # mask some services that we do not want to run in these tests ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service diff --git a/test/TEST-13-NSPAWN-SMOKE/Makefile b/test/TEST-13-NSPAWN-SMOKE/Makefile index 41cca23c7f..ddcbbc302f 100644 --- a/test/TEST-13-NSPAWN-SMOKE/Makefile +++ b/test/TEST-13-NSPAWN-SMOKE/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh index 7f7380fd62..239c7e0731 100755 --- a/test/TEST-13-NSPAWN-SMOKE/test.sh +++ b/test/TEST-13-NSPAWN-SMOKE/test.sh @@ -18,12 +18,12 @@ test_setup() { eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) setup_basic_environment - dracut_install busybox chmod rmdir unshare + dracut_install busybox chmod rmdir unshare ip cp create-busybox-container $initdir/ ./create-busybox-container $initdir/nc-container - initdir="$initdir/nc-container" dracut_install nc + initdir="$initdir/nc-container" dracut_install nc ip # setup the testsuite service cat >$initdir/etc/systemd/system/testsuite.service <<EOF @@ -34,6 +34,8 @@ After=multi-user.target [Service] ExecStart=/test-nspawn.sh Type=oneshot +StandardOutput=tty +StandardError=tty EOF cat >$initdir/test-nspawn.sh <<'EOF' @@ -107,6 +109,52 @@ function run { [[ "$is_user_ns_supported" = "no" && "$3" = "yes" ]] && return 1 fi + local _netns_opt="--network-namespace-path=/proc/self/ns/net" + + # --network-namespace-path and network-related options cannot be used together + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-interface=lo -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-macvlan=lo -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-ipvlan=lo -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-veth -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-veth-extra=lo -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-bridge=lo -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-zone=zone -b; then + return 1 + fi + + if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --private-network -b; 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" + UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" ip a | grep -E '^1: lo.*DOWN' + local r=$? + ip netns del nspawn_test + + if [ $r -ne 0 ]; then + return 1 + fi + return 0 } diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh index b932060bc2..7342645bc5 100755 --- a/test/TEST-14-MACHINE-ID/test.sh +++ b/test/TEST-14-MACHINE-ID/test.sh @@ -2,7 +2,7 @@ # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh set -e -TEST_DESCRIPTION="Basic systemd setup" +TEST_DESCRIPTION="/etc/machine-id testing" TEST_NO_NSPAWN=1 SKIP_INITRD=yes . $TEST_BASE_DIR/test-functions diff --git a/test/TEST-16-EXTEND-TIMEOUT/Makefile b/test/TEST-16-EXTEND-TIMEOUT/Makefile new file mode 120000 index 0000000000..e9f93b1104 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-16-EXTEND-TIMEOUT/assess.sh b/test/TEST-16-EXTEND-TIMEOUT/assess.sh new file mode 100755 index 0000000000..e7f643f9ad --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/assess.sh @@ -0,0 +1,55 @@ +#!/bin/bash +set -v -x + +rm -f /test.log + +TL=/test.log.XXXXXXXX + +function wait_for() +{ + service=${1} + result=${2:-success} + time=${3:-45} + + while [[ ! -f /${service}.terminated && ! -f /${service}.success && $time -gt 0 ]] + do + sleep 1 + time=$(( $time - 1 )) + done + + if [[ ! -f /${service}.${result} ]] + then + journalctl -u testsuite-${service/_/-}.service >> "${TL}" + fi +} + +# This checks all stages, start, runtime and stop, can be extended by +# EXTEND_TIMEOUT_USEC + +wait_for success_all + +# These check that EXTEND_TIMEOUT_USEC that occurs at greater than the +# extend timeout interval but less then the stage limit (TimeoutStartSec, +# RuntimeMaxSec, TimeoutStopSec) still succeed. + +wait_for success_start +wait_for success_runtime +wait_for success_stop + +# These ensure that EXTEND_TIMEOUT_USEC will still timeout in the +# approprate stage, after the stage limit, when the EXTEND_TIMEOUT_USEC +# message isn't sent within the extend timeout interval. + +wait_for fail_start startfail +wait_for fail_stop stopfail +wait_for fail_runtime runtimefail + +if [[ -f "${TL}" ]] +then + # no mv + cp "${TL}" /test.log + exit 1 +else + touch /testok + exit 0 +fi diff --git a/test/TEST-16-EXTEND-TIMEOUT/extend_timeout_test_service.sh b/test/TEST-16-EXTEND-TIMEOUT/extend_timeout_test_service.sh new file mode 100755 index 0000000000..1fd2768fd2 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/extend_timeout_test_service.sh @@ -0,0 +1,70 @@ +#!/bin/bash +set -x +set -e +set -o pipefail + +# sleep interval (seconds) +sleep_interval=1 +# extend_timeout_interval second(s) +extend_timeout_interval=1 +# number of sleep_intervals before READY=1 +start_intervals=10 +# number of sleep_intervals before exiting +stop_intervals=10 +# run intervals, number of sleep_intervals to run +run_intervals=7 +# service name +SERVICE=unknown + +while [ $# -gt 0 ]; +do + eval ${1%=*}=${1#*=} + shift +done + +# We convert to usec +extend_timeout_interval=$(( $extend_timeout_interval * 1000000 )) + +trap "{ touch /${SERVICE}.terminated; exit 1; }" SIGTERM SIGABRT + +rm -f /${SERVICE}.* +touch /${SERVICE}.startfail + +systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval +while [ $start_intervals -gt 0 ] +do + sleep $sleep_interval + start_intervals=$(( $start_intervals - 1 )) + systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval +done + +systemd-notify --ready --status="Waiting for your request" + +touch /${SERVICE}.runtimefail +rm /${SERVICE}.startfail + +systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval +while [ $run_intervals -gt 0 ] +do + sleep $sleep_interval + run_intervals=$(( $run_intervals - 1 )) + systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval +done + +systemd-notify STOPPING=1 + +touch /${SERVICE}.stopfail +rm /${SERVICE}.runtimefail + +systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval +while [ $stop_intervals -gt 0 ] +do + sleep $sleep_interval + stop_intervals=$(( $stop_intervals - 1 )) + systemd-notify EXTEND_TIMEOUT_USEC=$extend_timeout_interval +done + +touch /${SERVICE}.success +rm /${SERVICE}.stopfail + +exit 0 diff --git a/test/TEST-16-EXTEND-TIMEOUT/test.sh b/test/TEST-16-EXTEND-TIMEOUT/test.sh new file mode 100755 index 0000000000..4544672066 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/test.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +set -e +TEST_DESCRIPTION="EXTEND_TIMEOUT_USEC=usec start/runtime/stop tests" +SKIP_INITRD=yes + +. $TEST_BASE_DIR/test-functions + +test_setup() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + + # Create what will eventually be our root filesystem onto an overlay + ( + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + + for s in success-all success-start success-stop success-runtime \ + fail-start fail-stop fail-runtime + do + cp testsuite-${s}.service ${initdir}/etc/systemd/system + done + cp testsuite.service ${initdir}/etc/systemd/system + + cp extend_timeout_test_service.sh ${initdir}/ + cp assess.sh ${initdir}/ + cp $BUILD_DIR/systemd-notify ${initdir}/bin + cp $BUILD_DIR/src/shared/libsystemd-shared-*.so ${initdir}/usr/lib + + setup_testsuite + ) || return 1 + # mask some services that we do not want to run in these tests + ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket + ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service + + setup_nspawn_root + + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root +} + +test_cleanup() { + return 0 +} + +do_test "$@" diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-runtime.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-runtime.service new file mode 100644 index 0000000000..e0b9f6a70b --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-runtime.service @@ -0,0 +1,13 @@ + +[Unit] +Description=Testsuite: Fail Runtime (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after RuntimeSecMax.) + +[Service] + +# EXTEND_TIMEOUT_USEC on runtime start (0) and 7 seconds after. Systemd will expect one at 7+5 (extend_timeout_interval) +# seconds this won't happen until 7 + 7 (sleep interval) seconds. Therefore timeout at 12 seconds. +Type=notify +TimeoutStartSec=4 +TimeoutStopSec=4 +RuntimeMaxSec=10 +ExecStart=/extend_timeout_test_service.sh SERVICE=fail_runtime extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=2 stop_intervals=0 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-start.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-start.service new file mode 100644 index 0000000000..c3fcf23dc0 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-start.service @@ -0,0 +1,13 @@ + +[Unit] +Description=Testsuite: Fail Start (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after TimeoutStartSec.) + +[Service] + +# EXTEND_TIMEOUT_USEC on startup and 7 seconds from start. Systemd will expect one at 7+5 (extend_timeout_interval) +# seconds this won't happen until 7 + 7 (sleep interval) seconds. Therefore timeout at 12 seconds. +Type=notify +TimeoutStartSec=10 +TimeoutStopSec=4 +RuntimeMaxSec=4 +ExecStart=/extend_timeout_test_service.sh SERVICE=fail_start extend_timeout_interval=5 sleep_interval=7 start_intervals=2 run_intervals=0 stop_intervals=0 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-stop.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-stop.service new file mode 100644 index 0000000000..ce76d10db7 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-stop.service @@ -0,0 +1,16 @@ + +[Unit] +Description=Testsuite: Fail Stop (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after TimeoutStopSec.) + +[Service] + +# EXTEND_TIMEOUT_USEC on stop (0) and 7 seconds after. Systemd will expect one at 7+5 (extend_timeout_interval) +# seconds this won't happen until 7 + 7 (sleep interval) seconds. Therefore timeout at 12 seconds. +Type=notify +TimeoutStartSec=4 +TimeoutStopSec=10 +RuntimeMaxSec=4 +ExecStart=/extend_timeout_test_service.sh SERVICE=fail_stop extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=0 stop_intervals=2 +# Due to 6041a7ee2c1bbff6301082f192fc1b0882400d42 SIGTERM isn't sent as the service shuts down with STOPPING=1 +# This file makes the test assess.sh quicker by notifing it that this test has finished. +ExecStopPost=/bin/bash -c '[[ $SERVICE_RESULT == timeout && $EXIT_CODE == killed ]] && touch /fail_runtime.terminated' diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-all.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-all.service new file mode 100644 index 0000000000..666f4229bf --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-all.service @@ -0,0 +1,14 @@ + +[Unit] +Description=Testsuite: EXTEND_TIMEOUT_USEC Success - extend timeout on all services + +[Service] + +# Normal success - startup / runtime / shutdown all take 8 seconds which is within the EXTEND_TIMEOUT_USEC=4 seconds interval +# runtime is 8+8+8 seconds. so we are relying on the EXTEND_TIMEOUT_USEC to exceed all stages, Start, Runtime and Stop. +# success occurs after 24 seconds +Type=notify +TimeoutStartSec=4 +TimeoutStopSec=4 +RuntimeMaxSec=4 +ExecStart=/extend_timeout_test_service.sh SERVICE=success_all extend_timeout_interval=4 sleep_interval=2 start_intervals=3 run_intervals=3 stop_intervals=3 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-runtime.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-runtime.service new file mode 100644 index 0000000000..dc226f5054 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-runtime.service @@ -0,0 +1,13 @@ + +[Unit] +Description=Testsuite: Success Runtime (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < RuntimeMaxSec) + +[Service] + +# EXTEND_TIMEOUT_USEC=4 second once during runtime, but sleep for 6 seconds. +# Runtime is 6 seconds and < RuntimeMaxSec so still successful. +Type=notify +TimeoutStartSec=4 +TimeoutStopSec=4 +RuntimeMaxSec=8 +ExecStart=/extend_timeout_test_service.sh SERVICE=success_runtime extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=1 stop_intervals=0 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-start.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-start.service new file mode 100644 index 0000000000..228eece73e --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-start.service @@ -0,0 +1,13 @@ + +[Unit] +Description=Testsuite: Success Start (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < TimeoutStartSec) + +[Service] + +# EXTEND_TIMEOUT_USEC=4 second interval once at startup, but sleep 6 seconds. +# Therefore startup is 6 seconds and < TimeoutStartSec so still successful. +Type=notify +TimeoutStartSec=8 +TimeoutStopSec=4 +RuntimeMaxSec=4 +ExecStart=/extend_timeout_test_service.sh SERVICE=success_start extend_timeout_interval=4 sleep_interval=6 start_intervals=1 run_intervals=0 stop_intervals=0 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-stop.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-stop.service new file mode 100644 index 0000000000..b809397bf3 --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-stop.service @@ -0,0 +1,13 @@ + +[Unit] +Description=Testsuite: Success Stop (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < TimeoutStopSec) + +[Service] + +# EXTEND_TIMEOUT_USEC=4 seconds once during shutdown, but sleep for 6 seconds. +# Therefore stop time is 6 seconds and < TimeoutStopSec so still successful. +Type=notify +TimeoutStartSec=4 +TimeoutStopSec=8 +RuntimeMaxSec=4 +ExecStart=/extend_timeout_test_service.sh SERVICE=success_stop extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=0 stop_intervals=1 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite.service new file mode 100644 index 0000000000..e1cd5caeea --- /dev/null +++ b/test/TEST-16-EXTEND-TIMEOUT/testsuite.service @@ -0,0 +1,18 @@ + +[Unit] +Description=Testsuite: Assess all other testsuite-*.services worked as expected + +Wants=testsuite-success-all.service +Wants=testsuite-success-start.service +Wants=testsuite-success-runtime.service +Wants=testsuite-success-stop.service +Wants=testsuite-fail-start.service +Wants=testsuite-fail-stop.service +Wants=testsuite-fail-runtime.service +StopWhenUnneeded=yes + +[Service] + +Type=simple +ExecStartPre=/assess.sh +ExecStart=/bin/true diff --git a/test/TEST-17-UDEV-WANTS/Makefile b/test/TEST-17-UDEV-WANTS/Makefile new file mode 100644 index 0000000000..3a212a07a9 --- /dev/null +++ b/test/TEST-17-UDEV-WANTS/Makefile @@ -0,0 +1,4 @@ +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) + +all setup clean run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-17-UDEV-WANTS/test.sh b/test/TEST-17-UDEV-WANTS/test.sh new file mode 100755 index 0000000000..24989ebcf6 --- /dev/null +++ b/test/TEST-17-UDEV-WANTS/test.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +set -e +TEST_DESCRIPTION="UDEV SYSTEMD_WANTS property" +TEST_NO_NSPAWN=1 + +. $TEST_BASE_DIR/test-functions +QEMU_TIMEOUT=180 + +test_setup() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + + ( + LOG_LEVEL=5 + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + + # mask some services that we do not want to run in these tests + ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket + ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service + + # setup the testsuite service + cat >$initdir/etc/systemd/system/testsuite.service <<EOF +[Unit] +Description=Testsuite service + +[Service] +ExecStart=/bin/bash -x /testsuite.sh +Type=oneshot +StandardOutput=tty +StandardError=tty +EOF + cp testsuite.sh $initdir/ + + setup_testsuite + ) || return 1 + + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root +} + +do_test "$@" diff --git a/test/TEST-17-UDEV-WANTS/testsuite.sh b/test/TEST-17-UDEV-WANTS/testsuite.sh new file mode 100755 index 0000000000..5f97084cee --- /dev/null +++ b/test/TEST-17-UDEV-WANTS/testsuite.sh @@ -0,0 +1,76 @@ +#!/bin/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 -o pipefail + +mkdir -p /run/udev/rules.d/ + +rm -f /run/udev/rules.d/50-testsuite.rules +udevadm control --reload +udevadm trigger /dev/sda + +while : ; do + ( + udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service + udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service + systemctl show -p WantedBy foobar.service | grep -q -v sda + systemctl show -p WantedBy waldo.service | grep -q -v sda + ) && break + + sleep .5 +done + +cat > /run/udev/rules.d/50-testsuite.rules <<EOF +ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="foobar.service" +EOF +udevadm control --reload +udevadm trigger /dev/sda + +while : ; do + ( + udevadm info /dev/sda | grep -q SYSTEMD_WANTS=foobar.service + udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service + systemctl show -p WantedBy foobar.service | grep -q sda + systemctl show -p WantedBy waldo.service | grep -q -v sda + ) && break + + sleep .5 +done + +cat > /run/udev/rules.d/50-testsuite.rules <<EOF +ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="waldo.service" +EOF +udevadm control --reload +udevadm trigger /dev/sda + +while : ; do + ( + udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service + udevadm info /dev/sda | grep -q SYSTEMD_WANTS=waldo.service + systemctl show -p WantedBy foobar.service | grep -q -v sda + systemctl show -p WantedBy waldo.service | grep -q sda + ) && break + + sleep .5 +done + +rm /run/udev/rules.d/50-testsuite.rules + +udevadm control --reload +udevadm trigger /dev/sda + +while : ; do + ( + udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service + udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service + systemctl show -p WantedBy foobar.service | grep -q -v sda + systemctl show -p WantedBy waldo.service | grep -q -v sda + ) && break + + sleep .5 +done + +echo OK > /testok + +exit 0 diff --git a/test/TEST-18-FAILUREACTION/Makefile b/test/TEST-18-FAILUREACTION/Makefile new file mode 100644 index 0000000000..3a212a07a9 --- /dev/null +++ b/test/TEST-18-FAILUREACTION/Makefile @@ -0,0 +1,4 @@ +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) + +all setup clean run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-18-FAILUREACTION/test.sh b/test/TEST-18-FAILUREACTION/test.sh new file mode 100755 index 0000000000..e48ba9bac3 --- /dev/null +++ b/test/TEST-18-FAILUREACTION/test.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +set -e +TEST_DESCRIPTION="FailureAction= operation" + +. $TEST_BASE_DIR/test-functions +QEMU_TIMEOUT=180 + +test_setup() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + + ( + LOG_LEVEL=5 + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + + # setup the testsuite service + cat >$initdir/etc/systemd/system/testsuite.service <<EOF +[Unit] +Description=Testsuite service + +[Service] +ExecStart=/bin/bash -x /testsuite.sh +Type=oneshot +StandardOutput=tty +StandardError=tty +EOF + cp testsuite.sh $initdir/ + + setup_testsuite + ) || return 1 + setup_nspawn_root + + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root +} + +do_test "$@" diff --git a/test/TEST-18-FAILUREACTION/testsuite.sh b/test/TEST-18-FAILUREACTION/testsuite.sh new file mode 100755 index 0000000000..1867cc3c47 --- /dev/null +++ b/test/TEST-18-FAILUREACTION/testsuite.sh @@ -0,0 +1,18 @@ +#!/bin/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 -o pipefail + +systemd-run --wait -p FailureAction=poweroff true +! systemd-run --wait -p SuccessAction=poweroff false + +if test -f /firstphase ; then + echo OK > /firstphase + systemd-run --wait -p SuccessAction=reboot true +else + echo OK > /testok + systemd-run --wait -p FailureAction=poweroff false +fi + +sleep infinity diff --git a/test/TEST-19-DELEGATE/Makefile b/test/TEST-19-DELEGATE/Makefile new file mode 100644 index 0000000000..3a212a07a9 --- /dev/null +++ b/test/TEST-19-DELEGATE/Makefile @@ -0,0 +1,4 @@ +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) + +all setup clean run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-19-DELEGATE/test.sh b/test/TEST-19-DELEGATE/test.sh new file mode 100755 index 0000000000..841a29c06f --- /dev/null +++ b/test/TEST-19-DELEGATE/test.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +set -e +TEST_DESCRIPTION="test cgroup delegation in the unifier hierarchy" +TEST_NO_NSPAWN=1 + +. $TEST_BASE_DIR/test-functions +QEMU_TIMEOUT=180 +UNIFIED_CGROUP_HIERARCHY=yes + +test_setup() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + + ( + LOG_LEVEL=5 + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + + # setup the testsuite service + cat >$initdir/etc/systemd/system/testsuite.service <<EOF +[Unit] +Description=Testsuite service + +[Service] +ExecStart=/bin/bash -x /testsuite.sh +Type=oneshot +StandardOutput=tty +StandardError=tty +EOF + cp testsuite.sh $initdir/ + + setup_testsuite + ) || return 1 + + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root +} + +do_test "$@" diff --git a/test/TEST-19-DELEGATE/testsuite.sh b/test/TEST-19-DELEGATE/testsuite.sh new file mode 100755 index 0000000000..c738bea10e --- /dev/null +++ b/test/TEST-19-DELEGATE/testsuite.sh @@ -0,0 +1,24 @@ +#!/bin/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 -o pipefail + +if grep -q cgroup2 /proc/filesystems ; then + systemd-run --wait --unit=test0.service -p "DynamicUser=1" -p "Delegate=" \ + test -w /sys/fs/cgroup/system.slice/test0.service/ -a \ + -w /sys/fs/cgroup/system.slice/test0.service/cgroup.procs -a \ + -w /sys/fs/cgroup/system.slice/test0.service/cgroup.subtree_control + + systemd-run --wait --unit=test1.service -p "DynamicUser=1" -p "Delegate=memory pids" \ + grep memory /sys/fs/cgroup/system.slice/test1.service/cgroup.controllers + + systemd-run --wait --unit=test2.service -p "DynamicUser=1" -p "Delegate=memory pids" \ + grep pids /sys/fs/cgroup/system.slice/test2.service/cgroup.controllers +else + echo "Skipping TEST-19-DELEGATE, as the kernel doesn't actually support cgroupsv2" >&2 +fi + +echo OK > /testok + +exit 0 diff --git a/test/create-sys-script.py b/test/create-sys-script.py index a4f1f302f6..e25f3b4f8f 100755 --- a/test/create-sys-script.py +++ b/test/create-sys-script.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ OUTFILE_HEADER = """#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ # # create-sys-script.py # diff --git a/test/hwdb-test.sh b/test/hwdb-test.sh index 2221c0d7fd..a1f3270b64 100755 --- a/test/hwdb-test.sh +++ b/test/hwdb-test.sh @@ -1,5 +1,7 @@ #!/bin/sh -# call built systemd-hwdb update on our hwdb files to ensure that they parse +# SPDX-License-Identifier: LGPL-2.1+ +# +# Call built systemd-hwdb update on our hwdb files to ensure that they parse # without error # # (C) 2016 Canonical Ltd. @@ -9,7 +11,7 @@ # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. - +# # systemd is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -20,6 +22,7 @@ set -e +export SYSTEMD_LOG_LEVEL=info ROOTDIR=$(dirname $(dirname $(readlink -f $0))) SYSTEMD_HWDB=./systemd-hwdb diff --git a/test/meson.build b/test/meson.build index 995a971778..5c533f4833 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,18 +1,38 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# Copyright 2017 Zbigniew Jędrzejewski-Szmek +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + test_data_files = ''' a.service - basic.target b.service + basic.target c.service - daughter.service d.service - end.service + daughter.service e.service + end.service f.service - grandchild.service g.service + grandchild.service + h.service hello-after-sleep.target hello.service - h.service + hwdb/10-bad.hwdb + journal-data/journal-1.txt + journal-data/journal-2.txt parent-deep.slice parent.slice sched_idle_bad.service @@ -25,112 +45,124 @@ test_data_files = ''' sockets.target son.service sysinit.target - testsuite.target - timers.target - unstoppable.service - test-path/paths.target - test-path/basic.target - test-path/sysinit.target - test-path/path-changed.service - test-path/path-directorynotempty.service - test-path/path-existsglob.service - test-path/path-exists.service - test-path/path-makedirectory.service - test-path/path-modified.service - test-path/path-mycustomunit.service - test-path/path-service.service - test-path/path-changed.path - test-path/path-directorynotempty.path - test-path/path-existsglob.path - test-path/path-exists.path - test-path/path-makedirectory.path - test-path/path-modified.path - test-path/path-unit.path + test-execute/exec-bindpaths.service + test-execute/exec-capabilityambientset-merge-nfsnobody.service + test-execute/exec-capabilityambientset-merge.service + test-execute/exec-capabilityambientset-nfsnobody.service + test-execute/exec-capabilityambientset.service + test-execute/exec-capabilityboundingset-invert.service + test-execute/exec-capabilityboundingset-merge.service + test-execute/exec-capabilityboundingset-reset.service + test-execute/exec-capabilityboundingset-simple.service + test-execute/exec-cpuaffinity1.service + test-execute/exec-cpuaffinity2.service + test-execute/exec-cpuaffinity3.service + test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service + test-execute/exec-dynamicuser-fixeduser.service + test-execute/exec-dynamicuser-statedir-migrate-step1.service + test-execute/exec-dynamicuser-statedir-migrate-step2.service + test-execute/exec-dynamicuser-statedir.service + test-execute/exec-dynamicuser-supplementarygroups.service test-execute/exec-environment-empty.service test-execute/exec-environment-multiple.service test-execute/exec-environment.service + test-execute/exec-environmentfile.service + test-execute/exec-group-nfsnobody.service + test-execute/exec-group-nogroup.service + test-execute/exec-group.service + test-execute/exec-ignoresigpipe-no.service + test-execute/exec-ignoresigpipe-yes.service + test-execute/exec-inaccessiblepaths-mount-propagation.service + test-execute/exec-inaccessiblepaths-proc.service + test-execute/exec-ioschedulingclass-best-effort.service + test-execute/exec-ioschedulingclass-idle.service + test-execute/exec-ioschedulingclass-none.service + test-execute/exec-ioschedulingclass-realtime.service + test-execute/exec-oomscoreadjust-negative.service + test-execute/exec-oomscoreadjust-positive.service test-execute/exec-passenvironment-absent.service test-execute/exec-passenvironment-empty.service test-execute/exec-passenvironment-repeated.service test-execute/exec-passenvironment.service - test-execute/exec-group.service - test-execute/exec-group-nfsnobody.service - test-execute/exec-supplementarygroups.service - test-execute/exec-supplementarygroups-single-group.service - test-execute/exec-supplementarygroups-single-group-user.service - test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service - test-execute/exec-supplementarygroups-multiple-groups-withgid.service - test-execute/exec-supplementarygroups-multiple-groups-withuid.service - test-execute/exec-dynamicuser-fixeduser.service - test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service - test-execute/exec-dynamicuser-supplementarygroups.service - test-execute/exec-dynamicuser-state-dir.service - test-execute/exec-ignoresigpipe-no.service - test-execute/exec-ignoresigpipe-yes.service - test-execute/exec-personality-x86-64.service - test-execute/exec-personality-x86.service - test-execute/exec-personality-s390.service + test-execute/exec-personality-aarch64.service test-execute/exec-personality-ppc64.service test-execute/exec-personality-ppc64le.service - test-execute/exec-personality-aarch64.service - test-execute/exec-privatedevices-no.service - test-execute/exec-privatedevices-yes.service + test-execute/exec-personality-s390.service + test-execute/exec-personality-x86-64.service + test-execute/exec-personality-x86.service test-execute/exec-privatedevices-no-capability-mknod.service + test-execute/exec-privatedevices-no-capability-sys-rawio.service + test-execute/exec-privatedevices-no.service test-execute/exec-privatedevices-yes-capability-mknod.service + test-execute/exec-privatedevices-yes-capability-sys-rawio.service + test-execute/exec-privatedevices-yes.service + test-execute/exec-privatenetwork-yes.service + test-execute/exec-privatetmp-no.service + test-execute/exec-privatetmp-yes.service test-execute/exec-protectkernelmodules-no-capabilities.service test-execute/exec-protectkernelmodules-yes-capabilities.service test-execute/exec-protectkernelmodules-yes-mount-propagation.service - test-execute/exec-privatetmp-no.service - test-execute/exec-privatetmp-yes.service - test-execute/exec-readonlypaths.service test-execute/exec-readonlypaths-mount-propagation.service + test-execute/exec-readonlypaths-simple.service + test-execute/exec-readonlypaths-with-bindpaths.service + test-execute/exec-readonlypaths.service test-execute/exec-readwritepaths-mount-propagation.service - test-execute/exec-inaccessiblepaths-mount-propagation.service - test-execute/exec-inaccessiblepaths-proc.service - test-execute/exec-spec-interpolation.service - test-execute/exec-systemcallerrornumber.service - test-execute/exec-systemcallfilter-failing2.service + test-execute/exec-restrictnamespaces-mnt-blacklist.service + test-execute/exec-restrictnamespaces-mnt.service + test-execute/exec-restrictnamespaces-no.service + test-execute/exec-restrictnamespaces-yes.service + test-execute/exec-runtimedirectory-mode.service + test-execute/exec-runtimedirectory-owner-nfsnobody.service + test-execute/exec-runtimedirectory-owner.service + test-execute/exec-runtimedirectory.service + test-execute/exec-specifier-interpolation.service + test-execute/exec-specifier.service + test-execute/exec-specifier@.service + test-execute/exec-standardinput-data.service + test-execute/exec-standardinput-file.service + test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service + test-execute/exec-supplementarygroups-multiple-groups-withgid.service + test-execute/exec-supplementarygroups-multiple-groups-withuid.service + test-execute/exec-supplementarygroups-single-group-user.service + test-execute/exec-supplementarygroups-single-group.service + test-execute/exec-supplementarygroups.service + test-execute/exec-systemcallerrornumber-name.service + test-execute/exec-systemcallerrornumber-number.service test-execute/exec-systemcallfilter-failing.service - test-execute/exec-systemcallfilter-not-failing2.service + test-execute/exec-systemcallfilter-failing2.service test-execute/exec-systemcallfilter-not-failing.service - test-execute/exec-systemcallfilter-system-user.service + test-execute/exec-systemcallfilter-not-failing2.service test-execute/exec-systemcallfilter-system-user-nfsnobody.service - test-execute/exec-unset-environment.service - test-execute/exec-user.service - test-execute/exec-user-nfsnobody.service - test-execute/exec-workingdirectory.service + test-execute/exec-systemcallfilter-system-user.service + test-execute/exec-systemcallfilter-with-errno-name.service + test-execute/exec-systemcallfilter-with-errno-number.service test-execute/exec-umask-0177.service test-execute/exec-umask-default.service - test-execute/exec-privatenetwork-yes.service - test-execute/exec-environmentfile.service - test-execute/exec-oomscoreadjust-positive.service - test-execute/exec-oomscoreadjust-negative.service - test-execute/exec-ioschedulingclass-best-effort.service - test-execute/exec-ioschedulingclass-idle.service - test-execute/exec-ioschedulingclass-none.service - test-execute/exec-ioschedulingclass-realtime.service - test-execute/exec-capabilityboundingset-invert.service - test-execute/exec-capabilityboundingset-merge.service - test-execute/exec-capabilityboundingset-reset.service - test-execute/exec-capabilityboundingset-simple.service - test-execute/exec-capabilityambientset.service - test-execute/exec-capabilityambientset-nfsnobody.service - test-execute/exec-capabilityambientset-merge.service - test-execute/exec-capabilityambientset-merge-nfsnobody.service - test-execute/exec-runtimedirectory.service - test-execute/exec-runtimedirectory-mode.service - test-execute/exec-runtimedirectory-owner.service - test-execute/exec-runtimedirectory-owner-nfsnobody.service - test-execute/exec-restrict-namespaces-no.service - test-execute/exec-restrict-namespaces-yes.service - test-execute/exec-restrict-namespaces-mnt.service - test-execute/exec-restrict-namespaces-mnt-blacklist.service - test-execute/exec-read-only-path-succeed.service - test-execute/exec-privatedevices-yes-capability-sys-rawio.service - test-execute/exec-privatedevices-no-capability-sys-rawio.service - hwdb/10-bad.hwdb - journal-data/journal-1.txt - journal-data/journal-2.txt + test-execute/exec-unsetenvironment.service + test-execute/exec-user-nfsnobody.service + test-execute/exec-user.service + test-execute/exec-workingdirectory.service + test-path/basic.target + test-path/path-changed.path + test-path/path-changed.service + test-path/path-directorynotempty.path + test-path/path-directorynotempty.service + test-path/path-exists.path + test-path/path-exists.service + test-path/path-existsglob.path + test-path/path-existsglob.service + test-path/path-makedirectory.path + test-path/path-makedirectory.service + test-path/path-modified.path + test-path/path-modified.service + test-path/path-mycustomunit.service + test-path/path-service.service + test-path/path-unit.path + test-path/paths.target + test-path/sysinit.target + testsuite.target + timers.target + unstoppable.service '''.split() if conf.get('ENABLE_RESOLVE') == 1 @@ -163,9 +195,18 @@ endif ############################################################ -sysv_generator_test_py = find_program('sysv-generator-test.py') -test('sysv-generator-test', - sysv_generator_test_py) +rule_syntax_check_py = find_program('rule-syntax-check.py') +test('rule-syntax-check', + rule_syntax_check_py, + args : all_rules) + +############################################################ + +if conf.get('HAVE_SYSV_COMPAT') == 1 + sysv_generator_test_py = find_program('sysv-generator-test.py') + test('sysv-generator-test', + sysv_generator_test_py) +endif ############################################################ @@ -181,6 +222,9 @@ udev_test_pl = find_program('udev-test.pl') test('udev-test', udev_test_pl) -hwdb_test_sh = find_program('hwdb-test.sh') -test('hwdb-test', - hwdb_test_sh) +if conf.get('ENABLE_HWDB') == 1 + hwdb_test_sh = find_program('hwdb-test.sh') + test('hwdb-test', + hwdb_test_sh, + timeout : 90) +endif diff --git a/test/networkd-test.py b/test/networkd-test.py index 5760ca5137..3918d85ef0 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ # # networkd integration test # This uses temporary configuration in /run and temporary veth devices, and diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py index 14739df493..e053b027ca 100755 --- a/test/rule-syntax-check.py +++ b/test/rule-syntax-check.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# # Simple udev rules syntax checker # # (C) 2010 Canonical Ltd. @@ -22,17 +24,9 @@ import sys import os from glob import glob -if len(sys.argv) > 1: - # explicit rule file list - rules_files = sys.argv[1:] -else: - # take them from the build dir - root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - rules_dir = os.path.join(os.environ.get('top_srcdir', root_dir), 'rules') - if not os.path.isdir(rules_dir): - sys.stderr.write('No rules files given, and %s does not exist, aborting' % rules_dir) - sys.exit(2) - rules_files = glob(os.path.join(rules_dir, '*.rules')) +rules_files = sys.argv[1:] +if not rules_files: + sys.exit('Specify files to test as arguments') no_args_tests = re.compile(r'(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') @@ -42,6 +36,7 @@ args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=) result = 0 buffer = '' for path in rules_files: + print('# looking at {}'.format(path)) lineno = 0 for line in open(path): lineno += 1 @@ -64,9 +59,9 @@ for path in rules_files: if not (no_args_tests.match(clause) or args_tests.match(clause) or no_args_assign.match(clause) or args_assign.match(clause)): - print('Invalid line %s:%i: %s' % (path, lineno, line)) - print(' clause: %s' % clause) - print('') + print('Invalid line {}:{}: {}'.format(path, lineno, line)) + print(' clause:', clause) + print() result = 1 break diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh new file mode 100755 index 0000000000..7d70be3fea --- /dev/null +++ b/test/run-integration-tests.sh @@ -0,0 +1,48 @@ +#!/bin/bash -e + +BUILD_DIR="$($(dirname "$0")/../tools/find-build-dir.sh)" +if [ $# -gt 0 ]; then + args="$@" +else + args="clean setup run" +fi + +ninja -C "$BUILD_DIR" + +declare -A results + +RESULT=0 +FAILURES=0 + +cd "$(dirname "$0")" +for TEST in TEST-??-* ; do + echo -e "\n--x-- Starting $TEST --x--" + set +e + make -C "$TEST" "BUILD_DIR=$BUILD_DIR" $args + RESULT=$? + set -e + echo "--x-- Result of $TEST: $RESULT --x--" + + results["$TEST"]="$RESULT" + + [ "$RESULT" -ne "0" ] && FAILURES=$(($FAILURES+1)) +done + +echo "" + +for TEST in ${!results[@]}; do + RESULT="${results[$TEST]}" + if [ "$RESULT" -eq "0" ] ; then + echo "$TEST: SUCCESS" + else + echo "$TEST: FAIL" + fi +done | sort + +if [ "$FAILURES" -eq 0 ] ; then + echo -e "\nALL PASSED" +else + echo -e "\nTOTAL FAILURES: $FAILURES" +fi + +exit "$FAILURES" diff --git a/test/sys-script.py b/test/sys-script.py index 2de7d7ea30..468c1dc972 100755 --- a/test/sys-script.py +++ b/test/sys-script.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ # # sys-script.py # diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py index 18bb40f812..0b4710aeab 100755 --- a/test/sysv-generator-test.py +++ b/test/sysv-generator-test.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ # # systemd-sysv-generator integration test # diff --git a/test/test-exec-deserialization.py b/test/test-exec-deserialization.py index c3fe0824c7..1b8863746c 100755 --- a/test/test-exec-deserialization.py +++ b/test/test-exec-deserialization.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 - +# SPDX-License-Identifier: LGPL-2.1+ # # Copyright 2017 Michal Sekletar <msekleta@redhat.com> # diff --git a/test/test-execute/exec-bindpaths.service b/test/test-execute/exec-bindpaths.service new file mode 100644 index 0000000000..7bd8fa7402 --- /dev/null +++ b/test/test-execute/exec-bindpaths.service @@ -0,0 +1,17 @@ +[Unit] +Description=Test for BindPaths= and BindReadOnlyPaths= + +[Service] +Type=oneshot +# Create a file in /tmp/test-exec-bindpaths +ExecStart=/bin/sh -c 'touch /tmp/test-exec-bindpaths/thisisasimpletest' +# Then, the file can be access through /tmp +ExecStart=/bin/sh -c 'test -f /tmp/thisisasimpletest' +# Also, through /tmp/test-exec-bindreadonlypaths +ExecStart=/bin/sh -c 'test -f /tmp/test-exec-bindreadonlypaths/thisisasimpletest' +# The file cannot modify through /tmp/test-exec-bindreadonlypaths +ExecStart=/bin/sh -x -c '! touch /tmp/test-exec-bindreadonlypaths/thisisasimpletest' +# Cleanup +ExecStart=/bin/sh -c 'rm /tmp/thisisasimpletest' +BindPaths=/tmp:/tmp/test-exec-bindpaths +BindReadOnlyPaths=/tmp:/tmp/test-exec-bindreadonlypaths diff --git a/test/test-execute/exec-cpuaffinity1.service b/test/test-execute/exec-cpuaffinity1.service new file mode 100644 index 0000000000..84d550a385 --- /dev/null +++ b/test/test-execute/exec-cpuaffinity1.service @@ -0,0 +1,6 @@ +[Unit] +Description=Test for CPUAffinity (simple) + +[Service] +ExecStart=/bin/sh -c 'test $$(cat /proc/self/status | grep Cpus_allowed: | rev | cut -c 1) = 1' +CPUAffinity=0 diff --git a/test/test-execute/exec-cpuaffinity2.service b/test/test-execute/exec-cpuaffinity2.service new file mode 100644 index 0000000000..0dda77f939 --- /dev/null +++ b/test/test-execute/exec-cpuaffinity2.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test for CPUAffinity (reset) + +[Service] +ExecStart=/bin/sh -c 'test $$(cat /proc/self/status | grep Cpus_allowed: | rev | cut -c 1) = 1' +CPUAffinity=0-1 3 +CPUAffinity= +CPUAffinity=0 diff --git a/test/test-execute/exec-cpuaffinity3.service b/test/test-execute/exec-cpuaffinity3.service new file mode 100644 index 0000000000..4a45d3b2d5 --- /dev/null +++ b/test/test-execute/exec-cpuaffinity3.service @@ -0,0 +1,7 @@ +[Unit] +Description=Test for CPUAffinity (merge) + +[Service] +ExecStart=/bin/sh -c 'test $$(cat /proc/self/status | grep Cpus_allowed: | rev | cut -c 1) = 7' +CPUAffinity=0,1 +CPUAffinity=1-2 diff --git a/test/test-execute/exec-dynamicuser-statedir-migrate-step1.service b/test/test-execute/exec-dynamicuser-statedir-migrate-step1.service new file mode 100644 index 0000000000..83bdfb311a --- /dev/null +++ b/test/test-execute/exec-dynamicuser-statedir-migrate-step1.service @@ -0,0 +1,16 @@ +[Unit] +Description=Test DynamicUser= migrate StateDirectory= (preparation) + +[Service] +ExecStart=/bin/sh -c 'test -w /var/lib/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test -w /var/lib/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'test ! -L /var/lib/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test ! -L /var/lib/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'test -d /var/lib/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test -d /var/lib/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'touch /var/lib/test-dynamicuser-migrate/yay' +ExecStart=/bin/sh -c 'touch /var/lib/test-dynamicuser-migrate2/hoge/yayyay' + +Type=oneshot +DynamicUser=no +StateDirectory=test-dynamicuser-migrate test-dynamicuser-migrate2/hoge diff --git a/test/test-execute/exec-dynamicuser-statedir-migrate-step2.service b/test/test-execute/exec-dynamicuser-statedir-migrate-step2.service new file mode 100644 index 0000000000..8154922a2f --- /dev/null +++ b/test/test-execute/exec-dynamicuser-statedir-migrate-step2.service @@ -0,0 +1,24 @@ +[Unit] +Description=Test DynamicUser= migrate StateDirectory= (preparation) + +[Service] +ExecStart=/bin/sh -c 'test -w /var/lib/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test -w /var/lib/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'test -L /var/lib/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test -L /var/lib/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'test -d /var/lib/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test -d /var/lib/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'test -f /var/lib/test-dynamicuser-migrate/yay' +ExecStart=/bin/sh -c 'test -f /var/lib/test-dynamicuser-migrate2/hoge/yayyay' +ExecStart=/bin/sh -c 'test -d /var/lib/private/test-dynamicuser-migrate' +ExecStart=/bin/sh -c 'test -d /var/lib/private/test-dynamicuser-migrate2/hoge' +ExecStart=/bin/sh -c 'test -f /var/lib/private/test-dynamicuser-migrate/yay' +ExecStart=/bin/sh -c 'test -f /var/lib/private/test-dynamicuser-migrate2/hoge/yayyay' +ExecStart=/bin/sh -c 'touch /var/lib/test-dynamicuser-migrate/yay' +ExecStart=/bin/sh -c 'touch /var/lib/test-dynamicuser-migrate2/hoge/yayyay' +ExecStart=/bin/sh -c 'touch /var/lib/private/test-dynamicuser-migrate/yay' +ExecStart=/bin/sh -c 'touch /var/lib/private/test-dynamicuser-migrate2/hoge/yayyay' + +Type=oneshot +DynamicUser=yes +StateDirectory=test-dynamicuser-migrate test-dynamicuser-migrate2/hoge diff --git a/test/test-execute/exec-dynamicuser-state-dir.service b/test/test-execute/exec-dynamicuser-statedir.service index 7e2d88450b..cc09c938cf 100644 --- a/test/test-execute/exec-dynamicuser-state-dir.service +++ b/test/test-execute/exec-dynamicuser-statedir.service @@ -2,14 +2,14 @@ Description=Test DynamicUser= with StateDirectory= [Service] -ExecStart=/usr/bin/test -w /var/lib/waldo -ExecStart=/usr/bin/test -w /var/lib/quux/pief -ExecStart=/bin/touch /var/lib/waldo/yay -ExecStart=/bin/touch /var/lib/quux/pief/yayyay -ExecStart=/usr/bin/test -f /var/lib/waldo/yay -ExecStart=/usr/bin/test -f /var/lib/quux/pief/yayyay -ExecStart=/usr/bin/test -f /var/lib/private/waldo/yay -ExecStart=/usr/bin/test -f /var/lib/private/quux/pief/yayyay +ExecStart=/bin/sh -c 'test -w /var/lib/waldo' +ExecStart=/bin/sh -c 'test -w /var/lib/quux/pief' +ExecStart=/bin/sh -c 'touch /var/lib/waldo/yay' +ExecStart=/bin/sh -c 'touch /var/lib/quux/pief/yayyay' +ExecStart=/bin/sh -c 'test -f /var/lib/waldo/yay' +ExecStart=/bin/sh -c 'test -f /var/lib/quux/pief/yayyay' +ExecStart=/bin/sh -c 'test -f /var/lib/private/waldo/yay' +ExecStart=/bin/sh -c 'test -f /var/lib/private/quux/pief/yayyay' # Make sure that /var/lib/private/waldo is really the only writable directory besides the obvious candidates ExecStart=/bin/sh -x -c 'test $$(find / -type d -writable 2> /dev/null | egrep -v -e \'^(/var/tmp$$|/tmp$$|/proc/|/dev/mqueue$$|/dev/shm$$)\' | sort -u | tr -d '\\\\n') = /var/lib/private/quux/pief/var/lib/private/waldo' diff --git a/test/test-execute/exec-group-nogroup.service b/test/test-execute/exec-group-nogroup.service new file mode 100644 index 0000000000..cf0773229e --- /dev/null +++ b/test/test-execute/exec-group-nogroup.service @@ -0,0 +1,7 @@ +[Unit] +Description=Test for Group + +[Service] +ExecStart=/bin/sh -x -c 'test "$$(id -n -g)" = "nogroup"' +Type=oneshot +Group=nogroup diff --git a/test/test-execute/exec-read-only-path-succeed.service b/test/test-execute/exec-readonlypaths-simple.service index b54d48f281..a9a715905c 100644 --- a/test/test-execute/exec-read-only-path-succeed.service +++ b/test/test-execute/exec-readonlypaths-simple.service @@ -1,8 +1,11 @@ +[Unit] +Description=Test for ReadOnlyPaths= + [Service] Type=oneshot # This should work, as we explicitly disable the effect of ReadOnlyPaths= -ExecStart=+/bin/touch /tmp/thisisasimpletest +ExecStart=+/bin/sh -c 'touch /tmp/thisisasimpletest' # This should also work, as we do not disable the effect of ReadOnlyPaths= but invert the exit code -ExecStart=/bin/sh -x -c '! /bin/touch /tmp/thisisasimpletest' -ExecStart=+/bin/rm /tmp/thisisasimpletest +ExecStart=/bin/sh -x -c '! touch /tmp/thisisasimpletest' +ExecStart=+/bin/sh -c 'rm /tmp/thisisasimpletest' ReadOnlyPaths=/tmp diff --git a/test/test-execute/exec-readonlypaths-with-bindpaths.service b/test/test-execute/exec-readonlypaths-with-bindpaths.service new file mode 100644 index 0000000000..ea9211395d --- /dev/null +++ b/test/test-execute/exec-readonlypaths-with-bindpaths.service @@ -0,0 +1,9 @@ +[Unit] +Description=Test for ReadOnlyPaths= + +[Service] +ReadOnlyPaths=/etc -/i-dont-exist /usr +# From 6c47cd7d3bf35c8158a0737f34fe2c5dc95e72d6, RuntimeDirectory= implies BindPaths=. +RuntimeDirectory=foo +ExecStart=/bin/sh -x -c 'test ! -w /etc && test ! -w /usr && test ! -e /i-dont-exist && test -w /var' +Type=oneshot diff --git a/test/test-execute/exec-restrict-namespaces-mnt-blacklist.service b/test/test-execute/exec-restrictnamespaces-mnt-blacklist.service index ab909cbd94..ab909cbd94 100644 --- a/test/test-execute/exec-restrict-namespaces-mnt-blacklist.service +++ b/test/test-execute/exec-restrictnamespaces-mnt-blacklist.service diff --git a/test/test-execute/exec-restrict-namespaces-mnt.service b/test/test-execute/exec-restrictnamespaces-mnt.service index 1aeed72717..1aeed72717 100644 --- a/test/test-execute/exec-restrict-namespaces-mnt.service +++ b/test/test-execute/exec-restrictnamespaces-mnt.service diff --git a/test/test-execute/exec-restrict-namespaces-no.service b/test/test-execute/exec-restrictnamespaces-no.service index 33500302d2..33500302d2 100644 --- a/test/test-execute/exec-restrict-namespaces-no.service +++ b/test/test-execute/exec-restrictnamespaces-no.service diff --git a/test/test-execute/exec-restrict-namespaces-yes.service b/test/test-execute/exec-restrictnamespaces-yes.service index 3fe70e2bea..3fe70e2bea 100644 --- a/test/test-execute/exec-restrict-namespaces-yes.service +++ b/test/test-execute/exec-restrictnamespaces-yes.service diff --git a/test/test-execute/exec-spec-interpolation.service b/test/test-execute/exec-specifier-interpolation.service index 3e62662aa9..3e62662aa9 100644 --- a/test/test-execute/exec-spec-interpolation.service +++ b/test/test-execute/exec-specifier-interpolation.service diff --git a/test/test-execute/exec-specifier.service b/test/test-execute/exec-specifier.service new file mode 100644 index 0000000000..37852390ac --- /dev/null +++ b/test/test-execute/exec-specifier.service @@ -0,0 +1,24 @@ +[Unit] +Description=Test for specifiers + +[Service] +Type=oneshot +ExecStart=/usr/bin/test %n = exec-specifier.service +ExecStart=/usr/bin/test %N = exec-specifier +ExecStart=/usr/bin/test %p = exec-specifier +ExecStart=/usr/bin/test %P = exec/specifier +ExecStart=/usr/bin/test %i = "" +ExecStart=/usr/bin/test %I = "" +ExecStart=/usr/bin/test %f = /exec/specifier +ExecStart=/usr/bin/test %t = /run +ExecStart=/usr/bin/test %S = /var/lib +ExecStart=/usr/bin/test %C = /var/cache +ExecStart=/usr/bin/test %L = /var/log +ExecStart=/bin/sh -c 'test %u = $$(id -un 0)' +ExecStart=/usr/bin/test %U = 0 +ExecStart=/bin/sh -c 'test %h = $$(getent passwd 0 | cut -d: -f 6) +ExecStart=/bin/sh -c 'test %s = $$(getent passwd 0 | cut -d: -f 7) +ExecStart=/bin/sh -c 'test %m = $$(cat /etc/machine-id)' +ExecStart=/bin/sh -c 'test %b = $$(cat /proc/sys/kernel/random/boot_id | sed -e 's/-//g')' +ExecStart=/bin/sh -c 'test %H = $$(hostname)' +ExecStart=/bin/sh -c 'test %v = $$(uname -r)' diff --git a/test/test-execute/exec-specifier@.service b/test/test-execute/exec-specifier@.service new file mode 100644 index 0000000000..0015dffca6 --- /dev/null +++ b/test/test-execute/exec-specifier@.service @@ -0,0 +1,24 @@ +[Unit] +Description=Test for specifiers (template unit) + +[Service] +Type=oneshot +ExecStart=/usr/bin/test %n = exec-specifier@foo-bar.service +ExecStart=/usr/bin/test %N = exec-specifier@foo-bar +ExecStart=/usr/bin/test %p = exec-specifier +ExecStart=/usr/bin/test %P = exec/specifier +ExecStart=/usr/bin/test %i = foo-bar +ExecStart=/usr/bin/test %I = foo/bar +ExecStart=/usr/bin/test %f = /foo/bar +ExecStart=/usr/bin/test %t = /run +ExecStart=/usr/bin/test %S = /var/lib +ExecStart=/usr/bin/test %C = /var/cache +ExecStart=/usr/bin/test %L = /var/log +ExecStart=/bin/sh -c 'test %u = $$(id -un 0)' +ExecStart=/usr/bin/test %U = 0 +ExecStart=/bin/sh -c 'test %h = $$(getent passwd 0 | cut -d: -f 6) +ExecStart=/bin/sh -c 'test %s = $$(getent passwd 0 | cut -d: -f 7) +ExecStart=/bin/sh -c 'test %m = $$(cat /etc/machine-id)' +ExecStart=/bin/sh -c 'test %b = $$(cat /proc/sys/kernel/random/boot_id | sed -e 's/-//g')' +ExecStart=/bin/sh -c 'test %H = $$(hostname)' +ExecStart=/bin/sh -c 'test %v = $$(uname -r)' diff --git a/test/test-execute/exec-standardinput-data.service b/test/test-execute/exec-standardinput-data.service new file mode 100644 index 0000000000..1ca536ffc5 --- /dev/null +++ b/test/test-execute/exec-standardinput-data.service @@ -0,0 +1,19 @@ +[Unit] +Description=Test for StandardInputText= and StandardInputData= + +[Service] +ExecStart=/bin/sh -x -c 'd=$$(mktemp -d -p /tmp); echo -e "this is a test\nand this is more\nsomething encoded!\nsomething in multiple lines\nand some more\nand a more bas64 data\nsomething with strange\nembedded\tcharacters\nand something with a exec-stdin-data.service specifier" > $d/text ; cmp $d/text ; rm -rf $d' +Type=oneshot +StandardInput=data +StandardInputText=this is a test +StandardInputText=and this is more +StandardInputData=c29tZXRoaW5nIGVuY29kZWQhCg== +StandardInputText=something \ + in multiple lines +StandardInputText=\ +and some more +StandardInputData=YW5kIGEgbW9y \ + ZSBiYXM2NCBk\ +YXRhCg== +StandardInputText=something with strange\nembedded\tcharacters +StandardInputText=and something with a %n specifier diff --git a/test/test-execute/exec-standardinput-file.service b/test/test-execute/exec-standardinput-file.service new file mode 100644 index 0000000000..8fd11caf8e --- /dev/null +++ b/test/test-execute/exec-standardinput-file.service @@ -0,0 +1,7 @@ +[Unit] +Description=Test for StandardInput=file: + +[Service] +ExecStart=/usr/bin/cmp /usr/bin/cmp +Type=oneshot +StandardInput=file:/usr/bin/cmp diff --git a/test/test-execute/exec-systemcallerrornumber.service b/test/test-execute/exec-systemcallerrornumber-name.service index ff7da3c1a4..e167d2716b 100644 --- a/test/test-execute/exec-systemcallerrornumber.service +++ b/test/test-execute/exec-systemcallerrornumber-name.service @@ -2,7 +2,7 @@ Description=Test for SystemCallErrorNumber [Service] -ExecStart=/bin/sh -x -c 'uname -a' +ExecStart=/usr/bin/python3 -c 'import os\ntry: os.uname()\nexcept Exception as e: exit(e.errno)' Type=oneshot SystemCallFilter=~uname SystemCallErrorNumber=EACCES diff --git a/test/test-execute/exec-systemcallerrornumber-number.service b/test/test-execute/exec-systemcallerrornumber-number.service new file mode 100644 index 0000000000..203215682f --- /dev/null +++ b/test/test-execute/exec-systemcallerrornumber-number.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test for SystemCallErrorNumber + +[Service] +ExecStart=/usr/bin/python3 -c 'import os\ntry: os.uname()\nexcept Exception as e: exit(e.errno)' +Type=oneshot +SystemCallFilter=~uname +SystemCallErrorNumber=255 diff --git a/test/test-execute/exec-systemcallfilter-failing.service b/test/test-execute/exec-systemcallfilter-failing.service index 5c6422f0fd..bcebc99507 100644 --- a/test/test-execute/exec-systemcallfilter-failing.service +++ b/test/test-execute/exec-systemcallfilter-failing.service @@ -2,7 +2,7 @@ Description=Test for SystemCallFilter [Service] -ExecStart=/bin/echo "This should not be seen" +ExecStart=/bin/sh -c 'echo "This should not be seen"' Type=oneshot SystemCallFilter=ioperm SystemCallFilter=~ioperm diff --git a/test/test-execute/exec-systemcallfilter-failing2.service b/test/test-execute/exec-systemcallfilter-failing2.service index 3516078e1f..2fdc0ed772 100644 --- a/test/test-execute/exec-systemcallfilter-failing2.service +++ b/test/test-execute/exec-systemcallfilter-failing2.service @@ -2,6 +2,6 @@ Description=Test for SystemCallFilter [Service] -ExecStart=/bin/echo "This should not be seen" +ExecStart=/bin/sh -c 'echo "This should not be seen"' Type=oneshot SystemCallFilter=~write open execve exit_group close mmap munmap fstat DONOTEXIST diff --git a/test/test-execute/exec-systemcallfilter-not-failing.service b/test/test-execute/exec-systemcallfilter-not-failing.service index c794b67edd..f3a752b3ef 100644 --- a/test/test-execute/exec-systemcallfilter-not-failing.service +++ b/test/test-execute/exec-systemcallfilter-not-failing.service @@ -2,7 +2,7 @@ Description=Test for SystemCallFilter [Service] -ExecStart=/bin/echo "Foo bar" +ExecStart=/bin/sh -c 'echo "Foo bar"' Type=oneshot SystemCallFilter=~read write open execve ioperm SystemCallFilter=ioctl diff --git a/test/test-execute/exec-systemcallfilter-not-failing2.service b/test/test-execute/exec-systemcallfilter-not-failing2.service index a62c81bd48..1df076ab90 100644 --- a/test/test-execute/exec-systemcallfilter-not-failing2.service +++ b/test/test-execute/exec-systemcallfilter-not-failing2.service @@ -2,6 +2,6 @@ Description=Test for SystemCallFilter [Service] -ExecStart=/bin/echo "Foo bar" +ExecStart=/bin/sh -c 'echo "Foo bar"' Type=oneshot SystemCallFilter= diff --git a/test/test-execute/exec-systemcallfilter-system-user-nfsnobody.service b/test/test-execute/exec-systemcallfilter-system-user-nfsnobody.service index 9393e0a998..b1195d0d25 100644 --- a/test/test-execute/exec-systemcallfilter-system-user-nfsnobody.service +++ b/test/test-execute/exec-systemcallfilter-system-user-nfsnobody.service @@ -2,7 +2,7 @@ Description=Test for SystemCallFilter in system mode with User set [Service] -ExecStart=/bin/echo "Foo bar" +ExecStart=/bin/sh -c 'echo "Foo bar"' Type=oneshot User=nfsnobody SystemCallFilter=~read write open execve ioperm diff --git a/test/test-execute/exec-systemcallfilter-system-user.service b/test/test-execute/exec-systemcallfilter-system-user.service index 462f94133d..da129a30e4 100644 --- a/test/test-execute/exec-systemcallfilter-system-user.service +++ b/test/test-execute/exec-systemcallfilter-system-user.service @@ -2,7 +2,7 @@ Description=Test for SystemCallFilter in system mode with User set [Service] -ExecStart=/bin/echo "Foo bar" +ExecStart=/bin/sh -c 'echo "Foo bar"' Type=oneshot User=nobody SystemCallFilter=~read write open execve ioperm diff --git a/test/test-execute/exec-systemcallfilter-with-errno-name.service b/test/test-execute/exec-systemcallfilter-with-errno-name.service new file mode 100644 index 0000000000..8380d5a155 --- /dev/null +++ b/test/test-execute/exec-systemcallfilter-with-errno-name.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test for SystemCallFilter with errno name + +[Service] +ExecStart=/usr/bin/python3 -c 'import os\ntry: os.uname()\nexcept Exception as e: exit(e.errno)' +Type=oneshot +SystemCallFilter=~uname:EILSEQ +SystemCallErrorNumber=EACCES diff --git a/test/test-execute/exec-systemcallfilter-with-errno-number.service b/test/test-execute/exec-systemcallfilter-with-errno-number.service new file mode 100644 index 0000000000..dbb9540a1e --- /dev/null +++ b/test/test-execute/exec-systemcallfilter-with-errno-number.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test for SystemCallFilter with errno number + +[Service] +ExecStart=/usr/bin/python3 -c 'import os\ntry: os.uname()\nexcept Exception as e: exit(e.errno)' +Type=oneshot +SystemCallFilter=~uname:255 +SystemCallErrorNumber=EACCES diff --git a/test/test-execute/exec-unset-environment.service b/test/test-execute/exec-unsetenvironment.service index 5b0123b81e..5b0123b81e 100644 --- a/test/test-execute/exec-unset-environment.service +++ b/test/test-execute/exec-unsetenvironment.service diff --git a/test/test-functions b/test/test-functions index 745c0a9abe..a2f82725d1 100644 --- a/test/test-functions +++ b/test/test-functions @@ -12,15 +12,16 @@ KERNEL_MODS="/lib/modules/$KERNEL_VER/" QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}" NSPAWN_TIMEOUT="${NSPAWN_TIMEOUT:-infinity}" TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out -[[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext3}" +[[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext4}" UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}" +EFI_MOUNT="$(bootctl -p 2>/dev/null || echo /boot)" if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2 ROOTLIBDIR=/usr/lib/systemd fi -BASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm" +BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false" DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find" STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))" @@ -61,10 +62,10 @@ function find_qemu_bin() { run_qemu() { if [ -f /etc/machine-id ]; then read MACHINE_ID < /etc/machine-id - [ -z "$INITRD" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/initrd" ] \ - && INITRD="/boot/$MACHINE_ID/$KERNEL_VER/initrd" - [ -z "$KERNEL_BIN" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/linux" ] \ - && KERNEL_BIN="/boot/$MACHINE_ID/$KERNEL_VER/linux" + [ -z "$INITRD" ] && [ -e "$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/initrd" ] \ + && INITRD="$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/initrd" + [ -z "$KERNEL_BIN" ] && [ -e "$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/linux" ] \ + && KERNEL_BIN="$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/linux" fi if [[ ! "$KERNEL_BIN" ]]; then |