From ebaabe5647825f4d490b26abbc88ca2cbfadfef2 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 11:45:41 +0800 Subject: [PATCH] test/librbd: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- src/test/librbd/cache/pwl/test_WriteLogMap.cc | 2 ++ src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc | 2 ++ src/test/librbd/journal/test_Entries.cc | 1 + .../librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc | 2 +- src/test/librbd/mock/MockImageCtx.h | 2 +- src/test/librbd/test_DeepCopy.cc | 2 +- src/test/librbd/test_Groups.cc | 4 ++-- src/test/librbd/test_ImageWatcher.cc | 1 + src/test/librbd/test_Migration.cc | 4 ++-- src/test/librbd/test_ObjectMap.cc | 2 ++ src/test/librbd/test_internal.cc | 2 ++ src/test/librbd/test_mirroring.cc | 2 ++ src/test/librbd/test_mock_ManagedLock.cc | 2 ++ src/test/librbd/test_mock_Watcher.cc | 1 + 14 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/test/librbd/cache/pwl/test_WriteLogMap.cc b/src/test/librbd/cache/pwl/test_WriteLogMap.cc index 7263d0831ac..1cafb00ffe6 100644 --- a/src/test/librbd/cache/pwl/test_WriteLogMap.cc +++ b/src/test/librbd/cache/pwl/test_WriteLogMap.cc @@ -13,6 +13,8 @@ namespace librbd { namespace cache { namespace pwl { +using namespace std; + struct TestLogEntry { uint64_t image_offset_bytes; uint64_t write_bytes; diff --git a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc index 4fac9ea41dc..4bcca201f7a 100644 --- a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc +++ b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc @@ -116,6 +116,8 @@ DiffRequest* DiffRequest::s_instance = nullp #include "librbd/deep_copy/ImageCopyRequest.cc" template class librbd::deep_copy::ImageCopyRequest; +using namespace std::chrono_literals; + namespace librbd { namespace deep_copy { diff --git a/src/test/librbd/journal/test_Entries.cc b/src/test/librbd/journal/test_Entries.cc index d89c4f8e423..c392fb9f88a 100644 --- a/src/test/librbd/journal/test_Entries.cc +++ b/src/test/librbd/journal/test_Entries.cc @@ -89,6 +89,7 @@ public: } bool wait_for_entries_available(librbd::ImageCtx *ictx) { + using namespace std::chrono_literals; std::unique_lock locker{m_replay_handler.lock}; while (!m_replay_handler.entries_available) { if (m_replay_handler.cond.wait_for(locker, 10s) == std::cv_status::timeout) { diff --git a/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc b/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc index 9826bf9b0a4..95b25ffa12f 100644 --- a/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc +++ b/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc @@ -347,7 +347,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, SuccessUnlinkNoPeer) { MockUnlinkPeerRequest mock_unlink_peer_request; auto it = mock_image_ctx.snap_info.rbegin(); auto snap_id = it->first; - std::list peer_uuids = {"uuid"}; + std::list peer_uuids = {"uuid"}; expect_unlink_peer(mock_image_ctx, mock_unlink_peer_request, snap_id, "uuid", false, 0); diff --git a/src/test/librbd/mock/MockImageCtx.h b/src/test/librbd/mock/MockImageCtx.h index 525071fbe3e..3e1483d2d02 100644 --- a/src/test/librbd/mock/MockImageCtx.h +++ b/src/test/librbd/mock/MockImageCtx.h @@ -170,7 +170,7 @@ struct MockImageCtx { MOCK_CONST_METHOD1(get_parent_info, const ParentImageInfo*(librados::snap_t)); MOCK_CONST_METHOD2(get_parent_overlap, int(librados::snap_t in_snap_id, uint64_t *overlap)); - MOCK_CONST_METHOD2(prune_parent_extents, uint64_t(vector >& , + MOCK_CONST_METHOD2(prune_parent_extents, uint64_t(std::vector >& , uint64_t)); MOCK_CONST_METHOD2(is_snap_protected, int(librados::snap_t in_snap_id, diff --git a/src/test/librbd/test_DeepCopy.cc b/src/test/librbd/test_DeepCopy.cc index 1a512aa292c..bb6d3f6bf00 100644 --- a/src/test/librbd/test_DeepCopy.cc +++ b/src/test/librbd/test_DeepCopy.cc @@ -59,7 +59,7 @@ struct TestDeepCopy : public TestFixture { } void compare() { - vector src_snaps, dst_snaps; + std::vector src_snaps, dst_snaps; EXPECT_EQ(m_src_ictx->size, m_dst_ictx->size); EXPECT_EQ(0, librbd::api::Snapshot<>::list(m_src_ictx, src_snaps)); diff --git a/src/test/librbd/test_Groups.cc b/src/test/librbd/test_Groups.cc index 3182d2a2004..29b29e478a5 100644 --- a/src/test/librbd/test_Groups.cc +++ b/src/test/librbd/test_Groups.cc @@ -52,7 +52,7 @@ TEST_F(TestGroup, group_createPP) librbd::RBD rbd; ASSERT_EQ(0, rbd.group_create(ioctx, "mygroup")); - vector groups; + std::vector groups; ASSERT_EQ(0, rbd.group_list(ioctx, &groups)); ASSERT_EQ(1U, groups.size()); ASSERT_EQ("mygroup", groups[0]); @@ -172,7 +172,7 @@ TEST_F(TestGroup, add_imagePP) ASSERT_TRUE((op_features & RBD_OPERATION_FEATURE_GROUP) == RBD_OPERATION_FEATURE_GROUP); - vector images; + std::vector images; ASSERT_EQ(0, rbd.group_image_list(ioctx, group_name, &images, sizeof(librbd::group_image_info_t))); ASSERT_EQ(1U, images.size()); diff --git a/src/test/librbd/test_ImageWatcher.cc b/src/test/librbd/test_ImageWatcher.cc index f02c7b37b81..c8d39645a44 100644 --- a/src/test/librbd/test_ImageWatcher.cc +++ b/src/test/librbd/test_ImageWatcher.cc @@ -28,6 +28,7 @@ #include #include +using namespace std::chrono_literals; using namespace ceph; using namespace boost::assign; using namespace librbd::watch_notify; diff --git a/src/test/librbd/test_Migration.cc b/src/test/librbd/test_Migration.cc index 959eb093475..8c0f4b61b21 100644 --- a/src/test/librbd/test_Migration.cc +++ b/src/test/librbd/test_Migration.cc @@ -70,7 +70,7 @@ struct TestMigration : public TestFixture { } void compare(const std::string &description = "") { - vector src_snaps, dst_snaps; + std::vector src_snaps, dst_snaps; EXPECT_EQ(m_ref_ictx->size, m_ictx->size); EXPECT_EQ(0, librbd::api::Snapshot<>::list(m_ref_ictx, src_snaps)); @@ -489,7 +489,7 @@ struct TestMigration : public TestFixture { migration_prepare(m_ioctx, m_image_name); migration_status(RBD_IMAGE_MIGRATION_STATE_PREPARED); - thread user([this]() { + std::thread user([this]() { test_stress("user", 'a'); for (int i = 0; i < 5; i++) { uint64_t off = (i + 1) * m_ictx->size / 10; diff --git a/src/test/librbd/test_ObjectMap.cc b/src/test/librbd/test_ObjectMap.cc index 61497b2af85..32d223a1d27 100644 --- a/src/test/librbd/test_ObjectMap.cc +++ b/src/test/librbd/test_ObjectMap.cc @@ -158,6 +158,8 @@ TEST_F(TestObjectMap, AcquireLockInvalidatesWhenTooSmall) { ASSERT_TRUE(flags_set); } +namespace chrono = std::chrono; + TEST_F(TestObjectMap, DISABLED_StressTest) { REQUIRE_FEATURE(RBD_FEATURE_OBJECT_MAP); diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 4a793a021b6..06423d4f105 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -29,6 +29,8 @@ #include #include +using namespace std; + void register_test_internal() { } diff --git a/src/test/librbd/test_mirroring.cc b/src/test/librbd/test_mirroring.cc index 4fe1d97b9ed..4d39ae27e07 100644 --- a/src/test/librbd/test_mirroring.cc +++ b/src/test/librbd/test_mirroring.cc @@ -36,6 +36,8 @@ #include #include +using namespace std; + void register_test_mirroring() { } diff --git a/src/test/librbd/test_mock_ManagedLock.cc b/src/test/librbd/test_mock_ManagedLock.cc index 3e6b15f6112..800a8ee7ccb 100644 --- a/src/test/librbd/test_mock_ManagedLock.cc +++ b/src/test/librbd/test_mock_ManagedLock.cc @@ -13,6 +13,8 @@ #include "gtest/gtest.h" #include +using namespace std; + namespace librbd { struct MockManagedLockImageCtx : public MockImageCtx { diff --git a/src/test/librbd/test_mock_Watcher.cc b/src/test/librbd/test_mock_Watcher.cc index 97f77574053..54b395b1f0d 100644 --- a/src/test/librbd/test_mock_Watcher.cc +++ b/src/test/librbd/test_mock_Watcher.cc @@ -118,6 +118,7 @@ public: } bool wait_for_watch(MockImageCtx &mock_image_ctx, size_t count) { + using namespace std::chrono_literals; std::unique_lock locker{m_lock}; while (m_watch_count < count) { if (m_cond.wait_for(locker, 10s) == std::cv_status::timeout) { -- 2.39.5