diff --git a/meson.build b/meson.build index 5af7c112f1..fb90077563 100644 --- a/meson.build +++ b/meson.build @@ -49,9 +49,12 @@ fuzzer_build = want_ossfuzz or want_libfuzzer ##################################################################### # Try to install the git pre-commit hook -git_hook = run_command(join_paths(project_source_root, 'tools/add-git-hook.sh')) -if git_hook.returncode() == 0 - message(git_hook.stdout().strip()) +add_git_hook_sh = find_program('tools/add-git-hook.sh', required : false) +if add_git_hook_sh.found() + git_hook = run_command(add_git_hook_sh) + if git_hook.returncode() == 0 + message(git_hook.stdout().strip()) + endif endif ##################################################################### @@ -2503,7 +2506,7 @@ if conf.get('ENABLE_BINFMT') == 1 endif if conf.get('ENABLE_REPART') == 1 - executable('systemd-repart', + exe = executable('systemd-repart', systemd_repart_sources, include_directories : includes, link_with : [libshared], @@ -2515,6 +2518,12 @@ if conf.get('ENABLE_REPART') == 1 install_rpath : rootlibexecdir, install : true, install_dir : rootbindir) + + if want_tests != 'false' + test('test-repart', + test_repart_sh, + args : exe.full_path()) + endif endif if conf.get('ENABLE_VCONSOLE') == 1 @@ -2959,13 +2968,20 @@ if conf.get('ENABLE_NETWORKD') == 1 install_dir : rootbindir) public_programs += exe - executable('systemd-network-generator', + exe = executable('systemd-network-generator', network_generator_sources, include_directories : includes, link_with : [networkd_link_with], install_rpath : rootlibexecdir, install : true, install_dir : rootlibexecdir) + + if want_tests != 'false' + test('test-network-generator-conversion', + test_network_generator_conversion_sh, + # https://github.com/mesonbuild/meson/issues/2681 + args : exe.full_path()) + endif endif executable('systemd-sulogin-shell', @@ -3467,6 +3483,7 @@ foreach tuple : [ ['debug siphash'], ['valgrind', conf.get('VALGRIND') == 1], ['trace logging', conf.get('LOG_TRACE') == 1], + ['install tests', install_tests], ['link-udev-shared', get_option('link-udev-shared')], ['link-systemctl-shared', get_option('link-systemctl-shared')], ['link-networkd-shared', get_option('link-networkd-shared')], diff --git a/semaphoreci/semaphore-runner.sh b/semaphoreci/semaphore-runner.sh index 2bf8ce0d52..177fe77cda 100755 --- a/semaphoreci/semaphore-runner.sh +++ b/semaphoreci/semaphore-runner.sh @@ -17,7 +17,7 @@ PHASES=(${@:-SETUP RUN}) create_container() { # create autopkgtest LXC image; this sometimes fails with "Unable to fetch # GPG key from keyserver", so retry a few times - for retry in $(seq 5); do + for retry in {1..5}; do sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH --keyserver hkp://keyserver.ubuntu.com:80 && break sleep $((retry*retry)) done diff --git a/src/partition/meson.build b/src/partition/meson.build index d0c111a473..3a75d5712d 100644 --- a/src/partition/meson.build +++ b/src/partition/meson.build @@ -3,3 +3,5 @@ systemd_repart_sources = files(''' repart.c '''.split()) + +test_repart_sh = find_program('test-repart.sh') diff --git a/src/partition/test-repart.sh b/src/partition/test-repart.sh new file mode 100755 index 0000000000..7da6b1b027 --- /dev/null +++ b/src/partition/test-repart.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +set -ex + +repart=$1 +test -x $repart + +D=$(mktemp --directory) +trap "rm -rf '$D'" EXIT INT QUIT PIPE +mkdir -p $D/definitions + +truncate -s 1G $D/zzz + +SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8 + +$repart $D/zzz --empty=force --dry-run=no --seed=$SEED + +sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' > $D/empty + +cmp $D/empty - <$D/definitions/root.conf <$D/definitions/home.conf < $D/definitions/swap.conf <$D/populated + +cmp $D/populated - <$D/definitions/swap.conf <$D/definitions/extra.conf <$D/populated2 + +cmp $D/populated2 - <$D/populated3 + +cmp $D/populated3 - <= 0); assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0); N = g.gl_pathc; fnames = g.gl_pathv; diff --git a/src/shared/tests.c b/src/shared/tests.c index 96b5b805a9..764e4656bb 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -58,21 +58,25 @@ static void load_testdata_env(void) { setenv(*k, *v, 0); } -const char* get_testdata_dir(void) { - const char *env; +int get_testdata_dir(const char *suffix, char **ret) { + const char *dir; + char *p; load_testdata_env(); /* if the env var is set, use that */ - env = getenv("SYSTEMD_TEST_DATA"); - if (!env) - env = SYSTEMD_TEST_DATA; - if (access(env, F_OK) < 0) { - fprintf(stderr, "ERROR: $SYSTEMD_TEST_DATA directory [%s] does not exist\n", env); - exit(EXIT_FAILURE); - } + dir = getenv("SYSTEMD_TEST_DATA"); + if (!dir) + dir = SYSTEMD_TEST_DATA; + if (access(dir, F_OK) < 0) + return log_error_errno(errno, "ERROR: $SYSTEMD_TEST_DATA directory [%s] not accesible: %m", dir); - return env; + p = path_join(dir, suffix); + if (!p) + return log_oom(); + + *ret = p; + return 0; } const char* get_catalog_dir(void) { diff --git a/src/shared/tests.h b/src/shared/tests.h index 5a6fd53f36..6817ef4860 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -20,7 +20,7 @@ static inline bool manager_errno_skip_test(int r) { char* setup_fake_runtime_dir(void); int enter_cgroup_subroot(char **ret_cgroup); -const char* get_testdata_dir(void); +int get_testdata_dir(const char *suffix, char **ret); const char* get_catalog_dir(void); bool slow_tests_enabled(void); void test_setup_logging(int level); diff --git a/src/test/test-bpf-firewall.c b/src/test/test-bpf-firewall.c index fbaa349b45..71aed12558 100644 --- a/src/test/test-bpf-firewall.c +++ b/src/test/test-bpf-firewall.c @@ -48,7 +48,9 @@ int main(int argc, char *argv[]) { if (r == -ENOMEDIUM) return log_tests_skipped("cgroupfs not available"); - assert_se(set_unit_path(get_testdata_dir()) >= 0); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("units", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p); diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index 02c8549b4b..daafba4ef6 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -38,7 +38,9 @@ static int test_cgroup_mask(void) { return log_tests_skipped("cgroupfs not available"); /* Prepare the manager. */ - assert_se(set_unit_path(get_testdata_dir()) >= 0); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("units", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m); if (IN_SET(r, -EPERM, -EACCES)) { diff --git a/src/test/test-cgroup-unit-default.c b/src/test/test-cgroup-unit-default.c index 1286f11e4e..372667041c 100644 --- a/src/test/test-cgroup-unit-default.c +++ b/src/test/test-cgroup-unit-default.c @@ -22,7 +22,9 @@ static int test_default_memory_low(void) { if (r == -ENOMEDIUM) return log_tests_skipped("cgroupfs not available"); - assert_se(set_unit_path(get_testdata_dir()) >= 0); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("units", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m); if (IN_SET(r, -EPERM, -EACCES)) { diff --git a/src/test/test-engine.c b/src/test/test-engine.c index b8351141fe..6465151b27 100644 --- a/src/test/test-engine.c +++ b/src/test/test-engine.c @@ -26,8 +26,11 @@ int main(int argc, char *argv[]) { return log_tests_skipped("cgroupfs not available"); /* prepare the test */ - assert_se(set_unit_path(get_testdata_dir()) >= 0); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("units", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); + r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m); if (manager_errno_skip_test(r)) return log_tests_skipped_errno(r, "manager_new"); diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 4e0fd7d5b4..5a96b46a77 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -806,7 +806,6 @@ static int run_tests(UnitFileScope scope, const test_entry tests[], char **patte int main(int argc, char *argv[]) { _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL; - _cleanup_free_ char *test_execute_path = NULL; static const test_entry user_tests[] = { entry(test_exec_basic), @@ -878,9 +877,10 @@ int main(int argc, char *argv[]) { if (r == -ENOMEDIUM) return log_tests_skipped("cgroupfs not available"); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("test-execute/", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); - test_execute_path = path_join(get_testdata_dir(), "test-execute"); - assert_se(set_unit_path(test_execute_path) >= 0); /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test * cases, otherwise (and if they are present in the environment), diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 23c7d370d4..32a00349ac 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -444,20 +444,20 @@ static void test_write_string_file_verify(void) { _cleanup_free_ char *buf = NULL, *buf2 = NULL; int r; - assert_se(read_one_line_file("/proc/cmdline", &buf) >= 0); + assert_se(read_one_line_file("/proc/version", &buf) >= 0); assert_se(buf2 = strjoin(buf, "\n")); - r = write_string_file("/proc/cmdline", buf, 0); + r = write_string_file("/proc/version", buf, 0); assert_se(IN_SET(r, -EACCES, -EIO)); - r = write_string_file("/proc/cmdline", buf2, 0); + r = write_string_file("/proc/version", buf2, 0); assert_se(IN_SET(r, -EACCES, -EIO)); - assert_se(write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); - assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); + assert_se(write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); + assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); - r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE); + r = write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE); assert_se(IN_SET(r, -EACCES, -EIO)); - assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0); + assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0); } static void test_load_env_file_pairs(void) { @@ -757,7 +757,7 @@ static void test_read_line3(void) { _cleanup_free_ char *line = NULL; int r; - f = fopen("/proc/cmdline", "re"); + f = fopen("/proc/uptime", "re"); if (!f && IN_SET(errno, ENOENT, EPERM)) return; assert_se(f); diff --git a/src/test/test-journal-importer.c b/src/test/test-journal-importer.c index 7e898735c9..4883356956 100644 --- a/src/test/test-journal-importer.c +++ b/src/test/test-journal-importer.c @@ -25,7 +25,7 @@ static void test_basic_parsing(void) { _cleanup_free_ char *journal_data_path = NULL; int r; - journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-1.txt"); + assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0); imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC); assert_se(imp.fd >= 0); @@ -56,7 +56,7 @@ static void test_bad_input(void) { _cleanup_free_ char *journal_data_path = NULL; int r; - journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-2.txt"); + assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0); imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC); assert_se(imp.fd >= 0); diff --git a/src/test/test-path.c b/src/test/test-path.c index 6ad222b5f9..830d5f261b 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -251,7 +251,7 @@ int main(int argc, char *argv[]) { test_setup_logging(LOG_INFO); - test_path = path_join(get_testdata_dir(), "test-path"); + assert_se(get_testdata_dir("test-path", &test_path) >= 0); assert_se(set_unit_path(test_path) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c index cd45537847..da6d2a21e6 100644 --- a/src/test/test-sched-prio.c +++ b/src/test/test-sched-prio.c @@ -25,8 +25,11 @@ int main(int argc, char *argv[]) { return log_tests_skipped("cgroupfs not available"); /* prepare the test */ - assert_se(set_unit_path(get_testdata_dir()) >= 0); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("units", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); + r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m); if (manager_errno_skip_test(r)) return log_tests_skipped_errno(r, "manager_new"); diff --git a/src/test/test-umount.c b/src/test/test-umount.c index 6ab5758ede..b27b75b352 100644 --- a/src/test/test-umount.c +++ b/src/test/test-umount.c @@ -15,8 +15,10 @@ static void test_mount_points_list(const char *fname) { log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo"); - if (fname) - fname = testdata_fname = path_join(get_testdata_dir(), fname); + if (fname) { + assert_se(get_testdata_dir(fname, &testdata_fname) >= 0); + fname = testdata_fname; + } LIST_HEAD_INIT(mp_list_head); assert_se(mount_points_list_get(fname, &mp_list_head) >= 0); @@ -37,8 +39,10 @@ static void test_swap_list(const char *fname) { log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps"); - if (fname) - fname = testdata_fname = path_join(get_testdata_dir(), fname); + if (fname) { + assert_se(get_testdata_dir(fname, &testdata_fname) >= 0); + fname = testdata_fname; + } LIST_HEAD_INIT(mp_list_head); assert_se(swap_list_get(fname, &mp_list_head) >= 0); diff --git a/src/test/test-watch-pid.c b/src/test/test-watch-pid.c index bad289767d..28ecffb0c0 100644 --- a/src/test/test-watch-pid.c +++ b/src/test/test-watch-pid.c @@ -20,7 +20,10 @@ int main(int argc, char *argv[]) { if (r == -ENOMEDIUM) return log_tests_skipped("cgroupfs not available"); - assert_se(set_unit_path(get_testdata_dir()) >= 0); + _cleanup_free_ char *unit_dir = NULL; + assert_se(get_testdata_dir("units/", &unit_dir) >= 0); + assert_se(set_unit_path(unit_dir) >= 0); + assert_se(runtime_dir = setup_fake_runtime_dir()); assert_se(manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m) >= 0); diff --git a/test/README.testsuite b/test/README.testsuite index 471771acd4..7204fdb00b 100644 --- a/test/README.testsuite +++ b/test/README.testsuite @@ -10,10 +10,10 @@ ninja: no work to do. --x-- Running TEST-01-BASIC --x-- + make -C TEST-01-BASIC BUILD_DIR=/home/zbyszek/src/systemd/build clean setup run make: Entering directory '/home/zbyszek/src/systemd/test/TEST-01-BASIC' -TEST CLEANUP: Basic systemd setup -TEST SETUP: Basic systemd setup +TEST-01-BASIC CLEANUP: Basic systemd setup +TEST-01-BASIC SETUP: Basic systemd setup ... -TEST RUN: Basic systemd setup [OK] +TEST-01-BASIC RUN: Basic systemd setup [OK] make: Leaving directory '/home/zbyszek/src/systemd/test/TEST-01-BASIC' --x-- Result of TEST-01-BASIC: 0 --x-- --x-- Running TEST-02-CRYPTSETUP --x-- diff --git a/test/TEST-01-BASIC/Makefile b/test/TEST-01-BASIC/Makefile index 45e9bfc67c..79fe9688b8 100644 --- a/test/TEST-01-BASIC/Makefile +++ b/test/TEST-01-BASIC/Makefile @@ -1,9 +1,6 @@ BUILD_DIR=$(shell ../../tools/find-build-dir.sh) -all setup run: +all setup run clean clean-again: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ -clean clean-again: - @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --clean - .PHONY: all setup run clean clean-again diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 0eaa8f991a..58f6cd1414 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -1,34 +1,25 @@ #!/usr/bin/env bash set -e TEST_DESCRIPTION="Basic systemd setup" +IMAGE_NAME="basic" RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes} +TEST_REQUIRE_INSTALL_TESTS=0 . $TEST_BASE_DIR/test-functions -test_setup() { +test_create_image() { create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( 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 < /failed ; systemctl daemon-reload ; echo OK > /testok' -Type=oneshot -EOF - - setup_testsuite + # install tests manually so the test is functional even when -Dinstall-tests=false + mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/ + cp -v $(dirname $0)/../units/{testsuite-01,end}.service $initdir/usr/lib/systemd/tests/testdata/units/ ) setup_nspawn_root } -do_test "$@" +do_test "$@" 01 diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh index a859b345d0..157a70021b 100755 --- a/test/TEST-02-CRYPTSETUP/test.sh +++ b/test/TEST-02-CRYPTSETUP/test.sh @@ -1,21 +1,22 @@ #!/usr/bin/env bash set -e TEST_DESCRIPTION="cryptsetup systemd setup" +IMAGE_NAME="cryptsetup" TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions check_result_qemu() { ret=1 - mkdir -p $initdir - mount ${LOOPDEV}p1 $initdir + mount_initdir [[ -e $initdir/testok ]] && ret=0 [[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile mount /dev/mapper/varcrypt $initdir/var cp -a $initdir/var/log/journal $TESTDIR - umount $initdir/var - umount $initdir + rm -r $initdir/var/log/journal/* + _umount_dir $initdir/var + _umount_dir $initdir cryptsetup luksClose /dev/mapper/varcrypt [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal @@ -23,8 +24,7 @@ check_result_qemu() { return $ret } - -test_setup() { +test_create_image() { create_empty_image_rootdir echo -n test >$TESTDIR/keyfile cryptsetup -q luksFormat --pbkdf pbkdf2 --pbkdf-force-iterations 1000 ${LOOPDEV}p2 $TESTDIR/keyfile @@ -42,25 +42,12 @@ test_setup() { setup_basic_environment mask_supporting_services - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service < /failed ; echo OK > /testok' -Type=oneshot -EOF - - setup_testsuite - install_dmevent generate_module_dependencies cat >$initdir/etc/crypttab < $initdir/etc/varkey + echo -n test >$initdir/etc/varkey cat $initdir/etc/crypttab | ddebug cat >>$initdir/etc/fstab <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/forever-print-hola.service <$initdir/etc/systemd/system.conf <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service -[Unit] -Description=Testsuite service - -[Service] -ExecStart=/test-selinux-checks.sh -Type=oneshot -EOF - - cat <$initdir/etc/systemd/system/hola.service -[Service] -Type=oneshot -ExecStart=/bin/echo Start Hola -ExecReload=/bin/echo Reload Hola -ExecStop=/bin/echo Stop Hola -RemainAfterExit=yes -EOF - - setup_testsuite - - cat <$initdir/etc/systemd/system/load-systemd-test-module.service -[Unit] -Description=Load systemd-test module -DefaultDependencies=no -Requires=local-fs.target -Conflicts=shutdown.target -After=local-fs.target -Before=sysinit.target shutdown.target autorelabel.service -ConditionSecurity=selinux -ConditionPathExists=|/.load-systemd-test-module - -[Service] -ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && cd /systemd-test-module && make -f /usr/share/selinux/devel/Makefile load && rm /.load-systemd-test-module' -Type=oneshot -TimeoutSec=0 -RemainAfterExit=yes -EOF - - touch $initdir/.load-systemd-test-module - mkdir -p $initdir/etc/systemd/system/basic.target.wants - ln -fs load-systemd-test-module.service $initdir/etc/systemd/system/basic.target.wants/load-systemd-test-module.service - local _modules_dir=/var/lib/selinux rm -rf $initdir/$_modules_dir if ! cp -ar $_modules_dir $initdir/$_modules_dir; then @@ -87,11 +44,10 @@ EOF mkdir $initdir/systemd-test-module cp systemd_test.te $initdir/systemd-test-module cp systemd_test.if $initdir/systemd-test-module - cp test-selinux-checks.sh $initdir dracut_install -o sesearch dracut_install runcon dracut_install checkmodule semodule semodule_package m4 make /usr/libexec/selinux/hll/pp load_policy sefcontext_compile ) } -do_test "$@" +do_test "$@" 06 diff --git a/test/TEST-07-ISSUE-1981/test.sh b/test/TEST-07-ISSUE-1981/test.sh index 7927294a8a..5da24a987c 100755 --- a/test/TEST-07-ISSUE-1981/test.sh +++ b/test/TEST-07-ISSUE-1981/test.sh @@ -7,32 +7,4 @@ TEST_NO_QEMU=1 NSPAWN_TIMEOUT=30 -test_setup() { - create_empty_image_rootdir - - # Create what will eventually be our root filesystem onto an overlay - ( - LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service < /testok; systemctl poweroff' -Type=oneshot -EOF - - rm $initdir/etc/fstab - cat >$initdir/etc/systemd/system/-.mount <$initdir/etc/systemd/system/systemd-remount-fs.service <$initdir/etc/systemd/system/testsuite.service <<'EOF' -[Unit] -Description=Testsuite service - -[Service] -Type=oneshot -ExecStart=/bin/sh -c '>/testok' -RemainAfterExit=yes -ExecStop=/bin/sh -c 'kill -SEGV $$$$' -TimeoutStopSec=270s -EOF - - setup_testsuite - ) -} - -do_test "$@" +do_test "$@" 09 diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh index 1761ad1e43..14ded56ba1 100755 --- a/test/TEST-10-ISSUE-2467/test.sh +++ b/test/TEST-10-ISSUE-2467/test.sh @@ -4,45 +4,4 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467" . $TEST_BASE_DIR/test-functions -test_setup() { - create_empty_image_rootdir - - # Create what will eventually be our root filesystem onto an overlay - ( - LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - dracut_install true rm socat - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <<'EOF' -[Unit] -Description=Testsuite service - -[Service] -Type=oneshot -ExecStart=/bin/sh -e -x -c 'rm -f /tmp/nonexistent; systemctl start test.socket; printf x > test.file; socat -t20 OPEN:test.file UNIX-CONNECT:/run/test.ctl; >/testok' -EOF - - cat >$initdir/etc/systemd/system/test.socket <<'EOF' -[Socket] -ListenStream=/run/test.ctl -EOF - - cat > $initdir/etc/systemd/system/test.service <<'EOF' -[Unit] -Requires=test.socket -ConditionPathExistsGlob=/tmp/nonexistent - -[Service] -ExecStart=/bin/true -EOF - - setup_testsuite - ) - setup_nspawn_root -} - -do_test "$@" +do_test "$@" 10 diff --git a/test/TEST-11-ISSUE-3166/test.sh b/test/TEST-11-ISSUE-3166/test.sh index e444414a90..da003c90d5 100755 --- a/test/TEST-11-ISSUE-3166/test.sh +++ b/test/TEST-11-ISSUE-3166/test.sh @@ -5,58 +5,4 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions -test_setup() { - create_empty_image_rootdir - - # Create what will eventually be our root filesystem onto an overlay - ( - LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - dracut_install false touch - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/fail-on-restart.service <$initdir/test-fail-on-restart.sh <<'EOF' -#!/usr/bin/env bash -set -x - -systemctl start fail-on-restart.service -active_state=$(systemctl show --property ActiveState fail-on-restart.service) -while [[ "$active_state" == "ActiveState=activating" || "$active_state" == "ActiveState=active" ]]; do - sleep 1 - active_state=$(systemctl show --property ActiveState fail-on-restart.service) -done -systemctl is-failed fail-on-restart.service || exit 1 -touch /testok -EOF - - chmod 0755 $initdir/test-fail-on-restart.sh - setup_testsuite - ) -} - -do_test "$@" +do_test "$@" 11 diff --git a/test/TEST-12-ISSUE-3171/test.sh b/test/TEST-12-ISSUE-3171/test.sh index e30c36ed86..c8abefbd86 100755 --- a/test/TEST-12-ISSUE-3171/test.sh +++ b/test/TEST-12-ISSUE-3171/test.sh @@ -5,85 +5,4 @@ TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions -test_setup() { - create_empty_image_rootdir - - # Create what will eventually be our root filesystem onto an overlay - ( - LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - dracut_install cat mv stat nc - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/test-socket-group.sh <<'EOF' -#!/usr/bin/env bash -set -x -set -e -set -o pipefail - -U=/run/systemd/system/test.socket -cat <<'EOL' >$U -[Unit] -Description=Test socket -[Socket] -Accept=yes -ListenStream=/run/test.socket -SocketGroup=adm -SocketMode=0660 -EOL - -cat <<'EOL' > /run/systemd/system/test@.service -[Unit] -Description=Test service -[Service] -StandardInput=socket -ExecStart=/bin/sh -x -c cat -EOL - -systemctl start test.socket -systemctl is-active test.socket -[[ "$(stat --format='%G' /run/test.socket)" == adm ]] -echo A | nc -w1 -U /run/test.socket - -mv $U ${U}.disabled -systemctl daemon-reload -systemctl is-active test.socket -[[ "$(stat --format='%G' /run/test.socket)" == adm ]] -echo B | nc -w1 -U /run/test.socket && exit 1 - -mv ${U}.disabled $U -systemctl daemon-reload -systemctl is-active test.socket -echo C | nc -w1 -U /run/test.socket && exit 1 -[[ "$(stat --format='%G' /run/test.socket)" == adm ]] - -systemctl restart test.socket -systemctl is-active test.socket -echo D | nc -w1 -U /run/test.socket -[[ "$(stat --format='%G' /run/test.socket)" == adm ]] - - -touch /testok -EOF - - chmod 0755 $initdir/test-socket-group.sh - setup_testsuite - ) - - setup_nspawn_root -} - -do_test "$@" +do_test "$@" 12 diff --git a/test/TEST-13-NSPAWN-SMOKE/Makefile b/test/TEST-13-NSPAWN-SMOKE/Makefile deleted file mode 100644 index e5e3350211..0000000000 --- a/test/TEST-13-NSPAWN-SMOKE/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -BUILD_DIR=$(shell ../../tools/find-build-dir.sh) - -all setup run: - @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ - -clean clean-again: - @basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean - @rm -f has-overflow - -.PHONY: all setup run clean clean-again diff --git a/test/TEST-13-NSPAWN-SMOKE/Makefile b/test/TEST-13-NSPAWN-SMOKE/Makefile new file mode 120000 index 0000000000..e9f93b1104 --- /dev/null +++ b/test/TEST-13-NSPAWN-SMOKE/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh index 974b239d80..c777c166f7 100755 --- a/test/TEST-13-NSPAWN-SMOKE/test.sh +++ b/test/TEST-13-NSPAWN-SMOKE/test.sh @@ -1,193 +1,23 @@ #!/usr/bin/env bash set -e TEST_DESCRIPTION="systemd-nspawn smoke test" +IMAGE_NAME=nspawn TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions -test_setup() { +test_create_image() { create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - setup_basic_environment mask_supporting_services - dracut_install busybox chmod rmdir unshare ip sysctl - cp create-busybox-container $initdir/ - - ./create-busybox-container $initdir/nc-container + ../create-busybox-container $initdir/nc-container initdir="$initdir/nc-container" dracut_install nc ip - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/test-nspawn.sh <<'EOF' -#!/usr/bin/env bash -set -x -set -e -set -u -set -o pipefail - -export SYSTEMD_LOG_LEVEL=debug - -# check cgroup-v2 -is_v2_supported=no -mkdir -p /tmp/cgroup2 -if mount -t cgroup2 cgroup2 /tmp/cgroup2; then - is_v2_supported=yes - umount /tmp/cgroup2 -fi -rmdir /tmp/cgroup2 - -# check cgroup namespaces -is_cgns_supported=no -if [[ -f /proc/1/ns/cgroup ]]; then - is_cgns_supported=yes -fi - -is_user_ns_supported=no -# On some systems (e.g. CentOS 7) the default limit for user namespaces -# is set to 0, which causes the following unshare syscall to fail, even -# with enabled user namespaces support. By setting this value explicitly -# we can ensure the user namespaces support to be detected correctly. -sysctl -w user.max_user_namespaces=10000 -if unshare -U sh -c :; then - is_user_ns_supported=yes -fi - -function check_bind_tmp_path { - # https://github.com/systemd/systemd/issues/4789 - local _root="/var/lib/machines/bind-tmp-path" - /create-busybox-container "$_root" - >/tmp/bind - systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' -} - -function check_norbind { - # https://github.com/systemd/systemd/issues/13170 - local _root="/var/lib/machines/norbind-path" - mkdir -p /tmp/binddir/subdir - echo -n "outer" > /tmp/binddir/subdir/file - mount -t tmpfs tmpfs /tmp/binddir/subdir - echo -n "inner" > /tmp/binddir/subdir/file - /create-busybox-container "$_root" - systemd-nspawn --register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' -} - -function check_notification_socket { - # https://github.com/systemd/systemd/issues/4944 - local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/systemd/nspawn/notify' - systemd-nspawn --register=no -D /nc-container /bin/sh -x -c "$_cmd" - systemd-nspawn --register=no -D /nc-container -U /bin/sh -x -c "$_cmd" -} - -function run { - if [[ "$1" = "yes" && "$is_v2_supported" = "no" ]]; then - printf "Unified cgroup hierarchy is not supported. Skipping.\n" >&2 - return 0 - fi - if [[ "$2" = "yes" && "$is_cgns_supported" = "no" ]]; then - printf "CGroup namespaces are not supported. Skipping.\n" >&2 - return 0 - fi - - local _root="/var/lib/machines/unified-$1-cgns-$2-api-vfs-writable-$3" - /create-busybox-container "$_root" - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b - - if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -U -b; then - [[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1 - else - [[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1 - fi - - if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -U -b; then - [[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1 - else - [[ "$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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 - - # allow combination of --network-namespace-path and --private-network - if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --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" - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP' - local r=$? - ip netns del nspawn_test - - if [ $r -ne 0 ]; then - return 1 - fi - - return 0 -} - -check_bind_tmp_path - -check_norbind - -check_notification_socket - -for api_vfs_writable in yes no network; do - run no no $api_vfs_writable - run yes no $api_vfs_writable - run no yes $api_vfs_writable - run yes yes $api_vfs_writable -done - -touch /testok -EOF - - chmod 0755 $initdir/test-nspawn.sh - setup_testsuite ) } -do_test "$@" +do_test "$@" 13 diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh index 74cabf86aa..d1486f0aae 100755 --- a/test/TEST-14-MACHINE-ID/test.sh +++ b/test/TEST-14-MACHINE-ID/test.sh @@ -1,78 +1,21 @@ #!/usr/bin/env bash set -e TEST_DESCRIPTION="/etc/machine-id testing" +IMAGE_NAME=badid TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions -test_setup() { +test_create_image() { create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - setup_basic_environment mask_supporting_services printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id - dracut_install mount cmp - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service < /failed ; echo OK > /testok' -Type=oneshot -EOF - -cat >$initdir/test-machine-id-setup.sh <<'EOF' -#!/usr/bin/env bash - -set -e -set -x - -function setup_root { - local _root="$1" - mkdir -p "$_root" - mount -t tmpfs tmpfs "$_root" - mkdir -p "$_root/etc" "$_root/run" -} - -function check { - printf "Expected\n" - cat "$1" - printf "\nGot\n" - cat "$2" - cmp "$1" "$2" -} - -r="$(pwd)/overwrite-broken-machine-id" -setup_root "$r" -systemd-machine-id-setup --print --root "$r" -echo abc >>"$r/etc/machine-id" -id=$(systemd-machine-id-setup --print --root "$r") -echo $id >expected -check expected "$r/etc/machine-id" - -r="$(pwd)/transient-machine-id" -setup_root "$r" -systemd-machine-id-setup --print --root "$r" -echo abc >>"$r/etc/machine-id" -mount -o remount,ro "$r" -mount -t tmpfs tmpfs "$r/run" -transient_id=$(systemd-machine-id-setup --print --root "$r") -mount -o remount,rw "$r" -commited_id=$(systemd-machine-id-setup --print --commit --root "$r") -[[ "$transient_id" = "$commited_id" ]] -check "$r/etc/machine-id" "$r/run/machine-id" -EOF -chmod +x $initdir/test-machine-id-setup.sh - - setup_testsuite ) } -do_test "$@" +do_test "$@" 14 diff --git a/test/TEST-15-DROPIN/test.sh b/test/TEST-15-DROPIN/test.sh index 63bbd35051..1540e2e1f1 100755 --- a/test/TEST-15-DROPIN/test.sh +++ b/test/TEST-15-DROPIN/test.sh @@ -5,18 +5,4 @@ TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions -test_setup() { - # create the basic filesystem layout - setup_basic_environment - mask_supporting_services - - # import the test scripts in the rootfs and plug them in systemd - cp testsuite.service $initdir/etc/systemd/system/ - cp test-dropin.sh $initdir/ - setup_testsuite - - # create dedicated rootfs for nspawn (located in $TESTDIR/nspawn-root) - setup_nspawn_root -} - -do_test "$@" +do_test "$@" 15 diff --git a/test/TEST-15-DROPIN/testsuite.service b/test/TEST-15-DROPIN/testsuite.service deleted file mode 100644 index 4c9f65e2b1..0000000000 --- a/test/TEST-15-DROPIN/testsuite.service +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=Testsuite service - -[Service] -ExecStart=/test-dropin.sh -Type=oneshot diff --git a/test/TEST-16-EXTEND-TIMEOUT/test.sh b/test/TEST-16-EXTEND-TIMEOUT/test.sh index 43d9f1278b..e1e2a68fa9 100755 --- a/test/TEST-16-EXTEND-TIMEOUT/test.sh +++ b/test/TEST-16-EXTEND-TIMEOUT/test.sh @@ -6,30 +6,4 @@ TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions -test_setup() { - create_empty_image - - # Create what will eventually be our root filesystem onto an overlay - ( - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - - 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}/ - - setup_testsuite - ) - - setup_nspawn_root -} - -do_test "$@" +do_test "$@" 16 diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite.service b/test/TEST-16-EXTEND-TIMEOUT/testsuite.service deleted file mode 100644 index 7512ba9e12..0000000000 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite.service +++ /dev/null @@ -1,18 +0,0 @@ - -[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 -TimeoutStartSec=infinity -ExecStartPre=/assess.sh -ExecStart=/bin/true diff --git a/test/TEST-17-UDEV-WANTS/test.sh b/test/TEST-17-UDEV-WANTS/test.sh index e196003e80..5b8f22cbaa 100755 --- a/test/TEST-17-UDEV-WANTS/test.sh +++ b/test/TEST-17-UDEV-WANTS/test.sh @@ -6,29 +6,4 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions QEMU_TIMEOUT=300 -test_setup() { - create_empty_image_rootdir - - ( - LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/specifier-j-wants.service << EOF -[Unit] -Description=Wants with percent-j specifier -Wants=specifier-j-depends-%j.service -After=specifier-j-depends-%j.service - -[Service] -Type=oneshot -ExecStart=test -f /tmp/test-specifier-j-%j -ExecStart=/bin/sh -c 'echo OK > /testok' -EOF - cat >$initdir/etc/systemd/system/specifier-j-depends-wants.service << EOF -[Unit] -Description=Dependent service for percent-j specifier - -[Service] -Type=oneshot -ExecStart=touch /tmp/test-specifier-j-wants -EOF - cat >$initdir/etc/systemd/system/testsuite.service << EOF -[Unit] -Description=Testsuite: Ensure %j Wants directives work -Wants=specifier-j-wants.service -After=specifier-j-wants.service - -[Service] -Type=oneshot -ExecStart=/bin/true -EOF - - setup_testsuite - ) - - setup_nspawn_root -} - -do_test "$@" +do_test "$@" 28 diff --git a/test/TEST-29-UDEV-ID_RENAMING/test.sh b/test/TEST-29-UDEV-ID_RENAMING/test.sh index fb570b0347..4feafc04d7 100755 --- a/test/TEST-29-UDEV-ID_RENAMING/test.sh +++ b/test/TEST-29-UDEV-ID_RENAMING/test.sh @@ -6,29 +6,4 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions QEMU_TIMEOUT=300 -test_setup() { - create_empty_image_rootdir - - ( - LOG_LEVEL=5 - eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - - setup_basic_environment - mask_supporting_services - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/systemd-timedated.service.d/watchdog.conf <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service < $initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf < - - - - - - -EOF - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/etc/sysusers.d/testuser.conf <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service < /testok - exit 0 -fi - -systemd-analyze log-level debug - -truncate -s 1G /tmp/zzz - -SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8 - -systemd-repart /tmp/zzz --empty=force --dry-run=no --seed=$SEED - -sfdisk -d /tmp/zzz | grep -v -e 'sector-size' -e '^$' > /tmp/empty - -cmp /tmp/empty - < /tmp/definitions/root.conf < /tmp/definitions/home.conf < /tmp/definitions/swap.conf < /tmp/populated - -cmp /tmp/populated - < /tmp/definitions/swap.conf < /tmp/definitions/extra.conf < /tmp/populated2 - -cmp /tmp/populated2 - < /tmp/populated3 - -cmp /tmp/populated3 - < /testok - -exit 0 diff --git a/test/TEST-46-HOMED/test.sh b/test/TEST-46-HOMED/test.sh index 99fd5b85b8..877cbfefd0 100755 --- a/test/TEST-46-HOMED/test.sh +++ b/test/TEST-46-HOMED/test.sh @@ -5,38 +5,4 @@ TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions -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_supporting_services - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service < $initdir/etc/systemd/system/issue_14566_test.service << EOF -[Unit] -Description=Issue 14566 Repro - -[Service] -ExecStart=/repro.sh -ExecStopPost=/bin/true -KillMode=mixed -EOF - - cp testsuite.sh $initdir/ - cp repro.sh $initdir/ - - setup_testsuite - ) - setup_nspawn_root -} - -do_test "$@" +do_test "$@" 47 diff --git a/test/basic.target b/test/basic.target deleted file mode 120000 index 0612934682..0000000000 --- a/test/basic.target +++ /dev/null @@ -1 +0,0 @@ -../units/basic.target \ No newline at end of file diff --git a/test/TEST-13-NSPAWN-SMOKE/create-busybox-container b/test/create-busybox-container similarity index 100% rename from test/TEST-13-NSPAWN-SMOKE/create-busybox-container rename to test/create-busybox-container diff --git a/test/loopy2.service b/test/loopy2.service deleted file mode 120000 index 961b1fe9bc..0000000000 --- a/test/loopy2.service +++ /dev/null @@ -1 +0,0 @@ -loopy.service \ No newline at end of file diff --git a/test/loopy4.service b/test/loopy4.service deleted file mode 120000 index 43e5658bcd..0000000000 --- a/test/loopy4.service +++ /dev/null @@ -1 +0,0 @@ -loopy3.service \ No newline at end of file diff --git a/test/meson.build b/test/meson.build index 2fbea31ccd..404b923467 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,236 +1,56 @@ # SPDX-License-Identifier: LGPL-2.1+ -test_data_files = ''' - a.service - a-conj.service - b.service - basic.target - c.service - d.service - daughter.service - dml.slice - dml-passthrough.slice - dml-passthrough-empty.service - dml-passthrough-set-dml.service - dml-passthrough-set-ml.service - dml-override.slice - dml-override-empty.service - dml-discard.slice - dml-discard-empty.service - dml-discard-set-ml.service - e.service - end.service - f.service - g.service - grandchild.service - h.service - hello-after-sleep.target - hello.service - hwdb.d/10-bad.hwdb - i.service - journal-data/journal-1.txt - journal-data/journal-2.txt - nomem.slice - nomemleaf.service - parent-deep.slice - parent.slice - sched_idle_bad.service - sched_idle_ok.service - sched_rr_bad.service - sched_rr_change.service - sched_rr_ok.service - shutdown.target - sleep.service - sockets.target - son.service - sysinit.target - test-execute/exec-basic.service - test-execute/exec-ambientcapabilities-merge-nfsnobody.service - test-execute/exec-ambientcapabilities-merge-nobody.service - test-execute/exec-ambientcapabilities-merge.service - test-execute/exec-ambientcapabilities-nfsnobody.service - test-execute/exec-ambientcapabilities-nobody.service - test-execute/exec-ambientcapabilities.service - test-execute/exec-bindpaths.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-condition-failed.service - test-execute/exec-condition-skip.service - test-execute/exec-cpuaffinity1.service - test-execute/exec-cpuaffinity2.service - test-execute/exec-cpuaffinity3.service - test-execute/exec-dynamicuser-fixeduser-adm.service - test-execute/exec-dynamicuser-fixeduser-games.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-no-substitute.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-nobody.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-sys.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-personality-aarch64.service - test-execute/exec-personality-ppc64.service - test-execute/exec-personality-ppc64le.service - test-execute/exec-personality-s390.service - test-execute/exec-personality-x86-64.service - test-execute/exec-personality-x86.service - test-execute/exec-privatedevices-disabled-by-prefix.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-with-group.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-privatetmp-disabled-by-prefix.service - test-execute/exec-protecthome-tmpfs-vs-protectsystem-strict.service - test-execute/exec-protectkernellogs-yes-capabilities.service - test-execute/exec-protectkernellogs-no-capabilities.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-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-restrictnamespaces-merge-all.service - test-execute/exec-restrictnamespaces-merge-and.service - test-execute/exec-restrictnamespaces-merge-or.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-nobody.service - test-execute/exec-runtimedirectory-owner-nogroup.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-standardinput-file-cat.service - test-execute/exec-standardoutput-file.service - test-execute/exec-standardoutput-append.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-failing2.service - test-execute/exec-systemcallfilter-not-failing.service - test-execute/exec-systemcallfilter-not-failing2.service - test-execute/exec-systemcallfilter-system-user-nfsnobody.service - test-execute/exec-systemcallfilter-system-user-nobody.service - test-execute/exec-systemcallfilter-system-user.service - test-execute/exec-systemcallfilter-with-errno-multi.service - test-execute/exec-systemcallfilter-with-errno-name.service - test-execute/exec-systemcallfilter-with-errno-number.service - test-execute/exec-temporaryfilesystem-options.service - test-execute/exec-temporaryfilesystem-ro.service - test-execute/exec-temporaryfilesystem-rw.service - test-execute/exec-temporaryfilesystem-usr.service - test-execute/exec-umask-0177.service - test-execute/exec-umask-default.service - test-execute/exec-unsetenvironment.service - test-execute/exec-user-nfsnobody.service - test-execute/exec-user-nobody.service - test-execute/exec-user.service - test-execute/exec-workingdirectory.service - test-execute/exec-workingdirectory-trailing-dot.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 - test-umount/empty.mountinfo - test-umount/example.swaps - test-umount/garbled.mountinfo - test-umount/rhbug-1554943.mountinfo - testsuite.target - timers.target - unit-with-.service.d/20-override.conf - unit-with-multiple-.service.d/20-override.conf - unit-with-multiple-.service.d/30-override.conf - unit-with-multiple-dashes.service - unit-with-multiple-dashes.service.d/10-override.conf - unstoppable.service -'''.split() +testdata_dir = testsdir + '/testdata/' + +install_subdir('journal-data', + install_dir : testdata_dir) +install_subdir('units', + install_dir : testdata_dir) +install_subdir('test-execute', + install_dir : testdata_dir) +install_subdir('test-path', + install_dir : testdata_dir) +install_subdir('test-umount', + install_dir : testdata_dir) +install_subdir('test-network-generator-conversion', + install_dir : testdata_dir) +install_subdir('testsuite-04.units', + install_dir : testdata_dir) +install_subdir('testsuite-06.units', + install_dir : testdata_dir) +install_subdir('testsuite-10.units', + install_dir : testdata_dir) +install_subdir('testsuite-11.units', + install_dir : testdata_dir) +install_subdir('testsuite-16.units', + install_dir : testdata_dir) +install_subdir('testsuite-28.units', + install_dir : testdata_dir) +install_subdir('testsuite-30.units', + install_dir : testdata_dir) + +testsuite08_dir = testdata_dir + '/testsuite-08.units' +install_data('testsuite-08.units/-.mount', + install_dir : testsuite08_dir) +install_data('testsuite-08.units/systemd-remount-fs.service', + install_dir : testsuite08_dir) +meson.add_install_script(meson_make_symlink, + './-.mount', + testsuite08_dir + '/root.mount') +meson.add_install_script(meson_make_symlink, + '../-.mount', + testsuite08_dir + '/local-fs.target.wants/-.mount') if conf.get('ENABLE_RESOLVE') == 1 - test_data_files += ''' - test-resolve/_openpgpkey.fedoraproject.org.pkts - test-resolve/fedoraproject.org.pkts - test-resolve/gandi.net.pkts - test-resolve/google.com.pkts - test-resolve/root.pkts - test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts - test-resolve/teamits.com.pkts - test-resolve/zbyszek@fedoraproject.org.pkts - test-resolve/_443._tcp.fedoraproject.org.pkts - test-resolve/kyhwana.org.pkts - test-resolve/fake-caa.pkts - '''.split() + install_subdir('test-resolve', + install_dir : testdata_dir) endif -if install_tests - foreach file : test_data_files - subdir = file.split('/')[0] - if subdir == file - subdir = '' - endif +install_data('create-busybox-container', + install_mode : 'rwxr-xr-x', + install_dir : testdata_dir) - install_data(file, - install_dir : testsdir + '/testdata/' + subdir) - endforeach -endif +test_network_generator_conversion_sh = find_program('test-network-generator-conversion.sh') ############################################################ @@ -257,6 +77,9 @@ if install_tests install_data('run-unit-tests.py', install_mode : 'rwxr-xr-x', install_dir : testsdir) + install_data('test-network-generator-conversion.sh', + install_mode : 'rwxr-xr-x', + install_dir : testsdir) endif ############################################################ diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index c0a8448a88..bcbbb8b7ed 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -4,8 +4,10 @@ set -e BUILD_DIR="$($(dirname "$0")/../tools/find-build-dir.sh)" if [ $# -gt 0 ]; then args="$@" + do_clean=0 else - args="clean setup run clean-again" + args="setup run clean-again" + do_clean=1 fi ninja -C "$BUILD_DIR" @@ -16,6 +18,13 @@ COUNT=0 FAILURES=0 cd "$(dirname "$0")" + +if [ $do_clean = 1 ]; then + for TEST in TEST-??-* ; do + ( set -x ; make -C "$TEST" "BUILD_DIR=$BUILD_DIR" clean ) + done +fi + for TEST in TEST-??-* ; do COUNT=$(($COUNT+1)) @@ -31,6 +40,12 @@ for TEST in TEST-??-* ; do [ "$RESULT" -ne "0" ] && FAILURES=$(($FAILURES+1)) done +if [ $FAILURES -eq 0 -a $do_clean = 1 ]; then + for TEST in TEST-??-* ; do + ( set -x ; make -C "$TEST" "BUILD_DIR=$BUILD_DIR" clean-again ) + done +fi + echo "" for TEST in ${!results[@]}; do diff --git a/test/shutdown.target b/test/shutdown.target deleted file mode 120000 index 1a3c2eec84..0000000000 --- a/test/shutdown.target +++ /dev/null @@ -1 +0,0 @@ -../units/shutdown.target \ No newline at end of file diff --git a/test/sockets.target b/test/sockets.target deleted file mode 120000 index 8ff86a0775..0000000000 --- a/test/sockets.target +++ /dev/null @@ -1 +0,0 @@ -../units/sockets.target \ No newline at end of file diff --git a/test/sysinit.target b/test/sysinit.target deleted file mode 120000 index 3301338185..0000000000 --- a/test/sysinit.target +++ /dev/null @@ -1 +0,0 @@ -../units/sysinit.target \ No newline at end of file diff --git a/test/test-functions b/test/test-functions index 66cd60b559..ead815f2fa 100644 --- a/test/test-functions +++ b/test/test-functions @@ -14,8 +14,11 @@ 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:-ext4}" UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}" -EFI_MOUNT="$(bootctl -x 2>/dev/null || echo /boot)" +EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}" QEMU_MEM="${QEMU_MEM:-512M}" +IMAGE_NAME=${IMAGE_NAME:-default} +TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}" +LOOPDEV= # Decide if we can (and want to) run QEMU with KVM acceleration. # Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not, @@ -39,11 +42,104 @@ PATH_TO_INIT=$ROOTLIBDIR/systemd [ "$SYSTEMD_NSPAWN" ] || SYSTEMD_NSPAWN=$(which -a $BUILD_DIR/systemd-nspawn systemd-nspawn 2>/dev/null | grep '^/' -m1) [ "$JOURNALCTL" ] || JOURNALCTL=$(which -a $BUILD_DIR/journalctl journalctl 2>/dev/null | grep '^/' -m1) -BASICTOOLS="test env sh bash setsid loadkeys setfont login sulogin gzip sleep echo head tail cat mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs" -DEBUGTOOLS="df free ls stty ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find vi mv" +BASICTOOLS=( + awk + basename + bash + busybox + capsh + cat + chmod + chown + cmp + cryptsetup + cut + date + dd + diff + dirname + dmsetup + echo + env + false + getent + getfacl + grep + gunzip + gzip + head + ionice + ip + ln + loadkeys + login + lz4cat + mkfifo + mktemp + modprobe + mount + mv + nc + nproc + readlink + rev + rm + rmdir + sed + seq + setfont + setsid + sfdisk + sh + sleep + socat + stat + su + sulogin + sysctl + tail + tar + tee + test + touch + tr + true + truncate + umount + uname + unshare + xargs + xzcat +) + +DEBUGTOOLS=( + cp + df + dhclient + dmesg + du + find + free + grep + hostname + id + less + ln + ls + mkdir + ping + ps + route + sort + strace + stty + tty + vi +) STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))" STATEFILE="$STATEDIR/.testdir" +IMAGESTATEDIR="$STATEDIR/.." TESTLOG="$STATEDIR/test.log" is_built_with_asan() { @@ -138,6 +234,10 @@ run_qemu() { CONSOLE=ttyS0 + # make sure the initdir is not mounted to avoid concurrent access + cleanup_initdir + umount_loopback + if [[ ! "$KERNEL_BIN" ]]; then if [[ "$LOOKS_LIKE_ARCH" ]]; then KERNEL_BIN=/boot/vmlinuz-linux @@ -184,6 +284,9 @@ run_qemu() { find_qemu_bin || return 1 + # Umount initdir to avoid concurrent access to the filesystem + _umount_dir $initdir + local _cgroup_args if [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ]]; then _cgroup_args="systemd.unified_cgroup_hierarchy=yes" @@ -198,14 +301,18 @@ run_qemu() { if [[ "$LOOKS_LIKE_SUSE" ]]; then PARAMS+="rd.hostonly=0" - elif [[ "$LOOKS_LIKE_ARCH" ]]; then - PARAMS+="rw" + fi + + local _end + if [[ ! "$INTERACTIVE_DEBUG" ]]; then + _end="systemd.wants=end.service" else - PARAMS+="ro" + _end="" fi KERNEL_APPEND="$PARAMS \ root=/dev/sda1 \ +rw \ raid=noautodetect \ rd.luks=0 \ loglevel=2 \ @@ -213,6 +320,9 @@ init=$PATH_TO_INIT \ console=$CONSOLE \ selinux=0 \ $_cgroup_args \ +SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/testsuite-$1.units:/usr/lib/systemd/tests/testdata/units: \ +systemd.unit=testsuite.target \ +systemd.wants=testsuite-$1.service ${_end} \ $KERNEL_APPEND \ " @@ -221,7 +331,7 @@ $KERNEL_APPEND \ -m $QEMU_MEM \ -nographic \ -kernel $KERNEL_BIN \ --drive format=raw,cache=unsafe,file=${TESTDIR}/rootdisk.img \ +-drive format=raw,cache=unsafe,file=${IMAGESTATEDIR}/${IMAGE_NAME}.img \ $QEMU_OPTIONS \ " @@ -253,24 +363,41 @@ $QEMU_OPTIONS \ run_nspawn() { [[ -d /run/systemd/system ]] || return 1 - local _nspawn_cmd="$SYSTEMD_NSPAWN $NSPAWN_ARGUMENTS --register=no --kill-signal=SIGKILL --directory=$TESTDIR/$1 $PATH_TO_INIT $KERNEL_APPEND" + local _nspawn_cmd=( + --register=no + --kill-signal=SIGKILL + --directory=$1 + --setenv=SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/testsuite-$2.units:/usr/lib/systemd/tests/testdata/units: + $PATH_TO_INIT + $KERNEL_APPEND + systemd.unit=testsuite.target + systemd.wants=testsuite-$2.service + ) + + if [[ ! "$INTERACTIVE_DEBUG" ]]; then + _nspawn_cmd+=( systemd.wants=end.service ) + fi + + local _nspawn_pre if [[ "$NSPAWN_TIMEOUT" != "infinity" ]]; then - _nspawn_cmd="timeout --foreground $NSPAWN_TIMEOUT $_nspawn_cmd" + _nspawn_pre=(timeout --foreground $NSPAWN_TIMEOUT) + else + _nspawn_pre=() fi if [[ "$UNIFIED_CGROUP_HIERARCHY" = "hybrid" ]]; then dwarn "nspawn doesn't support SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=hybrid, skipping" exit elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" || "$UNIFIED_CGROUP_HIERARCHY" = "no" ]]; then - _nspawn_cmd="env SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd" + _nspawn_pre=("${nspawn_pre[@]}" env SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY) elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "default" ]]; then - _nspawn_cmd="env --unset=UNIFIED_CGROUP_HIERARCHY --unset=SYSTEMD_NSPAWN_UNIFIED_HIERARCHY $_nspawn_cmd" + _nspawn_pre=("${nspawn_pre[@]}" env --unset=UNIFIED_CGROUP_HIERARCHY --unset=SYSTEMD_NSPAWN_UNIFIED_HIERARCHY) else dfatal "Unknown UNIFIED_CGROUP_HIERARCHY. Got $UNIFIED_CGROUP_HIERARCHY, expected [yes|no|hybrid|default]" exit 1 fi - (set -x; $_nspawn_cmd) + (set -x; "${_nspawn_pre[@]}" "$SYSTEMD_NSPAWN" $NSPAWN_ARGUMENTS "${_nspawn_cmd[@]}") rc=$? if [ "$rc" = 124 ] && [ "$NSPAWN_TIMEOUT" != "infinity" ]; then derror "test timed out after $NSPAWN_TIMEOUT s" @@ -288,6 +415,7 @@ setup_basic_environment() { install_systemd install_missing_libraries install_config_files + install_zoneinfo create_rc_local install_basic_tools install_libnss @@ -301,6 +429,8 @@ setup_basic_environment() { install_plymouth install_debug_tools install_ld_so_conf + install_testuser + has_user_dbus_socket && install_user_dbus setup_selinux strip_binaries install_depmod_files @@ -326,27 +456,9 @@ setup_selinux() { exit 1 fi - cat <$initdir/etc/systemd/system/autorelabel.service -[Unit] -Description=Relabel all filesystems -DefaultDependencies=no -Requires=local-fs.target -Conflicts=shutdown.target -After=local-fs.target -Before=sysinit.target shutdown.target -ConditionSecurity=selinux -ConditionPathExists=|/.autorelabel - -[Service] -ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && fixfiles -f -F relabel && rm /.autorelabel && systemctl --force reboot' -Type=oneshot -TimeoutSec=0 -RemainAfterExit=yes -EOF - touch $initdir/.autorelabel - mkdir -p $initdir/etc/systemd/system/basic.target.wants - ln -fs autorelabel.service $initdir/etc/systemd/system/basic.target.wants/autorelabel.service + mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/basic.target.wants + ln -sf ../autorelabel.service $initdir/usr/lib/systemd/tests/testdata/units/basic.target.wants/ dracut_install $_fixfiles_tools dracut_install fixfiles @@ -475,7 +587,7 @@ unset_ld_preload() { } unset_ld_preload systemd-remount-fs -unset_ld_preload testsuite +unset_ld_preload testsuite- export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS exec $ROOTLIBDIR/systemd "\$@" @@ -530,7 +642,7 @@ install_systemd() { # and it could fill the available space strip_binaries - [[ "$LOOKS_LIKE_SUSE" ]] && setup_suse + [[ "$LOOKS_LIKE_SUSE" ]] && setup_suse # enable debug logging in PID1 echo LogLevel=debug >> $initdir/etc/systemd/system.conf @@ -556,17 +668,37 @@ install_missing_libraries() { done } +cleanup_loopdev() { + if [ -n "${LOOPDEV}" ]; then + ddebug "losetup -d $LOOPDEV" + losetup -d "${LOOPDEV}" + fi +} + +trap cleanup_loopdev EXIT + create_empty_image() { + if [ -z "$IMAGE_NAME" ]; then + echo "create_empty_image: \$IMAGE_NAME not set" + exit 1 + fi + local _size=500 if [[ "$STRIP_BINARIES" = "no" ]]; then _size=$((4*_size)) fi - rm -f "$TESTDIR/rootdisk.img" + + image="${TESTDIR}/${IMAGE_NAME}.img" + public="$IMAGESTATEDIR/${IMAGE_NAME}.img" + echo "Setting up $public (${_size} MB)" + rm -f "$image" "$public" + # Create the blank file to use as a root filesystem - truncate -s "${_size}M" "$TESTDIR/rootdisk.img" - LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img) + truncate -s "${_size}M" "$image" + ln -vs "$(realpath $image)" "$public" + + LOOPDEV=$(losetup --show -P -f "$public") [ -b "$LOOPDEV" ] || return 1 - echo "LOOPDEV=$LOOPDEV" >> $STATEFILE sfdisk "$LOOPDEV" <$initdir/etc/sysusers.d/testuser.conf < $initdir/etc/environment > $initdir/etc/machine-id + # set the hostname echo systemd-testsuite > $initdir/etc/hostname - # fstab - if [[ "$LOOKS_LIKE_SUSE" ]]; then - ROOTMOUNT="/dev/sda1 / ${FSTYPE} rw 0 1" - else - ROOTMOUNT="LABEL=systemd / ${FSTYPE} rw 0 1" - fi - - cat >$initdir/etc/fstab < $initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf < + + + + + + +EOF } install_user_dbus() { @@ -885,10 +1064,16 @@ install_keymaps() { } install_zoneinfo() { - for i in /usr/share/zoneinfo/{,*/,*/*/}*; do - [[ -f $i ]] || continue - inst $i - done + inst_any /usr/share/zoneinfo/Asia/Seoul + inst_any /usr/share/zoneinfo/Asia/Vladivostok + inst_any /usr/share/zoneinfo/Australia/Sydney + inst_any /usr/share/zoneinfo/Europe/Berlin + inst_any /usr/share/zoneinfo/Europe/Kiev + inst_any /usr/share/zoneinfo/Pacific/Auckland + inst_any /usr/share/zoneinfo/Pacific/Honolulu + inst_any /usr/share/zoneinfo/CET + inst_any /usr/share/zoneinfo/EET + inst_any /usr/share/zoneinfo/UTC } install_fonts() { @@ -916,40 +1101,17 @@ has_user_dbus_socket() { fi } -enable_user_manager() { - has_user_dbus_socket || return 0 - - local _userid - [[ $# -gt 0 ]] || set -- nobody - mkdir -p "$initdir/var/lib/systemd/linger" - for _userid; do - touch "$initdir/var/lib/systemd/linger/$_userid" - done - dracut_install su - install_user_dbus -} - -setup_testsuite() { - cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/ - cp $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/ - - mkdir -p $initdir/etc/systemd/system/testsuite.target.wants - ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service - # Don't shutdown the machine after running the test when INTERACTIVE_DEBUG is set - [[ -z $INTERACTIVE_DEBUG ]] && ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service - - # make the testsuite the default target - ln -fs testsuite.target $initdir/etc/systemd/system/default.target -} - setup_nspawn_root() { - rm -fr $TESTDIR/nspawn-root - ddebug "cp -ar $initdir $TESTDIR/nspawn-root" - cp -ar $initdir $TESTDIR/nspawn-root - # we don't mount in the nspawn root - rm -f $TESTDIR/nspawn-root/etc/fstab + if [ -z "${initdir}" ]; then + dfatal "\$initdir not defined" + exit 1 + fi + + rm -rf "$TESTDIR/unprivileged-nspawn-root" + if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then - cp -ar $TESTDIR/nspawn-root $TESTDIR/unprivileged-nspawn-root + ddebug "cp -ar $initdir $TESTDIR/unprivileged-nspawn-root" + cp -ar $initdir $TESTDIR/unprivileged-nspawn-root fi } @@ -1005,7 +1167,10 @@ inst_libs() { } import_testdir() { + # make sure we don't get a stale LOOPDEV value from old times + __LOOPDEV=$LOOPDEV [[ -e $STATEFILE ]] && . $STATEFILE + LOOPDEV=$__LOOPDEV if [[ ! -d "$TESTDIR" ]]; then if [[ -z "$TESTDIR" ]]; then TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX) @@ -1013,7 +1178,9 @@ import_testdir() { mkdir -p "$TESTDIR" fi - echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE + cat >$STATEFILE</dev/null && \ + [[ "$(meson configure $BUILD_DIR | grep install-tests | awk '{ print $2 }')" != "true" ]]; then + dfatal "Needs to be built with -Dinstall-tests=true" + exit 1 + fi + + image="${TESTDIR}/${IMAGE_NAME}.img" + public="${IMAGESTATEDIR}/${IMAGE_NAME}.img" + if [ -e "$image" ]; then + echo "Reusing existing image $PWD/$image → $(realpath $image)" + mount_initdir + elif [ -e "$public" ]; then + echo "Reusing existing cached image $PWD/$public → $(realpath $public)" + ln -s "$(realpath $public)" "$image" + mount_initdir + else + test_create_image + fi + + setup_nspawn_root +} + test_run() { + mount_initdir + rm -f "$initdir"/{testok,failed,skipped} + if [ -z "$TEST_NO_QEMU" ]; then - if run_qemu; then - check_result_qemu || return 1 + if run_qemu "$1"; then + check_result_qemu || { echo "QEMU test failed"; return 1; } else dwarn "can't run QEMU, skipping" fi fi if [ -z "$TEST_NO_NSPAWN" ]; then - if run_nspawn "nspawn-root"; then - check_result_nspawn "nspawn-root" || return 1 + mount_initdir + if run_nspawn "$initdir" "$1"; then + check_result_nspawn "$initdir" || { echo "nspawn-root test failed"; return 1; } else dwarn "can't run systemd-nspawn, skipping" fi if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then - if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "unprivileged-nspawn-root"; then - check_result_nspawn "unprivileged-nspawn-root" || return 1 + dir="$TESTDIR/unprivileged-nspawn-root" + if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "$dir" "$1"; then + check_result_nspawn "$dir" || { echo "unprivileged-nspawn-root test failed"; return 1; } else dwarn "can't run systemd-nspawn, skipping" fi @@ -1830,34 +2035,40 @@ do_test() { import_testdir import_initdir + testname="$(basename $PWD)" + while (($# > 0)); do case $1 in --run) - echo "TEST RUN: $TEST_DESCRIPTION" - test_run + echo "${testname} RUN: $TEST_DESCRIPTION" + test_run "$2" ret=$? if (( $ret == 0 )); then - echo "TEST RUN: $TEST_DESCRIPTION [OK]" + echo "${testname} RUN: $TEST_DESCRIPTION [OK]" else - echo "TEST RUN: $TEST_DESCRIPTION [FAILED]" + echo "${testname} RUN: $TEST_DESCRIPTION [FAILED]" fi exit $ret;; --setup) - echo "TEST SETUP: $TEST_DESCRIPTION" + echo "${testname} SETUP: $TEST_DESCRIPTION" test_setup test_setup_cleanup ;; --clean) - echo "TEST CLEANUP: $TEST_DESCRIPTION" + echo "${testname} CLEANUP: $TEST_DESCRIPTION" test_cleanup ;; + --clean-again) + echo "${testname} CLEANUP AGAIN: $TEST_DESCRIPTION" + test_cleanup_again + ;; --all) ret=0 - echo -n "TEST: $TEST_DESCRIPTION " + echo -n "${testname}: $TEST_DESCRIPTION " ( test_setup test_setup_cleanup - test_run + test_run "$2" ) "$TESTLOG" 2>&1 || ret=$? test_cleanup if [ $ret -eq 0 ]; then diff --git a/test/test-network-generator-conversion.sh b/test/test-network-generator-conversion.sh new file mode 100755 index 0000000000..d0d0834518 --- /dev/null +++ b/test/test-network-generator-conversion.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -ex + +if [[ -n "$1" ]]; then + generator=$1 +elif [[ -x /usr/lib/systemd/systemd-network-generator ]]; then + generator=/usr/lib/systemd/systemd-network-generator +elif [[ -x /lib/systemd/systemd-network-generator ]]; then + generator=/lib/systemd/systemd-network-generator +else + exit 1 +fi + +src="$(dirname "$0")/testdata/test-network-generator-conversion" + +for f in "$src"/test-*.input; do + echo "*** Running $f" + + ( + out=$(mktemp --directory) + trap "rm -rf '$out'" EXIT INT QUIT PIPE + + $generator --root "$out" -- $(cat $f) + + if ! diff -u "$out"/run/systemd/network ${f%.input}.expected; then + echo "**** Unexpected output for $f" + exit 1 + fi + ) || exit 1 +done diff --git a/test/TEST-35-NETWORK-GENERATOR/test-01-dhcp.expected/91-default.network b/test/test-network-generator-conversion/test-01-dhcp.expected/91-default.network similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-01-dhcp.expected/91-default.network rename to test/test-network-generator-conversion/test-01-dhcp.expected/91-default.network diff --git a/test/TEST-35-NETWORK-GENERATOR/test-01-dhcp.input b/test/test-network-generator-conversion/test-01-dhcp.input similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-01-dhcp.input rename to test/test-network-generator-conversion/test-01-dhcp.input diff --git a/test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-bridge99.netdev b/test/test-network-generator-conversion/test-02-bridge.expected/90-bridge99.netdev similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-bridge99.netdev rename to test/test-network-generator-conversion/test-02-bridge.expected/90-bridge99.netdev diff --git a/test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-bridge99.network b/test/test-network-generator-conversion/test-02-bridge.expected/90-bridge99.network similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-bridge99.network rename to test/test-network-generator-conversion/test-02-bridge.expected/90-bridge99.network diff --git a/test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-eth0.network b/test/test-network-generator-conversion/test-02-bridge.expected/90-eth0.network similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-eth0.network rename to test/test-network-generator-conversion/test-02-bridge.expected/90-eth0.network diff --git a/test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-eth1.network b/test/test-network-generator-conversion/test-02-bridge.expected/90-eth1.network similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-02-bridge.expected/90-eth1.network rename to test/test-network-generator-conversion/test-02-bridge.expected/90-eth1.network diff --git a/test/TEST-35-NETWORK-GENERATOR/test-02-bridge.input b/test/test-network-generator-conversion/test-02-bridge.input similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-02-bridge.input rename to test/test-network-generator-conversion/test-02-bridge.input diff --git a/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.expected/90-enp3s0.network b/test/test-network-generator-conversion/test-03-issue-14319.expected/90-enp3s0.network similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.expected/90-enp3s0.network rename to test/test-network-generator-conversion/test-03-issue-14319.expected/90-enp3s0.network diff --git a/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.input b/test/test-network-generator-conversion/test-03-issue-14319.input similarity index 100% rename from test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.input rename to test/test-network-generator-conversion/test-03-issue-14319.input diff --git a/test/test-path/basic.target b/test/test-path/basic.target deleted file mode 120000 index a882b72cc9..0000000000 --- a/test/test-path/basic.target +++ /dev/null @@ -1 +0,0 @@ -../../units/basic.target \ No newline at end of file diff --git a/test/test-path/basic.target b/test/test-path/basic.target new file mode 100644 index 0000000000..4f44292249 --- /dev/null +++ b/test/test-path/basic.target @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=Basic System +Documentation=man:systemd.special(7) +Requires=sysinit.target +Wants=sockets.target timers.target paths.target slices.target +After=sysinit.target sockets.target paths.target slices.target tmp.mount + +# We support /var, /tmp, /var/tmp, being on NFS, but we don't pull in +# remote-fs.target by default, hence pull them in explicitly here. Note that we +# require /var and /var/tmp, but only add a Wants= type dependency on /tmp, as +# we support that unit being masked, and this should not be considered an error. +RequiresMountsFor=/var /var/tmp +Wants=tmp.mount diff --git a/test/test-path/path-changed.service b/test/test-path/path-changed.service deleted file mode 120000 index 8bdf178830..0000000000 --- a/test/test-path/path-changed.service +++ /dev/null @@ -1 +0,0 @@ -path-service.service \ No newline at end of file diff --git a/test/test-path/path-changed.service b/test/test-path/path-changed.service new file mode 100644 index 0000000000..f8499ec619 --- /dev/null +++ b/test/test-path/path-changed.service @@ -0,0 +1,6 @@ +[Unit] +Description=Service Test for Path units + +[Service] +ExecStart=/bin/true +Type=oneshot diff --git a/test/test-path/path-directorynotempty.service b/test/test-path/path-directorynotempty.service deleted file mode 120000 index 8bdf178830..0000000000 --- a/test/test-path/path-directorynotempty.service +++ /dev/null @@ -1 +0,0 @@ -path-service.service \ No newline at end of file diff --git a/test/test-path/path-directorynotempty.service b/test/test-path/path-directorynotempty.service new file mode 100644 index 0000000000..f8499ec619 --- /dev/null +++ b/test/test-path/path-directorynotempty.service @@ -0,0 +1,6 @@ +[Unit] +Description=Service Test for Path units + +[Service] +ExecStart=/bin/true +Type=oneshot diff --git a/test/test-path/path-exists.service b/test/test-path/path-exists.service deleted file mode 120000 index 8bdf178830..0000000000 --- a/test/test-path/path-exists.service +++ /dev/null @@ -1 +0,0 @@ -path-service.service \ No newline at end of file diff --git a/test/test-path/path-exists.service b/test/test-path/path-exists.service new file mode 100644 index 0000000000..f8499ec619 --- /dev/null +++ b/test/test-path/path-exists.service @@ -0,0 +1,6 @@ +[Unit] +Description=Service Test for Path units + +[Service] +ExecStart=/bin/true +Type=oneshot diff --git a/test/test-path/path-existsglob.service b/test/test-path/path-existsglob.service deleted file mode 120000 index 8bdf178830..0000000000 --- a/test/test-path/path-existsglob.service +++ /dev/null @@ -1 +0,0 @@ -path-service.service \ No newline at end of file diff --git a/test/test-path/path-existsglob.service b/test/test-path/path-existsglob.service new file mode 100644 index 0000000000..f8499ec619 --- /dev/null +++ b/test/test-path/path-existsglob.service @@ -0,0 +1,6 @@ +[Unit] +Description=Service Test for Path units + +[Service] +ExecStart=/bin/true +Type=oneshot diff --git a/test/test-path/path-makedirectory.service b/test/test-path/path-makedirectory.service deleted file mode 120000 index 8bdf178830..0000000000 --- a/test/test-path/path-makedirectory.service +++ /dev/null @@ -1 +0,0 @@ -path-service.service \ No newline at end of file diff --git a/test/test-path/path-makedirectory.service b/test/test-path/path-makedirectory.service new file mode 100644 index 0000000000..f8499ec619 --- /dev/null +++ b/test/test-path/path-makedirectory.service @@ -0,0 +1,6 @@ +[Unit] +Description=Service Test for Path units + +[Service] +ExecStart=/bin/true +Type=oneshot diff --git a/test/test-path/path-modified.service b/test/test-path/path-modified.service deleted file mode 120000 index 8bdf178830..0000000000 --- a/test/test-path/path-modified.service +++ /dev/null @@ -1 +0,0 @@ -path-service.service \ No newline at end of file diff --git a/test/test-path/path-modified.service b/test/test-path/path-modified.service new file mode 100644 index 0000000000..f8499ec619 --- /dev/null +++ b/test/test-path/path-modified.service @@ -0,0 +1,6 @@ +[Unit] +Description=Service Test for Path units + +[Service] +ExecStart=/bin/true +Type=oneshot diff --git a/test/test-path/paths.target b/test/test-path/paths.target deleted file mode 120000 index b402796cb9..0000000000 --- a/test/test-path/paths.target +++ /dev/null @@ -1 +0,0 @@ -../../units/paths.target \ No newline at end of file diff --git a/test/test-path/paths.target b/test/test-path/paths.target new file mode 100644 index 0000000000..9b6ed1c13f --- /dev/null +++ b/test/test-path/paths.target @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=Paths +Documentation=man:systemd.special(7) diff --git a/test/test-path/sysinit.target b/test/test-path/sysinit.target deleted file mode 120000 index 9d10e5b2e2..0000000000 --- a/test/test-path/sysinit.target +++ /dev/null @@ -1 +0,0 @@ -../../units/sysinit.target \ No newline at end of file diff --git a/test/test-path/sysinit.target b/test/test-path/sysinit.target new file mode 100644 index 0000000000..b6c16a1412 --- /dev/null +++ b/test/test-path/sysinit.target @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=System Initialization +Documentation=man:systemd.special(7) +Conflicts=emergency.service emergency.target +Wants=local-fs.target swap.target +After=local-fs.target swap.target emergency.service emergency.target diff --git a/test/testdata b/test/testdata new file mode 120000 index 0000000000..945c9b46d6 --- /dev/null +++ b/test/testdata @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/test/testsuite-04.units/forever-print-hola.service b/test/testsuite-04.units/forever-print-hola.service new file mode 100644 index 0000000000..a0dc095688 --- /dev/null +++ b/test/testsuite-04.units/forever-print-hola.service @@ -0,0 +1,6 @@ +[Unit] +Description=ForeverPrintHola service + +[Service] +Type=simple +ExecStart=sh -x -c 'while :; do printf "Hola\n" || touch /i-lose-my-logs; sleep 1; done' diff --git a/test/testsuite-06.units/hola.service b/test/testsuite-06.units/hola.service new file mode 100644 index 0000000000..5dc633206a --- /dev/null +++ b/test/testsuite-06.units/hola.service @@ -0,0 +1,6 @@ +[Service] +Type=oneshot +ExecStart=/bin/echo Start Hola +ExecReload=/bin/echo Reload Hola +ExecStop=/bin/echo Stop Hola +RemainAfterExit=yes diff --git a/test/testsuite-06.units/load-systemd-test-module.service b/test/testsuite-06.units/load-systemd-test-module.service new file mode 100644 index 0000000000..323a76c68d --- /dev/null +++ b/test/testsuite-06.units/load-systemd-test-module.service @@ -0,0 +1,14 @@ +[Unit] +Description=Load systemd-test module +DefaultDependencies=no +Requires=local-fs.target +Conflicts=shutdown.target +After=local-fs.target +Before=sysinit.target shutdown.target autorelabel.service +ConditionSecurity=selinux + +[Service] +ExecStart=sh -x -c 'echo 0 >/sys/fs/selinux/enforce && cd /systemd-test-module && make -f /usr/share/selinux/devel/Makefile load' +Type=oneshot +TimeoutSec=0 +RemainAfterExit=yes diff --git a/test/testsuite-08.units/-.mount b/test/testsuite-08.units/-.mount new file mode 100644 index 0000000000..af4e219759 --- /dev/null +++ b/test/testsuite-08.units/-.mount @@ -0,0 +1,12 @@ +[Unit] +Before=local-fs.target + +[Mount] +What=/dev/sda1 +Where=/ +Type=ext4 +Options=errors=remount-ro,noatime + +[Install] +WantedBy=local-fs.target +Alias=root.mount diff --git a/test/testsuite-08.units/local-fs.target.wants/-.mount b/test/testsuite-08.units/local-fs.target.wants/-.mount new file mode 120000 index 0000000000..5566fceaa3 --- /dev/null +++ b/test/testsuite-08.units/local-fs.target.wants/-.mount @@ -0,0 +1 @@ +../-.mount \ No newline at end of file diff --git a/test/testsuite-08.units/root.mount b/test/testsuite-08.units/root.mount new file mode 120000 index 0000000000..fd8c47d1b0 --- /dev/null +++ b/test/testsuite-08.units/root.mount @@ -0,0 +1 @@ +-.mount \ No newline at end of file diff --git a/test/testsuite-08.units/systemd-remount-fs.service b/test/testsuite-08.units/systemd-remount-fs.service new file mode 100644 index 0000000000..398d612749 --- /dev/null +++ b/test/testsuite-08.units/systemd-remount-fs.service @@ -0,0 +1,11 @@ +[Unit] +DefaultDependencies=no +Conflicts=shutdown.target +After=systemd-fsck-root.service +Before=local-fs-pre.target local-fs.target shutdown.target +Wants=local-fs-pre.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/systemctl reload / diff --git a/test/testsuite-10.units/test10.service b/test/testsuite-10.units/test10.service new file mode 100644 index 0000000000..d0be786b01 --- /dev/null +++ b/test/testsuite-10.units/test10.service @@ -0,0 +1,6 @@ +[Unit] +Requires=test10.socket +ConditionPathExistsGlob=/tmp/nonexistent + +[Service] +ExecStart=true diff --git a/test/testsuite-10.units/test10.socket b/test/testsuite-10.units/test10.socket new file mode 100644 index 0000000000..9cceebbb8e --- /dev/null +++ b/test/testsuite-10.units/test10.socket @@ -0,0 +1,2 @@ +[Socket] +ListenStream=/run/test.ctl diff --git a/test/testsuite-11.units/fail-on-restart.service b/test/testsuite-11.units/fail-on-restart.service new file mode 100644 index 0000000000..9264f151f3 --- /dev/null +++ b/test/testsuite-11.units/fail-on-restart.service @@ -0,0 +1,9 @@ +[Unit] +Description=Fail on restart +StartLimitIntervalSec=1m +StartLimitBurst=3 + +[Service] +Type=simple +ExecStart=false +Restart=always diff --git a/test/TEST-16-EXTEND-TIMEOUT/extend_timeout_test_service.sh b/test/testsuite-16.units/extend-timeout.sh similarity index 88% rename from test/TEST-16-EXTEND-TIMEOUT/extend_timeout_test_service.sh rename to test/testsuite-16.units/extend-timeout.sh index 40bf046dcd..ed1af8afeb 100755 --- a/test/TEST-16-EXTEND-TIMEOUT/extend_timeout_test_service.sh +++ b/test/testsuite-16.units/extend-timeout.sh @@ -4,23 +4,15 @@ set -e set -o pipefail # sleep interval (seconds) -sleep_interval=1 +: ${sleep_interval:=1} # extend_timeout_interval second(s) -extend_timeout_interval=1 +: ${extend_timeout_interval:=1} # number of sleep_intervals before READY=1 -start_intervals=10 +: ${start_intervals:=10} # number of sleep_intervals before exiting -stop_intervals=10 +: ${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 +: ${run_intervals:=7} # We convert to usec extend_timeout_interval=$(( $extend_timeout_interval * 1000000 )) diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-runtime.service b/test/testsuite-16.units/fail-runtime.service similarity index 66% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-runtime.service rename to test/testsuite-16.units/fail-runtime.service index e0b9f6a70b..baa655f2f1 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-runtime.service +++ b/test/testsuite-16.units/fail-runtime.service @@ -1,13 +1,12 @@ - [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 +Environment=SERVICE=fail_runtime extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=2 stop_intervals=0 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-start.service b/test/testsuite-16.units/fail-start.service similarity index 66% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-start.service rename to test/testsuite-16.units/fail-start.service index c3fcf23dc0..882900440f 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-start.service +++ b/test/testsuite-16.units/fail-start.service @@ -1,4 +1,3 @@ - [Unit] Description=Testsuite: Fail Start (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after TimeoutStartSec.) @@ -10,4 +9,5 @@ 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 +Environment=SERVICE=fail_start extend_timeout_interval=5 sleep_interval=7 start_intervals=2 run_intervals=0 stop_intervals=0 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-stop.service b/test/testsuite-16.units/fail-stop.service similarity index 78% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-stop.service rename to test/testsuite-16.units/fail-stop.service index ce76d10db7..cdea2a9a2d 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-fail-stop.service +++ b/test/testsuite-16.units/fail-stop.service @@ -1,16 +1,15 @@ - [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 +Environment=SERVICE=fail_stop extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=0 stop_intervals=2 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh # 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/testsuite-16.units/success-all.service similarity index 68% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-success-all.service rename to test/testsuite-16.units/success-all.service index 666f4229bf..e2d7e607ba 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-all.service +++ b/test/testsuite-16.units/success-all.service @@ -1,4 +1,3 @@ - [Unit] Description=Testsuite: EXTEND_TIMEOUT_USEC Success - extend timeout on all services @@ -11,4 +10,5 @@ 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 +Environment=SERVICE=success_all extend_timeout_interval=4 sleep_interval=2 start_intervals=3 run_intervals=3 stop_intervals=3 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-runtime.service b/test/testsuite-16.units/success-runtime.service similarity index 60% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-success-runtime.service rename to test/testsuite-16.units/success-runtime.service index dc226f5054..15283b73a8 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-runtime.service +++ b/test/testsuite-16.units/success-runtime.service @@ -1,4 +1,3 @@ - [Unit] Description=Testsuite: Success Runtime (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < RuntimeMaxSec) @@ -10,4 +9,5 @@ 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 +Environment=SERVICE=success_runtime extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=1 stop_intervals=0 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-start.service b/test/testsuite-16.units/success-start.service similarity index 61% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-success-start.service rename to test/testsuite-16.units/success-start.service index 228eece73e..cfdcc33cc8 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-start.service +++ b/test/testsuite-16.units/success-start.service @@ -1,13 +1,12 @@ - [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 +Environment=SERVICE=success_start extend_timeout_interval=4 sleep_interval=6 start_intervals=1 run_intervals=0 stop_intervals=0 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh diff --git a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-stop.service b/test/testsuite-16.units/success-stop.service similarity index 61% rename from test/TEST-16-EXTEND-TIMEOUT/testsuite-success-stop.service rename to test/testsuite-16.units/success-stop.service index b809397bf3..c4600ace41 100644 --- a/test/TEST-16-EXTEND-TIMEOUT/testsuite-success-stop.service +++ b/test/testsuite-16.units/success-stop.service @@ -1,13 +1,12 @@ - [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 +Environment=SERVICE=success_stop extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=0 stop_intervals=1 +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh diff --git a/test/testsuite-28.units/specifier-j-depends-wants.service b/test/testsuite-28.units/specifier-j-depends-wants.service new file mode 100644 index 0000000000..f9c6abb493 --- /dev/null +++ b/test/testsuite-28.units/specifier-j-depends-wants.service @@ -0,0 +1,7 @@ +[Unit] +Description=Dependent service for percent-j specifier +After=testsuite-28-pre.service + +[Service] +Type=oneshot +ExecStart=touch /tmp/test-specifier-j-wants diff --git a/test/testsuite-28.units/specifier-j-wants.service b/test/testsuite-28.units/specifier-j-wants.service new file mode 100644 index 0000000000..facf5577be --- /dev/null +++ b/test/testsuite-28.units/specifier-j-wants.service @@ -0,0 +1,10 @@ +[Unit] +Description=Wants with percent-j specifier +Wants=specifier-j-depends-%j.service +After=specifier-j-depends-%j.service +After=testsuite-28-pre.service + +[Service] +Type=oneshot +ExecStart=test -f /tmp/test-specifier-j-%j +ExecStart=sh -c 'echo OK > /testok' diff --git a/test/testsuite-28.units/testsuite-28-pre.service b/test/testsuite-28.units/testsuite-28-pre.service new file mode 100644 index 0000000000..2b8ef98911 --- /dev/null +++ b/test/testsuite-28.units/testsuite-28-pre.service @@ -0,0 +1,3 @@ +[Service] +ExecStart=rm -f /failed /testok +Type=oneshot diff --git a/test/testsuite-30.units/systemd-timedated.service.d/watchdog.conf b/test/testsuite-30.units/systemd-timedated.service.d/watchdog.conf new file mode 100644 index 0000000000..d5ed27cf6b --- /dev/null +++ b/test/testsuite-30.units/systemd-timedated.service.d/watchdog.conf @@ -0,0 +1,2 @@ +[Service] +WatchdogSec=10min diff --git a/test/timers.target b/test/timers.target deleted file mode 120000 index 576d47fed7..0000000000 --- a/test/timers.target +++ /dev/null @@ -1 +0,0 @@ -../units/timers.target \ No newline at end of file diff --git a/test/a-conj.service b/test/units/a-conj.service similarity index 100% rename from test/a-conj.service rename to test/units/a-conj.service diff --git a/test/a.service b/test/units/a.service similarity index 100% rename from test/a.service rename to test/units/a.service diff --git a/test/units/autorelabel.service b/test/units/autorelabel.service new file mode 100644 index 0000000000..cb38849373 --- /dev/null +++ b/test/units/autorelabel.service @@ -0,0 +1,18 @@ +[Unit] +Description=Relabel all filesystems +DefaultDependencies=no +Requires=local-fs.target +Conflicts=shutdown.target +After=local-fs.target +Before=sysinit.target shutdown.target +ConditionSecurity=selinux +ConditionPathExists=|/.autorelabel + +[Service] +ExecStart=sh -x -c 'echo 0 >/sys/fs/selinux/enforce && fixfiles -f -F relabel && rm /.autorelabel && systemctl --force reboot' +Type=oneshot +TimeoutSec=0 +RemainAfterExit=yes + +[Install] +WantedBy=basic.target diff --git a/test/b.service b/test/units/b.service similarity index 100% rename from test/b.service rename to test/units/b.service diff --git a/test/units/basic.target b/test/units/basic.target new file mode 100644 index 0000000000..4f44292249 --- /dev/null +++ b/test/units/basic.target @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=Basic System +Documentation=man:systemd.special(7) +Requires=sysinit.target +Wants=sockets.target timers.target paths.target slices.target +After=sysinit.target sockets.target paths.target slices.target tmp.mount + +# We support /var, /tmp, /var/tmp, being on NFS, but we don't pull in +# remote-fs.target by default, hence pull them in explicitly here. Note that we +# require /var and /var/tmp, but only add a Wants= type dependency on /tmp, as +# we support that unit being masked, and this should not be considered an error. +RequiresMountsFor=/var /var/tmp +Wants=tmp.mount diff --git a/test/c.service b/test/units/c.service similarity index 100% rename from test/c.service rename to test/units/c.service diff --git a/test/d.service b/test/units/d.service similarity index 100% rename from test/d.service rename to test/units/d.service diff --git a/test/daughter.service b/test/units/daughter.service similarity index 100% rename from test/daughter.service rename to test/units/daughter.service diff --git a/test/dml-discard-empty.service b/test/units/dml-discard-empty.service similarity index 100% rename from test/dml-discard-empty.service rename to test/units/dml-discard-empty.service diff --git a/test/dml-discard-set-ml.service b/test/units/dml-discard-set-ml.service similarity index 100% rename from test/dml-discard-set-ml.service rename to test/units/dml-discard-set-ml.service diff --git a/test/dml-discard.slice b/test/units/dml-discard.slice similarity index 100% rename from test/dml-discard.slice rename to test/units/dml-discard.slice diff --git a/test/dml-override-empty.service b/test/units/dml-override-empty.service similarity index 100% rename from test/dml-override-empty.service rename to test/units/dml-override-empty.service diff --git a/test/dml-override.slice b/test/units/dml-override.slice similarity index 100% rename from test/dml-override.slice rename to test/units/dml-override.slice diff --git a/test/dml-passthrough-empty.service b/test/units/dml-passthrough-empty.service similarity index 100% rename from test/dml-passthrough-empty.service rename to test/units/dml-passthrough-empty.service diff --git a/test/dml-passthrough-set-dml.service b/test/units/dml-passthrough-set-dml.service similarity index 100% rename from test/dml-passthrough-set-dml.service rename to test/units/dml-passthrough-set-dml.service diff --git a/test/dml-passthrough-set-ml.service b/test/units/dml-passthrough-set-ml.service similarity index 100% rename from test/dml-passthrough-set-ml.service rename to test/units/dml-passthrough-set-ml.service diff --git a/test/dml-passthrough.slice b/test/units/dml-passthrough.slice similarity index 100% rename from test/dml-passthrough.slice rename to test/units/dml-passthrough.slice diff --git a/test/dml.slice b/test/units/dml.slice similarity index 100% rename from test/dml.slice rename to test/units/dml.slice diff --git a/test/e.service b/test/units/e.service similarity index 100% rename from test/e.service rename to test/units/e.service diff --git a/test/end.service b/test/units/end.service similarity index 89% rename from test/end.service rename to test/units/end.service index 6e1996fd02..e7ed75ef05 100644 --- a/test/end.service +++ b/test/units/end.service @@ -1,6 +1,6 @@ [Unit] Description=End the test -After=testsuite.service +After=testsuite.target OnFailure=poweroff.target OnFailureJobMode=replace-irreversibly diff --git a/test/f.service b/test/units/f.service similarity index 100% rename from test/f.service rename to test/units/f.service diff --git a/test/g.service b/test/units/g.service similarity index 100% rename from test/g.service rename to test/units/g.service diff --git a/test/grandchild.service b/test/units/grandchild.service similarity index 100% rename from test/grandchild.service rename to test/units/grandchild.service diff --git a/test/h.service b/test/units/h.service similarity index 100% rename from test/h.service rename to test/units/h.service diff --git a/test/hello-after-sleep.target b/test/units/hello-after-sleep.target similarity index 100% rename from test/hello-after-sleep.target rename to test/units/hello-after-sleep.target diff --git a/test/hello.service b/test/units/hello.service similarity index 100% rename from test/hello.service rename to test/units/hello.service diff --git a/test/i.service b/test/units/i.service similarity index 100% rename from test/i.service rename to test/units/i.service diff --git a/test/loopy.service b/test/units/loopy.service similarity index 100% rename from test/loopy.service rename to test/units/loopy.service diff --git a/test/loopy.service.d/compat.conf b/test/units/loopy.service.d/compat.conf similarity index 100% rename from test/loopy.service.d/compat.conf rename to test/units/loopy.service.d/compat.conf diff --git a/test/units/loopy2.service b/test/units/loopy2.service new file mode 100644 index 0000000000..9eb645748e --- /dev/null +++ b/test/units/loopy2.service @@ -0,0 +1,2 @@ +[Service] +ExecStart=/bin/true diff --git a/test/loopy3.service b/test/units/loopy3.service similarity index 100% rename from test/loopy3.service rename to test/units/loopy3.service diff --git a/test/units/loopy4.service b/test/units/loopy4.service new file mode 100644 index 0000000000..606e26b5da --- /dev/null +++ b/test/units/loopy4.service @@ -0,0 +1,5 @@ +[Service] +ExecStart=/bin/true + +[Unit] +Conflicts=loopy4.service diff --git a/test/nomem.slice b/test/units/nomem.slice similarity index 100% rename from test/nomem.slice rename to test/units/nomem.slice diff --git a/test/nomemleaf.service b/test/units/nomemleaf.service similarity index 100% rename from test/nomemleaf.service rename to test/units/nomemleaf.service diff --git a/test/parent-deep.slice b/test/units/parent-deep.slice similarity index 100% rename from test/parent-deep.slice rename to test/units/parent-deep.slice diff --git a/test/parent.slice b/test/units/parent.slice similarity index 100% rename from test/parent.slice rename to test/units/parent.slice diff --git a/test/sched_idle_bad.service b/test/units/sched_idle_bad.service similarity index 100% rename from test/sched_idle_bad.service rename to test/units/sched_idle_bad.service diff --git a/test/sched_idle_ok.service b/test/units/sched_idle_ok.service similarity index 100% rename from test/sched_idle_ok.service rename to test/units/sched_idle_ok.service diff --git a/test/sched_rr_bad.service b/test/units/sched_rr_bad.service similarity index 100% rename from test/sched_rr_bad.service rename to test/units/sched_rr_bad.service diff --git a/test/sched_rr_change.service b/test/units/sched_rr_change.service similarity index 100% rename from test/sched_rr_change.service rename to test/units/sched_rr_change.service diff --git a/test/sched_rr_ok.service b/test/units/sched_rr_ok.service similarity index 100% rename from test/sched_rr_ok.service rename to test/units/sched_rr_ok.service diff --git a/test/units/shutdown.target b/test/units/shutdown.target new file mode 100644 index 0000000000..d48e6d6494 --- /dev/null +++ b/test/units/shutdown.target @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=Shutdown +Documentation=man:systemd.special(7) +DefaultDependencies=no +RefuseManualStart=yes diff --git a/test/sleep.service b/test/units/sleep.service similarity index 100% rename from test/sleep.service rename to test/units/sleep.service diff --git a/test/units/sockets.target b/test/units/sockets.target new file mode 100644 index 0000000000..9af67fdb1f --- /dev/null +++ b/test/units/sockets.target @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=Sockets +Documentation=man:systemd.special(7) diff --git a/test/son.service b/test/units/son.service similarity index 100% rename from test/son.service rename to test/units/son.service diff --git a/test/units/sysinit.target b/test/units/sysinit.target new file mode 100644 index 0000000000..b6c16a1412 --- /dev/null +++ b/test/units/sysinit.target @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=System Initialization +Documentation=man:systemd.special(7) +Conflicts=emergency.service emergency.target +Wants=local-fs.target swap.target +After=local-fs.target swap.target emergency.service emergency.target diff --git a/test/units/testsuite-01.service b/test/units/testsuite-01.service new file mode 100644 index 0000000000..85b9cf5a96 --- /dev/null +++ b/test/units/testsuite-01.service @@ -0,0 +1,8 @@ +[Unit] +Description=TEST-01-BASIC +After=multi-user.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=sh -e -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok' +Type=oneshot diff --git a/test/units/testsuite-02.service b/test/units/testsuite-02.service new file mode 100644 index 0000000000..701610b790 --- /dev/null +++ b/test/units/testsuite-02.service @@ -0,0 +1,8 @@ +[Unit] +Description=TEST-02-CRYPTSETUP +After=multi-user.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=sh -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; echo OK > /testok' +Type=oneshot diff --git a/test/units/testsuite-03.service b/test/units/testsuite-03.service new file mode 100644 index 0000000000..fe18fdc7d7 --- /dev/null +++ b/test/units/testsuite-03.service @@ -0,0 +1,8 @@ +[Unit] +Description=TEST-03-JOBS +After=multi-user.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-03-JOBS/test-jobs.sh b/test/units/testsuite-03.sh similarity index 100% rename from test/TEST-03-JOBS/test-jobs.sh rename to test/units/testsuite-03.sh diff --git a/test/units/testsuite-04.service b/test/units/testsuite-04.service new file mode 100644 index 0000000000..3d2b4a8bc2 --- /dev/null +++ b/test/units/testsuite-04.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-04-JOURNAL + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/units/testsuite-04.sh similarity index 100% rename from test/TEST-04-JOURNAL/test-journal.sh rename to test/units/testsuite-04.sh diff --git a/test/units/testsuite-05.service b/test/units/testsuite-05.service new file mode 100644 index 0000000000..66356fd16f --- /dev/null +++ b/test/units/testsuite-05.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-05-RLIMITS + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/units/testsuite-05.sh b/test/units/testsuite-05.sh new file mode 100755 index 0000000000..eed30c8b85 --- /dev/null +++ b/test/units/testsuite-05.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -x +set -e +set -o pipefail + +P=/run/systemd/system.conf.d +mkdir $P + +cat >$P/rlimits.conf </sys/fs/selinux/enforce +echo 1 >/sys/fs/selinux/enforce || { + echo "Can't make selinux enforcing, skipping test" + touch /testok + exit +} + runcon -t systemd_test_start_t systemctl start hola runcon -t systemd_test_reload_t systemctl reload hola runcon -t systemd_test_stop_t systemctl stop hola diff --git a/test/units/testsuite-07.service b/test/units/testsuite-07.service new file mode 100644 index 0000000000..2506c211c2 --- /dev/null +++ b/test/units/testsuite-07.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-07-ISSUE-1981 + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-07-ISSUE-1981/test-segfault.sh b/test/units/testsuite-07.sh similarity index 100% rename from test/TEST-07-ISSUE-1981/test-segfault.sh rename to test/units/testsuite-07.sh diff --git a/test/units/testsuite-08.service b/test/units/testsuite-08.service new file mode 100644 index 0000000000..d961dc7ae2 --- /dev/null +++ b/test/units/testsuite-08.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-08-ISSUE-2730 + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=sh -x -c 'mount -o remount,rw /dev/sda1 && echo OK >/testok; systemctl poweroff' +Type=oneshot diff --git a/test/units/testsuite-09.service b/test/units/testsuite-09.service new file mode 100644 index 0000000000..fc59e80889 --- /dev/null +++ b/test/units/testsuite-09.service @@ -0,0 +1,10 @@ +[Unit] +Description=TEST-09-ISSUE-2691 + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=sh -c '>/testok' +ExecStop=sh -c 'kill -SEGV $$$$' +Type=oneshot +RemainAfterExit=yes +TimeoutStopSec=270s diff --git a/test/units/testsuite-10.service b/test/units/testsuite-10.service new file mode 100644 index 0000000000..24f0da35ab --- /dev/null +++ b/test/units/testsuite-10.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-10-ISSUE-2467 + +[Service] +ExecStartPre=rm -f /failed /testok +Type=oneshot +ExecStart=sh -e -x -c 'rm -f /tmp/nonexistent; systemctl start test10.socket; printf x >test.file; socat -t20 OPEN:test.file UNIX-CONNECT:/run/test.ctl; >/testok' diff --git a/test/units/testsuite-11.service b/test/units/testsuite-11.service new file mode 100644 index 0000000000..1544fd6819 --- /dev/null +++ b/test/units/testsuite-11.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-11-ISSUE-3166 + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/units/testsuite-11.sh b/test/units/testsuite-11.sh new file mode 100755 index 0000000000..708c7cebb7 --- /dev/null +++ b/test/units/testsuite-11.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -x + +systemctl start fail-on-restart.service +active_state=$(systemctl show --value --property ActiveState fail-on-restart.service) +while [[ "$active_state" == "activating" || "$active_state" == "active" ]]; do + sleep 1 + active_state=$(systemctl show --value --property ActiveState fail-on-restart.service) +done +systemctl is-failed fail-on-restart.service || exit 1 +touch /testok diff --git a/test/units/testsuite-12.service b/test/units/testsuite-12.service new file mode 100644 index 0000000000..72894eff92 --- /dev/null +++ b/test/units/testsuite-12.service @@ -0,0 +1,8 @@ +[Unit] +Description=TEST-12-ISSUE-3171 +After=multi-user.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/units/testsuite-12.sh b/test/units/testsuite-12.sh new file mode 100755 index 0000000000..b5888a255b --- /dev/null +++ b/test/units/testsuite-12.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -x +set -e +set -o pipefail + +U=/run/systemd/system/test12.socket +cat <<'EOF' >$U +[Unit] +Description=Test 12 socket +[Socket] +Accept=yes +ListenStream=/run/test12.socket +SocketGroup=adm +SocketMode=0660 +EOF + +cat <<'EOF' > /run/systemd/system/test12@.service +[Unit] +Description=Test service +[Service] +StandardInput=socket +ExecStart=/bin/sh -x -c cat +EOF + +systemctl start test12.socket +systemctl is-active test12.socket +[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] +echo A | nc -w1 -U /run/test12.socket + +mv $U ${U}.disabled +systemctl daemon-reload +systemctl is-active test12.socket +[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] +echo B | nc -w1 -U /run/test12.socket && exit 1 + +mv ${U}.disabled $U +systemctl daemon-reload +systemctl is-active test12.socket +echo C | nc -w1 -U /run/test12.socket && exit 1 +[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] + +systemctl restart test12.socket +systemctl is-active test12.socket +echo D | nc -w1 -U /run/test12.socket +[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] + +touch /testok diff --git a/test/units/testsuite-13.service b/test/units/testsuite-13.service new file mode 100644 index 0000000000..5086793a90 --- /dev/null +++ b/test/units/testsuite-13.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-13-NSPAWN-SMOKE + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh new file mode 100755 index 0000000000..0ab684732c --- /dev/null +++ b/test/units/testsuite-13.sh @@ -0,0 +1,150 @@ +#!/usr/bin/env bash +set -x +set -e +set -u +set -o pipefail + +export SYSTEMD_LOG_LEVEL=debug + +# check cgroup-v2 +is_v2_supported=no +mkdir -p /tmp/cgroup2 +if mount -t cgroup2 cgroup2 /tmp/cgroup2; then + is_v2_supported=yes + umount /tmp/cgroup2 +fi +rmdir /tmp/cgroup2 + +# check cgroup namespaces +is_cgns_supported=no +if [[ -f /proc/1/ns/cgroup ]]; then + is_cgns_supported=yes +fi + +is_user_ns_supported=no +# On some systems (e.g. CentOS 7) the default limit for user namespaces +# is set to 0, which causes the following unshare syscall to fail, even +# with enabled user namespaces support. By setting this value explicitly +# we can ensure the user namespaces support to be detected correctly. +sysctl -w user.max_user_namespaces=10000 +if unshare -U sh -c :; then + is_user_ns_supported=yes +fi + +function check_bind_tmp_path { + # https://github.com/systemd/systemd/issues/4789 + local _root="/var/lib/machines/bind-tmp-path" + /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" + >/tmp/bind + systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' +} + +function check_norbind { + # https://github.com/systemd/systemd/issues/13170 + local _root="/var/lib/machines/norbind-path" + mkdir -p /tmp/binddir/subdir + echo -n "outer" > /tmp/binddir/subdir/file + mount -t tmpfs tmpfs /tmp/binddir/subdir + echo -n "inner" > /tmp/binddir/subdir/file + /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" + systemd-nspawn --register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' +} + +function check_notification_socket { + # https://github.com/systemd/systemd/issues/4944 + local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/systemd/nspawn/notify' + systemd-nspawn --register=no -D /nc-container /bin/sh -x -c "$_cmd" + systemd-nspawn --register=no -D /nc-container -U /bin/sh -x -c "$_cmd" +} + +function run { + if [[ "$1" = "yes" && "$is_v2_supported" = "no" ]]; then + printf "Unified cgroup hierarchy is not supported. Skipping.\n" >&2 + return 0 + fi + if [[ "$2" = "yes" && "$is_cgns_supported" = "no" ]]; then + printf "CGroup namespaces are not supported. Skipping.\n" >&2 + return 0 + fi + + local _root="/var/lib/machines/unified-$1-cgns-$2-api-vfs-writable-$3" + /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b + + if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -U -b; then + [[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1 + else + [[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1 + fi + + if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -U -b; then + [[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1 + else + [[ "$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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 SYSTEMD_NSPAWN_UNIFIED_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 + + # allow combination of --network-namespace-path and --private-network + if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --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" + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP' + local r=$? + ip netns del nspawn_test + + if [ $r -ne 0 ]; then + return 1 + fi + + return 0 +} + +check_bind_tmp_path + +check_norbind + +check_notification_socket + +for api_vfs_writable in yes no network; do + run no no $api_vfs_writable + run yes no $api_vfs_writable + run no yes $api_vfs_writable + run yes yes $api_vfs_writable +done + +touch /testok diff --git a/test/units/testsuite-14.service b/test/units/testsuite-14.service new file mode 100644 index 0000000000..1606c68fb1 --- /dev/null +++ b/test/units/testsuite-14.service @@ -0,0 +1,8 @@ +[Unit] +Description=TEST-14-MACHINE-ID + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +ExecStart=/bin/sh -e -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; echo OK >/testok' +Type=oneshot diff --git a/test/units/testsuite-14.sh b/test/units/testsuite-14.sh new file mode 100755 index 0000000000..95ac9b65ae --- /dev/null +++ b/test/units/testsuite-14.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -e +set -x + +function setup_root { + local _root="$1" + mkdir -p "$_root" + mount -t tmpfs tmpfs "$_root" + mkdir -p "$_root/etc" "$_root/run" +} + +function check { + printf "Expected\n" + cat "$1" + printf "\nGot\n" + cat "$2" + cmp "$1" "$2" +} + +r="$(pwd)/overwrite-broken-machine-id" +setup_root "$r" +systemd-machine-id-setup --print --root "$r" +echo abc >>"$r/etc/machine-id" +id=$(systemd-machine-id-setup --print --root "$r") +echo $id >expected +check expected "$r/etc/machine-id" + +r="$(pwd)/transient-machine-id" +setup_root "$r" +systemd-machine-id-setup --print --root "$r" +echo abc >>"$r/etc/machine-id" +mount -o remount,ro "$r" +mount -t tmpfs tmpfs "$r/run" +transient_id=$(systemd-machine-id-setup --print --root "$r") +mount -o remount,rw "$r" +commited_id=$(systemd-machine-id-setup --print --commit --root "$r") +[[ "$transient_id" = "$commited_id" ]] +check "$r/etc/machine-id" "$r/run/machine-id" diff --git a/test/units/testsuite-15.service b/test/units/testsuite-15.service new file mode 100644 index 0000000000..09571ed1ab --- /dev/null +++ b/test/units/testsuite-15.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-15-DROPIN + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-15-DROPIN/test-dropin.sh b/test/units/testsuite-15.sh similarity index 59% rename from test/TEST-15-DROPIN/test-dropin.sh rename to test/units/testsuite-15.sh index f80c9df107..b872a24c20 100755 --- a/test/TEST-15-DROPIN/test-dropin.sh +++ b/test/units/testsuite-15.sh @@ -7,6 +7,12 @@ _clear_service () { rm -f /{etc,run,usr/lib}/systemd/system/$1.service rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.d rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.{wants,requires} + if [[ $1 == *@ ]]; then + systemctl stop $1*.service 2>/dev/null || : + rm -f /{etc,run,usr/lib}/systemd/system/$1*.service + rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.d + rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.{wants,requires} + fi } clear_services () { @@ -56,65 +62,66 @@ test_basic_dropins () { echo "Testing basic dropins..." echo "*** test a wants b wants c" - create_services a b c - ln -s ../b.service /etc/systemd/system/a.service.wants/ - ln -s ../c.service /etc/systemd/system/b.service.wants/ - check_ok a Wants b.service - check_ok b Wants c.service + create_services test15-a test15-b test15-c + ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/ + ln -s ../test15-c.service /etc/systemd/system/test15-b.service.wants/ + check_ok test15-a Wants test15-b.service + check_ok test15-b Wants test15-c.service echo "*** test a wants,requires b" - create_services a b c - ln -s ../b.service /etc/systemd/system/a.service.wants/ - ln -s ../b.service /etc/systemd/system/a.service.requires/ - check_ok a Wants b.service - check_ok a Requires b.service + create_services test15-a test15-b test15-c + ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/ + ln -s ../test15-b.service /etc/systemd/system/test15-a.service.requires/ + check_ok test15-a Wants test15-b.service + check_ok test15-a Requires test15-b.service echo "*** test a wants nonexistent" - create_service a - ln -s ../nonexistent.service /etc/systemd/system/a.service.wants/ - check_ok a Wants nonexistent.service - systemctl start a - systemctl stop a + create_service test15-a + ln -s ../nonexistent.service /etc/systemd/system/test15-a.service.wants/ + check_ok test15-a Wants nonexistent.service + systemctl start test15-a + systemctl stop test15-a echo "*** test a requires nonexistent" - ln -sf ../nonexistent.service /etc/systemd/system/a.service.requires/ + ln -sf ../nonexistent.service /etc/systemd/system/test15-a.service.requires/ systemctl daemon-reload - check_ok a Requires nonexistent.service + check_ok test15-a Requires nonexistent.service # 'b' is already loaded when 'c' pulls it in via a dropin. echo "*** test a,c require b" - create_services a b c - ln -sf ../b.service /etc/systemd/system/a.service.requires/ - ln -sf ../b.service /etc/systemd/system/c.service.requires/ - systemctl start a - check_ok c Requires b.service - systemctl stop a b + create_services test15-a test15-b test15-c + ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/ + ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/ + systemctl start test15-a + check_ok test15-c Requires test15-b.service + systemctl stop test15-a test15-b # 'b' is already loaded when 'c' pulls it in via an alias dropin. echo "*** test a wants alias" - create_services a b c - ln -sf c.service /etc/systemd/system/c1.service - ln -sf ../c.service /etc/systemd/system/a.service.wants/ - ln -sf ../c1.service /etc/systemd/system/b.service.wants/ - systemctl start a - check_ok a Wants c.service - check_ok b Wants c.service - systemctl stop a c + create_services test15-a test15-b test15-c + ln -sf test15-c.service /etc/systemd/system/test15-c1.service + ln -sf ../test15-c.service /etc/systemd/system/test15-a.service.wants/ + ln -sf ../test15-c1.service /etc/systemd/system/test15-b.service.wants/ + systemctl start test15-a + check_ok test15-a Wants test15-c.service + check_ok test15-b Wants test15-c.service + systemctl stop test15-a test15-c echo "*** test service.d/ top level drop-in" - create_services a b - check_ko a ExecCondition "/bin/echo a" - check_ko b ExecCondition "/bin/echo b" + create_services test15-a test15-b + check_ko test15-a ExecCondition "/bin/echo a" + check_ko test15-b ExecCondition "/bin/echo b" mkdir -p /usr/lib/systemd/system/service.d cat >/usr/lib/systemd/system/service.d/override.conf < /usr/lib/systemd/system/$dropin/override.conf + systemctl daemon-reload check_ok a-b-c ExecCondition "/bin/echo $dropin" done for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do @@ -294,153 +302,153 @@ test_alias_dropins () { echo "Testing alias dropins..." echo "*** test a wants b1 alias of b" - create_services a b - ln -sf b.service /etc/systemd/system/b1.service - ln -sf ../b1.service /etc/systemd/system/a.service.wants/ - check_ok a Wants b.service - systemctl start a - systemctl --quiet is-active b - systemctl stop a b - rm /etc/systemd/system/b1.service - clear_services a b + create_services test15-a test15-b + ln -sf test15-b.service /etc/systemd/system/test15-b1.service + ln -sf ../test15-b1.service /etc/systemd/system/test15-a.service.wants/ + check_ok test15-a Wants test15-b.service + systemctl start test15-a + systemctl --quiet is-active test15-b + systemctl stop test15-a test15-b + rm /etc/systemd/system/test15-b1.service + clear_services test15-a test15-b # Check that dependencies don't vary. echo "*** test 2" - create_services a x y - mkdir -p /etc/systemd/system/a1.service.wants/ - ln -sf a.service /etc/systemd/system/a1.service - ln -sf ../x.service /etc/systemd/system/a.service.wants/ - ln -sf ../y.service /etc/systemd/system/a1.service.wants/ - check_ok a1 Wants x.service # see [1] - check_ok a1 Wants y.service - systemctl start a - check_ok a1 Wants x.service # see [2] - check_ok a1 Wants y.service - systemctl stop a x y - rm /etc/systemd/system/a1.service + create_services test15-a test15-x test15-y + mkdir -p /etc/systemd/system/test15-a1.service.wants/ + ln -sf test15-a.service /etc/systemd/system/test15-a1.service + ln -sf ../test15-x.service /etc/systemd/system/test15-a.service.wants/ + ln -sf ../test15-y.service /etc/systemd/system/test15-a1.service.wants/ + check_ok test15-a1 Wants test15-x.service # see [1] + check_ok test15-a1 Wants test15-y.service + systemctl start test15-a + check_ok test15-a1 Wants test15-x.service # see [2] + check_ok test15-a1 Wants test15-y.service + systemctl stop test15-a test15-x test15-y + rm /etc/systemd/system/test15-a1.service - clear_services a x y + clear_services test15-a test15-x test15-y } test_masked_dropins () { echo "Testing masked dropins..." - create_services a b + create_services test15-a test15-b # 'b' is masked for both deps echo "*** test a wants,requires b is masked" - ln -sf /dev/null /etc/systemd/system/a.service.wants/b.service - ln -sf /dev/null /etc/systemd/system/a.service.requires/b.service - check_ko a Wants b.service - check_ko a Requires b.service + ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service + ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service + check_ko test15-a Wants test15-b.service + check_ko test15-a Requires test15-b.service # 'a' wants 'b' and 'b' is masked at a lower level echo "*** test a wants b, mask override" - ln -sf ../b.service /etc/systemd/system/a.service.wants/b.service - ln -sf /dev/null /usr/lib/systemd/system/a.service.wants/b.service - check_ok a Wants b.service + ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.wants/test15-b.service + ln -sf /dev/null /usr/lib/systemd/system/test15-a.service.wants/test15-b.service + check_ok test15-a Wants test15-b.service # 'a' wants 'b' and 'b' is masked at a higher level echo "*** test a wants b, mask" - ln -sf /dev/null /etc/systemd/system/a.service.wants/b.service - ln -sf ../b.service /usr/lib/systemd/system/a.service.wants/b.service - check_ko a Wants b.service + ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service + ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service + check_ko test15-a Wants test15-b.service # 'a' is masked but has an override config file echo "*** test a is masked but has an override" - create_services a b - ln -sf /dev/null /etc/systemd/system/a.service - cat >/usr/lib/systemd/system/a.service.d/override.conf </usr/lib/systemd/system/test15-a.service.d/override.conf </usr/lib/systemd/system/a.service.d/wants-b.conf</usr/lib/systemd/system/test15-a.service.d/wants-b.conf<> "${TL}" + journalctl -u ${service/_/-}.service >> "${TL}" fi } diff --git a/test/units/testsuite-17.service b/test/units/testsuite-17.service new file mode 100644 index 0000000000..ed2017a848 --- /dev/null +++ b/test/units/testsuite-17.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-17-UDEV-WANTS + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-17-UDEV-WANTS/testsuite.sh b/test/units/testsuite-17.sh similarity index 99% rename from test/TEST-17-UDEV-WANTS/testsuite.sh rename to test/units/testsuite-17.sh index 989c190ce3..7f8740ba35 100755 --- a/test/TEST-17-UDEV-WANTS/testsuite.sh +++ b/test/units/testsuite-17.sh @@ -69,6 +69,6 @@ while : ; do sleep .5 done -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-18.service b/test/units/testsuite-18.service new file mode 100644 index 0000000000..e4a945dc3e --- /dev/null +++ b/test/units/testsuite-18.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-18-FAILUREACTION + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-18-FAILUREACTION/testsuite.sh b/test/units/testsuite-18.sh similarity index 100% rename from test/TEST-18-FAILUREACTION/testsuite.sh rename to test/units/testsuite-18.sh diff --git a/test/units/testsuite-19.service b/test/units/testsuite-19.service new file mode 100644 index 0000000000..d6ad5beded --- /dev/null +++ b/test/units/testsuite-19.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-19-DELEGATE + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-19-DELEGATE/testsuite.sh b/test/units/testsuite-19.sh similarity index 100% rename from test/TEST-19-DELEGATE/testsuite.sh rename to test/units/testsuite-19.sh diff --git a/test/units/testsuite-20.service b/test/units/testsuite-20.service new file mode 100644 index 0000000000..d31d531175 --- /dev/null +++ b/test/units/testsuite-20.service @@ -0,0 +1,10 @@ +[Unit] +Description=TEST-20-MAINPIDGAMES +Before=getty-pre.target +Wants=getty-pre.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot +NotifyAccess=all diff --git a/test/TEST-20-MAINPIDGAMES/testsuite.sh b/test/units/testsuite-20.sh similarity index 56% rename from test/TEST-20-MAINPIDGAMES/testsuite.sh rename to test/units/testsuite-20.sh index f894026070..c038c05fa7 100755 --- a/test/TEST-20-MAINPIDGAMES/testsuite.sh +++ b/test/units/testsuite-20.sh @@ -5,7 +5,7 @@ set -o pipefail systemd-analyze log-level debug systemd-analyze log-target console -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ # Start a test process inside of our own cgroup sleep infinity & @@ -13,48 +13,48 @@ INTERNALPID=$! disown # Start a test process outside of our own cgroup -systemd-run -p DynamicUser=1 --unit=sleep.service /bin/sleep infinity -EXTERNALPID=`systemctl show -p MainPID --value sleep.service` +systemd-run -p DynamicUser=1 --unit=test20-sleep.service /bin/sleep infinity +EXTERNALPID=`systemctl show -p MainPID --value test20-sleep.service` # Update our own main PID to the external test PID, this should work systemd-notify MAINPID=$EXTERNALPID -test `systemctl show -p MainPID --value testsuite.service` -eq $EXTERNALPID +test `systemctl show -p MainPID --value testsuite-20.service` -eq $EXTERNALPID # Update our own main PID to the internal test PID, this should work, too systemd-notify MAINPID=$INTERNALPID -test `systemctl show -p MainPID --value testsuite.service` -eq $INTERNALPID +test `systemctl show -p MainPID --value testsuite-20.service` -eq $INTERNALPID # Update it back to our own PID, this should also work systemd-notify MAINPID=$$ -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ # Try to set it to PID 1, which it should ignore, because that's the manager systemd-notify MAINPID=1 -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ # Try to set it to PID 0, which is invalid and should be ignored systemd-notify MAINPID=0 -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ # Try to set it to a valid but non-existing PID, which should be ignored. (Note # that we set the PID to a value well above any known /proc/sys/kernel/pid_max, # which means we can be pretty sure it doesn't exist by coincidence) systemd-notify MAINPID=1073741824 -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ # Change it again to the external PID, without privileges this time. This should be ignored, because the PID is from outside of our cgroup and we lack privileges. systemd-notify --uid=1000 MAINPID=$EXTERNALPID -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ # Change it again to the internal PID, without privileges this time. This should work, as the process is on our cgroup, and that's enough even if we lack privileges. systemd-notify --uid=1000 MAINPID=$INTERNALPID -test `systemctl show -p MainPID --value testsuite.service` -eq $INTERNALPID +test `systemctl show -p MainPID --value testsuite-20.service` -eq $INTERNALPID # Update it back to our own PID, this should also work systemd-notify --uid=1000 MAINPID=$$ -test `systemctl show -p MainPID --value testsuite.service` -eq $$ +test `systemctl show -p MainPID --value testsuite-20.service` -eq $$ -cat >/tmp/mainpid.sh </tmp/test20-mainpid.sh < /run/mainpidsh/pid EOF -chmod +x /tmp/mainpid.sh +chmod +x /tmp/test20-mainpid.sh -systemd-run --unit=mainpidsh.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh -p PIDFile=/run/mainpidsh/pid /tmp/mainpid.sh -test `systemctl show -p MainPID --value mainpidsh.service` -eq `cat /run/mainpidsh/pid` +systemd-run --unit=test20-mainpidsh.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh -p PIDFile=/run/mainpidsh/pid /tmp/test20-mainpid.sh +test `systemctl show -p MainPID --value test20-mainpidsh.service` -eq `cat /run/mainpidsh/pid` -cat >/tmp/mainpid2.sh </tmp/test20-mainpid2.sh < /run/mainpidsh2/pid chown 1001:1001 /run/mainpidsh2/pid EOF -chmod +x /tmp/mainpid2.sh +chmod +x /tmp/test20-mainpid2.sh -systemd-run --unit=mainpidsh2.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh2 -p PIDFile=/run/mainpidsh2/pid /tmp/mainpid2.sh -test `systemctl show -p MainPID --value mainpidsh2.service` -eq `cat /run/mainpidsh2/pid` +systemd-run --unit=test20-mainpidsh2.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh2 -p PIDFile=/run/mainpidsh2/pid /tmp/test20-mainpid2.sh +test `systemctl show -p MainPID --value test20-mainpidsh2.service` -eq `cat /run/mainpidsh2/pid` -cat >/dev/shm/mainpid3.sh </dev/shm/test20-mainpid3.sh </failed -for t in test-*.sh; do - echo "Running $t"; ./$t +for t in ${0%.sh}.*.sh; do + echo "Running $t"; ./$t done touch /testok diff --git a/test/units/testsuite-23.service b/test/units/testsuite-23.service new file mode 100644 index 0000000000..b3b3297af8 --- /dev/null +++ b/test/units/testsuite-23.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-23-TYPE-EXEC + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-23-TYPE-EXEC/testsuite.sh b/test/units/testsuite-23.sh similarity index 100% rename from test/TEST-23-TYPE-EXEC/testsuite.sh rename to test/units/testsuite-23.sh diff --git a/test/units/testsuite-24.service b/test/units/testsuite-24.service new file mode 100644 index 0000000000..43d4816d48 --- /dev/null +++ b/test/units/testsuite-24.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-24-UNIT-TESTS + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-24-UNIT-TESTS/testsuite.sh b/test/units/testsuite-24.sh similarity index 90% rename from test/TEST-24-UNIT-TESTS/testsuite.sh rename to test/units/testsuite-24.sh index cc78adbbe9..1ff1c3347b 100755 --- a/test/TEST-24-UNIT-TESTS/testsuite.sh +++ b/test/units/testsuite-24.sh @@ -6,6 +6,9 @@ NPROC=$(nproc) MAX_QUEUE_SIZE=${NPROC:-2} IFS=$'\n' TEST_LIST=($(ls /usr/lib/systemd/tests/test-*)) +# reset state +rm /failed-tests /skipped-tests /skipped + # Check & report test results # Arguments: # $1: test path @@ -21,23 +24,23 @@ function report_result() { if [[ $ret -ne 0 && $ret != 77 ]]; then echo "$name failed with $ret" - echo "$name" >> /failed-tests + echo "$name" >>/failed-tests { echo "--- $name begin ---" cat "/$name.log" echo "--- $name end ---" - } >> /failed + } >>/failed elif [[ $ret == 77 ]]; then echo "$name skipped" - echo "$name" >> /skipped-tests + echo "$name" >>/skipped-tests { echo "--- $name begin ---" cat "/$name.log" echo "--- $name end ---" - } >> /skipped + } >>/skipped else echo "$name OK" - echo "$name" >> /testok + echo "$name" >>/testok fi systemd-cat echo "--- $name ---" @@ -69,7 +72,7 @@ for task in "${TEST_LIST[@]}"; do if [[ -x $task ]]; then log_file="/${task##*/}.log" - $task &> "$log_file" & + $task &>"$log_file" & running[$task]=$! fi done diff --git a/test/units/testsuite-25.service b/test/units/testsuite-25.service new file mode 100644 index 0000000000..45d8b6945f --- /dev/null +++ b/test/units/testsuite-25.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-25-IMPORT + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-25-IMPORT/testsuite.sh b/test/units/testsuite-25.sh similarity index 97% rename from test/TEST-25-IMPORT/testsuite.sh rename to test/units/testsuite-25.sh index 6dcb780508..2558d5bf4c 100755 --- a/test/TEST-25-IMPORT/testsuite.sh +++ b/test/units/testsuite-25.sh @@ -133,6 +133,11 @@ rm -rf /var/tmp/extract rm -rf /var/tmp/scratch +# Test removal +machinectl remove scratch5 +! test -f /var/lib/machines/scratch5 +! machinectl image-status scratch5 + echo OK > /testok exit 0 diff --git a/test/units/testsuite-26.service b/test/units/testsuite-26.service new file mode 100644 index 0000000000..65b66835ed --- /dev/null +++ b/test/units/testsuite-26.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-26-SETENV + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-26-SETENV/testsuite.sh b/test/units/testsuite-26.sh similarity index 100% rename from test/TEST-26-SETENV/testsuite.sh rename to test/units/testsuite-26.sh diff --git a/test/units/testsuite-27.service b/test/units/testsuite-27.service new file mode 100644 index 0000000000..52185f0572 --- /dev/null +++ b/test/units/testsuite-27.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-27-STDOUTFILE + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-27-STDOUTFILE/testsuite.sh b/test/units/testsuite-27.sh similarity index 85% rename from test/TEST-27-STDOUTFILE/testsuite.sh rename to test/units/testsuite-27.sh index c522f75dbc..9d92e6e574 100755 --- a/test/TEST-27-STDOUTFILE/testsuite.sh +++ b/test/units/testsuite-27.sh @@ -5,7 +5,7 @@ set -o pipefail systemd-analyze log-level debug systemd-analyze log-target console -systemd-run --wait --unit=one \ +systemd-run --wait --unit=test27-one \ -p StandardOutput=file:/tmp/stdout \ -p StandardError=file:/tmp/stderr \ -p Type=exec \ @@ -17,7 +17,7 @@ cmp /tmp/stderr < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-28.service b/test/units/testsuite-28.service new file mode 100644 index 0000000000..7ea8630011 --- /dev/null +++ b/test/units/testsuite-28.service @@ -0,0 +1,11 @@ +[Unit] +Description=TEST-28-PERCENTJ-WANTEDBY +# Testsuite: Ensure %j Wants directives work +Wants=specifier-j-wants.service +After=specifier-j-wants.service +Requires=testsuite-28-pre.service +After=testsuite-28-pre.service + +[Service] +ExecStart=true +Type=oneshot diff --git a/test/units/testsuite-29.service b/test/units/testsuite-29.service new file mode 100644 index 0000000000..90c2187bd7 --- /dev/null +++ b/test/units/testsuite-29.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-29-UDEV-ID_RENAMING + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-29-UDEV-ID_RENAMING/testsuite.sh b/test/units/testsuite-29.sh similarity index 100% rename from test/TEST-29-UDEV-ID_RENAMING/testsuite.sh rename to test/units/testsuite-29.sh diff --git a/test/units/testsuite-30.service b/test/units/testsuite-30.service new file mode 100644 index 0000000000..eb342f3d17 --- /dev/null +++ b/test/units/testsuite-30.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-30-ONCLOCKCHANGE + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-30-ONCLOCKCHANGE/testsuite.sh b/test/units/testsuite-30.sh similarity index 100% rename from test/TEST-30-ONCLOCKCHANGE/testsuite.sh rename to test/units/testsuite-30.sh diff --git a/test/units/testsuite-31.service b/test/units/testsuite-31.service new file mode 100644 index 0000000000..07dfb0bb54 --- /dev/null +++ b/test/units/testsuite-31.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-31-DEVICE-ENUMERATION + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-31-DEVICE-ENUMERATION/testsuite.sh b/test/units/testsuite-31.sh similarity index 100% rename from test/TEST-31-DEVICE-ENUMERATION/testsuite.sh rename to test/units/testsuite-31.sh diff --git a/test/units/testsuite-32.service b/test/units/testsuite-32.service new file mode 100644 index 0000000000..aab95cb741 --- /dev/null +++ b/test/units/testsuite-32.service @@ -0,0 +1,8 @@ +[Unit] +Description=TEST-32-OOMPOLICY + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot +MemoryAccounting=yes diff --git a/test/TEST-32-OOMPOLICY/testsuite.sh b/test/units/testsuite-32.sh similarity index 72% rename from test/TEST-32-OOMPOLICY/testsuite.sh rename to test/units/testsuite-32.sh index aafafc1183..6b899652e2 100755 --- a/test/TEST-32-OOMPOLICY/testsuite.sh +++ b/test/units/testsuite-32.sh @@ -8,17 +8,19 @@ set -o pipefail # an easier thing to test for, and also: let's not get confused by older # kernels where the concept was still new. -if test -f /sys/fs/cgroup/system.slice/testsuite.service/memory.oom.group ; then +if test -f /sys/fs/cgroup/system.slice/testsuite-32.service/memory.oom.group; then systemd-analyze log-level debug systemd-analyze log-target console # Run a service that is guaranteed to be the first candidate for OOM killing - systemd-run --unit=oomtest.service -p Type=exec -p OOMScoreAdjust=1000 -p OOMPolicy=stop -p MemoryAccounting=yes /bin/sleep infinity + systemd-run --unit=oomtest.service \ + -p Type=exec -p OOMScoreAdjust=1000 -p OOMPolicy=stop -p MemoryAccounting=yes \ + sleep infinity # Trigger an OOM killer run - echo 1 > /proc/sys/kernel/sysrq - echo f > /proc/sysrq-trigger + echo 1 >/proc/sys/kernel/sysrq + echo f >/proc/sysrq-trigger while : ; do STATE=`systemctl show -p ActiveState --value oomtest.service` @@ -32,6 +34,6 @@ if test -f /sys/fs/cgroup/system.slice/testsuite.service/memory.oom.group ; then systemd-analyze log-level info fi -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-33.service b/test/units/testsuite-33.service new file mode 100644 index 0000000000..b64f1e0b79 --- /dev/null +++ b/test/units/testsuite-33.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-33-CLEAN-UNIT + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-33-CLEAN-UNIT/testsuite.sh b/test/units/testsuite-33.sh similarity index 100% rename from test/TEST-33-CLEAN-UNIT/testsuite.sh rename to test/units/testsuite-33.sh diff --git a/test/units/testsuite-34.service b/test/units/testsuite-34.service new file mode 100644 index 0000000000..361e328221 --- /dev/null +++ b/test/units/testsuite-34.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-34-DYNAMICUSERMIGRATE + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-34-DYNAMICUSERMIGRATE/testsuite.sh b/test/units/testsuite-34.sh similarity index 100% rename from test/TEST-34-DYNAMICUSERMIGRATE/testsuite.sh rename to test/units/testsuite-34.sh diff --git a/test/units/testsuite-36.service b/test/units/testsuite-36.service new file mode 100644 index 0000000000..a681153ee4 --- /dev/null +++ b/test/units/testsuite-36.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-36-NUMAPOLICY + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/units/testsuite-36.sh similarity index 99% rename from test/TEST-36-NUMAPOLICY/testsuite.sh rename to test/units/testsuite-36.sh index bd04bb2efe..d04751b3f0 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/units/testsuite-36.sh @@ -22,7 +22,7 @@ journalLog='journal.log' # Systemd config files testUnit='numa-test.service' -testUnitFile="/etc/systemd/system/$testUnit" +testUnitFile="/run/systemd/system/$testUnit" testUnitNUMAConf="$testUnitFile.d/numa.conf" # Sleep constants (we should probably figure out something better but nothing comes to mind) @@ -70,9 +70,9 @@ writePID1NUMAPolicy() { } writeTestUnit() { + mkdir -p $testUnitFile.d/ echo [Service] > $testUnitFile echo ExecStart=/bin/sleep 3600 >> $testUnitFile - mkdir -p $testUnitFile.d/ } writeTestUnitNUMAPolicy() { @@ -129,7 +129,7 @@ systemctlCheckNUMAProperties() { writeTestUnit # Create systemd config drop-in directory -confDir="/etc/systemd/system.conf.d/" +confDir="/run/systemd/system.conf.d/" mkdir -p "$confDir" if ! checkNUMA; then diff --git a/test/units/testsuite-37.service b/test/units/testsuite-37.service new file mode 100644 index 0000000000..d25c6d2cf9 --- /dev/null +++ b/test/units/testsuite-37.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-37-RUNTIMEDIRECTORYPRESERVE + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-37-RUNTIMEDIRECTORYPRESERVE/testsuite.sh b/test/units/testsuite-37.sh similarity index 100% rename from test/TEST-37-RUNTIMEDIRECTORYPRESERVE/testsuite.sh rename to test/units/testsuite-37.sh diff --git a/test/units/testsuite-39.service b/test/units/testsuite-39.service new file mode 100644 index 0000000000..395fe803e7 --- /dev/null +++ b/test/units/testsuite-39.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-39-EXECRELOAD + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-39-EXECRELOAD/testsuite.sh b/test/units/testsuite-39.sh old mode 100644 new mode 100755 similarity index 100% rename from test/TEST-39-EXECRELOAD/testsuite.sh rename to test/units/testsuite-39.sh diff --git a/test/units/testsuite-40.service b/test/units/testsuite-40.service new file mode 100644 index 0000000000..38b0bd80d1 --- /dev/null +++ b/test/units/testsuite-40.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-40-EXEC-COMMAND-EX + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-40-EXEC-COMMAND-EX/testsuite.sh b/test/units/testsuite-40.sh similarity index 100% rename from test/TEST-40-EXEC-COMMAND-EX/testsuite.sh rename to test/units/testsuite-40.sh diff --git a/test/units/testsuite-41.service b/test/units/testsuite-41.service new file mode 100644 index 0000000000..766cb4c99a --- /dev/null +++ b/test/units/testsuite-41.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-41-ONESHOT-RESTART + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-41-ONESHOT-RESTART/testsuite.sh b/test/units/testsuite-41.sh similarity index 95% rename from test/TEST-41-ONESHOT-RESTART/testsuite.sh rename to test/units/testsuite-41.sh index 905f32e994..e3c5f1dad6 100755 --- a/test/TEST-41-ONESHOT-RESTART/testsuite.sh +++ b/test/units/testsuite-41.sh @@ -19,9 +19,9 @@ if [[ "$(systemctl show one.service -p NRestarts --value)" -le 0 ]]; then exit 1 fi -TMP_FILE="/test-41-oneshot-restart-test" +TMP_FILE="/tmp/test-41-oneshot-restart-test" -touch $TMP_FILE +: >$TMP_FILE # test two: make sure StartLimitBurst correctly limits the number of restarts # and restarts execution of the unit from the first ExecStart= diff --git a/test/units/testsuite-42.service b/test/units/testsuite-42.service new file mode 100644 index 0000000000..a5504b515d --- /dev/null +++ b/test/units/testsuite-42.service @@ -0,0 +1,9 @@ +[Unit] +Description=TEST-42-EXECSTOPPOST +Before=getty-pre.target +Wants=getty-pre.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-42-EXECSTOPPOST/testsuite.sh b/test/units/testsuite-42.sh similarity index 100% rename from test/TEST-42-EXECSTOPPOST/testsuite.sh rename to test/units/testsuite-42.sh diff --git a/test/units/testsuite-43.service b/test/units/testsuite-43.service new file mode 100644 index 0000000000..31248f17e8 --- /dev/null +++ b/test/units/testsuite-43.service @@ -0,0 +1,9 @@ +[Unit] +Description=TEST-43-PRIVATEUSER-UNPRIV +After=systemd-logind.service user@4711.service +Wants=user@4711.service + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-43-PRIVATEUSER-UNPRIV/testsuite.sh b/test/units/testsuite-43.sh similarity index 100% rename from test/TEST-43-PRIVATEUSER-UNPRIV/testsuite.sh rename to test/units/testsuite-43.sh diff --git a/test/units/testsuite-44.service b/test/units/testsuite-44.service new file mode 100644 index 0000000000..bd4dd728aa --- /dev/null +++ b/test/units/testsuite-44.service @@ -0,0 +1,12 @@ +[Unit] +Description=TESTSUITE-44-LOG-NAMESPACE +Before=getty-pre.target +Wants=getty-pre.target +Wants=systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket +After=systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot +LogTarget=foobar diff --git a/test/TEST-44-LOG-NAMESPACE/testsuite.sh b/test/units/testsuite-44.sh similarity index 100% rename from test/TEST-44-LOG-NAMESPACE/testsuite.sh rename to test/units/testsuite-44.sh diff --git a/test/units/testsuite-46.service b/test/units/testsuite-46.service new file mode 100644 index 0000000000..da359cbb23 --- /dev/null +++ b/test/units/testsuite-46.service @@ -0,0 +1,10 @@ +[Unit] +Description=TEST-46-HOMED +Before=getty-pre.target +Wants=getty-pre.target + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot +NotifyAccess=all diff --git a/test/TEST-46-HOMED/testsuite.sh b/test/units/testsuite-46.sh similarity index 100% rename from test/TEST-46-HOMED/testsuite.sh rename to test/units/testsuite-46.sh diff --git a/test/units/testsuite-47-repro.service b/test/units/testsuite-47-repro.service new file mode 100644 index 0000000000..655eea68e5 --- /dev/null +++ b/test/units/testsuite-47-repro.service @@ -0,0 +1,7 @@ +[Unit] +Description=Issue 14566 Repro + +[Service] +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +ExecStopPost=/bin/true +KillMode=mixed diff --git a/test/TEST-47-ISSUE-14566/repro.sh b/test/units/testsuite-47-repro.sh similarity index 71% rename from test/TEST-47-ISSUE-14566/repro.sh rename to test/units/testsuite-47-repro.sh index 5217602257..8c34289c52 100755 --- a/test/TEST-47-ISSUE-14566/repro.sh +++ b/test/units/testsuite-47-repro.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash sleep infinity & echo $! > /leakedtestpid diff --git a/test/units/testsuite-47.service b/test/units/testsuite-47.service new file mode 100644 index 0000000000..3816c57eed --- /dev/null +++ b/test/units/testsuite-47.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-47-ISSUE-14566 + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/TEST-47-ISSUE-14566/testsuite.sh b/test/units/testsuite-47.sh similarity index 71% rename from test/TEST-47-ISSUE-14566/testsuite.sh rename to test/units/testsuite-47.sh index a0ba32530e..09be780a68 100755 --- a/test/TEST-47-ISSUE-14566/testsuite.sh +++ b/test/units/testsuite-47.sh @@ -1,17 +1,17 @@ -#!/bin/bash +#!/usr/bin/env bash set -ex set -o pipefail systemd-analyze log-level debug systemd-analyze log-target console -systemctl start issue_14566_test +systemctl start testsuite-47-repro sleep 1 -systemctl status issue_14566_test +systemctl status testsuite-47-repro leaked_pid=$(cat /leakedtestpid) -systemctl stop issue_14566_test +systemctl stop testsuite-47-repro # Leaked PID will still be around if we're buggy. # I personally prefer to see 42. diff --git a/test/testsuite.target b/test/units/testsuite.target similarity index 100% rename from test/testsuite.target rename to test/units/testsuite.target diff --git a/test/units/timers.target b/test/units/timers.target new file mode 100644 index 0000000000..b1aa8c797c --- /dev/null +++ b/test/units/timers.target @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# 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. + +[Unit] +Description=Timers +Documentation=man:systemd.special(7) + +DefaultDependencies=no +Conflicts=shutdown.target diff --git a/test/unit-.service.d/10-override.conf b/test/units/unit-.service.d/10-override.conf similarity index 100% rename from test/unit-.service.d/10-override.conf rename to test/units/unit-.service.d/10-override.conf diff --git a/test/unit-with-.service.d/20-override.conf b/test/units/unit-with-.service.d/20-override.conf similarity index 100% rename from test/unit-with-.service.d/20-override.conf rename to test/units/unit-with-.service.d/20-override.conf diff --git a/test/unit-with-multiple-.service.d/20-override.conf b/test/units/unit-with-multiple-.service.d/20-override.conf similarity index 100% rename from test/unit-with-multiple-.service.d/20-override.conf rename to test/units/unit-with-multiple-.service.d/20-override.conf diff --git a/test/unit-with-multiple-.service.d/30-override.conf b/test/units/unit-with-multiple-.service.d/30-override.conf similarity index 100% rename from test/unit-with-multiple-.service.d/30-override.conf rename to test/units/unit-with-multiple-.service.d/30-override.conf diff --git a/test/unit-with-multiple-dashes.service b/test/units/unit-with-multiple-dashes.service similarity index 100% rename from test/unit-with-multiple-dashes.service rename to test/units/unit-with-multiple-dashes.service diff --git a/test/unit-with-multiple-dashes.service.d/10-override.conf b/test/units/unit-with-multiple-dashes.service.d/10-override.conf similarity index 100% rename from test/unit-with-multiple-dashes.service.d/10-override.conf rename to test/units/unit-with-multiple-dashes.service.d/10-override.conf diff --git a/test/unstoppable.service b/test/units/unstoppable.service similarity index 100% rename from test/unstoppable.service rename to test/units/unstoppable.service diff --git a/tools/meson-make-symlink.sh b/tools/meson-make-symlink.sh index da0d13a341..cdd5214125 100755 --- a/tools/meson-make-symlink.sh +++ b/tools/meson-make-symlink.sh @@ -5,8 +5,8 @@ set -eu # and we need to create the target directory... mkdir -vp "$(dirname "${DESTDIR:-}$2")" -if [ "$(dirname $1)" = . ]; then - ln -vfs -T "$1" "${DESTDIR:-}$2" +if [ "$(dirname $1)" = . -o "$(dirname $1)" = .. ]; then + ln -vfs -T -- "$1" "${DESTDIR:-}$2" else - ln -vfs -T --relative "${DESTDIR:-}$1" "${DESTDIR:-}$2" + ln -vfs -T --relative -- "${DESTDIR:-}$1" "${DESTDIR:-}$2" fi