| 633 | |
| 634 | template <typename AllocateFunction> |
| 635 | void TestZeroSizeAllocateBuffer(MemoryPool* pool, AllocateFunction&& allocate_func) { |
| 636 | auto allocated_bytes = pool->bytes_allocated(); |
| 637 | { |
| 638 | std::shared_ptr<Buffer> buffer, buffer2; |
| 639 | |
| 640 | ASSERT_OK(allocate_func(pool, 0, &buffer)); |
| 641 | AssertIsCPUBuffer(*buffer); |
| 642 | ASSERT_EQ(buffer->size(), 0); |
| 643 | // Even 0-sized buffers should not have a null data pointer |
| 644 | auto data = buffer->data(); |
| 645 | ASSERT_NE(data, nullptr); |
| 646 | ASSERT_EQ(buffer->mutable_data(), data); |
| 647 | |
| 648 | // As an optimization, another 0-size buffer should share the same memory "area" |
| 649 | ASSERT_OK(allocate_func(pool, 0, &buffer2)); |
| 650 | AssertIsCPUBuffer(*buffer2); |
| 651 | ASSERT_EQ(buffer2->size(), 0); |
| 652 | ASSERT_EQ(buffer2->data(), data); |
| 653 | |
| 654 | ASSERT_GE(pool->bytes_allocated(), allocated_bytes); |
| 655 | } |
| 656 | ASSERT_EQ(pool->bytes_allocated(), allocated_bytes); |
| 657 | } |
| 658 | |
| 659 | TEST(TestAllocateBuffer, ZeroSize) { |
| 660 | MemoryPool* pool = default_memory_pool(); |
no test coverage detected