From 363939d537d8866673e3d92caec5143e68d6ad5b Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 5 Sep 2022 13:13:46 +0000 Subject: [PATCH] test/libcephfs: address windows issues This commit addresses a few issues that prevent the libcephfs from running on Windows: * added missing definitions to fs_compat.h * the "nobody" user is ignored on Windows, which is why we'll skip the tests that rely on it * sys/mman.h and sys/resource.h are not available on Windows and will be skipped * skip rlimit, not available on Windows * fork is not available on Windows, for now we'll avoid compiling those tests when targetting Windows. For what is worth, those are skipped on other platforms anyway but currently fail at compile time when using mingw. * use "strchr" instead of "index" or "strchrnul" Signed-off-by: Lucian Petrut --- src/client/Client.cc | 4 ++-- src/include/win32/fs_compat.h | 6 ++++++ src/test/libcephfs/acl.cc | 3 +++ src/test/libcephfs/flock.cc | 7 +++++++ src/test/libcephfs/recordlock.cc | 7 +++++++ src/test/libcephfs/test.cc | 23 ++++++++++++++++++++--- src/test/libcephfs/vxattr.cc | 5 ++++- 7 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 4c180ef754d..6a29f534f20 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -33,10 +33,10 @@ #include "common/async/waiter.h" -#if defined(__FreeBSD__) || defined(_WIN32) +#if defined(__FreeBSD__) #define XATTR_CREATE 0x1 #define XATTR_REPLACE 0x2 -#else +#elif !defined(_WIN32) #include #endif diff --git a/src/include/win32/fs_compat.h b/src/include/win32/fs_compat.h index c3405e670f9..2fce1b72e85 100644 --- a/src/include/win32/fs_compat.h +++ b/src/include/win32/fs_compat.h @@ -34,3 +34,9 @@ #define AT_REMOVEDIR 0x200 #define MAXSYMLINKS 65000 + +#define O_DIRECTORY 0200000 +#define O_NOFOLLOW 0400000 + +#define XATTR_CREATE 1 +#define XATTR_REPLACE 2 diff --git a/src/test/libcephfs/acl.cc b/src/test/libcephfs/acl.cc index 2827a9b4b78..2e5989f49ea 100644 --- a/src/test/libcephfs/acl.cc +++ b/src/test/libcephfs/acl.cc @@ -147,7 +147,10 @@ TEST(ACL, SetACL) { ASSERT_EQ(ceph_fchown(cmount, fd, 65534, 65534), 0); ASSERT_EQ(0, ceph_conf_set(cmount, "client_permissions", "1")); + // "nobody" will be ignored on Windows + #ifndef _WIN32 ASSERT_EQ(ceph_open(cmount, test_file, O_RDWR, 0), -EACCES); + #endif ASSERT_EQ(0, ceph_conf_set(cmount, "client_permissions", "0")); size_t acl_buf_size = acl_ea_size(5); diff --git a/src/test/libcephfs/flock.cc b/src/test/libcephfs/flock.cc index a213fbb5cc9..1c400f9dc1e 100644 --- a/src/test/libcephfs/flock.cc +++ b/src/test/libcephfs/flock.cc @@ -30,7 +30,10 @@ #include #include #include + +#ifndef _WIN32 #include +#endif #ifdef __linux__ #include @@ -432,6 +435,7 @@ static void process_ConcurrentLocking(str_ConcurrentLocking& s) { exit(EXIT_SUCCESS); } +#ifndef _WIN32 // Disabled because of fork() issues (http://tracker.ceph.com/issues/16556) TEST(LibCephFS, DISABLED_InterProcessLocking) { PROCESS_SLOW_MS(); @@ -531,7 +535,9 @@ TEST(LibCephFS, DISABLED_InterProcessLocking) { ASSERT_EQ(0, ceph_unlink(cmount, c_file)); CLEANUP_CEPH(); } +#endif +#ifndef _WIN32 // Disabled because of fork() issues (http://tracker.ceph.com/issues/16556) TEST(LibCephFS, DISABLED_ThreesomeInterProcessLocking) { PROCESS_SLOW_MS(); @@ -644,3 +650,4 @@ TEST(LibCephFS, DISABLED_ThreesomeInterProcessLocking) { ASSERT_EQ(0, ceph_unlink(cmount, c_file)); CLEANUP_CEPH(); } +#endif diff --git a/src/test/libcephfs/recordlock.cc b/src/test/libcephfs/recordlock.cc index 9189038f89d..3c0679d7db3 100644 --- a/src/test/libcephfs/recordlock.cc +++ b/src/test/libcephfs/recordlock.cc @@ -32,7 +32,10 @@ #include #include #include + +#ifndef _WIN32 #include +#endif #ifdef __linux__ #include @@ -763,6 +766,7 @@ static void process_ConcurrentRecordLocking(str_ConcurrentRecordLocking& s) { } // Disabled because of fork() issues (http://tracker.ceph.com/issues/16556) +#ifndef _WIN32 TEST(LibCephFS, DISABLED_InterProcessRecordLocking) { PROCESS_SLOW_MS(); // Process synchronization @@ -923,7 +927,9 @@ TEST(LibCephFS, DISABLED_InterProcessRecordLocking) { ASSERT_EQ(0, ceph_ll_unlink(cmount, root, c_file, perms)); CLEANUP_CEPH(); } +#endif +#ifndef _WIN32 // Disabled because of fork() issues (http://tracker.ceph.com/issues/16556) TEST(LibCephFS, DISABLED_ThreesomeInterProcessRecordLocking) { PROCESS_SLOW_MS(); @@ -1095,3 +1101,4 @@ TEST(LibCephFS, DISABLED_ThreesomeInterProcessRecordLocking) { ASSERT_EQ(0, ceph_ll_unlink(cmount, root, c_file, perms)); CLEANUP_CEPH(); } +#endif diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 998c86ec51a..a94ab036e33 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -25,7 +25,10 @@ #include #include #include + +#ifndef _WIN32 #include +#endif #include "common/Clock.h" @@ -595,7 +598,7 @@ TEST(LibCephFS, Xattrs) { sprintf(xattrv, "testxattr%c", i); ASSERT_TRUE(!strncmp(xattrv, gxattrv, alen)); - n = index(p, '\0'); + n = strchr(p, '\0'); n++; len -= (n - p); p = n; @@ -895,8 +898,11 @@ TEST(LibCephFS, Fchown) { ceph_close(cmount, fd); + // "nobody" will be ignored on Windows + #ifndef _WIN32 fd = ceph_open(cmount, test_file, O_RDWR, 0); ASSERT_EQ(fd, -EACCES); + #endif ceph_shutdown(cmount); } @@ -2167,6 +2173,8 @@ TEST(LibCephFS, OperationsOnRoot) ceph_shutdown(cmount); } +// no rlimits on Windows +#ifndef _WIN32 static void shutdown_racer_func() { const int niter = 32; @@ -2212,6 +2220,7 @@ TEST(LibCephFS, ShutdownRace) */ // ASSERT_EQ(setrlimit(RLIMIT_NOFILE, &rold), 0); } +#endif static void get_current_time_utimbuf(struct utimbuf *utb) { @@ -2442,7 +2451,8 @@ TEST(LibCephFS, SnapXattrs) { ASSERT_LT(0, alen); ASSERT_LT(alen, xbuflen); gxattrv[alen] = '\0'; - char *s = strchrnul(gxattrv, '.'); + char *s = strchr(gxattrv, '.'); + ASSERT_NE(0, s); ASSERT_LT(s, gxattrv + alen); ASSERT_EQ('.', *s); *s = '\0'; @@ -2469,7 +2479,8 @@ TEST(LibCephFS, SnapXattrs) { ASSERT_LT(0, alen); ASSERT_LT(alen, xbuflen); gxattrv2[alen] = '\0'; - s = strchrnul(gxattrv2, '.'); + s = strchr(gxattrv2, '.'); + ASSERT_NE(0, s); ASSERT_LT(s, gxattrv2 + alen); ASSERT_EQ('.', *s); *s = '\0'; @@ -3331,8 +3342,11 @@ TEST(LibCephFS, Chownat) { ASSERT_EQ(ceph_conf_set(cmount, "client_permissions", "1"), 0); ceph_close(cmount, fd); + // "nobody" will be ignored on Windows + #ifndef _WIN32 fd = ceph_open(cmount, file_path, O_RDWR, 0); ASSERT_EQ(fd, -EACCES); + #endif ASSERT_EQ(ceph_conf_set(cmount, "client_permissions", "0"), 0); ASSERT_EQ(0, ceph_unlink(cmount, file_path)); @@ -3372,8 +3386,11 @@ TEST(LibCephFS, ChownatATFDCWD) { ASSERT_EQ(ceph_chownat(cmount, CEPHFS_AT_FDCWD, rel_file_path, 65534, 65534, 0), 0); ASSERT_EQ(ceph_conf_set(cmount, "client_permissions", "1"), 0); + // "nobody" will be ignored on Windows + #ifndef _WIN32 fd = ceph_open(cmount, file_path, O_RDWR, 0); ASSERT_EQ(fd, -EACCES); + #endif ASSERT_EQ(ceph_conf_set(cmount, "client_permissions", "0"), 0); ASSERT_EQ(0, ceph_unlink(cmount, file_path)); diff --git a/src/test/libcephfs/vxattr.cc b/src/test/libcephfs/vxattr.cc index 2a5ad70e4a0..9af85a0c40e 100644 --- a/src/test/libcephfs/vxattr.cc +++ b/src/test/libcephfs/vxattr.cc @@ -25,9 +25,12 @@ #include #include #include -#include #include +#ifndef _WIN32 +#include +#endif + #include "common/Clock.h" #include "common/ceph_json.h" -- 2.39.5