summaryrefslogtreecommitdiffstats
path: root/src/test/test-stat-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-stat-util.c')
-rw-r--r--src/test/test-stat-util.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c
index 8d7fd5b..6f274c9 100644
--- a/src/test/test-stat-util.c
+++ b/src/test/test-stat-util.c
@@ -3,6 +3,7 @@
#include <fcntl.h>
#include <linux/magic.h>
#include <sched.h>
+#include <sys/eventfd.h>
#include <unistd.h>
#include "alloc-util.h"
@@ -73,11 +74,11 @@ TEST(is_symlink) {
TEST(path_is_fs_type) {
/* run might not be a mount point in build chroots */
- if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
+ if (path_is_mount_point_full("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0);
assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0);
}
- if (path_is_mount_point("/proc", NULL, AT_SYMLINK_FOLLOW) > 0) {
+ if (path_is_mount_point_full("/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);
}
@@ -95,7 +96,7 @@ TEST(path_is_temporary_fs) {
}
/* run might not be a mount point in build chroots */
- if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
+ if (path_is_mount_point_full("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
assert_se(path_is_temporary_fs("/run") > 0);
assert_se(path_is_temporary_fs("/proc") == 0);
assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
@@ -111,7 +112,7 @@ TEST(path_is_read_only_fs) {
s, r, r < 0 ? errno_to_name(r) : yes_no(r));
}
- if (path_is_mount_point("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
+ if (path_is_mount_point_full("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
assert_se(IN_SET(path_is_read_only_fs("/sys"), 0, 1));
assert_se(path_is_read_only_fs("/proc") == 0);
@@ -180,6 +181,36 @@ TEST(dir_is_empty) {
assert_se(dir_is_empty_at(AT_FDCWD, empty_dir, /* ignore_hidden_or_backup= */ false) > 0);
}
+TEST(inode_type_from_string) {
+ static const mode_t types[] = {
+ S_IFREG,
+ S_IFDIR,
+ S_IFLNK,
+ S_IFCHR,
+ S_IFBLK,
+ S_IFIFO,
+ S_IFSOCK,
+ };
+
+ FOREACH_ELEMENT(m, types)
+ assert_se(inode_type_from_string(inode_type_to_string(*m)) == *m);
+}
+
+TEST(anonymous_inode) {
+ _cleanup_close_ int fd = -EBADF;
+
+ fd = eventfd(0, EFD_CLOEXEC);
+ assert_se(fd >= 0);
+
+ /* Verify that we handle anonymous inodes correctly, i.e. those which have no file type */
+
+ struct stat st;
+ ASSERT_OK_ERRNO(fstat(fd, &st));
+ assert_se((st.st_mode & S_IFMT) == 0);
+
+ assert_se(!inode_type_to_string(st.st_mode));
+}
+
TEST(fd_verify_linked) {
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
_cleanup_close_ int tfd = -EBADF, fd = -EBADF;