2 Unix SMB/CIFS implementation.
4 libcli composite function testing
6 Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/composite/composite.h"
28 #define BASEDIR "\\composite"
30 static void loadfile_complete(struct composite_context *c)
32 int *count = talloc_get_type(c->async.private, int);
37 test a simple savefile/loadfile combination
39 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
41 const char *fname = BASEDIR "\\test.txt";
43 struct smb_composite_savefile io1;
44 struct smb_composite_loadfile io2;
45 struct composite_context **c;
47 size_t len = random() % 100000;
48 const int num_ops = 50;
50 int *count = talloc_zero(mem_ctx, int);
52 data = talloc_array(mem_ctx, uint8_t, len);
54 generate_random_buffer(data, len);
60 printf("testing savefile\n");
62 status = smb_composite_savefile(cli->tree, &io1);
63 if (!NT_STATUS_IS_OK(status)) {
64 printf("savefile failed: %s\n", nt_errstr(status));
70 printf("testing parallel loadfile with %d ops\n", num_ops);
72 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
74 for (i=0;i<num_ops;i++) {
75 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
76 c[i]->async.fn = loadfile_complete;
77 c[i]->async.private = count;
80 printf("waiting for completion\n");
81 while (*count != num_ops) {
82 event_loop_once(cli->transport->socket->event.ctx);
83 printf("count=%d\r", *count);
86 printf("count=%d\n", *count);
88 for (i=0;i<num_ops;i++) {
89 status = smb_composite_loadfile_recv(c[i], mem_ctx);
90 if (!NT_STATUS_IS_OK(status)) {
91 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
95 if (io2.out.size != len) {
96 printf("wrong length in returned data - %d should be %d\n",
101 if (memcmp(io2.out.data, data, len) != 0) {
102 printf("wrong data in loadfile!\n");
113 test a simple savefile/loadfile combination
115 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
117 const char *fname = BASEDIR "\\test.txt";
119 struct smb_composite_savefile io1;
120 struct smb_composite_fetchfile io2;
121 struct composite_context **c;
124 size_t len = random() % 10000;
125 extern int torture_numops;
126 struct event_context *event_ctx;
127 int *count = talloc_zero(mem_ctx, int);
130 data = talloc_array(mem_ctx, uint8_t, len);
132 generate_random_buffer(data, len);
134 io1.in.fname = fname;
138 printf("testing savefile\n");
140 status = smb_composite_savefile(cli->tree, &io1);
141 if (!NT_STATUS_IS_OK(status)) {
142 printf("savefile failed: %s\n", nt_errstr(status));
146 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
148 io2.in.called_name = lp_parm_string(-1, "torture", "host");
149 io2.in.calling_name = lp_netbios_name();
150 io2.in.service = lp_parm_string(-1, "torture", "share");
151 io2.in.service_type = "A:";
152 io2.in.user = lp_parm_string(-1, "torture", "username");
153 io2.in.domain = lp_parm_string(-1, "torture", "userdomain");
154 io2.in.password = lp_parm_string(-1, "torture", "password");
155 io2.in.filename = fname;
157 printf("testing parallel fetchfile with %d ops\n", torture_numops);
159 event_ctx = event_context_init(mem_ctx);
160 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
162 for (i=0; i<torture_numops; i++) {
163 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
164 c[i]->async.fn = loadfile_complete;
165 c[i]->async.private = count;
168 printf("waiting for completion\n");
170 while (*count != torture_numops) {
171 event_loop_once(event_ctx);
172 printf("count=%d\r", *count);
175 printf("count=%d\n", *count);
177 for (i=0;i<torture_numops;i++) {
178 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
179 if (!NT_STATUS_IS_OK(status)) {
180 printf("loadfile[%d] failed - %s\n", i,
186 if (io2.out.size != len) {
187 printf("wrong length in returned data - %d "
194 if (memcmp(io2.out.data, data, len) != 0) {
195 printf("wrong data in loadfile!\n");
205 basic testing of libcli composite calls
207 BOOL torture_raw_composite(void)
209 struct smbcli_state *cli;
213 if (!torture_open_connection(&cli)) {
217 mem_ctx = talloc_init("torture_raw_composite");
219 if (!torture_setup_dir(cli, BASEDIR)) {
223 ret &= test_fetchfile(cli, mem_ctx);
224 ret &= test_loadfile(cli, mem_ctx);
226 smb_raw_exit(cli->session);
227 smbcli_deltree(cli->tree, BASEDIR);
229 torture_close_connection(cli);
230 talloc_free(mem_ctx);