From 429b65c63971da566044f68a140c3526adc1aa5b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 5 May 2017 15:48:46 -0400 Subject: [PATCH] mempool: kill unittest_? mempools These were just annoying. Use some real ones that will be empty for the unit tests. Signed-off-by: Sage Weil --- src/include/mempool.h | 24 +++++++------- src/test/test_mempool.cc | 68 ++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/include/mempool.h b/src/include/mempool.h index b995905b545..016b76b9c66 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -62,15 +62,15 @@ automatically created (name is same as in DEFINE_MEMORY_POOLS_HELPER). That namespace contains a set of common STL containers that are predefined with the appropriate allocators. -Thus for mempool "unittest_1" we have automatically available to us: +Thus for mempool "osd" we have automatically available to us: - mempool::unittest_1::map - mempool::unittest_1::multimap - mempool::unittest_1::set - mempool::unittest_1::multiset - mempool::unittest_1::list - mempool::unittest_1::vector - mempool::unittest_1::unordered_map + mempool::osd::map + mempool::osd::multimap + mempool::osd::set + mempool::osd::multiset + mempool::osd::list + mempool::osd::vector + mempool::osd::unordered_map Putting objects in a mempool @@ -88,7 +88,7 @@ For a class: Then, in an appropriate .cc file, - MEMPOOL_DEFINE_OBJECT_FACTORY(Foo, foo, unittest_1); + MEMPOOL_DEFINE_OBJECT_FACTORY(Foo, foo, osd); The second argument can generally be identical to the first, except when the type contains a nested scope. For example, for @@ -103,7 +103,7 @@ can't use :: in a variable name.) In order to use the STL containers, simply use the namespaced variant of the container type. For example, - mempool::unittest_1::map myvec; + mempool::osd::map myvec; Introspection ------------- @@ -146,9 +146,7 @@ namespace mempool { f(buffer_data) \ f(osd) \ f(osdmap) \ - f(osdmap_mapping) \ - f(unittest_1) \ - f(unittest_2) + f(osdmap_mapping) // give them integer ids diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index e2a8895c3b6..3be6f02d171 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -86,32 +86,32 @@ void do_insert_key(A& a, B& b, int count, int base) for (int i = 0; i < count; ++i) { a.insert(make_pair(base+i,base+i)); b.insert(make_pair(base+i,base+i)); - check_usage(mempool::unittest_1::id); + check_usage(mempool::osd::id); } } TEST(mempool, vector_context) { - check_usage(mempool::unittest_1::id); - EXPECT_EQ(mempool::unittest_1::allocated_bytes(), 0u); - EXPECT_EQ(mempool::unittest_1::allocated_items(), 0u); + check_usage(mempool::osd::id); + EXPECT_EQ(mempool::osd::allocated_bytes(), 0u); + EXPECT_EQ(mempool::osd::allocated_items(), 0u); for (unsigned i = 0; i < 10; ++i) { vector a; - mempool::unittest_1::vector b,c; + mempool::osd::vector b,c; eq_elements(a,b); do_push_back(a,b,i,i); eq_elements(a,b); - check_usage(mempool::unittest_1::id); + check_usage(mempool::osd::id); mempool::stats_t total; map by_type; - mempool::get_pool(mempool::unittest_1::id).get_stats(&total, &by_type); - EXPECT_GE(mempool::unittest_1::allocated_bytes(), i * 4u); - EXPECT_GE(mempool::unittest_1::allocated_items(), i); + mempool::get_pool(mempool::osd::id).get_stats(&total, &by_type); + EXPECT_GE(mempool::osd::allocated_bytes(), i * 4u); + EXPECT_GE(mempool::osd::allocated_items(), i); c.swap(b); eq_elements(a,c); - check_usage(mempool::unittest_1::id); + check_usage(mempool::osd::id); a.clear(); b.clear(); c.clear(); @@ -122,7 +122,7 @@ TEST(mempool, list_context) { for (unsigned i = 1; i < 10; ++i) { list a; - mempool::unittest_1::list b,c; + mempool::osd::list b,c; eq_elements(a,b); do_push_back(a,b,i,i); eq_elements(a,b); @@ -139,12 +139,12 @@ TEST(mempool, list_context) mempool::stats_t total; map by_type; - mempool::get_pool(mempool::unittest_1::id).get_stats(&total, &by_type); - EXPECT_GE(mempool::unittest_1::allocated_bytes(), i * 4u); - EXPECT_EQ(mempool::unittest_1::allocated_items(), i); + mempool::get_pool(mempool::osd::id).get_stats(&total, &by_type); + EXPECT_GE(mempool::osd::allocated_bytes(), i * 4u); + EXPECT_EQ(mempool::osd::allocated_items(), i); eq_elements(a,c); - check_usage(mempool::unittest_1::id); + check_usage(mempool::osd::id); } } @@ -152,22 +152,22 @@ TEST(mempool, set_context) { for (int i = 0; i < 10; ++i) { set a; - mempool::unittest_1::set b; + mempool::osd::set b; do_insert(a,b,i,i); eq_elements(a,b); - check_usage(mempool::unittest_1::id); + check_usage(mempool::osd::id); } for (int i = 1; i < 10; ++i) { set a; - mempool::unittest_1::set b; + mempool::osd::set b; do_insert(a,b,i,0); EXPECT_NE(a.find(i/2),a.end()); EXPECT_NE(b.find(i/2),b.end()); a.erase(a.find(i/2)); b.erase(b.find(i/2)); eq_elements(a,b); - check_usage(mempool::unittest_1::id); + check_usage(mempool::osd::id); } } @@ -182,14 +182,14 @@ struct obj { return l.a < r.a; } }; -MEMPOOL_DEFINE_OBJECT_FACTORY(obj, obj, unittest_2); +MEMPOOL_DEFINE_OBJECT_FACTORY(obj, obj, osdmap); TEST(mempool, test_factory) { obj *o1 = new obj(); obj *o2 = new obj(10); obj *o3 = new obj(20,30); - check_usage(mempool::unittest_2::id); + check_usage(mempool::osdmap::id); EXPECT_NE(o1,nullptr); EXPECT_EQ(o1->a,1); EXPECT_EQ(o1->b,1); @@ -201,18 +201,18 @@ TEST(mempool, test_factory) delete o1; delete o2; delete o3; - check_usage(mempool::unittest_2::id); + check_usage(mempool::osdmap::id); } TEST(mempool, vector) { { - mempool::unittest_1::vector v; + mempool::osd::vector v; v.push_back(1); v.push_back(2); } { - mempool::unittest_2::vector v; + mempool::osdmap::vector v; v.push_back(obj()); v.push_back(obj(1)); } @@ -220,10 +220,10 @@ TEST(mempool, vector) TEST(mempool, set) { - mempool::unittest_1::set set_int; + mempool::osd::set set_int; set_int.insert(1); set_int.insert(2); - mempool::unittest_2::set set_obj; + mempool::osdmap::set set_obj; set_obj.insert(obj()); set_obj.insert(obj(1)); set_obj.insert(obj(1, 2)); @@ -232,12 +232,12 @@ TEST(mempool, set) TEST(mempool, map) { { - mempool::unittest_1::map v; + mempool::osd::map v; v[1] = 2; v[3] = 4; } { - mempool::unittest_2::map v; + mempool::osdmap::map v; v[1] = obj(); v[2] = obj(2); v[3] = obj(2, 3); @@ -247,12 +247,12 @@ TEST(mempool, map) TEST(mempool, list) { { - mempool::unittest_1::list v; + mempool::osd::list v; v.push_back(1); v.push_back(2); } { - mempool::unittest_2::list v; + mempool::osdmap::list v; v.push_back(obj()); v.push_back(obj(1)); } @@ -260,7 +260,7 @@ TEST(mempool, list) TEST(mempool, unordered_map) { - mempool::unittest_2::unordered_map h; + mempool::osdmap::unordered_map h; h[1] = obj(); h[2] = obj(1); } @@ -279,13 +279,13 @@ TEST(mempool, bufferlist) TEST(mempool, string_test) { - mempool::unittest_2::string s; + mempool::osdmap::string s; s.reserve(100); - EXPECT_GE(mempool::unittest_2::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination : + EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination : for (size_t i = 0; i < 10; ++i) { s += '1'; s.append(s); - EXPECT_GE(mempool::unittest_2::allocated_items(), s.capacity() + 1u); + EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u); } } -- 2.39.5