2 Unix SMB/CIFS implementation.
3 test suite for echo rpc operations
5 Copyright (C) Andrew Tridgell 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 test the AddOne interface
28 static BOOL test_addone(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
33 printf("\nTesting AddOne\n");
40 status = dcerpc_echo_AddOne(p, mem_ctx, &r);
41 if (!NT_STATUS_IS_OK(status)) {
42 printf("AddOne(%d) failed - %s\n", i, nt_errstr(status));
45 printf("%d + 1 = %u\n", i, n);
52 test the EchoData interface
54 static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
58 char *data_in, *data_out;
59 int len = 1 + (random() % 5000);
60 struct echo_EchoData r;
62 printf("\nTesting EchoData\n");
64 data_in = talloc(mem_ctx, len);
65 data_out = talloc(mem_ctx, len);
71 r.in.in_data = data_in;
73 status = dcerpc_echo_EchoData(p, mem_ctx, &r);
74 if (!NT_STATUS_IS_OK(status)) {
75 printf("EchoData(%d) failed - %s\n", len, nt_errstr(status));
79 data_out = r.out.out_data;
82 if (data_in[i] != data_out[i]) {
83 printf("Bad data returned for len %d at offset %d\n",
86 dump_data(0, data_in+i, MIN(len-i, 16));
88 dump_data(0, data_out+i, MIN(len-1, 16));
99 test the SourceData interface
101 static BOOL test_sourcedata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
105 int len = 200000 + (random() % 5000);
107 struct echo_SourceData r;
109 printf("\nTesting SourceData\n");
111 data_out = talloc(mem_ctx, len);
114 r.out.data = data_out;
116 status = dcerpc_echo_SourceData(p, mem_ctx, &r);
117 if (!NT_STATUS_IS_OK(status)) {
118 printf("SourceData(%d) failed - %s\n", len, nt_errstr(status));
122 for (i=0;i<len;i++) {
123 uint8_t *v = (uint8_t *)data_out;
124 if (v[i] != (i & 0xFF)) {
125 printf("bad data 0x%x at %d\n", (uint8_t)data_out[i], i);
134 test the SinkData interface
136 static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
141 int len = 200000 + (random() % 5000);
142 struct echo_SinkData r;
144 printf("\nTesting SinkData\n");
146 data_in = talloc(mem_ctx, len);
147 for (i=0;i<len;i++) {
154 status = dcerpc_echo_SinkData(p, mem_ctx, &r);
155 if (!NT_STATUS_IS_OK(status)) {
156 printf("SinkData(%d) failed - %s\n", len, nt_errstr(status));
160 printf("sunk %d bytes\n", len);
167 test the testcall interface
169 static BOOL test_testcall(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
172 struct echo_TestCall r;
174 r.in.s1 = "input string";
176 printf("\nTesting TestCall\n");
177 status = dcerpc_echo_TestCall(p, mem_ctx, &r);
178 if (!NT_STATUS_IS_OK(status)) {
179 printf("TestCall failed - %s\n", nt_errstr(status));
187 test the testcall interface
189 static BOOL test_testcall2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
192 struct echo_TestCall2 r;
199 printf("\nTesting TestCall2 level %d\n", i);
200 status = dcerpc_echo_TestCall2(p, mem_ctx, &r);
201 if (!NT_STATUS_IS_OK(status)) {
202 printf("TestCall2 failed - %s\n", nt_errstr(status));
212 test the TestSleep interface
214 static BOOL test_sleep(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
218 #define ASYNC_COUNT 5
219 struct rpc_request *req[ASYNC_COUNT];
220 struct echo_TestSleep r[ASYNC_COUNT];
221 int done[ASYNC_COUNT];
222 struct event_context *ctx;
226 printf("\nTesting TestSleep\n");
228 for (i=0;i<ASYNC_COUNT;i++) {
230 r[i].in.seconds = ASYNC_COUNT-i;
231 req[i] = dcerpc_echo_TestSleep_send(p, mem_ctx, &r[i]);
233 printf("Failed to send async sleep request\n");
238 ctx = dcerpc_event_context(p);
239 while (total_done < ASYNC_COUNT) {
240 if (event_loop_once(ctx) != 0) {
243 for (i=0;i<ASYNC_COUNT;i++) {
244 if (done[i] == 0 && req[i]->state == RPC_REQUEST_DONE) {
247 status = dcerpc_ndr_request_recv(req[i]);
248 if (!NT_STATUS_IS_OK(status)) {
249 printf("TestSleep(%d) failed - %s\n",
250 i, nt_errstr(status));
253 printf("Sleep for %d seconds\n",
263 BOOL torture_rpc_echo(int dummy)
266 struct dcerpc_pipe *p;
270 mem_ctx = talloc_init("torture_rpc_echo");
272 status = torture_rpc_connection(&p,
275 DCERPC_RPCECHO_VERSION);
276 if (!NT_STATUS_IS_OK(status)) {
280 if (!test_addone(p, mem_ctx)) {
284 if (!test_sinkdata(p, mem_ctx)) {
288 if (!test_echodata(p, mem_ctx)) {
292 if (!test_sourcedata(p, mem_ctx)) {
296 if (!test_testcall(p, mem_ctx)) {
300 if (!test_testcall2(p, mem_ctx)) {
305 if (!test_sleep(p, mem_ctx)) {
311 talloc_destroy(mem_ctx);
313 torture_rpc_close(p);