LCOV - code coverage report
Current view: top level - source3/modules - test_vfs_gpfs.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 70 70 100.0 %
Date: 2021-09-23 10:06:22 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *
       4             :  *  Unit test for vfs_gpfs module.
       5             :  *
       6             :  *  Copyright (C) Christof Schmitt 2020
       7             :  *
       8             :  *  This program is free software; you can redistribute it and/or modify
       9             :  *  it under the terms of the GNU General Public License as published by
      10             :  *  the Free Software Foundation; either version 3 of the License, or
      11             :  *  (at your option) any later version.
      12             :  *
      13             :  *  This program is distributed in the hope that it will be useful,
      14             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :  *  GNU General Public License for more details.
      17             :  *
      18             :  *  You should have received a copy of the GNU General Public License
      19             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      20             :  */
      21             : 
      22             : #include "vfs_gpfs.c"
      23             : #include <cmocka.h>
      24             : 
      25           1 : static void test_share_deny_mapping(void **state)
      26             : {
      27           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_NONE),
      28             :                          GPFS_DENY_READ|GPFS_DENY_WRITE|GPFS_DENY_DELETE);
      29           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_READ),
      30             :                          GPFS_DENY_WRITE|GPFS_DENY_DELETE);
      31           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_WRITE),
      32             :                          GPFS_DENY_READ|GPFS_DENY_DELETE);
      33           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_DELETE),
      34             :                          GPFS_DENY_READ|GPFS_DENY_WRITE);
      35           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(
      36             :                                  FILE_SHARE_READ|FILE_SHARE_DELETE),
      37             :                          GPFS_DENY_WRITE);
      38           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(
      39             :                                  FILE_SHARE_WRITE|FILE_SHARE_DELETE),
      40             :                          GPFS_DENY_READ);
      41           1 :         assert_int_equal(vfs_gpfs_share_access_to_deny(
      42             :                                  FILE_SHARE_READ|FILE_SHARE_WRITE),
      43             :                          0); /* GPFS limitation, cannot deny only delete. */
      44           1 : }
      45             : 
      46           1 : static void test_gpfs_lease_mapping(void **state)
      47             : {
      48           1 :         assert_int_equal(lease_type_to_gpfs(F_RDLCK), GPFS_LEASE_READ);
      49           1 :         assert_int_equal(lease_type_to_gpfs(F_WRLCK), GPFS_LEASE_WRITE);
      50           1 :         assert_int_equal(lease_type_to_gpfs(F_UNLCK), GPFS_LEASE_NONE);
      51           1 : }
      52             : 
      53           1 : static void test_gpfs_winattrs_to_dosmode(void **state)
      54             : {
      55           1 :         assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_ARCHIVE),
      56             :                          FILE_ATTRIBUTE_ARCHIVE);
      57           1 :         assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_READONLY),
      58             :                          FILE_ATTRIBUTE_READONLY);
      59           1 :         assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_HIDDEN),
      60             :                          FILE_ATTRIBUTE_HIDDEN);
      61           1 :         assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_OFFLINE),
      62             :                          FILE_ATTRIBUTE_OFFLINE);
      63           1 :         assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_SPARSE_FILE),
      64             :                          FILE_ATTRIBUTE_SPARSE);
      65           1 :         assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_SYSTEM),
      66             :                          FILE_ATTRIBUTE_SYSTEM);
      67           1 : }
      68             : 
      69           1 : static void test_dosmode_to_gpfs_winattrs(void **state)
      70             : {
      71           1 :         assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_ARCHIVE),
      72             :                          GPFS_WINATTR_ARCHIVE);
      73           1 :         assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_HIDDEN),
      74             :                          GPFS_WINATTR_HIDDEN);
      75           1 :         assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_OFFLINE),
      76             :                          GPFS_WINATTR_OFFLINE);
      77           1 :         assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_READONLY),
      78             :                          GPFS_WINATTR_READONLY);
      79           1 :         assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_SPARSE),
      80             :                          GPFS_WINATTR_SPARSE_FILE);
      81           1 :         assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_SYSTEM),
      82             :                          GPFS_WINATTR_SYSTEM);
      83           1 : }
      84             : 
      85           1 : static void test_gpfs_get_file_id(void **state)
      86             : {
      87             :         struct gpfs_iattr64 iattr;
      88             :         uint64_t fileid1, fileid2;
      89             :         NTSTATUS status;
      90             : 
      91             :         /*
      92             :          * Ensure that the generated fileid only depends on the
      93             :          * ia_inode, ia_gen and ia_modsnapid fields in struct
      94             :          * gpfs_iattr64 and any changes to these fields result in a
      95             :          * different file id.
      96             :          */
      97             : 
      98           1 :         memset(&iattr, 1, sizeof(iattr));
      99           1 :         iattr.ia_inode = 0x11;
     100           1 :         iattr.ia_gen = 0x22;
     101           1 :         iattr.ia_modsnapid = 0x33;
     102           1 :         status = vfs_gpfs_get_file_id(&iattr, &fileid1);
     103           1 :         assert_true(NT_STATUS_IS_OK(status));
     104             : 
     105           1 :         memset(&iattr, 2, sizeof(iattr));
     106           1 :         iattr.ia_inode = 0x11;
     107           1 :         iattr.ia_gen = 0x22;
     108           1 :         iattr.ia_modsnapid = 0x33;
     109           1 :         status = vfs_gpfs_get_file_id(&iattr, &fileid2);
     110           1 :         assert_true(NT_STATUS_IS_OK(status));
     111           1 :         assert_int_equal(fileid1, fileid2);
     112             : 
     113           1 :         iattr.ia_inode = 0x44;
     114           1 :         iattr.ia_gen = 0x22;
     115           1 :         iattr.ia_modsnapid = 0x33;
     116           1 :         status = vfs_gpfs_get_file_id(&iattr, &fileid2);
     117           1 :         assert_true(NT_STATUS_IS_OK(status));
     118           1 :         assert_true(NT_STATUS_IS_OK(status));
     119           1 :         assert_int_not_equal(fileid1, fileid2);
     120             : 
     121           1 :         iattr.ia_inode = 0x11;
     122           1 :         iattr.ia_gen = 0x44;
     123           1 :         iattr.ia_modsnapid = 0x33;
     124           1 :         status = vfs_gpfs_get_file_id(&iattr, &fileid2);
     125           1 :         assert_true(NT_STATUS_IS_OK(status));
     126           1 :         assert_true(NT_STATUS_IS_OK(status));
     127           1 :         assert_int_not_equal(fileid1, fileid2);
     128             : 
     129           1 :         iattr.ia_inode = 0x11;
     130           1 :         iattr.ia_gen = 0x22;
     131           1 :         iattr.ia_modsnapid = 0x44;
     132           1 :         status = vfs_gpfs_get_file_id(&iattr, &fileid2);
     133           1 :         assert_true(NT_STATUS_IS_OK(status));
     134           1 :         assert_true(NT_STATUS_IS_OK(status));
     135           1 :         assert_int_not_equal(fileid1, fileid2);
     136           1 : }
     137             : 
     138           1 : int main(int argc, char **argv)
     139             : {
     140           1 :         const struct CMUnitTest tests[] = {
     141             :                 cmocka_unit_test(test_share_deny_mapping),
     142             :                 cmocka_unit_test(test_gpfs_lease_mapping),
     143             :                 cmocka_unit_test(test_gpfs_winattrs_to_dosmode),
     144             :                 cmocka_unit_test(test_dosmode_to_gpfs_winattrs),
     145             :                 cmocka_unit_test(test_gpfs_get_file_id),
     146             :         };
     147             : 
     148           1 :         cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
     149             : 
     150           1 :         return cmocka_run_group_tests(tests, NULL, NULL);
     151             : }

Generated by: LCOV version 1.13