]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shutdown/test-umount.c
sd-boot+bootctl: invert order of entries w/o sort-key
[thirdparty/systemd.git] / src / shutdown / test-umount.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "alloc-util.h"
4 #include "errno-util.h"
5 #include "log.h"
6 #include "path-util.h"
7 #include "string-util.h"
8 #include "tests.h"
9 #include "umount.h"
10 #include "util.h"
11
12 static void test_mount_points_list_one(const char *fname) {
13 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
14 _cleanup_free_ char *testdata_fname = NULL;
15 MountPoint *m;
16
17 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
18
19 if (fname) {
20 assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
21 fname = testdata_fname;
22 }
23
24 LIST_HEAD_INIT(mp_list_head);
25 assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
26
27 LIST_FOREACH(mount_point, m, mp_list_head)
28 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
29 m->path,
30 strempty(m->remount_options),
31 m->remount_flags,
32 yes_no(m->try_remount_ro),
33 major(m->devnum), minor(m->devnum));
34 }
35
36 TEST(mount_points_list) {
37 test_mount_points_list_one(NULL);
38 test_mount_points_list_one("/test-umount/empty.mountinfo");
39 test_mount_points_list_one("/test-umount/garbled.mountinfo");
40 test_mount_points_list_one("/test-umount/rhbug-1554943.mountinfo");
41 }
42
43 static void test_swap_list_one(const char *fname) {
44 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
45 _cleanup_free_ char *testdata_fname = NULL;
46 MountPoint *m;
47 int r;
48
49 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
50
51 if (fname) {
52 assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
53 fname = testdata_fname;
54 }
55
56 LIST_HEAD_INIT(mp_list_head);
57 r = swap_list_get(fname, &mp_list_head);
58 if (ERRNO_IS_PRIVILEGE(r))
59 return;
60 assert_se(r >= 0);
61
62 LIST_FOREACH(mount_point, m, mp_list_head)
63 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
64 m->path,
65 strempty(m->remount_options),
66 m->remount_flags,
67 yes_no(m->try_remount_ro),
68 major(m->devnum), minor(m->devnum));
69 }
70
71 TEST(swap_list) {
72 test_swap_list_one(NULL);
73 test_swap_list_one("/test-umount/example.swaps");
74 }
75
76 DEFINE_TEST_MAIN(LOG_DEBUG);