diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/test/librados/TestCase.cc | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/librados/TestCase.cc')
-rw-r--r-- | src/test/librados/TestCase.cc | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/src/test/librados/TestCase.cc b/src/test/librados/TestCase.cc new file mode 100644 index 000000000..1066587b5 --- /dev/null +++ b/src/test/librados/TestCase.cc @@ -0,0 +1,190 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include <errno.h> +#include "test/librados/test.h" +#include "test/librados/TestCase.h" +#include "include/scope_guard.h" + + +std::string RadosTestNS::pool_name; +rados_t RadosTestNS::s_cluster = NULL; + + +void RadosTestNS::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool(pool_name, &s_cluster)); +} + +void RadosTestNS::TearDownTestCase() +{ + ASSERT_EQ(0, destroy_one_pool(pool_name, &s_cluster)); +} + +void RadosTestNS::SetUp() +{ + cluster = RadosTestNS::s_cluster; + ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx)); + int requires; + ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires)); + ASSERT_FALSE(requires); +} + +void RadosTestNS::TearDown() +{ + if (cleanup) + cleanup_all_objects(ioctx); + rados_ioctx_destroy(ioctx); +} + +void RadosTestNS::cleanup_all_objects(rados_ioctx_t ioctx) +{ + // remove all objects to avoid polluting other tests + rados_ioctx_snap_set_read(ioctx, LIBRADOS_SNAP_HEAD); + rados_ioctx_set_namespace(ioctx, LIBRADOS_ALL_NSPACES); + rados_list_ctx_t list_ctx; + + ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx)); + auto sg = make_scope_guard([&] { rados_nobjects_list_close(list_ctx); }); + + int r; + const char *entry = NULL; + const char *key = NULL; + const char *nspace = NULL; + while ((r = rados_nobjects_list_next(list_ctx, &entry, &key, &nspace)) != -ENOENT) { + ASSERT_EQ(0, r); + rados_ioctx_locator_set_key(ioctx, key); + rados_ioctx_set_namespace(ioctx, nspace); + ASSERT_EQ(0, rados_remove(ioctx, entry)); + } +} + +std::string RadosTestECNS::pool_name; +rados_t RadosTestECNS::s_cluster = NULL; + +void RadosTestECNS::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_ec_pool(pool_name, &s_cluster)); +} + +void RadosTestECNS::TearDownTestCase() +{ + ASSERT_EQ(0, destroy_one_ec_pool(pool_name, &s_cluster)); +} + +void RadosTestECNS::SetUp() +{ + cluster = RadosTestECNS::s_cluster; + ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx)); + int requires; + ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires)); + ASSERT_TRUE(requires); + ASSERT_EQ(0, rados_ioctx_pool_required_alignment2(ioctx, &alignment)); + ASSERT_NE(0U, alignment); +} + +void RadosTestECNS::TearDown() +{ + if (cleanup) + cleanup_all_objects(ioctx); + rados_ioctx_destroy(ioctx); +} + +std::string RadosTest::pool_name; +rados_t RadosTest::s_cluster = NULL; + +void RadosTest::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool(pool_name, &s_cluster)); +} + +void RadosTest::TearDownTestCase() +{ + ASSERT_EQ(0, destroy_one_pool(pool_name, &s_cluster)); +} + +void RadosTest::SetUp() +{ + cluster = RadosTest::s_cluster; + ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx)); + nspace = get_temp_pool_name(); + rados_ioctx_set_namespace(ioctx, nspace.c_str()); + int requires; + ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires)); + ASSERT_FALSE(requires); +} + +void RadosTest::TearDown() +{ + if (cleanup) { + cleanup_default_namespace(ioctx); + cleanup_namespace(ioctx, nspace); + } + rados_ioctx_destroy(ioctx); +} + +void RadosTest::cleanup_default_namespace(rados_ioctx_t ioctx) +{ + // remove all objects from the default namespace to avoid polluting + // other tests + cleanup_namespace(ioctx, ""); +} + +void RadosTest::cleanup_namespace(rados_ioctx_t ioctx, std::string ns) +{ + rados_ioctx_snap_set_read(ioctx, LIBRADOS_SNAP_HEAD); + rados_ioctx_set_namespace(ioctx, ns.c_str()); + rados_list_ctx_t list_ctx; + + ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx)); + auto sg = make_scope_guard([&] { rados_nobjects_list_close(list_ctx); }); + + int r; + const char *entry = NULL; + const char *key = NULL; + while ((r = rados_nobjects_list_next(list_ctx, &entry, &key, NULL)) != -ENOENT) { + ASSERT_EQ(0, r); + rados_ioctx_locator_set_key(ioctx, key); + ASSERT_EQ(0, rados_remove(ioctx, entry)); + } +} + +std::string RadosTestEC::pool_name; +rados_t RadosTestEC::s_cluster = NULL; + +void RadosTestEC::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_ec_pool(pool_name, &s_cluster)); +} + +void RadosTestEC::TearDownTestCase() +{ + ASSERT_EQ(0, destroy_one_ec_pool(pool_name, &s_cluster)); +} + +void RadosTestEC::SetUp() +{ + cluster = RadosTestEC::s_cluster; + ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx)); + nspace = get_temp_pool_name(); + rados_ioctx_set_namespace(ioctx, nspace.c_str()); + int requires; + ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires)); + ASSERT_TRUE(requires); + ASSERT_EQ(0, rados_ioctx_pool_required_alignment2(ioctx, &alignment)); + ASSERT_NE(0U, alignment); +} + +void RadosTestEC::TearDown() +{ + if (cleanup) { + cleanup_default_namespace(ioctx); + cleanup_namespace(ioctx, nspace); + } + rados_ioctx_destroy(ioctx); +} + |