2 * Unix SMB/CIFS implementation.
4 * Unit test for vfs_gpfs module.
6 * Copyright (C) Christof Schmitt 2020
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.
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.
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/>.
25 static void test_share_deny_mapping(void **state
)
27 assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_NONE
),
28 GPFS_DENY_READ
|GPFS_DENY_WRITE
|GPFS_DENY_DELETE
);
29 assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_READ
),
30 GPFS_DENY_WRITE
|GPFS_DENY_DELETE
);
31 assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_WRITE
),
32 GPFS_DENY_READ
|GPFS_DENY_DELETE
);
33 assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_DELETE
),
34 GPFS_DENY_READ
|GPFS_DENY_WRITE
);
35 assert_int_equal(vfs_gpfs_share_access_to_deny(
36 FILE_SHARE_READ
|FILE_SHARE_DELETE
),
38 assert_int_equal(vfs_gpfs_share_access_to_deny(
39 FILE_SHARE_WRITE
|FILE_SHARE_DELETE
),
41 assert_int_equal(vfs_gpfs_share_access_to_deny(
42 FILE_SHARE_READ
|FILE_SHARE_WRITE
),
43 0); /* GPFS limitation, cannot deny only delete. */
46 static void test_gpfs_lease_mapping(void **state
)
48 assert_int_equal(lease_type_to_gpfs(F_RDLCK
), GPFS_LEASE_READ
);
49 assert_int_equal(lease_type_to_gpfs(F_WRLCK
), GPFS_LEASE_WRITE
);
50 assert_int_equal(lease_type_to_gpfs(F_UNLCK
), GPFS_LEASE_NONE
);
53 static void test_gpfs_winattrs_to_dosmode(void **state
)
55 assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_ARCHIVE
),
56 FILE_ATTRIBUTE_ARCHIVE
);
57 assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_READONLY
),
58 FILE_ATTRIBUTE_READONLY
);
59 assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_HIDDEN
),
60 FILE_ATTRIBUTE_HIDDEN
);
61 assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_OFFLINE
),
62 FILE_ATTRIBUTE_OFFLINE
);
63 assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_SPARSE_FILE
),
64 FILE_ATTRIBUTE_SPARSE
);
65 assert_int_equal(vfs_gpfs_winattrs_to_dosmode(GPFS_WINATTR_SYSTEM
),
66 FILE_ATTRIBUTE_SYSTEM
);
69 static void test_dosmode_to_gpfs_winattrs(void **state
)
71 assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_ARCHIVE
),
72 GPFS_WINATTR_ARCHIVE
);
73 assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_HIDDEN
),
75 assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_OFFLINE
),
76 GPFS_WINATTR_OFFLINE
);
77 assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_READONLY
),
78 GPFS_WINATTR_READONLY
);
79 assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_SPARSE
),
80 GPFS_WINATTR_SPARSE_FILE
);
81 assert_int_equal(vfs_gpfs_dosmode_to_winattrs(FILE_ATTRIBUTE_SYSTEM
),
85 static void test_gpfs_get_file_id(void **state
)
87 struct gpfs_iattr64 iattr
;
88 uint64_t fileid1
, fileid2
;
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
98 memset(&iattr
, 1, sizeof(iattr
));
99 iattr
.ia_inode
= 0x11;
101 iattr
.ia_modsnapid
= 0x33;
102 status
= vfs_gpfs_get_file_id(&iattr
, &fileid1
);
103 assert_true(NT_STATUS_IS_OK(status
));
105 memset(&iattr
, 2, sizeof(iattr
));
106 iattr
.ia_inode
= 0x11;
108 iattr
.ia_modsnapid
= 0x33;
109 status
= vfs_gpfs_get_file_id(&iattr
, &fileid2
);
110 assert_true(NT_STATUS_IS_OK(status
));
111 assert_int_equal(fileid1
, fileid2
);
113 iattr
.ia_inode
= 0x44;
115 iattr
.ia_modsnapid
= 0x33;
116 status
= vfs_gpfs_get_file_id(&iattr
, &fileid2
);
117 assert_true(NT_STATUS_IS_OK(status
));
118 assert_true(NT_STATUS_IS_OK(status
));
119 assert_int_not_equal(fileid1
, fileid2
);
121 iattr
.ia_inode
= 0x11;
123 iattr
.ia_modsnapid
= 0x33;
124 status
= vfs_gpfs_get_file_id(&iattr
, &fileid2
);
125 assert_true(NT_STATUS_IS_OK(status
));
126 assert_true(NT_STATUS_IS_OK(status
));
127 assert_int_not_equal(fileid1
, fileid2
);
129 iattr
.ia_inode
= 0x11;
131 iattr
.ia_modsnapid
= 0x44;
132 status
= vfs_gpfs_get_file_id(&iattr
, &fileid2
);
133 assert_true(NT_STATUS_IS_OK(status
));
134 assert_true(NT_STATUS_IS_OK(status
));
135 assert_int_not_equal(fileid1
, fileid2
);
138 int main(int argc
, char **argv
)
140 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
),
148 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
150 return cmocka_run_group_tests(tests
, NULL
, NULL
);