summaryrefslogtreecommitdiffstats
path: root/src/shutdown/test-umount.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/shutdown/test-umount.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/shutdown/test-umount.c')
-rw-r--r--src/shutdown/test-umount.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/shutdown/test-umount.c b/src/shutdown/test-umount.c
new file mode 100644
index 0000000..93da2e0
--- /dev/null
+++ b/src/shutdown/test-umount.c
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "alloc-util.h"
+#include "detach-swap.h"
+#include "errno-util.h"
+#include "log.h"
+#include "path-util.h"
+#include "string-util.h"
+#include "tests.h"
+#include "umount.h"
+
+static void test_mount_points_list_one(const char *fname) {
+ _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
+ _cleanup_free_ char *testdata_fname = NULL;
+
+ log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
+
+ if (fname) {
+ assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
+ fname = testdata_fname;
+ }
+
+ LIST_HEAD_INIT(mp_list_head);
+ assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
+
+ LIST_FOREACH(mount_point, m, mp_list_head)
+ log_debug("path=%s o=%s f=0x%lx try-ro=%s",
+ m->path,
+ strempty(m->remount_options),
+ m->remount_flags,
+ yes_no(m->try_remount_ro));
+}
+
+TEST(mount_points_list) {
+ test_mount_points_list_one(NULL);
+ test_mount_points_list_one("/test-umount/empty.mountinfo");
+ test_mount_points_list_one("/test-umount/garbled.mountinfo");
+ test_mount_points_list_one("/test-umount/rhbug-1554943.mountinfo");
+}
+
+static void test_swap_list_one(const char *fname) {
+ _cleanup_(swap_devices_list_free) LIST_HEAD(SwapDevice, sd_list_head);
+ _cleanup_free_ char *testdata_fname = NULL;
+ int r;
+
+ log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
+
+ if (fname) {
+ assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
+ fname = testdata_fname;
+ }
+
+ LIST_HEAD_INIT(sd_list_head);
+ r = swap_list_get(fname, &sd_list_head);
+ if (ERRNO_IS_PRIVILEGE(r))
+ return;
+ assert_se(r >= 0);
+
+ LIST_FOREACH(swap_device, m, sd_list_head)
+ log_debug("path=%s", m->path);
+}
+
+TEST(swap_list) {
+ test_swap_list_one(NULL);
+ test_swap_list_one("/test-umount/example.swaps");
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);