tests: fix fs tests run w/o full getdents support

fs_access, fs_async_dir and fs_symlink_dir could fail when the
filesystem where the tests are run does not fully support getting the
file type via getdents.  Having getdents support does not imply that the
underlying filesystem fully supports what is necessary for these tests
to have passed prior to this commit.  So the failing tests were updated
to check for UV_DIRENT_FILE as it did previously but it will also check for
UV_DIRENT_UNKNOWN as well to handle the filesystems that do not fully support
getting the file type via getdents.  For OS X and Windows, which are
known to fully support getting the file type, the tests work as they did
before and will not check for UV_DIRENT_UNKNOWN.  We could/should update the
preprocessor directive that chooses "rigorous" or "lax" checks
accordingly when we learn of new environments that should always do the
original "rigorous" checks.

Fixes: https://github.com/libuv/libuv/issues/501
PR-URL: https://github.com/libuv/libuv/pull/508
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Jeremy Whitlock 2015-09-03 09:58:48 -06:00 committed by Saúl Ibarra Corretgé
parent 866dc3f98b
commit 30fc362560

View File

@ -427,6 +427,28 @@ static void rmdir_cb(uv_fs_t* req) {
}
static void assert_is_file_type(uv_dirent_t dent) {
#ifdef HAVE_DIRENT_TYPES
/*
* For Apple and Windows, we know getdents is expected to work but for other
* environments, the filesystem dictates whether or not getdents supports
* returning the file type.
*
* See:
* http://man7.org/linux/man-pages/man2/getdents.2.html
* https://github.com/libuv/libuv/issues/501
*/
#if defined(__APPLE__) || defined(_WIN32)
ASSERT(dent.type == UV_DIRENT_FILE);
#else
ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN);
#endif
#else
ASSERT(dent.type == UV_DIRENT_UNKNOWN);
#endif
}
static void scandir_cb(uv_fs_t* req) {
uv_dirent_t dent;
ASSERT(req == &scandir_req);
@ -436,11 +458,7 @@ static void scandir_cb(uv_fs_t* req) {
while (UV_EOF != uv_fs_scandir_next(req, &dent)) {
ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
#ifdef HAVE_DIRENT_TYPES
ASSERT(dent.type == UV_DIRENT_FILE);
#else
ASSERT(dent.type == UV_DIRENT_UNKNOWN);
#endif
assert_is_file_type(dent);
}
scandir_cb_count++;
ASSERT(req->path);
@ -878,11 +896,7 @@ TEST_IMPL(fs_async_dir) {
ASSERT(scandir_req.ptr);
while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
#ifdef HAVE_DIRENT_TYPES
ASSERT(dent.type == UV_DIRENT_FILE);
#else
ASSERT(dent.type == UV_DIRENT_UNKNOWN);
#endif
assert_is_file_type(dent);
}
uv_fs_req_cleanup(&scandir_req);
ASSERT(!scandir_req.ptr);
@ -1724,6 +1738,7 @@ TEST_IMPL(fs_symlink_dir) {
r = uv_fs_symlink(NULL, &req, test_dir, "test_dir_symlink",
UV_FS_SYMLINK_JUNCTION, NULL);
fprintf(stderr, "r == %i\n", r);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
@ -1774,11 +1789,7 @@ TEST_IMPL(fs_symlink_dir) {
ASSERT(scandir_req.ptr);
while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
#ifdef HAVE_DIRENT_TYPES
ASSERT(dent.type == UV_DIRENT_FILE);
#else
ASSERT(dent.type == UV_DIRENT_UNKNOWN);
#endif
assert_is_file_type(dent);
}
uv_fs_req_cleanup(&scandir_req);
ASSERT(!scandir_req.ptr);
@ -1798,11 +1809,7 @@ TEST_IMPL(fs_symlink_dir) {
ASSERT(scandir_req.ptr);
while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
#ifdef HAVE_DIRENT_TYPES
ASSERT(dent.type == UV_DIRENT_FILE);
#else
ASSERT(dent.type == UV_DIRENT_UNKNOWN);
#endif
assert_is_file_type(dent);
}
uv_fs_req_cleanup(&scandir_req);
ASSERT(!scandir_req.ptr);