From 1c01c3a456c53dafdb8fb7654d54d239994923e2 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 11 Dec 2014 12:53:59 -0500 Subject: [PATCH] tests: create unittest_librbd The existing ceph_test_librbd integration tests are now used within unittest_librbd as unit tests run during 'make check'. The unit tests use librados_test_stub to simulate RADOS. Signed-off-by: Jason Dillaman --- src/test/Makefile.am | 25 ++++++++++++++++++++---- src/test/librbd/test_ImageWatcher.cc | 12 +++++++++--- src/test/librbd/test_internal.cc | 3 +++ src/test/librbd/test_librbd.cc | 16 +++------------ src/test/librbd/test_main.cc | 29 ++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 src/test/librbd/test_main.cc diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 8e61a0e8bf988..430678ebe6590 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -747,20 +747,37 @@ noinst_HEADERS += \ test/librados_test_stub/TestIoCtxImpl.h noinst_LTLIBRARIES += librados_test_stub.la -ceph_test_librbd_SOURCES = \ +librbd_test_la_SOURCES = \ test/librbd/test_fixture.cc \ test/librbd/test_librbd.cc \ test/librbd/test_ImageWatcher.cc \ - test/librbd/test_internal.cc -ceph_test_librbd_LDADD = \ - librbd_api.la librbd_internal.la \ + test/librbd/test_internal.cc \ + test/librbd/test_main.cc +librbd_test_la_CXXFLAGS = $(UNITTEST_CXXFLAGS) +noinst_LTLIBRARIES += librbd_test.la + +unittest_librbd_SOURCES = +nodist_EXTRA_unittest_librbd_SOURCES = dummy.cc +unittest_librbd_LDADD = \ + librbd_test.la librbd_api.la librbd_internal.la \ libcls_rbd_client.la libcls_lock_client.la \ + librados_test_stub.la librados_internal.la \ + $(LIBOSDC) $(UNITTEST_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_LDADD = \ + librbd_test.la librbd_api.la librbd_internal.la \ + 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 if WITH_LTTNG +unittest_librbd_LDADD += $(LIBRBD_TP) ceph_test_librbd_LDADD += $(LIBRBD_TP) endif diff --git a/src/test/librbd/test_ImageWatcher.cc b/src/test/librbd/test_ImageWatcher.cc index 2b8b945bdab73..7b87c55e64ede 100644 --- a/src/test/librbd/test_ImageWatcher.cc +++ b/src/test/librbd/test_ImageWatcher.cc @@ -26,6 +26,9 @@ using namespace ceph; +void register_test_image_watcher() { +} + class TestImageWatcher : public TestFixture { public: @@ -342,14 +345,17 @@ TEST_F(TestImageWatcher, UnlockNotifyReleaseLock) { ASSERT_EQ(0, register_image_watch(*ictx)); m_notify_acks = boost::assign::list_of( - std::make_pair(NOTIFY_OP_ACQUIRED_LOCK, bufferlist()))( - std::make_pair(NOTIFY_OP_RELEASED_LOCK, bufferlist())); + std::make_pair(NOTIFY_OP_ACQUIRED_LOCK, bufferlist())); RWLock::WLocker l(ictx->owner_lock); ASSERT_EQ(0, ictx->image_watcher->try_lock()); - ASSERT_EQ(0, ictx->image_watcher->unlock()); + ASSERT_TRUE(wait_for_notifies(*ictx)); + m_notify_acks = boost::assign::list_of( + std::make_pair(NOTIFY_OP_RELEASED_LOCK, bufferlist())); + ASSERT_EQ(0, ictx->image_watcher->unlock()); ASSERT_TRUE(wait_for_notifies(*ictx)); + ASSERT_TRUE(m_notify_acks.empty()); NotifyOpPayloads expected_notify_ops = boost::assign::list_of( std::make_pair(NOTIFY_OP_ACQUIRED_LOCK, bufferlist()))( diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 0bd747f443e36..4c004b868f2ed 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -7,6 +7,9 @@ #include #include +void register_test_internal() { +} + class TestInternal : public TestFixture { public: diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index afe4988f67f49..71648726bd5a6 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -54,6 +54,9 @@ using namespace std; ASSERT_TRUE(passed); \ } while(0) +void register_test_librbd() { +} + static int get_features(bool *old_format, uint64_t *features) { const char *c = getenv("RBD_FEATURES"); @@ -2243,16 +2246,3 @@ TEST_F(TestLibRBD, TestPendingAio) rados_ioctx_destroy(ioctx); } - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - vector args; - argv_to_vec(argc, (const char **)argv, args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - - return RUN_ALL_TESTS(); -} diff --git a/src/test/librbd/test_main.cc b/src/test/librbd/test_main.cc new file mode 100644 index 0000000000000..4b72eb464dece --- /dev/null +++ b/src/test/librbd/test_main.cc @@ -0,0 +1,29 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "gtest/gtest.h" +#include "common/ceph_argparse.h" +#include "global/global_context.h" +#include "global/global_init.h" +#include + +extern void register_test_image_watcher(); +extern void register_test_internal(); +extern void register_test_librbd(); + +int main(int argc, char **argv) +{ + register_test_image_watcher(); + register_test_internal(); + register_test_librbd(); + + ::testing::InitGoogleTest(&argc, argv); + + vector args; + argv_to_vec(argc, (const char **)argv, args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + + return RUN_ALL_TESTS(); +} -- 2.39.5