From 26c2b30277f5a4c7656b732d2093000ffa895297 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Thu, 26 Jan 2023 16:07:17 +0100 Subject: [PATCH 1/5] test: install unit tests in a dedicated subdirectory below '$testsdir' /usr/lib/systemd/tests may contain more than the unit tests. For example on SUSE we also install the integration tests there. Putting the unit tests in a dedicated directory named 'unit-tests' makes the layout cleaner. Note that `run-unit-tests.py` has not been moved so we don't need to adjust (Fedora) packaging and users also don't need to descend into the subdirectory. --- meson.build | 11 ++++++----- test/meson.build | 8 ++++---- test/run-unit-tests.py | 2 +- test/test-functions | 5 ++--- test/units/testsuite-02.sh | 2 +- test/units/testsuite-35.sh | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index 6770deed4f..100bf54506 100644 --- a/meson.build +++ b/meson.build @@ -201,6 +201,7 @@ kernelinstalldir = kerneldir / 'install.d' factorydir = datadir / 'factory' bootlibdir = prefixdir / 'lib/systemd/boot/efi' testsdir = prefixdir / 'lib/systemd/tests' +unittestsdir = testsdir / 'unit-tests' systemdstatedir = localstatedir / 'lib/systemd' catalogstatedir = systemdstatedir / 'catalog' randomseeddir = localstatedir / 'lib/systemd' @@ -4330,7 +4331,7 @@ foreach test : tests build_by_default : want_tests != 'false', install_rpath : rootpkglibdir, install : install_tests, - install_dir : testsdir / type, + install_dir : unittestsdir / type, link_depends : runtest_env) if type == 'manual' @@ -4354,7 +4355,7 @@ exe = executable( dependencies : userspace, build_by_default : want_tests != 'false', install : install_tests, - install_dir : testsdir) + install_dir : unittestsdir) if want_tests != 'false' test('test-libsystemd-sym', exe) endif @@ -4372,7 +4373,7 @@ exe = executable( ], build_by_default : want_tests != 'false' and static_libsystemd_pic, install : install_tests and static_libsystemd_pic, - install_dir : testsdir) + install_dir : unittestsdir) if want_tests != 'false' and static_libsystemd_pic test('test-libsystemd-static-sym', exe) endif @@ -4386,7 +4387,7 @@ exe = executable( dependencies : userspace, build_by_default : want_tests != 'false', install : install_tests, - install_dir : testsdir) + install_dir : unittestsdir) if want_tests != 'false' test('test-libudev-sym', exe) endif @@ -4400,7 +4401,7 @@ exe = executable( dependencies : userspace, build_by_default : want_tests != 'false' and static_libudev_pic, install : install_tests and static_libudev_pic, - install_dir : testsdir) + install_dir : unittestsdir) if want_tests != 'false' and static_libudev_pic test('test-libudev-static-sym', exe) endif diff --git a/test/meson.build b/test/meson.build index 1721cffcd5..4bd7376c62 100644 --- a/test/meson.build +++ b/test/meson.build @@ -76,7 +76,7 @@ test_sysusers_sh = configure_file( configuration : conf) if install_tests and conf.get('ENABLE_SYSUSERS') == 1 install_data(test_sysusers_sh, - install_dir : testsdir) + install_dir : unittestsdir) install_subdir('test-sysusers', exclude_files : '.gitattributes', install_dir : testdata_dir) @@ -87,7 +87,7 @@ endif test_compare_versions_sh = files('test-compare-versions.sh') if install_tests install_data(test_compare_versions_sh, - install_dir : testsdir) + install_dir : unittestsdir) endif ############################################################ @@ -109,11 +109,11 @@ if install_tests install_data('test-fstab-generator.sh', install_mode : 'rwxr-xr-x', - install_dir : testsdir) + install_dir : unittestsdir) install_data('test-network-generator-conversion.sh', install_mode : 'rwxr-xr-x', - install_dir : testsdir) + install_dir : unittestsdir) endif ############################################################ diff --git a/test/run-unit-tests.py b/test/run-unit-tests.py index 4b180cc8df..2d6709b703 100755 --- a/test/run-unit-tests.py +++ b/test/run-unit-tests.py @@ -32,7 +32,7 @@ def argument_parser(): opts = argument_parser().parse_args() -unittestdir = pathlib.Path(__file__).parent.absolute() +unittestdir = pathlib.Path(__file__).parent.absolute() / 'unit-tests' tests = list(unittestdir.glob('test-*')) if opts.unsafe: diff --git a/test/test-functions b/test/test-functions index 820cb93e95..472ede1ba0 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1188,9 +1188,8 @@ install_suse_systemd() { # long as it runs an equivalent version of systemd) getting rid of the # hassles of fetching, configuring, building the source code. dinfo "Install the files needed by the tests at runtime" - image_install "${SOURCE_DIR}"/test-* inst_recursive "${SOURCE_DIR}/testdata" - inst_recursive "${SOURCE_DIR}/manual" + inst_recursive "${SOURCE_DIR}/unit-tests" # On openSUSE, this directory is not created at package install, at least # for now. @@ -1272,7 +1271,7 @@ get_ldpath() { install_missing_libraries() { dinfo "Install missing libraries" # install possible missing libraries - for i in "${initdir:?}"{,/usr}/{sbin,bin}/* "$initdir"{,/usr}/lib/systemd/{,tests/{,manual/,unsafe/}}*; do + for i in "${initdir:?}"{,/usr}/{sbin,bin}/* "$initdir"{,/usr}/lib/systemd/{,tests/unit-tests/{,manual/,unsafe/}}*; do LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$(get_ldpath "$i")" inst_libs "$i" done diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index 8ebcc575ee..61f6d06397 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -6,7 +6,7 @@ set -o pipefail NPROC=$(nproc) MAX_QUEUE_SIZE=${NPROC:-2} TESTS_GLOB=${TESTS_GLOB:-test-*} -mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/ -maxdepth 1 -type f -name "${TESTS_GLOB}") +mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/unit-tests/ -maxdepth 1 -type f -name "${TESTS_GLOB}") # reset state rm -fv /failed-tests /skipped-tests /skipped diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh index 02f22cf2a2..8dcd7563bb 100755 --- a/test/units/testsuite-35.sh +++ b/test/units/testsuite-35.sh @@ -517,7 +517,7 @@ test_session_properties() { create_session s=$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $1 }') - /usr/lib/systemd/tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}" + /usr/lib/systemd/tests/unit-tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}" } test_list_users() { From 539ee7ab11bed7925820e32194542bdccd7a1789 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Fri, 17 Mar 2023 14:14:16 +0100 Subject: [PATCH 2/5] meson: define testdata_dir globally --- meson.build | 3 ++- test/meson.build | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 100bf54506..0d175d2cee 100644 --- a/meson.build +++ b/meson.build @@ -202,6 +202,7 @@ factorydir = datadir / 'factory' bootlibdir = prefixdir / 'lib/systemd/boot/efi' testsdir = prefixdir / 'lib/systemd/tests' unittestsdir = testsdir / 'unit-tests' +testdata_dir = testsdir / 'testdata' systemdstatedir = localstatedir / 'lib/systemd' catalogstatedir = systemdstatedir / 'catalog' randomseeddir = localstatedir / 'lib/systemd' @@ -275,7 +276,7 @@ conf.set_quoted('SYSTEMD_LANGUAGE_FALLBACK_MAP', pkgdatadir / 'lang conf.set_quoted('SYSTEMD_MAKEFS_PATH', rootlibexecdir / 'systemd-makefs') conf.set_quoted('SYSTEMD_PULL_PATH', rootlibexecdir / 'systemd-pull') conf.set_quoted('SYSTEMD_SHUTDOWN_BINARY_PATH', rootlibexecdir / 'systemd-shutdown') -conf.set_quoted('SYSTEMD_TEST_DATA', testsdir / 'testdata') +conf.set_quoted('SYSTEMD_TEST_DATA', testdata_dir) conf.set_quoted('SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH', rootbindir / 'systemd-tty-ask-password-agent') conf.set_quoted('SYSTEMD_UPDATE_HELPER_PATH', rootlibexecdir / 'systemd-update-helper') conf.set_quoted('SYSTEMD_USERWORK_PATH', rootlibexecdir / 'systemd-userwork') diff --git a/test/meson.build b/test/meson.build index 4bd7376c62..a05b667208 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,8 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later if install_tests - testdata_dir = testsdir + '/testdata/' - foreach subdir : [ 'auxv', 'journal-data', From c18cc7f7fb83b42b12db04d0a1ed4466402ae85b Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Fri, 17 Mar 2023 14:18:50 +0100 Subject: [PATCH 3/5] meson: make sure the unit test scripts find testdata/ even if they are not installed in the same directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testdata/ is shared by both the unit tests and the integration tests. Hence it makes sense to place them right under /usr/lib/systemd/tests/ while the tests themself are located under dedicated sub-directories: /usr/lib/systemd/tests/ ├── integration-tests ├── testdata └── unit-tests ├── testdata -> ../testdata However the unit tests implemented as shell scripts (such as test-fstab-generator.sh) expect to find testdata/ where the scripts are installed, ie they do something like: src="$(dirname "$0")/testdata/test-fstab-generator" This patch installs a symlink in 'unitestsdir' named "testdata" and that points to whatever value 'testdata_dir' is set. --- test/meson.build | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/meson.build b/test/meson.build index a05b667208..80a83813cb 100644 --- a/test/meson.build +++ b/test/meson.build @@ -57,6 +57,12 @@ if install_tests install_data('create-busybox-container', install_mode : 'rwxr-xr-x', install_dir : testdata_dir) + + # The unit tests implemented as shell scripts expect to find testdata/ + # in the directory where they are stored. + meson.add_install_script(meson_make_symlink, + testdata_dir, + unittestsdir / 'testdata') endif test_bootctl_json_sh = find_program('test-bootctl-json.sh') From fa2745a3e1ddcf0160aa6f316ab629674574b8b4 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 20 Mar 2023 18:23:33 +0100 Subject: [PATCH 4/5] test: on openSUSE install the collection of unit test binaries in the target only for TEST-02-UNITTESTS --- test/TEST-02-UNITTESTS/test.sh | 7 +++++++ test/test-functions | 11 +---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/test/TEST-02-UNITTESTS/test.sh b/test/TEST-02-UNITTESTS/test.sh index 80cb82a50d..3d766db3e7 100755 --- a/test/TEST-02-UNITTESTS/test.sh +++ b/test/TEST-02-UNITTESTS/test.sh @@ -20,6 +20,13 @@ $KERNEL_APPEND # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" +test_append_files() { + if get_bool "$LOOKS_LIKE_SUSE"; then + dinfo "Install the unit test binaries needed by the TEST-02-UNITTESTS at runtime" + inst_recursive "${SOURCE_DIR}/unit-tests" + fi +} + check_result_nspawn() { check_result_nspawn_unittests "${1}" } diff --git a/test/test-functions b/test/test-functions index 472ede1ba0..fbb35a84ad 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1179,17 +1179,8 @@ install_suse_systemd() { done < <(rpm -ql "$p") done - # Embed the files needed by the extended testsuite at runtime. Also include - # the unit tests needed by TEST-02-UNITTESTS. This is mostly equivalent to - # what `ninja install` does for the tests when '-Dinstall-tests=true'. - # - # Why? openSUSE ships a package named 'systemd-testsuite' which contains - # the minimal set of files that allows to run the testsuite on the host (as - # long as it runs an equivalent version of systemd) getting rid of the - # hassles of fetching, configuring, building the source code. - dinfo "Install the files needed by the tests at runtime" + dinfo "Install the data needed by the tests at runtime" inst_recursive "${SOURCE_DIR}/testdata" - inst_recursive "${SOURCE_DIR}/unit-tests" # On openSUSE, this directory is not created at package install, at least # for now. From f8d527aa9a9c724199aeafab45714a94eea2caf3 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Fri, 24 Mar 2023 13:46:24 +0100 Subject: [PATCH 5/5] test: install symlinks with valid targets on SUSE and Debian --- test/test-functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-functions b/test/test-functions index fbb35a84ad..be87aaec2a 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1144,7 +1144,7 @@ install_debian_systemd() { ddebug "Install debian files from package $deb" for file in $files; do [ -e "$file" ] || continue - [ -d "$file" ] && continue + [ ! -L "$file" ] && [ -d "$file" ] && continue inst "$file" done done < <(grep -E '^Package:' "${SOURCE_DIR}/debian/control" | cut -d ':' -f 2) @@ -1174,7 +1174,7 @@ install_suse_systemd() { ddebug "Install files from package $p" while read -r f; do [ -e "$f" ] || continue - [ -d "$f" ] && continue + [ ! -L "$file" ] && [ -d "$file" ] && continue inst "$f" done < <(rpm -ql "$p") done