From d8d0da1f19cd1db235851807c869e4667475b099 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 10 Jun 2021 12:31:09 +0200 Subject: [PATCH] test-stat-util: add a very basic test for test_path_is_read_only() --- src/test/test-stat-util.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index d4190d4c77..9f94d66b02 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -6,6 +6,7 @@ #include #include "alloc-util.h" +#include "errno-list.h" #include "fd-util.h" #include "macro.h" #include "mountpoint-util.h" @@ -68,8 +69,18 @@ static void test_path_is_fs_type(void) { } static void test_path_is_temporary_fs(void) { + const char *s; + int r; + log_info("/* %s */", __func__); + FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") { + r = path_is_temporary_fs(s); + + log_info_errno(r, "path_is_temporary_fs(\"%s\"): %d, %s", + s, r, r < 0 ? errno_to_name(r) : yes_no(r)); + } + /* run might not be a mount point in build chroots */ if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) assert_se(path_is_temporary_fs("/run") > 0); @@ -77,6 +88,26 @@ static void test_path_is_temporary_fs(void) { assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT); } +static void test_path_is_read_only_fs(void) { + const char *s; + int r; + + log_info("/* %s */", __func__); + + FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") { + r = path_is_read_only_fs(s); + + log_info_errno(r, "path_is_read_only_fs(\"%s\"): %d, %s", + s, r, r < 0 ? errno_to_name(r) : yes_no(r)); + } + + if (path_is_mount_point("/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); + assert_se(path_is_read_only_fs("/i-dont-exist") == -ENOENT); +} + static void test_fd_is_ns(void) { _cleanup_close_ int fd = -1; @@ -184,6 +215,7 @@ int main(int argc, char *argv[]) { test_is_symlink(); test_path_is_fs_type(); test_path_is_temporary_fs(); + test_path_is_read_only_fs(); test_fd_is_ns(); test_device_major_minor_valid(); test_device_path_make_canonical(); -- 2.25.1