Browse Source

uv: upgrade to d808cf9

v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
666aa0a343
  1. 2
      deps/uv/.gitignore
  2. 9
      deps/uv/.travis.yml
  3. 1
      deps/uv/AUTHORS
  4. 2
      deps/uv/README.md
  5. 10
      deps/uv/src/unix/core.c
  6. 1
      deps/uv/src/unix/cygwin.c
  7. 4
      deps/uv/src/unix/fs.c
  8. 75
      deps/uv/src/unix/internal.h
  9. 3
      deps/uv/src/unix/kqueue.c
  10. 114
      deps/uv/src/unix/linux.c
  11. 1
      deps/uv/src/unix/pipe.c
  12. 4
      deps/uv/src/unix/process.c
  13. 6
      deps/uv/src/unix/stream.c
  14. 3
      deps/uv/src/unix/sunos.c
  15. 3
      deps/uv/src/unix/udp.c
  16. 2
      deps/uv/src/win/pipe.c
  17. 3
      deps/uv/src/win/tcp.c
  18. 2
      deps/uv/src/win/tty.c
  19. 2
      deps/uv/test/runner.c
  20. 216
      deps/uv/test/test-counters-init.c
  21. 2
      deps/uv/test/test-list.h
  22. 1
      deps/uv/uv.gyp

2
deps/uv/.gitignore

@ -7,6 +7,8 @@
*.orig *.orig
*.sdf *.sdf
*.suo *.suo
core
vgcore.*
/out/ /out/
/build/gyp /build/gyp

9
deps/uv/.travis.yml

@ -0,0 +1,9 @@
language: node_js
script:
- "make test"
notifications:
email: false
irc:
- "irc.freenode.net#libuv"

1
deps/uv/AUTHORS

@ -36,3 +36,4 @@ Tj Holowaychuk <tj@vision-media.ca>
Shimon Doodkin <helpmepro1@gmail.com> Shimon Doodkin <helpmepro1@gmail.com>
Ryan Emery <seebees@gmail.com> Ryan Emery <seebees@gmail.com>
Bruce Mitchener <bruce.mitchener@gmail.com> Bruce Mitchener <bruce.mitchener@gmail.com>
Maciej Małecki <maciej.malecki@notimplemented.org>

2
deps/uv/README.md

@ -1,4 +1,4 @@
# libuv # libuv [![Build Status](https://secure.travis-ci.org/joyent/libuv.png)](http://travis-ci.org/joyent/libuv)
libuv is a new platform layer for Node. Its purpose is to abstract IOCP on libuv is a new platform layer for Node. Its purpose is to abstract IOCP on
Windows and libev on Unix systems. We intend to eventually contain all Windows and libev on Unix systems. We intend to eventually contain all

10
deps/uv/src/unix/core.c

@ -317,8 +317,8 @@ int64_t uv_now(uv_loop_t* loop) {
} }
void uv__req_init(uv_req_t* req) { void uv__req_init(uv_loop_t* loop, uv_req_t* req) {
/* loop->counters.req_init++; */ loop->counters.req_init++;
req->type = UV_UNKNOWN_REQ; req->type = UV_UNKNOWN_REQ;
} }
@ -658,7 +658,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
return -1; return -1;
} }
uv__req_init((uv_req_t*)handle); uv__req_init(loop, (uv_req_t*)handle);
handle->type = UV_GETADDRINFO; handle->type = UV_GETADDRINFO;
handle->loop = loop; handle->loop = loop;
handle->cb = cb; handle->cb = cb;
@ -735,8 +735,8 @@ int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
assert(sockfd >= 0); assert(sockfd >= 0);
while (1) { while (1) {
#if HAVE_ACCEPT4 #if HAVE_SYS_ACCEPT4
peerfd = accept4(sockfd, saddr, &slen, SOCK_NONBLOCK | SOCK_CLOEXEC); peerfd = sys_accept4(sockfd, saddr, &slen, SOCK_NONBLOCK | SOCK_CLOEXEC);
if (peerfd != -1) if (peerfd != -1)
break; break;

1
deps/uv/src/unix/cygwin.c

@ -72,6 +72,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename, const char* filename,
uv_fs_event_cb cb, uv_fs_event_cb cb,
int flags) { int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS); uv__set_sys_error(loop, ENOSYS);
return -1; return -1;
} }

