s4:torture: add boilerplate code for vfs_fruit
[obnox/samba/samba-obnox.git] / source4 / torture / vfs / vfs.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Ralph Boehme 2014
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "libcli/libcli.h"
23 #include "../lib/util/dlinklist.h"
24
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "param/param.h"
29 #include "libcli/resolve/resolve.h"
30
31 #include "torture/util.h"
32 #include "torture/smbtorture.h"
33 #include "torture/vfs/proto.h"
34 #include "torture/smb2/proto.h"
35
36 static bool wrap_2ns_smb2_test(struct torture_context *torture_ctx,
37                                struct torture_tcase *tcase,
38                                struct torture_test *test)
39 {
40         bool (*fn) (struct torture_context *, struct smb2_tree *, struct smb2_tree *);
41         bool ret = false;
42
43         struct smb2_tree *tree1;
44         struct smb2_tree *tree2;
45         TALLOC_CTX *mem_ctx = talloc_new(torture_ctx);
46
47         if (!torture_smb2_con_sopt(torture_ctx, "share1", &tree1)) {
48                 torture_fail(torture_ctx,
49                     "Establishing SMB2 connection failed\n");
50                 goto done;
51         }
52
53         talloc_steal(mem_ctx, tree1);
54
55         if (!torture_smb2_con_sopt(torture_ctx, "share2", &tree2)) {
56                 torture_fail(torture_ctx,
57                     "Establishing SMB2 connection failed\n");
58                 goto done;
59         }
60
61         talloc_steal(mem_ctx, tree2);
62
63         fn = test->fn;
64
65         ret = fn(torture_ctx, tree1, tree2);
66
67 done:
68         /* the test may already have closed some of the connections */
69         talloc_free(mem_ctx);
70
71         return ret;
72 }
73
74 /*
75  * Run a test with 2 connected trees, Share names to connect are taken
76  * from option strings "torture:share1" and "torture:share2"
77  */
78 struct torture_test *torture_suite_add_2ns_smb2_test(struct torture_suite *suite,
79                                                      const char *name,
80                                                      bool (*run)(struct torture_context *,
81                                                                  struct smb2_tree *,
82                                                                  struct smb2_tree *))
83 {
84         struct torture_test *test;
85         struct torture_tcase *tcase;
86
87         tcase = torture_suite_add_tcase(suite, name);
88
89         test = talloc(tcase, struct torture_test);
90
91         test->name = talloc_strdup(test, name);
92         test->description = NULL;
93         test->run = wrap_2ns_smb2_test;
94         test->fn = run;
95         test->dangerous = false;
96
97         DLIST_ADD_END(tcase->tests, test, struct torture_test *);
98
99         return test;
100 }
101
102 NTSTATUS torture_vfs_init(void)
103 {
104         struct torture_suite *suite = torture_suite_create(
105                 talloc_autofree_context(), "vfs");
106
107         suite->description = talloc_strdup(suite, "VFS modules tests");
108
109         torture_suite_add_suite(suite, torture_vfs_fruit());
110
111         torture_register_suite(suite);
112
113         return NT_STATUS_OK;
114 }