diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-03-10 17:01:21 -0700 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-03-10 17:01:21 -0700 |
commit | e92d35d80be6e193cb547e94c6fbf3654542dbaa (patch) | |
tree | bede6f090b8cca1397728634b03b31cfa7a4334c /deps/uv/test | |
parent | b444392a98e66b49dfee8c7e36c59d4e7c6ea1ac (diff) | |
download | android-node-v8-e92d35d80be6e193cb547e94c6fbf3654542dbaa.tar.gz android-node-v8-e92d35d80be6e193cb547e94c6fbf3654542dbaa.tar.bz2 android-node-v8-e92d35d80be6e193cb547e94c6fbf3654542dbaa.zip |
uv: Upgrade to v0.11.22
Diffstat (limited to 'deps/uv/test')
-rw-r--r-- | deps/uv/test/benchmark-multi-accept.c | 27 | ||||
-rw-r--r-- | deps/uv/test/task.h | 29 | ||||
-rw-r--r-- | deps/uv/test/test-cwd-and-chdir.c | 6 | ||||
-rw-r--r-- | deps/uv/test/test-fs.c | 4 | ||||
-rw-r--r-- | deps/uv/test/test-ipc-send-recv.c | 40 | ||||
-rw-r--r-- | deps/uv/test/test-ipc.c | 41 | ||||
-rw-r--r-- | deps/uv/test/test-list.h | 2 | ||||
-rw-r--r-- | deps/uv/test/test-pipe-sendmsg.c | 169 |
8 files changed, 270 insertions, 48 deletions
diff --git a/deps/uv/test/benchmark-multi-accept.c b/deps/uv/test/benchmark-multi-accept.c index b1b0c1e3ce..da0c76df1b 100644 --- a/deps/uv/test/benchmark-multi-accept.c +++ b/deps/uv/test/benchmark-multi-accept.c @@ -83,10 +83,9 @@ static void ipc_connection_cb(uv_stream_t* ipc_pipe, int status); static void ipc_write_cb(uv_write_t* req, int status); static void ipc_close_cb(uv_handle_t* handle); static void ipc_connect_cb(uv_connect_t* req, int status); -static void ipc_read2_cb(uv_pipe_t* ipc_pipe, - ssize_t nread, - const uv_buf_t* buf, - uv_handle_type type); +static void ipc_read_cb(uv_stream_t* handle, + ssize_t nread, + const uv_buf_t* buf); static void ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); @@ -155,9 +154,9 @@ static void ipc_connect_cb(uv_connect_t* req, int status) { struct ipc_client_ctx* ctx; ctx = container_of(req, struct ipc_client_ctx, connect_req); ASSERT(0 == status); - ASSERT(0 == uv_read2_start((uv_stream_t*) &ctx->ipc_pipe, - ipc_alloc_cb, - ipc_read2_cb)); + ASSERT(0 == uv_read_start((uv_stream_t*) &ctx->ipc_pipe, + ipc_alloc_cb, + ipc_read_cb)); } @@ -171,16 +170,20 @@ static void ipc_alloc_cb(uv_handle_t* handle, } -static void ipc_read2_cb(uv_pipe_t* ipc_pipe, - ssize_t nread, - const uv_buf_t* buf, - uv_handle_type type) { +static void ipc_read_cb(uv_stream_t* handle, + ssize_t nread, + const uv_buf_t* buf) { struct ipc_client_ctx* ctx; uv_loop_t* loop; + uv_handle_type type; + uv_pipe_t* ipc_pipe; + ipc_pipe = (uv_pipe_t*) handle; ctx = container_of(ipc_pipe, struct ipc_client_ctx, ipc_pipe); loop = ipc_pipe->loop; + ASSERT(1 == uv_pipe_pending_count(ipc_pipe)); + type = uv_pipe_pending_type(ipc_pipe); if (type == UV_TCP) ASSERT(0 == uv_tcp_init(loop, (uv_tcp_t*) ctx->server_handle)); else if (type == UV_NAMED_PIPE) @@ -188,7 +191,7 @@ static void ipc_read2_cb(uv_pipe_t* ipc_pipe, else ASSERT(0); - ASSERT(0 == uv_accept((uv_stream_t*) &ctx->ipc_pipe, ctx->server_handle)); + ASSERT(0 == uv_accept(handle, ctx->server_handle)); uv_close((uv_handle_t*) &ctx->ipc_pipe, NULL); } diff --git a/deps/uv/test/task.h b/deps/uv/test/task.h index 3b786a8c6e..e890c77fe1 100644 --- a/deps/uv/test/task.h +++ b/deps/uv/test/task.h @@ -22,6 +22,8 @@ #ifndef TASK_H_ #define TASK_H_ +#include "uv.h" + #include <stdio.h> #include <stddef.h> #include <stdlib.h> @@ -112,8 +114,11 @@ typedef enum { /* This macro cleans up the main loop. This is used to avoid valgrind * warnings about memory being "leaked" by the main event loop. */ -#define MAKE_VALGRIND_HAPPY() \ - uv_loop_delete(uv_default_loop()) +#define MAKE_VALGRIND_HAPPY() \ + do { \ + close_loop(uv_default_loop()); \ + uv_loop_delete(uv_default_loop()); \ + } while (0) /* Just sugar for wrapping the main() for a task or helper. */ #define TEST_IMPL(name) \ @@ -204,4 +209,24 @@ static int snprintf(char* buf, size_t len, const char* fmt, ...) { #endif +#if defined(__clang__) || \ + defined(__GNUC__) || \ + defined(__INTEL_COMPILER) || \ + defined(__SUNPRO_C) +# define UNUSED __attribute__((unused)) +#else +# define UNUSED +#endif + +/* Fully close a loop */ +static void close_walk_cb(uv_handle_t* handle, void* arg) { + if (!uv_is_closing(handle)) + uv_close(handle, NULL); +} + +UNUSED static void close_loop(uv_loop_t* loop) { + uv_walk(loop, close_walk_cb, NULL); + uv_run(loop, UV_RUN_DEFAULT); +} + #endif /* TASK_H_ */ diff --git a/deps/uv/test/test-cwd-and-chdir.c b/deps/uv/test/test-cwd-and-chdir.c index f1082ac47f..6f6173192d 100644 --- a/deps/uv/test/test-cwd-and-chdir.c +++ b/deps/uv/test/test-cwd-and-chdir.c @@ -33,8 +33,8 @@ TEST_IMPL(cwd_and_chdir) { char* last_slash; int err; - size = sizeof(buffer_orig) / sizeof(buffer_orig[0]); - err = uv_cwd(buffer_orig, size); + size = sizeof(buffer_orig); + err = uv_cwd(buffer_orig, &size); ASSERT(err == 0); /* Remove trailing slash unless at a root directory. */ @@ -55,7 +55,7 @@ TEST_IMPL(cwd_and_chdir) { err = uv_chdir(buffer_orig); ASSERT(err == 0); - err = uv_cwd(buffer_new, size); + err = uv_cwd(buffer_new, &size); ASSERT(err == 0); ASSERT(strcmp(buffer_orig, buffer_new) == 0); diff --git a/deps/uv/test/test-fs.c b/deps/uv/test/test-fs.c index 940672f8bc..306ec6b0d4 100644 --- a/deps/uv/test/test-fs.c +++ b/deps/uv/test/test-fs.c @@ -1465,8 +1465,10 @@ TEST_IMPL(fs_symlink_dir) { #ifdef _WIN32 { static char src_path_buf[PATHMAX]; + size_t size; + size = sizeof(src_path_buf); strcpy(src_path_buf, "\\\\?\\"); - uv_cwd(src_path_buf + 4, sizeof(src_path_buf)); + uv_cwd(src_path_buf + 4, &size); strcat(src_path_buf, "\\test_dir\\"); test_dir = src_path_buf; } diff --git a/deps/uv/test/test-ipc-send-recv.c b/deps/uv/test/test-ipc-send-recv.c index b2b5aa0e92..d9b913339d 100644 --- a/deps/uv/test/test-ipc-send-recv.c +++ b/deps/uv/test/test-ipc-send-recv.c @@ -60,15 +60,20 @@ static void alloc_cb(uv_handle_t* handle, } -static void recv_cb(uv_pipe_t* handle, +static void recv_cb(uv_stream_t* handle, ssize_t nread, - const uv_buf_t* buf, - uv_handle_type pending) { + const uv_buf_t* buf) { + uv_handle_type pending; + uv_pipe_t* pipe; int r; - ASSERT(pending == ctx.expected_type); - ASSERT(handle == &ctx.channel); + pipe = (uv_pipe_t*) handle; + ASSERT(pipe == &ctx.channel); ASSERT(nread >= 0); + ASSERT(1 == uv_pipe_pending_count(pipe)); + + pending = uv_pipe_pending_type(pipe); + ASSERT(pending == ctx.expected_type); if (pending == UV_NAMED_PIPE) r = uv_pipe_init(ctx.channel.loop, &ctx.recv.pipe, 0); @@ -78,7 +83,7 @@ static void recv_cb(uv_pipe_t* handle, abort(); ASSERT(r == 0); - r = uv_accept((uv_stream_t*)&ctx.channel, &ctx.recv.stream); + r = uv_accept(handle, &ctx.recv.stream); ASSERT(r == 0); uv_close((uv_handle_t*)&ctx.channel, NULL); @@ -103,7 +108,7 @@ static int run_test(void) { NULL); ASSERT(r == 0); - r = uv_read2_start((uv_stream_t*)&ctx.channel, alloc_cb, recv_cb); + r = uv_read_start((uv_stream_t*)&ctx.channel, alloc_cb, recv_cb); ASSERT(r == 0); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); @@ -165,16 +170,21 @@ static void write2_cb(uv_write_t* req, int status) { } -static void read2_cb(uv_pipe_t* handle, - ssize_t nread, - const uv_buf_t* rdbuf, - uv_handle_type pending) { +static void read_cb(uv_stream_t* handle, + ssize_t nread, + const uv_buf_t* rdbuf) { uv_buf_t wrbuf; + uv_pipe_t* pipe; + uv_handle_type pending; int r; - ASSERT(pending == UV_NAMED_PIPE || pending == UV_TCP); - ASSERT(handle == &ctx.channel); + pipe = (uv_pipe_t*) handle; + ASSERT(pipe == &ctx.channel); ASSERT(nread >= 0); + ASSERT(1 == uv_pipe_pending_count(pipe)); + + pending = uv_pipe_pending_type(pipe); + ASSERT(pending == UV_NAMED_PIPE || pending == UV_TCP); wrbuf = uv_buf_init(".", 1); @@ -186,7 +196,7 @@ static void read2_cb(uv_pipe_t* handle, abort(); ASSERT(r == 0); - r = uv_accept((uv_stream_t*)handle, &ctx.recv.stream); + r = uv_accept(handle, &ctx.recv.stream); ASSERT(r == 0); r = uv_write2(&ctx.write_req, @@ -215,7 +225,7 @@ int ipc_send_recv_helper(void) { ASSERT(1 == uv_is_writable((uv_stream_t*)&ctx.channel)); ASSERT(0 == uv_is_closing((uv_handle_t*)&ctx.channel)); - r = uv_read2_start((uv_stream_t*)&ctx.channel, alloc_cb, read2_cb); + r = uv_read_start((uv_stream_t*)&ctx.channel, alloc_cb, read_cb); ASSERT(r == 0); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); diff --git a/deps/uv/test/test-ipc.c b/deps/uv/test/test-ipc.c index cc44d32e28..61b649b66c 100644 --- a/deps/uv/test/test-ipc.c +++ b/deps/uv/test/test-ipc.c @@ -30,7 +30,7 @@ static uv_tcp_t tcp_server; static uv_tcp_t tcp_connection; static int exit_cb_called; -static int read2_cb_called; +static int read_cb_called; static int tcp_write_cb_called; static int tcp_read_cb_called; static int on_pipe_read_called; @@ -138,13 +138,16 @@ static void make_many_connections(void) { } -static void on_read(uv_pipe_t* pipe, +static void on_read(uv_stream_t* handle, ssize_t nread, - const uv_buf_t* buf, - uv_handle_type pending) { + const uv_buf_t* buf) { int r; + uv_pipe_t* pipe; + uv_handle_type pending; uv_buf_t outbuf; + pipe = (uv_pipe_t*) handle; + if (nread == 0) { /* Everything OK, but nothing read. */ free(buf->base); @@ -163,9 +166,11 @@ static void on_read(uv_pipe_t* pipe, fprintf(stderr, "got %d bytes\n", (int)nread); + pending = uv_pipe_pending_type(pipe); if (!tcp_server_listening) { + ASSERT(1 == uv_pipe_pending_count(pipe)); ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE); - read2_cb_called++; + read_cb_called++; /* Accept the pending TCP server, and start listening on it. */ ASSERT(pending == UV_TCP); @@ -191,6 +196,7 @@ static void on_read(uv_pipe_t* pipe, make_many_connections(); } else if (memcmp("accepted_connection\n", buf->base, nread) == 0) { /* Remote server has accepted a connection. Close the channel. */ + ASSERT(0 == uv_pipe_pending_count(pipe)); ASSERT(pending == UV_UNKNOWN_HANDLE); remote_conn_accepted = 1; uv_close((uv_handle_t*)&channel, NULL); @@ -267,13 +273,15 @@ static void on_tcp_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) { } -static void on_read_connection(uv_pipe_t* pipe, +static void on_read_connection(uv_stream_t* handle, ssize_t nread, - const uv_buf_t* buf, - uv_handle_type pending) { + const uv_buf_t* buf) { int r; uv_buf_t outbuf; + uv_pipe_t* pipe; + uv_handle_type pending; + pipe = (uv_pipe_t*) handle; if (nread == 0) { /* Everything OK, but nothing read. */ free(buf->base); @@ -292,15 +300,18 @@ static void on_read_connection(uv_pipe_t* pipe, fprintf(stderr, "got %d bytes\n", (int)nread); + ASSERT(1 == uv_pipe_pending_count(pipe)); + pending = uv_pipe_pending_type(pipe); + ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE); - read2_cb_called++; + read_cb_called++; /* Accept the pending TCP connection */ ASSERT(pending == UV_TCP); r = uv_tcp_init(uv_default_loop(), &tcp_connection); ASSERT(r == 0); - r = uv_accept((uv_stream_t*)pipe, (uv_stream_t*)&tcp_connection); + r = uv_accept(handle, (uv_stream_t*)&tcp_connection); ASSERT(r == 0); /* Make sure that the expected data is correctly multiplexed. */ @@ -319,12 +330,12 @@ static void on_read_connection(uv_pipe_t* pipe, } -static int run_ipc_test(const char* helper, uv_read2_cb read_cb) { +static int run_ipc_test(const char* helper, uv_read_cb read_cb) { uv_process_t process; int r; spawn_helper(&channel, &process, helper); - uv_read2_start((uv_stream_t*)&channel, on_alloc, read_cb); + uv_read_start((uv_stream_t*)&channel, on_alloc, read_cb); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); @@ -338,7 +349,7 @@ TEST_IMPL(ipc_listen_before_write) { int r = run_ipc_test("ipc_helper_listen_before_write", on_read); ASSERT(local_conn_accepted == 1); ASSERT(remote_conn_accepted == 1); - ASSERT(read2_cb_called == 1); + ASSERT(read_cb_called == 1); ASSERT(exit_cb_called == 1); return r; } @@ -348,7 +359,7 @@ TEST_IMPL(ipc_listen_after_write) { int r = run_ipc_test("ipc_helper_listen_after_write", on_read); ASSERT(local_conn_accepted == 1); ASSERT(remote_conn_accepted == 1); - ASSERT(read2_cb_called == 1); + ASSERT(read_cb_called == 1); ASSERT(exit_cb_called == 1); return r; } @@ -356,7 +367,7 @@ TEST_IMPL(ipc_listen_after_write) { TEST_IMPL(ipc_tcp_connection) { int r = run_ipc_test("ipc_helper_tcp_connection", on_read_connection); - ASSERT(read2_cb_called == 1); + ASSERT(read_cb_called == 1); ASSERT(tcp_write_cb_called == 1); ASSERT(tcp_read_cb_called == 1); ASSERT(exit_cb_called == 1); diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index 0252acc354..345df51144 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -96,6 +96,7 @@ TEST_DECLARE (pipe_connect_bad_name) TEST_DECLARE (pipe_connect_to_file) TEST_DECLARE (pipe_getsockname) TEST_DECLARE (pipe_getsockname_abstract) +TEST_DECLARE (pipe_sendmsg) TEST_DECLARE (pipe_server_close) TEST_DECLARE (connection_fail) TEST_DECLARE (connection_fail_doesnt_auto_close) @@ -362,6 +363,7 @@ TASK_LIST_START TEST_ENTRY (pipe_listen_without_bind) TEST_ENTRY (pipe_getsockname) TEST_ENTRY (pipe_getsockname_abstract) + TEST_ENTRY (pipe_sendmsg) TEST_ENTRY (connection_fail) TEST_ENTRY (connection_fail_doesnt_auto_close) diff --git a/deps/uv/test/test-pipe-sendmsg.c b/deps/uv/test/test-pipe-sendmsg.c new file mode 100644 index 0000000000..f6d893b449 --- /dev/null +++ b/deps/uv/test/test-pipe-sendmsg.c @@ -0,0 +1,169 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + + +#ifndef _WIN32 + +#include <fcntl.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <unistd.h> + + +/* NOTE: size should be divisible by 2 */ +static uv_pipe_t incoming[4]; +static unsigned int incoming_count; +static unsigned int close_called; + + +static void set_nonblocking(uv_os_sock_t sock) { + int r; +#ifdef _WIN32 + unsigned long on = 1; + r = ioctlsocket(sock, FIONBIO, &on); + ASSERT(r == 0); +#else + int flags = fcntl(sock, F_GETFL, 0); + ASSERT(flags >= 0); + r = fcntl(sock, F_SETFL, flags | O_NONBLOCK); + ASSERT(r >= 0); +#endif +} + + + + +static void close_cb(uv_handle_t* handle) { + close_called++; +} + + +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + static char base[1]; + + buf->base = base; + buf->len = sizeof(base); +} + + +static void read_cb(uv_stream_t* handle, + ssize_t nread, + const uv_buf_t* buf) { + uv_pipe_t* p; + uv_pipe_t* inc; + uv_handle_type pending; + unsigned int i; + + p = (uv_pipe_t*) handle; + ASSERT(nread >= 0); + + while (uv_pipe_pending_count(p) != 0) { + pending = uv_pipe_pending_type(p); + ASSERT(pending == UV_NAMED_PIPE); + + ASSERT(incoming_count < ARRAY_SIZE(incoming)); + inc = &incoming[incoming_count++]; + ASSERT(0 == uv_pipe_init(p->loop, inc, 0)); + ASSERT(0 == uv_accept(handle, (uv_stream_t*) inc)); + } + + if (incoming_count != ARRAY_SIZE(incoming)) + return; + + ASSERT(0 == uv_read_stop((uv_stream_t*) p)); + uv_close((uv_handle_t*) p, close_cb); + for (i = 0; i < ARRAY_SIZE(incoming); i++) + uv_close((uv_handle_t*) &incoming[i], close_cb); +} + + +TEST_IMPL(pipe_sendmsg) { + uv_pipe_t p; + int r; + int fds[2]; + int send_fds[ARRAY_SIZE(incoming)]; + struct msghdr msg; + char scratch[64]; + struct cmsghdr *cmsg; + unsigned int i; + uv_buf_t buf; + + ASSERT(0 == socketpair(AF_UNIX, SOCK_STREAM, 0, fds)); + for (i = 0; i < ARRAY_SIZE(send_fds); i += 2) + ASSERT(0 == socketpair(AF_UNIX, SOCK_STREAM, 0, send_fds + i)); + ASSERT(i == ARRAY_SIZE(send_fds)); + ASSERT(0 == uv_pipe_init(uv_default_loop(), &p, 1)); + ASSERT(0 == uv_pipe_open(&p, fds[1])); + + buf = uv_buf_init("X", 1); + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = (struct iovec*) &buf; + msg.msg_iovlen = 1; + msg.msg_flags = 0; + + msg.msg_control = (void*) scratch; + msg.msg_controllen = CMSG_LEN(sizeof(send_fds)); + ASSERT(sizeof(scratch) >= msg.msg_controllen); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = msg.msg_controllen; + + /* silence aliasing warning */ + { + void* pv = CMSG_DATA(cmsg); + int* pi = pv; + for (i = 0; i < ARRAY_SIZE(send_fds); i++) + pi[i] = send_fds[i]; + } + + set_nonblocking(fds[1]); + ASSERT(0 == uv_read_start((uv_stream_t*) &p, alloc_cb, read_cb)); + + do + r = sendmsg(fds[0], &msg, 0); + while (r == -1 && errno == EINTR); + ASSERT(r == 1); + + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + ASSERT(ARRAY_SIZE(incoming) == incoming_count); + ASSERT(ARRAY_SIZE(incoming) + 1 == close_called); + close(fds[0]); + + MAKE_VALGRIND_HAPPY(); + return 0; +} + +#else /* !_WIN32 */ + +TEST_IMPL(pipe_sendmsg) { + MAKE_VALGRIND_HAPPY(); + return 0; +} + +#endif /* _WIN32 */ |