4
deps/uv/src/unix/fs.c

@ -66,7 +66,7 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
/* Make sure the thread pool is initialized. */ /* Make sure the thread pool is initialized. */
uv_eio_init(loop); uv_eio_init(loop);
uv__req_init((uv_req_t*) req); uv__req_init(loop, (uv_req_t*)req);
req->type = UV_FS; req->type = UV_FS;
req->loop = loop; req->loop = loop;
req->fs_type = fs_type; req->fs_type = fs_type;
@ -685,7 +685,7 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
uv_eio_init(loop); uv_eio_init(loop);
uv__req_init((uv_req_t*) req); uv__req_init(loop, (uv_req_t*)req);
uv_ref(loop); uv_ref(loop);
req->loop = loop; req->loop = loop;
req->data = data; req->data = data;

75
deps/uv/src/unix/internal.h

@ -32,30 +32,69 @@
#endif #endif
#undef HAVE_FUTIMES #undef HAVE_FUTIMES
#undef HAVE_PIPE2
#undef HAVE_ACCEPT4
#undef HAVE_KQUEUE #undef HAVE_KQUEUE
#undef HAVE_PORTS_FS #undef HAVE_PORTS_FS
#if defined(__linux__) #if defined(__linux__)
#include <linux/version.h> # undef HAVE_SYS_UTIMESAT
#include <features.h> # undef HAVE_SYS_PIPE2
# undef HAVE_SYS_ACCEPT4
/* futimes() requires linux >= 2.6.22 and glib >= 2.6 */ # undef _GNU_SOURCE
#if LINUX_VERSION_CODE >= 0x20616 && __GLIBC_PREREQ(2, 6) # define _GNU_SOURCE
#define HAVE_FUTIMES 1
#endif
/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */ # include <linux/version.h>
#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9) # include <sys/syscall.h>
#define HAVE_PIPE2 1 # include <features.h>
#endif # include <unistd.h>
/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */ # if __NR_utimensat
#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10) # define HAVE_SYS_UTIMESAT 1
#define HAVE_ACCEPT4 1 # endif
#endif # if __NR_pipe2
# define HAVE_SYS_PIPE2 1
# endif
# if __NR_accept4
# define HAVE_SYS_ACCEPT4 1
# endif
# if HAVE_SYS_UTIMESAT
inline static int sys_utimesat(int dirfd,
const char* path,
const struct timespec times[2],
int flags)
{
return syscall(__NR_utimensat, dirfd, path, times, flags);
}
inline static int sys_futimes(int fd, const struct timeval times[2])
{
struct timespec ts[2];
ts[0].tv_sec = times[0].tv_sec, ts[0].tv_nsec = times[0].tv_usec * 1000;
ts[1].tv_sec = times[1].tv_sec, ts[1].tv_nsec = times[1].tv_usec * 1000;
return sys_utimesat(fd, NULL, ts, 0);
}
# undef HAVE_FUTIMES
# define HAVE_FUTIMES 1
# define futimes(fd, times) sys_futimes(fd, times)
# endif /* HAVE_SYS_FUTIMESAT */
# if HAVE_SYS_PIPE2
inline static int sys_pipe2(int pipefd[2], int flags)
{
return syscall(__NR_pipe2, pipefd, flags);
}
# endif /* HAVE_SYS_PIPE2 */
# if HAVE_SYS_ACCEPT4
inline static int sys_accept4(int fd,
struct sockaddr* addr,
socklen_t* addrlen,
int flags)
{
return syscall(__NR_accept4, fd, addr, addrlen, flags);
}
# endif /* HAVE_SYS_ACCEPT4 */
#endif /* __linux__ */ #endif /* __linux__ */
@ -106,7 +145,6 @@ enum {
size_t uv__strlcpy(char* dst, const char* src, size_t size); size_t uv__strlcpy(char* dst, const char* src, size_t size);
int uv__close(int fd); int uv__close(int fd);
void uv__req_init(uv_req_t*);
void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type); void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type);
@ -118,6 +156,9 @@ int uv__socket(int domain, int type, int protocol);
uv_err_code uv_translate_sys_error(int sys_errno); uv_err_code uv_translate_sys_error(int sys_errno);
void uv_fatal_error(const int errorno, const char* syscall); void uv_fatal_error(const int errorno, const char* syscall);
/* requests */
void uv__req_init(uv_loop_t* loop, uv_req_t*);
/* stream */ /* stream */
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
uv_handle_type type); uv_handle_type type);

