LCOV - code coverage report
Current view: top level - test - test-mount-util.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 45 45 100.0 %
Date: 2019-08-23 13:36:53 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 62 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <sys/mount.h>
       4                 :            : 
       5                 :            : #include "alloc-util.h"
       6                 :            : #include "mount-util.h"
       7                 :            : #include "string-util.h"
       8                 :            : #include "tests.h"
       9                 :            : 
      10                 :          4 : static void test_mount_option_mangle(void) {
      11                 :          4 :         char *opts = NULL;
      12                 :            :         unsigned long f;
      13                 :            : 
      14         [ -  + ]:          4 :         assert_se(mount_option_mangle(NULL, MS_RDONLY|MS_NOSUID, &f, &opts) == 0);
      15         [ -  + ]:          4 :         assert_se(f == (MS_RDONLY|MS_NOSUID));
      16         [ -  + ]:          4 :         assert_se(opts == NULL);
      17                 :            : 
      18         [ -  + ]:          4 :         assert_se(mount_option_mangle("", MS_RDONLY|MS_NOSUID, &f, &opts) == 0);
      19         [ -  + ]:          4 :         assert_se(f == (MS_RDONLY|MS_NOSUID));
      20         [ -  + ]:          4 :         assert_se(opts == NULL);
      21                 :            : 
      22         [ -  + ]:          4 :         assert_se(mount_option_mangle("ro,nosuid,nodev,noexec", 0, &f, &opts) == 0);
      23         [ -  + ]:          4 :         assert_se(f == (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC));
      24         [ -  + ]:          4 :         assert_se(opts == NULL);
      25                 :            : 
      26         [ -  + ]:          4 :         assert_se(mount_option_mangle("ro,nosuid,nodev,noexec,mode=755", 0, &f, &opts) == 0);
      27         [ -  + ]:          4 :         assert_se(f == (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC));
      28         [ -  + ]:          4 :         assert_se(streq(opts, "mode=755"));
      29                 :          4 :         opts = mfree(opts);
      30                 :            : 
      31         [ -  + ]:          4 :         assert_se(mount_option_mangle("rw,nosuid,foo,hogehoge,nodev,mode=755", 0, &f, &opts) == 0);
      32         [ -  + ]:          4 :         assert_se(f == (MS_NOSUID|MS_NODEV));
      33         [ -  + ]:          4 :         assert_se(streq(opts, "foo,hogehoge,mode=755"));
      34                 :          4 :         opts = mfree(opts);
      35                 :            : 
      36         [ -  + ]:          4 :         assert_se(mount_option_mangle("rw,nosuid,nodev,noexec,relatime,net_cls,net_prio", MS_RDONLY, &f, &opts) == 0);
      37         [ -  + ]:          4 :         assert_se(f == (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME));
      38         [ -  + ]:          4 :         assert_se(streq(opts, "net_cls,net_prio"));
      39                 :          4 :         opts = mfree(opts);
      40                 :            : 
      41         [ -  + ]:          4 :         assert_se(mount_option_mangle("rw,nosuid,nodev,relatime,size=1630748k,mode=700,uid=1000,gid=1000", MS_RDONLY, &f, &opts) == 0);
      42         [ -  + ]:          4 :         assert_se(f == (MS_NOSUID|MS_NODEV|MS_RELATIME));
      43         [ -  + ]:          4 :         assert_se(streq(opts, "size=1630748k,mode=700,uid=1000,gid=1000"));
      44                 :          4 :         opts = mfree(opts);
      45                 :            : 
      46         [ -  + ]:          4 :         assert_se(mount_option_mangle("size=1630748k,rw,gid=1000,,,nodev,relatime,,mode=700,nosuid,uid=1000", MS_RDONLY, &f, &opts) == 0);
      47         [ -  + ]:          4 :         assert_se(f == (MS_NOSUID|MS_NODEV|MS_RELATIME));
      48         [ -  + ]:          4 :         assert_se(streq(opts, "size=1630748k,gid=1000,mode=700,uid=1000"));
      49                 :          4 :         opts = mfree(opts);
      50                 :            : 
      51         [ -  + ]:          4 :         assert_se(mount_option_mangle("rw,exec,size=8143984k,nr_inodes=2035996,mode=755", MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV, &f, &opts) == 0);
      52         [ -  + ]:          4 :         assert_se(f == (MS_NOSUID|MS_NODEV));
      53         [ -  + ]:          4 :         assert_se(streq(opts, "size=8143984k,nr_inodes=2035996,mode=755"));
      54                 :          4 :         opts = mfree(opts);
      55                 :            : 
      56         [ -  + ]:          4 :         assert_se(mount_option_mangle("rw,relatime,fmask=0022,,,dmask=0022", MS_RDONLY, &f, &opts) == 0);
      57         [ -  + ]:          4 :         assert_se(f == MS_RELATIME);
      58         [ -  + ]:          4 :         assert_se(streq(opts, "fmask=0022,dmask=0022"));
      59                 :          4 :         opts = mfree(opts);
      60                 :            : 
      61         [ -  + ]:          4 :         assert_se(mount_option_mangle("rw,relatime,fmask=0022,dmask=0022,\"hogehoge", MS_RDONLY, &f, &opts) < 0);
      62                 :          4 : }
      63                 :            : 
      64                 :          4 : int main(int argc, char *argv[]) {
      65                 :          4 :         test_setup_logging(LOG_DEBUG);
      66                 :            : 
      67                 :          4 :         test_mount_option_mangle();
      68                 :            : 
      69                 :          4 :         return 0;
      70                 :            : }

Generated by: LCOV version 1.14