mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 03:25:31 +03:00
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.)
This commit is contained in:
parent
d8d0da1f19
commit
51db8fdb92
@ -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);
|
||||
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 (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? */
|
||||
log_notice("Device %s cannot be resolved, skipping test", path);
|
||||
return;
|
||||
}
|
||||
|
||||
assert_se(r >= 0);
|
||||
assert_se(path_equal(path, resolved));
|
||||
|
Loading…
Reference in New Issue
Block a user