diff options
Diffstat (limited to 'deps/uv/test')
-rw-r--r-- | deps/uv/test/test-condvar.c | 54 | ||||
-rw-r--r-- | deps/uv/test/test-fork.c | 2 | ||||
-rw-r--r-- | deps/uv/test/test-fs-copyfile.c | 11 | ||||
-rw-r--r-- | deps/uv/test/test-fs-event.c | 4 | ||||
-rw-r--r-- | deps/uv/test/test-fs.c | 42 | ||||
-rw-r--r-- | deps/uv/test/test-ipc-send-recv.c | 2 | ||||
-rw-r--r-- | deps/uv/test/test-list.h | 2 | ||||
-rw-r--r-- | deps/uv/test/test.gyp | 279 |
8 files changed, 382 insertions, 14 deletions
diff --git a/deps/uv/test/test-condvar.c b/deps/uv/test/test-condvar.c index 83b28494ad..d956efef3c 100644 --- a/deps/uv/test/test-condvar.c +++ b/deps/uv/test/test-condvar.c @@ -34,7 +34,7 @@ typedef struct worker_config { volatile int posted_1; volatile int posted_2; void (*signal_cond)(struct worker_config* c, volatile int* flag); - void (*wait_cond)(struct worker_config* c, const volatile int* flag); + int (*wait_cond)(struct worker_config* c, const volatile int* flag); } worker_config; @@ -44,6 +44,9 @@ static void worker(void* arg) { c->wait_cond(c, &c->posted_2); } +static void noop_worker(void* arg) { + return; +} static void condvar_signal(worker_config* c, volatile int* flag) { if (c->signal_delay) @@ -60,7 +63,7 @@ static void condvar_signal(worker_config* c, volatile int* flag) { } -static void condvar_wait(worker_config* c, const volatile int* flag) { +static int condvar_wait(worker_config* c, const volatile int* flag) { uv_mutex_lock(&c->mutex); if (c->wait_delay) uv_sleep(c->wait_delay); @@ -69,6 +72,8 @@ static void condvar_wait(worker_config* c, const volatile int* flag) { } ASSERT(*flag == 1); uv_mutex_unlock(&c->mutex); + + return 0; } @@ -85,7 +90,7 @@ TEST_IMPL(condvar_1) { ASSERT(0 == uv_mutex_init(&wc.mutex)); ASSERT(0 == uv_thread_create(&thread, worker, &wc)); - wc.wait_cond(&wc, &wc.posted_1); + ASSERT(0 == wc.wait_cond(&wc, &wc.posted_1)); wc.signal_cond(&wc, &wc.posted_2); ASSERT(0 == uv_thread_join(&thread)); @@ -109,7 +114,7 @@ TEST_IMPL(condvar_2) { ASSERT(0 == uv_mutex_init(&wc.mutex)); ASSERT(0 == uv_thread_create(&thread, worker, &wc)); - wc.wait_cond(&wc, &wc.posted_1); + ASSERT(0 == wc.wait_cond(&wc, &wc.posted_1)); wc.signal_cond(&wc, &wc.posted_2); ASSERT(0 == uv_thread_join(&thread)); @@ -120,20 +125,26 @@ TEST_IMPL(condvar_2) { } -static void condvar_timedwait(worker_config* c, const volatile int* flag) { +static int condvar_timedwait(worker_config* c, const volatile int* flag) { int r; + r = 0; + uv_mutex_lock(&c->mutex); if (c->wait_delay) uv_sleep(c->wait_delay); while (*flag == 0) { r = uv_cond_timedwait(&c->cond, &c->mutex, (uint64_t)(150 * 1e6)); - ASSERT(r == 0); + ASSERT(r == 0 || r == UV_ETIMEDOUT); + if (r == UV_ETIMEDOUT) + break; } uv_mutex_unlock(&c->mutex); -} + return r; +} +/* Test that uv_cond_timedwait will return early when cond is signaled. */ TEST_IMPL(condvar_3) { uv_thread_t thread; worker_config wc; @@ -147,7 +158,7 @@ TEST_IMPL(condvar_3) { ASSERT(0 == uv_mutex_init(&wc.mutex)); ASSERT(0 == uv_thread_create(&thread, worker, &wc)); - wc.wait_cond(&wc, &wc.posted_1); + ASSERT(0 == wc.wait_cond(&wc, &wc.posted_1)); wc.signal_cond(&wc, &wc.posted_2); ASSERT(0 == uv_thread_join(&thread)); @@ -205,3 +216,30 @@ TEST_IMPL(condvar_5) { return 0; } + +/* Test that uv_cond_timedwait will time out when cond is not signaled. */ +TEST_IMPL(condvar_6) { + uv_thread_t thread; + worker_config wc; + int r; + + memset(&wc, 0, sizeof(wc)); + wc.signal_delay = 100; + wc.signal_cond = condvar_signal; + wc.wait_cond = condvar_timedwait; + + ASSERT(0 == uv_cond_init(&wc.cond)); + ASSERT(0 == uv_mutex_init(&wc.mutex)); + ASSERT(0 == uv_thread_create(&thread, noop_worker, &wc)); + + /* This can only return having timed out, because otherwise we + * loop forever in condvar_timedwait. */ + r = wc.wait_cond(&wc, &wc.posted_1); + ASSERT(r == UV_ETIMEDOUT); + + ASSERT(0 == uv_thread_join(&thread)); + uv_mutex_destroy(&wc.mutex); + uv_cond_destroy(&wc.cond); + + return 0; +} diff --git a/deps/uv/test/test-fork.c b/deps/uv/test/test-fork.c index 924c65b214..39b59c8f20 100644 --- a/deps/uv/test/test-fork.c +++ b/deps/uv/test/test-fork.c @@ -335,7 +335,7 @@ TEST_IMPL(fork_signal_to_child_closed) { /* Note that we're deliberately not running the loop * in the child, and also not closing the loop's handles, * so the child default loop can't be cleanly closed. - * We need te explicitly exit to avoid an automatic failure + * We need to explicitly exit to avoid an automatic failure * in that case. */ exit(0); diff --git a/deps/uv/test/test-fs-copyfile.c b/deps/uv/test/test-fs-copyfile.c index 460c1dc6ae..4b1fdc5e79 100644 --- a/deps/uv/test/test-fs-copyfile.c +++ b/deps/uv/test/test-fs-copyfile.c @@ -36,6 +36,10 @@ static const char dst[] = "test_file_dst"; static int result_check_count; +static void fail_cb(uv_fs_t* req) { + FATAL("fail_cb should not have been called"); +} + static void handle_result(uv_fs_t* req) { uv_fs_t stat_req; uint64_t size; @@ -158,7 +162,12 @@ TEST_IMPL(fs_copyfile) { ASSERT(result_check_count == 5); uv_run(loop, UV_RUN_DEFAULT); ASSERT(result_check_count == 6); - unlink(dst); /* Cleanup */ + /* If the flags are invalid, the loop should not be kept open */ + unlink(dst); + r = uv_fs_copyfile(loop, &req, fixture, dst, -1, fail_cb); + ASSERT(r == UV_EINVAL); + uv_run(loop, UV_RUN_DEFAULT); + unlink(dst); /* Cleanup */ return 0; } diff --git a/deps/uv/test/test-fs-event.c b/deps/uv/test/test-fs-event.c index dc47b3a62d..39d73300dc 100644 --- a/deps/uv/test/test-fs-event.c +++ b/deps/uv/test/test-fs-event.c @@ -199,7 +199,7 @@ static void fs_event_cb_dir_multi_file(uv_fs_event_t* handle, fs_event_cb_called++; ASSERT(handle == &fs_event); ASSERT(status == 0); - ASSERT(events == UV_CHANGE || UV_RENAME); + ASSERT(events == UV_CHANGE || events == UV_RENAME); #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) ASSERT(strncmp(filename, file_prefix, sizeof(file_prefix) - 1) == 0); #else @@ -283,7 +283,7 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle, fs_event_cb_called++; ASSERT(handle == &fs_event); ASSERT(status == 0); - ASSERT(events == UV_CHANGE || UV_RENAME); + ASSERT(events == UV_CHANGE || events == UV_RENAME); #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) ASSERT(strncmp(filename, file_prefix_in_subdir, diff --git a/deps/uv/test/test-fs.c b/deps/uv/test/test-fs.c index 7c481f0711..3318b86649 100644 --- a/deps/uv/test/test-fs.c +++ b/deps/uv/test/test-fs.c @@ -319,6 +319,9 @@ static void ftruncate_cb(uv_fs_t* req) { ASSERT(r == 0); } +static void fail_cb(uv_fs_t* req) { + FATAL("fail_cb should not have been called"); +} static void read_cb(uv_fs_t* req) { int r; @@ -2884,7 +2887,19 @@ TEST_IMPL(fs_read_write_null_arguments) { uv_fs_req_cleanup(&read_req); r = uv_fs_write(NULL, &write_req, 0, NULL, 0, -1, NULL); + /* Validate some memory management on failed input validation before sending + fs work to the thread pool. */ ASSERT(r == UV_EINVAL); + ASSERT(write_req.path == NULL); + ASSERT(write_req.ptr == NULL); +#ifdef _WIN32 + ASSERT(write_req.file.pathw == NULL); + ASSERT(write_req.fs.info.new_pathw == NULL); + ASSERT(write_req.fs.info.bufs == NULL); +#else + ASSERT(write_req.new_path == NULL); + ASSERT(write_req.bufs == NULL); +#endif uv_fs_req_cleanup(&write_req); iov = uv_buf_init(NULL, 0); @@ -2897,6 +2912,31 @@ TEST_IMPL(fs_read_write_null_arguments) { ASSERT(r == UV_EINVAL); uv_fs_req_cleanup(&write_req); + /* If the arguments are invalid, the loop should not be kept open */ + loop = uv_default_loop(); + + r = uv_fs_read(loop, &read_req, 0, NULL, 0, -1, fail_cb); + ASSERT(r == UV_EINVAL); + uv_run(loop, UV_RUN_DEFAULT); + uv_fs_req_cleanup(&read_req); + + r = uv_fs_write(loop, &write_req, 0, NULL, 0, -1, fail_cb); + ASSERT(r == UV_EINVAL); + uv_run(loop, UV_RUN_DEFAULT); + uv_fs_req_cleanup(&write_req); + + iov = uv_buf_init(NULL, 0); + r = uv_fs_read(loop, &read_req, 0, &iov, 0, -1, fail_cb); + ASSERT(r == UV_EINVAL); + uv_run(loop, UV_RUN_DEFAULT); + uv_fs_req_cleanup(&read_req); + + iov = uv_buf_init(NULL, 0); + r = uv_fs_write(loop, &write_req, 0, &iov, 0, -1, fail_cb); + ASSERT(r == UV_EINVAL); + uv_run(loop, UV_RUN_DEFAULT); + uv_fs_req_cleanup(&write_req); + return 0; } @@ -3084,7 +3124,7 @@ TEST_IMPL(fs_exclusive_sharing_mode) { unlink("test_file"); ASSERT(UV_FS_O_EXLOCK > 0); - + r = uv_fs_open(NULL, &open_req1, "test_file", diff --git a/deps/uv/test/test-ipc-send-recv.c b/deps/uv/test/test-ipc-send-recv.c index 160c235078..917744cbae 100644 --- a/deps/uv/test/test-ipc-send-recv.c +++ b/deps/uv/test/test-ipc-send-recv.c @@ -304,7 +304,7 @@ static void read_cb(uv_stream_t* handle, union handles* recv; uv_write_t* write_req; - if (nread == UV__EOF || nread == UV__ECONNABORTED) { + if (nread == UV_EOF || nread == UV_ECONNABORTED) { return; } diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index 5a50ec6713..ff0a31d16b 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -42,6 +42,7 @@ TEST_DECLARE (condvar_2) TEST_DECLARE (condvar_3) TEST_DECLARE (condvar_4) TEST_DECLARE (condvar_5) +TEST_DECLARE (condvar_6) TEST_DECLARE (semaphore_1) TEST_DECLARE (semaphore_2) TEST_DECLARE (semaphore_3) @@ -445,6 +446,7 @@ TASK_LIST_START TEST_ENTRY (condvar_3) TEST_ENTRY (condvar_4) TEST_ENTRY (condvar_5) + TEST_ENTRY (condvar_6) TEST_ENTRY (semaphore_1) TEST_ENTRY (semaphore_2) TEST_ENTRY (semaphore_3) diff --git a/deps/uv/test/test.gyp b/deps/uv/test/test.gyp new file mode 100644 index 0000000000..480e5a26c4 --- /dev/null +++ b/deps/uv/test/test.gyp @@ -0,0 +1,279 @@ +{ + 'targets': [ + { + 'target_name': 'run-tests', + 'type': 'executable', + 'dependencies': [ '../uv.gyp:libuv' ], + 'sources': [ + 'blackhole-server.c', + 'echo-server.c', + 'run-tests.c', + 'runner.c', + 'runner.h', + 'test-get-loadavg.c', + 'task.h', + 'test-active.c', + 'test-async.c', + 'test-async-null-cb.c', + 'test-callback-stack.c', + 'test-callback-order.c', + 'test-close-fd.c', + 'test-close-order.c', + 'test-connect-unspecified.c', + 'test-connection-fail.c', + 'test-cwd-and-chdir.c', + 'test-default-loop-close.c', + 'test-delayed-accept.c', + 'test-eintr-handling.c', + 'test-error.c', + 'test-embed.c', + 'test-emfile.c', + 'test-env-vars.c', + 'test-fail-always.c', + 'test-fork.c', + 'test-fs.c', + 'test-fs-copyfile.c', + 'test-fs-event.c', + 'test-getters-setters.c', + 'test-get-currentexe.c', + 'test-get-memory.c', + 'test-get-passwd.c', + 'test-getaddrinfo.c', + 'test-gethostname.c', + 'test-getnameinfo.c', + 'test-getsockname.c', + 'test-handle-fileno.c', + 'test-homedir.c', + 'test-hrtime.c', + 'test-idle.c', + 'test-ip6-addr.c', + 'test-ipc.c', + 'test-ipc-send-recv.c', + 'test-list.h', + 'test-loop-handles.c', + 'test-loop-alive.c', + 'test-loop-close.c', + 'test-loop-stop.c', + 'test-loop-time.c', + 'test-loop-configure.c', + 'test-walk-handles.c', + 'test-watcher-cross-stop.c', + 'test-multiple-listen.c', + 'test-osx-select.c', + 'test-pass-always.c', + 'test-ping-pong.c', + 'test-pipe-bind-error.c', + 'test-pipe-connect-error.c', + 'test-pipe-connect-multiple.c', + 'test-pipe-connect-prepare.c', + 'test-pipe-getsockname.c', + 'test-pipe-pending-instances.c', + 'test-pipe-sendmsg.c', + 'test-pipe-server-close.c', + 'test-pipe-close-stdout-read-stdin.c', + 'test-pipe-set-non-blocking.c', + 'test-pipe-set-fchmod.c', + 'test-platform-output.c', + 'test-poll.c', + 'test-poll-close.c', + 'test-poll-close-doesnt-corrupt-stack.c', + 'test-poll-closesocket.c', + 'test-poll-oob.c', + 'test-process-title.c', + 'test-process-title-threadsafe.c', + 'test-queue-foreach-delete.c', + 'test-ref.c', + 'test-run-nowait.c', + 'test-run-once.c', + 'test-semaphore.c', + 'test-shutdown-close.c', + 'test-shutdown-eof.c', + 'test-shutdown-twice.c', + 'test-signal.c', + 'test-signal-multiple-loops.c', + 'test-socket-buffer-size.c', + 'test-spawn.c', + 'test-fs-poll.c', + 'test-stdio-over-pipes.c', + 'test-tcp-alloc-cb-fail.c', + 'test-tcp-bind-error.c', + 'test-tcp-bind6-error.c', + 'test-tcp-close.c', + 'test-tcp-close-accept.c', + 'test-tcp-close-while-connecting.c', + 'test-tcp-create-socket-early.c', + 'test-tcp-connect-error-after-write.c', + 'test-tcp-shutdown-after-write.c', + 'test-tcp-flags.c', + 'test-tcp-connect-error.c', + 'test-tcp-connect-timeout.c', + 'test-tcp-connect6-error.c', + 'test-tcp-open.c', + 'test-tcp-write-to-half-open-connection.c', + 'test-tcp-write-after-connect.c', + 'test-tcp-writealot.c', + 'test-tcp-write-fail.c', + 'test-tcp-try-write.c', + 'test-tcp-unexpected-read.c', + 'test-tcp-oob.c', + 'test-tcp-read-stop.c', + 'test-tcp-write-queue-order.c', + 'test-threadpool.c', + 'test-threadpool-cancel.c', + 'test-thread-equal.c', + 'test-tmpdir.c', + 'test-mutexes.c', + 'test-thread.c', + 'test-barrier.c', + 'test-condvar.c', + 'test-timer-again.c', + 'test-timer-from-check.c', + 'test-timer.c', + 'test-tty.c', + 'test-udp-alloc-cb-fail.c', + 'test-udp-bind.c', + 'test-udp-create-socket-early.c', + 'test-udp-dgram-too-big.c', + 'test-udp-ipv6.c', + 'test-udp-open.c', + 'test-udp-options.c', + 'test-udp-send-and-recv.c', + 'test-udp-send-hang-loop.c', + 'test-udp-send-immediate.c', + 'test-udp-send-unreachable.c', + 'test-udp-multicast-join.c', + 'test-udp-multicast-join6.c', + 'test-dlerror.c', + 'test-udp-multicast-ttl.c', + 'test-ip4-addr.c', + 'test-ip6-addr.c', + 'test-udp-multicast-interface.c', + 'test-udp-multicast-interface6.c', + 'test-udp-try-send.c', + ], + 'conditions': [ + [ 'OS=="win"', { + 'sources': [ + 'runner-win.c', + 'runner-win.h', + '../src/win/snprintf.c', + ], + 'libraries': [ '-lws2_32' ] + }, { # POSIX + 'sources': [ + 'runner-unix.c', + 'runner-unix.h', + ], + 'conditions': [ + [ 'OS != "zos"', { + 'defines': [ '_GNU_SOURCE' ], + 'cflags': [ '-Wno-long-long' ], + 'xcode_settings': { + 'WARNING_CFLAGS': [ '-Wno-long-long' ] + } + }], + ]}, + ], + [ 'OS in "mac dragonflybsd freebsd linux netbsd openbsd".split()', { + 'link_settings': { + 'libraries': [ '-lutil' ], + }, + }], + [ 'OS=="solaris"', { # make test-fs.c compile, needs _POSIX_C_SOURCE + 'defines': [ + '__EXTENSIONS__', + '_XOPEN_SOURCE=500', + ], + }], + [ 'OS=="aix"', { # make test-fs.c compile, needs _POSIX_C_SOURCE + 'defines': [ + '_ALL_SOURCE', + '_XOPEN_SOURCE=500', + ], + }], + [ 'OS == "zos"', { + 'cflags': [ '-qxplink' ], + 'ldflags': [ '-qxplink' ], + }], + ['uv_library=="shared_library"', { + 'defines': [ 'USING_UV_SHARED=1' ], + 'conditions': [ + [ 'OS == "zos"', { + 'cflags': [ '-Wc,DLL' ], + }], + ], + }], + ], + 'msvs-settings': { + 'VCLinkerTool': { + 'SubSystem': 1, # /subsystem:console + }, + }, + }, + + { + 'target_name': 'run-benchmarks', + 'type': 'executable', + 'dependencies': [ '../uv.gyp:libuv' ], + 'sources': [ + 'benchmark-async.c', + 'benchmark-async-pummel.c', + 'benchmark-fs-stat.c', + 'benchmark-getaddrinfo.c', + 'benchmark-list.h', + 'benchmark-loop-count.c', + 'benchmark-million-async.c', + 'benchmark-million-timers.c', + 'benchmark-multi-accept.c', + 'benchmark-ping-pongs.c', + 'benchmark-pound.c', + 'benchmark-pump.c', + 'benchmark-sizes.c', + 'benchmark-spawn.c', + 'benchmark-thread.c', + 'benchmark-tcp-write-batch.c', + 'benchmark-udp-pummel.c', + 'dns-server.c', + 'echo-server.c', + 'blackhole-server.c', + 'run-benchmarks.c', + 'runner.c', + 'runner.h', + 'task.h', + ], + 'conditions': [ + [ 'OS=="win"', { + 'sources': [ + 'runner-win.c', + 'runner-win.h', + '../src/win/snprintf.c', + ], + 'libraries': [ '-lws2_32' ] + }, { # POSIX + 'defines': [ '_GNU_SOURCE' ], + 'sources': [ + 'runner-unix.c', + 'runner-unix.h', + ] + }], + [ 'OS == "zos"', { + 'cflags': [ '-qxplink' ], + 'ldflags': [ '-qxplink' ], + }], + ['uv_library=="shared_library"', { + 'defines': [ 'USING_UV_SHARED=1' ], + 'conditions': [ + [ 'OS == "zos"', { + 'cflags': [ '-Wc,DLL' ], + }], + ], + }], + ], + 'msvs-settings': { + 'VCLinkerTool': { + 'SubSystem': 1, # /subsystem:console + }, + }, + }, + ], +} |