]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_test_rados_api_io: add tests for sparse_read
authorKefu Chai <kchai@redhat.com>
Thu, 27 Aug 2015 14:57:16 +0000 (22:57 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 14 Sep 2015 13:22:34 +0000 (21:22 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 4d4920610ebfcb516630ed15678979c9e9292f5a)

 Conflicts:
src/test/librados/test.cc
minor changes and remove C++11 stuff

src/test/librados/io.cc
src/test/librados/test.cc
src/test/librados/test.h

index 6f391df7353bd7b751de7b1a7eb294535066ad07..0cb2a8e9f0366aa72209442417652e7e99e1f08a 100644 (file)
@@ -223,6 +223,25 @@ TEST_F(LibRadosIoPP, ReadOpPP) {
   }
 }
 
+TEST_F(LibRadosIoPP, SparseReadOpPP) {
+  char buf[128];
+  memset(buf, 0xcc, sizeof(buf));
+  bufferlist bl;
+  bl.append(buf, sizeof(buf));
+  ASSERT_EQ(0, ioctx.write("foo", bl, sizeof(buf), 0));
+
+  {
+    std::map<uint64_t, uint64_t> extents;
+    bufferlist read_bl;
+    int rval = -1;
+    ObjectReadOperation op;
+    op.sparse_read(0, sizeof(buf), &extents, &read_bl, &rval);
+    ASSERT_EQ(0, ioctx.operate("foo", &op, NULL));
+    ASSERT_EQ(0, rval);
+    assert_eq_sparse(bl, extents, read_bl);
+  }
+}
+
 TEST_F(LibRadosIo, RoundTrip) {
   char buf[128];
   char buf2[128];
@@ -689,6 +708,25 @@ TEST_F(LibRadosIoECPP, ReadOpPP) {
   }
 }
 
+TEST_F(LibRadosIoECPP, SparseReadOpPP) {
+  char buf[128];
+  memset(buf, 0xcc, sizeof(buf));
+  bufferlist bl;
+  bl.append(buf, sizeof(buf));
+  ASSERT_EQ(0, ioctx.write("foo", bl, sizeof(buf), 0));
+
+  {
+    std::map<uint64_t, uint64_t> extents;
+    bufferlist read_bl;
+    int rval = -1;
+    ObjectReadOperation op;
+    op.sparse_read(0, sizeof(buf), &extents, &read_bl, &rval);
+    ASSERT_EQ(0, ioctx.operate("foo", &op, NULL));
+    ASSERT_EQ(0, rval);
+    assert_eq_sparse(bl, extents, read_bl);
+  }
+}
+
 TEST_F(LibRadosIoEC, RoundTrip) {
   char buf[128];
   char buf2[128];
index f8a92a2ffad330f119133d7cb416ea07dbc4247e..e5f815664c2fadbf98bcf99ede77631ef36a5033 100644 (file)
@@ -10,6 +10,7 @@
 #include <string>
 #include <time.h>
 #include <unistd.h>
+#include "gtest/gtest.h"
 
 using namespace librados;
 
@@ -255,3 +256,29 @@ int destroy_one_ec_pool_pp(const std::string &pool_name, Rados &cluster)
   cluster.shutdown();
   return ret;
 }
+
+void assert_eq_sparse(bufferlist& expected,
+                      const std::map<uint64_t, uint64_t>& extents,
+                      bufferlist& actual) {
+  bufferlist::iterator i = expected.begin();
+  bufferlist::iterator p = actual.begin();
+  uint64_t pos = 0;
+  for (std::map<uint64_t, uint64_t>::const_iterator extent = extents.begin();
+       extent != extents.end();
+       ++extent) {
+    const uint64_t start = extent->first;
+    const uint64_t end = start + extent->second;
+    for (; pos < end; ++i, ++pos) {
+      ASSERT_FALSE(i.end());
+      if (pos < start) {
+        // check the hole
+        ASSERT_EQ('\0', *i);
+      } else {
+        // then the extent
+        ASSERT_EQ(*i, *p);
+        ++p;
+      }
+    }
+  }
+  ASSERT_EQ(expected.length(), pos);
+}
index 6cf522def31d8194c9170311c4f3fd44be69d000..cd1f9817653458646b62e2b724b2dc8c237103e7 100644 (file)
@@ -18,6 +18,7 @@
 #include "include/rados/librados.h"
 #include "include/rados/librados.hpp"
 
+#include <map>
 #include <string>
 #include <unistd.h>
 
@@ -35,6 +36,9 @@ int destroy_one_pool(const std::string &pool_name, rados_t *cluster);
 int destroy_one_ec_pool(const std::string &pool_name, rados_t *cluster);
 int destroy_one_pool_pp(const std::string &pool_name, librados::Rados &cluster);
 int destroy_one_ec_pool_pp(const std::string &pool_name, librados::Rados &cluster);
+void assert_eq_sparse(bufferlist& expected,
+                      const std::map<uint64_t, uint64_t>& extents,
+                      bufferlist& actual);
 
 class TestAlarm
 {