]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/libcephfs: add newops test case
authorXiubo Li <xiubli@redhat.com>
Fri, 29 Jul 2022 04:37:40 +0000 (12:37 +0800)
committerXiubo Li <xiubli@redhat.com>
Mon, 5 Dec 2022 00:52:11 +0000 (08:52 +0800)
Fixes: https://tracker.ceph.com/issues/56529
Signed-off-by: Xiubo Li <xiubli@redhat.com>
(cherry picked from commit 91fcdbb58e572a5e891e986b85d70cd84f3daf7d)

qa/workunits/libcephfs/test.sh
src/test/libcephfs/CMakeLists.txt
src/test/libcephfs/newops.cc [new file with mode: 0644]

index 9d3656be735c2fb2890448897694601668e5d0fd..23fccfc4eb941d96c11abee1e4b192db2777ac42 100755 (executable)
@@ -4,5 +4,6 @@ ceph_test_libcephfs
 ceph_test_libcephfs_access
 ceph_test_libcephfs_reclaim
 ceph_test_libcephfs_lazyio
+ceph_test_libcephfs_newops
 
 exit 0
index f49290bcdfd404787da66da7abee03b2e4952423..dc4c27905a542f07988f184481d8a8430d04c386 100644 (file)
@@ -22,6 +22,20 @@ if(${WITH_CEPHFS})
   install(TARGETS ceph_test_libcephfs
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
+  add_executable(ceph_test_libcephfs_newops
+    main.cc
+    newops.cc
+  )
+  target_link_libraries(ceph_test_libcephfs_newops
+    ceph-common
+    cephfs
+    ${UNITTEST_LIBS}
+    ${EXTRALIBS}
+    ${CMAKE_DL_LIBS}
+    )
+  install(TARGETS ceph_test_libcephfs_newops
+    DESTINATION ${CMAKE_INSTALL_BINDIR})
+
   add_executable(ceph_test_libcephfs_reclaim
     reclaim.cc
   )
diff --git a/src/test/libcephfs/newops.cc b/src/test/libcephfs/newops.cc
new file mode 100644 (file)
index 0000000..9897cb8
--- /dev/null
@@ -0,0 +1,86 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2021 Red Hat Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include "gtest/gtest-spi.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock-more-matchers.h"
+#include "include/compat.h"
+#include "include/cephfs/libcephfs.h"
+#include "mds/mdstypes.h"
+#include "include/stat.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#ifdef __linux__
+#include <limits.h>
+#include <sys/xattr.h>
+#endif
+
+#include <fmt/format.h>
+#include <map>
+#include <vector>
+#include <thread>
+#include <regex>
+#include <string>
+
+using ::testing::AnyOf;
+using ::testing::Gt;
+using ::testing::Eq;
+using namespace std;
+
+/*
+ * Test this with different ceph versions
+ */
+
+TEST(LibCephFS, NewOPs)
+{
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+  ASSERT_EQ(0, ceph_mount(cmount, "/"));
+
+  const char *test_path = "test_newops_dir";
+
+  ASSERT_EQ(0, ceph_mkdirs(cmount, test_path, 0777));
+
+  {
+    char value[1024] = "";
+    int r = ceph_getxattr(cmount, test_path, "ceph.dir.pin.random", (void*)value, sizeof(value));
+    // Clients will return -ENODATA if new getvxattr op not support yet.
+    EXPECT_THAT(r, AnyOf(Gt(0), Eq(-ENODATA)));
+  }
+
+  {
+    double val = (double)1.0/(double)128.0;
+    std::stringstream ss;
+    ss << val;
+    int r = ceph_setxattr(cmount, test_path, "ceph.dir.pin.random", (void*)ss.str().c_str(), strlen(ss.str().c_str()), XATTR_CREATE);
+    // Old cephs will return -EINVAL if not support "ceph.dir.pin.random" yet.
+    EXPECT_THAT(r, AnyOf(Eq(0), Eq(-EINVAL)));
+
+    char value[1024] = "";
+    r = ceph_getxattr(cmount, test_path, "ceph.dir.pin.random", (void*)value, sizeof(value));
+    // Clients will return -ENODATA if new getvxattr op not support yet.
+    EXPECT_THAT(r, AnyOf(Gt(0), Eq(-ENODATA)));
+  }
+
+  ASSERT_EQ(0, ceph_rmdir(cmount, test_path));
+
+  ceph_shutdown(cmount);
+}