diff options
author | Michael Adam <obnox@samba.org> | 2014-09-25 00:28:14 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-09-30 16:36:10 +0200 |
commit | f16dd644aaec0071b06057d74b54fb8b508a74f7 (patch) | |
tree | eb7c41a449d61014e889ab67bda6b57b10b61427 /source3/torture | |
parent | 797ada104e4a68f601e473c46dbb33871dda12e1 (diff) | |
download | samba-f16dd644aaec0071b06057d74b54fb8b508a74f7.tar.gz |
s3:torture: add LOCAL-MESSAGING-READ4 - send 1MB message
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'source3/torture')
-rw-r--r-- | source3/torture/proto.h | 1 | ||||
-rw-r--r-- | source3/torture/test_messaging_read.c | 230 | ||||
-rw-r--r-- | source3/torture/torture.c | 1 |
3 files changed, 232 insertions, 0 deletions
diff --git a/source3/torture/proto.h b/source3/torture/proto.h index a1d4151a0d9..b12c8bed2af 100644 --- a/source3/torture/proto.h +++ b/source3/torture/proto.h @@ -116,6 +116,7 @@ bool run_bench_pthreadpool(int dummy); bool run_messaging_read1(int dummy); bool run_messaging_read2(int dummy); bool run_messaging_read3(int dummy); +bool run_messaging_read4(int dummy); bool run_messaging_fdpass1(int dummy); bool run_messaging_fdpass2(int dummy); bool run_oplock_cancel(int dummy); diff --git a/source3/torture/test_messaging_read.c b/source3/torture/test_messaging_read.c index ef054ed47ab..9c4017c36f2 100644 --- a/source3/torture/test_messaging_read.c +++ b/source3/torture/test_messaging_read.c @@ -470,3 +470,233 @@ fail: TALLOC_FREE(ev); return retval; } + +/** + * read4: + * + * test transferring a big payload. + */ + +#define MSG_TORTURE_READ4 0xF104 + +static bool read4_child(int ready_fd) +{ + struct tevent_context *ev = NULL; + struct messaging_context *msg_ctx = NULL; + TALLOC_CTX *frame = talloc_stackframe(); + bool retval = false; + uint8_t c = 1; + struct tevent_req *subreq; + int ret; + ssize_t bytes; + struct messaging_rec *rec; + bool ok; + + ev = samba_tevent_context_init(frame); + if (ev == NULL) { + fprintf(stderr, "child: tevent_context_init failed\n"); + goto done; + } + + msg_ctx = messaging_init(ev, ev); + if (msg_ctx == NULL) { + fprintf(stderr, "child: messaging_init failed\n"); + goto done; + } + + printf("child: telling parent we're ready to receive messages\n"); + + /* Tell the parent we are ready to receive mesages. */ + bytes = write(ready_fd, &c, 1); + if (bytes != 1) { + perror("child: failed to write to ready_fd"); + goto done; + } + + printf("child: waiting for messages\n"); + + subreq = messaging_read_send(frame, /* TALLOC_CTX */ + ev, msg_ctx, + MSG_TORTURE_READ4); + if (subreq == NULL) { + fprintf(stderr, "child: messaging_read_send failed\n"); + goto done; + } + + ok = tevent_req_poll(subreq, ev); + if (!ok) { + fprintf(stderr, "child: tevent_req_poll failed\n"); + goto done; + } + + printf("child: receiving message\n"); + + ret = messaging_read_recv(subreq, frame, &rec); + TALLOC_FREE(subreq); + if (ret != 0) { + fprintf(stderr, "child: messaging_read_recv failed\n"); + goto done; + } + + printf("child: received message\n"); + + /* Tell the parent we are done. */ + bytes = write(ready_fd, &c, 1); + if (bytes != 1) { + perror("child: failed to write to ready_fd"); + goto done; + } + + printf("child: done\n"); + + retval = true; + +done: + TALLOC_FREE(frame); + return retval; +} + +struct child_done_state { + int fd; + bool done; +}; + +static void child_done_cb(struct tevent_context *ev, + struct tevent_fd *fde, + uint16_t flags, + void *private_data) +{ + struct child_done_state *state = + (struct child_done_state *)private_data; + char c = 0; + ssize_t bytes; + + bytes = read(state->fd, &c, 1); + if (bytes != 1) { + perror("parent: read from ready_fd failed"); + } + + state->done = true; +} + +static bool read4_parent(pid_t child_pid, int ready_fd) +{ + struct tevent_context *ev = NULL; + struct messaging_context *msg_ctx = NULL; + bool retval = false; + int ret; + NTSTATUS status; + struct server_id dst; + TALLOC_CTX *frame = talloc_stackframe(); + uint8_t c; + ssize_t bytes; + struct iovec iov; + DATA_BLOB blob; + struct tevent_fd *child_done_fde; + struct child_done_state child_state; + + /* wait until the child is ready to receive messages */ + bytes = read(ready_fd, &c, 1); + if (bytes != 1) { + perror("parent: read from ready_fd failed"); + goto done; + } + + printf("parent: child is ready to receive messages\n"); + + ev = samba_tevent_context_init(frame); + if (ev == NULL) { + fprintf(stderr, "parent: tevent_context_init failed\n"); + goto done; + } + + msg_ctx = messaging_init(ev, ev); + if (msg_ctx == NULL) { + fprintf(stderr, "parent: messaging_init failed\n"); + goto done; + } + + child_state.fd = ready_fd; + child_state.done = false; + + child_done_fde = tevent_add_fd(ev, ev, ready_fd, TEVENT_FD_READ, + child_done_cb, &child_state); + if (child_done_fde == NULL) { + fprintf(stderr, + "parent: failed tevent_add_fd for child done\n"); + goto done; + } + + /* + * Send a 1M payload with the message. + */ + blob = data_blob_talloc_zero(frame, 1000*1000); + iov.iov_base = blob.data; + iov.iov_len = blob.length; + + dst = messaging_server_id(msg_ctx); + dst.pid = child_pid; + + printf("parent: sending message to child\n"); + + status = messaging_send_iov(msg_ctx, dst, MSG_TORTURE_READ4, &iov, 1, + NULL, 0); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, "parent: messaging_send_iov failed: %s\n", + nt_errstr(status)); + goto done; + } + + printf("parent: waiting for child to confirm\n"); + + while (!child_state.done) { + ret = tevent_loop_once(ev); + if (ret != 0) { + fprintf(stderr, "parent: tevent_loop_once failed\n"); + goto done; + } + } + + printf("parent: child confirmed\n"); + + ret = waitpid(child_pid, NULL, 0); + if (ret == -1) { + perror("parent: waitpid failed"); + goto done; + } + + printf("parent: done\n"); + + retval = true; + +done: + TALLOC_FREE(frame); + return retval; +} + +bool run_messaging_read4(int dummy) +{ + bool retval = false; + pid_t child_pid; + int ready_pipe[2]; + int ret; + + ret = pipe(ready_pipe); + if (ret != 0) { + perror("parent: pipe failed for ready_pipe"); + return retval; + } + + child_pid = fork(); + if (child_pid == -1) { + perror("fork failed"); + } else if (child_pid == 0) { + close(ready_pipe[0]); + retval = read4_child(ready_pipe[1]); + } else { + close(ready_pipe[1]); + retval = read4_parent(child_pid, ready_pipe[0]); + } + + return retval; +} diff --git a/source3/torture/torture.c b/source3/torture/torture.c index ebc81db9d5f..deb0e60a2f5 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -9606,6 +9606,7 @@ static struct { { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 }, { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 }, { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 }, + { "LOCAL-MESSAGING-READ4", run_messaging_read4, 0 }, { "LOCAL-MESSAGING-FDPASS1", run_messaging_fdpass1, 0 }, { "LOCAL-MESSAGING-FDPASS2", run_messaging_fdpass2, 0 }, { "LOCAL-BASE64", run_local_base64, 0}, |