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);
72 r.out.data = data_out;
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 if (memcmp(data_in, data_out, len) != 0) {
81 printf("Bad data returned for len %d!\n", len);
91 test the SourceData interface
93 static BOOL test_sourcedata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
97 int len = 200000 + (random() % 5000);
99 struct echo_SourceData r;
101 printf("\nTesting SourceData\n");
103 data_out = talloc(mem_ctx, len);
106 r.out.data = data_out;
108 status = dcerpc_echo_SourceData(p, mem_ctx, &r);
109 if (!NT_STATUS_IS_OK(status)) {
110 printf("SourceData(%d) failed - %s\n", len, nt_errstr(status));
114 for (i=0;i<len;i++) {
115 unsigned char *v = (unsigned char *)data_out;
116 if (v[i] != (i & 0xFF)) {
117 printf("bad data 0x%x at %d\n", (unsigned char)data_out[i], i);
126 test the SinkData interface
128 static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
133 int len = 200000 + (random() % 5000);
134 struct echo_SinkData r;
136 printf("\nTesting SinkData\n");
138 data_in = talloc(mem_ctx, len);
139 for (i=0;i<len;i++) {
146 status = dcerpc_echo_SinkData(p, mem_ctx, &r);
147 if (!NT_STATUS_IS_OK(status)) {
148 printf("SinkData(%d) failed - %s\n", len, nt_errstr(status));
152 printf("sunk %d bytes\n", len);
157 BOOL torture_rpc_echo(int dummy)
160 struct dcerpc_pipe *p;
164 mem_ctx = talloc_init("torture_rpc_echo");
166 status = torture_rpc_connection(&p, "rpcecho");
167 if (!NT_STATUS_IS_OK(status)) {
171 if (!test_addone(p, mem_ctx)) {
175 if (!test_echodata(p, mem_ctx)) {
179 if (!test_sourcedata(p, mem_ctx)) {
183 if (!test_sinkdata(p, mem_ctx)) {
189 torture_rpc_close(p);