LCOV - code coverage report
Current view: top level - test - test-umount.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 30 30 100.0 %
Date: 2019-08-23 13:36:53 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 24 75.0 %

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

Generated by: LCOV version 1.14