diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-02-10 13:50:05 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-02-10 13:50:05 +0100 |
commit | e66bdcf264ca817d17173c9d4748ff86b8e0b91f (patch) | |
tree | 2dd8d3950b227e6b0c56a273cfe596765863eb75 /vespalib/src/tests/datastore | |
parent | fed60ae90b4e230129b4e9e6b72dd125d354e6c0 (diff) |
Add memory allocator to unique store allocator
Diffstat (limited to 'vespalib/src/tests/datastore')
4 files changed, 32 insertions, 4 deletions
diff --git a/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp b/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp index 417b92af9ac..599cb209e6c 100644 --- a/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp +++ b/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp @@ -68,7 +68,7 @@ struct DataStoreFixedSizeHashTest : public ::testing::Test DataStoreFixedSizeHashTest::DataStoreFixedSizeHashTest() : _generation_handler(), _generation_holder(), - _allocator(), + _allocator({}), _store(_allocator.get_data_store()), _comp(std::make_unique<MyCompare>(_store)), _hash_map(), diff --git a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp index 796e19a97d1..13f9ae251b6 100644 --- a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp +++ b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp @@ -132,7 +132,7 @@ struct DataStoreShardedHashTest : public ::testing::Test DataStoreShardedHashTest::DataStoreShardedHashTest() : _generationHandler(), - _allocator(), + _allocator({}), _store(_allocator.get_data_store()), _hash_map(std::make_unique<MyCompare>(_store)), _writer(1, 128_Ki), diff --git a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp index 917c91f2dff..7f279689985 100644 --- a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp +++ b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp @@ -9,6 +9,7 @@ #include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/test/datastore/buffer_stats.h> #include <vespa/vespalib/test/insertion_operators.h> +#include <vespa/vespalib/test/memory_allocator_observer.h> #include <vespa/vespalib/util/traits.h> #include <vector> @@ -21,6 +22,9 @@ using namespace vespalib::datastore; using vespalib::ArrayRef; using generation_t = vespalib::GenerationHandler::generation_t; using vespalib::datastore::test::BufferStats; +using vespalib::alloc::MemoryAllocator; +using vespalib::alloc::test::MemoryAllocatorObserver; +using AllocStats = MemoryAllocatorObserver::Stats; template <typename UniqueStoreT> struct TestBaseValues { @@ -39,6 +43,7 @@ struct TestBase : public ::testing::Test { using ReferenceStoreValueType = std::conditional_t<std::is_same_v<ValueType, const char *>, std::string, ValueType>; using ReferenceStore = std::map<EntryRef, std::pair<ReferenceStoreValueType,uint32_t>>; + AllocStats stats; UniqueStoreType store; ReferenceStore refStore; generation_t generation; @@ -148,7 +153,8 @@ struct TestBase : public ::testing::Test { template <typename UniqueStoreTypeAndDictionaryType> TestBase<UniqueStoreTypeAndDictionaryType>::TestBase() - : store(), + : stats(), + store(std::make_unique<MemoryAllocatorObserver>(stats)), refStore(), generation(1) { @@ -424,6 +430,15 @@ TYPED_TEST(TestBase, store_can_be_enumerated) EXPECT_EQ(2u, enumValue2); } +TYPED_TEST(TestBase, provided_memory_allocator_is_used) +{ + if constexpr (std::is_same_v<const char *, typename TestFixture::ValueType>) { + EXPECT_EQ(AllocStats(18, 0), this->stats); + } else { + EXPECT_EQ(AllocStats(1, 0), this->stats); + } +} + #pragma GCC diagnostic pop TEST_F(DoubleTest, nan_is_handled) diff --git a/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp b/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp index 158b85f6bf5..21330c22166 100644 --- a/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp +++ b/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/test/datastore/buffer_stats.h> #include <vespa/vespalib/test/insertion_operators.h> +#include <vespa/vespalib/test/memory_allocator_observer.h> #include <vespa/vespalib/util/traits.h> #include <vector> @@ -11,6 +12,10 @@ using namespace vespalib::datastore; using vespalib::MemoryUsage; using generation_t = vespalib::GenerationHandler::generation_t; using BufferStats = vespalib::datastore::test::BufferStats; +using vespalib::alloc::MemoryAllocator; +using vespalib::alloc::test::MemoryAllocatorObserver; +using AllocStats = MemoryAllocatorObserver::Stats; + namespace { @@ -24,10 +29,12 @@ template <typename RefT = EntryRefT<22>> struct TestBase : public ::testing::Test { using EntryRefType = RefT; + AllocStats stats; UniqueStoreStringAllocator<EntryRefType> allocator; generation_t generation; TestBase() - : allocator(), + : stats(), + allocator(std::make_unique<MemoryAllocatorObserver>(stats)), generation(1) {} void assert_add(const char *input) { @@ -170,6 +177,11 @@ TEST_F(StringTest, free_list_is_never_used_for_move) assert_buffer_state(ref2, BufferStats().used(4).hold(0).dead(2).extra_used(2002)); } +TEST_F(StringTest, provided_memory_allocator_is_used) +{ + EXPECT_EQ(AllocStats(18, 0), stats); +} + TEST_F(SmallOffsetStringTest, new_underlying_buffer_is_allocated_when_current_is_full) { uint32_t first_buffer_id = get_buffer_id(add(small.c_str())); @@ -184,6 +196,7 @@ TEST_F(SmallOffsetStringTest, new_underlying_buffer_is_allocated_when_current_is uint32_t buffer_id = get_buffer_id(add(small.c_str())); EXPECT_EQ(second_buffer_id, buffer_id); } + EXPECT_LT(18, stats.alloc_cnt); } GTEST_MAIN_RUN_ALL_TESTS() |