From 6ae213181433dd2ae392d8eed85c2606b9c4bb54 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 19 Aug 2019 14:39:31 +0300 Subject: [PATCH] test/allocator_test: additional coverage for get_fragmentation_score Tests the function results agains the same cases as we do for get_fragmentation. Signed-off-by: Igor Fedotov --- src/test/objectstore/Allocator_test.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index 34d1489a02e..06285a971f0 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -267,6 +267,8 @@ TEST_P(AllocTest, test_alloc_fragmentation) alloc->release(release_set); } EXPECT_EQ(1.0, alloc->get_fragmentation(alloc_unit)); + EXPECT_EQ(66u, uint64_t(alloc->get_fragmentation_score() * 100)); + for (size_t i = 1; i < allocated.size() / 2; i += 2) { interval_set release_set; @@ -280,6 +282,7 @@ TEST_P(AllocTest, test_alloc_fragmentation) // fragmentation approx = 257 intervals / 768 max intervals EXPECT_EQ(33u, uint64_t(alloc->get_fragmentation(alloc_unit) * 100)); } + EXPECT_EQ(27u, uint64_t(alloc->get_fragmentation_score() * 100)); for (size_t i = allocated.size() / 2 + 1; i < allocated.size(); i += 2) { @@ -292,6 +295,11 @@ TEST_P(AllocTest, test_alloc_fragmentation) // Hence leaving just two // digits after decimal point due to this. EXPECT_EQ(0u, uint64_t(alloc->get_fragmentation(alloc_unit) * 100)); + if (bitmap_alloc) { + EXPECT_EQ(0u, uint64_t(alloc->get_fragmentation_score() * 100)); + } else { + EXPECT_EQ(11u, uint64_t(alloc->get_fragmentation_score() * 100)); + } } TEST_P(AllocTest, test_dump_fragmentation_score) @@ -309,6 +317,7 @@ TEST_P(AllocTest, test_dump_fragmentation_score) alloc->init_add_free(0, capacity); EXPECT_EQ(0.0, alloc->get_fragmentation(alloc_unit)); + EXPECT_EQ(0.0, alloc->get_fragmentation_score()); uint64_t allocated_cnt = 0; for (size_t round = 0; round < rounds ; round++) { -- 2.39.5