3
deps/uv/src/unix/kqueue.c

@ -90,6 +90,8 @@ int uv_fs_event_init(uv_loop_t* loop,
int flags) { int flags) {
int fd; int fd;
loop->counters.fs_event_init++;
/* We don't support any flags yet. */ /* We don't support any flags yet. */
assert(!flags); assert(!flags);
@ -129,6 +131,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename, const char* filename,
uv_fs_event_cb cb, uv_fs_event_cb cb,
int flags) { int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS); uv__set_sys_error(loop, ENOSYS);
return -1; return -1;
} }

114
deps/uv/src/unix/linux.c

@ -27,14 +27,98 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/inotify.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <time.h> #include <time.h>
#undef NANOSEC #undef NANOSEC
#define NANOSEC 1000000000 #define NANOSEC 1000000000
#undef HAVE_INOTIFY_INIT
#undef HAVE_INOTIFY_INIT1
#undef HAVE_INOTIFY_ADD_WATCH
#undef HAVE_INOTIFY_RM_WATCH
#if __NR_inotify_init
# define HAVE_INOTIFY_INIT 1
#endif
#if __NR_inotify_init1
# define HAVE_INOTIFY_INIT1 1
#endif
#if __NR_inotify_add_watch
# define HAVE_INOTIFY_ADD_WATCH 1
#endif
#if __NR_inotify_rm_watch
# define HAVE_INOTIFY_RM_WATCH 1
#endif
#if HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1
# undef IN_ACCESS
# undef IN_MODIFY
# undef IN_ATTRIB
# undef IN_CLOSE_WRITE
# undef IN_CLOSE_NOWRITE
# undef IN_OPEN
# undef IN_MOVED_FROM
# undef IN_MOVED_TO
# undef IN_CREATE
# undef IN_DELETE
# undef IN_DELETE_SELF
# undef IN_MOVE_SELF
# define IN_ACCESS 0x001
# define IN_MODIFY 0x002
# define IN_ATTRIB 0x004
# define IN_CLOSE_WRITE 0x008
# define IN_CLOSE_NOWRITE 0x010
# define IN_OPEN 0x020
# define IN_MOVED_FROM 0x040
# define IN_MOVED_TO 0x080
# define IN_CREATE 0x100
# define IN_DELETE 0x200
# define IN_DELETE_SELF 0x400
# define IN_MOVE_SELF 0x800
struct inotify_event {
int32_t wd;
uint32_t mask;
uint32_t cookie;
uint32_t len;
/* char name[0]; */
};
#endif /* HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1 */
#undef IN_CLOEXEC
#undef IN_NONBLOCK
#if HAVE_INOTIFY_INIT1
# define IN_CLOEXEC O_CLOEXEC
# define IN_NONBLOCK O_NONBLOCK
#endif /* HAVE_INOTIFY_INIT1 */
#if HAVE_INOTIFY_INIT
inline static int inotify_init(void) {
return syscall(__NR_inotify_init);
}
#endif /* HAVE_INOTIFY_INIT */
#if HAVE_INOTIFY_INIT1
inline static int inotify_init1(int flags) {
return syscall(__NR_inotify_init1, flags);
}
#endif /* HAVE_INOTIFY_INIT1 */
#if HAVE_INOTIFY_ADD_WATCH
inline static int inotify_add_watch(int fd, const char* path, uint32_t mask) {
return syscall(__NR_inotify_add_watch, fd, path, mask);
}
#endif /* HAVE_INOTIFY_ADD_WATCH */
#if HAVE_INOTIFY_RM_WATCH
inline static int inotify_rm_watch(int fd, uint32_t wd) {
return syscall(__NR_inotify_rm_watch, fd, wd);
}
#endif /* HAVE_INOTIFY_RM_WATCH */
/* Don't look aghast, this is exactly how glibc's basename() works. */ /* Don't look aghast, this is exactly how glibc's basename() works. */
static char* basename_r(const char* path) { static char* basename_r(const char* path) {
@ -83,8 +167,10 @@ uint64_t uv_get_total_memory(void) {
return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
} }
#if HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1
static int new_inotify_fd(void) { static int new_inotify_fd(void) {
#if defined(IN_NONBLOCK) && defined(IN_CLOEXEC) #if HAVE_INOTIFY_INIT1
return inotify_init1(IN_NONBLOCK | IN_CLOEXEC); return inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
#else #else
int fd; int fd;
@ -141,7 +227,7 @@ static void uv__inotify_read(EV_P_ ev_io* w, int revents) {
* for modifications. Repurpose the filename for API compatibility. * for modifications. Repurpose the filename for API compatibility.
* I'm not convinced this is a good thing, maybe it should go. * I'm not convinced this is a good thing, maybe it should go.
*/ */
filename = e->len ? e->name : basename_r(handle->filename); filename = e->len ? (const char*) (e + 1) : basename_r(handle->filename);
handle->cb(handle, filename, events, 0); handle->cb(handle, filename, events, 0);
@ -161,6 +247,8 @@ int uv_fs_event_init(uv_loop_t* loop,
int events; int events;
int fd; int fd;
loop->counters.fs_event_init++;
/* We don't support any flags yet. */ /* We don't support any flags yet. */
assert(!flags); assert(!flags);
@ -207,3 +295,23 @@ void uv__fs_event_destroy(uv_fs_event_t* handle) {
free(handle->filename); free(handle->filename);
handle->filename = NULL; handle->filename = NULL;
} }
#else /* !HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1 */
int uv_fs_event_init(uv_loop_t* loop,
uv_fs_event_t* handle,
const char* filename,
uv_fs_event_cb cb,
int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS);
return -1;
}
void uv__fs_event_destroy(uv_fs_event_t* handle) {
assert(0 && "unreachable");
abort();
}
#endif /* HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1 */

1
deps/uv/src/unix/pipe.c

@ -274,5 +274,4 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) {
void uv_pipe_pending_instances(uv_pipe_t* handle, int count) { void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
return 0;
} }

4
deps/uv/src/unix/process.c

@ -104,7 +104,7 @@ static int uv__make_socketpair(int fds[2], int flags) {
static int uv__make_pipe(int fds[2], int flags) { static int uv__make_pipe(int fds[2], int flags) {
#if HAVE_PIPE2 #if HAVE_SYS_PIPE2
int fl; int fl;
fl = O_CLOEXEC; fl = O_CLOEXEC;
@ -112,7 +112,7 @@ static int uv__make_pipe(int fds[2], int flags) {
if (flags & UV__F_NONBLOCK) if (flags & UV__F_NONBLOCK)
fl |= O_NONBLOCK; fl |= O_NONBLOCK;
if (pipe2(fds, fl) == 0) if (sys_pipe2(fds, fl) == 0)
return 0; return 0;
if (errno != ENOSYS) if (errno != ENOSYS)

6
deps/uv/src/unix/stream.c

@ -662,7 +662,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
} }
/* Initialize request */ /* Initialize request */
uv__req_init((uv_req_t*)req); uv__req_init(stream->loop, (uv_req_t*)req);
req->handle = stream; req->handle = stream;
req->cb = cb; req->cb = cb;
@ -772,7 +772,7 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
} }
} }
uv__req_init((uv_req_t*)req); uv__req_init(stream->loop, (uv_req_t*)req);
req->cb = cb; req->cb = cb;
req->handle = stream; req->handle = stream;
req->type = UV_CONNECT; req->type = UV_CONNECT;
@ -847,7 +847,7 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
empty_queue = (stream->write_queue_size == 0); empty_queue = (stream->write_queue_size == 0);
/* Initialize the req */ /* Initialize the req */
uv__req_init((uv_req_t*) req); uv__req_init(stream->loop, (uv_req_t*)req);
req->cb = cb; req->cb = cb;
req->handle = stream; req->handle = stream;
req->error = 0; req->error = 0;

