From a09da2a2c6c12c6bf2f8e17f2096b3ab24587007 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 5 May 2015 10:27:38 -0400 Subject: [PATCH] tests: create librbd API-only integration test suite The QA client-upgrade test suite requires a librbd test that is dynamically linked to librbd. Since the current ceph_test_librbd includes tests against the non-public API, it is statically linked against librbd and thus cannot be used to test a client upgrade scenario. Backport: hammer Signed-off-by: Jason Dillaman (cherry picked from commit 6fe94c8cbb924c31c1007e2d0c76f28ce9dbca57) --- src/test/Makefile-client.am | 26 +++++++++++++++++------- src/test/Makefile.am | 1 + src/test/librbd/test_ImageWatcher.cc | 1 + src/test/librbd/test_fixture.cc | 27 +------------------------ src/test/librbd/test_fixture.h | 12 ----------- src/test/librbd/test_internal.cc | 1 + src/test/librbd/test_librbd.cc | 3 ++- src/test/librbd/test_main.cc | 8 ++++++-- src/test/librbd/test_support.cc | 30 ++++++++++++++++++++++++++++ src/test/librbd/test_support.h | 19 ++++++++++++++++++ 10 files changed, 80 insertions(+), 48 deletions(-) create mode 100644 src/test/librbd/test_support.cc create mode 100644 src/test/librbd/test_support.h diff --git a/src/test/Makefile-client.am b/src/test/Makefile-client.am index e83a13107b996..39135502d3c6e 100644 --- a/src/test/Makefile-client.am +++ b/src/test/Makefile-client.am @@ -300,15 +300,16 @@ check_PROGRAMS += unittest_rbd_replay librbd_test_la_SOURCES = \ test/librbd/test_fixture.cc \ + test/librbd/test_support.cc \ test/librbd/test_librbd.cc \ test/librbd/test_ImageWatcher.cc \ - test/librbd/test_internal.cc \ - test/librbd/test_main.cc + test/librbd/test_internal.cc librbd_test_la_CXXFLAGS = $(UNITTEST_CXXFLAGS) noinst_LTLIBRARIES += librbd_test.la -unittest_librbd_SOURCES = -nodist_EXTRA_unittest_librbd_SOURCES = dummy.cc +unittest_librbd_SOURCES = \ + test/librbd/test_main.cc +unittest_librbd_CXXFLAGS = $(UNITTEST_CXXFLAGS) -DTEST_LIBRBD_INTERNALS unittest_librbd_LDADD = \ librbd_test.la librbd_api.la librbd_internal.la $(LIBRBD_TYPES) \ libcls_rbd_client.la libcls_lock_client.la \ @@ -317,19 +318,30 @@ unittest_librbd_LDADD = \ $(CEPH_GLOBAL) $(RADOS_TEST_LDADD) check_PROGRAMS += unittest_librbd -ceph_test_librbd_SOURCES = -nodist_EXTRA_ceph_test_librbd_SOURCES = dummy.cc +ceph_test_librbd_SOURCES = \ + test/librbd/test_main.cc +ceph_test_librbd_CXXFLAGS = $(UNITTEST_CXXFLAGS) -DTEST_LIBRBD_INTERNALS ceph_test_librbd_LDADD = \ librbd_test.la librbd_api.la librbd_internal.la $(LIBRBD_TYPES) \ libcls_rbd_client.la libcls_lock_client.la \ librados_api.la $(LIBRADOS_DEPS) $(UNITTEST_LDADD) \ $(CEPH_GLOBAL) $(RADOS_TEST_LDADD) -ceph_test_librbd_CXXFLAGS = $(UNITTEST_CXXFLAGS) bin_DEBUGPROGRAMS += ceph_test_librbd +ceph_test_librbd_api_SOURCES = \ + test/librbd/test_support.cc \ + test/librbd/test_librbd.cc \ + test/librbd/test_main.cc +ceph_test_librbd_api_CXXFLAGS = $(UNITTEST_CXXFLAGS) +ceph_test_librbd_api_LDADD = \ + $(LIBRBD) $(LIBRADOS) $(UNITTEST_LDADD) \ + $(CEPH_GLOBAL) $(RADOS_TEST_LDADD) +bin_DEBUGPROGRAMS += ceph_test_librbd_api + if WITH_LTTNG unittest_librbd_LDADD += $(LIBRBD_TP) ceph_test_librbd_LDADD += $(LIBRBD_TP) +ceph_test_librbd_api_LDADD += $(LIBRBD_TP) endif if LINUX diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 15f051d02059b..ab77ba7a512bc 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -425,6 +425,7 @@ noinst_HEADERS += \ test/librados/TestCase.h \ test/libradosstriper/TestCase.h \ test/librbd/test_fixture.h \ + test/librbd/test_support.h \ test/ObjectMap/KeyValueDBMemory.h \ test/omap_bench.h \ test/osdc/FakeWriteback.h \ diff --git a/src/test/librbd/test_ImageWatcher.cc b/src/test/librbd/test_ImageWatcher.cc index b73bc7b002091..8d9ffea3d143a 100644 --- a/src/test/librbd/test_ImageWatcher.cc +++ b/src/test/librbd/test_ImageWatcher.cc @@ -1,6 +1,7 @@ // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "test/librbd/test_fixture.h" +#include "test/librbd/test_support.h" #include "include/int_types.h" #include "include/stringify.h" #include "include/rados/librados.h" diff --git a/src/test/librbd/test_fixture.cc b/src/test/librbd/test_fixture.cc index 9e47125489971..e3db5c9f8496a 100644 --- a/src/test/librbd/test_fixture.cc +++ b/src/test/librbd/test_fixture.cc @@ -1,6 +1,7 @@ // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "test/librbd/test_fixture.h" +#include "test/librbd/test_support.h" #include "include/stringify.h" #include "cls/lock/cls_lock_client.h" #include "cls/lock/cls_lock_types.h" @@ -10,32 +11,6 @@ #include #include -bool get_features(uint64_t *features) { - const char *c = getenv("RBD_FEATURES"); - if (c == NULL) { - return false; - } - - std::stringstream ss(c); - if (!(ss >> *features)) { - return false; - } - return true; -} - -bool is_feature_enabled(uint64_t feature) { - uint64_t features; - return (get_features(&features) && (features & feature) == feature); -} - -int create_image_pp(librbd::RBD &rbd, librados::IoCtx &ioctx, - const std::string &name, uint64_t size) { - uint64_t features = 0; - get_features(&features); - int order = 0; - return rbd.create2(ioctx, name.c_str(), size, features, &order); -} - std::string TestFixture::_pool_name; librados::Rados TestFixture::_rados; uint64_t TestFixture::_image_number = 0; diff --git a/src/test/librbd/test_fixture.h b/src/test/librbd/test_fixture.h index d3246a7808d67..7e3fff81ca875 100644 --- a/src/test/librbd/test_fixture.h +++ b/src/test/librbd/test_fixture.h @@ -10,18 +10,6 @@ using namespace ceph; -bool get_features(uint64_t *features); -bool is_feature_enabled(uint64_t feature); -int create_image_pp(librbd::RBD &rbd, librados::IoCtx &ioctx, - const std::string &name, uint64_t size); - -#define REQUIRE_FEATURE(feature) { \ - if (!is_feature_enabled(feature)) { \ - std::cout << "SKIPPING" << std::endl; \ - return SUCCEED(); \ - } \ -} - class TestFixture : public ::testing::Test { public: diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index aac4d4dcc7194..9f456d1af3e9f 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -1,6 +1,7 @@ // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "test/librbd/test_fixture.h" +#include "test/librbd/test_support.h" #include "librbd/AioCompletion.h" #include "librbd/ImageWatcher.h" #include "librbd/internal.h" diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index cf76c67c7b645..73b3f5bbabca8 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -22,6 +22,7 @@ #include "global/global_init.h" #include "common/ceph_argparse.h" #include "common/config.h" +#include "common/Thread.h" #include "gtest/gtest.h" @@ -39,7 +40,7 @@ #include #include "test/librados/test.h" -#include "test/librbd/test_fixture.h" +#include "test/librbd/test_support.h" #include "common/errno.h" #include "include/interval_set.h" #include "include/stringify.h" diff --git a/src/test/librbd/test_main.cc b/src/test/librbd/test_main.cc index 4b72eb464dece..792e758954f57 100644 --- a/src/test/librbd/test_main.cc +++ b/src/test/librbd/test_main.cc @@ -7,15 +7,19 @@ #include "global/global_init.h" #include +extern void register_test_librbd(); +#ifdef TEST_LIBRBD_INTERNALS extern void register_test_image_watcher(); extern void register_test_internal(); -extern void register_test_librbd(); +#endif // TEST_LIBRBD_INTERNALS int main(int argc, char **argv) { + register_test_librbd(); +#ifdef TEST_LIBRBD_INTERNALS register_test_image_watcher(); register_test_internal(); - register_test_librbd(); +#endif // TEST_LIBRBD_INTERNALS ::testing::InitGoogleTest(&argc, argv); diff --git a/src/test/librbd/test_support.cc b/src/test/librbd/test_support.cc new file mode 100644 index 0000000000000..318b5be14624b --- /dev/null +++ b/src/test/librbd/test_support.cc @@ -0,0 +1,30 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#include "test/librbd/test_support.h" +#include + +bool get_features(uint64_t *features) { + const char *c = getenv("RBD_FEATURES"); + if (c == NULL) { + return false; + } + + std::stringstream ss(c); + if (!(ss >> *features)) { + return false; + } + return true; +} + +bool is_feature_enabled(uint64_t feature) { + uint64_t features; + return (get_features(&features) && (features & feature) == feature); +} + +int create_image_pp(librbd::RBD &rbd, librados::IoCtx &ioctx, + const std::string &name, uint64_t size) { + uint64_t features = 0; + get_features(&features); + int order = 0; + return rbd.create2(ioctx, name.c_str(), size, features, &order); +} diff --git a/src/test/librbd/test_support.h b/src/test/librbd/test_support.h new file mode 100644 index 0000000000000..5bdd958573d27 --- /dev/null +++ b/src/test/librbd/test_support.h @@ -0,0 +1,19 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#include "include/int_types.h" +#include "include/rados/librados.h" +#include "include/rbd/librbd.hpp" +#include + +bool get_features(uint64_t *features); +bool is_feature_enabled(uint64_t feature); +int create_image_pp(librbd::RBD &rbd, librados::IoCtx &ioctx, + const std::string &name, uint64_t size); + +#define REQUIRE_FEATURE(feature) { \ + if (!is_feature_enabled(feature)) { \ + std::cout << "SKIPPING" << std::endl; \ + return SUCCEED(); \ + } \ +} + -- 2.39.5