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.
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/composite/composite.h"
27 #define BASEDIR "\\composite"
29 static void loadfile_complete(struct smbcli_composite *c)
31 int *count = talloc_get_type(c->async.private, int);
36 test a simple savefile/loadfile combination
38 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
40 const char *fname = BASEDIR "\\test.txt";
42 struct smb_composite_savefile io1;
43 struct smb_composite_loadfile io2;
44 struct smbcli_composite **c;
46 size_t len = random() % 100000;
47 const int num_ops = 50;
49 int *count = talloc_zero(mem_ctx, int);
51 data = talloc_array(mem_ctx, uint8_t, len);
53 generate_random_buffer(data, len);
59 printf("testing savefile\n");
61 status = smb_composite_savefile(cli->tree, &io1);
62 if (!NT_STATUS_IS_OK(status)) {
63 printf("savefile failed: %s\n", nt_errstr(status));
69 printf("testing parallel loadfile with %d ops\n", num_ops);
71 c = talloc_array(mem_ctx, struct smbcli_composite *, num_ops);
73 for (i=0;i<num_ops;i++) {
74 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
75 c[i]->async.fn = loadfile_complete;
76 c[i]->async.private = count;
79 printf("waiting for completion\n");
80 while (*count != num_ops) {
81 event_loop_once(cli->transport->socket->event.ctx);
82 printf("count=%d\r", *count);
85 printf("count=%d\n", *count);
87 for (i=0;i<num_ops;i++) {
88 status = smb_composite_loadfile_recv(c[i], mem_ctx);
89 if (!NT_STATUS_IS_OK(status)) {
90 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
94 if (io2.out.size != len) {
95 printf("wrong length in returned data - %d should be %d\n",
100 if (memcmp(io2.out.data, data, len) != 0) {
101 printf("wrong data in loadfile!\n");
112 basic testing of libcli composite calls
114 BOOL torture_raw_composite(void)
116 struct smbcli_state *cli;
120 if (!torture_open_connection(&cli)) {
124 mem_ctx = talloc_init("torture_raw_composite");
126 if (!torture_setup_dir(cli, BASEDIR)) {
130 ret &= test_loadfile(cli, mem_ctx);
132 smb_raw_exit(cli->session);
133 smbcli_deltree(cli->tree, BASEDIR);
135 torture_close_connection(cli);
136 talloc_destroy(mem_ctx);