src/storage/blobfs/test/unit/allocator-test.cc
// Test the condition where we cannot allocate because (while looking for
// blocks) we hit an already-allocated prefix of reserved / committed blocks.
Test the condition where we cannot allocate because (while looking for
blocks) we hit an already-allocated prefix of reserved / committed blocks.
Test the condition where we cannot allocate because ( while looking for blocks ) we hit an already - allocated prefix of reserved / committed blocks .
TEST(AllocatorTest, PrefixCollision) {
  MockSpaceManager space_manager;
  std::unique_ptr<Allocator> allocator;
  InitializeAllocator(4, 4, &space_manager, &allocator);
  fbl::Vector<ReservedExtent> extents;
  ASSERT_EQ(allocator->ReserveBlocks(2, &extents), ZX_OK);
  ASSERT_EQ(1ul, extents.size());
  fbl::Vector<ReservedExtent> failed_extents;
  ASSERT_EQ(ZX_ERR_NO_SPACE, allocator->ReserveBlocks(3, &failed_extents));
  allocator->MarkBlocksAllocated(extents[0]);
  Extent extent = extents[0].extent();
  extents.reset();
  ASSERT_EQ(ZX_ERR_NO_SPACE, allocator->ReserveBlocks(3, &failed_extents));
  allocator->FreeBlocks(extent);
  ASSERT_EQ(allocator->ReserveBlocks(3, &extents), ZX_OK);
}
TEST ( AllocatorTest , PrefixCollision ) { MockSpaceManager space_manager ; std :: unique_ptr < Allocator > allocator ; InitializeAllocator ( 4 , 4 , & space_manager , & allocator ) ; fbl :: Vector < ReservedExtent > extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( 2 , & extents ) , ZX_OK ) ; ASSERT_EQ ( 1ul , extents . size ( ) ) ; fbl :: Vector < ReservedExtent > failed_extents ; ASSERT_EQ ( ZX_ERR_NO_SPACE , allocator -> ReserveBlocks ( 3 , & failed_extents ) ) ; allocator -> MarkBlocksAllocated ( extents [ 0 ] ) ; Extent extent = extents [ 0 ] . extent ( ) ; extents . reset ( ) ; ASSERT_EQ ( ZX_ERR_NO_SPACE , allocator -> ReserveBlocks ( 3 , & failed_extents ) ) ; allocator -> FreeBlocks ( extent ) ; ASSERT_EQ ( allocator -> ReserveBlocks ( 3 , & extents ) , ZX_OK ) ; }
Test the condition where we cannot allocate because (while looking for
blocks) we hit an already-allocated prefix of reserved / committed blocks.
Test the condition where we cannot allocate because ( while looking for blocks ) we hit an already - allocated prefix of reserved / committed blocks .
// Allocate a single extent of two blocks. // We have two blocks left; we cannot allocate three blocks. // After the extents are committed (and unreserved), we still cannot // utilize their space. // After freeing the allocated blocks, we can re-allocate.