Update libuv

This commit is contained in:
KimLS
2017-02-25 14:30:35 -08:00
parent d402b25d69
commit 6033f48b47
115 changed files with 4304 additions and 893 deletions
+134 -41
View File
@@ -29,12 +29,19 @@
# if defined(__APPLE__) || \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
# define HAVE_KQUEUE 1
# endif
#endif
#if defined(__arm__)/* Increase the timeout so the test passes on arm CI bots */
# define CREATE_TIMEOUT 100
#else
# define CREATE_TIMEOUT 1
#endif
static uv_fs_event_t fs_event;
static const char file_prefix[] = "fsevent-";
static const int fs_event_file_count = 16;
@@ -53,6 +60,14 @@ static char fs_event_filename[PATH_MAX];
static char fs_event_filename[1024];
#endif /* defined(PATH_MAX) */
static int timer_cb_touch_called;
static int timer_cb_exact_called;
static void fs_event_fail(uv_fs_event_t* handle,
const char* filename,
int events,
int status) {
ASSERT(0 && "should never be called");
}
static void create_dir(const char* name) {
int r;
@@ -143,7 +158,10 @@ static void fs_event_create_files(uv_timer_t* handle) {
if (++fs_event_created < fs_event_file_count) {
/* Create another file on a different event loop tick. We do it this way
* to avoid fs events coalescing into one fs event. */
ASSERT(0 == uv_timer_start(&timer, fs_event_create_files, 1, 0));
ASSERT(0 == uv_timer_start(&timer,
fs_event_create_files,
CREATE_TIMEOUT,
0));
}
}
@@ -254,6 +272,14 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle,
const char* filename,
int events,
int status) {
#ifdef _WIN32
/* Each file created (or deleted) will cause this callback to be called twice
* under Windows: once with the name of the file, and second time with the
* name of the directory. We will ignore the callback for the directory
* itself. */
if (filename && strcmp(filename, file_prefix_in_subdir) == 0)
return;
#endif
fs_event_cb_called++;
ASSERT(handle == &fs_event);
ASSERT(status == 0);
@@ -345,6 +371,21 @@ static void timer_cb_touch(uv_timer_t* timer) {
timer_cb_touch_called++;
}
static void timer_cb_exact(uv_timer_t* handle) {
int r;
if (timer_cb_exact_called == 0) {
touch_file("watch_dir/file.js");
} else {
uv_close((uv_handle_t*)handle, NULL);
r = uv_fs_event_stop(&fs_event);
ASSERT(r == 0);
uv_close((uv_handle_t*) &fs_event, NULL);
}
++timer_cb_exact_called;
}
static void timer_cb_watch_twice(uv_timer_t* handle) {
uv_fs_event_t* handles = handle->data;
uv_close((uv_handle_t*) (handles + 0), NULL);
@@ -353,6 +394,10 @@ static void timer_cb_watch_twice(uv_timer_t* handle) {
}
TEST_IMPL(fs_event_watch_dir) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop = uv_default_loop();
int r;
@@ -432,6 +477,10 @@ TEST_IMPL(fs_event_watch_dir_recursive) {
TEST_IMPL(fs_event_watch_file) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop = uv_default_loop();
int r;
@@ -467,7 +516,54 @@ TEST_IMPL(fs_event_watch_file) {
return 0;
}
TEST_IMPL(fs_event_watch_file_exact_path) {
/*
This test watches a file named "file.jsx" and modifies a file named
"file.js". The test verifies that no events occur for file.jsx.
*/
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop;
int r;
loop = uv_default_loop();
/* Setup */
remove("watch_dir/file.js");
remove("watch_dir/file.jsx");
remove("watch_dir/");
create_dir("watch_dir");
create_file("watch_dir/file.js");
create_file("watch_dir/file.jsx");
r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0);
r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir/file.jsx", 0);
ASSERT(r == 0);
r = uv_timer_init(loop, &timer);
ASSERT(r == 0);
r = uv_timer_start(&timer, timer_cb_exact, 100, 100);
ASSERT(r == 0);
r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT(timer_cb_exact_called == 2);
/* Cleanup */
remove("watch_dir/file.js");
remove("watch_dir/file.jsx");
remove("watch_dir/");
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(fs_event_watch_file_twice) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
const char path[] = "test/fixtures/empty_file";
uv_fs_event_t watchers[2];
uv_timer_t timer;
@@ -489,6 +585,9 @@ TEST_IMPL(fs_event_watch_file_twice) {
}
TEST_IMPL(fs_event_watch_file_current_dir) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_timer_t timer;
uv_loop_t* loop;
int r;
@@ -559,6 +658,10 @@ TEST_IMPL(fs_event_watch_file_root_dir) {
#endif
TEST_IMPL(fs_event_no_callback_after_close) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop = uv_default_loop();
int r;
@@ -593,6 +696,10 @@ TEST_IMPL(fs_event_no_callback_after_close) {
}
TEST_IMPL(fs_event_no_callback_on_close) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop = uv_default_loop();
int r;
@@ -626,12 +733,6 @@ TEST_IMPL(fs_event_no_callback_on_close) {
}
static void fs_event_fail(uv_fs_event_t* handle, const char* filename,
int events, int status) {
ASSERT(0 && "should never be called");
}
static void timer_cb(uv_timer_t* handle) {
int r;
@@ -646,6 +747,9 @@ static void timer_cb(uv_timer_t* handle) {
TEST_IMPL(fs_event_immediate_close) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_timer_t timer;
uv_loop_t* loop;
int r;
@@ -668,6 +772,9 @@ TEST_IMPL(fs_event_immediate_close) {
TEST_IMPL(fs_event_close_with_pending_event) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop;
int r;
@@ -698,20 +805,6 @@ TEST_IMPL(fs_event_close_with_pending_event) {
return 0;
}
#if defined(HAVE_KQUEUE) || defined(_AIX)
/* kqueue doesn't register fs events if you don't have an active watcher.
* The file descriptor needs to be part of the kqueue set of interest and
* that's not the case until we actually enter the event loop.
* This is also observed on AIX with ahafs.
*/
TEST_IMPL(fs_event_close_in_callback) {
fprintf(stderr, "Skipping test, doesn't work with kqueue and AIX.\n");
return 0;
}
#else /* !HAVE_KQUEUE || !_AIX */
static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,
int events, int status) {
ASSERT(status == 0);
@@ -724,52 +817,49 @@ static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,
}
}
TEST_IMPL(fs_event_close_in_callback) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop;
int r;
loop = uv_default_loop();
fs_event_unlink_files(NULL);
create_dir("watch_dir");
create_file("watch_dir/file1");
create_file("watch_dir/file2");
create_file("watch_dir/file3");
create_file("watch_dir/file4");
create_file("watch_dir/file5");
r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0);
r = uv_fs_event_start(&fs_event, fs_event_cb_close, "watch_dir", 0);
ASSERT(r == 0);
/* Generate a couple of fs events. */
touch_file("watch_dir/file1");
touch_file("watch_dir/file2");
touch_file("watch_dir/file3");
touch_file("watch_dir/file4");
touch_file("watch_dir/file5");
r = uv_timer_init(loop, &timer);
ASSERT(r == 0);
r = uv_timer_start(&timer, fs_event_create_files, 100, 0);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 1);
uv_close((uv_handle_t*)&timer, close_cb);
uv_run(loop, UV_RUN_ONCE);
ASSERT(close_cb_called == 2);
ASSERT(fs_event_cb_called == 3);
/* Clean up */
remove("watch_dir/file1");
remove("watch_dir/file2");
remove("watch_dir/file3");
remove("watch_dir/file4");
remove("watch_dir/file5");
fs_event_unlink_files(NULL);
remove("watch_dir/");
MAKE_VALGRIND_HAPPY();
return 0;
}
#endif /* HAVE_KQUEUE || _AIX */
TEST_IMPL(fs_event_start_and_close) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop;
uv_fs_event_t fs_event1;
uv_fs_event_t fs_event2;
@@ -802,6 +892,9 @@ TEST_IMPL(fs_event_start_and_close) {
}
TEST_IMPL(fs_event_getpath) {
#if defined(__MVS__)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop = uv_default_loop();
int r;
char buf[1024];