src/storage/blobfs/test/unit/allocator-test.cc
// Test the condition where our allocation request overlaps with both a
// previously allocated and reserved region.
Test the condition where our allocation request overlaps with both a
previously allocated and reserved region.
Test the condition where our allocation request overlaps with both a previously allocated and reserved region .
TEST(AllocatorTest, ReservedBeforeAllocated) {
  MockSpaceManager space_manager;
  std::unique_ptr<Allocator> allocator;
  InitializeAllocator(4, 4, &space_manager, &allocator);
  fbl::Vector<ReservedExtent> reserved_extents;
  ASSERT_EQ(allocator->ReserveBlocks(1, &reserved_extents), ZX_OK);
  ASSERT_EQ(1ul, reserved_extents.size());
  {
    fbl::Vector<ReservedExtent> committed_extents;
    ASSERT_EQ(allocator->ReserveBlocks(1, &committed_extents), ZX_OK);
    ASSERT_EQ(1ul, committed_extents.size());
    allocator->MarkBlocksAllocated(committed_extents[0]);
  }
  fbl::Vector<ReservedExtent> extents;
  ASSERT_EQ(allocator->ReserveBlocks(2, &extents), ZX_OK);
  ASSERT_EQ(1ul, extents.size());
}
TEST ( AllocatorTest , ReservedBeforeAllocated ) { MockSpaceManager space_manager ; std :: unique_ptr < Allocator > allocator ; InitializeAllocator ( 4 , 4 , & space_manager , & allocator ) ; fbl :: Vector < ReservedExtent > reserved_extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( 1 , & reserved_extents ) , ZX_OK ) ; ASSERT_EQ ( 1ul , reserved_extents . size ( ) ) ; { fbl :: Vector < ReservedExtent > committed_extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( 1 , & committed_extents ) , ZX_OK ) ; ASSERT_EQ ( 1ul , committed_extents . size ( ) ) ; allocator -> MarkBlocksAllocated ( committed_extents [ 0 ] ) ; } fbl :: Vector < ReservedExtent > extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( 2 , & extents ) , ZX_OK ) ; ASSERT_EQ ( 1ul , extents . size ( ) ) ; }
Test the condition where our allocation request overlaps with both a
previously allocated and reserved region.
Test the condition where our allocation request overlaps with both a previously allocated and reserved region .
// Reserve an extent of one block. // Allocate a single extent of one block, immediately following the prior // reservation. // We should still be able to reserve the remaining two blocks in a single // extent.