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.
23 #include "librpc/gen_ndr/ndr_echo.h"
27 test the AddOne interface
29 static BOOL test_addone(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
34 printf("\nTesting AddOne\n");
41 status = dcerpc_echo_AddOne(p, mem_ctx, &r);
42 if (!NT_STATUS_IS_OK(status)) {
43 printf("AddOne(%d) failed - %s\n", i, nt_errstr(status));
46 printf("%d + 1 = %u\n", i, n);
53 test the EchoData interface
55 static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
59 uint8_t *data_in, *data_out;
60 int len = 1 + (random() % 5000);
61 struct echo_EchoData r;
63 printf("\nTesting EchoData\n");
65 data_in = talloc(mem_ctx, len);
66 data_out = talloc(mem_ctx, len);
72 r.in.in_data = data_in;
74 status = dcerpc_echo_EchoData(p, mem_ctx, &r);
75 if (!NT_STATUS_IS_OK(status)) {
76 printf("EchoData(%d) failed - %s\n", len, nt_errstr(status));
80 data_out = r.out.out_data;
83 if (data_in[i] != data_out[i]) {
84 printf("Bad data returned for len %d at offset %d\n",
87 dump_data(0, data_in+i, MIN(len-i, 16));
89 dump_data(0, data_out+i, MIN(len-1, 16));
100 test the SourceData interface
102 static BOOL test_sourcedata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
106 int len = 200000 + (random() % 5000);
108 struct echo_SourceData r;
110 printf("\nTesting SourceData\n");
112 data_out = talloc(mem_ctx, len);
115 r.out.data = data_out;
117 status = dcerpc_echo_SourceData(p, mem_ctx, &r);
118 if (!NT_STATUS_IS_OK(status)) {
119 printf("SourceData(%d) failed - %s\n", len, nt_errstr(status));
123 for (i=0;i<len;i++) {
124 uint8_t *v = (uint8_t *)data_out;
125 if (v[i] != (i & 0xFF)) {
126 printf("bad data 0x%x at %d\n", (uint8_t)data_out[i], i);
135 test the SinkData interface
137 static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
142 int len = 200000 + (random() % 5000);
143 struct echo_SinkData r;
145 printf("\nTesting SinkData\n");
147 data_in = talloc(mem_ctx, len);
148 for (i=0;i<len;i++) {
155 status = dcerpc_echo_SinkData(p, mem_ctx, &r);
156 if (!NT_STATUS_IS_OK(status)) {
157 printf("SinkData(%d) failed - %s\n", len, nt_errstr(status));
161 printf("sunk %d bytes\n", len);
168 test the testcall interface
170 static BOOL test_testcall(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
173 struct echo_TestCall r;
175 r.in.s1 = "input string";
177 printf("\nTesting TestCall\n");
178 status = dcerpc_echo_TestCall(p, mem_ctx, &r);
179 if (!NT_STATUS_IS_OK(status)) {
180 printf("TestCall failed - %s\n", nt_errstr(status));
188 test the testcall interface
190 static BOOL test_testcall2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
193 struct echo_TestCall2 r;
200 printf("\nTesting TestCall2 level %d\n", i);
201 status = dcerpc_echo_TestCall2(p, mem_ctx, &r);
202 if (!NT_STATUS_IS_OK(status)) {
203 printf("TestCall2 failed - %s\n", nt_errstr(status));
213 test the TestSleep interface
215 static BOOL test_sleep(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
219 #define ASYNC_COUNT 5
220 struct rpc_request *req[ASYNC_COUNT];
221 struct echo_TestSleep r[ASYNC_COUNT];
222 int done[ASYNC_COUNT];
223 struct event_context *ctx;
227 printf("\nTesting TestSleep\n");
229 for (i=0;i<ASYNC_COUNT;i++) {
231 r[i].in.seconds = ASYNC_COUNT-i;
232 req[i] = dcerpc_echo_TestSleep_send(p, mem_ctx, &r[i]);
234 printf("Failed to send async sleep request\n");
239 ctx = dcerpc_event_context(p);
240 while (total_done < ASYNC_COUNT) {
241 if (event_loop_once(ctx) != 0) {
244 for (i=0;i<ASYNC_COUNT;i++) {
245 if (done[i] == 0 && req[i]->state == RPC_REQUEST_DONE) {
248 status = dcerpc_ndr_request_recv(req[i]);
249 if (!NT_STATUS_IS_OK(status)) {
250 printf("TestSleep(%d) failed - %s\n",
251 i, nt_errstr(status));
254 printf("Sleep for %d seconds\n",
269 static BOOL test_enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
272 struct echo_TestEnum r;
274 enum echo_Enum1 v = ECHO_ENUM1;
275 struct echo_Enum2 e2;
286 e2.e2 = ECHO_ENUM1_32;
289 printf("\nTesting TestEnum\n");
290 status = dcerpc_echo_TestEnum(p, mem_ctx, &r);
291 if (!NT_STATUS_IS_OK(status)) {
292 printf("TestEnum failed - %s\n", nt_errstr(status));
300 BOOL torture_rpc_echo(void)
303 struct dcerpc_pipe *p;
307 mem_ctx = talloc_init("torture_rpc_echo");
309 status = torture_rpc_connection(&p,
312 DCERPC_RPCECHO_VERSION);
313 if (!NT_STATUS_IS_OK(status)) {
317 if (!test_addone(p, mem_ctx)) {
321 if (!test_sinkdata(p, mem_ctx)) {
325 if (!test_echodata(p, mem_ctx)) {
329 if (!test_sourcedata(p, mem_ctx)) {
333 if (!test_testcall(p, mem_ctx)) {
337 if (!test_testcall2(p, mem_ctx)) {
341 if (!test_enum(p, mem_ctx)) {
346 if (!test_sleep(p, mem_ctx)) {
352 talloc_free(mem_ctx);
354 torture_rpc_close(p);