diff options
author | Michael Biebl <biebl@debian.org> | 2017-10-10 00:22:57 +0200 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2017-10-10 00:22:57 +0200 |
commit | f5e65279187b6aa0c0c5a00b14dca9eab441ffb2 (patch) | |
tree | b834735b2b8fabf24499bb8cc12d4f24870436f7 /test | |
parent | 81c583552ee1c3355cdef1b11a33737dd98e6971 (diff) | |
download | systemd-f5e65279187b6aa0c0c5a00b14dca9eab441ffb2.tar.gz |
New upstream version 235
Diffstat (limited to 'test')
39 files changed, 294 insertions, 696 deletions
diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 987a32548f..0000000000 --- a/test/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Just a little hook script to easy building when in this directory -.PHONY: all check clean - -all: - $(MAKE) -C .. - -clean: - @for i in TEST-[0-9]*; do \ - [ -d $$i ] || continue ; \ - [ -f $$i/Makefile ] || continue ; \ - make -C $$i clean ; \ - done - -check: - $(MAKE) -C .. all - @for i in TEST-[0-9]*; do \ - [ -d $$i ] || continue ; \ - [ -f $$i/Makefile ] || continue ; \ - make -C $$i all ; \ - done diff --git a/test/Makefile.guess b/test/Makefile.guess new file mode 100644 index 0000000000..1916d09a6c --- /dev/null +++ b/test/Makefile.guess @@ -0,0 +1,14 @@ +# 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 5e89a29eff..b895de8bcb 100644 --- a/test/TEST-01-BASIC/Makefile +++ b/test/TEST-01-BASIC/Makefile @@ -1,10 +1,4 @@ -all: - @make -s --no-print-directory -C ../.. all - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --all -setup: - @make --no-print-directory -C ../.. all - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --setup -clean: - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean -run: - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --run +include ../Makefile.guess + +all setup clean run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 041195dcd8..8b21ba05d3 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -1,38 +1,11 @@ #!/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="Basic systemd setup" . $TEST_BASE_DIR/test-functions -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - if run_nspawn; then - check_result_nspawn || return 1 - else - dwarn "can't run systemd-nspawn, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -71,10 +44,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh index aea0fc53f6..1280148b58 100755 --- a/test/TEST-02-CRYPTSETUP/test.sh +++ b/test/TEST-02-CRYPTSETUP/test.sh @@ -1,7 +1,9 @@ #!/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="cryptsetup systemd setup" +TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions @@ -24,15 +26,6 @@ check_result_qemu() { } -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image echo -n test >$TESTDIR/keyfile @@ -86,9 +79,9 @@ EOF } test_cleanup() { - umount $TESTDIR/root/var 2>/dev/null + [ -d $TESTDIR/root/var ] && mountpoint $TESTDIR/root/var && umount $TESTDIR/root/var [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt - umount $TESTDIR/root 2>/dev/null + umount $TESTDIR/root 2>/dev/null || true [[ $LOOPDEV ]] && losetup -d $LOOPDEV return 0 } diff --git a/test/TEST-03-JOBS/test-jobs.sh b/test/TEST-03-JOBS/test-jobs.sh index 48926290a6..4c954d0397 100755 --- a/test/TEST-03-JOBS/test-jobs.sh +++ b/test/TEST-03-JOBS/test-jobs.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash -e # Test merging of a --job-mode=ignore-dependencies job into a previously # installed job. @@ -10,7 +10,7 @@ while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do systemctl list-jobs > /root/list-jobs.txt done -grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1 +grep 'hello\.service.*waiting' /root/list-jobs.txt # This is supposed to finish quickly, not wait for sleep to finish. START_SEC=$(date -u '+%s') @@ -18,36 +18,36 @@ systemctl start --job-mode=ignore-dependencies hello END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) -[ "$ELAPSED" -lt 3 ] || exit 1 +[ "$ELAPSED" -lt 3 ] # sleep should still be running, hello not. systemctl list-jobs > /root/list-jobs.txt -grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1 +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 || exit 1 +systemctl stop sleep.service hello-after-sleep.target # Test for a crash when enqueuing a JOB_NOP when other job already exists -systemctl start --no-block hello-after-sleep.target || exit 1 +systemctl start --no-block hello-after-sleep.target # hello.service should still be waiting, so these try-restarts will collapse # into NOPs. -systemctl try-restart --job-mode=fail hello.service || exit 1 -systemctl try-restart hello.service || exit 1 -systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1 +systemctl try-restart --job-mode=fail hello.service +systemctl try-restart hello.service +systemctl stop hello.service sleep.service hello-after-sleep.target # TODO: add more job queueing/merging tests here. # Test for irreversible jobs -systemctl start unstoppable.service || exit 1 +systemctl start unstoppable.service # This is expected to fail with 'job cancelled' systemctl stop unstoppable.service && exit 1 # But this should succeed -systemctl stop --job-mode=replace-irreversibly unstoppable.service || exit 1 +systemctl stop --job-mode=replace-irreversibly unstoppable.service # We're going to shutdown soon. Let's see if it succeeds when # there's an active service that tries to be unstoppable. # Shutdown of the container/VM will hang if not. -systemctl start unstoppable.service || exit 1 +systemctl start unstoppable.service # Test waiting for a started unit(s) to terminate again cat <<EOF > /run/systemd/system/wait2.service @@ -65,7 +65,7 @@ EOF # wait2 succeeds START_SEC=$(date -u '+%s') -systemctl start --wait wait2.service || exit 1 +systemctl start --wait wait2.service END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1 diff --git a/test/TEST-03-JOBS/test.sh b/test/TEST-03-JOBS/test.sh index ab0de0bfd1..88bbf3cdac 100755 --- a/test/TEST-03-JOBS/test.sh +++ b/test/TEST-03-JOBS/test.sh @@ -1,38 +1,11 @@ #!/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="Job-related tests" . $TEST_BASE_DIR/test-functions -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - if run_nspawn; then - check_result_nspawn || return 1 - else - dwarn "can't run systemd-nspawn, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -69,10 +42,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-04-JOURNAL/test.sh b/test/TEST-04-JOURNAL/test.sh index 3ccf113019..30e7b181b2 100755 --- a/test/TEST-04-JOURNAL/test.sh +++ b/test/TEST-04-JOURNAL/test.sh @@ -1,38 +1,11 @@ #!/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="Journal-related tests" . $TEST_BASE_DIR/test-functions -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - if run_nspawn; then - check_result_nspawn || return 1 - else - dwarn "can't run systemd-nspawn, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -75,10 +48,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-05-RLIMITS/test.sh b/test/TEST-05-RLIMITS/test.sh index a5f7e8de0b..a1b855c5fb 100755 --- a/test/TEST-05-RLIMITS/test.sh +++ b/test/TEST-05-RLIMITS/test.sh @@ -1,38 +1,11 @@ #!/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="Resource limits-related tests" . $TEST_BASE_DIR/test-functions -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - if run_nspawn; then - check_result_nspawn || return 1 - else - dwarn "can't run systemd-nspawn, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -71,10 +44,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-06-SELINUX/test.sh b/test/TEST-06-SELINUX/test.sh index 1ae4a7c0d9..e0c4c10e1c 100755 --- a/test/TEST-06-SELINUX/test.sh +++ b/test/TEST-06-SELINUX/test.sh @@ -1,7 +1,9 @@ #!/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="SELinux tests" +TEST_NO_NSPAWN=1 # Requirements: # Fedora 23 @@ -12,29 +14,6 @@ TEST_DESCRIPTION="SELinux tests" SETUP_SELINUX=yes KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux" -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -126,10 +105,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-07-ISSUE-1981/test.sh b/test/TEST-07-ISSUE-1981/test.sh index 2f7f01058e..88d143e479 100755 --- a/test/TEST-07-ISSUE-1981/test.sh +++ b/test/TEST-07-ISSUE-1981/test.sh @@ -1,22 +1,14 @@ #!/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="https://github.com/systemd/systemd/issues/1981" +TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions NSPAWN_TIMEOUT=30s -test_run() { - dwarn "skipping QEMU" - if run_nspawn; then - check_result_nspawn || return 1 - else - dwarn "can't run systemd-nspawn, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -50,10 +42,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-08-ISSUE-2730/test.sh b/test/TEST-08-ISSUE-2730/test.sh index 44831983b3..68159c331f 100755 --- a/test/TEST-08-ISSUE-2730/test.sh +++ b/test/TEST-08-ISSUE-2730/test.sh @@ -1,37 +1,15 @@ #!/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="https://github.com/systemd/systemd/issues/2730" +TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions SKIP_INITRD=yes QEMU_TIMEOUT=180 FSTYPE=ext4 -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - [ -n "$TIMED_OUT" ] && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -103,10 +81,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-09-ISSUE-2691/test.sh b/test/TEST-09-ISSUE-2691/test.sh index 8ae02e61ac..4c3e9496b4 100755 --- a/test/TEST-09-ISSUE-2691/test.sh +++ b/test/TEST-09-ISSUE-2691/test.sh @@ -1,36 +1,14 @@ #!/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="https://github.com/systemd/systemd/issues/2691" +TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions SKIP_INITRD=yes QEMU_TIMEOUT=90 -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - [ -n "$TIMED_OUT" ] && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -71,10 +49,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh index 4eca6784bc..e7eb1cb303 100755 --- a/test/TEST-10-ISSUE-2467/test.sh +++ b/test/TEST-10-ISSUE-2467/test.sh @@ -1,34 +1,13 @@ #!/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="https://github.com/systemd/systemd/issues/2467" +TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions SKIP_INITRD=yes -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -82,10 +61,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-11-ISSUE-3166/test.sh b/test/TEST-11-ISSUE-3166/test.sh index 0f269c8211..4602bdfc98 100755 --- a/test/TEST-11-ISSUE-3166/test.sh +++ b/test/TEST-11-ISSUE-3166/test.sh @@ -1,34 +1,13 @@ #!/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="https://github.com/systemd/systemd/issues/3166" +TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions SKIP_INITRD=yes -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -85,10 +64,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-12-ISSUE-3171/test.sh b/test/TEST-12-ISSUE-3171/test.sh index c252bdfbad..559fa469cd 100755 --- a/test/TEST-12-ISSUE-3171/test.sh +++ b/test/TEST-12-ISSUE-3171/test.sh @@ -1,19 +1,12 @@ #!/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="https://github.com/systemd/systemd/issues/3171" +TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions -test_run() { - if run_nspawn; then - check_result_nspawn || return 1 - else - dwarn "can't run systemd-nspawn, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -100,10 +93,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-13-NSPAWN-SMOKE/Makefile b/test/TEST-13-NSPAWN-SMOKE/Makefile index ff1470f852..41cca23c7f 100644 --- a/test/TEST-13-NSPAWN-SMOKE/Makefile +++ b/test/TEST-13-NSPAWN-SMOKE/Makefile @@ -1,11 +1,7 @@ -all: - @make -s --no-print-directory -C ../.. all - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --all -setup: - @make --no-print-directory -C ../.. all - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --setup +include ../Makefile.guess + +all setup run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ clean: @basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean @rm -f has-overflow -run: - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --run diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh index 75b99236a3..7f7380fd62 100755 --- a/test/TEST-13-NSPAWN-SMOKE/test.sh +++ b/test/TEST-13-NSPAWN-SMOKE/test.sh @@ -1,33 +1,12 @@ #!/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="systemd-nspawn smoke test" +TEST_NO_NSPAWN=1 SKIP_INITRD=yes . $TEST_BASE_DIR/test-functions -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -153,10 +132,4 @@ EOF umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-14-MACHINE-ID/Makefile b/test/TEST-14-MACHINE-ID/Makefile index 5e89a29eff..e9f93b1104 100644..120000 --- a/test/TEST-14-MACHINE-ID/Makefile +++ b/test/TEST-14-MACHINE-ID/Makefile @@ -1,10 +1 @@ -all: - @make -s --no-print-directory -C ../.. all - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --all -setup: - @make --no-print-directory -C ../.. all - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --setup -clean: - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean -run: - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --run +../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh index 35106e39d2..b932060bc2 100755 --- a/test/TEST-14-MACHINE-ID/test.sh +++ b/test/TEST-14-MACHINE-ID/test.sh @@ -1,33 +1,12 @@ #!/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="Basic systemd setup" +TEST_NO_NSPAWN=1 SKIP_INITRD=yes . $TEST_BASE_DIR/test-functions -check_result_qemu() { - ret=1 - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root - [[ -e $TESTDIR/root/testok ]] && ret=0 - [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR - cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root - [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed - ls -l $TESTDIR/journal/*/*.journal - test -s $TESTDIR/failed && ret=$(($ret+1)) - return $ret -} - -test_run() { - if run_qemu; then - check_result_qemu || return 1 - else - dwarn "can't run QEMU, skipping" - fi - return 0 -} - test_setup() { create_empty_image mkdir -p $TESTDIR/root @@ -110,10 +89,4 @@ chmod +x $initdir/test-machine-id-setup.sh umount $TESTDIR/root } -test_cleanup() { - umount $TESTDIR/root 2>/dev/null - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 -} - do_test "$@" diff --git a/test/TEST-15-DROPIN/test.sh b/test/TEST-15-DROPIN/test.sh index 1b460db7b1..b85bffafaf 100755 --- a/test/TEST-15-DROPIN/test.sh +++ b/test/TEST-15-DROPIN/test.sh @@ -1,24 +1,12 @@ #!/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="Dropin tests" +TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions - -test_run_nspawn() { - if ! run_nspawn; then - dwarn "can't run systemd-nspawn, skipping" - return 0 - fi - check_result_nspawn -} - -test_run() { - test_run_nspawn || return -} - test_setup() { # create the basic filesystem layout setup_basic_environment >/dev/null diff --git a/test/bus-policy/check-own-rules.conf b/test/bus-policy/check-own-rules.conf deleted file mode 100644 index bc2f415fcb..0000000000 --- a/test/bus-policy/check-own-rules.conf +++ /dev/null @@ -1,14 +0,0 @@ -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> -<busconfig> - <user>mybususer</user> - <listen>unix:path=/foo/bar</listen> - <listen>tcp:port=1234</listen> - <servicedir>/usr/share/foo</servicedir> - <policy context="default"> - <allow user="*"/> - <deny own="*"/> - <allow own_prefix="org.freedesktop.ManySystems"/> - </policy> - -</busconfig> diff --git a/test/bus-policy/hello.conf b/test/bus-policy/hello.conf deleted file mode 100644 index af09893de6..0000000000 --- a/test/bus-policy/hello.conf +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0"?> <!--*-nxml-*--> -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - -<busconfig> - - <policy context="default"> - <allow user="*"/> - - <deny user="1"/> - <deny group="1"/> - </policy> - -</busconfig> diff --git a/test/bus-policy/many-rules.conf b/test/bus-policy/many-rules.conf deleted file mode 100644 index 70dd538c11..0000000000 --- a/test/bus-policy/many-rules.conf +++ /dev/null @@ -1,61 +0,0 @@ -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> -<busconfig> - <user>mybususer</user> - <listen>unix:path=/foo/bar</listen> - <listen>tcp:port=1234</listen> - <includedir>basic.d</includedir> - <standard_session_servicedirs /> - <servicedir>/usr/share/foo</servicedir> - <include ignore_missing="yes">nonexistent.conf</include> - <policy context="default"> - <allow user="*"/> - <deny send_interface="org.freedesktop.System" send_member="Reboot"/> - <deny receive_interface="org.freedesktop.System" receive_member="Reboot"/> - <deny send_path="/foo/bar/SystemObjectThing" send_member="Reboot"/> - <deny own="org.freedesktop.System"/> - <deny own_prefix="org.freedesktop.ManySystems"/> - <deny send_destination="org.freedesktop.System"/> - <deny receive_sender="org.freedesktop.System"/> - <deny user="root"/> - <deny group="bin"/> - <allow send_type="error"/> - <allow send_type="method_call"/> - <allow send_type="method_return"/> - <allow send_type="signal"/> - <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo"/> - <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo" send_type="method_call"/> - </policy> - - <policy context="mandatory"> - <allow user="*"/> - <deny send_interface="org.freedesktop.System" send_member="Reboot"/> - <deny receive_interface="org.freedesktop.System" receive_member="Reboot"/> - <deny send_path="/foo/bar/SystemObjectThing" send_member="Reboot"/> - <deny own="org.freedesktop.System"/> - <deny own_prefix="org.freedesktop.ManySystems"/> - <deny send_destination="org.freedesktop.System"/> - <deny receive_sender="org.freedesktop.System"/> - <deny user="root"/> - <deny group="bin"/> - <allow send_type="error"/> - <allow send_type="method_call"/> - <allow send_type="method_return"/> - <allow send_type="signal"/> - <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo"/> - <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo" send_type="method_call"/> - </policy> - - <limit name="max_incoming_bytes">5000</limit> - <limit name="max_outgoing_bytes">5000</limit> - <limit name="max_message_size">300</limit> - <limit name="service_start_timeout">5000</limit> - <limit name="auth_timeout">6000</limit> - <limit name="max_completed_connections">50</limit> - <limit name="max_incomplete_connections">80</limit> - <limit name="max_connections_per_user">64</limit> - <limit name="max_pending_service_starts">64</limit> - <limit name="max_names_per_connection">256</limit> - <limit name="max_match_rules_per_connection">512</limit> - -</busconfig> diff --git a/test/bus-policy/methods.conf b/test/bus-policy/methods.conf deleted file mode 100644 index 4bc38f9151..0000000000 --- a/test/bus-policy/methods.conf +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0"?> <!--*-nxml-*--> -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - -<busconfig> - - <policy context="default"> - <deny send_type="method_call"/> - - <deny send_destination="org.test.test1"/> - <allow send_destination="org.test.test1" send_interface="org.test.int1"/> - <allow send_destination="org.test.test1" send_interface="org.test.int2"/> - - <allow receive_sender="org.test.test3" receive_interface="org.test.int3" receive_member="Member111"/> - </policy> - -</busconfig> diff --git a/test/bus-policy/ownerships.conf b/test/bus-policy/ownerships.conf deleted file mode 100644 index bc3a230a26..0000000000 --- a/test/bus-policy/ownerships.conf +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0"?> <!--*-nxml-*--> -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - -<busconfig> - - <policy context="default"> - <allow own="org.test.test1"/> - </policy> - - <policy context="mandatory"> - <deny own="org.test.test3"/> - </policy> - - <policy user="root"> - <allow own="org.test.test2"/> - <allow own="org.test.test3"/> - </policy> - - <policy user="1"> - <allow own="org.test.test4"/> - </policy> - -</busconfig> diff --git a/test/bus-policy/signals.conf b/test/bus-policy/signals.conf deleted file mode 100644 index 440e3fe6d0..0000000000 --- a/test/bus-policy/signals.conf +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0"?> <!--*-nxml-*--> -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - -<busconfig> - - <policy context="default"> - <allow send_type="signal"/> - </policy> - - <policy user="1"> - <deny send_type="signal"/> - </policy> - -</busconfig> diff --git a/test/bus-policy/test.conf b/test/bus-policy/test.conf deleted file mode 100644 index ee6afcdfbb..0000000000 --- a/test/bus-policy/test.conf +++ /dev/null @@ -1,20 +0,0 @@ -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> -<busconfig> - <!-- The following demonstrates how to punch holes in a default deny-all - policy so that a particular user can own a service, and other - connections can get messages from it --> - - <!-- Only root can own the FooService service, and - this user can only send the one kind of message --> - <policy user="root"> - <allow own="org.foo.FooService"/> - <allow send_interface="org.foo.FooBroadcastInterface"/> - </policy> - - <!-- Allow any connection to receive the message, but - only if the message is sent by the owner of FooService --> - <policy context="default"> - <allow receive_interface="org.foo.FooBroadcastInterface" receive_sender="org.foo.FooService"/> - </policy> -</busconfig> diff --git a/test/create-sys-script.py b/test/create-sys-script.py index 402b4f83ab..a4f1f302f6 100755 --- a/test/create-sys-script.py +++ b/test/create-sys-script.py @@ -26,14 +26,17 @@ OUTFILE_HEADER = """#!/usr/bin/env python3 # after adding or modifying anything in the test/sys/ directory -import os, sys, stat, tempfile, filecmp - +import os, sys +import stat +import tempfile +import filecmp +import subprocess -OUTFILE = "sys-script.py" OUTFILE_MODE = 0o775 OUTFILE_FUNCS = r""" import os, sys +import shutil def d(path, mode): os.mkdir(path, mode) @@ -45,7 +48,6 @@ def f(path, mode, contents): with open(path, "wb") as f: f.write(contents) os.chmod(path, mode) - """ OUTFILE_MAIN = """ @@ -57,17 +59,19 @@ if not os.path.isdir(sys.argv[1]): os.chdir(sys.argv[1]) +if os.path.exists('sys'): + shutil.rmtree('sys') """ def handle_dir(outfile, path): m = os.lstat(path).st_mode & 0o777 - outfile.write("d('{}', {:#o})\n".format(path, m)) + outfile.write(f"d('{path}', {m:#o})\n") def handle_link(outfile, path): src = os.readlink(path) - outfile.write("l('{}', '{}')\n".format(path, src)) + outfile.write(f"l('{path}', '{src}')\n") def escape_single_quotes(b): @@ -85,15 +89,15 @@ def handle_file(outfile, path): with open(path, "rb") as f: b = f.read() if b.count(b"\n") > 1: - r = "\n".join([ escape_single_quotes(l) for l in b.split(b"\n") ]) - r = "b'''{r}'''".format(r=r) + r = "\n".join( escape_single_quotes(l) for l in b.split(b"\n") ) + r = f"b'''{r}'''" else: r = repr(b) - outfile.write("f('{}', {:#o}, {})\n".format(path, m, r)) + outfile.write(f"f('{path}', {m:#o}, {r})\n") def process_sysdir(outfile): - for (dirpath, dirnames, filenames) in os.walk("sys"): + for (dirpath, dirnames, filenames) in os.walk('sys'): handle_dir(outfile, dirpath) for d in dirnames: path = os.path.join(dirpath, d) @@ -139,7 +143,9 @@ def verify_file(tmpd, path_a): def verify_script(tmpd): + any = False for (dirpath, dirnames, filenames) in os.walk("sys"): + any = True try: path = dirpath verify_dir(tmpd, path) @@ -155,29 +161,31 @@ def verify_script(tmpd): elif stat.S_ISREG(mode): verify_file(tmpd, path) except Exception: - print("FAIL on '{}'".format(path), file=sys.stderr) + print(f'FAIL on "{path}"', file=sys.stderr) raise - + if not any: + exit('Nothing found!') if __name__ == "__main__": - # Always operate in the dir where this script is - os.chdir(os.path.dirname(sys.argv[0])) + if len(sys.argv) < 2: + exit('Usage: create-sys-script.py /path/to/test/') - if not os.path.isdir("sys"): - exit("No sys/ directory; please create before running this") + outfile = os.path.abspath(os.path.dirname(sys.argv[0]) + '/sys-script.py') + print(f'Creating {outfile} using contents of {sys.argv[1]}/sys') - print("Creating {} using contents of sys/".format(OUTFILE)) + os.chdir(sys.argv[1]) - with open(OUTFILE, "w") as f: - os.chmod(OUTFILE, OUTFILE_MODE) - f.write(OUTFILE_HEADER.replace(os.path.basename(sys.argv[0]), OUTFILE)) + with open(outfile, "w") as f: + os.chmod(outfile, OUTFILE_MODE) + f.write(OUTFILE_HEADER.replace(os.path.basename(sys.argv[0]), + os.path.basename(outfile))) f.write(OUTFILE_FUNCS) f.write(OUTFILE_MAIN) process_sysdir(f) with tempfile.TemporaryDirectory() as tmpd: - print("Recreating sys/ using {} at {}".format(OUTFILE, tmpd)) - os.system("./{script} {tmpd}".format(script=OUTFILE, tmpd=tmpd)) + print(f'Recreating sys/ using {outfile} at {tmpd}') + subprocess.check_call([outfile, tmpd]) verify_script(tmpd) - print("Verification successful, {} is correct".format(OUTFILE)) + print(f'Verification successful, {outfile} is correct') diff --git a/test/hwdb-test.sh b/test/hwdb-test.sh index 5373930df4..2221c0d7fd 100755 --- a/test/hwdb-test.sh +++ b/test/hwdb-test.sh @@ -21,7 +21,7 @@ set -e ROOTDIR=$(dirname $(dirname $(readlink -f $0))) -SYSTEMD_HWDB=${builddir:-.}/systemd-hwdb +SYSTEMD_HWDB=./systemd-hwdb if [ ! -x "$SYSTEMD_HWDB" ]; then echo "$SYSTEMD_HWDB does not exist, please build first" diff --git a/test/meson.build b/test/meson.build index 55e693ac72..995a971778 100644 --- a/test/meson.build +++ b/test/meson.build @@ -64,6 +64,7 @@ test_data_files = ''' 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 @@ -94,6 +95,7 @@ test_data_files = ''' test-execute/exec-systemcallfilter-not-failing.service test-execute/exec-systemcallfilter-system-user.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 @@ -126,19 +128,12 @@ test_data_files = ''' 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 - bus-policy/hello.conf - bus-policy/methods.conf - bus-policy/ownerships.conf - bus-policy/signals.conf - bus-policy/check-own-rules.conf - bus-policy/many-rules.conf - bus-policy/test.conf hwdb/10-bad.hwdb journal-data/journal-1.txt journal-data/journal-2.txt '''.split() -if conf.get('ENABLE_RESOLVED', false) +if conf.get('ENABLE_RESOLVE') == 1 test_data_files += ''' test-resolve/_openpgpkey.fedoraproject.org.pkts test-resolve/fedoraproject.org.pkts @@ -165,3 +160,27 @@ if install_tests install_dir : testsdir + '/testdata/' + subdir) endforeach endif + +############################################################ + +sysv_generator_test_py = find_program('sysv-generator-test.py') +test('sysv-generator-test', + sysv_generator_test_py) + +############################################################ + +# prepare test/sys tree +sys_script_py = find_program('sys-script.py') +custom_target( + 'sys', + command : [sys_script_py, meson.current_build_dir()], + output : 'sys', + build_by_default : true) + +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) diff --git a/test/networkd-test.py b/test/networkd-test.py index eee8b65ec0..5760ca5137 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -334,7 +334,7 @@ DHCP=%s # check networkctl state out = subprocess.check_output(['networkctl']) - self.assertRegex(out, (r'%s\s+ether\s+routable\s+unmanaged' % self.if_router).encode()) + self.assertRegex(out, (r'%s\s+ether\s+[a-z-]+\s+unmanaged' % self.if_router).encode()) self.assertRegex(out, (r'%s\s+ether\s+routable\s+configured' % self.iface).encode()) out = subprocess.check_output(['networkctl', 'status', self.iface]) @@ -752,7 +752,7 @@ DNS=192.168.5.1 EOF # run networkd as in systemd-networkd.service -exec $(systemctl cat systemd-networkd.service | sed -n '/^ExecStart=/ { s/^.*=//; p}') +exec $(systemctl cat systemd-networkd.service | sed -n '/^ExecStart=/ { s/^.*=//; s/^[@+-]//; s/^!*//; p}') ''' % {'ifr': self.if_router, 'ifc': self.iface, 'addr6': ipv6 and 'Address=2600::1/64' or '', 'dhopts': dhcpserver_opts or ''}) diff --git a/test/sys-script.py b/test/sys-script.py index 6c9ee5ff83..2de7d7ea30 100755 --- a/test/sys-script.py +++ b/test/sys-script.py @@ -20,6 +20,7 @@ # import os, sys +import shutil def d(path, mode): os.mkdir(path, mode) @@ -32,7 +33,6 @@ def f(path, mode, contents): f.write(contents) os.chmod(path, mode) - if len(sys.argv) < 2: exit("Usage: {} <target dir>".format(sys.argv[0])) @@ -41,6 +41,8 @@ if not os.path.isdir(sys.argv[1]): os.chdir(sys.argv[1]) +if os.path.exists('sys'): + shutil.rmtree('sys') d('sys', 0o755) d('sys/kernel', 0o775) f('sys/kernel/kexec_crash_loaded', 0o664, b'0\n') diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py index d116fffe38..18bb40f812 100755 --- a/test/sysv-generator-test.py +++ b/test/sysv-generator-test.py @@ -26,14 +26,9 @@ import tempfile import shutil from glob import glob import collections +from configparser import RawConfigParser -try: - from configparser import RawConfigParser -except ImportError: - # python 2 - from ConfigParser import RawConfigParser - -sysv_generator = os.path.join(os.environ.get('builddir', '.'), 'systemd-sysv-generator') +sysv_generator = './systemd-sysv-generator' class MultiDict(collections.OrderedDict): def __setitem__(self, key, value): @@ -153,7 +148,8 @@ class SysvGeneratorTest(unittest.TestCase): link = os.path.join(self.out_dir, '%s.target.wants' % target, unit) if target in targets: unit_file = os.readlink(link) - self.assertTrue(os.path.exists(unit_file)) + # os.path.exists() will fail on a dangling symlink + self.assertTrue(os.path.exists(link)) self.assertEqual(os.path.basename(unit_file), unit) else: self.assertFalse(os.path.exists(link), diff --git a/test/test-exec-deserialization.py b/test/test-exec-deserialization.py index 39a9e62e15..c3fe0824c7 100755 --- a/test/test-exec-deserialization.py +++ b/test/test-exec-deserialization.py @@ -178,6 +178,37 @@ class ExecutionResumeTest(unittest.TestCase): self.assertTrue(not os.path.exists(self.output_file)) + def test_issue_6533(self): + unit = "test-issue-6533.service" + unitfile_path = "/run/systemd/system/{}".format(unit) + + content = ''' + [Service] + ExecStart=/bin/sleep 5 + ''' + + with open(unitfile_path, 'w') as f: + f.write(content) + + self.reload() + + subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', unit]) + time.sleep(2) + + content = ''' + [Service] + ExecStart=/bin/sleep 5 + ExecStart=/bin/true + ''' + + with open(unitfile_path, 'w') as f: + f.write(content) + + self.reload() + time.sleep(5) + + self.assertTrue(subprocess.call("journalctl -b _PID=1 | grep -q 'Freezing execution'", shell=True) != 0) + def tearDown(self): for f in [self.output_file, self.unitfile_path]: try: diff --git a/test/test-execute/exec-dynamicuser-state-dir.service b/test/test-execute/exec-dynamicuser-state-dir.service new file mode 100644 index 0000000000..7e2d88450b --- /dev/null +++ b/test/test-execute/exec-dynamicuser-state-dir.service @@ -0,0 +1,19 @@ +[Unit] +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 + +# 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' + +Type=oneshot +DynamicUser=yes +StateDirectory=waldo quux/pief diff --git a/test/test-execute/exec-unset-environment.service b/test/test-execute/exec-unset-environment.service new file mode 100644 index 0000000000..5b0123b81e --- /dev/null +++ b/test/test-execute/exec-unset-environment.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test for UnsetEnvironment + +[Service] +ExecStart=/bin/sh -x -c 'test "$$FOO" = "bar" && test "$${QUUX-X}" = "X" && test "$$VAR3" = "value3" && test "$${VAR4-X}" = "X" && test "$$VAR5" = "value5" && test "$${X%b-X}" = "X"' +Type=oneshot +Environment=FOO=bar QUUX=waldo VAR3=value3 VAR4=value4 VAR5=value5 X%b=%U +UnsetEnvironment=QUUX=waldo VAR3=somethingelse VAR4 X%b=%U diff --git a/test/test-functions b/test/test-functions index ea4f700841..745c0a9abe 100644 --- a/test/test-functions +++ b/test/test-functions @@ -4,9 +4,9 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH -LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes) -LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes) -LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes) +LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes || true) +LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes || true) +LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes || true) KERNEL_VER=${KERNEL_VER-$(uname -r)} KERNEL_MODS="/lib/modules/$KERNEL_VER/" QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}" @@ -23,6 +23,10 @@ fi BASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm" 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)))" +STATEFILE="$STATEDIR/.testdir" +TESTLOG="$STATEDIR/test.log" + function find_qemu_bin() { # SUSE and Red Hat call the binary qemu-kvm # Debian and Gentoo call it kvm @@ -155,7 +159,7 @@ $KERNEL_APPEND \ run_nspawn() { [[ -d /run/systemd/system ]] || return 1 - local _nspawn_cmd="../../systemd-nspawn --register=no --kill-signal=SIGKILL --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND" + local _nspawn_cmd="$BUILD_DIR/systemd-nspawn --register=no --kill-signal=SIGKILL --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND" if [[ "$NSPAWN_TIMEOUT" != "infinity" ]]; then _nspawn_cmd="timeout --foreground $NSPAWN_TIMEOUT $_nspawn_cmd" fi @@ -317,7 +321,12 @@ install_dmevent() { install_systemd() { # install compiled files - (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install) + local _ninja_bin=$(type -P ninja || type -P ninja-build) + if [[ -z "$_ninja_bin" ]]; then + dfatal "ninja was not found" + exit 1 + fi + (set -x; DESTDIR=$initdir "$_ninja_bin" -C $BUILD_DIR install) # remove unneeded documentation rm -fr $initdir/usr/share/{man,doc} # we strip binaries since debug symbols increase binaries size a lot @@ -375,6 +384,22 @@ check_result_nspawn() { return $ret } +# can be overridden in specific test +check_result_qemu() { + ret=1 + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + [[ -e $TESTDIR/root/testok ]] && ret=0 + [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR + cp -a $TESTDIR/root/var/log/journal $TESTDIR + umount $TESTDIR/root + [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed + ls -l $TESTDIR/journal/*/*.journal + test -s $TESTDIR/failed && ret=$(($ret+1)) + [ -n "$TIMED_OUT" ] && ret=$(($ret+1)) + return $ret +} + strip_binaries() { if [[ "$STRIP_BINARIES" = "no" ]]; then ddebug "Don't strip binaries" @@ -396,13 +421,14 @@ EOF install_execs() { ddebug "install any Execs from the service files" ( - export PKG_CONFIG_PATH=$TEST_BASE_DIR/../src/core/ + export PKG_CONFIG_PATH=$BUILD_DIR/src/core/ systemdsystemunitdir=$(pkg-config --variable=systemdsystemunitdir systemd) systemduserunitdir=$(pkg-config --variable=systemduserunitdir systemd) egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/{$systemdsystemunitdir,$systemduserunitdir}/*.service \ | while read i; do - i=${i##Exec*=}; i=${i##-} - inst $i + i=${i##Exec*=}; i=${i##[@+\!-]}; i=${i##\!} + # some {rc,halt}.local scripts and programs are okay to not exist, the rest should + inst $i || [ "${i%.local}" != "$i" ] || [ "${i%systemd-update-done}" != "$i" ] done ) } @@ -437,15 +463,15 @@ install_ld_so_conf() { } install_config_files() { - inst /etc/sysconfig/init + inst /etc/sysconfig/init || true inst /etc/passwd inst /etc/shadow inst /etc/login.defs inst /etc/group inst /etc/shells inst /etc/nsswitch.conf - inst /etc/pam.conf - inst /etc/securetty + inst /etc/pam.conf || true + inst /etc/securetty || true inst /etc/os-release inst /etc/localtime # we want an empty environment @@ -495,12 +521,12 @@ install_dbus() { install_pam() { ( - [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f - find \ - /etc/pam.d \ - /etc/security \ - /lib64/security \ - /lib/security -xtype f \ + if [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null; then + find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f + else + find /lib*/security -xtype f + fi + find /etc/pam.d /etc/security -xtype f ) | while read file; do inst $file done @@ -605,7 +631,6 @@ inst_libs() { } import_testdir() { - STATEFILE=".testdir" [[ -e $STATEFILE ]] && . $STATEFILE if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX) @@ -899,7 +924,7 @@ inst_library() { # Create additional symlinks. See rev_symlinks description. for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do - [[ ! -e $initdir/$_symlink ]] && { + [[ -e $initdir/$_symlink ]] || { ddebug "Creating extra symlink: $_symlink" inst_symlink $_symlink } @@ -1360,6 +1385,31 @@ setup_suse() { inst_simple "/usr/lib/systemd/system/haveged.service" } +# can be overridden in specific test +test_cleanup() { + umount $TESTDIR/root 2>/dev/null || true + [[ $LOOPDEV ]] && losetup -d $LOOPDEV || true + return 0 +} + +test_run() { + if [ -z "$TEST_NO_QEMU" ]; then + if run_qemu; then + check_result_qemu || return 1 + else + dwarn "can't run QEMU, skipping" + fi + fi + if [ -z "$TEST_NO_NSPAWN" ]; then + if run_nspawn; then + check_result_nspawn || return 1 + else + dwarn "can't run systemd-nspawn, skipping" + fi + fi + return 0 +} + do_test() { if [[ $UID != "0" ]]; then echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2 @@ -1375,6 +1425,8 @@ do_test() { [[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break done + mkdir -p "$STATEDIR" + import_testdir import_initdir @@ -1382,9 +1434,7 @@ do_test() { case $1 in --run) echo "TEST RUN: $TEST_DESCRIPTION" - test_run - ret=$? - if [ $ret -eq 0 ]; then + if test_run; then echo "TEST RUN: $TEST_DESCRIPTION [OK]" else echo "TEST RUN: $TEST_DESCRIPTION [FAILED]" @@ -1393,30 +1443,30 @@ do_test() { --setup) echo "TEST SETUP: $TEST_DESCRIPTION" test_setup - exit $?;; + ;; --clean) echo "TEST CLEANUP: $TEST_DESCRIPTION" test_cleanup rm -fr "$TESTDIR" - rm -f .testdir - exit $?;; + rm -f "$STATEFILE" + ;; --all) + ret=0 echo -n "TEST: $TEST_DESCRIPTION "; ( test_setup && test_run ret=$? test_cleanup rm -fr "$TESTDIR" - rm -f .testdir + rm -f "$STATEFILE" exit $ret - ) </dev/null >test.log 2>&1 - ret=$? + ) </dev/null >"$TESTLOG" 2>&1 || ret=$? if [ $ret -eq 0 ]; then - rm test.log + rm "$TESTLOG" echo "[OK]" else echo "[FAILED]" - echo "see $(pwd)/test.log" + echo "see $TESTLOG" fi exit $ret;; *) break ;; diff --git a/test/udev-test.pl b/test/udev-test.pl index 7e33479004..0d348e5c08 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -333,6 +333,30 @@ SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo EOF }, { + desc => "program arguments combined with escaped double quotes, part 1", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "foo2" , + rules => <<EOF +SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}" +EOF + }, + { + desc => "program arguments combined with escaped double quotes, part 2", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "foo2" , + rules => <<EOF +SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}" +EOF + }, + { + desc => "program arguments combined with escaped double quotes, part 3", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "foo2" , + rules => <<EOF +SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}" +EOF + }, + { desc => "characters before the %c{N} substitution", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "my-foo9" , |