From: Daan De Meyer Date: Mon, 8 Apr 2024 17:56:36 +0000 (+0200) Subject: test: Various build environment fixes X-Git-Tag: v256-rc1~258 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae4088b23e1658a6f6e940d6e1c8d0a14f93449b;p=thirdparty%2Fsystemd.git test: Various build environment fixes All bets are off in build chroots, so let's handle more cases of files or executables that might not be available in build chroots. Specifically, these are all fixes to allow the unit tests to run in the opensuse build chroot. --- diff --git a/src/test/test-acl-util.c b/src/test/test-acl-util.c index 331faf1e4b3..3cb106a93f6 100644 --- a/src/test/test-acl-util.c +++ b/src/test/test-acl-util.c @@ -10,6 +10,7 @@ #include "fd-util.h" #include "format-util.h" #include "fs-util.h" +#include "path-util.h" #include "string-util.h" #include "tests.h" #include "tmpfile-util.h" @@ -22,6 +23,12 @@ TEST_RET(add_acls_for_user) { uid_t uid; int r; + FOREACH_STRING(s, "capsh", "getfacl", "ls") { + r = find_executable(s, NULL); + if (r < 0) + return log_tests_skipped_errno(r, "Could not find %s binary: %m", s); + } + fd = mkostemp_safe(fn); assert_se(fd >= 0); @@ -69,11 +76,18 @@ TEST_RET(add_acls_for_user) { return 0; } -TEST(fd_acl_make_read_only) { +TEST_RET(fd_acl_make_read_only) { _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-empty.XXXXXX"; _cleanup_close_ int fd = -EBADF; const char *cmd; struct stat st; + int r; + + FOREACH_STRING(s, "capsh", "getfacl", "ls", "stat") { + r = find_executable(s, NULL); + if (r < 0) + return log_tests_skipped_errno(r, "Could not find %s binary: %m", s); + } fd = mkostemp_safe(fn); assert_se(fd >= 0); @@ -125,6 +139,8 @@ TEST(fd_acl_make_read_only) { cmd = strjoina("stat ", fn); assert_se(system(cmd) == 0); + + return 0; } DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 111c001de6b..ea5d67ff483 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -290,7 +290,7 @@ TEST(copy_tree_at_symlink) { fd = safe_close(fd); } -TEST(copy_bytes) { +TEST_RET(copy_bytes) { _cleanup_close_pair_ int pipefd[2] = EBADF_PAIR; _cleanup_close_ int infd = -EBADF; int r, r2; @@ -299,7 +299,8 @@ TEST(copy_bytes) { infd = open("/usr/lib/os-release", O_RDONLY|O_CLOEXEC); if (infd < 0) infd = open("/etc/os-release", O_RDONLY|O_CLOEXEC); - assert_se(infd >= 0); + if (infd < 0) + return log_tests_skipped_errno(errno, "Could not open /usr/lib/os-release or /etc/os-release: %m"); assert_se(pipe2(pipefd, O_CLOEXEC) == 0); @@ -324,6 +325,8 @@ TEST(copy_bytes) { r = copy_bytes(pipefd[1], infd, 1, 0); assert_se(r == -EBADF); + + return 0; } static void test_copy_bytes_regular_file_one(const char *src, bool try_reflink, uint64_t max_bytes) { diff --git a/src/test/test-date.c b/src/test/test-date.c index 162ac342f50..2b96983e2cb 100644 --- a/src/test/test-date.c +++ b/src/test/test-date.c @@ -83,9 +83,11 @@ int main(int argc, char *argv[]) { test_one("today"); test_one("tomorrow"); test_one_noutc("16:20 UTC"); - test_one_noutc("16:20 Asia/Seoul"); - test_one_noutc("tomorrow Asia/Seoul"); - test_one_noutc("2012-12-30 18:42 Asia/Seoul"); + if (access("/usr/share/zoneinfo/Asia/Seoul", F_OK) >= 0) { + test_one_noutc("16:20 Asia/Seoul"); + test_one_noutc("tomorrow Asia/Seoul"); + test_one_noutc("2012-12-30 18:42 Asia/Seoul"); + } test_one_noutc("now"); test_one_noutc("+2d"); test_one_noutc("+2y 4d"); @@ -96,9 +98,11 @@ int main(int argc, char *argv[]) { test_should_fail("1969-12-31 UTC"); test_should_fail("-1000y"); test_should_fail("today UTC UTC"); - test_should_fail("now Asia/Seoul"); - test_should_fail("+2d Asia/Seoul"); - test_should_fail("@1395716396 Asia/Seoul"); + if (access("/usr/share/zoneinfo/Asia/Seoul", F_OK) >= 0) { + test_should_fail("now Asia/Seoul"); + test_should_fail("+2d Asia/Seoul"); + test_should_fail("@1395716396 Asia/Seoul"); + } #if SIZEOF_TIME_T == 8 test_should_pass("9999-12-30 23:59:59 UTC"); test_should_fail("9999-12-31 00:00:00 UTC"); diff --git a/src/test/test-os-util.c b/src/test/test-os-util.c index e51ab9d2908..e6838421709 100644 --- a/src/test/test-os-util.c +++ b/src/test/test-os-util.c @@ -20,10 +20,12 @@ TEST(path_is_os_tree) { } TEST(parse_os_release) { - /* Let's assume that we're running in a valid system, so os-release is available */ _cleanup_free_ char *id = NULL, *id2 = NULL, *name = NULL, *foobar = NULL; - ASSERT_EQ(parse_os_release(NULL, "ID", &id), 0); - log_info("ID: %s", id); + + if (access("/etc/os-release", F_OK) >= 0 || access("/usr/lib/os-release", F_OK) >= 0) { + ASSERT_EQ(parse_os_release(NULL, "ID", &id), 0); + log_info("ID: %s", id); + } ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1), 0); ASSERT_EQ(parse_os_release(NULL, "ID", &id2), 0); diff --git a/src/test/test-specifier.c b/src/test/test-specifier.c index d6a8b79aa4a..e50d4504360 100644 --- a/src/test/test-specifier.c +++ b/src/test/test-specifier.c @@ -138,6 +138,8 @@ TEST(specifiers) { xsprintf(spec, "%%%c", s->specifier); r = specifier_printf(spec, SIZE_MAX, specifier_table, NULL, NULL, &resolved); + if (s->specifier == 'A' && r == -EUNATCH) /* os-release might be missing in build chroots */ + continue; if (s->specifier == 'm' && IN_SET(r, -EUNATCH, -ENOMEDIUM, -ENOPKG)) /* machine-id might be missing in build chroots */ continue; assert_se(r >= 0);