From: Zbigniew Jędrzejewski-Szmek Date: Thu, 10 Jun 2021 11:25:59 +0000 (+0200) Subject: test-stat-util: don't fail under chroot X-Git-Tag: v249-rc1~34^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51db8fdb9233555cf6d863cb3b2f51d3a6e7c0bc;p=thirdparty%2Fsystemd.git test-stat-util: don't fail under chroot I wanted to see what is_path_read_only_fs() and is_path_temporary_fs() return in a chroot, and various tests would fail. For most of our codebase, we can assume that /proc and such are mounted, and it doesn't make sense to make the tests work in a chroot. But let's do it here. (In general, it would be useful for most stuff in src/basic/, since it's linked into libraries which might be invoked in incorrectly set up environments and should not fail too badly.) --- diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index 9f94d66b022..fa167fb263b 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -63,8 +63,10 @@ static void test_path_is_fs_type(void) { assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0); assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0); } - assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0); - assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0); + if (path_is_mount_point("/proc", NULL, AT_SYMLINK_FOLLOW) > 0) { + assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0); + assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0); + } assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT); } @@ -117,7 +119,13 @@ static void test_fd_is_ns(void) { assert_se(fd_is_ns(STDERR_FILENO, CLONE_NEWNET) == 0); assert_se(fd_is_ns(STDOUT_FILENO, CLONE_NEWNET) == 0); - assert_se((fd = open("/proc/self/ns/mnt", O_CLOEXEC|O_RDONLY)) >= 0); + fd = open("/proc/self/ns/mnt", O_CLOEXEC|O_RDONLY); + if (fd < 0) { + assert_se(errno == ENOENT); + log_notice("Path %s not found, skipping test", "/proc/self/ns/mnt"); + return; + } + assert_se(fd >= 0); assert_se(IN_SET(fd_is_ns(fd, CLONE_NEWNET), 0, -EUCLEAN)); fd = safe_close(fd); @@ -175,11 +183,19 @@ static void test_device_path_make_canonical_one(const char *path) { log_debug("> %s", path); - assert_se(stat(path, &st) >= 0); + if (stat(path, &st) < 0) { + assert(errno == ENOENT); + log_notice("Path %s not found, skipping test", path); + return; + } + r = device_path_make_canonical(st.st_mode, st.st_rdev, &resolved); - if (r == -ENOENT) /* maybe /dev/char/x:y and /dev/block/x:y are missing in this test environment, because we - * run in a container or so? */ + if (r == -ENOENT) { + /* maybe /dev/char/x:y and /dev/block/x:y are missing in this test environment, because we + * run in a container or so? */ + log_notice("Device %s cannot be resolved, skipping test", path); return; + } assert_se(r >= 0); assert_se(path_equal(path, resolved));