]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-umount.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / test / test-umount.c
CommitLineData
6fa392bf
ZJS
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
55890a40 3#include "alloc-util.h"
6fa392bf 4#include "log.h"
55890a40 5#include "path-util.h"
6fa392bf
ZJS
6#include "string-util.h"
7#include "tests.h"
8#include "umount.h"
9#include "util.h"
10
11static void test_mount_points_list(const char *fname) {
a6dcd229 12 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
55890a40 13 _cleanup_free_ char *testdata_fname = NULL;
6fa392bf
ZJS
14 MountPoint *m;
15
16 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
17
55890a40 18 if (fname)
62a85ee0 19 fname = testdata_fname = path_join(get_testdata_dir(), fname);
55890a40 20
6fa392bf
ZJS
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));
6fa392bf
ZJS
31}
32
1fd8edb5
ZJS
33static void test_swap_list(const char *fname) {
34 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
55890a40 35 _cleanup_free_ char *testdata_fname = NULL;
1fd8edb5
ZJS
36 MountPoint *m;
37
71ae04c4 38 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
1fd8edb5 39
55890a40 40 if (fname)
62a85ee0 41 fname = testdata_fname = path_join(get_testdata_dir(), fname);
55890a40 42
1fd8edb5
ZJS
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
6fa392bf 55int main(int argc, char **argv) {
6d7c4033 56 test_setup_logging(LOG_DEBUG);
6fa392bf
ZJS
57
58 test_mount_points_list(NULL);
55890a40
FB
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");
1fd8edb5
ZJS
62
63 test_swap_list(NULL);
55890a40 64 test_swap_list("/test-umount/example.swaps");
6fa392bf 65}