summaryrefslogtreecommitdiff
path: root/source4/torture/local
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-06-05 06:53:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:17:37 -0500
commitbf1ffa283caef6a3c98b5cc7f5bc8205c2818b06 (patch)
tree11b434e632aaee2472c906b7ddb9d14fdfd48e38 /source4/torture/local
parent03840652354598db203a3596077ecc55726880c8 (diff)
downloadsamba-bf1ffa283caef6a3c98b5cc7f5bc8205c2818b06.tar.gz
samba-bf1ffa283caef6a3c98b5cc7f5bc8205c2818b06.tar.bz2
samba-bf1ffa283caef6a3c98b5cc7f5bc8205c2818b06.zip
r7294: implemented the irpc messaging system. This is the core of the
management system I proposed on samba-technical a couple of days ago. Essentially it is a very lightweight way for any code in Samba to make IDL based rpc calls to anywhere else in the code, without the client or server having to go to the trouble of setting up a full rpc service. It can be used with any of our existing IDL, but I expect it will mostly be used for a new set of Samba specific management calls. The LOCAL-IRPC torture test demonstrates how it can be used by calling the echo_AddOne() call over this transport. (This used to be commit 3d589a09954eb8b318f567e1150b0c27412fb942)
Diffstat (limited to 'source4/torture/local')
-rw-r--r--source4/torture/local/irpc.c91
-rw-r--r--source4/torture/local/messaging.c1
2 files changed, 92 insertions, 0 deletions
diff --git a/source4/torture/local/irpc.c b/source4/torture/local/irpc.c
new file mode 100644
index 0000000000..3dc8c01da8
--- /dev/null
+++ b/source4/torture/local/irpc.c
@@ -0,0 +1,91 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local test for irpc code
+
+ Copyright (C) Andrew Tridgell 2004
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/messaging/irpc.h"
+#include "librpc/gen_ndr/ndr_echo.h"
+
+const uint32_t MSG_ID = 1;
+
+/*
+ serve up AddOne over the irpc system
+*/
+static NTSTATUS irpc_AddOne(struct irpc_message *irpc, struct echo_AddOne *r)
+{
+ *r->out.out_data = r->in.in_data + 1;
+ return NT_STATUS_OK;
+}
+
+
+/*
+ test a addone call over the internal messaging system
+*/
+static BOOL test_addone(TALLOC_CTX *mem_ctx, struct messaging_context *msg_ctx)
+{
+ struct echo_AddOne r;
+ NTSTATUS status;
+ uint32_t res;
+
+ /* register the server side function */
+ IRPC_REGISTER(msg_ctx, rpcecho, ECHO_ADDONE, irpc_AddOne);
+
+ /* make the call */
+ r.in.in_data = random();
+ r.out.out_data = &res;
+
+ status = IRPC_CALL(msg_ctx, MSG_ID, rpcecho, ECHO_ADDONE, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("AddOne failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ /* check the answer */
+ if (res != r.in.in_data + 1) {
+ printf("AddOne wrong answer - %u should be %u\n",
+ *r.out.out_data, r.in.in_data+1);
+ return False;
+ }
+
+ printf("%u + 1 = %u\n", r.in.in_data, res);
+
+ return True;
+}
+
+BOOL torture_local_irpc(void)
+{
+ TALLOC_CTX *mem_ctx = talloc_init("torture_local_irpc");
+ BOOL ret = True;
+ struct messaging_context *msg_ctx;
+ struct event_context *ev;
+
+ lp_set_cmdline("lock dir", "lockdir.tmp");
+
+ ev = event_context_init(mem_ctx);
+ msg_ctx = messaging_init(mem_ctx, MSG_ID, ev);
+
+ ret &= test_addone(mem_ctx, msg_ctx);
+
+ talloc_free(mem_ctx);
+
+ return True;
+}
diff --git a/source4/torture/local/messaging.c b/source4/torture/local/messaging.c
index 75e51fb534..85a6ff7e82 100644
--- a/source4/torture/local/messaging.c
+++ b/source4/torture/local/messaging.c
@@ -23,6 +23,7 @@
#include "includes.h"
#include "system/filesys.h"
#include "lib/events/events.h"
+#include "lib/messaging/irpc.h"
enum {MY_PING=1000, MY_PONG, MY_EXIT};