src/storage/blobfs/test/unit/allocator-test.cc
// Test a case of allocation where we try allocating more blocks than can fit
// within a single extent.
Test a case of allocation where we try allocating more blocks than can fit
within a single extent.
Test a case of allocation where we try allocating more blocks than can fit within a single extent .
TEST(AllocatorTest, MaxExtent) {
  MockSpaceManager space_manager;
  std::unique_ptr<Allocator> allocator;
  constexpr uint64_t kBlockCount = kBlockCountMax * 2;
  InitializeAllocator(kBlockCount, 4, &space_manager, &allocator);
  fbl::Vector<ReservedExtent> extents;
  ASSERT_EQ(allocator->ReserveBlocks(kBlockCountMax, &extents), ZX_OK);
  ASSERT_EQ(1ul, extents.size());
  extents.reset();
  ASSERT_EQ(allocator->ReserveBlocks(kBlockCountMax + 1, &extents), ZX_OK);
  ASSERT_EQ(2ul, extents.size());
  fbl::Vector<ReservedExtent> remainder;
  ASSERT_EQ(allocator->ReserveBlocks(kBlockCount - (kBlockCountMax + 1), &remainder), ZX_OK);
  fbl::Vector<ReservedExtent> failed_extent;
  ASSERT_EQ(ZX_ERR_NO_SPACE, allocator->ReserveBlocks(1, &failed_extent));
}
TEST ( AllocatorTest , MaxExtent ) { MockSpaceManager space_manager ; std :: unique_ptr < Allocator > allocator ; constexpr uint64_t kBlockCount = kBlockCountMax * 2 ; InitializeAllocator ( kBlockCount , 4 , & space_manager , & allocator ) ; fbl :: Vector < ReservedExtent > extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( kBlockCountMax , & extents ) , ZX_OK ) ; ASSERT_EQ ( 1ul , extents . size ( ) ) ; extents . reset ( ) ; ASSERT_EQ ( allocator -> ReserveBlocks ( kBlockCountMax + 1 , & extents ) , ZX_OK ) ; ASSERT_EQ ( 2ul , extents . size ( ) ) ; fbl :: Vector < ReservedExtent > remainder ; ASSERT_EQ ( allocator -> ReserveBlocks ( kBlockCount - ( kBlockCountMax + 1 ) , & remainder ) , ZX_OK ) ; fbl :: Vector < ReservedExtent > failed_extent ; ASSERT_EQ ( ZX_ERR_NO_SPACE , allocator -> ReserveBlocks ( 1 , & failed_extent ) ) ; }
Test a case of allocation where we try allocating more blocks than can fit
within a single extent.
Test a case of allocation where we try allocating more blocks than can fit within a single extent .
// Allocate a region which may be contained within one extent. // Allocate a region which may not be contined within one extent. // Demonstrate that the remaining blocks are still available. // But nothing more.