libuv 1.42.0.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3650 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-07-27 22:08:18 +00:00
parent 5197eb91f7
commit da51e87774
183 changed files with 4013 additions and 1768 deletions

View File

@ -343,7 +343,7 @@ static void statfs_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_STATFS);
ASSERT(req->result == 0);
ASSERT(req->ptr != NULL);
ASSERT_NOT_NULL(req->ptr);
stats = req->ptr;
#if defined(_WIN32) || defined(__sun) || defined(_AIX) || defined(__MVS__) || \
@ -366,7 +366,7 @@ static void statfs_cb(uv_fs_t* req) {
ASSERT(stats->f_ffree <= stats->f_files);
#endif
uv_fs_req_cleanup(req);
ASSERT(req->ptr == NULL);
ASSERT_NULL(req->ptr);
statfs_cb_count++;
}
@ -630,7 +630,7 @@ static void empty_scandir_cb(uv_fs_t* req) {
ASSERT(req == &scandir_req);
ASSERT(req->fs_type == UV_FS_SCANDIR);
ASSERT(req->result == 0);
ASSERT(req->ptr == NULL);
ASSERT_NULL(req->ptr);
ASSERT(UV_EOF == uv_fs_scandir_next(req, &dent));
uv_fs_req_cleanup(req);
scandir_cb_count++;
@ -642,7 +642,7 @@ static void non_existent_scandir_cb(uv_fs_t* req) {
ASSERT(req == &scandir_req);
ASSERT(req->fs_type == UV_FS_SCANDIR);
ASSERT(req->result == UV_ENOENT);
ASSERT(req->ptr == NULL);
ASSERT_NULL(req->ptr);
ASSERT(UV_ENOENT == uv_fs_scandir_next(req, &dent));
uv_fs_req_cleanup(req);
scandir_cb_count++;
@ -653,7 +653,7 @@ static void file_scandir_cb(uv_fs_t* req) {
ASSERT(req == &scandir_req);
ASSERT(req->fs_type == UV_FS_SCANDIR);
ASSERT(req->result == UV_ENOTDIR);
ASSERT(req->ptr == NULL);
ASSERT_NULL(req->ptr);
uv_fs_req_cleanup(req);
scandir_cb_count++;
}
@ -673,7 +673,7 @@ static void stat_cb(uv_fs_t* req) {
static void sendfile_cb(uv_fs_t* req) {
ASSERT(req == &sendfile_req);
ASSERT(req->fs_type == UV_FS_SENDFILE);
ASSERT(req->result == 65546);
ASSERT(req->result == 65545);
sendfile_cb_count++;
uv_fs_req_cleanup(req);
}
@ -816,13 +816,44 @@ static void check_utime(const char* path,
else
r = uv_fs_stat(loop, &req, path, NULL);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(req.result == 0);
ASSERT_EQ(req.result, 0);
s = &req.statbuf;
ASSERT(s->st_atim.tv_sec + (s->st_atim.tv_nsec / 1000000000.0) == atime);
ASSERT(s->st_mtim.tv_sec + (s->st_mtim.tv_nsec / 1000000000.0) == mtime);
if (s->st_atim.tv_nsec == 0 && s->st_mtim.tv_nsec == 0) {
/*
* Test sub-second timestamps only when supported (such as Windows with
* NTFS). Some other platforms support sub-second timestamps, but that
* support is filesystem-dependent. Notably OS X (HFS Plus) does NOT
* support sub-second timestamps. But kernels may round or truncate in
* either direction, so we may accept either possible answer.
*/
#ifdef _WIN32
ASSERT_DOUBLE_EQ(atime, (long) atime);
ASSERT_DOUBLE_EQ(mtime, (long) atime);
#endif
if (atime > 0 || (long) atime == atime)
ASSERT_EQ(s->st_atim.tv_sec, (long) atime);
if (mtime > 0 || (long) mtime == mtime)
ASSERT_EQ(s->st_mtim.tv_sec, (long) mtime);
ASSERT_GE(s->st_atim.tv_sec, (long) atime - 1);
ASSERT_GE(s->st_mtim.tv_sec, (long) mtime - 1);
ASSERT_LE(s->st_atim.tv_sec, (long) atime);
ASSERT_LE(s->st_mtim.tv_sec, (long) mtime);
} else {
double st_atim;
double st_mtim;
#ifndef __APPLE__
/* TODO(vtjnash): would it be better to normalize this? */
ASSERT_DOUBLE_GE(s->st_atim.tv_nsec, 0);
ASSERT_DOUBLE_GE(s->st_mtim.tv_nsec, 0);
#endif
st_atim = s->st_atim.tv_sec + s->st_atim.tv_nsec / 1e9;
st_mtim = s->st_mtim.tv_sec + s->st_mtim.tv_nsec / 1e9;
ASSERT_DOUBLE_EQ(st_atim, atime);
ASSERT_DOUBLE_EQ(st_mtim, mtime);
}
uv_fs_req_cleanup(&req);
}
@ -1159,6 +1190,8 @@ TEST_IMPL(fs_async_dir) {
static int test_sendfile(void (*setup)(int), uv_fs_cb cb, off_t expected_size) {
int f, r;
struct stat s1, s2;
uv_fs_t req;
char buf1[1];
loop = uv_default_loop();
@ -1188,7 +1221,7 @@ static int test_sendfile(void (*setup)(int), uv_fs_cb cb, off_t expected_size) {
uv_fs_req_cleanup(&open_req2);
r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result,
0, 131072, cb);
1, 131072, cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
@ -1203,9 +1236,26 @@ static int test_sendfile(void (*setup)(int), uv_fs_cb cb, off_t expected_size) {
ASSERT(0 == stat("test_file", &s1));
ASSERT(0 == stat("test_file2", &s2));
ASSERT(s1.st_size == s2.st_size);
ASSERT(s2.st_size == expected_size);
if (expected_size > 0) {
ASSERT_UINT64_EQ(s1.st_size, s2.st_size + 1);
r = uv_fs_open(NULL, &open_req1, "test_file2", O_RDWR, 0, NULL);
ASSERT(r >= 0);
ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
memset(buf1, 0, sizeof(buf1));
iov = uv_buf_init(buf1, sizeof(buf1));
r = uv_fs_read(NULL, &req, open_req1.result, &iov, 1, -1, NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
ASSERT_EQ(buf1[0], 'e'); /* 'e' from begin */
uv_fs_req_cleanup(&req);
} else {
ASSERT_UINT64_EQ(s1.st_size, s2.st_size);
}
/* Cleanup. */
unlink("test_file");
unlink("test_file2");
@ -1223,7 +1273,7 @@ static void sendfile_setup(int f) {
TEST_IMPL(fs_async_sendfile) {
return test_sendfile(sendfile_setup, sendfile_cb, 65546);
return test_sendfile(sendfile_setup, sendfile_cb, 65545);
}
@ -1403,7 +1453,8 @@ TEST_IMPL(fs_fstat) {
ASSERT(s->st_mtim.tv_nsec == t.st_mtimespec.tv_nsec);
ASSERT(s->st_ctim.tv_sec == t.st_ctimespec.tv_sec);
ASSERT(s->st_ctim.tv_nsec == t.st_ctimespec.tv_nsec);
#elif defined(_AIX)
#elif defined(_AIX) || \
defined(__MVS__)
ASSERT(s->st_atim.tv_sec == t.st_atime);
ASSERT(s->st_atim.tv_nsec == 0);
ASSERT(s->st_mtim.tv_sec == t.st_mtime);
@ -1961,12 +2012,12 @@ TEST_IMPL(fs_readlink) {
ASSERT(0 == uv_fs_readlink(loop, &req, "no_such_file", dummy_cb));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
ASSERT(dummy_cb_count == 1);
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
ASSERT(req.result == UV_ENOENT);
uv_fs_req_cleanup(&req);
ASSERT(UV_ENOENT == uv_fs_readlink(NULL, &req, "no_such_file", NULL));
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
ASSERT(req.result == UV_ENOENT);
uv_fs_req_cleanup(&req);
@ -1982,7 +2033,7 @@ TEST_IMPL(fs_realpath) {
ASSERT(0 == uv_fs_realpath(loop, &req, "no_such_file", dummy_cb));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
ASSERT(dummy_cb_count == 1);
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
#ifdef _WIN32
/*
* Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
@ -1996,7 +2047,7 @@ TEST_IMPL(fs_realpath) {
uv_fs_req_cleanup(&req);
ASSERT(UV_ENOENT == uv_fs_realpath(NULL, &req, "no_such_file", NULL));
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
ASSERT(req.result == UV_ENOENT);
uv_fs_req_cleanup(&req);
@ -2523,29 +2574,16 @@ TEST_IMPL(fs_utime) {
uv_fs_req_cleanup(&req);
uv_fs_close(loop, &req, r, NULL);
atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
/*
* Test sub-second timestamps only on Windows (assuming NTFS). Some other
* platforms support sub-second timestamps, but that support is filesystem-
* dependent. Notably OS X (HFS Plus) does NOT support sub-second timestamps.
*/
#ifdef _WIN32
mtime += 0.444; /* 1982-09-10 11:22:33.444 */
#endif
atime = mtime = 400497753.25; /* 1982-09-10 11:22:33.25 */
r = uv_fs_utime(NULL, &req, path, atime, mtime, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
r = uv_fs_stat(NULL, &req, path, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
check_utime(path, atime, mtime, /* test_lutime */ 0);
uv_fs_req_cleanup(&req);
atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
atime = mtime = 1291404900.25; /* 2010-12-03 20:35:00.25 - mees <3 */
checkme.path = path;
checkme.atime = atime;
checkme.mtime = mtime;
@ -2565,6 +2603,45 @@ TEST_IMPL(fs_utime) {
}
TEST_IMPL(fs_utime_round) {
const char path[] = "test_file";
double atime;
double mtime;
uv_fs_t req;
int r;
loop = uv_default_loop();
unlink(path);
r = uv_fs_open(NULL, &req, path, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, NULL);
ASSERT_GE(r, 0);
ASSERT_GE(req.result, 0);
uv_fs_req_cleanup(&req);
ASSERT_EQ(0, uv_fs_close(loop, &req, r, NULL));
atime = mtime = -14245440.25; /* 1969-07-20T02:56:00.25Z */
r = uv_fs_utime(NULL, &req, path, atime, mtime, NULL);
#if !defined(__linux__) && \
!defined(_WIN32) && \
!defined(__APPLE__) && \
!defined(__FreeBSD__) && \
!defined(__sun)
if (r != 0) {
ASSERT_EQ(r, UV_EINVAL);
RETURN_SKIP("utime on some OS (z/OS, IBM i PASE, AIX) or filesystems may reject pre-epoch timestamps");
}
#endif
ASSERT_EQ(0, r);
ASSERT_EQ(0, req.result);
uv_fs_req_cleanup(&req);
check_utime(path, atime, mtime, /* test_lutime */ 0);
unlink(path);
MAKE_VALGRIND_HAPPY();
return 0;
}
#ifdef _WIN32
TEST_IMPL(fs_stat_root) {
int r;
@ -2618,16 +2695,7 @@ TEST_IMPL(fs_futime) {
uv_fs_req_cleanup(&req);
uv_fs_close(loop, &req, r, NULL);
atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
/*
* Test sub-second timestamps only on Windows (assuming NTFS). Some other
* platforms support sub-second timestamps, but that support is filesystem-
* dependent. Notably OS X (HFS Plus) does NOT support sub-second timestamps.
*/
#ifdef _WIN32
mtime += 0.444; /* 1982-09-10 11:22:33.444 */
#endif
atime = mtime = 400497753.25; /* 1982-09-10 11:22:33.25 */
r = uv_fs_open(NULL, &req, path, O_RDWR, 0, NULL);
ASSERT(r >= 0);
@ -2645,11 +2713,7 @@ TEST_IMPL(fs_futime) {
#endif
uv_fs_req_cleanup(&req);
r = uv_fs_stat(NULL, &req, path, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
check_utime(path, atime, mtime, /* test_lutime */ 0);
uv_fs_req_cleanup(&req);
atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
@ -2708,11 +2772,7 @@ TEST_IMPL(fs_lutime) {
uv_fs_req_cleanup(&req);
/* Test the synchronous version. */
atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
#ifdef _WIN32
mtime += 0.444; /* 1982-09-10 11:22:33.444 */
#endif
atime = mtime = 400497753.25; /* 1982-09-10 11:22:33.25 */
checkme.atime = atime;
checkme.mtime = mtime;
@ -2784,7 +2844,7 @@ TEST_IMPL(fs_scandir_empty_dir) {
r = uv_fs_scandir(NULL, &req, path, 0, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
ASSERT(UV_EOF == uv_fs_scandir_next(&req, &dent));
uv_fs_req_cleanup(&req);
@ -2821,7 +2881,7 @@ TEST_IMPL(fs_scandir_non_existent_dir) {
r = uv_fs_scandir(NULL, &req, path, 0, NULL);
ASSERT(r == UV_ENOENT);
ASSERT(req.result == UV_ENOENT);
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
ASSERT(UV_ENOENT == uv_fs_scandir_next(&req, &dent));
uv_fs_req_cleanup(&req);
@ -2837,6 +2897,9 @@ TEST_IMPL(fs_scandir_non_existent_dir) {
}
TEST_IMPL(fs_scandir_file) {
#if defined(__ASAN__)
RETURN_SKIP("Test does not currently work in ASAN");
#endif
const char* path;
int r;
@ -2870,7 +2933,7 @@ TEST_IMPL(fs_open_dir) {
r = uv_fs_open(NULL, &req, path, O_RDONLY, 0, NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
ASSERT(req.ptr == NULL);
ASSERT_NULL(req.ptr);
file = r;
uv_fs_req_cleanup(&req);
@ -3083,6 +3146,9 @@ static void fs_read_bufs(int add_flags) {
uv_fs_req_cleanup(&close_req);
}
TEST_IMPL(fs_read_bufs) {
#if defined(__ASAN__)
RETURN_SKIP("Test does not currently work in ASAN");
#endif
fs_read_bufs(0);
fs_read_bufs(UV_FS_O_FILEMAP);
@ -3267,7 +3333,7 @@ static void fs_write_alotof_bufs(int add_flags) {
loop = uv_default_loop();
iovs = malloc(sizeof(*iovs) * iovcount);
ASSERT(iovs != NULL);
ASSERT_NOT_NULL(iovs);
iovmax = uv_test_getiovmax();
r = uv_fs_open(NULL,
@ -3296,7 +3362,7 @@ static void fs_write_alotof_bufs(int add_flags) {
/* Read the strings back to separate buffers. */
buffer = malloc(sizeof(test_buf) * iovcount);
ASSERT(buffer != NULL);
ASSERT_NOT_NULL(buffer);
for (index = 0; index < iovcount; ++index)
iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf),
@ -3379,7 +3445,7 @@ static void fs_write_alotof_bufs_with_offset(int add_flags) {
loop = uv_default_loop();
iovs = malloc(sizeof(*iovs) * iovcount);
ASSERT(iovs != NULL);
ASSERT_NOT_NULL(iovs);
iovmax = uv_test_getiovmax();
r = uv_fs_open(NULL,
@ -3415,7 +3481,7 @@ static void fs_write_alotof_bufs_with_offset(int add_flags) {
/* Read the strings back to separate buffers. */
buffer = malloc(sizeof(test_buf) * iovcount);
ASSERT(buffer != NULL);
ASSERT_NOT_NULL(buffer);
for (index = 0; index < iovcount; ++index)
iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf),
@ -3611,16 +3677,16 @@ static void test_fs_partial(int doread) {
iovcount = 54321;
iovs = malloc(sizeof(*iovs) * iovcount);
ASSERT(iovs != NULL);
ASSERT_NOT_NULL(iovs);
ctx.pid = pthread_self();
ctx.doread = doread;
ctx.interval = 1000;
ctx.size = sizeof(test_buf) * iovcount;
ctx.data = malloc(ctx.size);
ASSERT(ctx.data != NULL);
ASSERT_NOT_NULL(ctx.data);
buffer = malloc(ctx.size);
ASSERT(buffer != NULL);
ASSERT_NOT_NULL(buffer);
for (index = 0; index < iovcount; ++index)
iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf), sizeof(test_buf));
@ -3708,15 +3774,15 @@ TEST_IMPL(fs_read_write_null_arguments) {
/* 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);
ASSERT_NULL(write_req.path);
ASSERT_NULL(write_req.ptr);
#ifdef _WIN32
ASSERT(write_req.file.pathw == NULL);
ASSERT(write_req.fs.info.new_pathw == NULL);
ASSERT(write_req.fs.info.bufs == NULL);
ASSERT_NULL(write_req.file.pathw);
ASSERT_NULL(write_req.fs.info.new_pathw);
ASSERT_NULL(write_req.fs.info.bufs);
#else
ASSERT(write_req.new_path == NULL);
ASSERT(write_req.bufs == NULL);
ASSERT_NULL(write_req.new_path);
ASSERT_NULL(write_req.bufs);
#endif
uv_fs_req_cleanup(&write_req);
@ -4372,6 +4438,7 @@ TEST_IMPL(fs_invalid_mkdir_name) {
loop = uv_default_loop();
r = uv_fs_mkdir(loop, &req, "invalid>", 0, NULL);
ASSERT(r == UV_EINVAL);
ASSERT_EQ(UV_EINVAL, uv_fs_mkdir(loop, &req, "test:lol", 0, NULL));
return 0;
}