From: Kefu Chai Date: Thu, 27 Aug 2015 14:57:16 +0000 (+0800) Subject: ceph_test_rados_api_io: add tests for sparse_read X-Git-Tag: v0.94.6~103^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8849f9933fe0fc315da0981f9cd88ea108f686ed;p=ceph.git ceph_test_rados_api_io: add tests for sparse_read Signed-off-by: Kefu Chai (cherry picked from commit 4d4920610ebfcb516630ed15678979c9e9292f5a) Conflicts: src/test/librados/test.cc minor changes and remove C++11 stuff --- diff --git a/src/test/librados/io.cc b/src/test/librados/io.cc index 6f391df7353b..0cb2a8e9f036 100644 --- a/src/test/librados/io.cc +++ b/src/test/librados/io.cc @@ -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 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 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]; diff --git a/src/test/librados/test.cc b/src/test/librados/test.cc index f8a92a2ffad3..e5f815664c2f 100644 --- a/src/test/librados/test.cc +++ b/src/test/librados/test.cc @@ -10,6 +10,7 @@ #include #include #include +#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& extents, + bufferlist& actual) { + bufferlist::iterator i = expected.begin(); + bufferlist::iterator p = actual.begin(); + uint64_t pos = 0; + for (std::map::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); +} diff --git a/src/test/librados/test.h b/src/test/librados/test.h index 6cf522def31d..cd1f98176534 100644 --- a/src/test/librados/test.h +++ b/src/test/librados/test.h @@ -18,6 +18,7 @@ #include "include/rados/librados.h" #include "include/rados/librados.hpp" +#include #include #include @@ -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& extents, + bufferlist& actual); class TestAlarm {