From f924ac97446503f6b43d8667e8a273e55ec71854 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 7 Nov 2007 23:53:57 +0100 Subject: r25902: Move messaging tests to same directory as code. (This used to be commit d174dcbb76f3079a5f536f841bfffab3d7cd51e9) --- source4/lib/messaging/tests/irpc.c | 266 ++++++++++++++++++++++++++++++++ source4/lib/messaging/tests/messaging.c | 143 +++++++++++++++++ 2 files changed, 409 insertions(+) create mode 100644 source4/lib/messaging/tests/irpc.c create mode 100644 source4/lib/messaging/tests/messaging.c (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c new file mode 100644 index 0000000000..aae6b4882e --- /dev/null +++ b/source4/lib/messaging/tests/irpc.c @@ -0,0 +1,266 @@ +/* + 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 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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "lib/messaging/irpc.h" +#include "librpc/gen_ndr/ndr_echo.h" +#include "torture/torture.h" +#include "cluster/cluster.h" +#include "param/param.h" + +const uint32_t MSG_ID1 = 1, MSG_ID2 = 2; + +static bool test_debug; + +struct irpc_test_data +{ + struct messaging_context *msg_ctx1, *msg_ctx2; + struct event_context *ev; +}; + +/* + 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; + if (test_debug) { + printf("irpc_AddOne: in=%u in+1=%u out=%u\n", + r->in.in_data, r->in.in_data+1, *r->out.out_data); + } + return NT_STATUS_OK; +} + +/* + a deferred reply to echodata +*/ +static void deferred_echodata(struct event_context *ev, struct timed_event *te, + struct timeval t, void *private) +{ + struct irpc_message *irpc = talloc_get_type(private, struct irpc_message); + struct echo_EchoData *r = irpc->data; + r->out.out_data = talloc_memdup(r, r->in.in_data, r->in.len); + if (r->out.out_data == NULL) { + irpc_send_reply(irpc, NT_STATUS_NO_MEMORY); + } + printf("sending deferred reply\n"); + irpc_send_reply(irpc, NT_STATUS_OK); +} + + +/* + serve up EchoData over the irpc system +*/ +static NTSTATUS irpc_EchoData(struct irpc_message *irpc, struct echo_EchoData *r) +{ + irpc->defer_reply = true; + event_add_timed(irpc->ev, irpc, timeval_zero(), deferred_echodata, irpc); + return NT_STATUS_OK; +} + + +/* + test a addone call over the internal messaging system +*/ +static bool test_addone(struct torture_context *test, const void *_data, + const void *_value) +{ + struct echo_AddOne r; + NTSTATUS status; + const struct irpc_test_data *data = (const struct irpc_test_data *)_data; + uint32_t value = (uint32_t)_value; + + /* make the call */ + r.in.in_data = value; + + test_debug = true; + status = IRPC_CALL(data->msg_ctx1, cluster_id(MSG_ID2), + rpcecho, ECHO_ADDONE, &r, test); + test_debug = false; + torture_assert_ntstatus_ok(test, status, "AddOne failed"); + + /* check the answer */ + torture_assert(test, *r.out.out_data == r.in.in_data + 1, + "AddOne wrong answer"); + + torture_comment(test, "%u + 1 = %u\n", r.in.in_data, *r.out.out_data); + return true; +} + +/* + test a echodata call over the internal messaging system +*/ +static bool test_echodata(struct torture_context *tctx, + const void *tcase_data, + const void *test_data) +{ + struct echo_EchoData r; + NTSTATUS status; + const struct irpc_test_data *data = (const struct irpc_test_data *)tcase_data; + TALLOC_CTX *mem_ctx = tctx; + + /* make the call */ + r.in.in_data = (unsigned char *)talloc_strdup(mem_ctx, "0123456789"); + r.in.len = strlen((char *)r.in.in_data); + + status = IRPC_CALL(data->msg_ctx1, cluster_id(MSG_ID2), + rpcecho, ECHO_ECHODATA, &r, + mem_ctx); + torture_assert_ntstatus_ok(tctx, status, "EchoData failed"); + + /* check the answer */ + if (memcmp(r.out.out_data, r.in.in_data, r.in.len) != 0) { + NDR_PRINT_OUT_DEBUG(echo_EchoData, &r); + torture_fail(tctx, "EchoData wrong answer"); + } + + torture_comment(tctx, "Echo '%*.*s' -> '%*.*s'\n", + r.in.len, r.in.len, + r.in.in_data, + r.in.len, r.in.len, + r.out.out_data); + return true; +} + + +static void irpc_callback(struct irpc_request *irpc) +{ + struct echo_AddOne *r = (struct echo_AddOne *)irpc->r; + int *pong_count = (int *)irpc->async.private; + NTSTATUS status = irpc_call_recv(irpc); + if (!NT_STATUS_IS_OK(status)) { + printf("irpc call failed - %s\n", nt_errstr(status)); + } + if (*r->out.out_data != r->in.in_data + 1) { + printf("AddOne wrong answer - %u + 1 = %u should be %u\n", + r->in.in_data, *r->out.out_data, r->in.in_data+1); + } + (*pong_count)++; +} + +/* + test echo speed +*/ +static bool test_speed(struct torture_context *tctx, + const void *tcase_data, + const void *test_data) +{ + int ping_count = 0; + int pong_count = 0; + const struct irpc_test_data *data = (const struct irpc_test_data *)tcase_data; + struct timeval tv; + struct echo_AddOne r; + TALLOC_CTX *mem_ctx = tctx; + int timelimit = torture_setting_int(tctx, "timelimit", 10); + + tv = timeval_current(); + + r.in.in_data = 0; + + torture_comment(tctx, "Sending echo for %d seconds\n", timelimit); + while (timeval_elapsed(&tv) < timelimit) { + struct irpc_request *irpc; + + irpc = IRPC_CALL_SEND(data->msg_ctx1, cluster_id(MSG_ID2), + rpcecho, ECHO_ADDONE, + &r, mem_ctx); + torture_assert(tctx, irpc != NULL, "AddOne send failed"); + + irpc->async.fn = irpc_callback; + irpc->async.private = &pong_count; + + ping_count++; + + while (ping_count > pong_count + 20) { + event_loop_once(data->ev); + } + } + + torture_comment(tctx, "waiting for %d remaining replies (done %d)\n", + ping_count - pong_count, pong_count); + while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { + event_loop_once(data->ev); + } + + torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed"); + + torture_comment(tctx, "echo rate of %.0f messages/sec\n", + (ping_count+pong_count)/timeval_elapsed(&tv)); + return true; +} + + +static bool irpc_setup(struct torture_context *tctx, void **_data) +{ + struct irpc_test_data *data; + + *_data = data = talloc(tctx, struct irpc_test_data); + + lp_set_cmdline(global_loadparm, "pid directory", "piddir.tmp"); + + data->ev = tctx->ev; + torture_assert(tctx, data->msg_ctx1 = + messaging_init(tctx, + lp_messaging_path(tctx, global_loadparm), + cluster_id(MSG_ID1), data->ev), + "Failed to init first messaging context"); + + torture_assert(tctx, data->msg_ctx2 = + messaging_init(tctx, + lp_messaging_path(tctx, global_loadparm), + cluster_id(MSG_ID2), data->ev), + "Failed to init second messaging context"); + + /* register the server side function */ + IRPC_REGISTER(data->msg_ctx1, rpcecho, ECHO_ADDONE, irpc_AddOne, NULL); + IRPC_REGISTER(data->msg_ctx2, rpcecho, ECHO_ADDONE, irpc_AddOne, NULL); + + IRPC_REGISTER(data->msg_ctx1, rpcecho, ECHO_ECHODATA, irpc_EchoData, NULL); + IRPC_REGISTER(data->msg_ctx2, rpcecho, ECHO_ECHODATA, irpc_EchoData, NULL); + + return true; +} + +struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "IRPC"); + struct torture_tcase *tcase = torture_suite_add_tcase(suite, "irpc"); + int i; + uint32_t *values = talloc_array(tcase, uint32_t, 5); + + values[0] = 0; + values[1] = 0x7FFFFFFE; + values[2] = 0xFFFFFFFE; + values[3] = 0xFFFFFFFF; + values[4] = random() & 0xFFFFFFFF; + + tcase->setup = irpc_setup; + + for (i = 0; i < 5; i++) { + torture_tcase_add_test(tcase, "addone", test_addone, (void *)values[i]); + } + + torture_tcase_add_test(tcase, "echodata", test_echodata, NULL); + torture_tcase_add_test(tcase, "speed", test_speed, NULL); + + return suite; +} diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c new file mode 100644 index 0000000000..bf2b83a0e4 --- /dev/null +++ b/source4/lib/messaging/tests/messaging.c @@ -0,0 +1,143 @@ +/* + Unix SMB/CIFS implementation. + + local test for messaging 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 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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "lib/messaging/irpc.h" +#include "torture/torture.h" +#include "cluster/cluster.h" +#include "param/param.h" + + +static uint32_t msg_pong; + +static void ping_message(struct messaging_context *msg, void *private, + uint32_t msg_type, struct server_id src, DATA_BLOB *data) +{ + NTSTATUS status; + status = messaging_send(msg, src, msg_pong, data); + if (!NT_STATUS_IS_OK(status)) { + printf("pong failed - %s\n", nt_errstr(status)); + } +} + +static void pong_message(struct messaging_context *msg, void *private, + uint32_t msg_type, struct server_id src, DATA_BLOB *data) +{ + int *count = private; + (*count)++; +} + +static void exit_message(struct messaging_context *msg, void *private, + uint32_t msg_type, struct server_id src, DATA_BLOB *data) +{ + talloc_free(private); + exit(0); +} + +/* + test ping speed +*/ +static bool test_ping_speed(struct torture_context *tctx) +{ + struct event_context *ev; + struct messaging_context *msg_client_ctx; + struct messaging_context *msg_server_ctx; + int ping_count = 0; + int pong_count = 0; + struct timeval tv; + int timelimit = torture_setting_int(tctx, "timelimit", 10); + uint32_t msg_ping, msg_exit; + TALLOC_CTX *mem_ctx = tctx; + + lp_set_cmdline(global_loadparm, "pid directory", "piddir.tmp"); + + ev = tctx->ev; + + msg_server_ctx = messaging_init(mem_ctx, + lp_messaging_path(tctx, global_loadparm), + cluster_id(1), ev); + + torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context"); + + messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping); + messaging_register_tmp(msg_server_ctx, mem_ctx, exit_message, &msg_exit); + + msg_client_ctx = messaging_init(mem_ctx, + lp_messaging_path(mem_ctx, global_loadparm), + cluster_id(2), ev); + + torture_assert(tctx, msg_client_ctx != NULL, + "msg_client_ctx messaging_init() failed"); + + messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong); + + tv = timeval_current(); + + torture_comment(tctx, "Sending pings for %d seconds\n", timelimit); + while (timeval_elapsed(&tv) < timelimit) { + DATA_BLOB data; + NTSTATUS status1, status2; + + data.data = discard_const_p(uint8_t, "testing"); + data.length = strlen((const char *)data.data); + + status1 = messaging_send(msg_client_ctx, cluster_id(1), msg_ping, &data); + status2 = messaging_send(msg_client_ctx, cluster_id(1), msg_ping, NULL); + + torture_assert_ntstatus_ok(tctx, status1, "msg1 failed"); + ping_count++; + + torture_assert_ntstatus_ok(tctx, status2, "msg2 failed"); + ping_count++; + + while (ping_count > pong_count + 20) { + event_loop_once(ev); + } + } + + torture_comment(tctx, "waiting for %d remaining replies (done %d)\n", + ping_count - pong_count, pong_count); + while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { + event_loop_once(ev); + } + + torture_comment(tctx, "sending exit\n"); + messaging_send(msg_client_ctx, cluster_id(1), msg_exit, NULL); + + torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed"); + + torture_comment(tctx, "ping rate of %.0f messages/sec\n", + (ping_count+pong_count)/timeval_elapsed(&tv)); + + talloc_free(msg_client_ctx); + talloc_free(msg_server_ctx); + + talloc_free(ev); + return true; +} + +struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *s = torture_suite_create(mem_ctx, "MESSAGING"); + torture_suite_add_simple_test(s, "ping_speed", test_ping_speed); + return s; +} -- cgit From 2f8dc4f48f1802baa3405e7803563f6840e0d1b3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 21:25:06 +0100 Subject: r26266: Remove more global_loadparm uses. (This used to be commit 99113075c4a96679bcec4f4d6bba4acb3dee4245) --- source4/lib/messaging/tests/irpc.c | 4 ++-- source4/lib/messaging/tests/messaging.c | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index aae6b4882e..28676c21c7 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -215,12 +215,12 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) *_data = data = talloc(tctx, struct irpc_test_data); - lp_set_cmdline(global_loadparm, "pid directory", "piddir.tmp"); + lp_set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp"); data->ev = tctx->ev; torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, - lp_messaging_path(tctx, global_loadparm), + lp_messaging_path(tctx, tctx->lp_ctx), cluster_id(MSG_ID1), data->ev), "Failed to init first messaging context"); diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index bf2b83a0e4..ba3d2f91d6 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -66,23 +66,22 @@ static bool test_ping_speed(struct torture_context *tctx) struct timeval tv; int timelimit = torture_setting_int(tctx, "timelimit", 10); uint32_t msg_ping, msg_exit; - TALLOC_CTX *mem_ctx = tctx; - lp_set_cmdline(global_loadparm, "pid directory", "piddir.tmp"); + lp_set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp"); ev = tctx->ev; - msg_server_ctx = messaging_init(mem_ctx, - lp_messaging_path(tctx, global_loadparm), + msg_server_ctx = messaging_init(tctx, + lp_messaging_path(tctx, tctx->lp_ctx), cluster_id(1), ev); torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context"); messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping); - messaging_register_tmp(msg_server_ctx, mem_ctx, exit_message, &msg_exit); + messaging_register_tmp(msg_server_ctx, tctx, exit_message, &msg_exit); - msg_client_ctx = messaging_init(mem_ctx, - lp_messaging_path(mem_ctx, global_loadparm), + msg_client_ctx = messaging_init(tctx, + lp_messaging_path(tctx, tctx->lp_ctx), cluster_id(2), ev); torture_assert(tctx, msg_client_ctx != NULL, -- cgit From 6c77f353d3d952b46b401ab29837ba5b75e353c2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Dec 2007 02:37:13 +0100 Subject: r26328: remove more uses of global_loadparm. (This used to be commit 40ae12c08647c47a9c504d39ee6f61c32b4e5748) --- source4/lib/messaging/tests/irpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index 28676c21c7..0618adcfb2 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -226,7 +226,7 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) torture_assert(tctx, data->msg_ctx2 = messaging_init(tctx, - lp_messaging_path(tctx, global_loadparm), + lp_messaging_path(tctx, tctx->lp_ctx), cluster_id(MSG_ID2), data->ev), "Failed to init second messaging context"); -- cgit From 84b476394713d4f2b84782c59dcc084a25af360f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 23:23:25 +0100 Subject: r26441: Remove global_loadparm uses. (This used to be commit 32007c6277efa46341da7741b749a98633d71640) --- source4/lib/messaging/tests/irpc.c | 8 ++++++-- source4/lib/messaging/tests/messaging.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index 0618adcfb2..ce3d1045e5 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -221,13 +221,17 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(MSG_ID1), data->ev), + cluster_id(MSG_ID1), + lp_iconv_convenience(tctx->lp_ctx), + data->ev), "Failed to init first messaging context"); torture_assert(tctx, data->msg_ctx2 = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(MSG_ID2), data->ev), + cluster_id(MSG_ID2), + lp_iconv_convenience(tctx->lp_ctx), + data->ev), "Failed to init second messaging context"); /* register the server side function */ diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index ba3d2f91d6..0df04bce2b 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -73,7 +73,9 @@ static bool test_ping_speed(struct torture_context *tctx) msg_server_ctx = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(1), ev); + cluster_id(1), + lp_iconv_convenience(tctx->lp_ctx), + ev); torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context"); @@ -82,7 +84,9 @@ static bool test_ping_speed(struct torture_context *tctx) msg_client_ctx = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(2), ev); + cluster_id(2), + lp_iconv_convenience(tctx->lp_ctx), + ev); torture_assert(tctx, msg_client_ctx != NULL, "msg_client_ctx messaging_init() failed"); -- cgit From 3c744ddd2c33a9a06013f357261b8ea86804e8e8 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 24 Dec 2007 13:04:56 -0600 Subject: r26588: Janitorial: Rename torture_*_add_*test to torture_*_add_*test_const. Also rename the corresponding wrap_ functions. (This used to be commit e59c2eaf681f076d175b9779d1c27b5f74a57c96) --- source4/lib/messaging/tests/irpc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index ce3d1045e5..a2995fc983 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -260,11 +260,12 @@ struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx) tcase->setup = irpc_setup; for (i = 0; i < 5; i++) { - torture_tcase_add_test(tcase, "addone", test_addone, (void *)values[i]); + torture_tcase_add_test_const(tcase, "addone", test_addone, + (void *)values[i]); } - - torture_tcase_add_test(tcase, "echodata", test_echodata, NULL); - torture_tcase_add_test(tcase, "speed", test_speed, NULL); + + torture_tcase_add_test_const(tcase, "echodata", test_echodata, NULL); + torture_tcase_add_test_const(tcase, "speed", test_speed, NULL); return suite; } -- cgit From 77f71c1b65358723771354fd9ff1dc418b227ccc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 4 Feb 2008 17:51:38 +1100 Subject: Rework cluster_id() to take an additional argument, as we need .. to be unique in a prefork process environment. Andrew Bartlett and David Disseldorp (This used to be commit 931994a7f185bbc98924823e9e8cef1011dd0957) --- source4/lib/messaging/tests/irpc.c | 10 +++++----- source4/lib/messaging/tests/messaging.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index a2995fc983..d9b0548643 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -93,7 +93,7 @@ static bool test_addone(struct torture_context *test, const void *_data, r.in.in_data = value; test_debug = true; - status = IRPC_CALL(data->msg_ctx1, cluster_id(MSG_ID2), + status = IRPC_CALL(data->msg_ctx1, cluster_id(0, MSG_ID2), rpcecho, ECHO_ADDONE, &r, test); test_debug = false; torture_assert_ntstatus_ok(test, status, "AddOne failed"); @@ -122,7 +122,7 @@ static bool test_echodata(struct torture_context *tctx, r.in.in_data = (unsigned char *)talloc_strdup(mem_ctx, "0123456789"); r.in.len = strlen((char *)r.in.in_data); - status = IRPC_CALL(data->msg_ctx1, cluster_id(MSG_ID2), + status = IRPC_CALL(data->msg_ctx1, cluster_id(0, MSG_ID2), rpcecho, ECHO_ECHODATA, &r, mem_ctx); torture_assert_ntstatus_ok(tctx, status, "EchoData failed"); @@ -180,7 +180,7 @@ static bool test_speed(struct torture_context *tctx, while (timeval_elapsed(&tv) < timelimit) { struct irpc_request *irpc; - irpc = IRPC_CALL_SEND(data->msg_ctx1, cluster_id(MSG_ID2), + irpc = IRPC_CALL_SEND(data->msg_ctx1, cluster_id(0, MSG_ID2), rpcecho, ECHO_ADDONE, &r, mem_ctx); torture_assert(tctx, irpc != NULL, "AddOne send failed"); @@ -221,7 +221,7 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(MSG_ID1), + cluster_id(0, MSG_ID1), lp_iconv_convenience(tctx->lp_ctx), data->ev), "Failed to init first messaging context"); @@ -229,7 +229,7 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) torture_assert(tctx, data->msg_ctx2 = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(MSG_ID2), + cluster_id(0, MSG_ID2), lp_iconv_convenience(tctx->lp_ctx), data->ev), "Failed to init second messaging context"); diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index 0df04bce2b..45b573518c 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -73,7 +73,7 @@ static bool test_ping_speed(struct torture_context *tctx) msg_server_ctx = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(1), + cluster_id(0, 1), lp_iconv_convenience(tctx->lp_ctx), ev); @@ -84,7 +84,7 @@ static bool test_ping_speed(struct torture_context *tctx) msg_client_ctx = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(2), + cluster_id(0, 2), lp_iconv_convenience(tctx->lp_ctx), ev); @@ -103,8 +103,8 @@ static bool test_ping_speed(struct torture_context *tctx) data.data = discard_const_p(uint8_t, "testing"); data.length = strlen((const char *)data.data); - status1 = messaging_send(msg_client_ctx, cluster_id(1), msg_ping, &data); - status2 = messaging_send(msg_client_ctx, cluster_id(1), msg_ping, NULL); + status1 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, &data); + status2 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, NULL); torture_assert_ntstatus_ok(tctx, status1, "msg1 failed"); ping_count++; @@ -124,7 +124,7 @@ static bool test_ping_speed(struct torture_context *tctx) } torture_comment(tctx, "sending exit\n"); - messaging_send(msg_client_ctx, cluster_id(1), msg_exit, NULL); + messaging_send(msg_client_ctx, cluster_id(0, 1), msg_exit, NULL); torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed"); -- cgit From 8eaf64b47b775a9f71ae6052d5199e5c8a697226 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 16 Apr 2008 09:02:12 +0200 Subject: Now that we don't create a new event context, don't free it. This previously would free the torture provided global event context. Andrew Bartlett (This used to be commit 664f2fc49f32a081f14638571ee0db01a7863347) --- source4/lib/messaging/tests/messaging.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index 45b573518c..f66b3a5b43 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -134,7 +134,6 @@ static bool test_ping_speed(struct torture_context *tctx) talloc_free(msg_client_ctx); talloc_free(msg_server_ctx); - talloc_free(ev); return true; } -- cgit From 2067fc60c50c1ca527faccdaa1fff56eec2d4c08 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 16:47:12 +0200 Subject: Add tests for irpc python bindings. (This used to be commit 1ce0632afeb94a69bf286706b3b1f9f4be7ea91f) --- source4/lib/messaging/tests/bindings.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 source4/lib/messaging/tests/bindings.py (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/bindings.py b/source4/lib/messaging/tests/bindings.py new file mode 100644 index 0000000000..ffb4dae326 --- /dev/null +++ b/source4/lib/messaging/tests/bindings.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# 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 . +# + +from samba.irpc import Messaging +from unittest import TestCase + +class MessagingTests(TestCase): + pass -- cgit From d9a6f04ddd8074c36fc8073ec9bd183438801817 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 01:52:35 +0200 Subject: Provide access to server_id from python bindings, add more tests. (This used to be commit adcd87ad07abbf60a0152deae4b975a2401d701b) --- source4/lib/messaging/tests/bindings.py | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/bindings.py b/source4/lib/messaging/tests/bindings.py index ffb4dae326..3d58843799 100644 --- a/source4/lib/messaging/tests/bindings.py +++ b/source4/lib/messaging/tests/bindings.py @@ -22,4 +22,36 @@ from samba.irpc import Messaging from unittest import TestCase class MessagingTests(TestCase): - pass + def get_context(self, *args, **kwargs): + kwargs["messaging_path"] = "." + return Messaging(*args, **kwargs) + + def test_register(self): + x = self.get_context() + def callback(): + pass + msg_type = x.register(callback) + x.deregister(callback, msg_type) + + def test_assign_server_id(self): + x = self.get_context() + self.assertTrue(isinstance(x.server_id, tuple)) + self.assertEquals(3, len(x.server_id)) + + def test_ping_speed(self): + server_ctx = self.get_context((0, 1)) + def ping_callback(src, data): + server_ctx.send(src, data) + def exit_callback(): + print "received exit" + msg_ping = server_ctx.register(ping_callback) + msg_exit = server_ctx.register(exit_callback) + + def pong_callback(): + print "received pong" + client_ctx = self.get_context((0, 2)) + msg_pong = client_ctx.register(pong_callback) + + client_ctx.send((0,1), msg_ping, "testing") + client_ctx.send((0,1), msg_ping, "") + -- cgit From dce310ef4ec2eedb496e814cf341ad7caab821af Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 13:31:57 +0200 Subject: Remove evil hack which breaks Python bindings. (This used to be commit 1c179566cb39eb09e522dbce69230472a5d4e655) --- source4/lib/messaging/tests/bindings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/messaging/tests') diff --git a/source4/lib/messaging/tests/bindings.py b/source4/lib/messaging/tests/bindings.py index 3d58843799..c89538ddfa 100644 --- a/source4/lib/messaging/tests/bindings.py +++ b/source4/lib/messaging/tests/bindings.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # -from samba.irpc import Messaging +from samba.messaging import Messaging from unittest import TestCase class MessagingTests(TestCase): -- cgit