From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- source3/torture/msgtest.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 source3/torture/msgtest.c (limited to 'source3/torture/msgtest.c') diff --git a/source3/torture/msgtest.c b/source3/torture/msgtest.c new file mode 100644 index 0000000..1d2a8a9 --- /dev/null +++ b/source3/torture/msgtest.c @@ -0,0 +1,171 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) Andrew Tridgell 2000 + + 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 . +*/ + +/* + test code for internal messaging + */ + +#include "includes.h" +#include "messages.h" + +static int pong_count; + + +/**************************************************************************** +a useful function for testing the message system +****************************************************************************/ +static void pong_message(struct messaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + struct server_id pid, + DATA_BLOB *data) +{ + pong_count++; +} + + int main(int argc, char *argv[]) +{ + struct tevent_context *evt_ctx; + struct messaging_context *msg_ctx; + pid_t pid; + int i, n; + char buf[12]; + int ret; + TALLOC_CTX *frame = talloc_stackframe(); + + smb_init_locale(); + + setup_logging(argv[0], DEBUG_STDOUT); + + lp_load_global(get_dyn_CONFIGFILE()); + + if (!(evt_ctx = samba_tevent_context_init(NULL)) || + !(msg_ctx = messaging_init(NULL, evt_ctx))) { + fprintf(stderr, "could not init messaging context\n"); + TALLOC_FREE(frame); + exit(1); + } + + if (argc != 3) { + fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], + argv[0]); + TALLOC_FREE(frame); + exit(1); + } + + pid = atoi(argv[1]); + n = atoi(argv[2]); + + messaging_register(msg_ctx, NULL, MSG_PONG, pong_message); + + for (i=0;i pong_count + 20) { + ret = tevent_loop_once(evt_ctx); + if (ret != 0) { + break; + } + } + } + + printf("waiting for %d remaining replies (done %d)\n", + (int)(ping_count - pong_count), pong_count); + while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { + ret = tevent_loop_once(evt_ctx); + if (ret != 0) { + break; + } + } + + if (ping_count != pong_count) { + fprintf(stderr, "ping test failed! received %d, sent " + "%d\n", pong_count, (int)ping_count); + } + + printf("ping rate of %.0f messages/sec\n", + (ping_count+pong_count)/timeval_elapsed(&tv)); + } + + TALLOC_FREE(frame); + return (0); +} + -- cgit v1.2.3