tests: add a simple test for the mountinfo parsing logic

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-03-16 10:12:50 +01:00
parent 95b862b054
commit 6fa392bf91
8 changed files with 122 additions and 16 deletions
+8
View File
@@ -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]],
]
############################################################
+38
View File
@@ -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"));
}