summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-14 11:03:36 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-16 10:12:50 +0100
commit6fa392bf911ef17caf4c13e839236c8edd11bfaf (patch)
treebb5f39b8412cd76cf9a48430a7e0bc5505a241b4 /src/test
parent95b862b0540ac24999fdfbd670e8744bb626729a (diff)
downloadsystemd-6fa392bf911ef17caf4c13e839236c8edd11bfaf.tar.gz
tests: add a simple test for the mountinfo parsing logic
Diffstat (limited to 'src/test')
-rw-r--r--src/test/meson.build8
-rw-r--r--src/test/test-umount.c38
2 files changed, 46 insertions, 0 deletions
diff --git a/src/test/meson.build b/src/test/meson.build
index 4f28ef8722..e45618ef88 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -652,6 +652,14 @@ tests += [
[],
[libdl],
'', 'manual'],
+
+ [['src/test/test-umount.c',
+ 'src/core/mount-setup.c',
+ 'src/core/mount-setup.h',
+ 'src/core/umount.c',
+ 'src/core/umount.h'],
+ [],
+ [libmount]],
]
############################################################
diff --git a/src/test/test-umount.c b/src/test/test-umount.c
new file mode 100644
index 0000000000..ca626041f6
--- /dev/null
+++ b/src/test/test-umount.c
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "log.h"
+#include "string-util.h"
+#include "tests.h"
+#include "umount.h"
+#include "util.h"
+
+static void test_mount_points_list(const char *fname) {
+ LIST_HEAD(MountPoint, mp_list_head);
+ MountPoint *m;
+
+ log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
+
+ 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 dev=%u:%u",
+ m->path,
+ strempty(m->remount_options),
+ m->remount_flags,
+ yes_no(m->try_remount_ro),
+ major(m->devnum), minor(m->devnum));
+
+ mount_points_list_free(&mp_list_head);
+}
+
+int main(int argc, char **argv) {
+ log_set_max_level(LOG_DEBUG);
+ log_parse_environment();
+ log_open();
+
+ test_mount_points_list(NULL);
+ test_mount_points_list(get_testdata_dir("/test-umount/empty.mountinfo"));
+ test_mount_points_list(get_testdata_dir("/test-umount/garbled.mountinfo"));
+ test_mount_points_list(get_testdata_dir("/test-umount/rhbug-1554943.mountinfo"));
+}