Skip to content

Commit

Permalink
Merge pull request #11190 from tchaikov/wip-memstore-clone-fixture
Browse files Browse the repository at this point in the history
tests: use a fixture for memstore clone testing

Reviewed-by: Casey Bodley <cbodley@redhat.com>
  • Loading branch information
cbodley committed Sep 22, 2016
2 parents bbf94dd + 0cad3dc commit 3bb268a
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 112 deletions.
10 changes: 8 additions & 2 deletions src/test/objectstore/CMakeLists.txt
Expand Up @@ -9,9 +9,13 @@ install(TARGETS ceph_perf_objectstore
DESTINATION bin)

#ceph_test_objectstore
add_library(store_test_fixture OBJECT store_test_fixture.cc)
set_target_properties(store_test_fixture PROPERTIES
COMPILE_FLAGS ${UNITTEST_CXX_FLAGS})

add_executable(ceph_test_objectstore
store_test.cc
)
$<TARGET_OBJECTS:store_test_fixture>)
set_target_properties(ceph_test_objectstore PROPERTIES COMPILE_FLAGS
${UNITTEST_CXX_FLAGS})
target_link_libraries(ceph_test_objectstore
Expand Down Expand Up @@ -138,6 +142,8 @@ add_ceph_unittest(unittest_transaction ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittes
target_link_libraries(unittest_transaction os common)

# unittest_memstore_clone
add_executable(unittest_memstore_clone test_memstore_clone.cc)
add_executable(unittest_memstore_clone
test_memstore_clone.cc
$<TARGET_OBJECTS:store_test_fixture>)
add_ceph_unittest(unittest_memstore_clone ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_memstore_clone)
target_link_libraries(unittest_memstore_clone os global)
55 changes: 10 additions & 45 deletions src/test/objectstore/store_test.cc
Expand Up @@ -34,6 +34,8 @@
#include <gtest/gtest.h>

#include "include/unordered_map.h"
#include "store_test_fixture.h"

typedef boost::mt11213b gen_type;

#if GTEST_HAS_PARAM_TEST
Expand Down Expand Up @@ -83,51 +85,6 @@ int apply_transaction(
}
}

class StoreTest : public ::testing::TestWithParam<const char*> {
public:
boost::scoped_ptr<ObjectStore> store;

StoreTest() : store(0) {}

void rm_r(string path) {
string cmd = string("rm -r ") + path;
cout << "==> " << cmd << std::endl;
int r = ::system(cmd.c_str());
if (r) {
cerr << "failed with exit code " << r
<< ", continuing anyway" << std::endl;
}
}

virtual void SetUp() {
int r = ::mkdir("store_test_temp_dir", 0777);
if (r < 0) {
r = -errno;
cerr << __func__ << ": unable to create store_test_temp_dir" << ": " << cpp_strerror(r) << std::endl;
return;
}

ObjectStore *store_ = ObjectStore::create(g_ceph_context,
string(GetParam()),
string("store_test_temp_dir"),
string("store_test_temp_journal"));
if (!store_) {
cerr << __func__ << ": objectstore type " << string(GetParam()) << " doesn't exist yet!" << std::endl;
return;
}
EXPECT_EQ(store_->mkfs(), 0);
EXPECT_EQ(store_->mount(), 0);
store.reset(store_);
}

virtual void TearDown() {
if (store) {
int r = store->umount();
EXPECT_EQ(r, 0);
rm_r("store_test_temp_dir");
}
}
};

bool sorted(const vector<ghobject_t> &in, bool bitwise) {
ghobject_t start;
Expand All @@ -143,6 +100,14 @@ bool sorted(const vector<ghobject_t> &in, bool bitwise) {
return true;
}

class StoreTest : public StoreTestFixture,
public ::testing::WithParamInterface<const char*> {
public:
StoreTest()
: StoreTestFixture(GetParam())
{}
};

TEST_P(StoreTest, collect_metadata) {
map<string,string> pm;
store->collect_metadata(&pm);
Expand Down
46 changes: 46 additions & 0 deletions src/test/objectstore/store_test_fixture.cc
@@ -0,0 +1,46 @@
#include <stdlib.h>
#include <string>
#include <iostream>
#include <gtest/gtest.h>

#include "common/errno.h"
#include "os/ObjectStore.h"
#include "store_test_fixture.h"

static void rm_r(const string& path) {
string cmd = string("rm -r ") + path;
cout << "==> " << cmd << std::endl;
int r = ::system(cmd.c_str());
if (r) {
cerr << "failed with exit code " << r
<< ", continuing anyway" << std::endl;
}
}

void StoreTestFixture::SetUp() {
int r = ::mkdir(data_dir.c_str(), 0777);
if (r < 0) {
r = -errno;
cerr << __func__ << ": unable to create " << data_dir << ": " << cpp_strerror(r) << std::endl;
}
ASSERT_EQ(0, r);

store.reset(ObjectStore::create(g_ceph_context,
type,
data_dir,
string("store_test_temp_journal")));
if (!store) {
cerr << __func__ << ": objectstore type " << type << " doesn't exist yet!" << std::endl;
}
ASSERT_TRUE(store);
ASSERT_EQ(0, store->mkfs());
ASSERT_EQ(0, store->mount());
}

void StoreTestFixture::TearDown() {
if (store) {
int r = store->umount();
EXPECT_EQ(0, r);
rm_r(data_dir);
}
}
19 changes: 19 additions & 0 deletions src/test/objectstore/store_test_fixture.h
@@ -0,0 +1,19 @@
#include <string>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>

class ObjectStore;

class StoreTestFixture : public ::testing::Test {
const std::string type;
const std::string data_dir;

public:
boost::scoped_ptr<ObjectStore> store;

StoreTestFixture(const std::string& type)
: type(type), data_dir(type + ".test_temp_dir")
{}
void SetUp() override;
void TearDown() override;
};
107 changes: 42 additions & 65 deletions src/test/objectstore/test_memstore_clone.cc
Expand Up @@ -18,10 +18,10 @@
#include <gtest/gtest.h>
#include "include/assert.h"
#include "common/errno.h"
#include "store_test_fixture.h"

namespace {

ObjectStore *g_store{nullptr};
const coll_t cid;

ghobject_t make_ghobject(const char *oid)
Expand All @@ -31,12 +31,32 @@ ghobject_t make_ghobject(const char *oid)

} // anonymous namespace

class MemStoreClone : public StoreTestFixture {
public:
MemStoreClone()
: StoreTestFixture("memstore")
{}
void SetUp() override {
StoreTestFixture::SetUp();
if (HasFailure()) {
return;
}
ObjectStore::Transaction t;
t.create_collection(cid, 4);
unsigned r = store->apply_transaction(nullptr, std::move(t));
if (r != 0) {
derr << "failed to create collection with " << cpp_strerror(r) << dendl;
}
ASSERT_EQ(0U, r);
}
};

// src 11[11 11 11 11]11
// dst 22 22 22 22 22 22
// res 22 11 11 11 11 22
TEST(MemStore, CloneRangeAllocated)
TEST_F(MemStoreClone, CloneRangeAllocated)
{
ASSERT_TRUE(g_store);
ASSERT_TRUE(store);

const auto src = make_ghobject("src1");
const auto dst = make_ghobject("dst1");
Expand All @@ -50,17 +70,17 @@ TEST(MemStore, CloneRangeAllocated)
t.write(cid, src, 0, 12, srcbl);
t.write(cid, dst, 0, 12, dstbl);
t.clone_range(cid, src, dst, 2, 8, 2);
ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
ASSERT_EQ(expected, result);
}

// src __[__ __ __ __]__ 11 11
// dst 22 22 22 22 22 22
// res 22 00 00 00 00 22
TEST(MemStore, CloneRangeHole)
TEST_F(MemStoreClone, CloneRangeHole)
{
ASSERT_TRUE(g_store);
ASSERT_TRUE(store);

const auto src = make_ghobject("src2");
const auto dst = make_ghobject("dst2");
Expand All @@ -74,17 +94,17 @@ TEST(MemStore, CloneRangeHole)
t.write(cid, src, 12, 4, srcbl);
t.write(cid, dst, 0, 12, dstbl);
t.clone_range(cid, src, dst, 2, 8, 2);
ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
ASSERT_EQ(expected, result);
}

// src __[__ __ __ 11]11
// dst 22 22 22 22 22 22
// res 22 00 00 00 11 22
TEST(MemStore, CloneRangeHoleStart)
TEST_F(MemStoreClone, CloneRangeHoleStart)
{
ASSERT_TRUE(g_store);
ASSERT_TRUE(store);

const auto src = make_ghobject("src3");
const auto dst = make_ghobject("dst3");
Expand All @@ -98,17 +118,17 @@ TEST(MemStore, CloneRangeHoleStart)
t.write(cid, src, 8, 4, srcbl);
t.write(cid, dst, 0, 12, dstbl);
t.clone_range(cid, src, dst, 2, 8, 2);
ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
ASSERT_EQ(expected, result);
}

// src 11[11 __ __ 11]11
// dst 22 22 22 22 22 22
// res 22 11 00 00 11 22
TEST(MemStore, CloneRangeHoleMiddle)
TEST_F(MemStoreClone, CloneRangeHoleMiddle)
{
ASSERT_TRUE(g_store);
ASSERT_TRUE(store);

const auto src = make_ghobject("src4");
const auto dst = make_ghobject("dst4");
Expand All @@ -123,17 +143,17 @@ TEST(MemStore, CloneRangeHoleMiddle)
t.write(cid, src, 8, 4, srcbl);
t.write(cid, dst, 0, 12, dstbl);
t.clone_range(cid, src, dst, 2, 8, 2);
ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
ASSERT_EQ(expected, result);
}

// src 11[11 __ __ __]__ 11 11
// dst 22 22 22 22 22 22
// res 22 11 00 00 00 22
TEST(MemStore, CloneRangeHoleEnd)
TEST_F(MemStoreClone, CloneRangeHoleEnd)
{
ASSERT_TRUE(g_store);
ASSERT_TRUE(store);

const auto src = make_ghobject("src5");
const auto dst = make_ghobject("dst5");
Expand All @@ -148,8 +168,8 @@ TEST(MemStore, CloneRangeHoleEnd)
t.write(cid, src, 12, 4, srcbl);
t.write(cid, dst, 0, 12, dstbl);
t.clone_range(cid, src, dst, 2, 8, 2);
ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
ASSERT_EQ(expected, result);
}

Expand All @@ -162,7 +182,7 @@ int main(int argc, char** argv)
// default to memstore
vector<const char*> defaults{
"--osd_objectstore", "memstore",
"--osd_data", "memstore_clone_temp_dir",
"--osd_data", "memstore.test_temp_dir",
"--memstore_page_size", "4",
};

Expand All @@ -176,49 +196,6 @@ int main(int argc, char** argv)
// release g_ceph_context on exit
boost::intrusive_ptr<CephContext> cct{g_ceph_context, false};

// create and mount the objectstore
std::unique_ptr<ObjectStore> store{ObjectStore::create(
g_ceph_context,
g_conf->osd_objectstore,
g_conf->osd_data,
g_conf->osd_journal,
g_conf->osd_os_flags)};
if (!store) {
derr << "failed to create osd_objectstore=" << g_conf->osd_objectstore << dendl;
return EXIT_FAILURE;
}

int r = store->mkfs();
if (r < 0) {
derr << "failed to mkfs with " << cpp_strerror(r) << dendl;
return EXIT_FAILURE;
}

r = store->mount();
if (r < 0) {
derr << "failed to mount with " << cpp_strerror(r) << dendl;
return EXIT_FAILURE;
}
g_store = store.get();

ObjectStore::Transaction t;
t.create_collection(cid, 4);
r = store->apply_transaction(nullptr, std::move(t));
if (r < 0) {
derr << "failed to create collection with " << cpp_strerror(r) << dendl;
return EXIT_FAILURE;
}

// unmount the store on exit
auto umount = [] (ObjectStore *store) {
int r = store->umount();
if (r < 0) {
derr << "failed to unmount with " << cpp_strerror(r) << dendl;
}
g_store = nullptr;
};
std::unique_ptr<ObjectStore, decltype(umount)> umounter{store.get(), umount};

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 3bb268a

Please sign in to comment.