LCOV - code coverage report
Current view: top level - test - test-umount.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 30 30 100.0 %
Date: 2019-08-22 15:41:25 Functions: 3 3 100.0 %

          Line data    Source code
       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           4 : static void test_mount_points_list(const char *fname) {
      12           4 :         _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
      13           4 :         _cleanup_free_ char *testdata_fname = NULL;
      14             :         MountPoint *m;
      15             : 
      16           4 :         log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
      17             : 
      18           4 :         if (fname)
      19           3 :                 fname = testdata_fname = path_join(get_testdata_dir(), fname);
      20             : 
      21           4 :         LIST_HEAD_INIT(mp_list_head);
      22           4 :         assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
      23             : 
      24          34 :         LIST_FOREACH(mount_point, m, mp_list_head)
      25          30 :                 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           4 : }
      32             : 
      33           2 : static void test_swap_list(const char *fname) {
      34           2 :         _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
      35           2 :         _cleanup_free_ char *testdata_fname = NULL;
      36             :         MountPoint *m;
      37             : 
      38           2 :         log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
      39             : 
      40           2 :         if (fname)
      41           1 :                 fname = testdata_fname = path_join(get_testdata_dir(), fname);
      42             : 
      43           2 :         LIST_HEAD_INIT(mp_list_head);
      44           2 :         assert_se(swap_list_get(fname, &mp_list_head) >= 0);
      45             : 
      46           5 :         LIST_FOREACH(mount_point, m, mp_list_head)
      47           3 :                 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           2 : }
      54             : 
      55           1 : int main(int argc, char **argv) {
      56           1 :         test_setup_logging(LOG_DEBUG);
      57             : 
      58           1 :         test_mount_points_list(NULL);
      59           1 :         test_mount_points_list("/test-umount/empty.mountinfo");
      60           1 :         test_mount_points_list("/test-umount/garbled.mountinfo");
      61           1 :         test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
      62             : 
      63           1 :         test_swap_list(NULL);
      64           1 :         test_swap_list("/test-umount/example.swaps");
      65             : }

Generated by: LCOV version 1.14