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 unsigned char *v = (unsigned char *)data_out;
124 if (v[i] != (i & 0xFF)) {
125 printf("bad data 0x%x at %d\n", (unsigned char)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)
177 printf("\nTesting TestCall\n");
178 status = dcerpc_TestCall(p, mem_ctx, &r);
179 if (!NT_STATUS_IS_OK(status)) {
180 printf("TestCall failed - %s\n", nt_errstr(status));
187 BOOL torture_rpc_echo(int dummy)
190 struct dcerpc_pipe *p;
194 mem_ctx = talloc_init("torture_rpc_echo");
196 status = torture_rpc_connection(&p,
199 DCERPC_RPCECHO_VERSION);
200 if (!NT_STATUS_IS_OK(status)) {
204 if (!test_addone(p, mem_ctx)) {
208 if (!test_echodata(p, mem_ctx)) {
212 if (!test_sourcedata(p, mem_ctx)) {
216 if (!test_sinkdata(p, mem_ctx)) {
220 if (!test_testcall(p, mem_ctx)) {
226 torture_rpc_close(p);