]> git-server-git.apps.pok.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>
Tue, 1 Sep 2015 05:49:22 +0000 (13:49 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/librados/io.cc
src/test/librados/test.cc
src/test/librados/test.h

index 09764223a92702bb66e02010c6d40ea2305521e8..2634119a4d29e94bd084779d1df59b25ffae6658 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, nullptr));
+    ASSERT_EQ(0, rval);
+    assert_eq_sparse(bl, extents, read_bl);
+  }
+}
+
 TEST_F(LibRadosIo, RoundTrip) {
   char buf[128];
   char buf2[128];
@@ -721,6 +740,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, nullptr));
+    ASSERT_EQ(0, rval);
+    assert_eq_sparse(bl, extents, read_bl);
+  }
+}
+
 TEST_F(LibRadosIoEC, RoundTrip) {
   char buf[128];
   char buf2[128];
index acf12276ac1c9221945b45f573d15f86867c9159..aac053a2e67b1db49412088a094ce693bf03110f 100644 (file)
@@ -11,6 +11,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <iostream>
+#include "gtest/gtest.h"
 
 using namespace librados;
 
@@ -256,3 +257,27 @@ 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) {
+  auto i = expected.begin();
+  auto p = actual.begin();
+  uint64_t pos = 0;
+  for (auto extent : extents) {
+    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
 {