]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-umount.c
libudev: hide definition of struct udev_list from other libudev components
[thirdparty/systemd.git] / src / test / test-umount.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "alloc-util.h"
4 #include "log.h"
5 #include "path-util.h"
6 #include "string-util.h"
7 #include "tests.h"
8 #include "umount.h"
9 #include "util.h"
10
11 static void test_mount_points_list(const char *fname) {
12 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
13 _cleanup_free_ char *testdata_fname = NULL;
14 MountPoint *m;
15
16 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
17
18 if (fname)
19 fname = testdata_fname = path_join(get_testdata_dir(), fname);
20
21 LIST_HEAD_INIT(mp_list_head);
22 assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
23
24 LIST_FOREACH(mount_point, m, mp_list_head)
25 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
26 m->path,
27 strempty(m->remount_options),
28 m->remount_flags,
29 yes_no(m->try_remount_ro),
30 major(m->devnum), minor(m->devnum));
31 }
32
33 static void test_swap_list(const char *fname) {
34 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
35 _cleanup_free_ char *testdata_fname = NULL;
36 MountPoint *m;
37
38 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
39
40 if (fname)
41 fname = testdata_fname = path_join(get_testdata_dir(), fname);
42
43 LIST_HEAD_INIT(mp_list_head);
44 assert_se(swap_list_get(fname, &mp_list_head) >= 0);
45
46 LIST_FOREACH(mount_point, m, mp_list_head)
47 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
48 m->path,
49 strempty(m->remount_options),
50 m->remount_flags,
51 yes_no(m->try_remount_ro),
52 major(m->devnum), minor(m->devnum));
53 }
54
55 int main(int argc, char **argv) {
56 test_setup_logging(LOG_DEBUG);
57
58 test_mount_points_list(NULL);
59 test_mount_points_list("/test-umount/empty.mountinfo");
60 test_mount_points_list("/test-umount/garbled.mountinfo");
61 test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
62
63 test_swap_list(NULL);
64 test_swap_list("/test-umount/example.swaps");
65 }