s3: Add a little test for the echo responder
authorVolker Lendecke <vl@samba.org>
Wed, 6 Oct 2010 16:46:43 +0000 (18:46 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 8 Oct 2010 19:11:45 +0000 (21:11 +0200)
source3/Makefile.in
source3/torture/proto.h
source3/torture/test_async_echo.c [new file with mode: 0644]
source3/torture/torture.c

index c80a8742d7c4a34dd501d3458dffef3872051497..4d2587fdaa231cec7c9e5d75a97a9a149204af35 100644 (file)
@@ -1192,6 +1192,7 @@ NMBLOOKUP_OBJ = utils/nmblookup.o $(PARAM_OBJ) $(LIBNMB_OBJ) \
 SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o torture/scanner.o torture/utable.o \
                torture/denytest.o torture/mangle_test.o \
                torture/nbench.o \
+               torture/test_async_echo.o \
                torture/test_posix_append.o
 
 SMBTORTURE_OBJ = $(SMBTORTURE_OBJ1) $(PARAM_OBJ) $(TLDAP_OBJ) \
@@ -1199,7 +1200,7 @@ SMBTORTURE_OBJ = $(SMBTORTURE_OBJ1) $(PARAM_OBJ) $(TLDAP_OBJ) \
        @LIBWBCLIENT_STATIC@ \
         ../nsswitch/libwbclient/wbc_async.o \
         ../nsswitch/libwbclient/wb_reqtrans.o \
-       $(LIBNDR_GEN_OBJ0)
+       $(LIBMSRPC_OBJ) $(LIBMSRPC_GEN_OBJ) $(LIBCLI_ECHO_OBJ)
 
 MASKTEST_OBJ = torture/masktest.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) \
                  $(LIB_NONSMBD_OBJ) \
index 4f9a1807aa62a40bca56f82da205822acbb24a56..63004345ca9020f092932b83ca83c0c61cc7a50e 100644 (file)
@@ -84,5 +84,6 @@ bool torture_casetable(int dummy);
 bool run_posix_append(int dummy);
 
 bool run_nbench2(int dummy);
+bool run_async_echo(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_async_echo.c b/source3/torture/test_async_echo.c
new file mode 100644 (file)
index 0000000..13d4679
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+   Unix SMB/CIFS implementation.
+   Run the async echo responder
+   Copyright (C) Volker Lendecke 2010
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/proto.h"
+#include "librpc/gen_ndr/cli_echo.h"
+
+static void rpccli_sleep_done(struct tevent_req *req)
+{
+       int *done = (int *)tevent_req_callback_data_void(req);
+       NTSTATUS status;
+       uint32_t result;
+
+       status = rpccli_echo_TestSleep_recv(req, talloc_tos(), &result);
+       TALLOC_FREE(req);
+       printf("sleep returned %s, %d\n", nt_errstr(status), (int)result);
+       *done -= 1;
+}
+
+static void cli_echo_done(struct tevent_req *req)
+{
+       int *done = (int *)tevent_req_callback_data_void(req);
+       NTSTATUS status;
+
+       status = cli_echo_recv(req);
+       TALLOC_FREE(req);
+       printf("echo returned %s\n", nt_errstr(status));
+       *done -= 1;
+}
+
+static void cli_close_done(struct tevent_req *req)
+{
+       int *done = (int *)tevent_req_callback_data_void(req);
+       NTSTATUS status;
+       size_t written;
+
+       status = cli_write_andx_recv(req, &written);
+       TALLOC_FREE(req);
+       printf("close returned %s\n", nt_errstr(status));
+       *done -= 1;
+}
+
+bool run_async_echo(int dummy)
+{
+       struct cli_state *cli = NULL;
+       struct rpc_pipe_client *p;
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status;
+       bool ret = false;
+       int i, num_reqs;
+       uint8_t buf[32768];
+
+       printf("Starting ASYNC_ECHO\n");
+
+       ev = tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               printf("tevent_context_init failed\n");
+               goto fail;
+       }
+
+       if (!torture_open_connection(&cli, 0)) {
+               printf("torture_open_connection failed\n");
+               goto fail;
+       }
+       status = cli_rpc_pipe_open_noauth(cli, &ndr_table_rpcecho.syntax_id,
+                                         &p);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Could not open echo pipe: %s\n", nt_errstr(status));
+               goto fail;
+       }
+
+       num_reqs = 0;
+
+       req = rpccli_echo_TestSleep_send(ev, ev, p, 15);
+       if (req == NULL) {
+               printf("rpccli_echo_TestSleep_send failed\n");
+               goto fail;
+       }
+       tevent_req_set_callback(req, rpccli_sleep_done, &num_reqs);
+       num_reqs += 1;
+
+       req = cli_echo_send(ev, ev, cli, 1, data_blob_const("hello", 5));
+       if (req == NULL) {
+               printf("cli_echo_send failed\n");
+               goto fail;
+       }
+       tevent_req_set_callback(req, cli_echo_done, &num_reqs);
+       num_reqs += 1;
+
+       memset(buf, 0, sizeof(buf));
+
+       for (i=0; i<10; i++) {
+               req = cli_write_andx_send(ev, ev, cli, 4711, 0, buf, 0, sizeof(buf));
+               if (req == NULL) {
+                       printf("cli_close_send failed\n");
+                       goto fail;
+               }
+               tevent_req_set_callback(req, cli_close_done, &num_reqs);
+               num_reqs += 1;
+
+               req = cli_echo_send(ev, ev, cli, 1, data_blob_const("hello", 5));
+               if (req == NULL) {
+                       printf("cli_echo_send failed\n");
+                       goto fail;
+               }
+               tevent_req_set_callback(req, cli_echo_done, &num_reqs);
+               num_reqs += 1;
+       }
+
+       while (num_reqs > 0) {
+               if (tevent_loop_once(ev) != 0) {
+                       printf("tevent_loop_once failed\n");
+                       goto fail;
+               }
+       }
+
+       TALLOC_FREE(p);
+
+       ret = true;
+fail:
+       if (cli != NULL) {
+               torture_close_connection(cli);
+       }
+       return ret;
+}
index 122c69434d345f0bd6c032dcc86cda086694ff09..abec6111bd49f9511fb394b98090b09469447523 100644 (file)
@@ -7777,6 +7777,7 @@ static struct {
        {"OPEN", run_opentest, 0},
        {"POSIX", run_simple_posix_open_test, 0},
        {"POSIX-APPEND", run_posix_append, 0},
+       {"ASYNC-ECHO", run_async_echo, 0},
        { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
        { "SHORTNAME-TEST", run_shortname_test, 0},
 #if 1