3
deps/uv/src/unix/sunos.c

@ -145,6 +145,8 @@ int uv_fs_event_init(uv_loop_t* loop,
int flags) { int flags) {
int portfd; int portfd;
loop->counters.fs_event_init++;
/* We don't support any flags yet. */ /* We don't support any flags yet. */
assert(!flags); assert(!flags);
@ -185,6 +187,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename, const char* filename,
uv_fs_event_cb cb, uv_fs_event_cb cb,
int flags) { int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS); uv__set_sys_error(loop, ENOSYS);
return -1; return -1;
} }

3
deps/uv/src/unix/udp.c

@ -401,8 +401,7 @@ static int uv__udp_send(uv_udp_send_t* req,
if (uv__udp_maybe_deferred_bind(handle, addr->sa_family)) if (uv__udp_maybe_deferred_bind(handle, addr->sa_family))
return -1; return -1;
/* Don't use uv__req_init(), it zeroes the data field. */ uv__req_init(handle->loop, (uv_req_t*)req);
handle->loop->counters.req_init++;
memcpy(&req->addr, addr, addrlen); memcpy(&req->addr, addr, addrlen);
req->addrlen = addrlen; req->addrlen = addrlen;

2
deps/uv/src/win/pipe.c

@ -1047,7 +1047,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
ipc_header_req = (uv_write_t*)&handle->ipc_header_write_req; ipc_header_req = (uv_write_t*)&handle->ipc_header_write_req;
} else { } else {
ipc_header_req = (uv_write_t*)malloc(sizeof(uv_write_t)); ipc_header_req = (uv_write_t*)malloc(sizeof(uv_write_t));
if (!handle->accept_reqs) { if (!ipc_header_req) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
} }

