diff options
Diffstat (limited to 'deps/uv/test')
-rw-r--r-- | deps/uv/test/run-tests.c | 5 | ||||
-rw-r--r-- | deps/uv/test/test-fs-event.c | 102 | ||||
-rw-r--r-- | deps/uv/test/test-ipc-heavy-traffic-deadlock-bug.c | 2 | ||||
-rw-r--r-- | deps/uv/test/test-ipc-send-recv.c | 3 | ||||
-rw-r--r-- | deps/uv/test/test-ipc.c | 141 | ||||
-rw-r--r-- | deps/uv/test/test-list.h | 10 | ||||
-rw-r--r-- | deps/uv/test/test-platform-output.c | 9 | ||||
-rw-r--r-- | deps/uv/test/test-uname.c | 69 | ||||
-rw-r--r-- | deps/uv/test/test.gyp | 1 |
9 files changed, 278 insertions, 64 deletions
diff --git a/deps/uv/test/run-tests.c b/deps/uv/test/run-tests.c index 2a699f46dc..eba28ecb9a 100644 --- a/deps/uv/test/run-tests.c +++ b/deps/uv/test/run-tests.c @@ -42,6 +42,7 @@ int ipc_helper_tcp_connection(void); int ipc_helper_closed_handle(void); int ipc_send_recv_helper(void); int ipc_helper_bind_twice(void); +int ipc_helper_send_zero(void); int stdio_over_pipes_helper(void); int spawn_stdin_stdout(void); int spawn_tcp_server_helper(void); @@ -104,6 +105,10 @@ static int maybe_run_test(int argc, char **argv) { return ipc_helper_bind_twice(); } + if (strcmp(argv[1], "ipc_helper_send_zero") == 0) { + return ipc_helper_send_zero(); + } + if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } diff --git a/deps/uv/test/test-fs-event.c b/deps/uv/test/test-fs-event.c index 5ddccffd0a..ea34bd63a7 100644 --- a/deps/uv/test/test-fs-event.c +++ b/deps/uv/test/test-fs-event.c @@ -480,6 +480,8 @@ TEST_IMPL(fs_event_watch_dir_recursive) { #ifdef _WIN32 TEST_IMPL(fs_event_watch_dir_short_path) { uv_loop_t* loop; + uv_fs_t req; + int has_shortnames; int r; /* Setup */ @@ -489,26 +491,37 @@ TEST_IMPL(fs_event_watch_dir_short_path) { create_dir("watch_dir"); create_file("watch_dir/file1"); - r = uv_fs_event_init(loop, &fs_event); - ASSERT(r == 0); - r = uv_fs_event_start(&fs_event, fs_event_cb_dir, "watch_~1", 0); - ASSERT(r == 0); - r = uv_timer_init(loop, &timer); - ASSERT(r == 0); - r = uv_timer_start(&timer, timer_cb_file, 100, 0); - ASSERT(r == 0); + /* Newer version of Windows ship with + HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation + not equal to 0. So we verify the files we created are addressable by a 8.3 + short name */ + has_shortnames = uv_fs_stat(NULL, &req, "watch_~1", NULL) != UV_ENOENT; + if (has_shortnames) { + r = uv_fs_event_init(loop, &fs_event); + ASSERT(r == 0); + r = uv_fs_event_start(&fs_event, fs_event_cb_dir, "watch_~1", 0); + ASSERT(r == 0); + r = uv_timer_init(loop, &timer); + ASSERT(r == 0); + r = uv_timer_start(&timer, timer_cb_file, 100, 0); + ASSERT(r == 0); - uv_run(loop, UV_RUN_DEFAULT); + uv_run(loop, UV_RUN_DEFAULT); - ASSERT(fs_event_cb_called == 1); - ASSERT(timer_cb_called == 1); - ASSERT(close_cb_called == 1); + ASSERT(fs_event_cb_called == 1); + ASSERT(timer_cb_called == 1); + ASSERT(close_cb_called == 1); + } /* Cleanup */ remove("watch_dir/file1"); remove("watch_dir/"); MAKE_VALGRIND_HAPPY(); + + if (!has_shortnames) + RETURN_SKIP("Was not able to address files with 8.3 short name."); + return 0; } #endif @@ -576,6 +589,14 @@ TEST_IMPL(fs_event_watch_file_exact_path) { create_dir("watch_dir"); create_file("watch_dir/file.js"); create_file("watch_dir/file.jsx"); +#if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_12) + /* Empirically, FSEvents seems to (reliably) report the preceeding + * create_file events prior to macOS 10.11.6 in the subsequent fs_watch + * creation, but that behavior hasn't been observed to occur on newer + * versions. Give a long delay here to let the system settle before running + * the test. */ + uv_sleep(1100); +#endif r = uv_fs_event_init(loop, &fs_event); ASSERT(r == 0); @@ -648,7 +669,7 @@ TEST_IMPL(fs_event_watch_file_current_dir) { r = uv_timer_init(loop, &timer); ASSERT(r == 0); - r = uv_timer_start(&timer, timer_cb_touch, 100, 0); + r = uv_timer_start(&timer, timer_cb_touch, 1100, 0); ASSERT(r == 0); ASSERT(timer_cb_touch_called == 0); @@ -936,32 +957,48 @@ TEST_IMPL(fs_event_getpath) { RETURN_SKIP(NO_FS_EVENTS); #endif uv_loop_t* loop = uv_default_loop(); + unsigned i; int r; char buf[1024]; size_t len; + const char* const watch_dir[] = { + "watch_dir", + "watch_dir/", + "watch_dir///", + "watch_dir/subfolder/..", + "watch_dir//subfolder//..//", + }; create_dir("watch_dir"); + create_dir("watch_dir/subfolder"); - r = uv_fs_event_init(loop, &fs_event); - ASSERT(r == 0); - len = sizeof buf; - r = uv_fs_event_getpath(&fs_event, buf, &len); - ASSERT(r == UV_EINVAL); - r = uv_fs_event_start(&fs_event, fail_cb, "watch_dir", 0); - ASSERT(r == 0); - len = sizeof buf; - r = uv_fs_event_getpath(&fs_event, buf, &len); - ASSERT(r == 0); - ASSERT(buf[len - 1] != 0); - ASSERT(buf[len] == '\0'); - ASSERT(memcmp(buf, "watch_dir", len) == 0); - r = uv_fs_event_stop(&fs_event); - ASSERT(r == 0); - uv_close((uv_handle_t*) &fs_event, close_cb); - uv_run(loop, UV_RUN_DEFAULT); + for (i = 0; i < ARRAY_SIZE(watch_dir); i++) { + r = uv_fs_event_init(loop, &fs_event); + ASSERT(r == 0); + len = sizeof buf; + r = uv_fs_event_getpath(&fs_event, buf, &len); + ASSERT(r == UV_EINVAL); + r = uv_fs_event_start(&fs_event, fail_cb, watch_dir[i], 0); + ASSERT(r == 0); + len = 0; + r = uv_fs_event_getpath(&fs_event, buf, &len); + ASSERT(r == UV_ENOBUFS); + ASSERT(len < sizeof buf); /* sanity check */ + ASSERT(len == strlen(watch_dir[i]) + 1); + r = uv_fs_event_getpath(&fs_event, buf, &len); + ASSERT(r == 0); + ASSERT(len == strlen(watch_dir[i])); + ASSERT(strcmp(buf, watch_dir[i]) == 0); + r = uv_fs_event_stop(&fs_event); + ASSERT(r == 0); + uv_close((uv_handle_t*) &fs_event, close_cb); - ASSERT(close_cb_called == 1); + uv_run(loop, UV_RUN_DEFAULT); + + ASSERT(close_cb_called == 1); + close_cb_called = 0; + } remove("watch_dir/"); MAKE_VALGRIND_HAPPY(); @@ -1082,6 +1119,9 @@ TEST_IMPL(fs_event_watch_invalid_path) { r = uv_fs_event_start(&fs_event, fs_event_cb_file, "<:;", 0); ASSERT(r != 0); ASSERT(uv_is_active((uv_handle_t*) &fs_event) == 0); + r = uv_fs_event_start(&fs_event, fs_event_cb_file, "", 0); + ASSERT(r != 0); + ASSERT(uv_is_active((uv_handle_t*) &fs_event) == 0); MAKE_VALGRIND_HAPPY(); return 0; } diff --git a/deps/uv/test/test-ipc-heavy-traffic-deadlock-bug.c b/deps/uv/test/test-ipc-heavy-traffic-deadlock-bug.c index 325305a644..753fb7b7c2 100644 --- a/deps/uv/test/test-ipc-heavy-traffic-deadlock-bug.c +++ b/deps/uv/test/test-ipc-heavy-traffic-deadlock-bug.c @@ -55,7 +55,7 @@ static void write_cb(uv_write_t* req, int status) { } static void shutdown_cb(uv_shutdown_t* req, int status) { - ASSERT(status == 0); + ASSERT(status == 0 || status == UV_ENOTCONN); uv_close((uv_handle_t*) req->handle, NULL); } diff --git a/deps/uv/test/test-ipc-send-recv.c b/deps/uv/test/test-ipc-send-recv.c index 166225c01c..12d4e33221 100644 --- a/deps/uv/test/test-ipc-send-recv.c +++ b/deps/uv/test/test-ipc-send-recv.c @@ -149,7 +149,6 @@ static void connect_cb(uv_connect_t* req, int status) { &ctx.send.stream, NULL); ASSERT(r == 0); - ASSERT(ctx.write_req.send_handle == &ctx.send.stream); /* Perform two writes to the same pipe to make sure that on Windows we are * not running into issue 505: @@ -161,7 +160,6 @@ static void connect_cb(uv_connect_t* req, int status) { &ctx.send2.stream, NULL); ASSERT(r == 0); - ASSERT(ctx.write_req2.send_handle == &ctx.send2.stream); r = uv_read_start((uv_stream_t*)&ctx.channel, alloc_cb, recv_cb); ASSERT(r == 0); @@ -346,7 +344,6 @@ static void read_cb(uv_stream_t* handle, &recv->stream, write2_cb); ASSERT(r == 0); - ASSERT(write_req->send_handle == &recv->stream); } while (uv_pipe_pending_count(pipe) > 0); } diff --git a/deps/uv/test/test-ipc.c b/deps/uv/test/test-ipc.c index 829d178d47..88d04ba143 100644 --- a/deps/uv/test/test-ipc.c +++ b/deps/uv/test/test-ipc.c @@ -39,12 +39,15 @@ static int local_conn_accepted; static int remote_conn_accepted; static int tcp_server_listening; static uv_write_t write_req; +static uv_write_t write_req2; static uv_write_t conn_notify_req; static int close_cb_called; static int connection_accepted; static int tcp_conn_read_cb_called; static int tcp_conn_write_cb_called; static int closed_handle_data_read; +static int closed_handle_write; +static int send_zero_write; typedef struct { uv_connect_t conn_req; @@ -54,7 +57,15 @@ typedef struct { #define CONN_COUNT 100 #define BACKLOG 128 -#define LARGE_SIZE 1000000 +#define LARGE_SIZE 100000 + +static uv_buf_t large_buf; +static char buffer[LARGE_SIZE]; +static uv_write_t write_reqs[300]; +static int write_reqs_completed; + +static unsigned int write_until_data_queued(void); +static void send_handle_and_close(void); static void close_server_conn_cb(uv_handle_t* handle) { @@ -92,6 +103,7 @@ static void exit_cb(uv_process_t* process, printf("exit_cb\n"); exit_cb_called++; ASSERT(exit_status == 0); + ASSERT(term_signal == 0); uv_close((uv_handle_t*)process, NULL); } @@ -420,6 +432,14 @@ static void on_read_closed_handle(uv_stream_t* handle, #endif +static void on_read_send_zero(uv_stream_t* handle, + ssize_t nread, + const uv_buf_t* buf) { + ASSERT(nread == 0 || nread == UV_EOF); + free(buf->base); +} + + static int run_ipc_test(const char* helper, uv_read_cb read_cb) { uv_process_t process; int r; @@ -544,6 +564,13 @@ TEST_IMPL(ipc_listen_after_bind_twice) { } #endif +TEST_IMPL(ipc_send_zero) { + int r; + r = run_ipc_test("ipc_helper_send_zero", on_read_send_zero); + ASSERT(r == 0); + return 0; +} + /* Everything here runs in a child process. */ @@ -573,14 +600,25 @@ static void tcp_connection_write_cb(uv_write_t* req, int status) { static void closed_handle_large_write_cb(uv_write_t* req, int status) { ASSERT(status == 0); ASSERT(closed_handle_data_read = LARGE_SIZE); + if (++write_reqs_completed == ARRAY_SIZE(write_reqs)) { + write_reqs_completed = 0; + if (write_until_data_queued() > 0) + send_handle_and_close(); + } } static void closed_handle_write_cb(uv_write_t* req, int status) { ASSERT(status == UV_EBADF); + closed_handle_write = 1; } +static void send_zero_write_cb(uv_write_t* req, int status) { + ASSERT(status == 0); + send_zero_write++; +} + static void on_tcp_child_process_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) { @@ -688,7 +726,6 @@ int ipc_helper(int listen_after_write) { * over which a handle will be transmitted. */ struct sockaddr_in addr; - uv_write_t write_req; int r; uv_buf_t buf; @@ -788,26 +825,28 @@ int ipc_helper_tcp_connection(void) { return 0; } - -int ipc_helper_closed_handle(void) { +static unsigned int write_until_data_queued() { + unsigned int i; int r; - struct sockaddr_in addr; - uv_write_t write_req; - uv_write_t write_req2; - uv_buf_t buf; - char buffer[LARGE_SIZE]; - r = uv_pipe_init(uv_default_loop(), &channel, 1); - ASSERT(r == 0); - - uv_pipe_open(&channel, 0); + i = 0; + do { + r = uv_write(&write_reqs[i], + (uv_stream_t*)&channel, + &large_buf, + 1, + closed_handle_large_write_cb); + ASSERT(r == 0); + i++; + } while (((uv_stream_t*)&channel)->write_queue_size == 0 && + i < ARRAY_SIZE(write_reqs)); - ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); - ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); - ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); + return ((uv_stream_t*)&channel)->write_queue_size; +} - memset(buffer, '.', LARGE_SIZE); - buf = uv_buf_init(buffer, LARGE_SIZE); +static void send_handle_and_close() { + int r; + struct sockaddr_in addr; r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); @@ -817,26 +856,40 @@ int ipc_helper_closed_handle(void) { r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); - r = uv_write(&write_req, - (uv_stream_t*)&channel, - &buf, - 1, - closed_handle_large_write_cb); - ASSERT(r == 0); - - r = uv_write2(&write_req2, + r = uv_write2(&write_req, (uv_stream_t*)&channel, - &buf, + &large_buf, 1, (uv_stream_t*)&tcp_server, closed_handle_write_cb); ASSERT(r == 0); uv_close((uv_handle_t*)&tcp_server, NULL); +} + +int ipc_helper_closed_handle(void) { + int r; + + memset(buffer, '.', LARGE_SIZE); + large_buf = uv_buf_init(buffer, LARGE_SIZE); + + r = uv_pipe_init(uv_default_loop(), &channel, 1); + ASSERT(r == 0); + + uv_pipe_open(&channel, 0); + + ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); + ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); + ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); + + if (write_until_data_queued() > 0) + send_handle_and_close(); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); + ASSERT(closed_handle_write == 1); + MAKE_VALGRIND_HAPPY(); return 0; } @@ -848,8 +901,6 @@ int ipc_helper_bind_twice(void) { * over which two handles will be transmitted. */ struct sockaddr_in addr; - uv_write_t write_req; - uv_write_t write_req2; int r; uv_buf_t buf; @@ -889,3 +940,35 @@ int ipc_helper_bind_twice(void) { MAKE_VALGRIND_HAPPY(); return 0; } + +int ipc_helper_send_zero(void) { + int r; + uv_buf_t zero_buf; + + zero_buf = uv_buf_init(0, 0); + + r = uv_pipe_init(uv_default_loop(), &channel, 0); + ASSERT(r == 0); + + uv_pipe_open(&channel, 0); + + ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); + ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); + ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); + + r = uv_write(&write_req, + (uv_stream_t*)&channel, + &zero_buf, + 1, + send_zero_write_cb); + + ASSERT(r == 0); + + r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); + ASSERT(r == 0); + + ASSERT(send_zero_write == 1); + + MAKE_VALGRIND_HAPPY(); + return 0; +}
\ No newline at end of file diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index cc37bc039b..53372c90f7 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -69,6 +69,7 @@ TEST_DECLARE (ipc_send_recv_pipe_inprocess) TEST_DECLARE (ipc_send_recv_tcp) TEST_DECLARE (ipc_send_recv_tcp_inprocess) TEST_DECLARE (ipc_tcp_connection) +TEST_DECLARE (ipc_send_zero) #ifndef _WIN32 TEST_DECLARE (ipc_closed_handle) #endif @@ -436,9 +437,13 @@ TEST_DECLARE (fork_socketpair) TEST_DECLARE (fork_socketpair_started) TEST_DECLARE (fork_signal_to_child) TEST_DECLARE (fork_signal_to_child_closed) +#ifndef __APPLE__ /* This is forbidden in a fork child: The process has forked + and you cannot use this CoreFoundation functionality + safely. You MUST exec(). */ TEST_DECLARE (fork_fs_events_child) TEST_DECLARE (fork_fs_events_child_dir) TEST_DECLARE (fork_fs_events_file_parent_child) +#endif #ifndef __MVS__ TEST_DECLARE (fork_threadpool_queue_work_simple) #endif @@ -446,6 +451,7 @@ TEST_DECLARE (fork_threadpool_queue_work_simple) TEST_DECLARE (idna_toascii) TEST_DECLARE (utf8_decode1) +TEST_DECLARE (uname) TASK_LIST_START TEST_ENTRY_CUSTOM (platform_output, 0, 1, 5000) @@ -510,6 +516,7 @@ TASK_LIST_START TEST_ENTRY (ipc_send_recv_tcp) TEST_ENTRY (ipc_send_recv_tcp_inprocess) TEST_ENTRY (ipc_tcp_connection) + TEST_ENTRY (ipc_send_zero) #ifndef _WIN32 TEST_ENTRY (ipc_closed_handle) #endif @@ -945,15 +952,18 @@ TASK_LIST_START TEST_ENTRY (fork_socketpair_started) TEST_ENTRY (fork_signal_to_child) TEST_ENTRY (fork_signal_to_child_closed) +#ifndef __APPLE__ TEST_ENTRY (fork_fs_events_child) TEST_ENTRY (fork_fs_events_child_dir) TEST_ENTRY (fork_fs_events_file_parent_child) +#endif #ifndef __MVS__ TEST_ENTRY (fork_threadpool_queue_work_simple) #endif #endif TEST_ENTRY (utf8_decode1) + TEST_ENTRY (uname) /* Doesn't work on z/OS because that platform uses EBCDIC, not ASCII. */ #ifndef __MVS__ diff --git a/deps/uv/test/test-platform-output.c b/deps/uv/test/test-platform-output.c index 43ed119deb..e651e5c582 100644 --- a/deps/uv/test/test-platform-output.c +++ b/deps/uv/test/test-platform-output.c @@ -35,6 +35,7 @@ TEST_IMPL(platform_output) { uv_cpu_info_t* cpus; uv_interface_address_t* interfaces; uv_passwd_t pwd; + uv_utsname_t uname; int count; int i; int err; @@ -153,5 +154,13 @@ TEST_IMPL(platform_output) { ASSERT(ppid > 0); printf("uv_os_getppid: %d\n", (int) ppid); + err = uv_os_uname(&uname); + ASSERT(err == 0); + printf("uv_os_uname:\n"); + printf(" sysname: %s\n", uname.sysname); + printf(" release: %s\n", uname.release); + printf(" version: %s\n", uname.version); + printf(" machine: %s\n", uname.machine); + return 0; } diff --git a/deps/uv/test/test-uname.c b/deps/uv/test/test-uname.c new file mode 100644 index 0000000000..105a17fe67 --- /dev/null +++ b/deps/uv/test/test-uname.c @@ -0,0 +1,69 @@ +/* Copyright libuv project 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 <string.h> + +#ifndef _WIN32 +# include <sys/utsname.h> +#endif + +TEST_IMPL(uname) { +#ifndef _WIN32 + struct utsname buf; +#endif +#ifdef _AIX + char temp[256]; +#endif + uv_utsname_t buffer; + int r; + + /* Verify that NULL is handled properly. */ + r = uv_os_uname(NULL); + ASSERT(r == UV_EINVAL); + + /* Verify the happy path. */ + r = uv_os_uname(&buffer); + ASSERT(r == 0); + +#ifndef _WIN32 + ASSERT(uname(&buf) != -1); + ASSERT(strcmp(buffer.sysname, buf.sysname) == 0); + ASSERT(strcmp(buffer.version, buf.version) == 0); + +# ifdef _AIX + snprintf(temp, sizeof(temp), "%s.%s", buf.version, buf.release); + ASSERT(strcmp(buffer.release, temp) == 0); +# else + ASSERT(strcmp(buffer.release, buf.release) == 0); +# endif /* _AIX */ + +# if defined(_AIX) || defined(__PASE__) + ASSERT(strcmp(buffer.machine, "ppc64") == 0); +# else + ASSERT(strcmp(buffer.machine, buf.machine) == 0); +# endif /* defined(_AIX) || defined(__PASE__) */ + +#endif /* _WIN32 */ + + return 0; +} diff --git a/deps/uv/test/test.gyp b/deps/uv/test/test.gyp index ae7dc0d628..604925861e 100644 --- a/deps/uv/test/test.gyp +++ b/deps/uv/test/test.gyp @@ -154,6 +154,7 @@ 'test-udp-multicast-interface.c', 'test-udp-multicast-interface6.c', 'test-udp-try-send.c', + 'test-uname.c', ], 'conditions': [ [ 'OS=="win"', { |