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/messaging.c | 143 ++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 source4/lib/messaging/tests/messaging.c (limited to 'source4/lib/messaging/tests/messaging.c') 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/messaging.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source4/lib/messaging/tests/messaging.c') 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 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/messaging.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/lib/messaging/tests/messaging.c') 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 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/messaging.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/messaging/tests/messaging.c') 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/messaging.c') 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