3
deps/uv/src/win/tcp.c

@ -822,7 +822,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
if (!REQ_SUCCESS(req)) { if (!REQ_SUCCESS(req)) {
/* An error occurred doing the read. */ /* An error occurred doing the read. */
if ((handle->flags & UV_HANDLE_READING)) { if ((handle->flags & UV_HANDLE_READING) ||
!(handle->flags & UV_HANDLE_ZERO_READ)) {
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
buf = (handle->flags & UV_HANDLE_ZERO_READ) ? buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
uv_buf_init(NULL, 0) : handle->read_buffer; uv_buf_init(NULL, 0) : handle->read_buffer;

2
deps/uv/src/win/tty.c

@ -90,6 +90,8 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
HANDLE win_handle; HANDLE win_handle;
CONSOLE_SCREEN_BUFFER_INFO info; CONSOLE_SCREEN_BUFFER_INFO info;
loop->counters.tty_init++;
win_handle = (HANDLE) _get_osfhandle(fd); win_handle = (HANDLE) _get_osfhandle(fd);
if (win_handle == INVALID_HANDLE_VALUE) { if (win_handle == INVALID_HANDLE_VALUE) {
uv__set_sys_error(loop, ERROR_INVALID_HANDLE); uv__set_sys_error(loop, ERROR_INVALID_HANDLE);

2
deps/uv/test/runner.c

@ -71,7 +71,7 @@ int run_tests(int timeout, int benchmark_output) {
log_progress(total, passed, failed, "Done.\n"); log_progress(total, passed, failed, "Done.\n");
} }
return 0; return failed;
} }

216
deps/uv/test/test-counters-init.c

@ -0,0 +1,216 @@
/* 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.
*/
#define UNIX (defined(__unix__) || defined(__POSIX__) || defined(__APPLE__))
#include "task.h"
#include "uv.h"
#include <fcntl.h>
#if UNIX
#include <unistd.h> /* unlink, rmdir, etc. */
#else
# include <direct.h>
# include <io.h>
# define unlink _unlink
# define rmdir _rmdir
# define stat _stati64
# define open _open
# define write _write
# define lseek _lseek
# define close _close
#endif
static char exepath[1024];
static size_t exepath_size = 1024;
static char* args[3];
static uv_fs_t open_req;
static uv_tcp_t tcp;
static uv_udp_t udp;
static uv_pipe_t uvpipe;
static uv_tty_t tty;
static uv_prepare_t prepare;
static uv_check_t check;
static uv_idle_t idle;
static uv_async_t async;
static uv_timer_t timer;
static uv_fs_event_t fs_event;
static uv_process_t process;
static uv_process_options_t options;
static uv_fs_t fs_req;
static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
ASSERT(exit_status == 1);
ASSERT(term_signal == 0);
uv_close((uv_handle_t*)process, NULL);
}
static void init_process_options(char* test, uv_exit_cb exit_cb) {
int r = uv_exepath(exepath, &exepath_size);
ASSERT(r == 0);
exepath[exepath_size] = '\0';
args[0] = exepath;
args[1] = test;
args[2] = NULL;
options.file = exepath;
options.args = args;
options.exit_cb = exit_cb;
}
static void create_dir(uv_loop_t* loop, const char* name) {
int r;
uv_fs_t req;
r = uv_fs_rmdir(loop, &req, name, NULL);
r = uv_fs_mkdir(loop, &req, name, 0755, NULL);
ASSERT(r == 0);
uv_fs_req_cleanup(&req);
}
static void create_cb(uv_fs_t* req) {
ASSERT(req == &open_req);
ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->result != -1);
uv_fs_req_cleanup(req);
unlink("test_file");
}
TEST_IMPL(counters_init) {
int r;
int eio_init_prev;
int req_init_prev;
int handle_init_prev;
int stream_init_prev;
int tcp_init_prev;
int udp_init_prev;
int pipe_init_prev;
int tty_init_prev;
int prepare_init_prev;
int check_init_prev;
int idle_init_prev;
int async_init_prev;
int timer_init_prev;
int process_init_prev;
int fs_event_init_prev;
/* req_init and eio_init test by uv_fs_open() */
unlink("test_file");
req_init_prev = uv_default_loop()->counters.req_init;
eio_init_prev = uv_default_loop()->counters.eio_init;
r = uv_fs_open(uv_default_loop(), &open_req, "test_file", O_WRONLY | O_CREAT,
S_IREAD | S_IWRITE, create_cb);
ASSERT(r == 0);
ASSERT(open_req.result == 0);
ASSERT(uv_default_loop()->counters.req_init == ++req_init_prev);
#ifndef _WIN32
ASSERT(uv_default_loop()->counters.eio_init == ++eio_init_prev);
#endif
/* tcp_init, stream_init and handle_init test by uv_tcp_init() */
tcp_init_prev = uv_default_loop()->counters.tcp_init;
stream_init_prev = uv_default_loop()->counters.stream_init;
handle_init_prev = uv_default_loop()->counters.handle_init;
r = uv_tcp_init(uv_default_loop(), &tcp);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.tcp_init == ++tcp_init_prev);
ASSERT(uv_default_loop()->counters.stream_init == ++stream_init_prev);
ASSERT(uv_default_loop()->counters.handle_init == ++handle_init_prev);
uv_close((uv_handle_t*)&tcp, NULL);
/* udp_init test by uv_udp_init() */
udp_init_prev = uv_default_loop()->counters.udp_init;
r = uv_udp_init(uv_default_loop(), &udp);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.udp_init == ++udp_init_prev);
uv_close((uv_handle_t*)&udp, NULL);
/* pipe_init uv_pipe_init() */
pipe_init_prev = uv_default_loop()->counters.pipe_init;
uv_pipe_init(uv_default_loop(), &uvpipe, 0);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.pipe_init == ++pipe_init_prev);
uv_close((uv_handle_t*)&uvpipe, NULL);
/* tty_init test by uv_tty_init()*/
tty_init_prev = uv_default_loop()->counters.tty_init;
r = uv_tty_init(uv_default_loop(), &tty, 1, 0);
/* uv_tty_init() always returns -1 in run_test in Windows
so that we avoid to check return value.
*/
#ifndef _WIN32
ASSERT(r == 0);
uv_close((uv_handle_t*)&tty, NULL);
#endif
ASSERT(uv_default_loop()->counters.tty_init == ++tty_init_prev);
/* prepare_init test by uv_prepare_init() */
prepare_init_prev = uv_default_loop()->counters.prepare_init;
r = uv_prepare_init(uv_default_loop(), &prepare);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.prepare_init == ++prepare_init_prev);
uv_close((uv_handle_t*)&prepare, NULL);
/* check_init test by uv_check_init() */
check_init_prev = uv_default_loop()->counters.check_init;
r = uv_check_init(uv_default_loop(), &check);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.check_init == ++check_init_prev);
uv_close((uv_handle_t*)&check, NULL);
/* idle_init test by uv_idle_init() */
idle_init_prev = uv_default_loop()->counters.idle_init;
r = uv_idle_init(uv_default_loop(), &idle);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.idle_init == ++idle_init_prev);
uv_close((uv_handle_t*)&idle, NULL);
/* async_init test by uv_async_init() */
async_init_prev = uv_default_loop()->counters.async_init;
r = uv_async_init(uv_default_loop(), &async, NULL);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.async_init == ++async_init_prev);
uv_close((uv_handle_t*)&async, NULL);
/* timer_init test by uv_timer_init() */
timer_init_prev = uv_default_loop()->counters.timer_init;
r = uv_timer_init(uv_default_loop(), &timer);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.timer_init == ++timer_init_prev);
uv_close((uv_handle_t*)&timer, NULL);
/* process_init test by uv_spawn() */
process_init_prev = uv_default_loop()->counters.process_init;
init_process_options("spawn_helper1", exit_cb);
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.process_init == ++process_init_prev);
r = uv_run(uv_default_loop());
ASSERT(r == 0);
/* fs_event_init test by uv_fs_event_init() */
create_dir(uv_default_loop(), "watch_dir");
fs_event_init_prev = uv_default_loop()->counters.fs_event_init;
r = uv_fs_event_init(uv_default_loop(), &fs_event, "watch_dir", NULL, 0);
ASSERT(r == 0);
ASSERT(uv_default_loop()->counters.fs_event_init == ++fs_event_init_prev);
r = uv_fs_rmdir(uv_default_loop(), &fs_req, "watch_dir", NULL);
ASSERT(r == 0);
uv_fs_req_cleanup(&fs_req);
return 0;
}

