diff options
author | Volker Lendecke <vl@samba.org> | 2016-09-09 16:51:25 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2016-10-05 00:06:22 +0200 |
commit | f9a84411e81d67311452228979648c9dd87a4631 (patch) | |
tree | 88669ceffd576db6e77cd7487e79bea2d61b02b1 /source4/lib/messaging/tests | |
parent | ddffebc0fed80c9937e39c3a8b6b39fc78c2c372 (diff) | |
download | samba-f9a84411e81d67311452228979648c9dd87a4631.tar.gz |
messaging: add an overflow test
Send 1000 messages without picking them up. Then destroy the sending messaging
context.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source4/lib/messaging/tests')
-rw-r--r-- | source4/lib/messaging/tests/messaging.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index 51195a18113..d8290ece75c 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -26,6 +26,8 @@ #include "cluster/cluster.h" #include "param/param.h" #include "torture/local/proto.h" +#include "system/select.h" +#include "system/filesys.h" static uint32_t msg_pong; @@ -134,9 +136,83 @@ static bool test_ping_speed(struct torture_context *tctx) return true; } +static bool test_messaging_overflow(struct torture_context *tctx) +{ + struct imessaging_context *msg_ctx; + ssize_t nwritten, nread; + pid_t child; + char c = 0; + int up_pipe[2], down_pipe[2]; + int i, ret, child_status; + + ret = pipe(up_pipe); + torture_assert(tctx, ret == 0, "pipe failed"); + ret = pipe(down_pipe); + torture_assert(tctx, ret == 0, "pipe failed"); + + child = fork(); + if (child < 0) { + torture_fail(tctx, "fork failed"); + } + + if (child == 0) { + torture_assert(tctx, ret == 0, "close failed"); + + msg_ctx = imessaging_init(tctx, tctx->lp_ctx, + cluster_id(getpid(), 0), + tctx->ev); + torture_assert(tctx, msg_ctx != NULL, + "imessaging_init failed"); + + do { + nwritten = write(up_pipe[1], &c, 1); + } while ((nwritten == -1) && (errno == EINTR)); + + ret = close(down_pipe[1]); + + do { + nread = read(down_pipe[0], &c, 1); + } while ((nread == -1) && (errno == EINTR)); + + exit(0); + } + + do { + nread = read(up_pipe[0], &c, 1); + } while ((nread == -1) && (errno == EINTR)); + + msg_ctx = imessaging_init(tctx, tctx->lp_ctx, cluster_id(getpid(), 0), + tctx->ev); + torture_assert(tctx, msg_ctx != NULL, "imessaging_init failed"); + + for (i=0; i<1000; i++) { + NTSTATUS status; + status = imessaging_send(msg_ctx, cluster_id(child, 0), + MSG_PING, NULL); + torture_assert_ntstatus_ok(tctx, status, + "imessaging_send failed"); + } + + tevent_loop_once(tctx->ev); + + talloc_free(msg_ctx); + + ret = close(down_pipe[1]); + torture_assert(tctx, ret == 0, "close failed"); + + ret = waitpid(child, &child_status, 0); + torture_assert(tctx, ret == child, "wrong child exited"); + torture_assert(tctx, child_status == 0, "child failed"); + + poll(NULL, 0, 500); + + 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, "overflow", test_messaging_overflow); torture_suite_add_simple_test(s, "ping_speed", test_ping_speed); return s; } |