summaryrefslogtreecommitdiff
path: root/deps/uv/test
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/test')
-rw-r--r--deps/uv/test/test-fs.c46
-rw-r--r--deps/uv/test/test-list.h7
-rw-r--r--deps/uv/test/test-process-priority.c81
-rw-r--r--deps/uv/test/test-tcp-open.c111
-rw-r--r--deps/uv/test/test.gyp1
5 files changed, 245 insertions, 1 deletions
diff --git a/deps/uv/test/test-fs.c b/deps/uv/test/test-fs.c
index 57da39891a..9c1e8bec20 100644
--- a/deps/uv/test/test-fs.c
+++ b/deps/uv/test/test-fs.c
@@ -3069,6 +3069,52 @@ TEST_IMPL(get_osfhandle_valid_handle) {
return 0;
}
+TEST_IMPL(open_osfhandle_valid_handle) {
+ int r;
+ uv_os_fd_t handle;
+ int fd;
+
+ /* Setup. */
+ unlink("test_file");
+
+ loop = uv_default_loop();
+
+ r = uv_fs_open(NULL,
+ &open_req1,
+ "test_file",
+ O_RDWR | O_CREAT,
+ S_IWUSR | S_IRUSR,
+ NULL);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
+ uv_fs_req_cleanup(&open_req1);
+
+ handle = uv_get_osfhandle(open_req1.result);
+#ifdef _WIN32
+ ASSERT(handle != INVALID_HANDLE_VALUE);
+#else
+ ASSERT(handle >= 0);
+#endif
+
+ fd = uv_open_osfhandle(handle);
+#ifdef _WIN32
+ ASSERT(fd > 0);
+#else
+ ASSERT(fd == open_req1.result);
+#endif
+
+ r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
+ uv_fs_req_cleanup(&close_req);
+
+ /* Cleanup. */
+ unlink("test_file");
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
+
TEST_IMPL(fs_file_pos_after_op_with_offset) {
int r;
diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h
index 24ba37461e..b501722d4d 100644
--- a/deps/uv/test/test-list.h
+++ b/deps/uv/test/test-list.h
@@ -121,6 +121,7 @@ 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 (tcp_write_ready)
TEST_DECLARE (udp_alloc_cb_fail)
TEST_DECLARE (udp_bind)
TEST_DECLARE (udp_bind_reuseaddr)
@@ -213,6 +214,7 @@ TEST_DECLARE (pipe_close_stdout_read_stdin)
TEST_DECLARE (pipe_set_non_blocking)
TEST_DECLARE (pipe_set_chmod)
TEST_DECLARE (process_ref)
+TEST_DECLARE (process_priority)
TEST_DECLARE (has_ref)
TEST_DECLARE (active)
TEST_DECLARE (embed)
@@ -334,6 +336,7 @@ TEST_DECLARE (fs_rename_to_existing_file)
TEST_DECLARE (fs_write_multiple_bufs)
TEST_DECLARE (fs_read_write_null_arguments)
TEST_DECLARE (get_osfhandle_valid_handle)
+TEST_DECLARE (open_osfhandle_valid_handle)
TEST_DECLARE (fs_write_alotof_bufs)
TEST_DECLARE (fs_write_alotof_bufs_with_offset)
TEST_DECLARE (fs_file_pos_after_op_with_offset)
@@ -544,6 +547,8 @@ TASK_LIST_START
TEST_ENTRY (tcp_open_bound)
TEST_ENTRY (tcp_open_connected)
TEST_HELPER (tcp_open_connected, tcp4_echo_server)
+ TEST_ENTRY (tcp_write_ready)
+ TEST_HELPER (tcp_write_ready, tcp4_echo_server)
TEST_ENTRY (tcp_shutdown_after_write)
TEST_HELPER (tcp_shutdown_after_write, tcp4_echo_server)
@@ -685,6 +690,7 @@ TASK_LIST_START
TEST_ENTRY (pipe_ref4)
TEST_HELPER (pipe_ref4, pipe_echo_server)
TEST_ENTRY (process_ref)
+ TEST_ENTRY (process_priority)
TEST_ENTRY (has_ref)
TEST_ENTRY (loop_handles)
@@ -887,6 +893,7 @@ TASK_LIST_START
TEST_ENTRY (fs_fchmod_archive_readonly)
#endif
TEST_ENTRY (get_osfhandle_valid_handle)
+ TEST_ENTRY (open_osfhandle_valid_handle)
TEST_ENTRY (threadpool_queue_work_simple)
TEST_ENTRY (threadpool_queue_work_einval)
TEST_ENTRY (threadpool_multiple_event_loops)
diff --git a/deps/uv/test/test-process-priority.c b/deps/uv/test/test-process-priority.c
new file mode 100644
index 0000000000..ebee6b90af
--- /dev/null
+++ b/deps/uv/test/test-process-priority.c
@@ -0,0 +1,81 @@
+/* Copyright libuv 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"
+
+
+TEST_IMPL(process_priority) {
+ int priority;
+ int r;
+ int i;
+
+#if defined(__MVS__)
+ if (uv_os_setpriority(0, 0) == UV_ENOSYS)
+ RETURN_SKIP("functionality not supported on zOS");
+#endif
+
+ /* Verify that passing a NULL pointer returns UV_EINVAL. */
+ r = uv_os_getpriority(0, NULL);
+ ASSERT(r == UV_EINVAL);
+
+ /* Verify that all valid values work. */
+ for (i = UV_PRIORITY_HIGHEST; i <= UV_PRIORITY_LOW; i++) {
+ r = uv_os_setpriority(0, i);
+
+ /* If UV_EACCES is returned, the current user doesn't have permission to
+ set this specific priority. */
+ if (r == UV_EACCES)
+ continue;
+
+ ASSERT(r == 0);
+ ASSERT(uv_os_getpriority(0, &priority) == 0);
+
+ /* Verify that the priority values match on Unix, and are range mapped
+ on Windows. */
+#ifndef _WIN32
+ ASSERT(priority == i);
+#else
+ if (i < UV_PRIORITY_HIGH)
+ ASSERT(priority == UV_PRIORITY_HIGHEST);
+ else if (i < UV_PRIORITY_ABOVE_NORMAL)
+ ASSERT(priority == UV_PRIORITY_HIGH);
+ else if (i < UV_PRIORITY_NORMAL)
+ ASSERT(priority == UV_PRIORITY_ABOVE_NORMAL);
+ else if (i < UV_PRIORITY_BELOW_NORMAL)
+ ASSERT(priority == UV_PRIORITY_NORMAL);
+ else if (i < UV_PRIORITY_LOW)
+ ASSERT(priority == UV_PRIORITY_BELOW_NORMAL);
+ else
+ ASSERT(priority == UV_PRIORITY_LOW);
+#endif
+
+ /* Verify that the current PID and 0 are equivalent. */
+ ASSERT(uv_os_getpriority(uv_os_getpid(), &r) == 0);
+ ASSERT(priority == r);
+ }
+
+ /* Verify that invalid priorities return UV_EINVAL. */
+ ASSERT(uv_os_setpriority(0, UV_PRIORITY_HIGHEST - 1) == UV_EINVAL);
+ ASSERT(uv_os_setpriority(0, UV_PRIORITY_LOW + 1) == UV_EINVAL);
+
+ return 0;
+}
diff --git a/deps/uv/test/test-tcp-open.c b/deps/uv/test/test-tcp-open.c
index f5d8f136b1..0d92886d61 100644
--- a/deps/uv/test/test-tcp-open.c
+++ b/deps/uv/test/test-tcp-open.c
@@ -30,6 +30,7 @@
#endif
static int shutdown_cb_called = 0;
+static int shutdown_requested = 0;
static int connect_cb_called = 0;
static int write_cb_called = 0;
static int close_cb_called = 0;
@@ -37,6 +38,8 @@ static int close_cb_called = 0;
static uv_connect_t connect_req;
static uv_shutdown_t shutdown_req;
static uv_write_t write_req;
+static uv_timer_t tm;
+static uv_tcp_t client;
static void startup(void) {
@@ -116,6 +119,20 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
}
else {
ASSERT(nread == UV_EOF);
+ uv_close((uv_handle_t*)tcp, close_cb);
+ }
+}
+
+
+static void read1_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
+ int i;
+ ASSERT(tcp != NULL);
+
+ if (nread >= 0) {
+ for (i = 0; i < nread; ++i)
+ ASSERT(buf->base[i] == 'P');
+ } else {
+ ASSERT(nread == UV_EOF);
printf("GOT EOF\n");
uv_close((uv_handle_t*)tcp, close_cb);
}
@@ -134,6 +151,37 @@ static void write_cb(uv_write_t* req, int status) {
}
+static void write1_cb(uv_write_t* req, int status) {
+ uv_buf_t buf;
+ int r;
+
+ ASSERT(req != NULL);
+ if (status) {
+ ASSERT(shutdown_cb_called);
+ return;
+ }
+
+ if (shutdown_requested)
+ return;
+
+ buf = uv_buf_init("P", 1);
+ r = uv_write(&write_req, req->handle, &buf, 1, write1_cb);
+ ASSERT(r == 0);
+
+ write_cb_called++;
+}
+
+
+static void timer_cb(uv_timer_t* handle) {
+ int r;
+
+ /* Shutdown on drain. */
+ r = uv_shutdown(&shutdown_req, (uv_stream_t*) &client, shutdown_cb);
+ ASSERT(r == 0);
+ shutdown_requested++;
+}
+
+
static void connect_cb(uv_connect_t* req, int status) {
uv_buf_t buf = uv_buf_init("PING", 4);
uv_stream_t* stream;
@@ -158,9 +206,35 @@ static void connect_cb(uv_connect_t* req, int status) {
}
+static void connect1_cb(uv_connect_t* req, int status) {
+ uv_buf_t buf;
+ uv_stream_t* stream;
+ int r;
+
+ ASSERT(req == &connect_req);
+ ASSERT(status == 0);
+
+ stream = req->handle;
+ connect_cb_called++;
+
+ r = uv_timer_init(uv_default_loop(), &tm);
+ ASSERT(r == 0);
+
+ r = uv_timer_start(&tm, timer_cb, 2000, 0);
+ ASSERT(r == 0);
+
+ buf = uv_buf_init("P", 1);
+ r = uv_write(&write_req, stream, &buf, 1, write1_cb);
+ ASSERT(r == 0);
+
+ /* Start reading */
+ r = uv_read_start(stream, alloc_cb, read1_cb);
+ ASSERT(r == 0);
+}
+
+
TEST_IMPL(tcp_open) {
struct sockaddr_in addr;
- uv_tcp_t client;
uv_os_sock_t sock;
int r;
@@ -289,3 +363,38 @@ TEST_IMPL(tcp_open_connected) {
MAKE_VALGRIND_HAPPY();
return 0;
}
+
+
+TEST_IMPL(tcp_write_ready) {
+ struct sockaddr_in addr;
+ uv_os_sock_t sock;
+ int r;
+
+ ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
+
+ startup();
+ sock = create_tcp_socket();
+
+ r = uv_tcp_init(uv_default_loop(), &client);
+ ASSERT(r == 0);
+
+ r = uv_tcp_open(&client, sock);
+ ASSERT(r == 0);
+
+ r = uv_tcp_connect(&connect_req,
+ &client,
+ (const struct sockaddr*) &addr,
+ connect1_cb);
+ ASSERT(r == 0);
+
+ uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+
+ ASSERT(shutdown_cb_called == 1);
+ ASSERT(shutdown_requested == 1);
+ ASSERT(connect_cb_called == 1);
+ ASSERT(write_cb_called > 0);
+ ASSERT(close_cb_called == 1);
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
diff --git a/deps/uv/test/test.gyp b/deps/uv/test/test.gyp
index 917533618b..855eda1c50 100644
--- a/deps/uv/test/test.gyp
+++ b/deps/uv/test/test.gyp
@@ -80,6 +80,7 @@
'test-poll-close-doesnt-corrupt-stack.c',
'test-poll-closesocket.c',
'test-poll-oob.c',
+ 'test-process-priority.c',
'test-process-title.c',
'test-process-title-threadsafe.c',
'test-queue-foreach-delete.c',