summaryrefslogtreecommitdiff
path: root/deps/uv/test
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2011-08-23 02:34:43 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2011-08-24 22:27:24 +0200
commit28998a8cfe92043b27ff573b54258e21123616a4 (patch)
treea54899d80d0a09d52903e374b44d878066eb5b57 /deps/uv/test
parent7003d6eff56193aa6f2370cafb7f7bf10db243c7 (diff)
downloadandroid-node-v8-28998a8cfe92043b27ff573b54258e21123616a4.tar.gz
android-node-v8-28998a8cfe92043b27ff573b54258e21123616a4.tar.bz2
android-node-v8-28998a8cfe92043b27ff573b54258e21123616a4.zip
uv: upgrade to 80e5491
Diffstat (limited to 'deps/uv/test')
-rw-r--r--deps/uv/test/benchmark-list.h21
-rw-r--r--deps/uv/test/benchmark-ping-pongs.c2
-rw-r--r--deps/uv/test/benchmark-pound.c4
-rw-r--r--deps/uv/test/benchmark-pump.c4
-rw-r--r--deps/uv/test/benchmark-spawn.c2
-rw-r--r--deps/uv/test/benchmark-udp-packet-storm.c247
-rw-r--r--deps/uv/test/dns-server.c2
-rw-r--r--deps/uv/test/echo-server.c2
-rw-r--r--deps/uv/test/test-callback-stack.c2
-rw-r--r--deps/uv/test/test-delayed-accept.c2
-rw-r--r--deps/uv/test/test-getsockname.c8
-rw-r--r--deps/uv/test/test-list.h9
-rw-r--r--deps/uv/test/test-ping-pong.c2
-rw-r--r--deps/uv/test/test-shutdown-eof.c2
-rw-r--r--deps/uv/test/test-spawn.c2
-rw-r--r--deps/uv/test/test-tcp-writealot.c2
-rw-r--r--deps/uv/test/test-udp-dgram-too-big.c88
-rw-r--r--deps/uv/test/test-udp-ipv6-only.c141
-rw-r--r--deps/uv/test/test-udp-ipv6.c158
-rw-r--r--deps/uv/test/test-udp-send-and-recv.c210
20 files changed, 892 insertions, 18 deletions
diff --git a/deps/uv/test/benchmark-list.h b/deps/uv/test/benchmark-list.h
index c05f37f7b5..0e5467c7a1 100644
--- a/deps/uv/test/benchmark-list.h
+++ b/deps/uv/test/benchmark-list.h
@@ -29,6 +29,16 @@ BENCHMARK_DECLARE (tcp_pump100_client)
BENCHMARK_DECLARE (tcp_pump1_client)
BENCHMARK_DECLARE (pipe_pump100_client)
BENCHMARK_DECLARE (pipe_pump1_client)
+BENCHMARK_DECLARE (udp_packet_storm_1v1)
+BENCHMARK_DECLARE (udp_packet_storm_1v10)
+BENCHMARK_DECLARE (udp_packet_storm_1v100)
+BENCHMARK_DECLARE (udp_packet_storm_1v1000)
+BENCHMARK_DECLARE (udp_packet_storm_10v10)
+BENCHMARK_DECLARE (udp_packet_storm_10v100)
+BENCHMARK_DECLARE (udp_packet_storm_10v1000)
+BENCHMARK_DECLARE (udp_packet_storm_100v100)
+BENCHMARK_DECLARE (udp_packet_storm_100v1000)
+BENCHMARK_DECLARE (udp_packet_storm_1000v1000)
BENCHMARK_DECLARE (gethostbyname)
BENCHMARK_DECLARE (getaddrinfo)
BENCHMARK_DECLARE (spawn)
@@ -68,6 +78,17 @@ TASK_LIST_START
BENCHMARK_ENTRY (pipe_pound_1000)
BENCHMARK_HELPER (pipe_pound_1000, pipe_echo_server)
+ BENCHMARK_ENTRY (udp_packet_storm_1v1)
+ BENCHMARK_ENTRY (udp_packet_storm_1v10)
+ BENCHMARK_ENTRY (udp_packet_storm_1v100)
+ BENCHMARK_ENTRY (udp_packet_storm_1v1000)
+ BENCHMARK_ENTRY (udp_packet_storm_10v10)
+ BENCHMARK_ENTRY (udp_packet_storm_10v100)
+ BENCHMARK_ENTRY (udp_packet_storm_10v1000)
+ BENCHMARK_ENTRY (udp_packet_storm_100v100)
+ BENCHMARK_ENTRY (udp_packet_storm_100v1000)
+ BENCHMARK_ENTRY (udp_packet_storm_1000v1000)
+
BENCHMARK_ENTRY (gethostbyname)
BENCHMARK_HELPER (gethostbyname, dns_server)
diff --git a/deps/uv/test/benchmark-ping-pongs.c b/deps/uv/test/benchmark-ping-pongs.c
index 53cea782cd..8056723998 100644
--- a/deps/uv/test/benchmark-ping-pongs.c
+++ b/deps/uv/test/benchmark-ping-pongs.c
@@ -52,7 +52,7 @@ static int completed_pingers = 0;
static int64_t start_time;
-static uv_buf_t buf_alloc(uv_stream_t* tcp, size_t size) {
+static uv_buf_t buf_alloc(uv_handle_t* tcp, size_t size) {
buf_t* ab;
ab = buf_freelist;
diff --git a/deps/uv/test/benchmark-pound.c b/deps/uv/test/benchmark-pound.c
index a5e38ac35a..bae5e46f8d 100644
--- a/deps/uv/test/benchmark-pound.c
+++ b/deps/uv/test/benchmark-pound.c
@@ -72,13 +72,13 @@ static uint64_t start; /* in ms */
static int closed_streams;
static int conns_failed;
-static uv_buf_t alloc_cb(uv_stream_t* stream, size_t suggested_size);
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size);
static void connect_cb(uv_connect_t* conn_req, int status);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf);
static void close_cb(uv_handle_t* handle);
-static uv_buf_t alloc_cb(uv_stream_t* stream, size_t suggested_size) {
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
static char slab[65536];
uv_buf_t buf;
buf.base = slab;
diff --git a/deps/uv/test/benchmark-pump.c b/deps/uv/test/benchmark-pump.c
index c6cd2d1419..7713a58582 100644
--- a/deps/uv/test/benchmark-pump.c
+++ b/deps/uv/test/benchmark-pump.c
@@ -41,7 +41,7 @@ static void maybe_connect_some();
static uv_req_t* req_alloc();
static void req_free(uv_req_t* uv_req);
-static uv_buf_t buf_alloc(uv_stream_t*, size_t size);
+static uv_buf_t buf_alloc(uv_handle_t*, size_t size);
static void buf_free(uv_buf_t uv_buf_t);
@@ -337,7 +337,7 @@ typedef struct buf_list_s {
static buf_list_t* buf_freelist = NULL;
-static uv_buf_t buf_alloc(uv_stream_t* stream, size_t size) {
+static uv_buf_t buf_alloc(uv_handle_t* handle, size_t size) {
buf_list_t* buf;
buf = buf_freelist;
diff --git a/deps/uv/test/benchmark-spawn.c b/deps/uv/test/benchmark-spawn.c
index 0297c74fb2..46ddca0e37 100644
--- a/deps/uv/test/benchmark-spawn.c
+++ b/deps/uv/test/benchmark-spawn.c
@@ -69,7 +69,7 @@ static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
}
-uv_buf_t on_alloc(uv_stream_t* tcp, size_t suggested_size) {
+uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
uv_buf_t buf;
buf.base = output + output_used;
buf.len = OUTPUT_SIZE - output_used;
diff --git a/deps/uv/test/benchmark-udp-packet-storm.c b/deps/uv/test/benchmark-udp-packet-storm.c
new file mode 100644
index 0000000000..9b97ffef30
--- /dev/null
+++ b/deps/uv/test/benchmark-udp-packet-storm.c
@@ -0,0 +1,247 @@
+/* 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 "task.h"
+#include "uv.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define EXPECTED "RANG TANG DING DONG I AM THE JAPANESE SANDMAN" /* "Take eight!" */
+
+#define TEST_DURATION 5000 /* ms */
+
+#define MAX_SENDERS 1000
+#define MAX_RECEIVERS 1000
+
+#define BASE_PORT 12345
+
+#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
+
+static int n_senders_;
+static int n_receivers_;
+static uv_udp_t senders[MAX_SENDERS];
+static uv_udp_t receivers[MAX_RECEIVERS];
+static uv_buf_t bufs[5];
+
+static int send_cb_called;
+static int recv_cb_called;
+static int close_cb_called;
+static int stopping = 0;
+
+typedef struct {
+ struct sockaddr_in addr;
+} sender_state_t;
+
+
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
+ static char slab[65536];
+ ASSERT(suggested_size <= sizeof slab);
+ return uv_buf_init(slab, sizeof slab);
+}
+
+
+static void send_cb(uv_udp_send_t* req, int status) {
+ sender_state_t* ss;
+ int r;
+
+ if (stopping) {
+ return;
+ }
+
+ ASSERT(req != NULL);
+ ASSERT(status == 0);
+
+ ss = req->data;
+
+ r = uv_udp_send(req, req->handle, bufs, ARRAY_SIZE(bufs), ss->addr, send_cb);
+ ASSERT(r == 0);
+
+ req->data = ss;
+
+ send_cb_called++;
+}
+
+
+static void recv_cb(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ if (nread == 0)
+ return;
+
+ if (nread == -1) {
+ ASSERT(uv_last_error().code == UV_EINTR); /* FIXME change error code */
+ return;
+ }
+
+ ASSERT(addr->sa_family == AF_INET);
+ ASSERT(!memcmp(buf.base, EXPECTED, nread));
+
+ recv_cb_called++;
+}
+
+
+static void close_cb(uv_handle_t* handle) {
+ ASSERT(handle != NULL);
+ close_cb_called++;
+}
+
+
+static void timeout_cb(uv_timer_t* timer, int status) {
+ int i;
+
+ stopping = 1;
+
+ for (i = 0; i < n_senders_; i++)
+ uv_close((uv_handle_t*)&senders[i], close_cb);
+
+ for (i = 0; i < n_receivers_; i++)
+ uv_close((uv_handle_t*)&receivers[i], close_cb);
+}
+
+
+static int do_packet_storm(int n_senders, int n_receivers) {
+ uv_timer_t timeout;
+ sender_state_t *ss;
+ uv_udp_send_t* req;
+ uv_udp_t* handle;
+ int i;
+ int r;
+
+ ASSERT(n_senders <= MAX_SENDERS);
+ ASSERT(n_receivers <= MAX_RECEIVERS);
+
+ uv_init();
+
+ n_senders_ = n_senders;
+ n_receivers_ = n_receivers;
+
+ r = uv_timer_init(&timeout);
+ ASSERT(r == 0);
+
+ r = uv_timer_start(&timeout, timeout_cb, TEST_DURATION, 0);
+ ASSERT(r == 0);
+
+ /* Timer should not keep loop alive. */
+ uv_unref();
+
+ for (i = 0; i < n_receivers; i++) {
+ struct sockaddr_in addr;
+ handle = &receivers[i];
+
+ r = uv_udp_init(handle);
+ ASSERT(r == 0);
+
+ addr = uv_ip4_addr("0.0.0.0", BASE_PORT + i);
+
+ r = uv_udp_bind(handle, addr, 0);
+ ASSERT(r == 0);
+
+ r = uv_udp_recv_start(handle, alloc_cb, recv_cb);
+ ASSERT(r == 0);
+ }
+
+ bufs[0] = uv_buf_init(EXPECTED + 0, 10);
+ bufs[1] = uv_buf_init(EXPECTED + 10, 10);
+ bufs[2] = uv_buf_init(EXPECTED + 20, 10);
+ bufs[3] = uv_buf_init(EXPECTED + 30, 10);
+ bufs[4] = uv_buf_init(EXPECTED + 40, 5);
+
+ for (i = 0; i < n_senders; i++) {
+ handle = &senders[i];
+
+ r = uv_udp_init(handle);
+ ASSERT(r == 0);
+
+ req = malloc(sizeof(*req) + sizeof(*ss));
+
+ ss = (void*)(req + 1);
+ ss->addr = uv_ip4_addr("127.0.0.1", BASE_PORT + (i % n_receivers));
+
+ r = uv_udp_send(req, handle, bufs, ARRAY_SIZE(bufs), ss->addr, send_cb);
+ ASSERT(r == 0);
+
+ req->data = ss;
+ }
+
+ uv_run();
+
+ printf("udp_packet_storm_%dv%d: %.0f/s received, %.0f/s sent\n",
+ n_receivers,
+ n_senders,
+ recv_cb_called / (TEST_DURATION / 1000.0),
+ send_cb_called / (TEST_DURATION / 1000.0));
+
+ return 0;
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_1v1) {
+ return do_packet_storm(1, 1);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_1v10) {
+ return do_packet_storm(1, 10);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_1v100) {
+ return do_packet_storm(1, 100);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_1v1000) {
+ return do_packet_storm(1, 1000);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_10v10) {
+ return do_packet_storm(10, 10);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_10v100) {
+ return do_packet_storm(10, 100);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_10v1000) {
+ return do_packet_storm(10, 1000);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_100v100) {
+ return do_packet_storm(100, 100);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_100v1000) {
+ return do_packet_storm(100, 1000);
+}
+
+
+BENCHMARK_IMPL(udp_packet_storm_1000v1000) {
+ return do_packet_storm(1000, 1000);
+}
diff --git a/deps/uv/test/dns-server.c b/deps/uv/test/dns-server.c
index f1593528ed..2e4a8f3949 100644
--- a/deps/uv/test/dns-server.c
+++ b/deps/uv/test/dns-server.c
@@ -247,7 +247,7 @@ static void on_close(uv_handle_t* peer) {
}
-static uv_buf_t buf_alloc(uv_stream_t* handle, size_t suggested_size) {
+static uv_buf_t buf_alloc(uv_handle_t* handle, size_t suggested_size) {
uv_buf_t buf;
buf.base = (char*) malloc(suggested_size);
buf.len = suggested_size;
diff --git a/deps/uv/test/echo-server.c b/deps/uv/test/echo-server.c
index 82be72a513..270af3787a 100644
--- a/deps/uv/test/echo-server.c
+++ b/deps/uv/test/echo-server.c
@@ -123,7 +123,7 @@ static void on_close(uv_handle_t* peer) {
}
-static uv_buf_t echo_alloc(uv_stream_t* handle, size_t suggested_size) {
+static uv_buf_t echo_alloc(uv_handle_t* handle, size_t suggested_size) {
return uv_buf_init(malloc(suggested_size), suggested_size);
}
diff --git a/deps/uv/test/test-callback-stack.c b/deps/uv/test/test-callback-stack.c
index 6582010aab..64cc4d9ecd 100644
--- a/deps/uv/test/test-callback-stack.c
+++ b/deps/uv/test/test-callback-stack.c
@@ -45,7 +45,7 @@ static int bytes_received = 0;
static int shutdown_cb_called = 0;
-static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) {
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
uv_buf_t buf;
buf.len = size;
buf.base = (char*) malloc(size);
diff --git a/deps/uv/test/test-delayed-accept.c b/deps/uv/test/test-delayed-accept.c
index 10f041b2cd..5a2704d4e4 100644
--- a/deps/uv/test/test-delayed-accept.c
+++ b/deps/uv/test/test-delayed-accept.c
@@ -30,7 +30,7 @@ static int close_cb_called = 0;
static int connect_cb_called = 0;
-static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) {
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
uv_buf_t buf;
buf.base = (char*)malloc(size);
buf.len = size;
diff --git a/deps/uv/test/test-getsockname.c b/deps/uv/test/test-getsockname.c
index 8b783ec568..c804ecc5e7 100644
--- a/deps/uv/test/test-getsockname.c
+++ b/deps/uv/test/test-getsockname.c
@@ -33,7 +33,7 @@ static uv_connect_t connect_req;
static uv_tcp_t tcpServer;
-static uv_buf_t alloc(uv_stream_t* handle, size_t suggested_size) {
+static uv_buf_t alloc(uv_handle_t* handle, size_t suggested_size) {
uv_buf_t buf;
buf.base = (char*) malloc(suggested_size);
buf.len = suggested_size;
@@ -89,7 +89,7 @@ static void on_connection(uv_stream_t* server, int status) {
r = uv_accept(server, (uv_stream_t*)handle);
ASSERT(r == 0);
- status = uv_getsockname((uv_tcp_t*)handle, &sockname, &namelen);
+ status = uv_getsockname(handle, &sockname, &namelen);
if (status != 0) {
fprintf(stderr, "uv_getsockname error (accepted) %d\n", uv_last_error().code);
}
@@ -110,7 +110,7 @@ static void on_connect(uv_connect_t* req, int status) {
ASSERT(status == 0);
- r = uv_getsockname(&tcp, &sockname, &namelen);
+ r = uv_getsockname((uv_handle_t*)&tcp, &sockname, &namelen);
if (r != 0) {
fprintf(stderr, "uv_getsockname error (connector) %d\n", uv_last_error().code);
}
@@ -147,7 +147,7 @@ static int tcp_listener(int port) {
return 1;
}
- r = uv_getsockname(&tcpServer, &sockname, &namelen);
+ r = uv_getsockname((uv_handle_t*)&tcpServer, &sockname, &namelen);
if (r != 0) {
fprintf(stderr, "uv_getsockname error (listening) %d\n", uv_last_error().code);
}
diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h
index 9d1f2e9be0..8a9f8c7e80 100644
--- a/deps/uv/test/test-list.h
+++ b/deps/uv/test/test-list.h
@@ -36,6 +36,10 @@ TEST_DECLARE (tcp_bind6_error_addrnotavail)
TEST_DECLARE (tcp_bind6_error_fault)
TEST_DECLARE (tcp_bind6_error_inval)
TEST_DECLARE (tcp_bind6_localhost_ok)
+TEST_DECLARE (udp_send_and_recv)
+TEST_DECLARE (udp_dgram_too_big)
+TEST_DECLARE (udp_dual_stack)
+TEST_DECLARE (udp_ipv6_only)
TEST_DECLARE (pipe_bind_error_addrinuse)
TEST_DECLARE (pipe_bind_error_addrnotavail)
TEST_DECLARE (pipe_bind_error_inval)
@@ -106,6 +110,11 @@ TASK_LIST_START
TEST_ENTRY (tcp_bind6_error_inval)
TEST_ENTRY (tcp_bind6_localhost_ok)
+ TEST_ENTRY (udp_send_and_recv)
+ TEST_ENTRY (udp_dgram_too_big)
+ TEST_ENTRY (udp_dual_stack)
+ TEST_ENTRY (udp_ipv6_only)
+
TEST_ENTRY (pipe_bind_error_addrinuse)
TEST_ENTRY (pipe_bind_error_addrnotavail)
TEST_ENTRY (pipe_bind_error_inval)
diff --git a/deps/uv/test/test-ping-pong.c b/deps/uv/test/test-ping-pong.c
index 26718cd36b..e9af29ae26 100644
--- a/deps/uv/test/test-ping-pong.c
+++ b/deps/uv/test/test-ping-pong.c
@@ -51,7 +51,7 @@ typedef struct {
void pinger_try_read(pinger_t* pinger);
-static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) {
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
uv_buf_t buf;
buf.base = (char*)malloc(size);
buf.len = size;
diff --git a/deps/uv/test/test-shutdown-eof.c b/deps/uv/test/test-shutdown-eof.c
index 67af49531f..cb57ad1eb5 100644
--- a/deps/uv/test/test-shutdown-eof.c
+++ b/deps/uv/test/test-shutdown-eof.c
@@ -39,7 +39,7 @@ static int called_timer_close_cb;
static int called_timer_cb;
-static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) {
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
uv_buf_t buf;
buf.base = (char*)malloc(size);
buf.len = size;
diff --git a/deps/uv/test/test-spawn.c b/deps/uv/test/test-spawn.c
index c0396e18cd..f2d84694ca 100644
--- a/deps/uv/test/test-spawn.c
+++ b/deps/uv/test/test-spawn.c
@@ -66,7 +66,7 @@ static void kill_cb(uv_process_t* process, int exit_status, int term_signal) {
}
-uv_buf_t on_alloc(uv_stream_t* tcp, size_t suggested_size) {
+uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
uv_buf_t buf;
buf.base = output + output_used;
buf.len = OUTPUT_SIZE - output_used;
diff --git a/deps/uv/test/test-tcp-writealot.c b/deps/uv/test/test-tcp-writealot.c
index 73cf45b1c9..6cb5e09928 100644
--- a/deps/uv/test/test-tcp-writealot.c
+++ b/deps/uv/test/test-tcp-writealot.c
@@ -45,7 +45,7 @@ static int bytes_received = 0;
static int bytes_received_done = 0;
-static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) {
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
uv_buf_t buf;
buf.base = (char*)malloc(size);
buf.len = size;
diff --git a/deps/uv/test/test-udp-dgram-too-big.c b/deps/uv/test/test-udp-dgram-too-big.c
new file mode 100644
index 0000000000..7de9b49a90
--- /dev/null
+++ b/deps/uv/test/test-udp-dgram-too-big.c
@@ -0,0 +1,88 @@
+/* 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"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define CHECK_HANDLE(handle) \
+ ASSERT((uv_udp_t*)(handle) == &handle_)
+
+#define CHECK_REQ(req) \
+ ASSERT((req) == &req_);
+
+static uv_udp_t handle_;
+static uv_udp_send_t req_;
+
+static int send_cb_called;
+static int close_cb_called;
+
+
+static void close_cb(uv_handle_t* handle) {
+ CHECK_HANDLE(handle);
+ close_cb_called++;
+}
+
+
+static void send_cb(uv_udp_send_t* req, int status) {
+ CHECK_REQ(req);
+ CHECK_HANDLE(req->handle);
+
+ ASSERT(status == -1);
+ ASSERT(uv_last_error().code == UV_EMSGSIZE);
+
+ uv_close((uv_handle_t*)req->handle, close_cb);
+ send_cb_called++;
+}
+
+
+TEST_IMPL(udp_dgram_too_big) {
+ char dgram[65536]; /* 64K MTU is unlikely, even on localhost */
+ struct sockaddr_in addr;
+ uv_buf_t buf;
+ int r;
+
+ memset(dgram, 42, sizeof dgram); /* silence valgrind */
+
+ uv_init();
+
+ r = uv_udp_init(&handle_);
+ ASSERT(r == 0);
+
+ buf = uv_buf_init(dgram, sizeof dgram);
+ addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
+
+ r = uv_udp_send(&req_, &handle_, &buf, 1, addr, send_cb);
+ ASSERT(r == 0);
+
+ ASSERT(close_cb_called == 0);
+ ASSERT(send_cb_called == 0);
+
+ uv_run();
+
+ ASSERT(send_cb_called == 1);
+ ASSERT(close_cb_called == 1);
+
+ return 0;
+}
diff --git a/deps/uv/test/test-udp-ipv6-only.c b/deps/uv/test/test-udp-ipv6-only.c
new file mode 100644
index 0000000000..c14647e0e2
--- /dev/null
+++ b/deps/uv/test/test-udp-ipv6-only.c
@@ -0,0 +1,141 @@
+/* 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"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define CHECK_HANDLE(handle) \
+ ASSERT((uv_udp_t*)(handle) == &server1 \
+ || (uv_udp_t*)(handle) == &server2 \
+ || (uv_udp_t*)(handle) == &client)
+
+#define CHECK_REQ(req) \
+ ASSERT((req) == &req_);
+
+static uv_udp_t client;
+static uv_udp_t server1;
+static uv_udp_t server2;
+static uv_udp_send_t req_;
+
+static int send_cb_called;
+static int recv_cb_called;
+static int close_cb_called;
+
+
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
+ static char slab[65536];
+ CHECK_HANDLE(handle);
+ return uv_buf_init(slab, sizeof slab);
+}
+
+
+static void close_cb(uv_handle_t* handle) {
+ CHECK_HANDLE(handle);
+ close_cb_called++;
+}
+
+
+static void send_cb(uv_udp_send_t* req, int status) {
+ CHECK_REQ(req);
+ CHECK_HANDLE(req->handle);
+ ASSERT(status == 0);
+ send_cb_called++;
+}
+
+static void ipv4_recv_cb(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ CHECK_HANDLE(handle);
+ ASSERT(nread >= 0);
+
+ uv_close((uv_handle_t*)&server1, close_cb);
+ uv_close((uv_handle_t*)&server2, close_cb);
+ uv_close((uv_handle_t*)&client, close_cb);
+
+ recv_cb_called++;
+}
+
+
+static void ipv6_recv_cb(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ ASSERT(0 && "this function should not have been called");
+}
+
+
+TEST_IMPL(udp_ipv6_only) {
+ struct sockaddr_in6 addr6;
+ struct sockaddr_in addr;
+ uv_buf_t buf;
+ int r;
+
+ uv_init();
+
+ addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
+ addr6 = uv_ip6_addr(":::0", TEST_PORT);
+
+ r = uv_udp_init(&server1);
+ ASSERT(r == 0);
+
+ r = uv_udp_bind(&server1, addr, 0);
+ ASSERT(r == 0);
+
+ r = uv_udp_recv_start(&server1, alloc_cb, ipv4_recv_cb);
+ ASSERT(r == 0);
+
+ r = uv_udp_init(&server2);
+ ASSERT(r == 0);
+
+ r = uv_udp_bind6(&server2, addr6, UV_UDP_IPV6ONLY);
+ ASSERT(r == 0);
+
+ r = uv_udp_recv_start(&server2, alloc_cb, ipv6_recv_cb);
+ ASSERT(r == 0);
+
+ r = uv_udp_init(&client);
+ ASSERT(r == 0);
+
+ buf = uv_buf_init("PING", 4);
+
+ /* This should fail but still call send_cb(). */
+ r = uv_udp_send(&req_, &client, &buf, 1, addr, send_cb);
+ ASSERT(r == 0);
+
+ ASSERT(close_cb_called == 0);
+ ASSERT(send_cb_called == 0);
+ ASSERT(recv_cb_called == 0);
+
+ uv_run();
+
+ ASSERT(recv_cb_called == 1);
+ ASSERT(send_cb_called == 1);
+ ASSERT(close_cb_called == 3);
+
+ return 0;
+}
diff --git a/deps/uv/test/test-udp-ipv6.c b/deps/uv/test/test-udp-ipv6.c
new file mode 100644
index 0000000000..489c17ccee
--- /dev/null
+++ b/deps/uv/test/test-udp-ipv6.c
@@ -0,0 +1,158 @@
+/* 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"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define CHECK_HANDLE(handle) \
+ ASSERT((uv_udp_t*)(handle) == &server \
+ || (uv_udp_t*)(handle) == &client \
+ || (uv_timer_t*)(handle) == &timeout)
+
+#define CHECK_REQ(req) \
+ ASSERT((req) == &req_);
+
+static uv_udp_t client;
+static uv_udp_t server;
+static uv_udp_send_t req_;
+static uv_timer_t timeout;
+
+static int send_cb_called;
+static int recv_cb_called;
+static int close_cb_called;
+
+
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
+ static char slab[65536];
+ CHECK_HANDLE(handle);
+ return uv_buf_init(slab, sizeof slab);
+}
+
+
+static void close_cb(uv_handle_t* handle) {
+ CHECK_HANDLE(handle);
+ close_cb_called++;
+}
+
+
+static void send_cb(uv_udp_send_t* req, int status) {
+ CHECK_REQ(req);
+ CHECK_HANDLE(req->handle);
+ ASSERT(status == 0);
+ send_cb_called++;
+}
+
+
+static void ipv6_recv_fail(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ ASSERT(0 && "this function should not have been called");
+}
+
+
+static void ipv6_recv_ok(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ CHECK_HANDLE(handle);
+ ASSERT(nread >= 0);
+
+ if (nread)
+ recv_cb_called++;
+}
+
+
+static void timeout_cb(uv_timer_t* timer, int status) {
+ uv_close((uv_handle_t*)&server, close_cb);
+ uv_close((uv_handle_t*)&client, close_cb);
+ uv_close((uv_handle_t*)&timeout, close_cb);
+}
+
+
+static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) {
+ struct sockaddr_in6 addr6;
+ struct sockaddr_in addr;
+ uv_buf_t buf;
+ int r;
+
+ uv_init();
+
+ addr6 = uv_ip6_addr("::0", TEST_PORT);
+
+ r = uv_udp_init(&server);
+ ASSERT(r == 0);
+
+ r = uv_udp_bind6(&server, addr6, bind_flags);
+ ASSERT(r == 0);
+
+ r = uv_udp_recv_start(&server, alloc_cb, recv_cb);
+ ASSERT(r == 0);
+
+ r = uv_udp_init(&client);
+ ASSERT(r == 0);
+
+ buf = uv_buf_init("PING", 4);
+ addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
+
+ r = uv_udp_send(&req_, &client, &buf, 1, addr, send_cb);
+ ASSERT(r == 0);
+
+ r = uv_timer_init(&timeout);
+ ASSERT(r == 0);
+
+ r = uv_timer_start(&timeout, timeout_cb, 500, 0);
+ ASSERT(r == 0);
+
+ ASSERT(close_cb_called == 0);
+ ASSERT(send_cb_called == 0);
+ ASSERT(recv_cb_called == 0);
+
+ uv_run();
+
+ ASSERT(close_cb_called == 3);
+}
+
+
+TEST_IMPL(udp_dual_stack) {
+ do_test(ipv6_recv_ok, 0);
+
+ ASSERT(recv_cb_called == 1);
+ ASSERT(send_cb_called == 1);
+
+ return 0;
+}
+
+
+TEST_IMPL(udp_ipv6_only) {
+ do_test(ipv6_recv_fail, UV_UDP_IPV6ONLY);
+
+ ASSERT(recv_cb_called == 0);
+ ASSERT(send_cb_called == 1);
+
+ return 0;
+}
diff --git a/deps/uv/test/test-udp-send-and-recv.c b/deps/uv/test/test-udp-send-and-recv.c
new file mode 100644
index 0000000000..6d61e83f99
--- /dev/null
+++ b/deps/uv/test/test-udp-send-and-recv.c
@@ -0,0 +1,210 @@
+/* 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"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define CHECK_HANDLE(handle) \
+ ASSERT((uv_udp_t*)(handle) == &server || (uv_udp_t*)(handle) == &client)
+
+static uv_udp_t server;
+static uv_udp_t client;
+
+static int cl_send_cb_called;
+static int cl_recv_cb_called;
+
+static int sv_send_cb_called;
+static int sv_recv_cb_called;
+
+static int close_cb_called;
+
+
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
+ static char slab[65536];
+
+ CHECK_HANDLE(handle);
+ ASSERT(suggested_size <= sizeof slab);
+
+ return uv_buf_init(slab, sizeof slab);
+}
+
+
+static void close_cb(uv_handle_t* handle) {
+ CHECK_HANDLE(handle);
+ close_cb_called++;
+}
+
+
+static void cl_recv_cb(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ CHECK_HANDLE(handle);
+ ASSERT(flags == 0);
+
+ if (nread < 0) {
+ ASSERT(0 && "unexpected error");
+ }
+
+ if (nread == 0) {
+ /* Returning unused buffer */
+ /* Don't count towards cl_recv_cb_called */
+ ASSERT(addr == NULL);
+ return;
+ }
+
+ ASSERT(addr != NULL);
+ ASSERT(nread == 4);
+ ASSERT(!memcmp("PONG", buf.base, nread));
+
+ cl_recv_cb_called++;
+
+ uv_close((uv_handle_t*) handle, close_cb);
+}
+
+
+static void cl_send_cb(uv_udp_send_t* req, int status) {
+ int r;
+
+ ASSERT(req != NULL);
+ ASSERT(status == 0);
+ CHECK_HANDLE(req->handle);
+
+ r = uv_udp_recv_start(req->handle, alloc_cb, cl_recv_cb);
+ ASSERT(r == 0);
+
+ cl_send_cb_called++;
+}
+
+
+static void sv_send_cb(uv_udp_send_t* req, int status) {
+ ASSERT(req != NULL);
+ ASSERT(status == 0);
+ CHECK_HANDLE(req->handle);
+
+ uv_close((uv_handle_t*) req->handle, close_cb);
+ free(req);
+
+ sv_send_cb_called++;
+}
+
+
+static void sv_recv_cb(uv_udp_t* handle,
+ ssize_t nread,
+ uv_buf_t buf,
+ struct sockaddr* addr,
+ unsigned flags) {
+ uv_udp_send_t* req;
+ int r;
+
+ if (nread < 0) {
+ ASSERT(0 && "unexpected error");
+ }
+
+ if (nread == 0) {
+ /* Returning unused buffer */
+ /* Don't count towards sv_recv_cb_called */
+ ASSERT(addr == NULL);
+ return;
+ }
+
+ CHECK_HANDLE(handle);
+ ASSERT(flags == 0);
+
+ ASSERT(addr != NULL);
+ ASSERT(nread == 4);
+ ASSERT(!memcmp("PING", buf.base, nread));
+
+ /* FIXME? `uv_udp_recv_stop` does what it says: recv_cb is not called
+ * anymore. That's problematic because the read buffer won't be returned
+ * either... Not sure I like that but it's consistent with `uv_read_stop`.
+ */
+ r = uv_udp_recv_stop(handle);
+ ASSERT(r == 0);
+
+ req = malloc(sizeof *req);
+ ASSERT(req != NULL);
+
+ buf = uv_buf_init("PONG", 4);
+
+ r = uv_udp_send(req,
+ handle,
+ &buf,
+ 1,
+ *(struct sockaddr_in*)addr,
+ sv_send_cb);
+ ASSERT(r == 0);
+
+ sv_recv_cb_called++;
+}
+
+
+TEST_IMPL(udp_send_and_recv) {
+ struct sockaddr_in addr;
+ uv_udp_send_t req;
+ uv_buf_t buf;
+ int r;
+
+ addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
+
+ uv_init();
+
+ r = uv_udp_init(&server);
+ ASSERT(r == 0);
+
+ r = uv_udp_bind(&server, addr, 0);
+ ASSERT(r == 0);
+
+ r = uv_udp_recv_start(&server, alloc_cb, sv_recv_cb);
+ ASSERT(r == 0);
+
+ addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
+
+ r = uv_udp_init(&client);
+ ASSERT(r == 0);
+
+ /* client sends "PING", expects "PONG" */
+ buf = uv_buf_init("PING", 4);
+
+ r = uv_udp_send(&req, &client, &buf, 1, addr, cl_send_cb);
+ ASSERT(r == 0);
+
+ ASSERT(close_cb_called == 0);
+ ASSERT(cl_send_cb_called == 0);
+ ASSERT(cl_recv_cb_called == 0);
+ ASSERT(sv_send_cb_called == 0);
+ ASSERT(sv_recv_cb_called == 0);
+
+ uv_run();
+
+ ASSERT(cl_send_cb_called == 1);
+ ASSERT(cl_recv_cb_called == 1);
+ ASSERT(sv_send_cb_called == 1);
+ ASSERT(sv_recv_cb_called == 1);
+ ASSERT(close_cb_called == 2);
+
+ return 0;
+}