2
deps/uv/test/test-list.h

@ -116,6 +116,7 @@ TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file) TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (fs_open_dir) TEST_DECLARE (fs_open_dir)
TEST_DECLARE (threadpool_queue_work_simple) TEST_DECLARE (threadpool_queue_work_simple)
TEST_DECLARE (counters_init)
#ifdef _WIN32 #ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows) TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
TEST_DECLARE (argument_escaping) TEST_DECLARE (argument_escaping)
@ -270,6 +271,7 @@ TASK_LIST_START
TEST_ENTRY (fs_readdir_file) TEST_ENTRY (fs_readdir_file)
TEST_ENTRY (fs_open_dir) TEST_ENTRY (fs_open_dir)
TEST_ENTRY (threadpool_queue_work_simple) TEST_ENTRY (threadpool_queue_work_simple)
TEST_ENTRY (counters_init)
#if 0 #if 0
/* These are for testing the test runner. */ /* These are for testing the test runner. */

1
deps/uv/uv.gyp

@ -319,6 +319,7 @@
'test/test-udp-ipv6.c', 'test/test-udp-ipv6.c',
'test/test-udp-send-and-recv.c', 'test/test-udp-send-and-recv.c',
'test/test-udp-multicast-join.c', 'test/test-udp-multicast-join.c',
'test/test-counters-init.c',
], ],
'conditions': [ 'conditions': [
[ 'OS=="win"', { [ 'OS=="win"', {

Loading…
Cancel
Save