selftest: Add unit test for vfs_gpfs
authorChristof Schmitt <cs@samba.org>
Fri, 21 Feb 2020 15:52:08 +0000 (16:52 +0100)
committerChristof Schmitt <cs@samba.org>
Tue, 8 Sep 2020 21:35:41 +0000 (21:35 +0000)
The mapping functions of the vfs_gpfs module can be easily unit tested.
Begin a cmocka test to cover those.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/test_vfs_gpfs.c [new file with mode: 0644]
source3/modules/wscript_build
source3/selftest/tests.py

diff --git a/source3/modules/test_vfs_gpfs.c b/source3/modules/test_vfs_gpfs.c
new file mode 100644 (file)
index 0000000..55b4861
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *
+ *  Unit test for vfs_gpfs module.
+ *
+ *  Copyright (C) Christof Schmitt 2020
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "vfs_gpfs.c"
+#include <cmocka.h>
+
+static void test_share_deny_mapping(void **state)
+{
+       assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_NONE),
+                        GPFS_DENY_READ|GPFS_DENY_WRITE|GPFS_DENY_DELETE);
+       assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_READ),
+                        GPFS_DENY_WRITE|GPFS_DENY_DELETE);
+       assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_WRITE),
+                        GPFS_DENY_READ|GPFS_DENY_DELETE);
+       assert_int_equal(vfs_gpfs_share_access_to_deny(FILE_SHARE_DELETE),
+                        GPFS_DENY_READ|GPFS_DENY_WRITE);
+       assert_int_equal(vfs_gpfs_share_access_to_deny(
+                                FILE_SHARE_READ|FILE_SHARE_DELETE),
+                        GPFS_DENY_WRITE);
+       assert_int_equal(vfs_gpfs_share_access_to_deny(
+                                FILE_SHARE_WRITE|FILE_SHARE_DELETE),
+                        GPFS_DENY_READ);
+       assert_int_equal(vfs_gpfs_share_access_to_deny(
+                                FILE_SHARE_READ|FILE_SHARE_WRITE),
+                        0); /* GPFS limitation, cannot deny only delete. */
+}
+
+int main(int argc, char **argv)
+{
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test(test_share_deny_mapping),
+       };
+
+       cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
+
+       return cmocka_run_group_tests(tests, NULL, NULL);
+}
index 2b1f264bab52f10248e3a2c4e3972287b76f2ead..c4f3db2229668ecc25848923b11c14950942f243 100644 (file)
@@ -370,6 +370,13 @@ bld.SAMBA3_MODULE('vfs_gpfs',
                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_gpfs'),
                  includes=bld.CONFIG_GET('CPPPATH_GPFS'))
 
+bld.SAMBA3_BINARY('test_vfs_gpfs',
+                  source='test_vfs_gpfs.c',
+                  deps='NFS4_ACLS non_posix_acls gpfswrap cmocka',
+                  for_selftest=True,
+                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_gpfs'),
+                  includes=bld.CONFIG_GET('CPPPATH_GPFS'))
+
 bld.SAMBA3_MODULE('vfs_readahead',
                  subsystem='vfs',
                  source='vfs_readahead.c',
index b2217fbea2b4b470e1361a11116ecd8c35fd9261..a8e8be8eb87fe84fef05b17627b17648ab112b35 100755 (executable)
@@ -571,6 +571,10 @@ plantestsuite("samba3.test_vfs_posixacl", "none",
               [os.path.join(bindir(), "test_vfs_posixacl"),
                "$SMB_CONF_PATH"])
 
+if is_module_enabled("vfs_gpfs"):
+    plantestsuite("samba3.test_vfs_gpfs", "none",
+                  [os.path.join(bindir(), "test_vfs_gpfs")])
+
 plantestsuite(
     "samba3.resolvconf", "none",
     [os.path.join(samba3srcdir, "script/tests/test_resolvconf.sh")])