From 0643001c2838d244a8698ea782414115034804bc Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 7 Apr 2022 12:33:25 +0200 Subject: test-nspawn-util: fix the test to actually find anything MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We would use a relative path, looking for globs like 'lib/systemd/libsystemd-shared-*.so' under the build directory, and never find anything. The test was supposed to find library in the current installation. But we cannot assume that the right library is installed, so the test only printed the result for manual inspection. Thus nobody noticed when it broke. I think it broke in c6134d3e2f1d1d17b32b6e06556cd0c5429bc78a, path-util: get rid of prefix_root(). But that commit doesn't compile because of changes in meson, so this is just a guess. Before: /* test_systemd_installation_has_version */ Current installation has systemd >= 0: no Current installation has systemd >= 231: no Current installation has systemd >= 249: no Current installation has systemd >= 999: no With the fix: $ build/test-nspawn-util /* test_systemd_installation_has_version */ Found libsystemd shared at "/lib/systemd/libsystemd-shared-245.so.so", version 245 (OK). Current installation has systemd >= 0: yes Found libsystemd shared at "/lib/systemd/libsystemd-shared-245.so.so", version 245 (OK). Current installation has systemd >= 231: yes Found libsystemd shared at "/lib/systemd/libsystemd-shared-245.so.so", version 245 (too old). Found libsystemd shared at "/lib/systemd/libsystemd-shared-251.so.so", version 251 (OK). Current installation has systemd >= 251: yes Found libsystemd shared at "/lib/systemd/libsystemd-shared-245.so.so", version 245 (too old). Found libsystemd shared at "/lib/systemd/libsystemd-shared-251.so.so", version 251 (too old). Found libsystemd shared at "/lib/systemd/libsystemd-shared-250.so.so", version 250 (too old). Found libsystemd shared at "/usr/lib/systemd/libsystemd-shared-245.so.so", version 245 (too old). Found libsystemd shared at "/usr/lib/systemd/libsystemd-shared-251.so.so", version 251 (too old). Found libsystemd shared at "/usr/lib/systemd/libsystemd-shared-250.so.so", version 250 (too old). Current installation has systemd >= 999: no $ build/test-nspawn-util /var/lib/machines/rawhide /* test_systemd_installation_has_version */ /* test_systemd_installation_has_version */ Found libsystemd shared at "/var/lib/machines/rawhide/lib/systemd/libsystemd-shared-251-rc1-1.fc37.so.so", version 251 (OK). /var/lib/machines/rawhide has systemd >= 0: yes Found libsystemd shared at "/var/lib/machines/rawhide/lib/systemd/libsystemd-shared-251-rc1-1.fc37.so.so", version 251 (OK). /var/lib/machines/rawhide has systemd >= 231: yes Found libsystemd shared at "/var/lib/machines/rawhide/lib/systemd/libsystemd-shared-251-rc1-1.fc37.so.so", version 251 (OK). /var/lib/machines/rawhide has systemd >= 251: yes Found libsystemd shared at "/var/lib/machines/rawhide/lib/systemd/libsystemd-shared-251-rc1-1.fc37.so.so", version 251 (too old). Found libsystemd shared at "/var/lib/machines/rawhide/usr/lib/systemd/libsystemd-shared-251-rc1-1.fc37.so.so", version 251 (too old). /var/lib/machines/rawhide has systemd >= 999: no While at it, NULSTR_FOREACH → FOREACH_STRING. --- src/nspawn/nspawn-util.c | 12 +++++------- src/nspawn/test-nspawn-util.c | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nspawn/nspawn-util.c b/src/nspawn/nspawn-util.c index 4b3bf2aa00..402554fa38 100644 --- a/src/nspawn/nspawn-util.c +++ b/src/nspawn/nspawn-util.c @@ -4,13 +4,11 @@ #include "glob-util.h" #include "log.h" #include "nspawn-util.h" -#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "string-util.h" int systemd_installation_has_version(const char *root, const char *minimal_version) { - const char *pattern; int r; /* Try to guess if systemd installation is later than the specified version. This @@ -18,15 +16,15 @@ int systemd_installation_has_version(const char *root, const char *minimal_versi * is non-standard. False positives should be relatively rare. */ - NULSTR_FOREACH(pattern, + FOREACH_STRING(pattern, /* /lib works for systems without usr-merge, and for systems with a sane * usr-merge, where /lib is a symlink to /usr/lib. /usr/lib is necessary * for Gentoo which does a merge without making /lib a symlink. */ - "lib/systemd/libsystemd-shared-*.so\0" - "lib64/systemd/libsystemd-shared-*.so\0" - "usr/lib/systemd/libsystemd-shared-*.so\0" - "usr/lib64/systemd/libsystemd-shared-*.so\0") { + "/lib/systemd/libsystemd-shared-*.so", + "/lib64/systemd/libsystemd-shared-*.so", + "/usr/lib/systemd/libsystemd-shared-*.so", + "/usr/lib64/systemd/libsystemd-shared-*.so") { _cleanup_strv_free_ char **names = NULL; _cleanup_free_ char *path = NULL; diff --git a/src/nspawn/test-nspawn-util.c b/src/nspawn/test-nspawn-util.c index ed68063630..08c8050dc5 100644 --- a/src/nspawn/test-nspawn-util.c +++ b/src/nspawn/test-nspawn-util.c @@ -16,4 +16,7 @@ TEST(systemd_installation_has_version) { } } +/* This program can be called with a path to an installation root. + * For example: build/test-nspawn-util /var/lib/machines/rawhide + */ DEFINE_TEST_MAIN(LOG_DEBUG); -- cgit v1.2.3